﻿_OTHERID = "252";
_PopupSelectorB_res_cn = {};
_PopupSelectorB_res_cn["ResidenceCity.style"] = { oneColumnLimit: 11, width: 466, height: 400, offsetTwo: { X: 110, Y: 0 }, className: { levelOne: "lay_wls", levelTwo1: "lay_wss", levelTwo2: "lay_ws"} };
_PopupSelectorB_res_cn["ResidenceCity.selectedMaxWordLen"] = 12;
_PopupSelectorB_res_cn["ResidenceCity.psHeader"] = "地点";
_PopupSelectorB_res_cn["ResidenceCity.selectingHeader"] = " 请选择您的现居住的具体城市：";
_PopupSelectorB_res_cn["ResidenceCity.noSelectedItemsTip"] = " 请选择您的现居住的具体城市。选项未包含的城市，请选择所在省份。";

_PopupSelectorB_res_cn["HuKouCity.style"] = _PopupSelectorB_res_cn["ResidenceCity.style"];
_PopupSelectorB_res_cn["HuKouCity.selectedMaxWordLen"] = 12;
_PopupSelectorB_res_cn["HuKouCity.psHeader"] = "地点";
_PopupSelectorB_res_cn["HuKouCity.selectingHeader"] = " 请选择您的户口所在地：";
_PopupSelectorB_res_cn["HuKouCity.noSelectedItemsTip"] = " 请选择您的户口所在地。";

_PopupSelectorB_res_cn["ExpectRegions.style"] = _PopupSelectorB_res_cn["ResidenceCity.style"];
_PopupSelectorB_res_cn["ExpectRegions.selectedMaxWordLen"] = 12;
_PopupSelectorB_res_cn["ExpectRegions.psHeader"] = "地点";
_PopupSelectorB_res_cn["ExpectRegions.selectingHeader"] = " 请选择您的期望从事工作地区：";
_PopupSelectorB_res_cn["ExpectRegions.noSelectedItemsTip"] = " 请选择您的期望从事工作的具体城市，最多可以选择5个城市。选项未包含的城市，请选择所在省份。";

_PopupSelectorB_res_cn["ExpectIndustries.style"] = { oneColumnLimit: 11, width: 746, height: 510, offsetTwo: { X: 110, Y: 0 }, className: { levelOne: "lay_wll", levelTwo1: "", levelTwo2: ""} };
_PopupSelectorB_res_cn["ExpectIndustries.selectedMaxWordLen"] = 20;
_PopupSelectorB_res_cn["ExpectIndustries.psHeader"] = "行业类别";
_PopupSelectorB_res_cn["ExpectIndustries.selectingHeader"] = " 请选择您期望从事的工作行业：";
_PopupSelectorB_res_cn["ExpectIndustries.noSelectedItemsTip"] = "请选择您期望从事的工作行业。";

_PopupSelectorB_res_cn["ExpectJobCategories.style"] = { oneColumnLimit: 12, width: 594, height: 526, offsetTwo: { X: 380, Y: 0 }, className: { levelOne: "lay_wl", levelTwo1: "lay_wm", levelTwo2: "lay_wl2"} };
_PopupSelectorB_res_cn["ExpectJobCategories.selectedMaxWordLen"] = 44;
_PopupSelectorB_res_cn["ExpectJobCategories.psHeader"] = "职业类别";
_PopupSelectorB_res_cn["ExpectJobCategories.selectingHeader"] = " 请选择您期望从事的的具体职业：";
_PopupSelectorB_res_cn["ExpectJobCategories.noSelectedItemsTip"] = "请选择您期望从事的的具体职业。如果选项中没有，请选择最为接近的职业类别。";

_PopupSelectorB_res_cn["OrgIndustry.style"] = _PopupSelectorB_res_cn["ExpectIndustries.style"]
_PopupSelectorB_res_cn["OrgIndustry.selectedMaxWordLen"] = 20;
_PopupSelectorB_res_cn["OrgIndustry.psHeader"] = "行业类别";
_PopupSelectorB_res_cn["OrgIndustry.selectingHeader"] = " 请选择公司所在行业:";
_PopupSelectorB_res_cn["OrgIndustry.noSelectedItemsTip"] = "请选择公司所在行业。";

_PopupSelectorB_res_cn["JobCategory.style"] = _PopupSelectorB_res_cn["ExpectJobCategories.style"]
_PopupSelectorB_res_cn["JobCategory.selectedMaxWordLen"] = 44;
_PopupSelectorB_res_cn["JobCategory.psHeader"] = "职业类别";
_PopupSelectorB_res_cn["JobCategory.selectingHeader"] = " 请选择您现在从事的的具体职业：";
_PopupSelectorB_res_cn["JobCategory.noSelectedItemsTip"] = "请选择您现在从事的的具体职业。如果选项中没有，请选择最为接近的职业类别。";

_PopupSelectorB_res_en = {};
_PopupSelectorB_res_en["ResidenceCity.style"] = { oneColumnLimit: 11, width: 466, height: 400, offsetTwo: { X: 110, Y: 0 }, className: { levelOne: "lay_wls", levelTwo1: "lay_wss", levelTwo2: "lay_ws"} };
_PopupSelectorB_res_en["ResidenceCity.selectedMaxWordLen"] = 12;
_PopupSelectorB_res_en["ResidenceCity.psHeader"] = "Location";
_PopupSelectorB_res_en["ResidenceCity.selectingHeader"] = "Current City:";
_PopupSelectorB_res_en["ResidenceCity.noSelectedItemsTip"] = "Please Select Current City.";

