function GetDay(intDay){
  var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", 
                           "Thursday", "Friday", "Saturday")
  return DayArray[intDay]}

function GetMonth(intMonth){
  var MonthArray = new Array("January", "February", "March",
                             "April", "May", "June",
                             "July", "August", "September",
                             "October", "November", "December") 
  return MonthArray[intMonth]}
  
function getDateStrWithDOW(){
  var today = new Date()
  var year = today.getYear()
  if(year<1000) year+=1900
  var todayStr = GetDay(today.getDay()) + ", "
			  
  todayStr += today.getDate() + " " +  GetMonth(today.getMonth())

  todayStr += " " + year
  return todayStr}
  
function openWin(url){
	var TagWin = null;
	TagWin = window.open(url,"TagWin","toolbar=0,location=0,status=no,menubar=0,scrollbars=1,resizable=1,top=7,left=2,width=380,height=400");
	TagWin.focus()}  
	
function gotoURL(url){
 if (url != "")
      document.location=url
}

function chkSelects(url,action){
	var recids;var i
	recids = ""
	if (document.forms[0].rec){
						if (document.forms[0].rec.length){
							for (i=0;i<document.forms[0].rec.length;i++){
									if (document.forms[0].rec[i].checked == true){
											if (recids==""){ 
												recids = document.forms[0].rec[i].value;}
											else{
												recids = recids + "," + document.forms[0].rec[i].value;}
										}}
							 }
						else if (document.forms[0].rec){
							if (document.forms[0].rec.checked == true)
								recids = document.forms[0].rec.value
							}
				}
	else	if (document.forms[1].rec){
						if (document.forms[1].rec.length){
									for (i=0;i<document.forms[1].rec.length;i++){
											if (document.forms[1].rec[i].checked == true){
																if (recids==""){ 
																	recids = document.forms[1].rec[i].value;}
																else{
																	recids = recids + "," + document.forms[1].rec[i].value;}
												}}
							 }
						else if (document.forms[1].rec){
							if (document.forms[1].rec.checked == true)
								recids = document.forms[1].rec.value
							}
			}
		
	
	if (recids==""){
		alert("You haven't select any records.")}
	else{
	  url = url + "&action=" + escape(action) + "&recids=" + escape(recids)
		if (action == "delete"){
			if (confirm("Are you sure you want to delete these records?")){
				gotoURL(url)}}
		else{gotoURL(url)}	
	}
}


//------------------------------ admin -------------------------------------------


function previewpage(hostpage,fileloc,type){	
	if (fileloc == "Select" || fileloc == ""){ 	        
		alert("You have not selected a file.")}
	else{
		if (type == 1){var url = hostpage + '/' + fileloc + '?pr=yes';openWin2(url,500,530)}
		else if (type == 2){var url = hostpage + '?fileloc=' + escape(fileloc);openWin2(url,500,530)}
		else if (type == 3){var url = fileloc;if (validateprevfile(fileloc)){openWin2(url,500,530)}}}
}

function openWin2(url,intwidth,intheight){
	var TagWin = null;
	var Opts = "toolbar=1,location=0,top=0,left=0,scrollbars=1,resizable=1,width=" + intwidth + ",height=" + intheight;
	TagWin = window.open(url,"TagWin",Opts);
	TagWin.focus()}


function validateprevfile(filename){
	var allowfiletypes = "htm,html,asp";
	var filelength = filename.length;
	var filetype = filename.substring(filelength-3,filelength);
	filetype = filetype.toLowerCase();
	if (allowfiletypes.indexOf(filetype,0) == -1){
		alert("File is not a htm, html or asp file.");return false}
	else{return true}	
}

function delcheckfiles(relocpage){
	var filelist;var i;var strMsg;
	filelist = ""
	if (document.filelibrary.fileid.length){
		for (i=0;i<document.filelibrary.fileid.length;i++){
				if (document.filelibrary.fileid[i].checked == true){
						if (filelist==""){ 
							filelist = document.filelibrary.fileid[i].value;}
						else{
							filelist = filelist + "," + document.filelibrary.fileid[i].value;}
				  }}
		 }
	else if (document.filelibrary.fileid){
		if (document.filelibrary.fileid.checked == true)
			filelist = document.filelibrary.fileid.value
		}
	if (filelist==""){
		alert("You have not ticked any files to delete.")}
	else{
	  strMsg = "You are about to delete the ticked file(s). Click OK if you want to continue."
		if (confirm(strMsg)){
			relocpage = relocpage + "&fileid=" + escape(filelist)
			self.location = relocpage}}
}

