var ShowTime = 500;
var show = null;
var hide = null;
var ShowplayMode = true;
var PageName = "/SearchResult.aspx";
var index = 1;
var ShowAllTips = false;

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;
    },
    GetFather: function(item){
        for (var i = 0; i < this.length; i++) {
            if (this[i].parObj == null) 
                continue;
            if (this[i].parObj.id == item.id) 
                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);
    }
});
var requestFromStr = {
    QueryString: function(Str, val){
        var uri = Str.substring(0, 1) == "?" ? Str : "?" + Str;
        var re = new RegExp("[&?]" + val + "=([^&?]*)", "ig");
        return ((uri.match(re)) ? (uri.match(re)[0].substr(val.length + 2)) : "");
    }
};
function locConverter(locIDs){
    var arrLoc = locIDs.split(",");
    var temp = [];
    for (var i = 0; i < arrLoc.length; i++) {
        temp.push(ConverterLoc(arrLoc[i]));
    }
    return temp;
}

function traversal(id, items){
    var p = items.findById(id);
    if (p != null) {
        return {
            id: p.id,
            name: p.name,
            parObj: null
        };
    }
    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
                    }
                };
        }
    }
    return null;
}

function dbcToSbc(str){
    return str.replace(/（/g, "(").replace(/）/g, ")");
}