_PopupSelectorB_res_en["HuKouCity.style"] = _PopupSelectorB_res_en["ResidenceCity.style"];
_PopupSelectorB_res_en["HuKouCity.selectedMaxWordLen"] = 12;
_PopupSelectorB_res_en["HuKouCity.psHeader"] = "Location";
_PopupSelectorB_res_en["HuKouCity.selectingHeader"] = "HuKou City:";
_PopupSelectorB_res_en["HuKouCity.noSelectedItemsTip"] = "Please Select HuKou City.";

_PopupSelectorB_res_en["ExpectRegions.style"] = _PopupSelectorB_res_en["ResidenceCity.style"];
_PopupSelectorB_res_en["ExpectRegions.selectedMaxWordLen"] = 12;
_PopupSelectorB_res_en["ExpectRegions.psHeader"] = "Job Area";
_PopupSelectorB_res_en["ExpectRegions.selectingHeader"] = "Job Area:";
_PopupSelectorB_res_en["ExpectRegions.noSelectedItemsTip"] = "Please Select Job Area（５Items Limit）";

_PopupSelectorB_res_en["ExpectIndustries.style"] = { oneColumnLimit: 11, width: 746, height: 510, offsetTwo: { X: 110, Y: 0 }, className: { levelOne: "lay_wll", levelTwo1: "", levelTwo2: ""} };
_PopupSelectorB_res_en["ExpectIndustries.selectedMaxWordLen"] = 20;
_PopupSelectorB_res_en["ExpectIndustries.psHeader"] = "Job Industry";
_PopupSelectorB_res_en["ExpectIndustries.selectingHeader"] = "Target Job Industry:";
_PopupSelectorB_res_en["ExpectIndustries.noSelectedItemsTip"] = "Please Select Job Industry（５Items Limit）.";

_PopupSelectorB_res_en["ExpectJobCategories.style"] = { oneColumnLimit: 12, width: 594, height: 526, offsetTwo: { X: 380, Y: 0 }, className: { levelOne: "lay_wl", levelTwo1: "lay_wm", levelTwo2: "lay_wl2"} };
_PopupSelectorB_res_en["ExpectJobCategories.selectedMaxWordLen"] = 44;
_PopupSelectorB_res_en["ExpectJobCategories.psHeader"] = "Job Category";
_PopupSelectorB_res_en["ExpectJobCategories.selectingHeader"] = "Job Category:";
_PopupSelectorB_res_en["ExpectJobCategories.noSelectedItemsTip"] = "Please Select Job Category（５Items Limit）.";

_PopupSelectorB_res_en["OrgIndustry.style"] = _PopupSelectorB_res_en["ExpectIndustries.style"]
_PopupSelectorB_res_en["OrgIndustry.selectedMaxWordLen"] = 20;
_PopupSelectorB_res_en["OrgIndustry.psHeader"] = "Current Industry";
_PopupSelectorB_res_en["OrgIndustry.selectingHeader"] = "Current Industry:";
_PopupSelectorB_res_en["OrgIndustry.noSelectedItemsTip"] = "Please Select Current Industry.";

_PopupSelectorB_res_en["JobCategory.style"] = _PopupSelectorB_res_en["ExpectJobCategories.style"]
_PopupSelectorB_res_en["JobCategory.selectedMaxWordLen"] = 44;
_PopupSelectorB_res_en["JobCategory.psHeader"] = "Job Category";
_PopupSelectorB_res_en["JobCategory.selectingHeader"] = "Job Category:";
_PopupSelectorB_res_en["JobCategory.noSelectedItemsTip"] = "Please Select Job Category.";
// className: {
// levelOne: { "cat": "lay_wl", "loc": "lay_wls", "ind": "lay_wll", "curcat": "lay_wl", "curind": "lay_wll", "curloc": "lay_wls" },
// //二级类别一列显示的样式
// levelTwo1: { "cat": "lay_wm", "loc": "lay_wss", "ind": "", "curcat": "lay_wm", "curind": "", "curloc": "lay_wss" },
// //二级类别两列显示的样式
// levelTwo2: { "cat": "lay_wl2", "loc": "lay_ws", "ind": "", "curcat": "lay_wl2", "curind": "", "curloc": "lay_ws" }
// },
// width: { "cat": 594, "loc": 466, "ind": 746, "curcat": 594, "curind": 746, "curloc": 466 },
// height: { "cat": 526, "loc": 400, "ind": 510, "curcat": 526, "curind": 510, "curloc": 400 },
// offset: {
// levelOne: { X: 0, Y: 20 },
// levelTwo: { "cat": { X: 284, Y: 0 }, "loc": { X: 110, Y: 0 }, "curcat": { X: 284, Y: 0 }, "curloc": { X: 110, Y: 0} }
// }
// _gtYourSelected: { cat: "您选择的职位类别是：", ind: "您最多可以选择５个行业类别", loc: "您选择的工作地点是：", curcat: "您选择的职位类别是：", curind: "请选择您现在从事工作的行业：", curloc: "请选择您的现居住地：" },
// _gtYourSelectedEn: { cat: "Please  Select  Job  Category（５Items  Limit）：", ind: "Please  Select  Job  Industry（５Items  Limit）：", loc: "Please  Select  Job  Area（５Items  Limit）：", curcat: "Please  Select  Job  Category：", curind: "Please Select Job Industry：", curloc: "Please Select Job Area：" },
// _gtPopupSelectorBHeader: { cat: "职位类别", ind: "行业类别", loc: "地点", curcat: "职位类别", curind: "行业类别", curloc: "地点" },
// _gtPopupSelectorBHeaderEn: { cat: "Job  Category", ind: "Job  Industry", loc: "Job  Area", curcat: "Job  Category", curind: "Job  Industry", curloc: "Job  Area" },
// _oneColumnLimit: { cat: 12, loc: 11, curcat: 12, curloc: 11 }, //二级类别显示成一列的最大条目数，超过这个数就要显示成两列
// _selectedMaxWordLen: { cat: 44, loc: 12, curcat: 44, curloc: 12 },

