Namespace.register("U.City"); //命名空间
window.onload = U.City.load = function () {

    U.CD.Init(); //初始化跨域文件
    //其他初始化写在下面
    //U.ACD.Request(U.CD.AjaxUrl, ([U.CD.Host, U.CD.Database, "UC_S_Select_Sta", '0']), U.Exam.aa_asyn, (["", "bb"]));
    //---------------------------db 为数据库名字, r为 存储过程函数， val为该存储过程的参数 若没有参数可以不传 若有多个参数采用数组的方法，
    //-----------------------------------------------------------------------------------例如传入 [a,b] 查看下面 div文本为北京的元素
    U.City($("#aa")[0], $("#qq")[0]);     //第一个参数是作为 放入哪个元素下 //第二个参数是元素点击提交数据
    U.School($("#aa")[0]);
}
U.City.first = function (Host, db) {
    U.CD.Host = Host;           //需要更换数据库host，在这里更换
    U.CD.Database = db; //需要更换数据库名字，在这里更换
}
U.CD.AsynJWH = function () { }
//-------------------------------------------------------------选择地区---------------------------------------------------------------
U.City = function (Udiv, Uit) {     //第一个参数为 放入哪个ID里面，   第二个参数为 onclick事件获取已选择的数据
    var _UT = new U.CityT(Udiv, Uit);
    _UT.init();
    return _UT;
}
U.CityT = function (Udiv, Uit) {    //定义初始化值
    this.Udiv = Udiv;
    this.Uit = Uit;
}
U.CityT.prototype = {
    init: function () {      //初始化
        this.sumbit(this.Uit);
        this.Odiv();
    },
    Odiv: function () {
        var U_C_Out = $$("div", { "id": "U_C_Out", "className": "U_C_Out" }, this.Udiv);
        var U_C_O_L = $$("div", { "id": "U_C_O_L", "className": "U_C_O_L U_C_left", "innerHTML": "详细地址:" }, U_C_Out);
        var U_C_O_R = $$("div", { "id": "U_C_O_R", "className": "U_C_O_R U_C_right" }, U_C_Out);
        var U_C_O_C = $$("div", { "id": "U_C_O_C", "className": "U_C_O_C U_C_left", "innerHTML": "完善资料，让大家更了解你" }, U_C_O_R);
        var U_C_O_R_D = $$("div", { "id": "U_C_O_R_D", "className": "U_C_O_R_T U_C_right", "innerHTML": "编辑", "onclick": [[this.view, ([this])]] }, U_C_O_R);
    },
    view: function (_this) {         //加载视图      整个选择地区的视图
        //一系列的生成
        var U_C_Out = $("#U_C_Out").animate({ "height": "150px" }, 200);
        var U_C_O_R = $("#U_C_O_R")[0];
        var U_C_Content = $$("div", { "id": "U_C_Content", "style": { "margin-top": "30px"} }, U_C_Out);
        $("#U_C_O_R_D")[0].style.display = "none";
        $("#U_C_O_C")[0].style.display = "none";
        $$("div", { "id": "U_C_O_R_P", "className": "U_C_O_R_T U_C_right", "innerHTML": "收起", "onclick": [[_this.pickup, ([U_C_Content, "C"])]] }, U_C_O_R);
        $$("div", { "id": "U_C_O_R_Remind", "className": "U_C_O_R_Remind", "innerHTML": "以下信息让您更方便让人了解" }, U_C_Content)
        var U_C_M_B_b = $$("div", { "id": "U_C_M_B_b", "className": "U_C_M_B_b U_C_left" }, U_C_Content);
        var U_C_M_B_big = $$("div", { "id": "U_C_M_B_big", "className": "U_C_M_B_big U_C_left" }, U_C_M_B_b);
        var U_C_M_B_b_t = $$("div", { "id": "U_C_M_B_b_t", "className": "U_C_M_B_b_t U_C_left", "innerHTML": "所在地" }, U_C_M_B_big);
        var U_C_M_B_Select = $$("div", { "id": "U_C_M_B_Select", "className": "U_C_M_B_Select U_C_left" }, U_C_M_B_big);
        var U_C_M_B_pro = $$("input", { "id": "U_C_M_B_pro", "className": "U_C_M_B_pro U_C_margin  U_C_left U_C_input", "type": "button", "value": "省/市", "onclick": [[_this.pro, ([_this, "U_C_M_B_pro", 0])]] }, U_C_M_B_Select);
        var U_C_M_B_city = $$("input", { "id": "U_C_M_B_city", "className": "U_C_M_B_city U_C_margin  U_C_left U_C_input", "type": "button", "value": "市/县", "onclick": [[_this.pro, ([_this, "U_C_M_B_city", 1])]] }, U_C_M_B_Select);
        var U_C_M_B_area = $$("input", { "id": "U_C_M_B_area", "className": "U_C_M_B_area U_C_margin  U_C_left U_C_input", "type": "button", "value": "乡/镇", "onclick": [[_this.pro, ([_this, "U_C_M_B_area", 2])]] }, U_C_M_B_Select);
        var U_C_M_L_Text = $$("div", { "id": "U_S_B_L_Text", "className": "U_S_B_L_Text", "style": { "margin-left": "11px"} }, U_C_M_B_big);
        var U_C_M_B_Text = $$("div", { "id": "U_C_M_B_Text", "className": "U_C_M_B_Text", "innerHTML": "找不到我家住址?" }, U_C_M_L_Text);
        U_C_M_B_Text.onclick = function () { U_C_M_B_input.focus() }
        var U_C_M_B_input = $$("input", { "id": "U_S_B_L_input", "className": "U_C_B_L_input", "placeholder": "例：广东省深圳市龙岗区", "type": "text" }, U_C_M_L_Text)
    },
    pro: function (_this, id, pro) {         //地区选择，访问后台得到数据
        var U_C_N = pro == 0 ? 1 : (pro == 1 ? _this.Fsort : _this.City);         //父ID
        var U_C_fp = pro == 0 ? 1 : (pro == 1 ? 2 : 3);     //判断当前传进来的是多少       深度
        if (U_C_fp != 1 && _this.Fsort == undefined) {
            U_C_fp == 2 ? alert("请先选择省份") : alert("请先选择城市"); return;
        }
        U.ACD.Request(U.CD.AjaxUrl, ([U.CD.Host, U.CD.Database, "UC_S_Select_Pro", U_C_N, U_C_fp]), _this.visit, (["", _this, id, pro]));
    },
    visit: function (r) {       //点击选择省份、城市、区域
        var _this = r.context[1];
        if (r.value[0].length == 0) { alert("该省份内区域正在开发中"); $("#" + r.context[2])[0].value = "乡/镇"; }  //如果改省份内没有区
        else {
            var U_C_Parent = $$("div", { "id": "U_C_parent", "className": "U_C_parent", "style": { "left": $("#" + r.context[2])[0].offsetLeft + "px", "top": $("#" + r.context[2])[0].offsetTop + 21 + "px"} }, _this.Udiv);
            $("body")[0].onclick = function () { _this.destroy(_this, [U_C_Parent]) };
            for (var i = 0; i < r.value[0].length; i++) {
                $$("div", { "id": "U_C_C_Select_" + i, "className": "U_C_C_Select U_C_left", "innerHTML": r.value[0][i].region_name, "type": "button", "onclick": [[_this.visitT, ([_this, r.value[0][i].region_id, r.value[0][i].region_name, r.context[2], U_C_Parent, r.context[3]])]] }, U_C_Parent);    //一系列的循环出数据用来判断当前省份
            }
        }
    },
    visitT: function (_this, _Fsort, Ctitle, id, del, pro) {      //已经选择过的区域，获取他，存好值，用来选择下一项
        $("#" + id)[0].value = Ctitle;                  //选择的值代替当前的值
        _this.destroy(_this, [del]);                      //销毁二级页面
        if (pro == 0 || pro == 1) {                     //点击过的区域，重新选择，若选择的和之前不一样，则把已选好的值全部重新初始化
            if (_this.Fsort != _Fsort && pro == 0) {
                $("#U_C_M_B_city")[0].value = "市/县";
                $("#U_C_M_B_area")[0].value = "乡/镇";
            } else if (_this.City != _Fsort) {
                $("#U_C_M_B_area")[0].value = "乡/镇";
            }
        }
        pro == 0 ? _this.Fsort = _Fsort : (pro == 1 ? _this.City = _Fsort : _this.area = _Fsort);       //判断当前选择到哪里了
    },
    pickup: function (del, str) {
        $("#U_" + str + "_Out").animate({ "height": "24px" }, 200);
        $("#U_" + str + "_Content")[0].innerHTML = "";
        del.parentNode.removeChild(del);
        $("#U_" + str + "_O_R_P")[0].parentNode.removeChild($("#U_" + str + "_O_R_P")[0]);
        $("#U_" + str + "_O_R_D")[0].style.display = "block";
        $("#U_" + str + "_O_C")[0].style.display = "block";
    },
    destroy: function (_this, del) {  //销毁二级页面
        for (var i = 0; i < del.length; i++) {
            del[i].parentNode.removeChild(del[i]);    //通过父元素移除子元素
        }
    },
    sumbit: function (Uit) {                   //这里是返回一个数组，  数组的值是用户选择的值
        Uit.onclick = (function (that) {
            return function () {
                if ($("#U_C_M_B_city")[0].value == "市/县" || $("#U_C_M_B_area")[0].value == "乡/镇" || $("#U_C_M_B_pro")[0].value == "省/市") {
                    return alert("请完善信息");
                }
                var arr = [$("#U_C_M_B_pro")[0].value, $("#U_C_M_B_city")[0].value, $("#U_C_M_B_area")[0].value]; //组成数组
                return alert(arr);
            }
        })(this)
    }
}
