if (typeof (window.jQuery) == "undefined")
{
    var s = document.createElement('script');
    s.type = 'text/javascript';
    s.id = 'jquery132min';
    s.src = 'http://my.job978.com/js/jquery/jquery-1.3.2.min.js';
    document.getElementsByTagName('head')[0].appendChild(s);
}
var allowSelectBigClass = "True";
$(document).ready(function()
{
    if (typeof (positions) == "undefined")
    {
        var s = document.createElement('script');
        s.type = 'text/javascript';
        s.id = 'PositionsJs';
        s.src = 'http://my.100038job.com/js/Positions.js';
        document.getElementsByTagName('head')[0].appendChild(s);
    }
});
//大类别

function setBigClassPosition()
{
    var _strHtml = "";
    for (var i = 0; i < positionarray.length; i++)
    {
        if (positionarray[i][1] == 0)
            _strHtml += "<option value='" + positionarray[i][2]+ "'>" + positionarray[i][0] + "</option>";
    }
    return _strHtml;
}
function setSelectClassPosition()
{
    if ($("#sltBigClass option:selected") != null)
    {
        var selectedOption = $("#sltBigClass option:selected");
        var disabled = "";
        var disabledTip = "（选择此大类，将包括以下所有小类）";
        if (allowSelectBigClass == "False")
        {
            disabled = " disabled='disabled'";
            disabledTip = "";
        }
        var _phtml = "<input onclick='setFatherCheckPosition(this)'" + disabled + " id='chkbigClass_" + selectedOption.val() + "' type='checkbox' value='" + selectedOption.val() + "' fid='" + selectedOption.attr("fid") + "' /><label for='chkbigClass_" + selectedOption.val() + "' style='font-weight:bold'>" + selectedOption.text() + "</label>" + disabledTip;
        $("#p_smallText").html(_phtml);

        var _strHtml = "";
        for (var i = 0; i < positionarray.length; i++)
        {
            if (positionarray[i][1] == selectedOption.val())
                _strHtml += "<dd style='PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px auto; PADDING-TOP: 0px'><input onclick='SetCheckedItemPosition(this)' id='chksmClass_" + positionarray[i][2]+ "' type='checkbox' value='" + positionarray[i][2] + "' /><label for='chksmClass_" + positionarray[i][2] +"'>" + positionarray[i][0]+ "</label></dd>";
        }
        $(".dlsm").html(_strHtml);
    }
}
function setFatherCheckPosition(c)
{
    if (c.checked)
    {
        $(".divcon :checkbox[fid=" + c.value + "]").removeAttr("checked");
        $(".divcon :checkbox[fid=" + c.value + "]").attr("disabled", "disabled");
    }
    else
    {
        $(".divcon :checkbox[fid=" + c.value + "]").removeAttr("disabled");
    }
    SetCheckedItemPosition(c);
}
function SetCheckedItemPosition(c)
{
    if (c.checked)
    {
        if ($("#selectitem :checkbox[fid=" + c.value + "]").val() != "undefined")
        {
            $("#selectitem :checkbox[fid=" + c.value + "]").next("label").remove();
            $("#selectitem :checkbox[fid=" + c.value + "]").remove();
        }
        if ($("#selectitem :checkbox[value=" + c.value + "]").val())
            return;
        if ($("#selectitem :checkbox").length == 5)
        {
            c.checked = false;
            alert("对不起！您选中的选项已经超过5项了，请先减少已选项再选择！");
            return;
        }
        var _strHtml = $("#selectitem").html();
        _strHtml += "<input onclick='removeCheckboxThisPosition(this)' id='chkSelectItem_" + c.value + "' checked='checked' type='checkbox' value='" + c.value + "' fid='" + c.getAttribute("fid") + "' /><label for='chkSelectItem_" + c.value + "'>" + $("#" + c.id).next("label").text() + "</label>";
        $("#selectitem").html(_strHtml);
        $(".divcon :checkbox[value=" + c.value + "]").attr("checked", "checked");
    }
    else
    {
        removeCheckboxThisPosition(c);
    }
}
function ClearItemPosition()
{
    $(".divcon :checkbox:checked").removeAttr("checked");
    $(".divcon :checkbox:disabled").removeAttr("disabled");
    if (allowSelectBigClass == "False")
        $("#p_smallText :checkbox").attr("disabled", "disabled");
    $("#selectitem").html("");
}
function removeCheckboxThisPosition(c)
{
    $("#selectitem :checkbox[value=" + c.value + "]").next("label").remove();
    $("#selectitem :checkbox[value=" + c.value + "]").remove();
    $(".divcon :checkbox[value=" + c.value + "]").removeAttr("checked");
    $(".divcon :checkbox[fid=" + c.value + "]").removeAttr("disabled");
}

//选择成功
function SelectOKPosition()
{
    var items = $("#selectitem :checkbox");
    var strItemsId = "";
    var strText = "";
    for (var i = 0; i < items.length; i++)
    {
        strItemsId += items.eq(i).val() + ",";
        strText += $.trim(items.eq(i).next("label").text()) + "+";
    }
    strItemsId = strItemsId.substring(0, strItemsId.lastIndexOf(","));
    strText = strText.substring(0, strText.lastIndexOf("+"));
    ShowSelectPosition(strItemsId, strText);
    SelectCenclePosition()
}


