var files = "/public/inc/select.aspx";
var files4 = "/public/inc/select4.aspx";
var sResult = "";

var Ares =
{
    getprovince : function()
    {
    alert(files);
    return;
        var strUrl = files + "?s=1";
        _sendx(strUrl, function(friendprovince, sResult)
        {
            if(Ares.appendOption("friendprovince", sResult))
            {
                Ares.getcity();
            }
            sResult = "";
        }
        , null);
    }
    ,
    getcity : function()
    {
        $("provinces").value = $("friendprovince").options[$("friendprovince").selectedIndex].text;
        var p = $("friendprovince").options[$("friendprovince").selectedIndex].value;
        if(p == "所有省份")
        {
            Ares.appendOption("friendcity", "||");
            Ares.getcitys();
        }
        else
        {
            var strUrl = files + "?s=2&p=" + escape(p);
            _sendx(strUrl, function(friendcity, sResult)
            {
                Ares.appendOption("friendcity", sResult);
                sResult = "";
                Ares.getcitys();
            }
            , null);
        }
        
    }
    ,
    getcitys : function()
    {
        $("citys").value = $("friendcity").options[$("friendcity").selectedIndex].text;
    }
    ,
    appendOption : function(sId, Value)
    {
        try
        {
            var sValues = Value.split('|');
            var sValue = sValues[0].split(',');
            var sText = sValues[1].split(',');
            var temps = "";
            $(sId).options.length = 0
            switch(sId)
            {
                case "friendprovince" :
                    temps = "所有省份";
                    break;
                case "friendcity" :
                    temps = "所有城市";
                    break;
            }
            $(sId).options.add(new Option(temps, temps));
            var itemp = 1;
            if(Value.length > 2)
            {
                itemp = 0;
            }
            for(var i = itemp; i < sValue.length ; i ++ )
            {
                $(sId).options.add(new Option(sText[i], sValue[i]));
                if(provinces && citys && (sText[i] == provinces || sText[i] == citys))
                {
                    $(sId).options[i + 1].selected = true;
                }
            }
        }
        catch(e)
        {
            return false;
            // alert(e.description);
        }
        return true;
    }
}
;

var homeAres =
{
    getprovince : function()
    {
        var strUrl = files + "?s=1";
        _sendx(strUrl, function(friendprovince, sResult)
        {
            if(homeAres.appendOption("homeprovince", sResult))
            {
                homeAres.getcity();
            }
            sResult = "";
        }
        , null);
    }
    ,
    getcity : function()
    {
        $("province").value = $("homeprovince").options[$("homeprovince").selectedIndex].text;
        var p = $("homeprovince").options[$("homeprovince").selectedIndex].value;
        if(p == "所有省份")
        {
            homeAres.appendOption("homecity", "||");
            homeAres.getcitys();
        }
        else
        {
            var strUrl = files + "?s=2&p=" + escape(p);
            _sendx(strUrl, function(homecity, sResult)
            {
                homeAres.appendOption("homecity", sResult);
                sResult = "";
                homeAres.getcitys();
            }
            , null);
        }
    }
    ,
    getcitys : function()
    {
        $("city").value = $("homecity").options[$("homecity").selectedIndex].text;
    }
    ,
    appendOption : function(sId, Value)
    {
        try
        {
            var sValues = Value.split('|');
            var sValue = sValues[0].split(',');
            var sText = sValues[1].split(',');
            var temps = "";
            $(sId).options.length = 0
            switch(sId)
            {
                case "homeprovince" :
                    temps = "所有省份";
                    break;
                case "homecity" :
                    temps = "所有城市";
                    break;
            }
            $(sId).options.add(new Option(temps, temps));
            var itemp = 1;
            if(Value.length > 2)
            {
                itemp = 0;
            }
            
            for(var i = itemp; i < sValue.length ; i ++ )
            {
                $(sId).options.add(new Option(sText[i], sValue[i]));

            }
        }
        catch(e)
        {
            return false;
            // alert(e.description);
        }
        return true;
    }
}
;

var Areas =
{
    getprovince : function()
    {
        $("province").value = "";
        var strUrl = files4 + "?s=1";
        _sendx(strUrl, function(province, sResult)
        {
            if(Areas.appendOption("homeprovince", sResult))
            {
                Areas.getcity();
            }
            sResult = "";
        }
        , null);
    }
    ,
    getcity : function()
    {
        $("province").value = $("homeprovince").options[$("homeprovince").selectedIndex].text;
        var p = $("homeprovince").options[$("homeprovince").selectedIndex].value;
        if(p == "所有省份")
        {
            if(Areas.appendOption("homecity", "||"))
            {
                Areas.getcounty();
            }
        }
        else
        {
            var strUrl = files4 + "?s=2&p=" + escape(p);
            _sendx(strUrl, function(city, sResult)
            {
                if(Areas.appendOption("homecity", sResult))
                {
                    Areas.getcounty();
                }
                sResult = "";
            }
            , null);
        }
    }
    ,
    getcounty : function()
    {
        $("city").value = $("homecity").options[$("homecity").selectedIndex].text;
        var c = $("homecity").options[$("homecity").selectedIndex].value;
        if(c == "所有城市")
        {
            if(Areas.appendOption("homecounty", "||"))
            {
                Areas.getsanjak();
            }
        }
        else
        {
            var strUrl = files4 + "?s=3&c=" + escape(c);
            _sendx(strUrl, function(county, sResult)
            {
                if(Areas.appendOption("homecounty", sResult))
                {
                    Areas.getsanjak();
                }
                sResult = "";
            }
            , null);
        }
    }
    ,
    getsanjak : function()
    {
        $("county").value = $("homecounty").options[$("homecounty").selectedIndex].text;
        var o = $("homecounty").options[$("homecounty").selectedIndex].value;
        if(o == "所有县区" && sanjak == "")
        {
            Areas.appendOption("homesanjak", "||");
            Areas.getsanjakValue();
        }
        else
        {
            var strUrl = files4 + "?s=4&o=" + escape(o);
            _sendx(strUrl, function(county, sResult)
            {
                Areas.appendOption("homesanjak", sResult);
                sResult = "";
                Areas.getsanjakValue();
            }
            , null);
        }
        
    }
    ,
    getsanjakValue : function()
    {
        $("sanjak").value = $("homesanjak").options[$("homesanjak").selectedIndex].text;
        province = "";
        city = "";
        county = "";
        sanjak = "";
    }
    ,
    appendOption : function(sId, Value)
    {
        try
        {
            var sValues = Value.split('|');
            var sValue = sValues[0].split(',');
            var sText = sValues[1].split(',');
            var sAbc = sValues[2].split(',');
            var temps = "";
            $(sId).options.length = 0
            switch(sId)
            {
                case "homeprovince" :
                    temps = "所有省份";
                    break;
                case "homecity" :
                    temps = "所有城市";
                    break;
                case "homecounty" :
                    temps = "所有县区";
                    break;
                case "homesanjak" :
                    temps = "所有小区";
                    break;
            }
            $(sId).options.add(new Option(temps, temps));
            var itemp = 1;
            if(Value.length > 2)
            {
                itemp = 0;
            }
            for(var i = itemp; i < sValue.length ; i ++ )
            {
                $(sId).options.add(new Option(sAbc[i] + "." + sText[i], sValue[i]));
                if(sText[i] == province || sText[i] == city || sText[i] == county || sText[i] == sanjak)
                {
                    $(sId).options[i + 1].selected = true;
                }
            }
            //alert($(sId).options.selectedIndex);
        }
        catch(e)
        {
            return false;
            // alert(e.description);
        }
        return true;
    }
}
;