
function JSHRef(page) {
	document.location="index.cfm?page="+page;
}

String.prototype.trim = function()
{  
  return( this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );   // example: str=str.trim();
}

function doQuickSearch() {
	var pObj=document.getElementById("quickSearch");
	var p=pObj.value;
	if(p.length==0) {
		alert("Please supply a search term before clicking SEARCH");
		pObj.focus();
	} else {
		document.location="index.cfm?page=search&p="+p;
	}
}

function checkForEnter(e) {
	if(e.keyCode==13) {
		doQuickSearch();
	}
}

function fpCheckPS() {
	var obj=document.getElementById("psId");
	if(obj.options[obj.selectedIndex].value==-1) {
		alert("Please choose a property status from the drop down first...");
	} else {
		document.location="index.cfm?page=buying&psId="+escape(obj.options[obj.selectedIndex].value);
	}
}

function fpCheckPT() {
	var obj=document.getElementById("ptId");
	if(obj.options[obj.selectedIndex].value==-1) {
		alert("Please choose a property type from the drop down first...");
	} else {
		document.location="index.cfm?page=buying&ptId="+escape(obj.options[obj.selectedIndex].value);
	}
}

function fpCheckPL() {
	var obj=document.getElementById("plId");
	if(obj.options[obj.selectedIndex].value==-1) {
		alert("Please choose a property location from the drop down first...");
	} else {
		document.location="index.cfm?page=buying&plId="+escape(obj.options[obj.selectedIndex].value);
	}
}

function validateMakeAppointment() {
	var validated=true;
	var errMsg="";
	var tObj;
	var tObjCount=0;
	
	var fieldArray = new Array("yourName","yourTelephone","yourEmail");

	for(i=0;i<fieldArray.length;i++) {
		if($(fieldArray[i]).value.blank()) {
			new Effect.Highlight(fieldArray[i]);
			validated=false;
		}
	}
	
	
	tObj=document.makeAppointmentForm.daysAvailable;
	
	for(i=0;i<tObj.length;i++) {
		if(tObj[i].checked) {
			tObjCount++;
		}
	}
	
	if( tObjCount==0) {
		errMsg += "\nPlease choose at least 1 day you are available for an appointment";
		validated=false;
		new Effect.Highlight("avail");
	} 
			
	if(validated) { 
		document.makeAppointmentForm.submit(); 
	} 
	
}

function validateSendEnquiry() {
	var validated=true;
	var errMsg="";
	
	var fieldArray = new Array("yourName","yourTelephone","yourEmail","yourEnquiry");

	for(i=0;i<fieldArray.length;i++) {
		if($(fieldArray[i]).value.blank()) {
			new Effect.Highlight(fieldArray[i]);
			validated=false;
		}
	}
			
	if(validated) { 
		document.sendEnquiryForm.submit(); 
	}
}

function validateEmailThisPage() {
	var validated=true;
	var errMsg="";
	
	if( document.getElementById("yourEmail").value.indexOf("@")==-1 || document.getElementById("yourEmail").value.indexOf(".")==-1 )
	{
		errMsg += "\nYour email address is invalid.";
		validated=false;
		document.getElementById("yourEmailBullet").className="formElementBulletRed";
	} else {
		document.getElementById("yourEmailBullet").className="formElementBullet";
	}
			
	if(validated) { 
		document.emailThisPageForm.submit(); 
	} else {
		alert("Please ammend the items highlighted in red and try again.\n"+errMsg);
	}
}