var PopupSelector = {
	clear: function() {
		this._selItems.cat = []; 
		this._selItems.loc = []; 
		this._selItems.ind= []; 
	},
    loadSelected: function(url){
        var temp = [];
        var selCatParentIDs = __occParentIDList; 
        if (selCatParentIDs.indexOf(",") > 0) 
            selCatParentIDs = selCatParentIDs.split(",");
        else {
            selCatParentIDs = selCatParentIDs.replace(/%2C/g, "%2c");
            selCatParentIDs = selCatParentIDs.split("%2c");
        }
        var selCatIDs = __occIDList;
        if (selCatIDs.indexOf(",") > 0) 
            selCatIDs = selCatIDs.split(",");
        else {
            selCatIDs = selCatIDs.replace(/%2C/g, "%2c");
            selCatIDs = selCatIDs.split("%2c");
        }
        var addCatID = "";
        if (addCatID != "") {
            selCatIDs.clear();
            selCatIDs[0] = addCatID;
        }
        this._selItems["cat"].clear();
        var allCats = getCat();
        if (addCatID != "" || selCatParentIDs == "") {
            var catItem;
            for (var i = 0; i < selCatIDs.length; i++) {
                catItem = traversal(selCatIDs[i], allCats);
                if (catItem != null) {
                    this._selItems["cat"].push(catItem);
                    temp.push(catItem.name);
                }
            }
        }
        if (selCatIDs.length > 0 && selCatIDs[0] != "" && selCatParentIDs != "" && addCatID == "") {
            for (var i = 0; i < selCatParentIDs.length; i++) {
                if (selCatParentIDs[i] == selCatIDs[i]) {
                    if (selCatIDs[i] != 255) {
                        var catItem = allCats.findById(selCatIDs[i]);
                        this._selItems["cat"].push({
                            id: catItem.id,
                            name: catItem.name,
                            parObj: null
                        });
                        temp.push(catItem.name);
                    }
                }
                else {
                    var parCatItem = allCats.findById(selCatParentIDs[i]);
                    var subCatItem = parCatItem.subItems.findById(selCatIDs[i]);
                    this._selItems["cat"].push({
                        id: subCatItem.id,
                        name: subCatItem.name,
                        parObj: {
                            id: parCatItem.id,
                            name: parCatItem.name,
                            parObj: null
                        }
                    });
                    temp.push(subCatItem.name);
                }
            }
        }
        $("#txtCat").val(temp.join("+"));
        temp.length = 0;
                var selIndIDs = __indIDList;
        selIndIDs = ConverterInd(selIndIDs.replace(/%2C/g, "%2c").replace(/%2c/g, ",")).split(",");
        var addIndID = $.cookie("addIndIDList");
        var allInds = getInd();
        var addIndItem = allInds.findById(addIndID);
        this._selItems["ind"].clear();
        if (addIndItem != null) {
            this._selItems["ind"].push({
                id: addIndItem.id,
                name: addIndItem.name,
                parObj: null
            });
            temp.push(addIndItem.name);
        }
        if (selIndIDs.length > 0 && selIndIDs[0] != "" && addIndItem == null) {
            for (var i = 0; i < selIndIDs.length; i++) {
                if (selIndIDs[i] != 255) {
                    var indItem = allInds.findById(selIndIDs[i]);
                    if (indItem == null) 
                        continue;
                    this._selItems["ind"].push({
                        id: indItem.id,
                        name: indItem.name,
                        parObj: null
                    });
                    temp.push(indItem.name);
                }
            }
        }
        $("#txtInd").val(temp.join("+"));
        temp.length = 0;
        var selLocParentIDs = __myLocParentIDList;
        selLocParentIDs = locConverter(selLocParentIDs.replace(/%2C/g, "%2c").replace(/%2c/g, ","));
        var selLocIDs = __myLocIDList;
        selLocIDs = locConverter(selLocIDs.replace(/%2C/g, "%2c").replace(/%2c/g, ","));
        var addLocID = "";
        if (addLocID != "") {
            selLocIDs.clear();
            selLocIDs[0] = addLocID;
        }
        this._selItems["loc"].clear();
        var allLocs = getLoc();
        if (addLocID != "" || selLocParentIDs == "") {
            var locItem;
            for (var i = 0; i < selLocIDs.length; i++) {
                locItem = traversal(selLocIDs[i], allLocs);
                if (locItem != null) {
                    this._selItems["loc"].push(locItem);
                    temp.push(locItem.name);
                }
            }
        }
        if (selLocIDs.length > 0 && selLocIDs[0] != "" && selLocParentIDs != "" && addLocID == "") {
            for (var i = 0; i < selLocParentIDs.length; i++) {
                if (selLocParentIDs[i] == selLocIDs[i]) {
                    if (selLocIDs[i] != 255) {
                        var locItem = allLocs.findById(selLocIDs[i]);
                        this._selItems["loc"].push({
                            id: locItem.id,
                            name: locItem.name,
                            parObj: null
                        });
                        temp.push(locItem.name);
                    }
                }
                else {
                    var parLocItem = allLocs.findById(selLocParentIDs[i]);
                    var subLocItem = parLocItem.subItems.findById(selLocIDs[i]);
                    this._selItems["loc"].push({
                        id: subLocItem.id,
                        name: subLocItem.name,
                        parObj: {
                            id: parLocItem.id,
                            name: parLocItem.name,
                            parObj: null
                        }
                    });
                    temp.push(subLocItem.name);
                }
            }
        }
        $("#txtLoc").val(temp.join("+"));
        temp.length = 0;
    },
    popup: function(type, ref){
        if (this._box == null) 
            this._box = $("#popupSelector");
        if (this._subBox == null) 
            this._subBox = document.getElementById("subItems");  //类别窗口
        this._ref = ref;
        this._type = type.toString().toLowerCase();
        this._curItems = this._selItems[this._type].clone();
        var offset = $(ref).offset();
        this._style.left = offset.left;
        this._style.top = offset.top;
        this.render();
        
    },
    render: function(){
        var pos = {
            top: (this._style.top + this._style.offset.levelOne.Y),
            left: this._style.left + this._style.offset.levelOne.X
        };
        if (this._type != "cat" && this._type != "comptype") {
            pos.left -= (this._style.width[this._type] - 384);
        }
        var remainHeight = $(window).height() - pos.top + document.documentElement.scrollTop;
        if (remainHeight < this._style.height[this._type]) 
            pos.top = pos.top - (this._style.height[this._type] - remainHeight);
        if (this._style.height[this._type] > $(window).height()) 
            pos.top = document.documentElement.scrollTop;
        var pslayer = $("#pslayer");
        for (var i = 0; i < this._types.length; i++) {
            pslayer.removeClass(this._style.className.levelOne[this._types[i]]);
        }
        pslayer.addClass(this._style.className.levelOne[this._type]);
        $("#selectingHeader").html(this._gtYourSelected[this._type]);
        $("#psHeader").html(this._gtPopupSelectorHeader[this._type]);
        var html = [];
        var parItems = this.allItems[this._type]();
        var start = 0;
        var end = parItems.length;
        if (this._type == "loc") {
            start = 1;
            end = 32;
            $("#subHeader1").html("<span>所有省市：</span>");
            
            for (var i = end; i < parItems.length; i++) {
                html.push("<li id=$" + i + " name=" + parItems[i].id + "class=\"nonelay\"><input id=\"");
                html.push(parItems[i].id);
                html.push("\" type=\"checkbox\" value=\"");
                html.push(parItems[i].id);
                html.push("@");
                html.push(parItems[i].name);
                html.push("\"");
                if (this._curItems.has({
                    id: parItems[i].id,
                    name: parItems[i].name,
                    parObj: null
                })) 
                    html.push(" checked");
                html.push(" onclick=\"PopupSelector.click(" + i + ",this, null," + parItems[i].id + ")\" />");
                html.push("<label for='" + i + "' >"+parItems[i].name+"</label>");
                html.push("</li>");
            }
            $("#subHeader1").show();
            $("#subHeader2").show();
            $("#allItems2").html(html.join("")).show();
        }
        else {
            $("#subHeader1").hide();
            $("#subHeader2").hide();
            $("#allItems2").hide();
        }
        html = [];
        for (var i = start; i < end; i++) {
            var parItem = parItems[i];
            if (parItem.subItems && parItem.subItems.length > 1) {
                if (this._type != "ind") {
                    if (this._curItems.has({
                        id: parItem.id,
                        name: parItem.name,
                        parObj: null
                    }) ||
                    this._curItems.GetFather({
                        id: parItem.id,
                        name: parItem.name,
                        parObj: null
                    })) 
                        html.push("<li id=$" + i + " name=" + parItem.id + " class=\"layicon\" onmouseover=\"PopupSelector.showSubItems(");
                    else 
                        html.push("<li id=$" + i + " name=" + parItem.id + " onmouseover=\"PopupSelector.showSubItems(");
                }
                else 
                    html.push("<li id=$" + i + " name=" + parItem.id + " onmouseover=\"PopupSelector.showSubItems(");
                html.push(i);
                html.push(", this, true)\" onmouseout=\"PopupSelector.hideSubItems(this)\">");
            }
            else {
                if (this._curItems.has({
                    id: parItem.id,
                    name: parItem.name,
                    parObj: null
                })) 
                    html.push("<li id=$" + i + " name=" + parItem.id + " class=\"layon\">");
                else 
                    html.push("<li id=$" + i + " name=" + parItem.id + " class=\"nonelay\">");
            }
            html.push("");
           // if (this._type == "ind") {
                html.push("<label for=\"pcbx");
                html.push(parItem.id);
                html.push("\">");
            //}
            html.push("<input id=\"pcbx");
            html.push(parItem.id);
            html.push("\" type=\"checkbox\" value=\"");
            html.push(parItem.id);
            html.push("@");
            html.push(parItem.name);
            html.push("\"");
            if (this._curItems.has({
                id: parItem.id,
                name: parItem.name,
                parObj: null
            })) 
                html.push(" checked");
            html.push(" onclick=\"PopupSelector.click(");
            html.push(i + ",this, null," + parItem.id + ")\" />");
            html.push(dbcToSbc(parItem.name));
            //if (this._type == "ind") {
                html.push("</label>");
            //}
            html.push("</li>");
        }
        $("#allItems1").html(html.join("").toString());
        html.length = 0;
        $("#divSelecting").css("display", (this._curItems.length == 0) ? "none" : "block");
        var displayNoSelected = (this._curItems.length == 0) ? "block" : "none";
        if (this._type == "cat") {
            $("#noSelectedCat").css("display", displayNoSelected);
            $("#noSelectedLoc").hide();
        }
        else 
            if (this._type == "loc") {
                $("#noSelectedLoc").css("display", displayNoSelected);
                $("#noSelectedCat").hide();
            }
            else {
                $("#noSelectedCat").hide();
                $("#noSelectedLoc").hide();
            }
        for (var i = 0; i < this._curItems.length; i++) {
            html.push("<li id=\"");
            html.push(this._curItems[i].id);
            html.push("\"><a href=\"###\" title=\"点击取消该项\" onclick=\"PopupSelector.remove(");
            html.push(this._curItems[i].id);
            if (this._curItems[i].parObj != null) 
                html.push("," + this._curItems[i].parObj.id + ")\">");
            else 
                html.push(")\">");
            html.push(dbcToSbc(this._curItems[i].name));
            html.push("</a></li>");
        }
        
        $("#selecting").html(html.join(""));
        if (this._type == "ind") {
            $("#divSelecting").show();
            $("#selecting").hide();
        }
        else 
            $("#selecting").show();
        $("#shield").width(this._style.width[this._type]).height(this._style.height[this._type]);
        $(this._box).css(pos).show();
        $("#mask").height($(document).height()).show();
    },
    close: function(){
        $("#mask").hide();
        this._ref = null;
        $(this._box).hide();
    },
    OK: function(){
        var temp = [];
        jQuery.each(this._curItems, function(){
           temp.push(this.name);
        });
        $(this._ref).val(dbcToSbc(temp.join("+")));
        this._ref = null;
        this._selItems[this._type] = this._curItems.clone();
        this._curItems.clear();
        $("#selecting").html("");
        $("#mask").hide();
        $(this._box).hide();
    },
    empty: function(){
        $("#selecting").html("");
        $("#allItems1 input").each(function(i){
            this.checked = false;
        });
        $("#allItems2 input").each(function(i){
            this.checked = false;
        });
        $("#allItems1 li").each(function(i){
            if (this.className == "layicon") 
                this.className = "";
            if (this.className == "layon") 
                this.className = "nonelay";
        });
        this._curItems.clear();
        PopupSelector.showtips();
    },
    click: function(ref, cbx, parObj, parName){
        if (cbx.checked && this._curItems.length == this._maxSize) {
            alert(this._gtMaxLimit);
            cbx.checked = false;
            return;
        }
        var item = {
            id: cbx.value.split("@")[0],
            name: cbx.value.split("@")[1],
            parObj: parObj
        };
        var selecting = document.getElementById("selecting");
        var selItem = null;
        if (cbx.checked) {
            selItem = document.createElement("li");
            selItem.id = item.id;
            if (parObj == null) 
                selItem.innerHTML = "<a href=\"###\" title=\"点击取消该项\" onclick=\"PopupSelector.remove(" + item.id + ",null);\">" + dbcToSbc(item.name) + "</a>";
            else 
                selItem.innerHTML = "<a href=\"###\" title=\"点击取消该项\" onclick=\"PopupSelector.remove(" + item.id + "," + parObj.id + ");\">" + dbcToSbc(item.name) + "</a>";
            selecting.appendChild(selItem);
            this._curItems.push(item);
            if (parObj != null) {
                document.getElementById('^' + ref).className = "layon";
                var id = parObj.id;
                $("li[@name=" + id + "]").addClass("layicon");
            }
            this.showHideSelecting(this);
        }
        else {
            selItem = document.getElementById(item.id);
            selecting.removeChild(selItem);
            this._curItems.remove(item.id);
            if (parObj != null) {
                document.getElementById('^' + ref).className = "";
                var id = parObj.id;
                if ($("#subItems ol").html().indexOf('CHECKED') < 0) 
                    $("li[@name=" + id + "]").removeClass("layicon");
            }
            PopupSelector.showtips();
        }
        if (parObj == null) {
            var parItems = this.allItems[this._type]();
            parItem = parItems[ref];
            if (cbx.checked) {
                if (parItem.subItems && parItem.subItems.length > 1) 
                    document.getElementById('$' + ref).className = "layicon";
                else 
                    document.getElementById('$' + ref).className = "layon";
            }
            else {
                if ((parItem.subItems && parItem.subItems.length > 1)) 
                    document.getElementById('$' + ref).className = "";
                else 
                    document.getElementById('$' + ref).className = "nonelay";
            }
            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]);
                }
            }
            $("#subItems input").each(function(i){
                this.checked = this.disabled = cbx.checked;
            });
            if (cbx.checked) 
                $("#subItems li").each(function(i){
                    this.className = "layon";
                });
            else 
                $("#subItems li").each(function(i){
                    this.className = "";
                });
        }
    },
    showtips: function(){
        if (this._curItems.length == 0) {
            if (this._type != "ind") 
                $("#divSelecting").css("display", "none");
            if (this._type == "cat") {
                $("#noSelectedLoc").hide();
                $("#noSelectedCat").show();
            }
            if (this._type == "loc") {
                $("#noSelectedCat").hide();
                $("#noSelectedLoc").show();
            }
        }
    },
    remove: function(id, parObj){
        document.getElementById("selecting").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]);
        }
        if (parObj == null) {
            $("li[@name=" + id + "]").removeClass("layicon");
            $("li[@name=" + id + "]").removeClass("layon");
        }
        else 
            if (!(this._curItems.GetFather({
                id: parObj,
                name: null,
                parObj: null
            }))) 
                $("li[@name=" + parObj + "]").removeClass("layicon");
        PopupSelector.showtips();
    },
    showHideSelecting: function(selector){
        $("#noSelectedCat").hide();
        $("#noSelectedLoc").hide();
        if (selector._curItems.length > 0) {
            $("#divSelecting").show();
        }
    },
    showSubItems: function(index, ref, isDelay, ev){
        var subItems = $("#subItems");
        if (this._hideTimer) 
            clearTimeout(this._hideTimer);
        if (this._showTimer) 
            clearTimeout(this._showTimer);
        if (index == this._lastPopupIndex && subItems.css("display") == "block") {
            $(ref).addClass("layshow");
            return;
        }
        if (!isDelay) 
            loadSubItems(index, ref, this);
        var self = this;
        this._showTimer = setTimeout(function(){
            loadSubItems(index, ref, self);
        }, this._delay);
        function loadSubItems(index, ref, self){
            var parItem = self.allItems[self._type]()[index];
            var offset = $(ref).offset();
            var pos = {
                top: offset.top + self._style.offset.levelTwo[self._type].Y,
                left: offset.left + self._style.offset.levelTwo[self._type].X
            };
            var actualSubItemCount = parItem.subItems.length - 1;
            var calItemCount = (actualSubItemCount % 2 == 0) ? actualSubItemCount / 2 : (actualSubItemCount / 2 + 1);
            if (actualSubItemCount <= self._oneColumnLimit[self._type]) 
                calItemCount = actualSubItemCount;
            var subBoxHeight = self._style.lineHeight * parseInt(calItemCount) + self._style.topBottomMargin;
            var winHeight = $(window).height();
            var remainHeight = winHeight - pos.top + document.documentElement.scrollTop;
            if (remainHeight < subBoxHeight) 
                pos.top = pos.top - (subBoxHeight - remainHeight);
            if (subBoxHeight > winHeight) 
                pos.top = document.documentElement.scrollTop;
            var parentChecked = (ref.getElementsByTagName("input")[0].checked == true) ? " checked disabled " : "";
            var item = {
                id: parItem.id,
                name: parItem.name,
                parObj: null
            };
            var html = [];
            html.push("<ol >");
            for (var i = 1; i < parItem.subItems.length; i++) {
                var subItem = parItem.subItems[i];
                subItem.parObj = item;
                if (ref.getElementsByTagName("input")[0].checked == true || self._curItems.has(subItem)) {
                    html.push("<li id=^" + i + " class=\"layon\"  >");
                }
                else 
                    html.push("<li id=^" + i + "  >");
                html.push("<label for=\"scbx");
                html.push(subItem.id);
                html.push("\"><input id=\"scbx");
                html.push(subItem.id);
                html.push("\" type=\"checkbox\" value=\"");
                html.push(subItem.id);
                html.push("@");
                html.push(subItem.name);
                html.push("\"");
                html.push(parentChecked);
                if (self._curItems.has(subItem)) 
                    html.push(" checked");
                html.push(" onclick=\"PopupSelector.click(" + i + ",this, { id: ");
                html.push(parItem.id);
                html.push(", name: '");
                html.push(parItem.name);
                html.push("', parObj: null }");
                html.push(",'')\" />");
                html.push(dbcToSbc(subItem.name));
                html.push("</label></li>");
            }
            html.push("</ol>");
			html.push("<div class='clear'></div>");
            var subBox = $("#subBox");
            for (var i = 0; i < self._types.length; i++) {
                subItems.removeClass(self._style.className.levelTwo1[self._types[i]]);
                subItems.removeClass(self._style.className.levelTwo2[self._types[i]]);
            }
            var levelTwo = (actualSubItemCount > self._oneColumnLimit[self._type]) ? self._style.className.levelTwo2[self._type] : self._style.className.levelTwo1[self._type];
            self._lastPopupIndex = index;
            $("#subItems").hover(function(e){
                self.showSubItems(index, ref, true, e);
            }, function(e){
                self.hideSubItems(ref);
            });
            subBox.html(html.join(""));
            subItems.addClass(levelTwo).css(pos).show();
        }
    },
    hideSubItems: function(ref){
        $(ref).removeClass("layshow");
        if (this._showTimer) 
            clearTimeout(this._showTimer);
        if (this._hideTimer) 
            clearTimeout(this._hideTimer);
        this._hideTimer = setTimeout(function(){
            $("#subItems").hide();
        }, 100);
    },
    _showTimer: null,
    _hideTimer: null,
    _lastPopupIndex: null,
    _box: null,
    _subbox: null,
    _ref: null,
    _type: null,
    _types: ["cat", "ind", "loc", "comptype"],
    _maxSize: 5,
    _curItems: [],
    _selItems: {
        cat: [],
        loc: [],
        ind: [],
        comptype: []
    },
    _gtMaxLimit: "对不起,您的已选项已经达到了5项.请减少已选项,再继续选择",
    _gtYourSelected: {
        cat: "您选择的职位类别是：",
        ind: "您最多可以选择５个行业类别",
        loc: "您选择的工作地点是：",
        comptype: "您选择的公司性质是："
    },
    _gtPopupSelectorHeader: {
        cat: "职位类别",
        ind: "行业类别",
        loc: "地点",
        comptype: "公司性质"
    },
    _oneColumnLimit: {
        cat: 12,
        loc: 11
    },
    _delay: 500,
    _style: {
        className: {
            levelOne: {
                "cat": "lay_wl",
                "loc": "lay_wls",
                "ind": "lay_wll",
                "comptype": "lay_wms"
            },
            levelTwo1: {
                "cat": "lay_wm",
                "loc": "lay_wss",
                "ind": "",
                "comptype": ""
            },
            levelTwo2: {
                "cat": "lay_wl2",
                "loc": "lay_ws",
                "ind": "",
                "comptype": ""
            }
        },
        left: 0,
        top: 0,
        width: {
            "cat": 594,
            "loc": 466,
            "ind": 746,
            "comptype": 360
        },
        height: {
            "cat": 517,
            "loc": 419,
            "ind": 510,
            "comptype": 173
        },
        lineHeight: 20,
        topBottomMargin: 17,
        offset: {
            levelOne: {
                X: 0,
                Y: 20
            },
            levelTwo: {
                "cat": {
                    X: 284,
                    Y: 0
                },
                "loc": {
                    X: 85,
                    Y: 0
                }
            }
        }
    },
    allItems: {
        cat: function(){
            return getCat();
        },
        ind: function(){
            return getInd();
        },
        loc: function(){
            return getLoc();
        },
        comptype: function(){
            return getCompanyType();
        }
    }
};
$(function(){
    $("#txtCat").click(function(){
        PopupSelector.popup("cat", this);
    });
    $("#txtInd").click(function(){
        PopupSelector.popup("ind", this);
    });
    $("#LocList,#LocList_down").click(function(){
        PopupSelector.popup("loc", $("#LocList").get(0));
    });
	
    $("#PositionList,#PositionList_down").click(function(){
        PopupSelector.popup("cat", $("#PositionList").get(0));
    });
    $("#IndustryList,#IndustryList_down").click(function(){
        PopupSelector.popup("ind", $("#IndustryList").get(0));
    });
    $("#txtLocDrop").click(function(){
        PopupSelector.popup("loc", $("#txtLoc")[0]);
    });
    $("#lnkEmpty").click(function(){
        PopupSelector.empty();
    });
    $("#lnkCancel").click(function(){
        PopupSelector.cancel();
    });
    $("#lnkOK").click(function(){
        PopupSelector.OK();
    });
    $("#btnOk").click(function(){
        PopupSelector.OK();
    });
    $("#btnOkLoc").click(function(){
        PopupSelector.OK();
    });
    $("#imgClose").click(function(){
        PopupSelector.close();
    });
    
    if (typeof(HTMLElement) != "undefined") {
        HTMLElement.prototype.contains = function(obj){
            while (obj != null && typeof(obj.tagName) != "undefined") {
                if (obj == this) 
                    return true;
                obj = obj.parentNode;
            }
            return false;
        };
    }
    
    $("#Categroy LI").mouseover(function(e){
		this.className = "checked";
        var CatNum = this.value;
        var CurCatid = this.id;
        var theevent = e || window.event;
        ShowSubMenu(CatNum, CurCatid, theevent);
    });
    $("#Categroy LI").click(function(){
        var CatNum = this.value;
        var CurCatid = this.id;
        var event = arguments[0] || window.event;
        ShowSubMenu(CatNum, CurCatid, event);
    });
    $("#Categroy LI").mouseout(function(){
		this.className = "";
        var event = arguments[0] || window.event;
        HideSubMenu(event);
    });
    
    $(".tab_two > h2").click(function(){
        if (!$(this).hasClass("checked")) {
            $(".tab_two > h2").toggleClass("checked");
            $(".main_l > ul").toggle();
        }
    });
    
	if (typeof __occParentIDList !== "undefined") PopupSelector.loadSelected();
});

