﻿var isPersonLogin = false;
var isCompanyLogin = false;
$(function () {
    var hId_1; //隐藏菜单计时器
    var hId_2; //隐藏菜单计时器
    var hId_3; //隐藏菜单计时器
    var hId_4; //隐藏菜单计时器
    var hId_5; //隐藏菜单计时器
    var searchType = "job";

    $("a").focus(function () { this.blur(); });
    $(".site_info a:eq(2)").click(function () {
        window.external.addFavorite("http://" + SiteConfig.DOMAIN, SiteConfig.SITENAME); return false;
    });

    //顶部工具条右侧的用户登录事件注册
    $(".h_login").mouseover(function () {
        clearTimeout(hId_1);
        if ($(this).children("ul").css("display") == "none") {
            $(this).children("ul").show();
        }
    }).mouseout(function () {
        clearTimeout(hId_1);
        hId_1 = setTimeout("$('.h_login').children('ul').hide();", 200);
    });


    //顶部工具条右侧的用户注册事件注册
    $(".h_reg").mouseover(function () {
        clearTimeout(hId_2);
        if ($(this).children("ul").css("display") == "none") {
            $(this).children("ul").show();
        }
    }).mouseout(function () {
        clearTimeout(hId_2);
        hId_2 = setTimeout("$('.h_reg').children('ul').hide();", 200);
    });


    //注册后顶部工具条右侧的用户登录事件注册
    $(".memberCenter").live("mouseover", function () {
        clearTimeout(hId_3);
        if ($(this).children("ul").css("display") == "none") {
            $(this).children("ul").show();
        }
    }).live("mouseout", function () {
        clearTimeout(hId_3);
        hId_3 = setTimeout("$('.memberCenter').children('ul').hide();", 200);
    });

    //头部搜索框事件注册
    $(".searchBox").focus(function () {
        $(".searchTip").hide();
    }).blur(function () {
        if ($.trim($(this).val()) == "") {
            $(".searchTip").show();
        }
    });

    //头部搜索框提示信息事件注册
    if ($.trim($(".searchBox").text()) != "") {
        $(".searchTip").hide();
    }
    $(".searchTip").click(function () {
        $(this).hide();
        $(".searchBox").trigger("focus");
    });

    $(".tabType li").click(function () {
        $(".tabType li").removeClass("tabActive").addClass("tabNormal");
        $(this).addClass("tabActive");
        if ($.trim($(this).text()) == "找工作") {
            searchType = "job";
            if ($.trim($(".searchBox").val()) == "") {
                $(".searchTip").text("请输入职位名称");
            }
            $(".searchItemText").text("搜索工作");
        }
        else if ($.trim($(this).text()) == "找人才") {
            searchType = "person";
            if ($.trim($(".searchBox").val()) == "") {
                $(".searchTip").text("请输入求职意向");
            }
            $(".searchItemText").text("搜索人才");
        }
    });

    $(".mainNav-rightSide-liIt:eq(0)").mouseover(function (e) {
        clearTimeout(hId_4);
        if ($(this).children("ul").css("display") == "none") {

            $(this).children("ul").show();
        }
    }).mouseout(function () {
        clearTimeout(hId_4);
        hId_4 = setTimeout("$('.mainNav-rightSide-liIt:eq(0)').children('ul').hide();", 200);
    });

    $(".mainNav-rightSide-liIt:eq(1)").mouseover(function (e) {
        clearTimeout(hId_5);
        if ($(this).children("ul").css("display") == "none") {

            $(this).children("ul").show();
        }
    }).mouseout(function () {
        clearTimeout(hId_5);
        hId_5 = setTimeout("$('.mainNav-rightSide-liIt:eq(1)').children('ul').hide();", 200);
    });

    $(".searchItemText").click(function () {
        if ($.trim($(".searchBox").val()) != "") {
            if (searchType == "job") {
                window.location.href = "../../Search/Job?k=" + escape($.trim($(".searchBox").val()));
            }
            if (searchType == "person") {
                window.location.href = "../../Search/Person?k=" + escape($.trim($(".searchBox").val()));
            }
        }
        else {
            popAlertBox("请输入搜索关键词");
        }
        return false;
    });

    $(".searchBox").keyup(function (e) {
        if (e.keyCode == "13") {
            $(".searchItemText").trigger("click");
        }
    });

    setTimeout(getLogin, 300);
});

//获取登录状态信息
var getLogin = function () {
    $.get("../../Login/WhichLogin/" + Math.random(), function (data) {
        var d = $.parseJSON(data);
        if (d.type == "person") {
            isPersonLogin = true;
            $(".quick_nav").html("<ul><li><strong>" + d.name + "，您好！</strong></li><li class='memberCenter'><a href='http://" + SiteConfig.PERSONDOMAIN + "/Index.aspx'>求职中心<span class='tipsArrow'></span></a><ul><li><a href='http://" + SiteConfig.PERSONDOMAIN + "/Per_Resume.aspx'>我的简历</a></li><li><a href='http://" + SiteConfig.PERSONDOMAIN + "/per_Interview.aspx'>我的职位</a></li><li><a href='http://" + SiteConfig.PERSONDOMAIN + "/Per_Account.aspx'>用户设置</a></li><li><a href='http://" + SiteConfig.PERSONDOMAIN + "/Index.aspx' >搜索器</a></li></ul></li><li><span></span><a href='http://" + SiteConfig.PERSONDOMAIN + "/perNews.aspx'>新消息(<strong class='red'>" + d.msgNum + "</strong>)</a></li><li><a href='../../Login/LoginOut'>退出</a></li></ul>");
        }
        else if (d.type == "company") {
            isCompanyLogin = true;
            $(".quick_nav").html("<ul><li><strong>" + d.name + "，您好！</strong></li><li class='memberCenter'><a href='http://" + SiteConfig.COMPANYDOMAIN + "/Index.aspx'>招聘中心<span class='tipsArrow'></span></a><ul><li><a href='http://" + SiteConfig.COMPANYDOMAIN + "/Introduce.aspx'>企业设置</a></li><li><a href='http://" + SiteConfig.COMPANYDOMAIN + "/JobList.aspx'>职位管理</a></li><li><a href='http://" + SiteConfig.COMPANYDOMAIN + "/Resume.aspx'>简历管理</a></li><li><a href='http://" + SiteConfig.COMPANYDOMAIN + "/Per_Store.aspx' >人才库</a></li></ul></li><li><span></span><a href='http://" + SiteConfig.COMPANYDOMAIN + "/comNews.aspx'>新消息(<strong class='red'>" + d.msgNum + "</strong>)</a></li><li><a href='../../Login/LoginOut' >退出</a></li></ul>");
        }
    });
};
