﻿// JScript 文件

var CityList=function()
{
    this.provincedll;
    this.citydll;
    this.countydll;
    this.provincelbl;
    this.citylbl;
    this.countylbl;
    this.initfun;
    this.cityfun;
    this.txt;
    this.val;
    this.bo = "01";
    this.type = "01";
    this.Handler = "../Handler/Handler.ashx";
}
CityList.prototype = {
    city_init:function()
    {
        var city = this;
        city.provincedll.onchange=function()
        {
            city.provincelbl.value = city.provincedll.value;
            city.citydll.options.length = 0;
            var varItem0 = new Option(city.txt,city.val);
            city.citydll.options.add(varItem0);
            if(city.provincelbl.value != "")
            {
                city.GetCity();
            }
            city.citylbl.value = city.val;
            if(city.type == "02")
            {
                city.countydll.options.length = 0;
                var varItem1 = new Option(city.txt,city.val);
                city.countydll.options.add(varItem1);
                city.countylbl.value = city.val;
            }
        }
        city.citydll.onchange=function()
        {
            if(city.type == "02")
            {
                city.countydll.options.length = 0;
                var varItem0 = new Option(city.txt,city.val);
                city.countydll.options.add(varItem0);
                if(city.citylbl.value != "")
                {
                    city.GetCounty();
                }
                city.countylbl.value = city.val;
            }
            city.citylbl.value = city.citydll.value;
        }
        if(city.type == "02")
        {
            city.countydll.onchange=function()
            {
                city.countylbl.value = city.countydll.value;
            }
        }
        if(city.bo == "01")
        {
            city.GetProvince();
        }
        else
        {
            if(typeof city.initfun == "function")
            {
                eval("city.initfun()");
            }
        }
    },
    GetProvince:function()
    {
        var city = this;
        var url = city.Handler;
        var repurl = city.Handler + "?op=GetCityInfo&Type=1&ParentID=0&dt="+new Date();
        Request.sendGET(repurl,city.AddProvince, city.AddProvince,this);
    },
    GetCity:function()
    {
        var city = this;
        var url = city.Handler;
        var repurl = city.Handler + "?op=GetCityInfo&Type=2&ParentID="+city.provincelbl.value+"&dt="+new Date();
        Request.sendGET(repurl,city.AddCity, city.AddCity,this);
    },
    GetCounty:function()
    {
        var city = this;
        var url = city.Handler;
        var repurl = city.Handler + "?op=GetCityInfo&Type=3&ParentID="+city.citylbl.value+"&dt="+new Date();
        Request.sendGET(repurl,city.AddCounty, city.AddCounty,this);
    },
    AddProvince:function(response,obj)
    {
        var city = obj;
        city.provincedll.options.length = 0;
        var varItem0 = new Option(city.txt,city.val);
        city.provincedll.options.add(varItem0);
        var ItemList = eval(response.responseText);
        for(var i = 0;i<ItemList.length;i++){
            var item = ItemList[i];
            var varItem = new Option(item.Name,item.Code);
            city.provincedll.options.add(varItem);
        }
        if(city.bo == "01")
        {
            if(typeof city.initfun == "function")
            {
                eval("city.initfun()");
            }
        }
    },
    AddCity:function(response,obj)
    {
        var city = obj;
        city.citydll.options.length = 0;
        var varItem0 = new Option(city.txt,city.val);
        city.citydll.options.add(varItem0);
        var ItemList = eval(response.responseText);
        for(var i = 0;i<ItemList.length;i++){
            var item = ItemList[i];
            var varItem = new Option(item.Name,item.Code);
            city.citydll.options.add(varItem);
        }
        
        if(typeof city.cityfun == "function")
        {
            eval("city.cityfun()");
        }
    },
    AddCounty:function(response,obj)
    {
        var city = obj;
        city.countydll.options.length = 0;
        var varItem0 = new Option(city.txt,city.val);
        city.countydll.options.add(varItem0);
        var ItemList = eval(response.responseText);
        for(var i = 0;i<ItemList.length;i++){
            var item = ItemList[i];
            var varItem = new Option(item.Name,item.Code);
            city.countydll.options.add(varItem);
        }
    }
}


function cityonload(provincedll,citydll,countydll,provincelbl,citylbl,countylbl,txt,val,bo,type,Handler,initfun)
{
    var city = new CityList();
    city.provincedll = provincedll;
    city.citydll = citydll;
    city.countydll = countydll;
    city.provincelbl = provincelbl;
    city.citylbl = citylbl;
    city.countylbl = countylbl;
    city.txt = txt;
    city.val = val;
    city.bo = bo;
    city.type = type;
    city.initfun = initfun;
    if(Handler != null)
    {
        city.Handler = Handler;
    }
    city.city_init();
}

function selprovince(citydll,provincelbl,txt,val,Handler,cityfun)
{
    var city = new CityList();
    city.provincelbl = provincelbl;
    city.citydll = citydll;
    city.txt = txt;
    city.val = val;
    city.cityfun = cityfun;
    if(Handler != null)
    {
        city.Handler = Handler;
    }
    city.GetCity();
}