function getCat(){
	
	var tpl_array = [];
	var _tmp_obj = {};
	var _layer_1_vals = [];
	var _layer_2_vals = [];
	
	for (var i in s_position) {
		
		_tmp_obj = {};
		_layer_1_vals = i.split("|");
		
		_tmp_obj.id = _layer_1_vals[0];
		_tmp_obj.name = _layer_1_vals[1];
		_tmp_obj.subItems = [];
		
		
		
		for (var j = 0 ; j <s_position[i].length ; j++) {
			
			_layer_2_vals = s_position[i][j].toString().split("|");
			
			if (j == 0 && _layer_2_vals[1] != _layer_1_vals[1]) {
				_tmp_obj.subItems.push(
					{
						id:_layer_1_vals[0],
						name:_layer_1_vals[1]
					}
				);
			}
			
			_tmp_obj.subItems.push(
				{
					id:_layer_2_vals[0],
					name:_layer_2_vals[1]
				}
			);
			
		}
		
		tpl_array.push(_tmp_obj);
		
	}
	
	return tpl_array;
	
}

function getLoc(){
	
	var tpl_array = [];
	var _tmp_obj = {};
	var _layer_1_vals = [];
	var _layer_2_vals = [];
	
	for (var i in s_area) {
		
		_tmp_obj = {};
		_layer_1_vals = i.split("|");
		
		_tmp_obj.id = _layer_1_vals[0];
		_tmp_obj.name = _layer_1_vals[1];
		_tmp_obj.subItems = [];
		
		for (var j = 0 ; j <s_area[i].length ; j++) {
			
			_layer_2_vals = s_area[i][j].toString().split("|");
			
			if (j == 0 && _layer_2_vals[1] != _layer_1_vals[1]) {
				_tmp_obj.subItems.push(
					{
						id:_layer_1_vals[0],
						name:_layer_1_vals[1]
					}
				);
			}
			
			_tmp_obj.subItems.push(
				{
					id:_layer_2_vals[0],
					name:_layer_2_vals[1]
				}
			);
			
		}
		
		tpl_array.push(_tmp_obj);
		
	}
	
	tpl_array.unshift({
        id: "-1",
        name: "请选择工作地点",
        subItems: [{
            id: "-1",
            name: "请选择工作地点"
        }, {
            id: "30000",
            name: "北京"
        }, {
            id: "31000",
            name: "上海"
        }, {
            id: "40",
            name: "广州"
        }, {
            id: "125",
            name: "深圳"
        }, {
            id: "220",
            name: "苏州"
        }, {
            id: "225",
            name: "东莞"
        }, {
            id: "55",
            name: "杭州"
        }, {
            id: "32000",
            name: "天津"
        }, {
            id: "160",
            name: "西安"
        }, {
            id: "150",
            name: "武汉"
        }, {
            id: "100",
            name: "南京"
        }, {
            id: "15",
            name: "长沙"
        }, {
            id: "20",
            name: "成都"
        }, {
            id: "30",
            name: "大连"
        }, {
            id: "12000",
            name: "山东"
        }, {
            id: "10000",
            name: "福建"
        }, {
            id: "33000",
            name: "重庆"
        }]
    });
	
	return tpl_array;
	
}

