// JavaScript Document
function ajaxRequest(){
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"]
 if (window.ActiveXObject){ 
  for (var i=0; i<activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
   }
  }
 }
 else if (window.XMLHttpRequest) 
  return new XMLHttpRequest()
 else
  return false
}


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]+"'");
}

// Global scripts
function addToFavorite(favTitle){
  if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
    window.external.AddFavorite(location.href, unescape(favTitle));
  }
}

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) { 

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;
	}

	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";
	var mypostrequest=new ajaxRequest();
	var ptype=encodeURIComponent(enqprop);
	var bedrooms=encodeURIComponent(agentref);
	var region=encodeURIComponent(agentspropref);
	var area=encodeURIComponent(vname);
	var price=encodeURIComponent(mobile);
	var sqltxt=encodeURIComponent(email);
	var sqltxt=encodeURIComponent(telephone);
	var sqltxt=encodeURIComponent(message);
	var parameters="enqprop="+enqprop+"&agentref="+agentref+"&agentspropref="+agentspropref+"&vname="+vname+"&mobile="+mobile+"&email="+email+"&telephone="+telephone+"&message="+message;
	mypostrequest.onreadystatechange=function(){
	 if (mypostrequest.readyState==4){
		if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
		 if (mypostrequest.responseText == '') {
			 parent.location="index.asp";
			 return;
		 }
		 document.getElementById("contwaitarea").innerHTML=mypostrequest.responseText
		}
		else{
		 alert("An error has occured while trying to send your message.\n\nPlease call APP Properties for assistance.")
		}
	 }
	}
	mypostrequest.open("POST", url, true)
	mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	mypostrequest.send(parameters)
}


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 browsermessOn(elm, text) {
	 document.getElementById(elm).innerHTML=text;
}
function browsermessOff(elm, text) {
	 document.getElementById(elm).innerHTML=text;
}
