 var cookies_pUserName; //求职者用户cookies
 var cache = {}; //搜索框关键字建议缓存项  
$(function(){    
    cookies_pUserName=$.cookie('Jobcu%5FJobSeeker>UserName');	
    regNavMyResume(); //导航栏“我的简历”是否登录验证
    regSearchBar(); //职位搜索框
});

//导航栏“我的简历
function regNavMyResume()
{
    $("#navMyResume").click(function(){   
        cookies_pUserName=$.cookie('Jobcu%5FJobSeeker>UserName');	        
        if (cookies_pUserName==null || $.trim(cookies_pUserName).length==0) {
           $("#siteHeader .right_ul .thickbox").click();
           return false;
        }
    });
}   
//个人用户是否登录验证
var User_CheckStatus=function(){   
    cookies_pUserName=$.cookie('Jobcu%5FJobSeeker>UserName');	
    if (cookies_pUserName!=null && $.trim(cookies_pUserName).length>0) {
        $("#siteHeader .right_ul").html("<li>欢迎 "+cookies_pUserName+" 登录</li><li><a href='/personal/welcome.asp'>求职管理中心</a></li><li><a href='/personal/MyResume_Preview.asp' target='_blank'>我的简历</a></li><li><a href='/personal/logout.asp'>退出</a></li>");
        $("#navMyResume").unbind("click");
    }
}

//职位搜索框
function regSearchBar()
{
    $("#keyLink>a").click(function(){$("#key").val($(this).html());});
    $("#cityLink>a").click(function(){$("#city").val($(this).html());});
    $("#btnSearch").bind("click", function(event) {            
        var vkey=$.trim($("#key").val());
        var vcity=$.trim($("#city").val());
        if(vkey!="")location.href="http://job.jobcu.com/s.asp?add=1&key="+escape(vkey)+"&city="+escape(vcity);            
        else $("#key").focus();
    });       
    //搜索建议
    if($("#key").length>0){
        $("#key").autocomplete({
            //delay: 600,
            minLength:1,
            source: function(request, response){
                if($.trim(request.term)!=""){
                    if ( request.term in cache ) {response(cache[request.term]); return;}
                    $.getScript("http://job.jobcu.com/sDB.asp?op=keysuggest&q="+escape(request.term), function()
                    {                             
                        var keyArry=keys.keylist.split(",");
                        if(keyArry==null){cache[request.term]=""; response("");} 
                        else{cache[request.term] = keyArry; response(keyArry);}
                    });                                        
                 }else{response("");}
            }
         });  
    }      
}       
        
 /*  tagbox  HTML结构需要特定的元素。可以参so/main.asp文件 
    示例：$("#tagbox_joblist1").tagbox(0);
 */       
   jQuery.fn.tagbox = function(defaultnum){
        var handle = jQuery(this);
        var idname=handle.attr("id");
        var init=function(){
            $("#"+idname+">.jobcu_tag>ul>li").bind("mouseover", function(event) {                 
               $("#"+idname+">.jobcu_tag>ul>li").removeClass("jobcu_tagselect");
                $(this).addClass("jobcu_tagselect");
                var index=$(this).attr("value");
                var boxul=$("#"+idname+">.jobcu_tagbox>ul");
                boxul.removeClass().addClass("hide");             
                boxul.eq(index).addClass("show");
            }); 
            $("#"+idname+">.jobcu_tag>ul>li").eq(defaultnum).mouseover();
        };
        init();
    };
 /*  jobcu_box 中的table  
    示例：$("#tagbox_joblist1").boxtable();
 */       
   jQuery.fn.boxtable = function(){
        var handle = jQuery(this);
        var idname=handle.attr("id");
        var init=function(){
            $("#"+idname+" tbody tr").bind("mouseover", function(event) {                 
               $("#"+idname+" tbody tr").removeClass("trover");
                $(this).addClass("trover");                
            });             
        };
        init();
    };
           
// ---------------------------------------------------
/**
  * 从1个包含有子节点的cookie串中取得指定cookie名的值 like ‘Request.Cookies("JobSeeker")("UserName")’
  * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
  */
  jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', escape(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            var arryName = name.split('>');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, arryName[0].length + 1) == (arryName[0] + '=')) {
                    if(arryName.length==1){
                        cookieValue = unescape(cookie.substring(arryName[0].length + 1));
                    }else{
                        var offset = cookie.indexOf(arryName[1]+ '=');
                        if (offset != -1)
                        {
                            offset += arryName[1].length + 1;
                            end = cookie.indexOf("&", offset) ;                           
                            if (end == -1) end = cookie.length;
                            cookieValue=unescape(cookie.substring(offset, end));
                        }
                    }
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/**
 *Google  Analytics 分析脚本    
 */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-7642990-1']);
_gaq.push(['_setDomainName', '.jobcu.com']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

