// Global identifier
function $(id)
{
    if (document.getElementById != null) {
        return document.getElementById(id);
    }
    if (document.all != null) {
        return document.all[id];
    }
    if (document.layers[id] != null) {
        return document.layers[id];
    }
    return null;
}
// XMLHTTP Request Initializer
function GetXmlHttpObject(handler)
{ 
    var objXmlHttp=null;
    if (navigator.userAgent.indexOf("Opera")>=0) {
        alert("This page doesn't work in Opera");
        return;
    }
    if (navigator.userAgent.indexOf("MSIE")>=0) {
        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) {
        objXmlHttp=new XMLHttpRequest();
        objXmlHttp.onload=handler;
        objXmlHttp.onerror=handler;
        return objXmlHttp;
    }
}
// Excecute an XMLHTTP request to a ColdFusion page to check the referrer
function checkReferrer(id)
{
    var url="checkAuthUrl.cfm?r="+encodeURI(document.referrer)+"&n="+id; // URL of ColdFusion file
    //window.location.href = url;
    var handler=function() {
        if (xmlHttp.readyState == 'complete' || xmlHttp.readyState == 4) {
            // Execute the following when the ColdFusion file is finished processing
            var resp = xmlHttp.responseText;
            if (resp == "false") {
                window.location.href="http://idxlistings.com/error.cfm";
            }
        }
    }
    var xmlHttp = GetXmlHttpObject(handler);
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}
function jsCheck()
{
    $('js').value = "on";
}
function validate(form)
{
    //alert(form.town.selectedIndex);
    if (form.town.selectedIndex == -1) {
        alert("Please select at least one town.");
        return false;
    }
    // Javascript needs to work with smaller numbers
    var minprice = form.minprice.options[form.minprice.selectedIndex].value / 100;
    var maxprice = form.maxprice.options[form.maxprice.selectedIndex].value / 100;
    //alert(form.minprice.options[form.minprice.selectedIndex].value+" >= "+form.maxprice.options[form.maxprice.selectedIndex].value);
    if (minprice >= maxprice) {
        alert("Your minimum price ("+form.minprice.options[form.minprice.selectedIndex].value+") cannot be greater than your maximum price ("+form.maxprice.options[form.maxprice.selectedIndex].value+").");
        return false;
    }
     if (form.Cat.length != undefined) {
          var stopFlag = true;
          for (var x=0;x<form.Cat.length;x++) {
               if (form.Cat[x].checked == true) {
                    stopFlag = false;
               }
          }
          if (stopFlag) {
               alert("Please select at least one property type.");
               return false;
          }
     }
     else {
          if (form.Cat.checked == false) {
               alert("You must select a property type.");
               return false;
          }
     }
    return true;
}