jQuery.extend(Array.prototype, {
    //特殊方法，不适用于普通数组
    remove: function(item) {
        var array = this.clone();
        this.length = 0;
        for (var i = 0; i < array.length; i++) {
            if (array[i].id != item) this.push(array[i]);
        }
        return this;
    },

    //特殊方法，不适用于普通数组
    has: function(item) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == item) return true;
            if (typeof item == "object" && this[i].id == item.id) return true;
        }
        return false;
    },

    //特殊方法，不适用于普通数组
    findById: function(id) {
        for (var i = 0; i < this.length; i++) {
            if (this[i].id == id) return this[i];
        }
        return null;
    },

    clear: function() {
        this.length = 0;
        return this;
    },

    clone: function() {
        return [].concat(this);
    }
});

function queryString(val) {
    var uri = window.location.search;
    var re = new RegExp("[\?|\&]+" + val + "\=([^\&\?]*)", "ig");
    return ((uri.match(re)) ? (uri.match(re)[0].substr(val.length + 2)) : null);
}

function dbcToSbc(str) {
    return str.replace(/（/g, "(").replace(/）/g, ")");
}

function getY(el) {
    var y = 0;
    for (var e = el; e; e = e.offsetParent) // Iterate the offsetParents
        y += e.offsetTop;                       // Add up offsetTop values

    // Now loop up through the ancestors of the element, looking for
    // any that have scrollTop set. Subtract these scrolling values from
    // the total offset. However, we must be sure to stop the loop before
    // we reach document.body, or we'll take document scrolling into account
    // and end up converting our offset to window coordinates.
    for (e = el.parentNode; e && e != document.body; e = e.parentNode)
        if (e.scrollTop) y -= e.scrollTop;  // subtract scrollbar values

    // This is the Y coordinate with document-internal scrolling accounted for.
    return y;
}

//通过验证选中的职位小类，改变提示信息的样式
function ChangCSSFromValidateCategory(obj, errtips) {
    var Categorylist = "'1200','100','900','604','1034000','3600','300','1035000','400','600','700','2700','2100','1013000','1036000','1014000','702','1016001','1017000','3300','3400','3420','1020000','3800','3500','1900','1700','2000','1026000','800','2600','3700','2500','1033000'";
    if (obj.value != "undefined") {
        var ol = obj.value.split(",");
        for (var i = 0; i < ol.length; i++) {
            if (Categorylist.indexOf("'" + ol[i] + "'") != -1) {
                errtips.className = "errmsg";
                return;
            }
        }
        errtips.className = "info";
    }
}