function getInd(){
	
	var tpl_array = [];
	var _tmp_obj = {};
	var _layer_1_vals = [];
	
	for (var i = 0 ; i <s_industry.length ; i++) {
		
		_tmp_obj = {};
		_layer_1_vals = s_industry[i].split("|");
		
		_tmp_obj.id = _layer_1_vals[0];
		_tmp_obj.name = _layer_1_vals[1];		
		
		tpl_array.push(_tmp_obj);
		
	}
	
	return tpl_array;
   
}



function LoadSubMenu(CatNum, CurCatid){
    var top = 0;
    document.getElementById("Subcat").style.top = "222px";
    document.getElementById("SubCatTwo").style.top = "222px";
    document.getElementById("Subcat").style.top = toPixel(document.getElementById("Subcat").style.top) + getY(document.getElementById(CurCatid)) - 228 + "px";
    document.getElementById("SubCatTwo").style.top = toPixel(document.getElementById("SubCatTwo").style.top) + getY(document.getElementById(CurCatid)) - 228 + "px";
    var items = [];
    var allCats = getCat();
    var url = PageName + "?prj=occ&occIDList={0}"
    items.push("<h4>");
    items.push("<a href=\"/search/result.php?p=");
    items.push(encodeURIComponent(allCats[CatNum].subItems[0].name));
    items.push("\"");
    items.push(">");
    items.push("[" + allCats[CatNum].subItems[0].name + "]")
    items.push("</a></h4>");
    if (allCats[CatNum].subItems.length > 1) {
        items.push("<ol>");
        for (var i = 1; i < allCats[CatNum].subItems.length; i++) {
            items.push("<li onmouseover=\"cancelEvent(event)\" onmouseout=\"cancelEvent(event)\" ><a href=\"");
            items.push("/search/result.php?p=");
            items.push(encodeURIComponent(allCats[CatNum].subItems[i].name));
            items.push("\"");
            items.push(">");
            items.push(allCats[CatNum].subItems[i].name);
            items.push("</a></li>");
        }
        items.push("</ol>");
    }
    var theevent = arguments[0] || window.event;
    if (allCats[CatNum].subItems.length > 33) {
        $("#Subcat").hide();
        $("#SubCatTwo").show();
        ShowplayMode = false;
        document.getElementById("SubCatTwo").onmouseover = function(e){
            if (!e) 
                e = window.event;
            ShowSubMenu(CatNum, CurCatid, e);
        };
        document.getElementById("SubCatTwo").onmouseout = function(e){
            if (!e) 
                e = window.event;
            HideSubMenu(e);
        };
        $("#containerTwo").html(items.join(""));
    }
    else {
        $("#Subcat").show();
        ShowplayMode = true;
        $("#SubCatTwo").hide();
        $("#container").html(items.join(""));
        $("#Subcat").hover(function(){
            ShowSubMenu(CatNum, CurCatid, theevent)
        }, function(){
            HideSubMenu(theevent);
        });
    }
    var TrueTop = 0;
    var TrueHeight = 0;
    if (document.getElementById("SubCatTwo").style.display == "none") {
        TrueTop = getY(document.getElementById("Subcat"));
        TrueHeight = document.getElementById("Subcat").offsetHeight;
    }
    else {
        TrueTop = getY(document.getElementById("SubCatTwo"));
        TrueHeight = document.getElementById("SubCatTwo").offsetHeight;
    }
    yScroll = Geometry.getVerticalScroll();
    var winHeight = $(window).height();
    if (TrueTop + TrueHeight - yScroll > winHeight) {
        document.getElementById("Subcat").style.top = toPixel(document.getElementById("Subcat").style.top) - (TrueTop + TrueHeight - winHeight - yScroll) + "px";
        document.getElementById("SubCatTwo").style.top = toPixel(document.getElementById("SubCatTwo").style.top) - (TrueTop + TrueHeight - winHeight - yScroll) + "px";
    }
}

