function popFindAgent(from) {
var width=480;
var height=320;
var newWidth = ((screen.availWidth-width)/2);
var newHeight = ((screen.availHeight-height)/2);
window.open('findagentpopup.php?from='+from,'','width='+width+',height='+height+',location=0,menubar=0,scrollbars=1,status=1,toolbar=0,resizable=1,screenX='+newWidth+',screenY='+newHeight+',left='+newWidth+',top='+newHeight+'');
}

// create correct httpRequest object for the clients browser
function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

function agentSearch(postcode, from, cols)
{
   document.getElementById("agent_result").style.display = "";
   document.getElementById("agent_result").innerHTML = "Loading<blink>...</blink>";
   
   var req = createRequestObject();
   req.open("get", "agentSearchAjax.php?pcode="+postcode+"&from="+from+"&num_cols="+cols, true);
   req.onreadystatechange = function ()
   {
      if(req.readyState == 4)
      {
         document.getElementById("agent_result").innerHTML = req.responseText;
      }
   }
   req.send(null);
}

function populateAgent(data)
{
      document.getElementById("agent_id").value = data[0];
      document.getElementById("agent_name").value = data[1];
      //document.getElementById("agent_result").style.display = "none";
      //document.getElementById("agent_search").style.display = "none";
      TINY.box.hide();
}


function echeck(str) {
   var at="@"
   var dot="."
   var lat=str.indexOf(at)
   var lstr=str.length
   var ldot=str.indexOf(dot)
   if (str.indexOf(at)==-1){
      alert("Invalid E-mail Address")
      return false
   }

   if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
      alert("Invalid E-mail Address")
      return false
   }

   if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      alert("Invalid E-mail Address")
      return false
   }

   if (str.indexOf(at,(lat+1))!=-1){
      alert("Invalid E-mail Address")
      return false
   }

   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      alert("Invalid E-mail Address")
      return false
   }

   if (str.indexOf(dot,(lat+2))==-1){
      alert("Invalid E-mail Address")
      return false
   }
		
   if (str.indexOf(" ")!=-1){
      alert("Invalid E-mail Address")
      return false
   }

   return true					
}

function validateContactUs()
{
   if(document.getElementById("firstname").value == "")
   {
      alert("You must enter your name!");
      return false;
   }
   
   if(document.getElementById("phone").value == "")
   {
      alert("You must enter a phone number!");
      return false;
   }
   
   if(document.getElementById("customer_type_a").checked == false && document.getElementById("customer_type_l").checked == false)
   {
      alert("You must select either Agent or Landlord!");
      return false;
   }

   if(document.getElementById("contact_email").value == "" && document.getElementById("customer_type_l").checked)
   {
      alert("Landlords must enter and email address!");
      return false;
   }
   
   if(document.getElementById("state_sel").value == "0")
   {
      alert("You must select your state");
      return false;
   }
   
   if(document.getElementById("enquiry").value == "")
   {
      alert("You must enter an enquiry");
      return false;
   }
   
   if(echeck(document.getElementById("contact_email").value) == false && document.getElementById("customer_type_l").checked)
   {
      return false;
   }
   
   return true;
}
