//var http_path = location.protocol + '//' + location.host + "/homefindingcommunity/";
var http_path = location.protocol + '//' + location.host + "/";
var xmlHttp = null;
var temp = null; 
function search_county(str, val)
{
    if(document.getElementById("edit-state").value == 0)
    {
        document.getElementById("search_county").innerHTML="";
        document.getElementById("search_city").innerHTML="";
        return false;
    }
    document.getElementById("search_city").innerHTML = "";
    
    temp = val;
    xmlHttp=GetSearchXmlHttpObject();
    var url;
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"search/search_county.php";
    url=url+"?state="+str+"&change=TRUE";
    xmlHttp.onreadystatechange=stateChangedSearch;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function search_city(str, val)
{
    if(document.getElementById("edit-county").value==0)
    {
        document.getElementById("search_city").innerHTML="";
        return false;
    }
    temp=val;
    xmlHttp=GetSearchXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"search/search_city.php";
    url=url+"?county="+str+"&change=TRUE";
    xmlHttp.onreadystatechange=stateChangedSearch;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function get_citypage(str)
{
    if(str)
    {
        window.location = http_path+"city.php?ctid="+str;
    }
}
function middle_side_city_function(itemLink,val)
{
    document.getElementById("middle_side_city_div").innerHTML = "";
    temp=val;
    xmlHttp = GetSearchXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"search/result_location_search.php";
    url = url+"?from_page=flight&from_text=middle_point&from_point="+itemLink;
    xmlHttp.onreadystatechange=stateChangedSearch;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function county_search(str, val)
{
    if(document.getElementById("quick-edit-state").value==0)
    {
        document.getElementById("search_county").innerHTML="";
        document.getElementById("search_city").innerHTML="";
        return false;
    }
    document.getElementById("search_city").innerHTML="";
    temp=val;
    xmlHttp=GetSearchXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"county_include/search_county.php";
    url=url+"?state="+str+"&change=TRUE";
    xmlHttp.onreadystatechange=stateChangedSearch;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function city_search(str, val)
{
    if(document.getElementById("quick-search-county").value==0)
    {
        document.getElementById("search_city").innerHTML="";
        return false;
    }
    temp=val;
    xmlHttp=GetSearchXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"county_include/search_city.php";
    url=url+"?county="+str+"&change=TRUE";
    xmlHttp.onreadystatechange=stateChangedSearch;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function search_btn(str)
{
    if(document.getElementById("quick-search-city").value > 0)
    {
        document.getElementById("search_btn").innerHTML = "<img src='"+http_path+"images/search_btn.png' class='hand' onclick=\"document.quick_search.submit()\" alt='' />";
    }
}

function search_county2(str, val)
{
    if(document.getElementById("edit-state2").value == 0)
    {
        document.getElementById("search_county2").innerHTML="";
        document.getElementById("search_city2").innerHTML="";
        return false;
    }
    document.getElementById("search_city2").innerHTML = "";
    
    temp = val;
    xmlHttp=GetSearchXmlHttpObject();
    var url;
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"agent_dir/search_county2.php";
    url=url+"?state2="+str+"&change=TRUE";
    xmlHttp.onreadystatechange=stateChangedSearch;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function search_city2(str, val)
{
    if(document.getElementById("edit-county2").value==0)
    {
        document.getElementById("search_city2").innerHTML="";
        return false;
    }
    temp=val;
    xmlHttp=GetSearchXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"agent_dir/search_city2.php";
    url=url+"?county2="+str+"&change=TRUE";
    xmlHttp.onreadystatechange=stateChangedSearch;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function map_search_county(str, val)
{
    if((document.getElementById("map-edit-state").value == 0)||(document.getElementById("map-edit-state").value == 'Select State'))
    {
        document.getElementById("map_select_county").innerHTML="";
        document.getElementById("map_select_city").innerHTML="";
        return false;
    }
    document.getElementById("map_select_city").innerHTML = "";
    
    temp = val;
    xmlHttp=GetSearchXmlHttpObject();
    var url;
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"home_include/search_county.php";
    url=url+"?state="+str+"&change=TRUE";
    xmlHttp.onreadystatechange=stateChangedSearch;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function map_search_city(str, val)
{
    if((document.getElementById("map-edit-county").value==0)||(document.getElementById("map-edit-county").value=='Select County'))
    {
        document.getElementById("map_select_city").innerHTML="";
        return false;
    }
    temp=val;
    xmlHttp=GetSearchXmlHttpObject();
    var url;
    
    if(xmlHttp==null)
    {
        alert("Your browser do not support AJAX");
        return;
    }
    url = http_path+"home_include/search_city.php";
    url=url+"?county="+str+"&change=TRUE";
    xmlHttp.onreadystatechange=stateChangedSearch;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}
function createurl()
{
    if((document.getElementById("map-edit-city").value!=0)||(document.getElementById("map-edit-city").value!='Select City'))
    {
        var statetxt = document.getElementById("map-edit-state").options[document.getElementById("map-edit-state").selectedIndex].text;
        var stateurltxt = statetxt.split(' ').join('_');
        var sturl = http_path+"city.php?state="+stateurltxt;
        
        var countytxt = document.getElementById("map-edit-county").options[document.getElementById("map-edit-county").selectedIndex].text;
        var countyurltxt = countytxt.split(' ').join('_');
        var countyurl = sturl+"&county="+countyurltxt;
        
        var citytxt = document.getElementById("map-edit-city").options[document.getElementById("map-edit-city").selectedIndex].text;
        var cityurltxt = citytxt.split(' ').join('_');
        var cityurl = countyurl+"&city="+cityurltxt;
        
        document.getElementById("home-map-form").action = cityurl;
    }
}
function stateChangedSearch()
{
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        if(xmlHttp.status==200)
        {
            if(temp==19)
            {   
                document.getElementById("search_county").innerHTML=xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
            if(temp==20)
            {   
                document.getElementById("search_county2").innerHTML=xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
            if(temp==21)
            {
                document.getElementById("search_city").innerHTML=xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
            if(temp==22)
            {
                document.getElementById("search_city2").innerHTML=xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
            if(temp==29)
            {
                document.getElementById("map_select_county").innerHTML = xmlHttp.responseText;
                var statetxt = document.getElementById("map-edit-state").options[document.getElementById("map-edit-state").selectedIndex].text;
                var stateurltxt = statetxt.split(' ').join('_');
                
                document.getElementById("home-map-form").action = http_path+"state.php?state="+stateurltxt;
                temp=null;
                xmlHttp=null;
            }
            if(temp==30)
            {
                document.getElementById("map_select_city").innerHTML=xmlHttp.responseText;
                var statetxt = document.getElementById("map-edit-state").options[document.getElementById("map-edit-state").selectedIndex].text;
                var stateurltxt = statetxt.split(' ').join('_');
                var sturl = http_path+"county.php?state="+stateurltxt;
                
                var countytxt = document.getElementById("map-edit-county").options[document.getElementById("map-edit-county").selectedIndex].text;
                var countyurltxt = countytxt.split(' ').join('_');
                var countyurl = sturl+"&county="+countyurltxt;
                
                document.getElementById("home-map-form").action = countyurl;
                temp=null;
                xmlHttp=null;
            }
            if(temp==40)
            {
                document.getElementById("search_county").innerHTML=xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
            if(temp==41)
            {
                document.getElementById("search_city").innerHTML=xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
            if(temp==51)
            {
                document.getElementById("middle_side_city_div").innerHTML=xmlHttp.responseText;
                temp=null;
                xmlHttp=null;
            }
        }
    }
}
 
function GetSearchXmlHttpObject()
{
    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;
}