function selectfile(form, field, value){
var objName = eval('document.'+form+'.'+field);
var objLength = objName.length;
var thisValue
if (objLength != 0){
	for (i = 0; i < objLength; i++){
		thisValue = eval('objName.options['+i+'].value')
		if (thisValue == value){
			eval('objName.selectedIndex='+i);
			break;}}
	}
}



function confirmdelete(href,item,itemname){
	var strMsg
	if (item == 'f'){
		strMsg = "Delete the folder '" + itemname + "' will also delete any folders and pages under it.\n"
	  strMsg = strMsg + "Click OK if you want to continue."
		if (confirm(strMsg)){
			self.location = href}}
	else if (item == 'p'){
	  strMsg = "You are about to delete the page '" + itemname + "'. Click OK if you want to continue."
		if (confirm(strMsg)){
			self.location = href}}
	else if (item == 'fi'){
	  strMsg = "You are about to delete the file '" + itemname + "'. Click OK if you want to continue."
		if (confirm(strMsg)){
			self.location = href}}
}


function editFile(params,id)
{
  var strMsg = ""
		if (id== "0"){
		 strMsg = "You must select a file to edit.\n"}
		 
  if (strMsg==""){
    var strURL = '../../FileLibrary/editfile.asp?' + params + '&fileid=' + id
				gotoURL(strURL)}
  else{
   alert (strMsg)}

}

function CheckSelection(obj)
{
	var icount;
	var anyselected;
	var anyindex;
	var optselected;
	anyindex = 0;
	anyselected = false;
	for (icount = 0 ; icount < obj.length; icount++)
	{
		if (obj.options[icount].value == 0)
		{
			anyindex = icount;
			if (obj.options[icount].selected)
			{
				anyselected = true;
				break;
			}
		}
	}

	optselected = 0;

	for (icount = 0 ; icount < obj.length; icount++)
	{
		if (obj.options[icount].selected)
		{
			optselected++;

			if ((obj.options[icount].value != 0) && (anyselected))
			{
				obj.options[icount].selected = false;
			}
		}
	}

	if (optselected == 0)
	{
		obj.options[anyindex].selected = true;
	}
}






// ----------------------------------------------------------------------------------
// ------------------------------ form validation -----------------------------------
// ----------------------------------------------------------------------------------


var errmsg
function validateformsearch(){
		errmsg = "";
		var searchfor = document.search.searchfor.value;
		if (searchfor == ""){
		  errmsg = errmsg + "Enter keyword(s) in the search field.\n"}
		if (errmsg == ""){
		 return true}
	  else{
		 alert(errmsg);	
	   return false;}
}



function selectfile2(form, field, value){
var objName = eval('document.'+form+'.'+field);
var objLength = objName.length;
var thisValue
eval('objName.options[0].selected = false')	

	if (objLength != 0){
	for (i = 0; i < objLength; i++){
		thisValue = eval('objName.options['+i+'].value')
		thisValue = '+' + thisValue + '+'
		if (value.indexOf(thisValue,0) != -1){
			eval('objName.options['+i+'].selected = true')
			}}

}
}



function IsNullString(strValue) {
  var blnReturn = true;
  //check for white space: "[ \f\n\r\t\v]".
    for (i = 0; i < strValue.length; i ++) {
        character = strValue.charAt(i);
        if (!(character == " " || character == "\f" || character == "\n" || character == "\r" || character == "\t" || character == "\v")) {
            blnReturn = false;
            break;
        }
    }
    return blnReturn;
}


function seloption(form, field, value,displaytext){
	var objName = eval('document.'+form+'.'+field);
	var objLength = objName.length;
	var thisValue;
	var OptionFound = false;
	if (objLength != 0){
		for (i = 0; i < objLength; i++){
			thisValue = eval('objName.options['+i+'].value')
			if (thisValue == value){
				eval('objName.selectedIndex='+i);
				OptionFound = true;
				break;}}
		if (OptionFound == false){
			eval('objName.options['+i+'] = new Option("'+displaytext+'","'+value+'")')
			eval('objName.selectedIndex='+i);
		}
	}
}


