//全选，反选
function checkall(obj, cc) {    
    $(cc).find(":checkbox").attr("checked", $(obj).attr("checked") == true);
}
//收藏按扭的事件
function collectjobs() {
    if (!checkBoxSel('chkjobid', '.joblist'))
    {
        alert("请选择操作的职位");
        return;
    }
    var jobidstr = $(".joblist").find('input[name="chkjobid"]:checked').fieldSerialize();
    var url = "/ajax/Jobhandler.ashx";
    url += "?a=collectjobs&" + jobidstr;alert(url);
    App.get(url, function (res) {
        if (res.type == "login")
        {
            POPS["login_box"] = App.html(res.message, "个人登录", 300);
        }
        else if (res.error == 1)
        {
            alert(res.message);
        } else
        {
            alert(res.content);
        }
    });
   // alert(jobidstr);
}
$(function () {

    //职位搜索向导
    var SearchSelect = $("#search_hot");
    if (SearchSelect.length > 0) {

        SearchSelect.find("a.s1").click(function () {

            if ($(this).hasClass("a_now")) {
                return;
            }

            SearchSelect.find("a.a_now").removeClass("a_now");
            $(this).addClass("a_now");
            var hidst = $("#hidst");
            hidst.val($(this).attr("defvalue"));
        });
    }
 
    $("#keywods").keyup(function (e) {
        if (e.keyCode == 13) return;
    }).focus(function () {
        if ($(this).val() == "请输入职位名称或公司名") $(this).val("");
    }).blur(function () {
        if ($(this).val() == "") $(this).val("请输入职位名称或公司名");
    });


});
$(function () {
  
    var selectobj = $("#jianli_so").find("h3");
    selectobj.children("a").click(function () {
        if ($(this).hasClass("a_now")) return;
        selectobj.children("a.a_now").removeClass("a_now");
        $(this).addClass("a_now");
        var index = selectobj.children("a").index($(this));

        $("#jianli_so").find("div[id^='mydiv']").hide();  
        $("#mydiv" + (index + 1)).show();
    });
});
$(function () {

    var selectobj = $("#search_swith").find("h3");
    selectobj.children("a").click(function () {
        if ($(this).hasClass("a_now")) return;
        selectobj.children("a.a_now").removeClass("a_now");
        $(this).addClass("a_now");
        var index = selectobj.children("a").index($(this));

        $("#search_swith").find("div[id^='mydiv']").hide();
        $("#mydiv" + (index + 1)).show();
    });
});
 
function getpass_submit(formobj) {
    var is_error = false;
    var check_val = $("input[name=email]").val();
    if (!$.is_email(check_val)) is_error = true;
    if (is_error == true) { App.alert("提交的邮件格式非法！"); return false; }
    App.form(formobj, function (res) {
        if (res.error == 1) {
            App.alert(res.message);
        } else {
            App.alert(res.content);
            setTimeout("App.redirect('" + res.url + "')", 2000);
        }
    });
    return false;
}
//收藏职位
function jobfavpost(post_id) {
    var url = "/ajax/Jobhandler.ashx";
    url += "?a=jobfavpost&app=" + post_id;
    App.get(url, function (res) {
        if (res.type == "login") {
            POPS["login_box"] = App.html(res.message, "个人登录", 300);
        } else if (res.error == 1) {
            alert(res.message);
        } else {
            alert(res.content);
        }
    });
}

///加关注
function payattention(post_id) { 
    var url = "/ajax/Jobhandler.ashx";
    url += "?a=payattention&app=" + post_id; 
    App.get(url, function (res) {
        if (res.type == "login")
        {
            POPS["login_box"] = App.html(res.message, "个人登录", 300);
        } else if (res.error == 1)
        {
          
            alert(res.message);
        }
        else
        {

            $('#fansbox').html(res.content);
           
        }
    });
}


function canncelattention(post_id) {
    var url = "/ajax/Jobhandler.ashx";
    url += "?a=canncelattention&app=" + post_id;
    App.get(url, function (res) {
        if (res.type == "login")
        {
            POPS["login_box"] = App.html(res.message, "个人登录", 300);
        } else if (res.error == 1)
        {

            alert(res.message);
        }
        else
        {

            $('#fansbox').html(res.content);

        }
    });

 }

