var xmlHttp;

function init()
{
	showTown();
}

function GetXmlHttpObject(handler)
{ 
  var objXmlHttp=null;
  
  if (navigator.userAgent.indexOf("Opera")>=0) {
    alert("This example doesn't work in Opera");
    return; 
  }
  if (navigator.userAgent.indexOf("MSIE")>=0)
  { 
    //alert("IS IE");
		var strName="Msxml2.XMLHTTP";
    if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
      strName="Microsoft.XMLHTTP";
    } 
    try { 
      objXmlHttp=new ActiveXObject(strName);
      objXmlHttp.onreadystatechange=handler; 
      return objXmlHttp;
    } 
    catch(e)
    { 
      alert("Error. Scripting for ActiveX might be disabled");
			return; 
    } 
	} 
  if (navigator.userAgent.indexOf("Mozilla")>=0) {
    //alert("IS MOZILLA");
		objXmlHttp=new XMLHttpRequest();
    objXmlHttp.onload=handler;
    objXmlHttp.onerror=handler; 
    return objXmlHttp;
  }
}

function stateChanged() 
{ 
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
    document.getElementById("town").innerHTML=xmlHttp.responseText; 
		document.getElementById("loading").style.display="none";
  } 
} 

function showTown()
{
     var cnty = document.getElementById("county").options[document.getElementById("county").selectedIndex].value;
     var type = document.getElementById("propType").options[document.getElementById("propType").selectedIndex].value;
	if (type != "0" && cnty != "") { 
       	var url="/gsmls/hub.cfm?county=" + cnty + "&table=" + type + "&function=getTowns";
       	document.getElementById("loading").style.display="block";
		xmlHttp=GetXmlHttpObject(stateChanged);
          xmlHttp.open("GET", url , true);
          xmlHttp.send(null);
	}
	else {
          document.getElementById("town").innerHTML="";
	}
}

function changePrice(val)
{
  if (val == "Rental") {
	  document.getElementById("maxprice").selectedIndex = 49;
	  document.getElementById("minprice").selectedIndex = 55;
	}
	else {
	  document.getElementById("maxprice").selectedIndex = 27;
	  document.getElementById("minprice").selectedIndex = 30;
	}
}

function validate(form)
{
  var townSelect = form.townSelect;
	
	if (townSelect.selectedIndex == -1) {
	  alert("You must select at least one town.");
		return false;
	}
	
	//alert("OK");
	return true;
}
document.body.onload = function () {
     if (document.getElementById("county").value != "") {
          showTown();
     }
};