function IsEmail(val)
	{		
		if (val != "")
			{			
					if(val.lenght < 5 || val.indexOf('@', 0) < 1)
							{
								return false;
							}
					else
							{
										var dot_index = val.indexOf('.', 0);
										if(dot_index == -1 || dot_index < 1)
										{
											return false;
										}
							}
			}
	return true
	}

function checktextsize(formname,elemname,max){
	var text = eval("document." + formname + "." + elemname + ".value");
	var textsize = text.length;
	if (textsize > max) {
	 text = text.substring(0,max);
	 eval("document." + formname + "." + elemname + ".value='" + text + "'");
	 alert("Your comments are too long.");}
}

function linkCustLoc(arrLocIn){
	 var arrLocOut = new Object();
	 for (LoopIndex = 0 ; LoopIndex < arrLocIn.length; LoopIndex++){ 
	   arrLocOut[arrLocIn[LoopIndex]] = 0;}
	 return(arrLocOut);}
	 
function rebuildlocations(objdepart,objlocate,arrcustlocate,arrlocate) {
		CheckSelection(objdepart);
		for (LoopIndex = 0 ; LoopIndex < objlocate.options.length; LoopIndex++){
					objlocate.options[LoopIndex].selected= false;}
		objlocate.options.length = 0
	
		arrLocOptions = new Array();
		for (LoopIndex = 0 ; LoopIndex < objdepart.length; LoopIndex++) {
			if (objdepart.options[LoopIndex].selected) {
					intDepID = objdepart.options[LoopIndex].value;
					for (intLocID in arrcustlocate[intDepID]){
											arrLocOptions[intLocID] = intLocID;}
				}
		}
	
		arrSortLocOptions = new Array();
		sortIndex=0;
		for (LoopIndex in arrLocOptions) {
			if (arrLocOptions[LoopIndex] != null) {
				arrSortLocOptions[sortIndex] = arrLocOptions[LoopIndex];
				sortIndex = sortIndex + 1;
			}
		}
	
		arrSortLocOptions.sort(ordernum);
		
		var ArrLocNameID=new Array(sortIndex);	
	 for (i=0; i <sortIndex; i++)
		{
				ArrLocNameID[i]=new Array(1);
				ArrLocNameID[i][0]=arrlocate[arrSortLocOptions[i]];
				ArrLocNameID[i][1]=arrSortLocOptions[i];
		}
		ArrLocNameID.sort();	
	
		objlocate.options[objlocate.options.length] = new Option("All", 0);
		
		for (i=0;i<ArrLocNameID.length;i++) {
			objlocate.options[objlocate.options.length] = new Option(ArrLocNameID[i][0], ArrLocNameID[i][1]);
		}
	
			objlocate.options[0].selected = true;
	}
	
		function ordernum(x, y) {
		return x - y;
	}



