/**
 * Commented out all the badly written rubbish that's trying to reference asp code.
 *
 */
 
/*
logo_on = new Image();
logo_on.src = "images/<%=vSiteImages%>/logo_on.gif";
logo_off = new Image();
logo_off.src = "images/<%=vSiteImages%>/logo_off.gif";

searchrentals_on = new Image();
searchrentals_on.src = "images/<%=vSiteImages%>/searchrentals_on.gif";
searchrentals_ron = new Image();
searchrentals_ron.src = "images/<%=vSiteImages%>/searchrentals_ron.gif";
searchrentals_off = new Image();
searchrentals_off.src = "images/<%=vSiteImages%>/searchrentals_off.gif";

MyAlertsAndSearches_on = new Image();
MyAlertsAndSearches_on.src = "images/<%=vSiteImages%>/MyAlertsAndSearches_on.gif";
MyAlertsAndSearches_ron = new Image();
MyAlertsAndSearches_ron.src = "images/<%=vSiteImages%>/MyAlertsAndSearches_ron.gif";
MyAlertsAndSearches_off = new Image();
MyAlertsAndSearches_off.src = "images/<%=vSiteImages%>/MyAlertsAndSearches_off.gif";

PlaceYourAd_on = new Image();
PlaceYourAd_on.src = "images/<%=vSiteImages%>/PlaceYourAd_on.gif";
PlaceYourAd_ron = new Image();
PlaceYourAd_ron.src = "images/<%=vSiteImages%>/PlaceYourAd_ron.gif";
PlaceYourAd_off = new Image();
PlaceYourAd_off.src = "images/<%=vSiteImages%>/PlaceYourAd_off.gif";

Logon_on = new Image();
Logon_on.src = "images/<%=vSiteImages%>/Logon_on.gif";
Logon_ron = new Image();
Logon_ron.src = "images/<%=vSiteImages%>/Logon_ron.gif";
Logon_off = new Image();
Logon_off.src = "images/<%=vSiteImages%>/Logon_off.gif";

AgentsAndProfessionals_on = new Image();
AgentsAndProfessionals_on.src = "images/<%=vSiteImages%>/AgentsAndProfessionals_on.gif";
AgentsAndProfessionals_ron = new Image();
AgentsAndProfessionals_ron.src = "images/<%=vSiteImages%>/AgentsAndProfessionals_ron.gif";
AgentsAndProfessionals_off = new Image();
AgentsAndProfessionals_off.src = "images/<%=vSiteImages%>/AgentsAndProfessionals_off.gif";

LandlordsAndOwners_on = new Image();
LandlordsAndOwners_on.src = "images/<%=vSiteImages%>/LandlordsAndOwners_on.gif";
LandlordsAndOwners_ron = new Image();
LandlordsAndOwners_ron.src = "images/<%=vSiteImages%>/LandlordsAndOwners_ron.gif";
LandlordsAndOwners_off = new Image();
LandlordsAndOwners_off.src = "images/<%=vSiteImages%>/LandlordsAndOwners_off.gif";

ShareAccomodation_on = new Image();
ShareAccomodation_on.src = "images/<%=vSiteImages%>/ShareAccomodation_on.gif";
ShareAccomodation_ron = new Image();
ShareAccomodation_ron.src = "images/<%=vSiteImages%>/ShareAccomodation_ron.gif";
ShareAccomodation_off = new Image();
ShareAccomodation_off.src = "images/<%=vSiteImages%>/ShareAccomodation_off.gif";

ImportantLinks_on = new Image();
ImportantLinks_on.src = "images/<%=vSiteImages%>/ImportantLinks_on.gif";
ImportantLinks_ron = new Image();
ImportantLinks_ron.src = "images/<%=vSiteImages%>/ImportantLinks_ron.gif";
ImportantLinks_off = new Image();
ImportantLinks_off.src = "images/<%=vSiteImages%>/ImportantLinks_off.gif";

AboutRent_on = new Image();
AboutRent_on.src = "images/<%=vSiteImages%>/AboutRent_on.gif";
AboutRent_ron = new Image();
AboutRent_ron.src = "images/<%=vSiteImages%>/AboutRent_ron.gif";
AboutRent_off = new Image();
AboutRent_off.src = "images/<%=vSiteImages%>/AboutRent_off.gif";

map_on = new Image();
map_on.src = "images/<%=vSiteImages%>/map_on.gif";
map_off = new Image();
map_off.src = "images/<%=vSiteImages%>/map_off.gif";

agents_on = new Image();
agents_on.src = "images/<%=vSiteImages%>/agents_on.gif";
agents_off = new Image();
agents_off.src = "images/<%=vSiteImages%>/agents_off.gif";

mem_on = new Image();
mem_on.src = "images/<%=vSiteImages%>/mem_on.gif";
mem_off = new Image();
mem_off.src = "images/<%=vSiteImages%>/mem_off.gif";

mov_on = new Image();
mov_on.src = "images/<%=vSiteImages%>/mov_on.gif";
mov_off = new Image();
mov_off.src = "images/<%=vSiteImages%>/mov_off.gif";

ts_on = new Image();
ts_on.src = "images/<%=vSiteImages%>/ts_on.gif";
ts_off = new Image();
ts_off.src = "images/<%=vSiteImages%>/ts_off.gif";

rent_on = new Image();
rent_on.src = "images/<%=vSiteImages%>/rent_on.gif";
rent_off = new Image();
rent_off.src = "images/<%=vSiteImages%>/rent_off.gif";

about_on = new Image();
about_on.src = "images/<%=vSiteImages%>/about_on.gif";
about_off = new Image();
about_off.src = "images/<%=vSiteImages%>/about_off.gif";

feedback_on = new Image();
feedback_on.src = "images/<%=vSiteImages%>/feedback_on.gif";
feedback_off = new Image();
feedback_off.src = "images/<%=vSiteImages%>/feedback_off.gif";

*/