function ShowSubMenu(CatNum, CurCatid, Theevent){
    var browser = navigator.userAgent;
    if (browser.indexOf("Firefox") > 0) {
        if (document.getElementById('SubCatTwo').contains(Theevent.relatedTarget)) 
            return;
        if (document.getElementById('Subcat').contains(Theevent.relatedTarget)) 
            return;
    }
    if (browser.indexOf("MSIE") > 0) {
        if (document.getElementById('SubCatTwo').contains(event.toElement)) 
            return;
        if (document.getElementById('Subcat').contains(event.toElement)) 
            return;
    }
    if (hide) 
        window.clearTimeout(hide);
    if (show) 
        window.clearTimeout(show);
    show = window.setTimeout(function(){
        LoadSubMenu(CatNum, CurCatid);
    }, ShowTime);
}

function HideSubMenu(Theevent){
    var browser = navigator.userAgent;
    if (browser.indexOf("Firefox") > 0) {
        if (document.getElementById('SubCatTwo').contains(Theevent.relatedTarget)) 
            return;
        if (document.getElementById('Subcat').contains(Theevent.relatedTarget)) 
            return;
    }
    if (browser.indexOf("MSIE") > 0) {
        if (document.getElementById('SubCatTwo').contains(event.toElement)) 
            return;
        if (document.getElementById('Subcat').contains(event.toElement)) 
            return;
    }
    if (show) 
        clearTimeout(show);
    if (hide) 
        clearTimeout(hide);
    if (ShowplayMode) 
        hide = window.setTimeout(function(){
            $("#Subcat").hide();
        }, 100);
    else 
        hide = window.setTimeout(function(){
            $("#SubCatTwo").hide();
        }, 100);
}