function check_date(field){
			var checkstr = "0123456789";
			var DateField = field;
			var Datevalue = "";
			var DateTemp = "";
			var seperator = "/";
			var day;
			var month;
			var year;
			var leap = 0;
			var err = 0;
			var i;
			var blnReturn
   err = 0;
   DateValue = DateField.value;
			
			/* extra number from 0 to 9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);}}
   
   DateValue = DateTemp;

   /* if year is entered as 2-digit / prepend 20 */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   
   if (DateValue.length != 8) {
      err = 19;}

   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;}

   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;}

   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;}

			/* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;}
   
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;}
   
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;}

  /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;}
   
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;}

   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";}

   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
						blnReturn = true}
   else {
      blnReturn = false}
			
			return blnReturn
}
	 
	 
	// --------------------------- admin ----------------------------------------------
	

	var errmsg
function validateformfile(layoutappend,optkey){
	if (optkey == 1 || optkey == 3){
		errmsg = "";
		var filename = document.file.filename.value;
	 var path = document.file.path.value;
		
		var i;

		for (i=0;i<document.file.sitelayoutappend.length;i++){
		if (document.file.sitelayoutappend[i].checked == true){
				var sitelayoutappend = document.file.sitelayoutappend[i].value;
			  break;}}
		validatefile(sitelayoutappend,filename)	
		if (path == ""){
		  errmsg = errmsg + "File folder is required.\n";
		  document.file.path.focus();
		  }



		if (errmsg == ""){
			return true}
	  else{
			errmsg = "The following error(s) have occurred.\n" + errmsg;
			alert(errmsg);	
			return false;}} 
	else{
		errmsg = "";
		var sitelayoutappend = document.file.sitelayoutappend.value;
		if (errmsg == ""){
		 return true}
	  else{
		 errmsg = "The following error(s) have occurred.\n" + errmsg
		 alert(errmsg);	
	   return false;}
	}
}

function validatefile(append,filename){
	if (append == "y"){
	  var allowfiletypes = "asp";
		 var errmsg2 = "File extension must be asp.\n"}
	else{
	  //var allowfiletypes = "htm,html,asp";
	  //var errmsg2 = "Target right file is not a htm, html or asp file.\n"}
	  var allowfiletypes = "asp";
			var errmsg2 = "File extension must be asp.\n"}
	if (filename == ""){
		errmsg = errmsg + "File is required.\n";
		document.file.filename.focus();
		}
	else{ 
		var filelength = filename.length;
		var filetype = filename.substring(filelength-3,filelength);
		filetype = filetype.toLowerCase();
		if (allowfiletypes.indexOf(filetype,0) == -1){
			errmsg = errmsg + "" + errmsg2;
			document.file.filename.focus();
			}}
}

function validateformfolder(){
		errmsg = "";
		var foldername = document.folder.foldername.value;
		var filesource = document.folder.filesource.options[document.folder.filesource.selectedIndex].value;
		var externalsource = document.folder.externalsource.value;
		var width = document.folder.width.value;
		var keywords = document.folder.keywords.value;
		var descriptionlength = document.folder.description.value.length;
		if (foldername == ""){
		  errmsg = errmsg + "Folder name is required.\n"}
		if (filesource != 0 && externalsource != ""){
		  errmsg = errmsg + "Can not select both Page file and Link url.\n"}
		if (width == ""){
		  errmsg = errmsg + "Block width is required.\n"}
		if (isNaN(width)){
		  errmsg = errmsg + "Block width must be a number.\n"}
		if (descriptionlength > 1024){
		  errmsg = errmsg + "Description is too long.\n"}
		if (errmsg == ""){
		 return true}
	  else{
		 errmsg = "The following error(s) have occurred.\n" + errmsg;
		 alert(errmsg);	
	   return false;}
}

function validateformpage(){
		errmsg = "";
		var pagename = document.page.pagename.value;
		var filesource = document.page.filesource.options[document.page.filesource.selectedIndex].value;
		var externalsource = document.page.externalsource.value;
		var width = document.page.width.value;
		var keywords = document.page.keywords.value;
		var descriptionlength = document.page.description.value.length;
		var i;
		for (i=0;i<document.page.show.length;i++){
			if (document.page.show[i].checked == true){
				var show = document.page.show[i].value;
			  break;}}
		if (pagename == ""){
		  errmsg = errmsg + "Link name is required.\n"}
		if (filesource == 0 && externalsource == ""){
		  errmsg = errmsg + "Page file or Link url is required.\n"}
		if (filesource != 0 && externalsource != ""){
		  errmsg = errmsg + "Can not select both Page file and Link url.\n"}
		if (show == "y"){
			if (width == ""){
			  errmsg = errmsg + "Block width is required.\n"}
			if (isNaN(width)){
			  errmsg = errmsg + "Block width must be a number.\n"}}
		else{if (width == ""){document.page.width.value = 0}}
		
		if (descriptionlength > 1024){
		  errmsg = errmsg + "Description is too long.\n"}
		if (errmsg == ""){
		 return true}
	  else{
		 errmsg = "The following error(s) have occurred.\n" + errmsg;
		 alert(errmsg);	
	   return false;}
}

function validateformlogin(){
		errmsg = "";
		var username = document.login.username.value;
		var password = document.login.password.value;
		if (username == ""){
		  errmsg = errmsg + "Username is required.\n"}
		if (password == ""){
		  errmsg = errmsg + "Password is required.\n"}
		if (errmsg == ""){
		 return true}
	  else{
		 alert(errmsg);	
	   return false;}
}

function validateformadminconfig(){
		errmsg = "";

		var SQLServer = document.adminconfig.SQLServer.value;
		var DBName = document.adminconfig.DBName.value;
		var DBUserID = document.adminconfig.DBUserID.value;		
		var DBPassword = document.adminconfig.DBPassword.value;

		if (SQLServer == ""){
		  errmsg = errmsg + "Database server is required.\n"}
		if (DBName == ""){
		  errmsg = errmsg + "Database name is required.\n"}
		if (DBUserID == ""){
		  errmsg = errmsg + "User ID is required.\n"}
		if (DBPassword == ""){
		  errmsg = errmsg + "Password is required.\n"}


		var httphost = document.adminconfig.httphost.value;
		var uploadroot = document.adminconfig.uploadroot.value;

		var mailserver = document.adminconfig.mailserver.value;
		var orderemail = document.adminconfig.orderemail.value;
		var infoemail = document.adminconfig.infoemail.value;		
		var feedbackemail = document.adminconfig.feedbackemail.value;
		var adminemail = document.adminconfig.adminemail.value;
		
		var i;
		for (i=0;i<document.adminconfig.accesstype.length;i++){
			if (document.adminconfig.accesstype[i].checked == true){
				var accesstype = document.adminconfig.accesstype[i].value;
			  break;}}
	
		var Port = document.adminconfig.Port.value;
		var proxyserver = document.adminconfig.proxyserver.value;

		var title = document.adminconfig.title.value;
		var description = document.adminconfig.description.value;
		var keywords = document.adminconfig.keywords.value;
		var pagesize = document.adminconfig.pagesize.value;
	
		if (httphost == ""){
		  errmsg = errmsg + "Http host is required.\n"}
		
		if (uploadroot == ""){
		  errmsg = errmsg + "Upload physical root is required.\n"}
	
		if (mailserver == ""){
		  errmsg = errmsg + "Mail server is required.\n"}

		if (orderemail == ""){
		  errmsg = errmsg + "Order email is required.\n"}

		if (infoemail == ""){
		  errmsg = errmsg + "Info email is required.\n"}

		if (feedbackemail == ""){
		  errmsg = errmsg + "Feedback email is required.\n"}

		if (adminemail == ""){
		  errmsg = errmsg + "Admin email is required.\n"}

		if (accesstype == "2" && proxyserver == ""){
		  errmsg = errmsg + "Proxy server is required.\n"}
		
		if (Port == ""){
		  errmsg = errmsg + "Port is required.\n"}

		if (title == ""){
		  errmsg = errmsg + "Title is required.\n"}
		
		if (description == ""){
		  errmsg = errmsg + "Description is required.\n"}
		if (keywords == ""){
		  errmsg = errmsg + "Keywords are required.\n"}
		
		if (keywords.length > 874){
		  errmsg = errmsg + "Keywords are too long.\n"}
		if (pagesize == ""){
		  errmsg = errmsg + "Page size is required.\n"}
		if (pagesize < 1 || isNaN(pagesize)){
		  errmsg = errmsg + "Page size is invalid. Page size must be a number and greater than 0.\n"}
		if (errmsg == ""){
			return true}
	  else{
			errmsg = "The following error(s) have occurred.\n" + errmsg;
			alert(errmsg);	
			return false;}
}

 function goSite() 
 {iwin = window.open("professionalFull.asp","IWIN","status=no,toolbar=no,location=no,menu=no,scrollbars=no,width=900,height=250,screenX=0,screenY=50,left=50,top=100")}

function previewlogo(hostpage,fileloc,allowfiles,winwidth,winheight){	
	if (fileloc == "Select" || fileloc == ""){ 	        
		alert("You must select a file.")}
	else{
		var url = hostpage + '?fileloc=' + escape(fileloc);if (validateprevfile2(fileloc,allowfiles)){openWin3(url,winwidth,winheight)}else{alert("File must be '" + allowfiles + "' type.");}
		}
}


function openWin3(url,width,height){
	var TagWin = null;
	TagWin = window.open(url,"TagWin","toolbar=0,location=0,status=no,menubar=0,scrollbars=1,resizable=1,top=7,left=2,width=" + width + ",height=" + height);
	TagWin.focus()}


function validateprevfile2(filename,allowfiletypes){
	var filelength = filename.length;
	var filetype = filename.substring(filelength-3,filelength);
	filetype = filetype.toLowerCase();
	if (allowfiletypes.indexOf(filetype,0) == -1){
		return false}
	else{return true}	
}





// --------------------------- admin ----------------------------------------------
 