function agreems(post_id, type, page) {
    var url = "/ajax/resumehandler.ashx";
    var type = (typeof type == "undefined") ? 0 : type;
    url += "?a=invitems&types=2&app=" + post_id;
    //    alert(url);
    if (type == 0) {
        App.get(url, function (res) {
            if (res.type == "login") {
                POPS["login_box"] = App.html(res.message, "企业登录", 400, 320);
            } else if (res.type == "invitemstemp") {
                POPS["invitemstemp"] = App.html(res.message, "邀请面试", 350, 150);
            } else {
                alert(res.message);
            }
        });
    } else if (type == 1) {
        $("#div_yqms").find("input[type='submit']").attr("disabled", true);
        App.form($("#form_yqms")[0], function (res) {
            if (res.error == 1) {//等于1的时候输出登陆框
                alert(res.message);
            } else {
                alert(res.content);
            }
            POPS["invitemstemp"].close();
        });
        return false;
    }
}
//下载简历
function downresume(post_id) {
    var url = "/hr/downresume.aspx";
    url += "?resumeid=" + post_id;
    App.redirect(url);
}

 

//申请职位
function applyjob(post_id, type, page) { 
    var url = "/ajax/Jobhandler.ashx"; 
    var type = (typeof type == "undefined") ? 0 : type; 
    url += "?a=applypost&app=" + post_id;
 
    if (type == 0) {
        App.get(url, function (res) {           
            if (res.type == "login") {
                POPS["login_box"] = App.html(res.message, "个人登录", 400, 320);
            } else if (res.type == "qzx") {
                POPS["qzx"] = App.html(res.message, "申请职位", 500, 320);
            } else {
                alert(res.message);
            }
        });
    } else if (type == 1) {    
        $("#div_qzx").find("input[type='submit']").attr("disabled", true);
        App.form($("#form_qzx")[0], function (res) {
            if (res.error == 1) {//等于1的时候输出登陆框
                alert(res.message);
            } else {
                alert(res.content);
            }
            POPS["qzx"].close();
        });
        return false;
    } 
}
//登录提交
function login_submit(formobj) {
    var is_error = false;
    var lasterror = "";
    $(formobj).find("input[check=1]").each(function () {
        if (!checkinput(this)) {
            is_error = true;
            lasterror = error_arr["err_" + $(this).attr("name")];
        }
    }); 
    if (is_error == true) {
        $("#ajaxmsg").html(lasterror).show();
        return false;
    }
    $("#btn_loginsubmit").attr("disabled", true);
    $("#ajaxmsg").html("<span>正在登录，请稍后……</span>").show();
    App.form(formobj, function (res) {
        if (res.error == 1) {
            $("#ajaxmsg").html("<span>" + res.message + "</span>").show();
            $("#btn_loginsubmit").attr("disabled", false);
            return false;
        } else {
            $("#ajaxmsg").html("<span>" + res.content + "</span>").show();
            switch (res.appname) {
                case "jobfavpost":
                    POPS["login_box"].close();
                    jobfavpost(res.post_id);
                    break;
                case "applypost":
                    POPS["login_box"].close();
                    applyjob(res.post_id);
                    break;
                case "invitems":
                    POPS["login_box"].close();
                    invitems(res.post_id);
                    break;
                case "collectjobs":
                    POPS["login_box"].close();
                    collectjobs(res.post_id);
                    break;
                case "payattention":
                    POPS["login_box"].close();
                    payattention(res.post_id);
                    break;
                case "canncelattention":
                    POPS["login_box"].close();
                    canncelattention(res.post_id);
                    break;              
                default:
                    break;
            }
            return false;
        }
    });
    return false;
}
//检查值
function checkinput(obj) {
    var check_item = $(obj).attr("name");
    var check_length = $(obj).attr("len");
    var check_val = $(obj).val();
    var is_check = $(obj).attr("error");
    $(obj).removeClass("box2_width").addClass("box1_width");
    var is_error = false;
    var errormsg = okmsg = "";
    if (check_val == "" || $.mb_strlen(check_val) < check_length) is_error = true;
    if (is_error == false && is_check != 0) {

    }
    //如果出错择判断
    if (is_error == true) {
        $("#ajaxmsg").html(error_arr["err_" + check_item]).show();
        $(obj).attr("error", 1);
        return false;
    } else {
        $(obj).attr("error", 0);
        $("#ajaxmsg").html("").hide();
        return true;
    }
}
function Jtrim(str) {
    var i = 0;
    var len = str.length;
    if (str == "") return (str);
    j = len - 1;
    flagbegin = true;
    flagend = true;
    while ((flagbegin == true) && (i < len))
    {
        if (str.charAt(i) == " ")
        {
            i = i + 1;
            flagbegin = true;
        }
        else
        {
            flagbegin = false;
        }
    }

    while ((flagend == true) && (j >= 0))
    {
        if (str.charAt(j) == " ")
        {
            j = j - 1;
            flagend = true;
        }
        else
        {
            flagend = false;
        }
    }

    if (i > j) return ("");

    trimstr = str.substring(i, j + 1);
    return trimstr;
}
function strlength(str) {
    return str.replace(/[^\x00-\xff]/gi, 'xx').length;
}
function Words_limit(infoname, str, showinput, isEnglish) {
    if (isEnglish)
    {
        $("#" + infoname).find("#" + showinput).html(strlength(Jtrim(str)));
    }
    else
    {
        $("#" + infoname).find("#" + showinput).html(Math.ceil(strlength(Jtrim(str)) / 2));
    }
}
//年月(单选)
function showyearbox(inputname) {
    $(inputname).click(function () {
        var input = $(this);
        $(input).parent("div").before("<div class=\"menu_bg_layer\"></div>");
        $(".menu_bg_layer").height($(document).height());
        $(".menu_bg_layer").css({ width: $(document).width(), position: "absolute", left: "0", top: "0", "z-index": "0" });
        $(input).parent("div").css("position", "relative");

        var myDate = new Date();
        var y = myDate.getFullYear();
        var ymin = y - 65;
        htm = "<div class=\"showyearbox yearlist\">";
        htm += "<div class=\"tit\">请选择年份>></div>";
        htm += "<ul>";
        for (i = y; i >= ymin; i--) {
            htm += "<li title=\"" + i + "年\">" + i + "年</li>";
        }
        htm += "<div class=\"clear\"></div>";
        htm += "</ul>";
        htm += "</div>";
        //
        htm += "<div class=\"showyearbox monthlist\">";
        htm += "<div class=\"tit\">请选择月份>></div>";
        htm += "<ul>";
        for (i = 1; i <= 12; i++) {
            htm += "<li title=\"" + i + "月\">" + i + "月</li>";
        }
        htm += "<div class=\"clear\"></div>";
        htm += "</ul>";
        htm += "</div>";
        $(input).blur();
        if ($(input).parent("div").find(".showyearbox").html()) {
            $(input).parent("div").children(".showyearbox.yearlist").slideToggle("fast");
        }
        else {
            $(input).parent("div").append(htm);
            $(input).parent("div").children(".showyearbox.yearlist").slideToggle("fast");
        }
        //
        $(input).parent("div").children(".yearlist").find("li").unbind("click").click(function () {
            $(input).val($(this).attr("title"));
            $(input).parent("div").children(".yearlist").hide();
            $(input).parent("div").children(".monthlist").show();
            $(input).parent("div").children(".monthlist").find("li").unbind("click").click(function () {
                $(input).val($(input).val() + $(this).attr("title"));
                $(".menu_bg_layer").hide();
                $(input).parent("div").css("position", "");
                $(input).parent("div").find(".showyearbox").hide();
            });
        });
        //
        $(".showyearbox>ul>li").hover(
		function () {
		    $(this).css("background-color", "#DAECF5");
		    $(this).css("color", "#ff0000");
		},
		function () {
		    $(this).css("background-color", "");
		    $(this).css("color", "");
		}
		);
        //
        $(".menu_bg_layer").click(function () {
            $(".menu_bg_layer").hide();
            $(input).parent("div").css("position", "");
            $(input).parent("div").find(".showyearbox").hide();
            //$(inputname+"_s").hide();

        });
    });
}
//广告弹出层
function callbackPub(id) {

    $("#" + id + " li").hover(function () {
         
        $("#" + id + " li").find("div:eq(0)").hide();
        //获取
        var comId = $(this).attr("comid");
        $("#" + id + " li").removeClass("hov");
        $(this).addClass("hov"); 
        if ($(this).find("div").html().length == 0)
        {
         
            var _this = this;
            $.ajax({          //  ajax请求
                type: 'GET',
                url: "/ajax/getadvinfo.ashx", timeout: 1000,
                data: { "comid": comId },
                success: function (result) {
               
                    $(_this).find("div").html(result);
                    if (result != "")
                    {
                        $(_this).find("div").show();
                    }
                    else
                    {
                        $(_this).find("div").hide();
                    }
                }
            });
        }
        else
        {
            $(this).find("div").show();
        }
    }, function () {
        $(this).find("div").hide();
    });

}

function CitySelect() {
    //下拉显示
    $("#liCity").hover(function () {
        $(this).addClass("hover");
        $("#selecity").show();
    }, function () {
        $(this).removeClass("hover");
        $("#selecity").hide();
    });
    $("#alst").find("a").bind("click", function () {
        $("#liCity").find("span").html($(this).text());
        $("#chooseCityName").val($(this).text());
        $("#chooseCityId").val($(this).attr("rel"));
        $("#liCity").removeClass("hover");
        $("#selecity").hide();
    });
}