// JavaScript Document

function ismaxChrs(obj){
var  mChrs=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length > 0) {
		if (obj.value.length > mChrs) {
			obj.value = obj.value.substr(0, mChrs);
		}
	}
}

function alltrim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, "");
   if (temp == " ") { temp = ""; }
   return temp;
}


function changecoloron(eltochange)
{
	document.getElementById(eltochange).className="inputrowreq";
	
}

function changecoloroff(eltochange)
{
	document.getElementById(eltochange).className="formlabel";
	
}

// send the mail
function sendMessage(enqprop, agentref, agentspropref, vname, mobile, email, telephone, message) { 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
		{
		alert ("Your browser does not support AJAX!");
		return;
		} 
	var errors = '';
	var contactdetails = mobile + telephone + email;

	if (alltrim(vname) == "") {
		document.getElementById('tdvname').className="inputrowreqmissing";
		errors = errors + "Please tell us your name\n\n";
	}

	if (alltrim(contactdetails) == "") {
		document.getElementById('tdmobile').className="inputrowreqmissing";
		document.getElementById('tdtelephone').className="inputrowreqmissing";
		document.getElementById('tdemail').className="inputrowreqmissing";
		errors = errors + "Please give us some contact details, thankyou.";
	}

	if (errors) {
	alert( errors);
	return;
	}
	else {
	document.getElementById("contmessagearea").innerHTML="Please wait while we send your message";
	document.getElementById("contwaitarea").innerHTML = "<img src='images/pleasewait.gif' width='140' height='16'>"
	}


var url="enqresp.asp";
url=url+"?enqprop="+enqprop+"&agentref="+agentref+"&agentspropref="+agentspropref+"&vname="+vname+"&mobile="+mobile+"&email="+email+"&telephone="+telephone+"&message="+message;

url=url+"&sid="+Math.random();
url = encodeURI(url);
xmlHttp.onreadystatechange=stateChangedM;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);


}

function stateChangedM() 
{ 


if (xmlHttp.readyState==4)
{ 
	if(document.getElementById("contmessagearea")) {
		document.getElementById("contmessagearea").innerHTML=xmlHttp.responseText;
		document.getElementById("contwaitarea").innerHTML = "&nbsp;"
	}

}
}


// send the mail
function findHome(pbuy, pname, pmobile, ptelephone, pemail, ptype, parea, pbudget, pmortgage, pbedrooms, ppool, pgarage, pmessage) { 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
		{
		alert ("Your browser does not support AJAX!");
		return;
		} 
	var errors = '';
	var contactdetails = pmobile + ptelephone + pemail;

	if (alltrim(pname) == "") {
		document.getElementById('tdpname').className="inputrowreqmissing";
		errors = errors + "Please tell us your name\n\n";
	}

	if (alltrim(contactdetails) == "") {
		document.getElementById('tdpmobile').className="inputrowreqmissing";
		document.getElementById('tdptelephone').className="inputrowreqmissing";
		document.getElementById('tdpemail').className="inputrowreqmissing";
		errors = errors + "Please give us some contact details, thankyou.";
	}

	if (errors) {
	alert( errors);
	return;
	}
	else {
	document.getElementById("contmessagearea").innerHTML="Please wait while we send your message";
	document.getElementById("contwaitarea").innerHTML = "<img src='images/pleasewait.gif' width='140' height='16'>"
	}


var url="findhome.asp";
url=url+"?pname="+pname+"&pmobile="+pmobile+"&ptelephone="+ptelephone+"&pemail="+pemail+"&ptype="+ptype+"&parea="+parea+"&pbudget="+pbudget+"&pmortgage="+pmortgage+"&pbedrooms="+pbedrooms+"&ppool="+ppool+"&pgarage="+pgarage+"&pmessage="+pmessage+"&pbuy="+pbuy;

url=url+"&sid="+Math.random();
url = encodeURI(url);
xmlHttp.onreadystatechange=stateChangedP;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);


}

function stateChangedP() 
{ 


if (xmlHttp.readyState==4)
{ 
	if(document.getElementById("contmessagearea")) {
		document.getElementById("contmessagearea").innerHTML=xmlHttp.responseText;
		document.getElementById("contwaitarea").innerHTML = "&nbsp;"
	}

}
}



// Global scripts
function addToFavorite(favTitle){
  if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
    window.external.AddFavorite(location.href, unescape(favTitle));
  }
}


function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