var PopupSelectorB = {
    _showTimer: null,
    _hideTimer: null,
    _lastPopupIndex: null,
    _box: null,
    _subbox: null,
    _ref: null,
    _type: null,
    _name: null,
    _types: [],
    _callback: null,
    _maxSize: 5,
    _isSingle: false,
    _writeText: false, //填写其他
    _allowSelectedLargeCategory: true, //允许选择大类
    _lang: queryString("lang") == "1" ? "EN" : "CN",

    //_curItems：在弹出层显示时，用户增加或减少的选项都在这个数组里，当用户清空时，也是清空此数组，
    //当点击确定时，将此数组中的选项复制到_selItems中对应的数组做持久保存，然后清空此数组
    //示例：[{id:xxx, name:xxxx, parObj:null/object ref, isParent:true/false}, .....]
    _curItems: [],

    _gtMaxLimit: "对不起,您的已选项已经达到了5项.请减少已选项,再继续选择",
    _gtMaxLimitEn: "5 Items Limit!",
    _delay: 500,
    _style: {
        // className: {
        // levelOne: { "cat": "lay_wl", "loc": "lay_wls", "ind": "lay_wll", "curcat": "lay_wl", "curind": "lay_wll", "curloc": "lay_wls" },
        // //二级类别一列显示的样式
        // levelTwo1: { "cat": "lay_wm", "loc": "lay_wss", "ind": "", "curcat": "lay_wm", "curind": "", "curloc": "lay_wss" },
        // //二级类别两列显示的样式
        // levelTwo2: { "cat": "lay_wl2", "loc": "lay_ws", "ind": "", "curcat": "lay_wl2", "curind": "", "curloc": "lay_ws" }
        // },
        // width: { "cat": 594, "loc": 466, "ind": 746, "curcat": 594, "curind": 746, "curloc": 466 },
        // height: { "cat": 526, "loc": 400, "ind": 510, "curcat": 526, "curind": 510, "curloc": 400 },
        defaultClassName: "alert_lay sech_lay lm",
        defaultClassTwo: "alert_lay sech_lay2",
        left: 0,
        top: 0,
        lineHeight: 20,
        topBottomMargin: 17,
        offset: {
            levelOne: { X: 0, Y: 20 }
        }
    },
    res: function(key) {
        key = this._name + "." + key;
        var resValue = this._res[key];
        if (typeof (resValue) == "undefined") resValue = "[empty]" + key;
        return resValue;
    },
    style: function(key) { return this.res("style"); },
    popup: function(type, propName, maxSize, propValue, writeText, allowSelectedLargeCategory, callback) {
        if (this._box == null) this._box = JQ("#popupSelectorB");
        if (this._subBox == null) this._subBox = JQ("#subItemsB");
        this._type = type.toString();
        if (this._types.has(this._type) == false) this._types.push(this._type);
        this._callback = callback;
        this._name = propName;
        this._curItems = propValue.clone();
        this._maxSize = maxSize;
        this._isSingle = this._maxSize == 1;
        this._writeText = writeText;
        this._allowSelectedLargeCategory = allowSelectedLargeCategory;
        if (this._lang == "CN") this._res = _PopupSelectorB_res_cn;
        else this._res = _PopupSelectorB_res_en;

        this.render();
    },
    render: function() {
        var pslayer = JQ("#pslayerB");
        pslayer[0].className = this._style.defaultClassName;
        pslayer.addClass(this.style().className.levelOne);
        JQ("#selectingHeaderB").html(this.res("selectingHeader"));
        JQ("#psHeaderB").html(this.res("psHeader"));

        var html = [];
        var parItems = this.getItems(this._type);
        this._hasSubItems = parItems.hasSubItems;
        var start = 0;
        var end = parItems.length;
        if (this._type == "C_CODE_ABBR_LOCATION") {
            start = 0;
            end = 35; //地区集合中前35位是国内省市
            JQ("#subHeader1B").html(this._lang == "CN" ? "<span>所有省市：</span>" : "<span>All  Provinces</span>");
            JQ("#subHeader2B").html(this._lang == "CN" ? "<span>其它国家和地区：</span>" : "<span>Other Countries or Regions：</span>").show();
            for (var i = end; i < parItems.length; i++) {
                var name = parItems[i].name;
                html.push("<li class=\"nonelay\"><a href=\"###\"><input id=\"");
                html.push(parItems[i].id);
                //html.push("\" type=\"checkbox\" value=\"");

                html.push("\" type=\"");
                html.push(this._isSingle ? "radio\" name=\"" + this._type : "checkbox");
                html.push("\" value=\"");

                html.push(parItems[i].id);
                html.push("@");
                html.push(name);
                html.push("\"");
                if (this._curItems.has({ id: parItems[i].id })) html.push(" checked");
                html.push(" onclick=\"PopupSelectorB.click(this, null);\" />");
                html.push(name);
                html.push("</a></li>");
            }
            JQ("#subHeader1B").show();
            JQ("#subHeader2B").show();
            JQ("#allItems2B").html(html.join("")).show();
        }
        else {
            JQ("#subHeader1B").hide();
            JQ("#subHeader2B").hide();
            JQ("#allItems2B").hide();
        }

        html = [];
        for (var i = start; i < end; i++) {
            var parItem = parItems[i];
            var name = parItem.name;
            if ((parItem.subItems && parItem.subItems.length > 0) || this._type == "C_CODE_ABBR_OCCUPATION") {
                html.push("<li onmouseover=\"PopupSelectorB.showSubItems(");
                html.push(i);
                html.push(", this, true)\" onmouseout=\"PopupSelectorB.hideSubItems(this)\">");
            }
            else {
                if (this._curItems.has({ id: parItem.id, name: parItem.name, parObj: null }))
                    html.push("<li id=l" + i + " name=" + parItem.id + " class=\"layon\">");
                else
                    html.push("<li id=l" + i + " name=" + parItem.id + " class=\"nonelay\">");
            }
            html.push("<a href=\"###\">");
            if (parItem.subItems || parItem.subItems.length < 1) {
                html.push("<label for=\"pcbx");
                html.push(parItem.id);
                html.push("\">");
            }

            if (this._type == "C_CODE_ABBR_INDUSTRY") {
                html.push("<input id=\"pcbx");
                html.push(parItem.id);
                html.push("\" type=\"");
                html.push(this._isSingle ? "radio\" name=\"" + this._type : "checkbox");
                html.push("\" value=\"");
                //            html.push("\" type=\"radio\" value=\"");
                html.push(parItem.id);
                html.push("@");
                html.push(name);
                html.push("\"");
                if (this._curItems.has({ id: parItem.id })) html.push(" checked");
                html.push(" onclick=\"PopupSelectorB.click(this, null);\" />");
            }
            html.push(dbcToSbc(name));
            if (parItem.subItems || parItem.subItems.length < 1) {
                html.push("</label>");
            }
            html.push("</a></li>");
        }
        JQ("#allItems1B").html(html.join(""));
        html.length = 0;
        JQ("#divSelectingB").css("display", (this._curItems.length == 0) ? "none" : "block");
        var displayNoSelected = (this._curItems.length == 0) ? "block" : "none";
        if (this._curItems.length == 0) {
            JQ("#noSelectedItemsB").css("display", "block");
            var noItemsTip = this.res("noSelectedItemsTip");
            JQ("#noSelectedItemsTipB").html(noItemsTip);
        }
        else JQ("#noSelectedItemsB").css("display", "none");


        for (var i = 0; i < this._curItems.length; i++) {
            html.push("<li id=\"");
            html.push(this._curItems[i].id);
            html.push("\"><a href=\"###\" onclick=\"PopupSelectorB.remove(");
            html.push(this._curItems[i].id);
            html.push(");return false;\">");
            var name = PopupSelectorB.itemName(this._curItems[i]);
            var tmpName = dbcToSbc(name);
            var selectedMaxWordLen = this.res("selectedMaxWordLen");
            if (selectedMaxWordLen != 0 && GetSubStringLen(tmpName) > selectedMaxWordLen)
                tmpName = GetSubString(tmpName, selectedMaxWordLen - 3) + "...";
            html.push(tmpName);
            html.push("</a></li>");
            if (this._writeText && this.isOther(this._curItems[i])) {
                html.push("<input id='txt");
                html.push(this._curItems[i].id)
                html.push("' type='text' size='50' maxlength='50' value='");
                html.push(this._curItems[i].text)
                html.push("'/>");
            }
        }
        JQ("#selectingB").html(html.join(""));
        if (this._hasSubItems == false) {
            JQ("#divSelectingB").show();
            JQ("#selectingB").hide();
            JQ("#noSelectedItemsB").hide();
        }
        else {
            JQ("#selectingB").show();
            if (this._curItems.length == 0)
                JQ("#noSelectedItemsB").show();
            else
                JQ("#noSelectedItemsB").hide();
        }

        JQ("#shieldB").width(this.style().width).height(this.style().height - 50);
        JQ(this._box).show();

        // var dvWidth = GetObjWHLT($('pslayer')).width;
        // var dvHeight = GetObjWHLT($('pslayer')).height;
        var dvWidth = JQ("div.box").width();
        var dvHeight = JQ("div.box").height()//500;
        var totalWidth = document.body.clientWidth;
        if (navigator.userAgent.toLowerCase().indexOf("msie 6.0") != -1)//IE6
            var totalHeight = document.body.scrollHeight;
        else
            var totalHeight = document.documentElement.scrollHeight;
        var leftPos = (totalWidth - dvWidth) / 2;
        var topPos = (totalHeight - dvHeight) / 2;

        //this._style.left = leftPos > 150 ? 150 : leftPos; //offset.left;

        this._style.left = (document.documentElement.offsetWidth - dvWidth) / 2; //offset.left;

        //alert((document.documentElement.offsetWidth - dvWidth)/2);
        //        var alertstr = "alert(";
        //        for (var i = 0; i < 2; i++) {
        //            var head;
        //            if (i == 0)
        //                head = "documentElement";
        //            else
        //                head = "body";
        //            for (var j = 0; j < 6; j++) {
        //                var tail;
        //                if (j == 0)
        //                    tail = "clientWidth";
        //                else if (j == 1)
        //                    tail = "clientHeight";
        //                else if (j == 2)
        //                    tail = "scrollWidth";
        //                else if (j == 3)
        //                    tail = "scrollHeight";
        //                else if (j == 4)
        //                    tail = "scrollTop";
        //                else
        //                    tail = "scrollLeft";
        //                if (i == 1 && j == 5)
        //                    alertstr += "\"" + head + "." + tail + ":\"+document." + head + "." + tail;
        //                else
        //                    alertstr += "\"" + head + "." + tail + ":\"+document." + head + "." + tail + "+\"\\r\\n\"+";
        //                //eval("alert(document." + head + "." + tail + ")");
        //            }

        //        }
        //        //alert(navigator.userAgent.toLowerCase());
        //        alertstr += ")";
        //        alert(alertstr);
        //        eval(alertstr);
        if (navigator.userAgent.toLowerCase().indexOf("msie 6.0") != -1)//IE6
            var offsetTop = document.body.scrollTop - (document.body.scrollHeight - document.documentElement.scrollHeight) / 2;
        else
            var offsetTop = document.documentElement.scrollTop - (document.documentElement.scrollHeight - document.documentElement.clientHeight) / 2;
        this._style.top = topPos + offsetTop; //简历编辑页加导航栏后窗口滚动条就出现了，必须考虑在内 //topPos > 120 ? 120 : topPos; //offset.top;// + $("dvMain").scrollTop /*层wrapResumeContent滚动条的top*/;

        var pos = { top: (this._style.top), left: this._style.left };

        JQ(this._box).css(pos);

        JQ("#maskB").height(JQ(document).height()).show();
    },

    close: function() {
        JQ("#maskB").hide();
        JQ(this._box).hide();
    },

    OK: function() {
        var selItems = this._curItems.clone();
        if (this._isSingle && selItems.length > 0 && this.isOther(selItems[0])) {
            var jqInput = JQ("#txt" + selItems[0].id);
            selItems[0].text = (jqInput.length > 0) ? jqInput[0].value : "";
        }
        this._callback(selItems);

        this._curItems.clear();
        JQ("#selectingB").html("");
        JQ("#maskB").hide();
        JQ(this._box).hide();
    },

    empty: function() {
        JQ("#selectingB").html("");
        JQ("#allItems1B input").each(function(i) { this.checked = false; });
        JQ("#allItems2B input").each(function(i) { this.checked = false; });
        this._curItems.clear();
        //this.showHideSelecting(this);
    },

    click: function(cbx, parObj, subCount) {
        if (!this._isSingle && cbx.checked && this._curItems.length == this._maxSize) {
            alert(this._lang == "CN" ? this._gtMaxLimit : this._gtMaxLimitEn);
            cbx.checked = false;
            return;
        }
        var item = { id: cbx.value.split("@")[0], name: cbx.value.split("@")[1], parObj: parObj, subCount: subCount };
        var selecting = JQ("#selectingB")[0];
        var selItem = null;
        if (cbx.checked) {
            selItem = document.createElement("li");
            selItem.id = item.id;
            var tmpName = PopupSelectorB.itemName(item);
            var selectedMaxWordLen = this.res("selectedMaxWordLen");
            if (selectedMaxWordLen != 0 && GetSubStringLen(tmpName) > selectedMaxWordLen)
                tmpName = GetSubString(tmpName, selectedMaxWordLen - 3) + "...";
            selItem.innerHTML = "<a href=\"###\" title=\"" + tmpName + "\" onclick=\"PopupSelectorB.remove(" + item.id + ");return false;\">" + tmpName + "</a>";
            if (!this._isSingle) {
                selecting.appendChild(selItem);
                this._curItems.push(item);
            }
            else {
                selecting.innerHTML = "";
                selecting.appendChild(selItem);
                if (this._writeText && this.isOther(item)) {
                    var inputText = document.createElement("input");
                    inputText.id = "txt" + item.id;
                    inputText.type = "text";
                    inputText.size = 50;
                    inputText.maxlength = 50;
                    selecting.appendChild(inputText);
                }
                this._curItems.clear();
                this._curItems.push(item);
            }
            JQ("#l" + item.id).removeClass("layicon");
            JQ("#l" + item.id).addClass("layon");
        }
        else {
            if (!this._isSingle) {
                selItem = document.getElementById(item.id);
                selecting.removeChild(selItem);
                this._curItems.remove(item.id);
                JQ("#l" + item.id).removeClass("layon");
                JQ("#l" + item.id).addClass("layicon");
            }
        }
        if (parObj == null && this._hasSubItems) {
            //当点击父类别时，需要取消已选项中属于该父类别的子类别
            var array = this._curItems.clone();
            this._curItems.clear();
            for (var i = 0; i < array.length; i++) {
                if (array[i].parObj != null && array[i].parObj.id == item.id) {
                    selecting.removeChild(document.getElementById(array[i].id));
                }
                else {
                    this._curItems.push(array[i]);
                }
            }

            var cbxChkd = cbx.checked;
            var subControl;
            //JQ("#subItems input").each(function(i) { this.checked = this.disabled = cbx.checked; });
            var chkList = JQ("#subItemsB input"); // = document.getElementsByTagName("subItems").getElementsByTagName("input");//JQ("#subItems input");
            for (var i = 1; i < chkList.length; i++) {
                subControl = chkList[i];
                if (!this._isSingle)
                    subControl.checked = cbxChkd;
                subControl.disabled = cbxChkd;
                subControl = null;
            }
            cbx.checked = cbxChkd;
        }
        this.showHideSelecting(this);
    },

    remove: function(id) {
        JQ("#selectingB")[0].removeChild(document.getElementById(id));
        var pcbx = document.getElementById("pcbx" + id);
        if (pcbx) pcbx.checked = false;
        var array = this._curItems.clone();
        this._curItems.clear();
        for (var i = 0; i < array.length; i++) {
            if (array[i].id != id) this._curItems.push(array[i]);
        }
        this.showHideSelecting(this);
    },

    //private method
    showHideSelecting: function(selector) {
        JQ("#noSelectedItemsB").hide();
        if (selector._curItems.length > 0) {
            JQ("#divSelectingB").show();
            if (this._hasSubItems) JQ("#selectingB").show();
        }
    },

    showSubItems: function(index, ref, isDelay, ev) {
        var subItems = JQ("#subItemsB");
        if (this._hideTimer) clearTimeout(this._hideTimer);
        if (this._showTimer) clearTimeout(this._showTimer);
        if (index == this._lastPopupIndex && subItems.css("display") == "block") {
            JQ(ref).addClass("layshow");
            return;
        }
        var self = this;
        if (!isDelay) loadSubItems(index, ref, self);
        this._showTimer = setTimeout(function() { loadSubItems(index, ref, self); }, this._delay);

        function loadSubItems(index, ref, self) {
            var parItem = self.getItems(self._type)[index];
            var offset = JQ(ref).offset();
            var self_style = self.style();
            var pos = { top: offset.top + self_style.offsetTwo.Y, left: offset.left + self_style.offsetTwo.X };
            //            alert("offset.left:" + offset.left);
            //            alert("self_style.offsetTwo.X " + self_style.offsetTwo.X);

            var actualSubItemCount = parItem.subItems.length - 1;
            if (index % 2 == 0)//左边列
                var calItemCount = (actualSubItemCount % 2 == 0) ? actualSubItemCount / 2 : (actualSubItemCount / 2 + 1);
            else //右边列
                var calItemCount = actualSubItemCount;
            if (actualSubItemCount <= self_style.oneColumnLimit[self._type]) calItemCount = actualSubItemCount;
            var subBoxHeight = self._style.lineHeight * parseInt(calItemCount) + self._style.topBottomMargin;
            var winHeight = JQ(window).height();
            var remainHeight = winHeight - pos.top + document.documentElement.scrollTop;
            //if (remainHeight < subBoxHeight) pos.top = pos.top - (subBoxHeight - remainHeight);
            //如果整个IE窗口的高度小于弹出层的高度，则弹出层以对齐顶部显示
            if (subBoxHeight > winHeight) pos.top = document.documentElement.scrollTop;


            //var layer=document.getElementById("subItemsB");
            var parentChecked = "";
            // if (self._isSingle)
            // {
            // if (self._allowSelectedLargeCategory)
            // parentChecked = (ref.getElementsByTagName("input")[0].checked == true) ? " disabled " : "";
            // else
            // parentChecked = "";
            // }
            // else
            // {
            // if (self._allowSelectedLargeCategory)
            // parentChecked = (ref.getElementsByTagName("input")[0].checked == true) ? " checked disabled " : "";
            // else
            // parentChecked = "";
            // }
            var item = { id: parItem.id, name: parItem.name, parObj: null };
            var parentName = item.name;
            var html = [];

            if (PopupSelectorB._type != "C_CODE_ABBR_LOCATION" || index > 3) {
                html.push("<h4><input id=\"scbx");
                html.push(PopupSelectorB._isSingle ? "radio\" name=\"" + self._type : "checkbox");
                //html.push(item.id);
                //html.push("\" type=\"checkbox\" value=\"");

                html.push("\" type=\"");
                html.push(PopupSelectorB._isSingle ? "radio\" name=\"" + self._type : "checkbox");
                html.push("\" value=\"");

                html.push(item.id);
                html.push("@");
                html.push(item.name);
                html.push("\"");
                html.push(parentChecked);
                if (self._curItems.has(item)) {
                    parentChecked = " checked disabled ";
                    html.push(" checked");
                }
                html.push(" onclick=\"PopupSelectorB.click(this, null,");
                html.push(parItem.subItems.length);
                html.push(");\" />");
                html.push(dbcToSbc(item.name));
                html.push("</h4>");
            }
            html.push("<ol>");

            for (var i = 0; i < parItem.subItems.length; i++) {
                var subItem = parItem.subItems[i];
                var name = subItem.name;
                subItem.parObj = item;
                if (self._curItems.has(subItem)) {
                    html.push("<li id=l" + i + " class=\"layon\"  >");
                }
                else
                    html.push("<li id=l" + i + "  >");
                html.push("<a href=\"###\"><label for=\"scbx");
                html.push(subItem.id);
                html.push("\"><input id=\"scbx");
                html.push(subItem.id);
                //html.push("\" type=\"checkbox\" value=\"");

                html.push("\" type=\"");
                html.push(PopupSelectorB._isSingle ? "radio\" name=\"" + self._type : "checkbox");
                html.push("\" value=\"");

                html.push(subItem.id);
                html.push("@");
                html.push(name);
                html.push("\"");
                html.push(parentChecked);
                if (self._curItems.has(subItem)) html.push(" checked");
                html.push(" onclick=\"PopupSelectorB.click(this, { id: ");
                html.push(parItem.id);
                html.push(", name: '");
                html.push(parentName);
                html.push("', parObj: null }, 0");
                html.push(");\" />");
                html.push(dbcToSbc(name));
                html.push("</label></a></li>");
            }
            html.push("</ol>");

            var subBox = JQ("#subBoxB");
            for (var i = 0; i < self._types.length; i++) {
                subItems.removeClass(self.style().className.levelTwo1);
                subItems.removeClass(self.style().className.levelTwo2);
            }
            var self_style = self.style();
            var levelTwo = (actualSubItemCount > self_style.oneColumnLimit) ? self_style.className.levelTwo2 : self_style.className.levelTwo1;
            self._lastPopupIndex = index;
            JQ("#subItemsB").hover(function(e) { self.showSubItems(index, ref, true, e); }, function(e) { self.hideSubItems(ref); });
            subBox.html(html.join(""));
            subItems[0].className = PopupSelectorB._style.defaultClassTwo;
            var oo = subItems.addClass(levelTwo);
            if (PopupSelectorB._type != "C_CODE_ABBR_OCCUPATION") {
                if (document.body.clientWidth < pos.left + subItems.width()) {
                    pos.left = offset.left - subItems.width();
                }

                if (pos.top + subItems.height() > winHeight) pos.top = winHeight - subItems.height();
            }
            else {
                pos.left = offset.left; //直接跟父左对齐
                pos.top = offset.top + JQ(ref).height();
                if (navigator.userAgent.toLowerCase().indexOf("msie 6.0") != -1)//IE6
                    var scrollTop = document.body.scrollTop;
                else
                    var scrollTop = document.documentElement.scrollTop;
                if (pos.top + subItems.height() > winHeight+scrollTop)//下面显示不了
                {
                    if (offset.top - subItems.height() - scrollTop >= 0)//上面显示的了，就显示到上面
                        pos.top = offset.top - subItems.height();
                }
            }
            oo.css(pos).show();
        }
    },

    hideSubItems: function(ref) {
        JQ(ref).removeClass("layshow");
        if (this._showTimer) clearTimeout(this._showTimer);
        if (this._hideTimer) clearTimeout(this._hideTimer);
        this._hideTimer = setTimeout(function() { JQ("#subItemsB").hide(); }, 100);
    },

    getItems: function(targetType) {
        if (arguments.length == 0) targetType = this._type;
        var items = this.allTypeItems[targetType];
        if (typeof (items) == "object") return items;

        var c = window['__Dictionary__' + targetType];
        if (typeof (c) != "object") alert("没有类型:" + targetType);
        if (c == null || c.DataItems == null || c.DataItems.length <= 0) alert("类型[" + targetType + "]没有数据");
        var itemCount = c.DataItems.length;

        var items = [];
        for (var i = 0; i < itemCount; i++) {
            dataItem = c.DataItems[i];
            if (dataItem.ParentId == 0) {
                var itenName = eval("dataItem.CodeName" + this._lang).replace("省", "").replace("自治区", "");
                items[items.length] = { id: dataItem.CodeId, name: itenName, subItems: [] };
            }
        }
        items.hasSubItems = items.length < itemCount;
        for (var m = 0; m < items.length; m++) {
            var targetItem = items[m];
            for (var i = 0; i < itemCount; i++) {
                dataItem = c.DataItems[i];
                if (dataItem.ParentId >= 0 && dataItem.ParentId == targetItem.id) {
                    targetItem.subItems[targetItem.subItems.length] = { id: dataItem.CodeId, name: eval("dataItem.CodeName" + this._lang) };
                }
            }
        }

        // if (targetType=="C_CODE_ABBR_LOCATION")
        // {
        // var ignoreParent = [];
        // if (targetType=="C_CODE_ABBR_LOCATION") ignoreParent = [30000,31000,32000,33000,34000,35000,37000];
        // for (var m= 0; m < items.length; m++) {
        // var targetItem = items[m];
        // if (ignoreParent.has( targetItem.id) == false)
        // {
        // targetItem.subItems[targetItem.subItems.length] = {id:this.otherId(targetItem),name: this._lang == "CN" ? "其他":"Other"};
        // }
        // }
        // }    

        this.allTypeItems[targetType] = items;
        return items;
    },
    findItem: function(targetType, id) {
        var items = this.getItems(targetType);
        var p = items.findById(id);
        if (p != null) {
            return { id: p.id, name: p.name, parObj: null, subCount: p.subItems.length };
        }
        else {
            var subItems, c;
            for (var i = 0; i < items.length; i++) {
                p = items[i];
                c = p.subItems.findById(id);
                if (c != null) return { id: c.id, name: c.name, parObj: { id: p.id, name: p.name, parObj: null, subCount: 0} };
            }
        }
        return null;
    },
    otherId: function(parent) {
        var parId = parent.id.toString()
        return parId.substring(0, 2) + _OTHERID;
    },
    isOther: function(subItem) {
        if (null == subItem.parObj) return false;
        var otherId = this.otherId(subItem.parObj);
        return otherId == subItem.id;
    },
    itemName: function(item) {
        return item.name;
        if (this._type == "C_CODE_ABBR_LOCATION" && this._isSingle) {
            if (item.text && item.text.length > 0)
                return item.parObj.name + "·" + item.text;
            else if (item.parObj != null) {
                if (PopupSelectorB.isOther(item))
                    return item.parObj.name;
                else
                    return item.parObj.name == item.name ? item.name : item.parObj.name + "·" + item.name;
            }
            else
                return item.name;
        }
        else
            return item.name;
    },
    allTypeItems: []
};
var PopupSelectorControl = function(dataItem, type, moduleId, propName, itemIndex, childIndex) {
    this._dataItem = dataItem;
    this._type = type;
    this._moduleId = moduleId;
    this._propName = propName;
    this._itemIndex = (arguments.length > 3) ? itemIndex : null;
    this._childIndex = (arguments.length > 4) ? childIndex : null;
    this._value = [];
    var _self = this;

    var ctlProp = JQ("#" + this.ctl("txt"))[0];
    if (typeof (ctlProp.getValidity) != "function") {
        ctlProp.getValidity = function() {
            var valid = !(this.value.length == 0 || this.value == "0");
            if (valid && _self._type == "C_CODE_ABBR_OCCUPATION") {
                var showInfo = false;
                for (var i = 0; i < _self._value.length; i++) {
                    var item = _self._value[i];
                    if (item.parObj == null && item.subCount > 0) {
                        showInfo = true;
                        break;
                    }
                }
                if (showInfo) JQ("#" + _self.ctl("info")).addClass("errtip");
                else JQ("#" + _self.ctl("info")).removeClass("errtip");
            }
            if (valid == false) JQ("#" + _self.ctl("info")).removeClass("errtip");
            if (JQ("#" + _self.ctl("v")).length > 0) JQ("#" + _self.ctl("v"))[0].style.backgroundColor = valid ? "#ffffff" : "#ffffd9";
            return valid;
        }
    }

    ctlProp.setValue = function(value) {
        this.value = value;
        _self.initEdit();
    }
}
jQuery.extend(PopupSelectorControl.prototype, {
    _ctlView: null,
    _ctlLargeCategory: null,
    _ctlSubCategory: null,
    _ctlText: null,
    _moduleId: null,
    _maxSize: 5,
    _writeText: false,
    _allowSelectedLargeCategory: true,

    popup: function() {
        PopupSelectorB.popup(this._type, this._propName, this._maxSize, this._value, this._writeText, this._allowSelectedLargeCategory, this.setValue.bind(this));
    },
    setValue: function(items) {
        this._value = items;
        this.setView();
    },
    ctl: function(type, id) {
        var name = type + this._moduleId + "_" + this._propName;
        if (arguments.length > 1) name = name + id;
        if (this._itemIndex != null) name = name + "__i" + this._itemIndex;
        if (this._childIndex != null) name = name + "__c" + this._childIndex;
        return name;
    },

    setView: function() {
        var names = [];
        var largeCategories = [];
        var subCategories = [];
        var _self = this;
        var text = null;
        jQuery.each(_self._value, function() {
            if (this.parObj != null) {
                largeCategories.push(this.parObj.id);
            }
            else largeCategories.push(this.id);
            if (_self._writeText && PopupSelectorB.isOther(this)) {
                subCategories.push(_OTHERID);
                this.id = PopupSelectorB.otherId(this.parObj);
                names.push(PopupSelectorB.itemName(this));
                JQ("#" + _self.ctl("txt", "Text")).val(dbcToSbc(this.text));
            }
            else {
                subCategories.push(this.id);
                names.push(PopupSelectorB.itemName(this));
            }
        });

        JQ("#" + this.ctl("v")).html(dbcToSbc(names.join("+")));
        JQ("#" + this.ctl("txt")).val(subCategories.join(","));
        JQ("#" + this.ctl("txt", "Parent")).val(largeCategories.join(","));

        ObjectSys.validateControl(JQ("#" + this.ctl("txt"))[0]);
        _self._dataItem.setDirty();
    },
    initEdit: function() {
        var _self = this;
        _self._value = [];
        var itemIds = JQ("#" + _self.ctl("txt"))[0].value.split(",");
        JQ.each(itemIds, function() {
            expItem = PopupSelectorB.findItem(_self._type, this);
            if (expItem != null) _self._value.push(expItem);
        });

        if (this._maxSize == 1 && _self._value.length == 1) {
            var item = _self._value[0];
            var tmpName = PopupSelectorB.itemName(item);
            JQ("#" + this.ctl("v")).html(tmpName);
        }
        else {
            var names = [];
            jQuery.each(_self._value, function() {
                names.push(this.name);
            });
            JQ("#" + this.ctl("v")).html(names.join("+"));
        }
    }
});    

