//var http_path = location.protocol + '//' + location.host + "/homefindingcommunity/";
var http_path = location.protocol + '//' + location.host + "/";
var xmlHttp = null;
var temp = null; 
function get_state(str, val)
{
    if(str == 0)
    {
        document.getElementById("bring_county").innerHTML="";
        document.getElementById("bring_city").innerHTML="";
        document.getElementById("bring_zipcode").innerHTML="";
        return false;
    }
    document.getElementById("bring_city").innerHTML = "";
    document.getElementById("bring_zipcode").innerHTML = "";
    
    temp = val;
    xmlHttp=GetXmlHttpObject();
    var url;
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"agent/select_county.php";
    url=url+"?state="+str;
    
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function get_city(str, val)
{
    if(document.getElementById("register-edit-county").value==0)
    {
        document.getElementById("bring_city").innerHTML="";
        document.getElementById("bring_zipcode").innerHTML="";
        return false;
    }

    document.getElementById("bring_zipcode").innerHTML="";
    
    temp=val;
    xmlHttp=GetXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"agent/select_city.php";
    url=url+"?county="+str;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function get_zipcode(str, val)
{
    
    if(document.getElementById("register-edit-city").value==0)
    {
        document.getElementById("bring_zipcode").innerHTML="";
        return false;
    }

    temp=val;
    xmlHttp=GetXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"agent/select_zipcode.php";
    url=url+"?city="+str;
    xmlHttp.onreadystatechange=stateChanged;    
    xmlHttp.open("GET",url,true);    
    xmlHttp.send(null);
}
function again(obj)
{
    var values=obj.split(' ');
    var temp0="state=";
    var temp1="&county=";
    var temp2="&city=";
    var temp3="&zipcode=";
    var str=temp0+values[0]+temp1+values[1]+temp2+values[2]+temp3+values[3];
    var url;
    url = http_path+"agent/selected_zip_for_edit.php?"+str;
    xmlHttp=GetXmlHttpObject();
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    temp=14;
}
function purchase_state(str, val)
{
    if(document.getElementById("edit-state").value == 0)
    {
        document.getElementById("purchase_county_label").innerHTML="";
        document.getElementById("purchase_bring_county").innerHTML="";
        document.getElementById("purchase_city_label").innerHTML="";
        document.getElementById("purchase_bring_city").innerHTML="";
        return false;
    }
    document.getElementById("purchase_city_label").innerHTML = "";
    document.getElementById("purchase_bring_city").innerHTML = "";
    
    temp = val;
    xmlHttp=GetXmlHttpObject();
    var url;
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"agent/purchase_select_county.php";
    url=url+"?state="+str;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function purchase_city(str, val)
{
    if(document.getElementById("edit-county").value==0)
    {
        document.getElementById("purchase_city_label").innerHTML="";
        document.getElementById("purchase_bring_city").innerHTML="";
        return false;
    }
    
    temp=val;
    xmlHttp=GetXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"agent/purchase_select_city.php";
    url=url+"?county="+str;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function GetAvailableCity(ctval)
{
    temp = 18;
    xmlHttp=GetXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"agent/CheckAvailableCity.php";
    url=url+"?ctid="+ctval;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function AjaxPurchaseState(str, val)
{
    if(document.getElementById("ajax-edit-state").value == 0)
    {
        document.getElementById("purchase_county_label").innerHTML="";
        document.getElementById("purchase_bring_county").innerHTML="";
        document.getElementById("purchase_city_label").innerHTML="";
        document.getElementById("purchase_bring_city").innerHTML="";
        return false;
    }
    document.getElementById("purchase_city_label").innerHTML = "";
    document.getElementById("purchase_bring_city").innerHTML = "";
    
    temp = val;
    xmlHttp=GetXmlHttpObject();
    var url;
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"agent/purchase_select_county2.php";
    url=url+"?state="+str;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function AjaxPurchaseCity(str, val)
{
    if(document.getElementById("ajax-edit-county").value==0)
    {
        document.getElementById("purchase_city_label").innerHTML="";
        document.getElementById("purchase_bring_city").innerHTML="";
        return false;
    }
    
    temp=val;
    xmlHttp=GetXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"agent/purchase_select_city2.php";
    url=url+"?county="+str;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function AddAvailableCity(btnval, ctval)
{
    temp = 19;
    xmlHttp=GetXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"agent/AddAvailableCity.php";
    url=url+"?Payment="+btnval+"&ctid="+ctval;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function stateChanged()
{
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        if(xmlHttp.status==200)
        {
            if(temp==1)
            {
                document.getElementById("bring_county").innerHTML=xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
            if(temp==2)
            {
                document.getElementById("bring_city").innerHTML=xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
            if(temp==3)
            {
                document.getElementById("bring_zipcode").innerHTML=xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
            if(temp==11)
            {
                document.getElementById("purchase_county").style.padding = "15px 0px 0px 0px";
                document.getElementById("purchase_county_label").innerHTML="County <span class='form-required'>*</span>";
                document.getElementById("purchase_bring_county").innerHTML=xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
            if(temp==12)
            {
                document.getElementById("purchase_city").style.padding = "15px 0px 0px 0px";
                document.getElementById("purchase_city_label").innerHTML="City <span class='form-required'>*</span>";
                document.getElementById("purchase_bring_city").innerHTML=xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
            if(temp==14)
            {
                var var1=xmlHttp.responseText;
                var values=var1.split("<select");
                var xml0="<select "+values[1];
                var xml1="<select "+values[2];
                var xml2="<select "+values[3];
                var xml3="<select "+values[4];
                
                document.getElementById("bring_state").innerHTML = xml0;
                document.getElementById("bring_county").innerHTML = xml1;
                document.getElementById("bring_city").innerHTML = xml2;
                document.getElementById("bring_zipcode").innerHTML = xml3;
            }
            if(temp==18)
            {
                document.getElementById("purchase_msg").innerHTML=xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
            if(temp==19)
            {
                document.getElementById("user_selected_city").innerHTML=xmlHttp.responseText;
                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;
}