function toPixel(str1){
    var oldLen = str1.length;
    var newLen = oldLen - 2;
    str2 = str1.slice(0, newLen);
    str3 = parseInt(str2);
    return str3;
}

function cancelEvent(e){
    if (!e) 
        e = window.event;
    if (e.preventDefault) {
        e.stopPropagation();
        e.preventDefault();
    }
    else {
        e.cancelBubble = true;
        e.returnValue = false;
    }
}

function getY(el){
    var y = 0;
    for (var e = el; e; e = e.offsetParent) 
        y += e.offsetTop;
    for (e = el.parentNode; e && e != document.body; e = e.parentNode) 
        if (e.scrollTop) 
            y -= e.scrollTop;
    return y;
}

function getX(el){
    var x = 0;
    while (el) {
        x += el.offsetLeft;
        el = el.offsetParent;
    }
    return x;
}

var Geometry = {};
Geometry.getVerticalScroll = function(){
    return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
};

function company_type_selector_do() {
	var iHtml = [];
	$("#company_type_selector input[@checked=1]").each(function(){
		iHtml.push(this.value);
	})
	$("#comapny_type").val(iHtml.join("+"));
	$("#company_type_selector").hide();
	$('#salary').show();
}


function search_it() {
	
	return true;
	
}


function ConverterLoc(obj){
    var Item;
    switch (obj) {
        case "5":
            Item = "30000";
            break;
        case "115":
            Item = "31000";
            break;
        case "140":
            Item = "32000";
            break;
        case "25":
            Item = "33000";
            break;
        case "185":
            Item = "34000";
            break;
        case "190":
            Item = "35000";
            break;
        case "195":
            Item = "36000";
            break;
        case "200":
            Item = "37000";
            break;
        case "205":
            Item = "38000";
            break;
        case "210":
            Item = "39000";
            break;
        case "215":
            Item = "40000";
            break;
        case "230":
            Item = "41000";
            break;
        case "235":
            Item = "42000";
            break;
        default:
            Item = obj;
            break;
    }
    return Item;
}