//选择职位完成
function ShowSelectPosition(strItems, strText) {
    $("#txbPositions").val(strText);
    $("#hidPositoins").val(strItems);
    var _strIdItems = strItems.toString().split(",");
    var _strTextItems = strText.toString().split("+");
    var _Temhtml = "<font color='red'>请选择范本：</font>";
    for (var i = 0; i < _strIdItems.length; i++) {
        _Temhtml += "<a href=\"javascript:\" title=\"查看" + _strTextItems[i] + "的职位描述范本\" onclick=\"getTemp(" + _strIdItems[i] + ")\">" + _strTextItems[i] + "<\/a>&nbsp;&nbsp;";
    }
    $("#PositionTxt").html(_Temhtml);
    $("#PositionTemp").val("点击以上岗位类别可查看职位描述范本。");
}
//选择地区完成
function ShowSelectArea(strItems, strText) {
    $("#txbWorkAddress").val(strText);
    $("#hidWorkAddress").val(strItems);
}


//取消选择
function SelectCenclePosition()
{
    $("#shield").hide();
    $("#positionShowDiv").hide();
    $(document).find("select").css({ visibility: "visible" });
    if (document.getElementById("shield"))
    {
        document.body.removeChild(document.getElementById("shield"));
    }
    if (document.getElementById("positionShowDiv"))
    {
        document.body.removeChild(document.getElementById("positionShowDiv"));
    }
}
function showPositionHtml(allowBigClass)
{
    allowSelectBigClass = allowBigClass;
    var shield = document.createElement("div");
    var W = $(document).width();
    var H = $(document).height();
    shield.id = "shield";
    shield.style.cssText = "position:absolute;z-index:1;width:" + W + "px;height:" + H + "px;background:#000;filter:alpha(opacity=50);opacity:0.5;top:0;left:0;";
    document.body.appendChild(shield);
    $(document).find("select").css({ visibility: "hidden" });

    var load = document.createElement("img");
    load.id = "loadingImg";
    load.src = "http://my.job978.com/imgblue2009/loading.gif";
    var _top = document.documentElement.scrollTop + 200 + "px";
    var _left = $(document).width() / 2 - 16 + "px";
    load.style.cssText = "display:block;position: absolute;z-index:99999;top:" + _top + ";left:" + _left;
    document.body.appendChild(load);

    var positionShowDiv = document.createElement("div");
    positionShowDiv.id = "positionShowDiv";
    positionShowDiv.className = "ShowSelect";
    var conHtml = "";
    conHtml += "<div onmousedown=\"MDownPosition8888(this.parentNode);\" title=\"可以随意拖动\" style=\"width: 100%;";
    conHtml += "cursor: move; padding-left: 10px; background:url(http://my.job978.com/imgblue2009/TABLE_T.gif) repeat-x; font-size: 12px;";
    conHtml += "color: #166ab6; line-height: 24px;\">";
    conHtml += "<span style=\"float: right; font-size: 12px; padding-right: 10px; font-weight: normal;";
    conHtml += "cursor: pointer; margin: 2px;\" onclick=\"SelectCenclePosition()\">[关闭]&nbsp;&nbsp;</span><span";
    conHtml += "id=\"wintit2\"><b>请选择岗位类别</b>&nbsp;&nbsp;最多5项</span></div>";

    conHtml += "<div id=\"changbox\" class=\"divcon\" style=\"margin-top: 10px; background-color: #efefef;\">";

    conHtml += "常用岗位：&nbsp;<input onclick=\"setFatherCheck(this)\" id=\"chkOfen_9107\" value=\"9107\" ";
    conHtml += "    type=\"checkbox\"><label for=\"chkOfen_9107\">美容师</label><input onclick=\"setFatherCheck(this)\"";
    conHtml += "        id=\"chkOfen_9104\" value=\"9104\" fid=\"9100\" type=\"checkbox\"><label for=\"chkOfen_9104\">美容导师</label><input";
    conHtml += " onclick=\"setFatherCheck(this)\" id=\"chkOfen_9105\" value=\"9105\" fid=\"9100\" type=\"checkbox\"><label";
    conHtml += "     for=\"chkOfen_9105\">美容顾问</label><input onclick=\"setFatherCheck(this)\" id=\"chkOfen_9106\"";
    conHtml += "         value=\"9106\" fid=\"9100\" type=\"checkbox\"><label for=\"chkOfen_9106\">美容院店长</label><input";
    conHtml += "  onclick=\"setFatherCheck(this)\" id=\"chkOfen_9102\" value=\"9102\" fid=\"9100\" type=\"checkbox\"><label";
    conHtml += "      for=\"chkOfen_9102\">培训讲师</label><input onclick=\"setFatherCheck(this)\" id=\"chkOfen_9301\"";
    conHtml += "          value=\"9301\" fid=\"9300\" type=\"checkbox\"><label for=\"chkOfen_9301\">化妆师</label><br>";
    conHtml += "<input onclick=\"setFatherCheck(this)\" id=\"chkOfen_9404\" value=\"9404\" fid=\"9400\" type=\"checkbox\"><label";
    conHtml += "    for=\"chkOfen_9404\">美甲师</label><input onclick=\"setFatherCheck(this)\" id=\"chkOfen_9001\"";
    conHtml += "        value=\"9001\" fid=\"9000\" type=\"checkbox\"><label for=\"chkOfen_9001\">市场总监</label><input";
    conHtml += " onclick=\"setFatherCheck(this)\" id=\"chkOfen_9004\" value=\"9004\" fid=\"9000\" type=\"checkbox\"><label";
    conHtml += "     for=\"chkOfen_9004\">品牌经理</label><input onclick=\"setFatherCheck(this)\" id=\"chkOfen_9005\"";
    conHtml += "         value=\"9005\" fid=\"9000\" type=\"checkbox\"><label for=\"chkOfen_29005\">区域经理</label><input";
    conHtml += "  onclick=\"setFatherCheck(this)\" id=\"chkOfen_9007\" value=\"9007\" fid=\"9000\" type=\"checkbox\"><label";
    conHtml += "      for=\"chkOfen_9007\">销售代表</label><input onclick=\"setFatherCheck(this)\" id=\"chkOfen_9202\"";
    conHtml += "          value=\"9202\" fid=\"9200\" type=\"checkbox\"><label for=\"chkOfen_9202\">美发师</label>";

    conHtml += "</div>";
    conHtml += "<div id=\"bigclass\" style=\"margin-left: 20px; width: 540px; margin-top: 8px;\">";
    conHtml += "    请先选择大类：<select id=\"sltBigClass\" onchange=\"setSelectClassPosition();$('#changbox :checkbox').removeAttr('disabled');\"></select>";
    conHtml += "</div>";
    conHtml += "<div id=\"smallclass\" class=\"divcon\" style=\"margin-top: 4px;\">";
    conHtml += "    <p id=\"p_smallText\">";
    conHtml += "    </p>";
    conHtml += "    <dl id=\"dlItems\" class=\"dlsm\">";
    conHtml += "    </dl>";
    conHtml += "</div>";
    conHtml += "<div style=\"clear: both\">";
    conHtml += "</div>";
    conHtml += "<div id=\"checktitle\" style=\"margin-left: 20px; width: 540px; margin-top: 8px; font-size: 13px;";
    conHtml += "    font-weight: bold;\">";
    conHtml += "    您已经选择的岗位类别是：<span style=\"cursor: pointer; font-size: 12px; font-weight: normal;\" onclick=\"ClearItemPosition();\">清空所有选项</span></div>";
    conHtml += "<div id=\"selectitem\" style=\"margin-left: 20px; width: 540px; margin-top: 4px;\">";
    conHtml += "</div>";
    conHtml += "<div id=\"selectok\" style=\"margin-left: 20px; margin-top: 4px; margin-bottom: 4px;";
    conHtml += "    text-align: right; padding-right: 40px;\">";
    conHtml += "    <input type=\"button\" value=\"确定\" onclick=\"SelectOKPosition()\" \>&nbsp;";
    conHtml += "    <input type=\"button\" value=\"取消\" onclick=\"SelectCenclePosition()\" \>";
    conHtml += "</div>";

    positionShowDiv.innerHTML = conHtml;
    document.body.appendChild(positionShowDiv);
    $("#sltBigClass").html(setBigClassPosition());
    setSelectClassPosition();
    $("#positionShowDiv").css({ top: document.documentElement.scrollTop + 85 + "px", left: $(document).width() / 2 - 291 + "px", display: "block" });
    $("#loadingImg").hide();
    if (document.getElementById("loadingImg"))
        document.body.removeChild(document.getElementById("loadingImg"));
}
//实现层移动
function MDownPosition(str)
{
    var e = window.event || arguments.callee.caller.arguments[0];
    var deltaX = e.clientX - parseInt(str.offsetLeft);
    var deltaY = e.clientY - parseInt(str.offsetTop);
    var deltaH = document.body.clientHeight;
    var deltaW = document.body.clientWidth;
    var drag = true;
    str.onmousemove = function(ev)
    {
        ev = ev ? ev : window.event;
        if (drag)
        {
            var Y = ev.clientY - deltaY;
            var X = ev.clientX - deltaX;
            var H = deltaH - str.offsetHeight;
            var W = deltaW - str.offsetWidth;
            if (Y > 0 || X > 0)
            {
                if (Y >= H)
                {
                    str.style.top = H + "px";
                } else
                {
                    str.style.top = Y + "px";
                }
                if (X >= W)
                {
                    str.style.left = W + "px";
                } else
                {
                    str.style.left = X + "px";
                }
            }
            if (Y <= 0)
            {
                str.style.top = 0;
            }
            if (X <= 0)
            {
                str.style.left = 0;
            }
            str.setCapture();
        }
    }
    str.onmouseup = function()
    {
        drag = false;
        str.releaseCapture();
    }
}
