﻿$(document).ready(function() { 
//         MiniSite.Weather.print("weather"); //加载时
         setCalendar1();
         window.setTimeout(function() {setCalendar();}, 3000);
          $("#weather1").mouseover(function(event){//绑定事件处理
              $("#SmarContent").show();
              $("#racePop").show();
          });    
        //当鼠标滑入时将div的class换成divOver
        $('.divbox').hover(function(){
            $(this).addClass('divOver');  
            },function(){
            //鼠标离开时移除divOver样式
                $(this).removeClass('divOver'); 
           }
        );
        var speed = 20;//动画速度
	    $("#racePop").mouseover(function(event){//绑定事件处理
            $("#racePop").show();
        });
        $("#racePop").bind("mouseleave", function(event) {  //离开区域隐藏
            $(this).hide(speed);  
        });
	    $("#weather1").bind("mouseleave", function() {  //离开区域隐藏
	        $("#racePop").toggle();
        });
	    $("#selectSTContainer").overlay({
	  	    mask: {closeOnClick: false,color:'#000',opacity: 0.6},
		    fixed: false,
		    speed: 0,
		    closeOnClick: false,
		    onBeforeLoad:function(){$("select").hide();},
	 	    onClose: function() {
	 	        doDefaultTextFromArray();
	 	        $("select").show();
	 	    }
    	});
    	setNavMenuSelected("navTopHome");
        $("#btnLoginH").bind("click", homeUserLogin);
        $("#btnSearch").bind("click", Search);
        $("#btnSJobType").bind("click", function(){initSelector(1)});
        $("#btnSIndustry").bind("click", function(){initSelector(2)});
        $("#btnSRegion").bind("click", function(){initSelector(3)});
          
	    checkHasLogin();
	    checkCompanyHasLogin();
});
function Search()
{
    var hdnSJobType = $("#hdnSJobType").val();
    var hdnSIndustry = $("#hdnSIndustry").val();
    var hdnSRegion = $("#hdnSRegion").val();
    var keyword = $("#keyword").val();
    var b_keyword = $("#b_keyword option:selected").val();
    var canSubmit = false;
    var strHref = "SearchJob.aspx?Action=User";
    if ((b_keyword != "-1") && (keyword.length > 0)){
       strHref += "&keyword=" + encodeURIComponent(keyword);
       strHref += "&b_keyword=" +b_keyword;
       canSubmit = true;
    }
    if (hdnSJobType.length > 0){
        strHref += "&JobType="+hdnSJobType;
        canSubmit = true;
    }
    if(hdnSIndustry.length){
        strHref += "&Industry="+hdnSIndustry;
        canSubmit = true;
    }
    if(hdnSRegion.length){
        strHref += "&Region="+hdnSRegion;
        canSubmit = true;
    }
    if (!canSubmit) {alert("关键字,职位类别,行业类别,工作地点至少选择一项");}
    else { window.open(strHref); }
}

function checkHasLogin(){
     $.ajax({
             type:"post",
             url:"../JobLoginAJ.ashx",
             dataType: "json",
             data: "action=checkLogin",
             success:function(data) {
                if (data.resultMsg == "1")
                {
                    $("#userNameH").text(data.userName);
                    $("#loginDate").text(data.loginDate);
                    $("#nowLoginDate").text(data.nowLoginDate);
                    $("#homeLoginDiv").hide();
                    $("#homeLoadingDiv").hide();
                    $("#homeUserInfoDiv").show(); 
                }
                else if (data.resultMsg == "-3")//未登录
                {  
                    $("#homeLoadingDiv").hide();
                    $("#homeUserInfoDiv").hide();  
                    $("#homeLoginDiv").show();
                    
                } else //-99
                {
                    $("#messageInfo").text("数据异常");
                    $("#messageInfo").show("fast"); 
                }
             },
             error: function() {
                $("#messageInfo").text("请求出错");
               $("#messageInfo").show("fast"); 
             }
         });
}
     
function homeUserLogin(){
     $("#messageInfo").text("");
     $("#messageInfo").hide();
     if (!checkRequired($("#txtLoginNameH").val()))
     {
         $("#messageInfo").text("用户名必填");
         $("#txtLoginNameH").focus();
         $("#messageInfo").show("fast"); 
         return false;
     }
     if (!checkRequired($("#txtPasswordH").val()))
     {
         $("#messageInfo").text("密码必填");
         $("#txtPasswordH").focus();
         $("#messageInfo").show("fast"); 
         return false;
     }
     var param  = "loginName=" + $("#txtLoginNameH").val() + "&password=" + $("#txtPasswordH").val();
     $.ajax({
         type:"post",
         url:"../JobLoginAJ.ashx",
         dataType: "json",
         data:param,
         //data: '{"loginName":"test111","password":"111111"}',
         success:function(data) {
            if (data.resultMsg == "1")
            {
                $("#userNameH").text(data.userName);
                $("#loginDate").text(data.loginDate);
                $("#nowLoginDate").text(data.nowLoginDate);
                $("#homeLoginDiv").hide();
                $("#homeLoadingDiv").hide();
                $("#homeUserInfoDiv").show(); 
            }
            else if (data.resultMsg == "-1")
            {
                $("#messageInfo").text("用户名密码错误");
                $("#messageInfo").show("fast"); 
            } else if (data.resultMsg == "-2")
            {
                $("#messageInfo").text("参数错误");
                $("#messageInfo").show("fast"); 
            } else //-99
            {
                $("#messageInfo").text("数据异常");
                $("#messageInfo").show("fast"); 
            }
           
         },
         error: function() { 
             $("#messageInfo").text("请求出错");
             $("#messageInfo").show("fast"); 
         },
         complete:function(){
         }  
     });
} 
function checkCompanyHasLogin(){

 $.ajax({
             type:"post",
             url:"../CompanyLoginAJ.ashx",
             dataType: "json",
             data: "action=checkCompanyLogin",
             success:function(data) {
                if (data.resultMsg == "1")
                {
                    $("#CompanyuserNameH").text(data.companyName);
                    $("#CompanyUserInfoDiv").show(); 
                }
                else if (data.resultMsg == "-3")//未登录
                {  
                    $("#CompanyUserInfoDiv").hide();  
                    
                } else //-99
                {
                    $("#messageInfo").text("数据异常");
                    $("#messageInfo").show("fast"); 
                }
             },
             error: function() {
//                 $("#messageInfo").text("请求出错");
//                 $("#messageInfo").show("fast"); 
             }
         });
}




