var xmlHttp;
var strQuery;

function ajaxFunction()
{
  var strQuery="" ;
  var sUrl     ;

  xmlHttp=GetXmlHttpObject() ;
  if (xmlHttp==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  }

  xmlHttp.onreadystatechange=stateChanged ;

  strQuery=loadparams() ;
  sUrl=("includes/countlistings.php" + strQuery) ;
  xmlHttp.open("GET",sUrl,true);

  xmlHttp.send(null);
}

function stateChanged()
{
  if(xmlHttp.readyState==4)
  {
    var oCountField;
    oCountField=document.getElementById("ListingCount")
    if (oCountField!=null)
    {
        oCountField.innerHTML=xmlHttp.responseText;
    }
  }
}


function loadparams()
{
    var sParams = "?agencyid="
    var oFeatured  = document.getElementById("searchfeatured") ;
    var oAgency  = document.getElementById("agency") ;
    var oCity    = document.getElementById("city") ;
    var oCounty  = document.getElementById("county") ;
    var oZipcode = document.getElementById("zipcode") ;
    var oPrice   = document.getElementById("price") ;
    var oPropCls = document.getElementById("propertytype") ;
    var oSchool  = document.getElementById("school") ;
    var oBdrms   = document.getElementById("bedrooms") ;
    var oBthrms  = document.getElementById("bathrooms") ;
    var oSqFt    = document.getElementById("sqft") ;
    var oAcres   = document.getElementById("acres") ;
	var oAid   = document.getElementById("aid") ;
    var osearchfeatured = document.getElementById("searchfeatured") ;
    var oCountField=oCountField=document.getElementById("ListingCount") ;
    if (oCountField!=null){
     oCountField.innerHTML="Estimating Listings...";
    }

    if (oAgency!=null){
        sParams = (sParams + oAgency.value)
    }
    if (oFeatured!=null){
        if (oFeatured.checked == "1") {
            sParams = (sParams + "&searchfeatured=yes");
        }
    }
    if (oCity!=null){
        if (oCity.value!="" && oCity.value!="any") {
            sParams = (sParams + "&city=" + oCity.value);
        }
    }
    if (oCounty!=null){
        if (oCounty.value!="" && oCounty.value!="any") {
            sParams = (sParams + "&county=" + oCounty.value);
        }
    }
    if (oZipcode!=null){
        if (oZipcode.value!="" && oZipcode.value!="any") {
            sParams = (sParams + "&zipcode=" + oZipcode.value);
        }
    }
    if (oPrice!=null){
        if (oPrice.value!="" && oPrice.value!="any") {
            sParams = (sParams + "&price=" + oPrice.value) ;
        }
    }
    if (oPropCls!=null){
        if (oPropCls.value!="" && oPropCls.value!="any") {
            sParams = (sParams + "&propertytype=" + oPropCls.value) ;
        }
    }
    if (oSchool!=null){
        if (oSchool.value!="" && oSchool.value!="any") {
            sParams = (sParams + "&school=" + oSchool.value)  ;
        }
    }
    if (oBdrms!=null){
        if (oBdrms.value!="" && oBdrms.value!="any") {
            sParams = (sParams + "&bedrooms=" + oBdrms.value) ;
        }
    }
    if (oBthrms!=null){
        if (oBthrms.value!="" && oBthrms.value!="any") {
            sParams = (sParams + "&bathrooms=" + oBthrms.value) ;
        }
    }
    if (oSqFt!=null){
        if (oSqFt.value!="" && oSqFt.value!="any") {
            sParams = (sParams + "&sqft=" + oSqFt.value)  ;
        }
    }
    if (oAcres!=null){
        if (oAcres.value!="" && oAcres.value!="any") {
            sParams = (sParams + "&acres=" + oAcres.value) ;
        }
    }
    if (osearchfeatured!=null){
        if (osearchfeatured.value!="" && osearchfeatured.value!="no") {
            sParams = (sParams + "&searchfeatured=" + osearchfeatured.value) ;
        }
    }
	    if (oAid!=null){
        if (oAid.value!="" && oAid.value!="any") {
            sParams = (sParams + "&aid=" + oAid.value);
        }
    }
return sParams ;
}

function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
return xmlHttp;
}

