//var http_path = location.protocol + '//' + location.host + "/homefindingcommunity/";
var http_path = location.protocol + '//' + location.host + "/";
function SelectCategory(path, type,val)
{
    if(val==1)
        temp = 1;
    
    xmlHttp=GetXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = path+"?type="+type;
    
    xmlHttp.onreadystatechange=stateChangedCat;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function SaveProperty(path, dispid)
{
    temp = 2;
    divid = dispid
    xmlHttp=GetXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = path;
    xmlHttp.onreadystatechange=stateChangedCat;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function CheckEmailExist(val, path, dispid)
{
    if((val!='')&&(val!='E-mail / Username'))
    {
        temp = 2;
        divid = dispid
        xmlHttp=GetXmlHttpObject();
        var url;
        
        if(xmlHttp==null)
        {
            alert("Your browser do not support AJAX");
            return;
        }
        url = http_path+path+val;
        xmlHttp.onreadystatechange=stateChangedCat;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }
    else{
        document.getElementById(divid).innerHTML = '';
    }
}
function ZipcheckStateCountyCity(val)
{
    if((val!='')&&(val!='Zip'))
    {
        temp = 3;
        xmlHttp=GetXmlHttpObject();
        var url;
        
        if(xmlHttp==null)
        {
            alert("Your browser do not support AJAX");
            return;
        }
        url = http_path+"common_directory/common.php?action=ZIPCHECKSTATECOUNTYCITY&zip="+val;
        xmlHttp.onreadystatechange=stateChangedCat;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }
    else{
        document.getElementById(divid).innerHTML = '';
    }
}
function SearchAdminStateCountyCity(filepath, val, extraarg, dbval, dispid)
{
    //alert(filepath+"  "+val+"  "+extraarg+"  "+dbval+"  "+dispid);
    temp = val;
    divid = dispid;
    xmlHttp=GetXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+filepath;
    if(extraarg!='')
    {
        url += "?"+extraarg+dbval;
    }
    //alert(url);
    xmlHttp.onreadystatechange=stateChangedCat;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function SearchStateCountyCityZipOnZipSelected(filepath, val, str)
{
    //alert(filepath+"  "+val+"  "+extraarg+"  "+dbval+"  "+dispid);
    temp = val;
    divid = 3;
    document.getElementById('bring_state').innerHTML = '';
    
    xmlHttp=GetXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+filepath+"?zip="+str;
    //alert(url);
    xmlHttp.onreadystatechange=stateChangedCat;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function SearchStateCountyCity(filepath, val, extraarg, dbval, dispid, cntdivid, ctdivid)
{
    //alert(filepath+"  "+val+"  "+extraarg+"  "+dbval+"  "+dispid);
    if((dbval=='')&&(cntdivid!='')&&(ctdivid!=''))
    {
        document.getElementById(cntdivid).innerHTML = '';
        document.getElementById(ctdivid).innerHTML = '';
    }
    else
        document.getElementById(ctdivid).innerHTML = '';
    
    if((dbval=='')&&(cntdivid!='')&&(ctdivid==''))
    {
        document.getElementById(cntdivid).innerHTML = '';
    }
    
    temp = val;
    divid = dispid;
    xmlHttp=GetXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+filepath;
    if(extraarg!='')
    {
        url += "?"+extraarg+dbval;
    }
    //alert(url);
    xmlHttp.onreadystatechange=stateChangedCat;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function stateChangedCat()
{
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        if(xmlHttp.status==200)
        {
            if(temp==1)
            {
                document.getElementById("disp_report_cat").innerHTML = xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
            if(temp==2)
            {
                document.getElementById(divid).innerHTML = xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
            if(temp==3)
            {
                //document.getElementById(divid).innerHTML = xmlHttp.responseText;
                responsetext = xmlHttp.responseText;
                splitedtext = responsetext.split(':');
                if(xmlHttp.responseText.length>10)
                {
                    document.getElementById('zip').value = splitedtext[0];
                    
                    document.getElementById('stid').value = splitedtext[5];
                    document.getElementById('rstname').value = splitedtext[6];
                    
                    document.getElementById('rcntname').value = splitedtext[4];
                    document.getElementById('cntid').value = splitedtext[3];
                    
                    document.getElementById('rctname').value = splitedtext[2];
                    document.getElementById('ctid').value = splitedtext[1];
                    document.getElementById('ziperror').innerHTML = "";
                }
                else{
                    document.getElementById('ziperror').innerHTML = "<b>Invalid Zipcode</b>";
                    document.getElementById('zip').value = '';
                    
                    document.getElementById('stid').value = '';
                    document.getElementById('rstname').value = 'State';
                    
                    document.getElementById('rcntname').value = 'County';
                    document.getElementById('cntid').value = '';
                    
                    document.getElementById('rctname').value = 'City';
                    document.getElementById('ctid').value = '';
                }
                temp=null;
                xmlHttp=null;
            }
        }
    }
}
 
function GetXmlHttpObject()
{
    try
    {
        //Firefox, safari ..
        xmlHttp=new XMLHttpRequest();
    }
    catch(e)
    {
        //internet explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}