function ConverterInd(obj){
    var array = new Array();
    var strList = ",";
    array = obj.split(',');
    var SubItem = "";
    for (var i = 0; i < array.length; i++) {
        SubItem = ConverterIndSubItem(array[i].toString());
        strList += SubItem + ",";
    }
    strList = TrimLR(strList, ',');
    return strList;
}

function ConverterIndSubItem(obj){
    var Item;
    switch (obj) {
        case "1107000":
            Item = "100";
            break;
        case "1108000":
            Item = "100";
            break;
        case "1109000":
            Item = "100";
            break;
        case "1117000":
            Item = "3700";
            break;
        case "1110000":
            Item = "1000";
            break;
        case "1111000":
            Item = "1000";
            break;
        case "1112000":
            Item = "1000";
            break;
        case "1119000":
            Item = "2200";
            break;
        case "1120000":
            Item = "2200";
            break;
        default:
            Item = obj;
            break;
    }
    return Item;
}


function LTrim(str, delStr){
    var whitespace = new String(delStr);
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(0)) != -1) {
        var j = 0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1) {
            j++;
        }
        s = s.substring(j, i);
    }
    return s;
};
function RTrim(str, delStr){
    var whitespace = new String(delStr);
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(s.length - 1)) != -1) {
        var i = s.length - 1;
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) {
            i--;
        }
        s = s.substring(0, i + 1);
    }
    return s;
};
function TrimLR(str, delStr){
    return RTrim(LTrim(str, delStr), delStr);
};