function saveCookie(name, ivalue, bSavetoDisk)	{
	if (navigator.cookieEnabled == 0) {
		alert("You need to enable cookies for this site to work properly!");
		document.location.href = "CookieTips.asp";
	} else {
		var sCookie = document.cookie;
		if ((sCookie.length!=0) && (document.cookie.indexOf(COOKIE_USERID) > 0)) {
			document.location.href = "setTmpUser.asp?u=" + GetCookie('tmpUser')
		}else{
			DeleteCookie(name);
			var tenYrs = new Date(2015, 01, 01);
			sCookie = name + "=" + escape(ivalue) + ";path=/;"
			if (bSavetoDisk) sCookie = sCookie + "expires=" + tenYrs.toGMTString();
			document.cookie =  sCookie; 
			document.location.href = "setTmpUser.asp?u=" + GetCookie('tmpUser')
		}
	}
}

function setCookie(name)	{
	DeleteCookie('img');
	document.cookie = "img=" + escape(name) + ";path=/;";
}

function MakeCookie(name, ivalue)	{
	DeleteCookie(name);
	document.cookie = name + "=" + escape(ivalue) + ";path=/;";
}

function DeleteCookie (name) {
  if (GetCookie(name)) {
	var oldDate = new Date(1997, 7 ,27);
    document.cookie = name + "=" +
      "; expires=" + oldDate.toGMTString();
  }
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
/*
function SetImages(imgName)	{
	if (imgName==GetCookie('img')) {
		document[imgName].src = "images/<%=vSiteImages%>/" + imgName + "_on.gif";
		if ((imgName=='Logon') || (imgName=='AgentsAndProfessionals') ||
			(imgName=='LandlordsAndOwners') || (imgName=='ShareAccomodation')
			|| (imgName=='ImportantLinks')){
				document['Liner'].src = "images/<%=vSiteImages%>/1x1_green.gif";
			}else{
				document['Liner'].src = "images/<%=vSiteImages%>/1x1_blank.gif";
			}
	} else {
		document[imgName].src = "images/<%=vSiteImages%>/" + imgName + "_off.gif";
	}
}
*/
function refreshImages(sPageName) {
	sPageName=sPageName.toLowerCase();
	if ((sPageName=='/rentlogon.asp') || (sPageName=='/agentsprofessionals.asp') 
		|| (sPageName=='/landlord.asp') || (sPageName=='/shareaccomodation.asp')
		|| (sPageName=='/importantlinks.asp') || (sPageName=='/ps_main.asp')
		|| (sPageName=='/pd.asp') || (sPageName=='/member_ask.asp')
		|| (sPageName=='/member_main.asp') || (sPageName=='/agent_main.asp'))
		{
		SetImages('searchrentals');
		SetImages('PlaceYourAd');
		SetImages('Logon');
		SetImages('AgentsAndProfessionals');
		SetImages('LandlordsAndOwners');
		SetImages('ShareAccomodation');
		SetImages('ImportantLinks');
	} else { setCookie('none');}

}

function imgOn(imgName) {
        if (document.images) {            
            document[imgName].src = eval(imgName + "_on.src");			
        }
}

function imgROn(imgName) {
		var iName;
		iName=GetCookie('img');
		if (imgName!=iName) {
			if (document.images) {
				document[imgName].src = eval(imgName + "_ron.src");			
			}
		}
}

function imgOff(imgName) {
		var iName;
		iName=GetCookie('img');
		if (imgName==iName) {
			document[imgName].src = eval(imgName + "_on.src");		
		}
		else
		{
			if (document.images) {
				document[imgName].src = eval(imgName + "_off.src");		
			}
		}
}

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function


function openModalWindow(theURL, winName) {
   var options;
   options = "dialogWidth:300px;dialogHeight:200px";
   window.showModalDialog(theURL, winName, options);
 }

function openModalWindow1(theURL, winName,iwidth,iheight) {
   var options;
   options = "dialogWidth:" + iwidth + "px;dialogHeight:" + iheight + "px;scrollbars:no";
   window.showModalDialog(theURL, winName, options);
}

function openLink(theURL, winName) {
   var options;
   options = "toolbar=no,location=no, directories=no, status=yes,menubar=no,scrollbars=yes,resizable=yes,width=620,height=520";
   winhandle = window.open(theURL, winName, options);
   winhandle.onload = "window.focus()";
   winhandle.focus();
}

function openLink2(theURL, winName) {
   var options;
   options = "toolbar=no,location=no, directories=no, status=yes,menubar=no,scrollbars=yes,resizable=yes,width=630,height=520";
   winhandle = window.open(theURL, winName, options);
   winhandle.onload = "window.focus()";
   winhandle.focus();
}


function openLink3(theURL, winName) {
   var options;
   options = "toolbar=no,location=no, directories=no, status=yes,menubar=no,scrollbars=yes,resizable=yes,width=320,height=360";
   winhandle = window.open(theURL, winName, options);
   winhandle.onload = "window.focus()";
   winhandle.focus();
}

function openLink4(theURL, winName, iWidth, iHeight) {
   var options;
   options = "toolbar=no,location=no, directories=no, status=yes,menubar=no,scrollbars=no,resizable=no,width=" + iWidth + ",height=" + iHeight + ";"
   winhandle = window.open(theURL, winName, options);
   winhandle.onload = "window.focus()";
   winhandle.focus();
}

function openLink5(theURL, winName, iWidth, iHeight) {
   var options;
   options = "toolbar=no,location=no, directories=no, status=yes,menubar=no,scrollbars=yes,resizable=no,width=" + iWidth + ",height=" + iHeight + ";"
   winhandle = window.open(theURL, winName, options);
   winhandle.onload = "window.focus()";
   winhandle.focus();
}

function openerLink(theURL) {
   //window.opener.location.href=theURL;
   window.close(); 	
   winname='newW';
   options = "toolbar=no,location=yes, directories=yes, status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=600";
   winhandle = window.open(theURL, winname, options);
   winhandle.onload = "window.focus()";
   winhandle.focus();
}

function closeWin() {
  window.close();
}

function VerifyFields(f){
	var sBlankElem="", oRadioList, oCheckList;
	var sErrors= '';
	var oSetFocusTo='';

	oRadioList = new Object();
	oCheckList = new Object();

	//sErrors = CheckNonStandard();
	
	//For each element on the Form go through checking process
	for (i=0; i< f.length; i++){

		fElem = f.elements[i];
		var EName=fElem.name;
		EName=EName.toLowerCase();				
		if ((EName.substring(0, 3)=="txt") || (EName.substring(0, 3)=="sel")){EName=EName.substr(3, 30);}else{EName=fElem.name;}

		if (oRadioList[fElem.name]){continue}
		
		//If we have got to a set of radio elements validate them
		/*
		if (fElem.type=="radio") {
			//record that this radio group has been tested
			oRadioList[fElem.name] = true; 
			if (isElement(f, fElem.name + ' Radio')) {
				//If the radio hidden field is present and optional
				//workaround due to probs with optional radio groups
				if (f[fElem.name + ' Radio'].Required) {continue}
			}
			//inserted this if statement for single radio buttons .length returns undefined
			if (f[fElem.name].length > 0) {
								alert(f[fElem.name](0).Required)

				fComplete = false;
				for (radioIndex = 0; radioIndex < f[fElem.name].length  && !fComplete; radioIndex++)
				{	
					//if (f[fElem.name](radioIndex).Required)	alert(f[fElem.name](radioIndex).Required);
					fComplete |= f[fElem.name][radioIndex].checked;
				}
					
				if (!fComplete){
					if (fElem.Msg){
						sBlankElem += "      " + fElem.Msg + "\n";
					} else {
						sBlankElem += "      " + EName + "\n";
					}
					if (oSetFocusTo=='') oSetFocusTo = fElem.name
				}
				continue
			}
		}	
		*/
		
		//If we have got to a set of check box elements validate them
		/*
		if (fElem.type=="checkbox") {
			//record that this check box group has been tested
			oCheckList[fElem.name] = true; 
			if (isElement(f, fElem.name)) {
				//If the check box hidden field is present and optional
				//workaround due to probs with optional check box groups
				//if (f[fElem.name].Required) {continue}
			}
			//inserted this if statement for single check box buttons .length returns undefined
			if (f[fElem.name].length > 0) {
				fComplete = false;
				for (chkBoxIndex = 0; chkBoxIndex < f[fElem.name].length  && !fComplete; chkBoxIndex++)
				{
					fComplete |= f[fElem.name][chkBoxIndex].checked};
					if (!fComplete){
						if (fElem.Msg){
							sBlankElem += "      " + fElem.Msg + "\n";
						} else {
							sBlankElem += "      " + EName + "\n";
						}
						if (oSetFocusTo=='') oSetFocusTo = fElem.name
					}
				continue
			}else{
				if (f[fElem.name].Required) {
					fComplete = f[fElem.name].checked;
					if (!fComplete){
						if (fElem.Msg){
							sBlankElem += "      " + fElem.Msg + "\n";
						} else {
							sBlankElem += "      " + EName + "\n";
						}
						if (oSetFocusTo=='') oSetFocusTo = fElem.name
					}
				}
			}
		}	
		*/
		//If we have got a selection box
		if ((fElem.type=="select-one" || fElem.type=="select-multiple" )&& fElem.Required){
			//alert(fElem.type);	
			fComplete = false;
			//if (fElem[0].value == "" )
			//{StartAt = 1}
			//else
			//{StartAt = 0};
			StartAt = 1;
			for (itemIndex = StartAt; itemIndex < fElem.length && !fComplete; itemIndex++)
				{fComplete |= fElem[itemIndex].selected};
			if (!fComplete){
				if (fElem.Msg){
					sBlankElem += "      " + fElem.Msg + "\n";
				} else {
					sBlankElem += "      " + EName + "\n";
				}
				if (oSetFocusTo=='') oSetFocusTo = fElem;
			};
			continue;
		}	
		
		//Check to see if element is Blank
		if ( fElem.value=="" || isBlank(fElem.value)){
		    //If the element is not optional record it for validation msg
		    if (fElem.Required){				
				if (fElem.Msg){
					sBlankElem += "      " + fElem.Msg + "\n";
				} else {
					sBlankElem += "      " + EName + "\n";
				}
				if (oSetFocusTo=='') oSetFocusTo = fElem; 
			};
			continue;
		};
		
		//If the element should be numeric then validate it
		if (fElem.numeric){
			var v = parseFloat(fElem.value);
			if (isNaN(v) || fElem.value.search(/[^0-9.]/) > 1) {
			    sErrors += "- The field " + EName + " must be a number. Remove spaces and characters";
			    sErrors += ".\n";}
			    if (oSetFocusTo=='') oSetFocusTo = fElem
			else{
				if (fElem.WholePosNumber && (parseFloat(fElem.value)%1 !=0 || parseFloat(fElem.value) < 1 )){
					sErrors += "- The field " + EName + " must be a whole and positive number.\n";
					if (oSetFocusTo=='') oSetFocusTo = fElem
				}
			};
		};
		
		//If the element should be phone then validate it
		if (fElem.phone){
			var strElem="";jCounter=0;blnErr=false;
			strElem = fElem.value;
			c=strElem.split("");	
			for (jCounter=0;jCounter<c.length-1;jCounter++) {
				if ((c[jCounter]=="+") || (c[jCounter]=="-") || (c[jCounter]=="(") || (c[jCounter]==")") || (c[jCounter]==" ")) {
					blnErr=false;
				} else {							    
					if ((parseInt(c[jCounter])>=0) && (parseInt(c[jCounter])<=9)) {
						blnErr=false;
					} else {
						blnErr=true;
						break;
					}
			    }				
			};
			if (blnErr==true) {
				sErrors += "- The field " + EName + " must be a Telephone. Remove any characters other than +, -, (, ) and Spaces.\n";
				if (oSetFocusTo=='') oSetFocusTo = fElem
			}
		};

		//If the element should be an email address then validate it
		 if (fElem.Email){
			if (!isEmailAddress(fElem.value)) {
			  //  sErrors += "- The field " + EName + " must be a valid email address.\n";
				sErrors += "      You must enter a valid Email Address.\n";
			    if (oSetFocusTo=='') oSetFocusTo = fElem;
			}
		};
	};
	
	if (!sBlankElem && !sErrors){
		return true;
	}
	else{
		var sMsg; 
		sMsg = "___________________________________________________\n\n";
		sMsg += "The form was not submitted because of the following error(s).\n";
		sMsg += "Please correct these error(s) and re-submit.\n";
		sMsg += "___________________________________________________\n\n";
		if (sBlankElem){
			sMsg += "The following fields are required:\n" + sBlankElem}
		if (sErrors){
			sMsg += "These Errors were found:\n" + sErrors}
		
		//alert(sMsg.substring(0,400));
		alert(sMsg);
		eval(oSetFocusTo).focus();
		return false;
	};
}

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}

function isBlank(s){
//True if string has no word character in it [a-zA-Z0-9]
	var regNotBlank=/\w/;
	if (regNotBlank.test(s)){
		return false
	}
	else {return true}
}

function isEmailAddress(sIn) {
	return (sIn.search(/\S@\S+\.\w/) >= 0)
	//return ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(sIn)))
}

function GetSelectedComboValue(objCombo) {
	var intSelectedIndex = objCombo.options.selectedIndex;
	var intRetval = parseInt(objCombo.options[intSelectedIndex].value);
	return intRetval;
}

function isElement(f, strElemname) {
	var flength = f.length;
	for (var i=0; i<flength; i++){
		if (f.elements[i].name==strElemname) {return true;}
	}
	return false;
}