function ct_change(f) {
	
	if (f == 0) {
		
		$.cookie("show_type","simply",{path:"/"});
		
	/*	$("#ctrl_simply").addClass("checked");
		$("#ctrl_detail").removeClass("checked");
		
		$("#display_simply").show();
		$("#display_detail").hide();
	*/
		document.forms['show_detail_title'].elements['showtypelink'].value='0';
		$('#show_detail_title').submit();
	} else {
		
		$.cookie("show_type","detail",{path:"/"});
		
	/*	$("#ctrl_simply").removeClass("checked");
		$("#ctrl_detail").addClass("checked");
		
		$("#display_simply").hide();
		$("#display_detail").show();
	*/
		document.forms['show_detail_title'].elements['showtypelink'].value='1';
		$('#show_detail_title').submit();
	}
}

function searcher_add(){
    if (loginBox._getLoginType() == 1) {
		$(".save_con").show('fast');
	} else {
		if (confirm("只有个人会员才能操作，请登录或免费注册！")) {
			location.href = '/personal/login.html?sc=se_sher';
		}
	}
}

function searcher_submit(o) {
	var searcher_name_val = $.trim($("#searcher_name").val());
	if (searcher_name_val == "") {
		alert("请输入保存搜索器的名称！");
		$("#searcher_name").select();
		return false;
	}
	$.post("/process/",{
		formAction : "job_addsearcher",
		searcher_name : searcher_name_val,
		searcher_alert : $("#searcher_alert").attr("checked"),
		searcher_count : $("#searcher_count").val(),
		searcher_conditions : $("#searcher_params").val()
	},function() {
		$("#add_searcher_form").hide().next().show();
		$("#return_searcher_name").html($.trim($("#searcher_name").val()));
	});
	return false;
}

function job_op(op) {
	
	if ($("input[@name^=checkbox][checked=1]").length < 1) {
		alert("请至少选择一个职位！");
		
	} else {
	
		switch (op) {
			case "bv":
				var jobs = [];
				$("form[@name=job_action_form] input[@checked=1]").each(function(){
					if ($.inArray($(this).val(), jobs) == -1){
						jobs.push($(this).val());
					}
				});
				$('#jobs').val(jobs.join(','));
				
				document.forms["batch_view"].action = "/search/batch.php";
				document.forms["batch_view"].submit();
				break;
			case "s":
				
				if (loginBox._getLoginType() != 1) {
					if (confirm("只有个人会员才能操作，请登录或免费注册！")) {
						location.href = '/personal/login.html?sc=se_sav';
					}
					
				} else {
				
					var _p_l = [];
					$("form[@name=job_action_form] input[@checked=1]").each(function(){
						if ($.inArray(this.value, _p_l) == -1) 
							_p_l.push(this.value);
					});
					var jobList_str = _p_l.join(",");
					$.post("/process/", {
						formAction: "job_saveJob",
						jobList: jobList_str
					}, function(){
						alert("收藏成功！您可以在个人后台查看^^");
					});
					
				}
				break;
				
			case "a":
				document.forms["job_action_form"].action = "/search/apply_job.php";
				document.forms["job_action_form"].submit();
				break;
		}
		
	}
	
	
}

function check_it(o,id) {
	
	if (o.checked) {
		$("#job_simply_"+id+"_cb").attr('checked',true);
		$("#job_detail_"+id+"_cb").attr('checked',true);
		if ($("#job_detail_" + id + "_li").attr('class') != "to_top" && $("#job_detail_" + id + "_li").attr('class') != "hlight") {
			$("#job_detail_" + id + "_li").attr('class', "checked").attr("s", "yes");
			$("#job_simply_" + id + "_tr").attr('class', "checked").attr("s", "yes");
		}
	} else {
		$("#job_simply_"+id+"_cb").attr('checked',false);
		$("#job_detail_"+id+"_cb").attr('checked',false);
		if ($("#job_detail_" + id + "_li").attr('class') != "to_top" && $("#job_detail_" + id + "_li").attr('class') != "hlight") {
			$("#job_detail_" + id + "_li").attr('class', "").attr("s", "no");
			$("#job_simply_" + id + "_tr").attr('class', "");
		}
	}
	
}

function check_all(o) {
	if (o.checked) {
		$("input[@name^=checkbox]").attr('checked',true);
		$("[@for_all^=yes]").addClass("checked").attr("s","yes");
	} else {
		$("input[@name^=checkbox]").attr('checked',false);
		$("[@for_all^=yes]").removeClass("checked").attr("s","no");
	}
}

function click_comapny_type(){
	$('#company_type_selector').toggle();
	$('#salary').toggle();
	var k=($.trim($("#comapny_type").val())).split("+");
	for(var j=0;j<k.length;j++){
		$("#company_type_selector input[@value='"+k[j]+"']").each(function(){
	            this.checked=1;
		})
	}
}

// 清空搜索框
function cleanUp(obj){
	$(obj).parents('form')
		.find('input[@type=text]').each(function(){
			$(this).val('');
		}).end()
		.find('select').each(function(){
			$(this).attr('selectedIndex', 0);
		}).end()
		.find('input[@type=checkbox]:gt(1)').each(function(){
			$(this).attr('checked', true);
		}).end()
		.find('input[@type=radio]:eq(0)').attr('checked', true).end();
	$('#company_type_selector > dl > dd input[@type=checkbox]').attr('checked', false);
	$('#salary_no').attr('checked', false);
	
	// 清空弹出层
	PopupSelector.clear();
}

function hide_more_filter(type) {
	$("#filter_"+type+"_more").hide();
};
function show_more_filter(type) {
	$("#filter_"+type+"_more").show();
};