//去除前后空格
function trimstr(str){
     if(str == null || str == "undefined")
     return "";
   return str.replace(/(^\s*)|(\s*$)/g, "");
}
function nullObject(value,defaultval)
{
    if(value!=null)return value;
    else return defaultval;
}
//cookie存取
function getUsername(name){ 
 var cookie = "";
 var strCookie=document.cookie;
 var arrCookie = strCookie.split(";");
   if(navigator.userAgent.indexOf("Firefox")>0){
   		for(var i=0;i<arrCookie.length;i++){ 
	       var arr=arrCookie[i].split("="); 
	        if(trim(name) == trim(arr[0])){
	            cookie+=arr[1]; 
	     } 
	   }
   }
   else
   {
	   for(var i=0;i<arrCookie.length;i++){ 
	       var arr=arrCookie[i].split("="); 
	        if(trim(name) == trim(arr[0])){
	            cookie=arr[1]; 
	          break; 
	     } 
	   }
   } 
   return unescape(cookie);
}
function getUsername2(name){ 
 var cookie = "";
 var strCookie=document.cookie;
 var arrCookie = strCookie.split(";");
   if(navigator.userAgent.indexOf("Firefox")>0){
   		for(var i=0;i<arrCookie.length;i++){ 
	       var arr=arrCookie[i].split("="); 
	        if(trim(name) == trim(arr[0])){
	            cookie+=arr[1]; 
	     } 
	   }
   }
   else
   {
	   for(var i=0;i<arrCookie.length;i++){ 
	       var arr=arrCookie[i].split("="); 
	        if(trim(name) == trim(arr[0])){
	            cookie=arr[1]; 
	          break; 
	     } 
	   }
   } 
   return cookie;
}
function getIndexForCase(name,value)
{
	var tmp=getUsername2(name);
	var index=-1;
	if( trim(tmp) == ""){
		return index;
	}
	var s = tmp.split("|");
	for(var i=0;i<tmp.length;i++)
	{
		if(s[i]==value)
		{
			index=i;
			break;
		}
	}
	return index;
}
function saveCompanyCase(name,value){
		value=escape(value); 
		var cookieString=name+"="+value;
    	var date=new Date(); 
		date.setTime(date.getTime()+30*24*3600*1000); 
		cookieString=cookieString+"; expires="+date.toGMTString()+"; path=/;"; 
		document.cookie=cookieString;
		return ;
}

function savePersonCase(name,value){
		value=escape(value); 
		var str =getUsername2(trim(name));
	    if( trim(str) == ""){
		  	var cookieString=name+"="+value;
	    	var date=new Date(); 
			date.setTime(date.getTime()+30*24*3600*1000); 
			cookieString=cookieString+"; expires="+date.toGMTString()+"; path=/;"; 
			document.cookie=cookieString;
			return ;
		}
		var s = str.split("|");
		if(s.length>0&&s.length<5){
			var cookieString=name+"="+value+"|"+str;
	    	var date=new Date(); 
			date.setTime(date.getTime()+30*24*3600*1000); 
			cookieString=cookieString+"; expires="+date.toGMTString()+"; path=/;"; 
			document.cookie=cookieString;
			return ;
		}
		else
		{
			var cookieString=name+"="+value+"|"+s[0]+"|"+s[1]+"|"+s[2]+"|"+s[3];
			var date=new Date(); 
			date.setTime(date.getTime()+30*24*3600*1000); 
			cookieString=cookieString+"; expires="+date.toGMTString()+"; path=/;";
			document.cookie=cookieString;
			return ;
		}
}
function savePersonCase2(name,value,index){
		value=escape(value); 
		var str =getUsername2(trim(name));
		var s = str.split("|");
		var cookieString=name+"="+s[index];
		for(var i=0;i<s.length;i++)
		{
			if(i!=index)
			{
				cookieString+="|"+s[i];
			}
		}
		var date=new Date(); 
		date.setTime(date.getTime()+30*24*3600*1000); 
		cookieString=cookieString+"; expires="+date.toGMTString()+"; path=/;";
		document.cookie=cookieString;
		return ;
}

function saveCompanyView(value){
	
	saveCompanyCase("viewCompanyName",value);
	return;
}
function saveCompanyViewVal(value){	
	
	saveCompanyCase("viewCompanyVal",value);
	return;
}

function getViewCompany_main()
{
	var str =getUsername(trim("viewCompanyName"));
	var str1=getUsername(trim("viewCompanyVal"));
	if(str!=""){
		document.write('<ul><span class="color6">'+nullAndLengObject(str,'',25)+'</span>&nbsp;<a class="c0079D6" target="_blank" href="companyShow/getCompanyShow.joinren?companyId='+str1+'"  >查看</a></ul>');
	}else{
		document.write('没有查看过公司');
	}
}

function savePersonSearch(value){
	var tmp=getPersonSearch("personSearchName",value);
	var index=getIndexForCase("personSearchName",escape(value));
	if(index>=0)
	{
	  savePersonCase2("personSearchName",value,index);
	}
	else
	{
	  savePersonCase("personSearchName",value);
	}
	return;
}
function savePersonSearchVal(value){	
	var tmp=getPersonSearchVal();
	var index=getIndexForCase("personSearchVal",escape(value));
	if(index>=0)
	{
	savePersonCase2("personSearchVal",value,index);
	}
	else
	{
		savePersonCase("personSearchVal",value);
	}
	
	return;
}
function getSearch(){
	return getUsername("searchName");
}
function getPersonSearch(){
	var str =getUsername(trim("personSearchName"));
    if( trim(str) == ""){
		return ;
	}
	var s = str.split("|");
	return s[0];
}
function getPersonSearchForIndex(index){
	var str =getUsername(trim("personSearchName"));
    if( trim(str) == ""){
		return ;
	}
	var s = str.split("|");
	return s[index];
}

function getpersonSearchForList()
{
	var str =getUsername(trim("personSearchName"));
	var str1=getUsername(trim("personSearchVal"));
    if( trim(str) == ""){
		return ;
	}
	var s = str.split("|");
	var s1=str1.split("|");
	for(var i=0;i<s.length;i++)
	{
		document.write('<li><a href="'+encodeURI('searchJob.joinren?'+s1[i].replaceAll("@","=")+'&searchname='+s[i]).replace(/\+/g,"%2b").replace(/\#/g,"%23")+'"  title='+s[i]+' >'+nullAndLengObject(s[i],'',15)+'</a></li>');
	}
	return;
}

function showCookieSearchname()
{
	document.write('<h3 title='+getPersonSearchForIndex(0)+'>'+nullAndLengObject(getPersonSearchForIndex(0),'',40)+'</h3>');
}

function getpersonSearchForList_1()
{
	var str =getUsername(trim("personSearchName"));
	var str1=getUsername(trim("personSearchVal"));
	var s = str.split("|");
	var s1=str1.split("|");
	
	for(var i=0;i<s.length;i++)
	{
		document.write('<li><a href="'+encodeURI('../search/searchJob.joinren?'+s1[i].replaceAll("@","=")+'&searchname='+s[i]).replace(/\+/g,"%2b").replace(/\#/g,"%23")+'"  title='+s[i]+' >'+nullAndLengObject(s[i],'',15)+'</a></li>');
	}
}
function getpersonSearchForList_main()
{
	var str =getUsername(trim("personSearchName"));
	var str1=getUsername(trim("personSearchVal"));
	var s = str.split("|");
	var s1=str1.split("|");
	for(var i=0;i<1;i++)
	{
		document.write('<ul><a class="c0079D6"  target="_blank" href="http://www.joinren.com/'+encodeURI('search/searchJob.joinren?'+s1[i].replaceAll("@","=")+'&searchname='+s[i]).replace(/\+/g,"%2b").replace(/\#/g,"%23")+'"  title='+s[i]+' >'+nullAndLengObject(s[i],'',22)+'</a></ul>');
	}
}
function getPersonSearchVal(){
	var str =getUsername(trim("personSearchVal"));
    if( trim(str) == ""){
		return ;
	}
	var s = str.split("|");
	return s[0];
}

function saveSearchVal(value){
    var cookieString="searchVal="+value;
    var date=new Date(); 
	date.setTime(date.getTime()+30*24*3600*1000); 
	cookieString=cookieString+"; expires="+date.toGMTString(); 
	document.cookie=cookieString;
    return ;
}
function getSearchVal(){
    return getUsername("searchVal");
}

function splitSearch(str,showstr){
  if(str=="")return;
  var s=str.split("&");
  var s2=showstr.split(" ");
  var tmp;
  for(var i=0,j=0;i<s.length;i++){
  
  if(s[i]=="")continue;
     tmp=s[i].split("=");
     if(tmp.length==2){
     if("currresidence"==tmp[0]){
      $("#areav").val(tmp[1]);
       $("#areas").val(s2[j++]);
       continue;
       }
     if("interviewpay"==tmp[0])
 	 {	
 		$("#allowinterpay").attr("checked",true);
 		 continue;
 	 }
       if("permresidence"==tmp[0]){
         $("#areamv").val(tmp[1]);
       $("#areams").val(s2[j++]);
       continue;
       }
       if("industry"==tmp[0]){
         $("#hengv").val(tmp[1]);
       $("#heng").val(s2[j++]);
       continue;
       }
       if("positiontype"==tmp[0]){
       if(tmp[1].indexOf(",")==0){
       $("#nearcid").val( tmp[1].substring(1,tmp[1].length));
       }else{
       $("#nearcid").val(tmp[1]);
       }
       $("#nearc").val(s2[j++]);
       continue;
       }
       if("worknature"==tmp[0])
       {
       $("#worknature").val(tmp[1]);
       $("#text__worknature").val(s2[j++]); 
       continue;
       }
       if("major"==tmp[0])
       {
       	 $("#categoryv").val(tmp[1]);
       $("#category").val(s2[j++]);
        continue;	
       }
       if("politics"==tmp[0])
       {
       	$("#cond_politics").val(tmp[1]);
        $("#text__cond_politics").val(s2[j++]); 
        continue;	
       }
       if("ltoffset"==tmp[0])
       {
       $("#cond_latestlogintime").val(tmp[1]);
       $("#text__cond_latestlogintime").val(s2[j++]); 
       continue;
       }
        if("keyword"==tmp[0])
       {
       	$("#keyword").val(tmp[1]);
       
       	continue;
       }
       $("#cond_"+tmp[0]).val(tmp[1]);
       $("#text__cond_"+tmp[0]).val(s2[j++]);
       
     }
  }
  return true;
}


//保存到cookie中,value=1己查看，2己申请
function setJobStatus(name,id,value){
name = convertFlag(name);
if(name == '') return;
   var cookieString=name+id+"="+value;
   var date=new Date(); 
date.setTime(date.getTime()+30*24*3600*1000); 
cookieString=cookieString+"; expires="+date.toGMTString(); 
document.cookie=cookieString;
return ;
}

//将名字转换成标识
function convertFlag(str){
    switch(str){
    case 'position': return 'pos';
    case 'person': return 'per';
    default :return '';
    }
}
 function delCookie(name){//为了删除指定名称的cookie，可以将其过期时间设定为一个过去的时间
    var date = new Date();
    date.setTime(date.getTime() - 10000);
    document.cookie = name + "=; expires=" + date.toGMTString();
   }
   
   
//去除前后空格
function trim(str){
     if(str == null || str == "undefined")
     return "";
   return str.replace(/(^\s*)|(\s*$)/g, "");
}
function nullObject(value,defaultval)
{
    if(value!=null)return value;
    else return defaultval;
}
/**  
* 时间对象的格式化;
*/
Date.prototype.format = function(format){
 /*
  * eg:format="YYYY-MM-dd hh:mm:ss";
  */
 var o = {
  "M+" :  this.getMonth()+1,  //month
  "d+" :  this.getDate(),     //day
  "h+" :  this.getHours(),    //hour
      "m+" :  this.getMinutes(),  //minute
      "s+" :  this.getSeconds(), //second
      "q+" :  Math.floor((this.getMonth()+3)/3),  //quarter
      "S"  :  this.getMilliseconds() //millisecond
   }

   if(/(y+)/.test(format)) {
    format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
   }

   for(var k in o) {
    if(new RegExp("("+ k +")").test(format)) {
      format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
    }
   }
 return format;
}

    String.prototype.replaceAll  = function(s1,s2){
        return this.replace(new RegExp(s1,"gm"),s2);
    }
   function formatNumber(value,num) {
   var a_int=parseInt(value*Math.pow(10,(num+1)));//乘以10的num+1次方
 if (a_int==0)
  return "0.00";
 var a_str=a_int.toString();//转成字符串

 if (a_str.substring(0,1)!="-")//正数
 {
  var b_str=a_str.substring(a_str.length-1,a_str.length);//取最后一位
  var b_int=parseInt(b_str);
  if (b_int>=5)
   a_int=a_int+10;
 }
 else//负数
 {
  var b_str=a_str.substring(a_str.length-1,a_str.length);
  var b_int=parseInt(b_str);
  if (b_int>=5)
   a_int=a_int-10;
 }
 a_str=a_int.toString();
 var leftlength=a_str.length-(num+1);//小数点左侧取的位数
 var rightlength=(num+1);//小数点右侧取的位数
 var leftstr = a_str.substring(0,leftlength);//小数点左侧的数
 var rightstr = a_str.substring(a_str.length-rightlength,a_str.length);
 rightstr = rightstr.substring(0,num);//小数点右侧的数
 var c_str=leftstr+"."+rightstr;//重新组合字符串


 if (value.toString().substring(0,3)=="-0.")
  c_str="-0."+rightstr;
 if(value.toString().substring(0,2)=="0.")
  c_str="0."+rightstr;

 return c_str;
}
    function formatDate(value,valueformat) {
        if(value==null)return "";
        //return parseDate(value).localeFormat("d");
//　　　　　　return value.format("d");
        //alert(value.substring(0,10));//年月日
        //alert(value.substring(11,19));时间分秒
        ///alert((new Date(value)).format("yyyy-MM-dd"));
        //alert(value);
        value = value.replace("T"," ");    //正常时间   //年月日 时间分秒,任何格式通过这个来过滤
        value = value.replaceAll("-","/");
        //alert(value);
        var d2 = new Date(value);
        if((d2==null)||(d2==undefined))return "";
        //alert(d2);
        if(valueformat=="")valueformat="yyyy-MM-dd hh:mm:ss";
        value = d2.format(valueformat);
        return value;
　}


function myStrLen(str){
    var len;var i;len=0;
    for (i=0;i<str.length;i++){
    if (str.charCodeAt(i)>255) len+=2; else len++;
    }
    return len;
}

//mSubstr()返回长度为slen字节的子串，如果刚好截取到半个中文字，则扔掉最后半个。
function mySubstr(str,slen)
{
    if(str==null)return "";
    else if(str==undefined)return "";
    var tmp = 0;
    var len = 0;
    var okLen = 0;
    for(var i=0;i<slen;i++)
    {
        if(str.charCodeAt(i)>255){
            tmp += 2;
        }else{
            len += 1;
        }
        okLen += 1;
        if(tmp + len == slen)
        {
            return (str.substring(0,okLen));
            break;
        }
        if(tmp + len > slen)
        {
            return (str.substring(0,okLen - 1));
            break;
        }
     }
}
function nullAndLengthObject(value,defaultval)
{
    if(value!=null){
       if(value.length >8 ){
         value = value.substring(0,8)+"...";
         return value;
       }else{
       return value;
       }
        }
    else return defaultval;
}

function nullAndLengObject(value,defaultval,length)
{
    if(value!=null){
       if(value.length >length ){
         value = value.substring(0,length)+"...";
         return value;
       }else{
       return value;
       }
        }
    else return defaultval;
}

function nullAndLengthObjectSearch(value,defaultval)
{
    if(value!=null){
    	value =value.replace(/&nbsp;/g,"");
       if(value.length >12 ){
         value = value.substring(0,12)+"...";
         return value;
       }else{
       return value;
       }
        }
    else return defaultval;
} 

	function showsoso(obj,sender)
			{   
				document.getElementById(obj).style.display = "block";
				var leftpos = 0,toppos = 0;
				var pObject = sender.offsetParent;
				if (pObject)
				{
					leftpos += pObject.offsetLeft;
					toppos += pObject.offsetTop;
				}
				while(pObject=pObject.offsetParent )
				{
					leftpos += pObject.offsetLeft;
					toppos += pObject.offsetTop;
				};

				document.getElementById(obj).style.left = (sender.offsetLeft + leftpos - 175) + "px";
				document.getElementById(obj).style.top = (sender.offsetTop + toppos + sender.offsetHeight + 5) + "px";
			    } 
	function showsoso1(obj,sender)
			{   
				 getPersonMatchJob();  
				document.getElementById(obj).style.display = "block";
				var leftpos = 0,toppos = 0;
				var pObject = sender.offsetParent;
				if (pObject)
				{
					leftpos += pObject.offsetLeft;
					toppos += pObject.offsetTop;
				}
				while(pObject=pObject.offsetParent )
				{
					leftpos += pObject.offsetLeft;
					toppos += pObject.offsetTop;
				};

				document.getElementById(obj).style.left = (sender.offsetLeft + leftpos - 120) + "px";
				document.getElementById(obj).style.top = (sender.offsetTop + toppos + sender.offsetHeight + 5) + "px";
			    } 		    
			    
	function getPersonMatchCount() {
      $.ajax({
                url: '../interface/getPersonMatchList.joinren',
                cache:false,
                async:true,
                contentType: "application/x-www-form-urlencoded",
                datatype:'json',
                type: 'GET',
                beforeSend: function() {
                },
                error: function(request) {alert("error");
                },
                success: function(data) {
                   json_result = JSON.parse(data);
                   var counts=json_result.more.length();
                   alert(counts); 
                }
        });
    }		    
     //获取匹配列表
   function getPersonMatchJob() {
      $.ajax({
                url: '../interface/getMatchJobListNoCount.joinren',
                cache:false,
                async:true,
                contentType: "application/x-www-form-urlencoded",
                dataType:'json',
                type: 'GET',
                beforeSend: function() {
                       //grid_ShowProgressInd();
                },
                error: function(request) {alert("error");
                          // grid_HideProgressInd();
                },
                success: function(data) {
                              grid_matchtemplate(data);
                }
        });

    }
    
   var json_result=null;
   function grid_matchtemplate(msg) {
        if(msg=="null")return;
            $("#search_Container").setTemplateElement("search_template");
            $("#search_Container").processTemplate(msg.more);
       }
 
 function showInfo(){
  $("#proxyaaa").click();
   getSearchCond();
  $("#s_name").html(searchStr);
 }
 
 function showInfo2()
 {
 	$("#proxybbb").click();
 	$.ajax({
                url: '../interface/getMatchJobList.joinren',
                cache:false,
                async:true,
                contentType: "application/x-www-form-urlencoded",
                datatype:'json',
                type: 'GET',
                beforeSend: function() {
                       //grid_ShowProgressInd();
                },
                error: function(request) {alert("error");
                          // grid_HideProgressInd();
                },
                success: function(data) {
                             if(data=="null")return;
        					 json_result = JSON.parse(data);
        					 $("#search_Container2").setTemplateElement("search_template2");
                             $("#search_Container2").processTemplate(json_result.more);
                }
        });
 	
 }
     function savecons()
    {
    	 var is_login=$("#is_login").val();
    	 if(is_login!=1)
    	 {
    	 	alert("登录后才能操作此项功能");
    	 	return;
    	 }
    	 $.ajax({
                url: '../interface/getMatchJobList.joinren',
                cache:false,
                async:true,
                contentType: "application/x-www-form-urlencoded",
                datatype:'json',
                type: 'GET',
                beforeSend: function() {
                       //grid_ShowProgressInd();
                },
                error: function(request) {alert("error");
                          // grid_HideProgressInd();
                },
                success: function(data) {
                             json_result = JSON.parse(data);
                             if(json_result.more.length<6)
                             {
                             	showInfo();
                             }
                             else
                             {
                             	showInfo2();
                             }
                }
        });
    }
    
   	function saveSearchCond(){
        var parm=getSearchCond();
        savePersonSearch(searchcond);
        savePersonSearchVal(searchVal);
        var params = parm+"&name="+$("#s1_name").val();
        params=params.replace("keywordtype","keyword_type").replace("salary","pay_from").replace("allowinterpay","pay_way").replace("worknature","work_nature");
        $.ajax({
	                url: "../interface/savePersonMatch.joinren",
	                cache:false,
	                async:true,
	                contentType: "application/x-www-form-urlencoded",
	                datatype:'json',
	                data:params,
	                type: 'post',
	        beforeSend: function() {
	                },
	                error: function(request) {
	                },
	        success: function(msg) {
	        if(msg=="null")return;
	        json_result = JSON.parse(msg);
	        if(json_result.returnCode == 0){
	        	getPersonMatchJob();
	        	tb_remove();
	        }
	        else{
	         alert("保存失败!");
	        }
	        }
	     });
    }
    
    function updatesearch(mid)
    {
    	var parm=getSearchCond();
        savePersonSearch(searchcond);
        savePersonSearchVal(searchVal);
        var params = parm+"&matchplan_id="+mid;
        params=params.replace("keywordtype","keyword_type").replace("salary","pay_from").replace("allowinterpay","pay_way").replace("worknature","work_nature");
    	$.ajax({
                url: "../interface/upatePersonMatch.joinren",
                cache:false,
                async:true,
                contentType: "application/x-www-form-urlencoded",
                datatype:'json',
                data:params,
                type: 'post',
        beforeSend: function() {
                },
                error: function(request) {
                },
        success: function(msg) {
        if(msg=="null")return;
        json_result = JSON.parse(msg);
        if(json_result.returnCode == 0){
        	alert("替换成功");
        	tb_remove();
        }
        else{
         alert("替换失败!");
        }
        }
     });
    } 

    function clearKeyword(obj) {
  			var keywordValue = obj.value.replace(/(^\s*)|(\s*$)/g, "");
  			if (keywordValue == "结果中包含关键词") {
    		obj.value = "";
   		}
  		}
  		
  	function clearKeyword_except(obj) {
  			var keywordValue = obj.value.replace(/(^\s*)|(\s*$)/g, "");
  			if (keywordValue == "输入排除词") {
    		obj.value = "";
   		}
  	} 
	function putPositionsInFavor(){
    	var ids=getselected();
	    if(ids!=""){
	        $.ajax({
	                 type: "POST",
	                    url: "../interface/putPositionsInFavor.joinren",
	                    cache:false,
	                    async:true,
	                    contentType: "application/x-www-form-urlencoded",
	                    dataType:'json',
	                    data:'positionId='+ids,
	                    beforeSend: function() {
	                         },
	                         error: function(request) {
	                         close_Shieldingpop();
	                         },
	                 success: function(msg) {
		                 if(msg.returnCode==0)
		                 {
		                 	alert("收藏成功");
		                 }
		                 else
		                 {
		                 	alert(msg.codeDesc);
		                 }
	                 }
	              });
	              }
	              else{
	               alert("请先选择！");return false;
	           }
	  }
   
   function putPositions_InFavor(ids){
	    if(ids!=""){
	        $.ajax({
	                 type: "POST",
	                    url: "../interface/putPositionsInFavor.joinren",
	                    cache:false,
	                    async:true,
	                    contentType: "application/x-www-form-urlencoded",
	                    datatype:'json',
	                    data:'positionId='+ids,
	                    beforeSend: function() {
	                         },
	                         error: function(request) {
	                         close_Shieldingpop();
	                         },
	                 success: function(msg) {
	                 alert("收藏成功");
	                 }
	              });
	              }
	              else{
	               alert("请先选择！");return false;
	           }
	  }
   	function replaceStr(s){
		s = s.replace(new RegExp("&lt;br&gt;","gm"),"   ");
		s = s.replace(new RegExp("&lt;/p&gt;","gm"),"   ");
		s=s.replaceAll("<br>","");
		s=s.replaceAll("<hr>","");
		s=s.replaceAll("</p>","");
		s=s.replaceAll("&nbsp;","");
		s=s.replaceAll("","");
		if(s.length>240)s=s.substring(0,240)+"....";   
		return s;
	}
	
	  function grid_PageAction(action,param){
            var tmpcurrentpage        =  parseInt($("#grid_currentpage").val());
            var tmppagecount   =  parseInt($("#grid_pagecount").val());
            if(action=="prev"){
                      tmpcurrentpage--;
            }
            else if(action=="next"){
                     tmpcurrentpage++;
            }
           if((tmpcurrentpage>0)&&(tmpcurrentpage<=tmppagecount)){
               parseInt($("#grid_currentpage").val(tmpcurrentpage));
               sub();
           }
        }	
     
     function toPage(cur)
     {
     	parseInt($("#grid_currentpage").val(cur));
        sub();
     }   

    function switchcheckall2(){
         $("input[name='grid_checkitem']").each(function() {
							$(this).attr("checked", $("#switchcheckall").attr("checked"));
          });
    }
	
    function getselected(){
          var aa="";
          $("input[name='grid_checkitem'][checked]").each(function() {
					aa += $(this).val()+",";
          });
         return aa;
    }
 /**申请**/   
 function bitchApply(obj){
   var ids=getselected();
    if(ids!=""){
     	$(obj).attr("href","../personCommon/toApplyJob.joinren?jobIds="+ids);
     	$(obj).attr("target","_blank");
     	return true; 
     }
    else{
     alert("请先选择！");
     return false;}
 }
 
 //获取表单参数
 function getSearchCond(){
        tmpmatch="";    
        var tmpparam="1=1";
        var tmpstr= "";
        var work_nature1=0;
        var work_nature2=0;
        if($("#keyword").val()!="" && $("#keyword").val()!="结果中包含关键词"){
        	tmpparam+="&keyword="+$("#keyword").val();
        	var keyt=$("input[name='cond_keyscope'][@checked]").val();
        	var kn="(全文)"
        	if(keyt==2)
        	{
        		kn="(职位)"
        	}
        	if(keyt==3)
        	{
        		kn="(公司)"
        	}
        	tmpstr+=$("#keyword").val()+kn;
        }
        if($("#work_area").val()!=""){
        	tmpparam+="&work_area="+$("#work_area").val();
        	if(tmpstr=="")
        	{
        		tmpstr+=$("#txtLoc").val();
        	}
        	else
        	{
        		tmpstr+="+"+$("#txtLoc").val();
        	}
        }
        if($("#position_level").val()!=""){
        	tmpparam+="&position_level="+$("#position_level").val();
        	if(tmpstr=="")
        	{
        		tmpstr+=$("#txtCat").val();
        	}
        	else
        	{
        		tmpstr+="+"+$("#txtCat").val();
        	}
        }
        if($("#industry").val()!=""){
        	tmpparam+="&industry="+$("#industry").val();
        	if(tmpstr=="")
        	{
        		tmpstr+=$("#txtInd").val();
        	}
        	else
        	{
        		tmpstr+="+"+$("#txtInd").val();
        	}
        }
       if($("#keyword_except").val()!="" && $("#keyword_except").val()!="输入排除词"){
        	tmpparam+="&keyword_except="+$("#keyword_except").val();
        	tmpstr+="-"+$("#keyword_except").val();
        }
        if($("#comp_nature").val()!=0){
        	tmpparam+="&comp_nature="+$("#comp_nature").val();
        	tmpstr+="+"+$("#comp_nature option:selected").text();
        }
        if($("#comp_scope").val()!=0){
        	tmpparam+="&comp_scope="+$("#comp_scope").val();
        	tmpstr+="+"+$("#comp_scope option:selected").text();
        }
        if($("#salary").val()!=0){
        	tmpparam+="&salary="+$("#salary").val();
        	tmpstr+="+"+$("#salary option:selected").text();
        }
        if($("#worknature1").attr('checked')==true){
        	work_nature1=$("#worknature1").attr("value");
        }
        if($("#worknature2").attr('checked')==true){
        	work_nature2 =$("#worknature2").attr("value");
        }
        if(work_nature1>0 && work_nature2==0){
          tmpparam+="&worknature="+work_nature1;
        }
        if(work_nature1==0 && work_nature2>0){
          tmpparam+="&worknature="+work_nature2;
        }
        if(work_nature1==0 && work_nature2==0)
        {
        	tmpparam+="&worknature=0";
        }
        if(work_nature1>0 && work_nature2>0)
        {
        	tmpparam+="&worknature=1";
        }
        if($("#work_years").val()!=0){
        	tmpparam+="&work_years="+$("#work_years").val();
        	tmpstr+="+"+$("#work_years option:selected").text();
        }
        if($("#education").val()!=0){
        	tmpparam+="&education="+$("#education").val();
        	tmpstr+="+"+$("#education option:selected").text();
        }
        if($("#marriage").val()!=0){
        	tmpparam+="&marriage="+$("#marriage").val();
        	tmpstr+="+"+$("#marriage option:selected").text();
        }
        
        if($("#update_date").val()!=0){
        	tmpparam+="&update_date="+$("#update_date").val();
        	tmpstr+="+"+$("#update_date option:selected").text();
        }

        if($("#allowinterpay").attr('checked')==true){
        	tmpparam+="&allowinterpay=1";
        }
        else
        {
        	tmpparam+="&allowinterpay=0";
        }
        var tmpsex=$("input[name='cond_sex'][@checked]").val();
     	if(tmpsex==99||tmpsex==100)
     	{
        	tmpparam+="&sex="+tmpsex;
        	if(tmpsex==99)
        	{
        		tmpstr+="+"+"男";
        	}
        	else
        	{
        		tmpstr+="+"+"女";
        	}
     	}
        tmpparam+="&keywordtype="+$("input[name='cond_keyscope'][@checked]").val();
        searchcond=tmpstr;
        searchVal=tmpparam;
        searchVal=searchVal.replaceAll("=","@");
        tmpmatch=tmpparam;
        searchStr=tmpstr;
        if($("#grid_currentpage").val()!=""||$("#grid_currentpage").val()!=null){
        	tmpparam+="&pageindex="+$("#grid_currentpage").val();
        }else{
        	tmpparam+="&pageindex=1";
        }
        return tmpparam;
    } 
     
function UrlEncode(str){ 
   var ret=""; 
   var strSpecial="!\"#$%'()*+,/:;<>[]^`{|}~%"; 
   alert(str.length);
   for(var i=0;i<str.length;i++){ 
    var chr = str.charAt(i);
     var c=str2asc(chr); 
     //tt += chr+":"+c+"n"; 
     if(parseInt("0x"+c) > 0x7f){ 
       ret+="%"+c.slice(0,2)+"%"+c.slice(-2); 
            alert(ret);
     }else{ 
       if(chr==" ") 
         ret+="+"; 
       else if(strSpecial.indexOf(chr)!=-1) 
         ret+="%"+c.toString(16); 
       else 
         ret+=chr; 
     } 
   } 
   return ret; 
} 
function str2asc(str){
    return str.charCodeAt(0).toString(16);
}
function asc2str(str){
    return String.fromCharCode(str);
}

function UrlDecode(str){ 
   var ret=""; 
   for(var i=0;i<str.length;i++){ 
    var chr = str.charAt(i); 
     if(chr == "+"){ 
       ret+=" "; 
     }else if(chr=="%"){ 
      var asc = str.substring(i+1,i+3); 
 
      if(parseInt("0x"+asc)>0x7f){ 
       ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6))); 
       i+=5; 
      }else{ 
       ret+=asc2str(parseInt("0x"+asc)); 
       i+=2; 
      } 
     }else{ 
       ret+= chr; 
     } 
   } 
   return ret; 
} 
    //搜索
    function sub()
    {
  		if(checkSearchForm()==false)
  		{
  			return;
  		}
  	
  		var tmpparam = getSearchCond();
  		savePersonSearch(searchcond);
        savePersonSearchVal(searchVal);
        var searchType=$("#searchType").val();
       	document.location.href=encodeURI("searchJob.joinren?"+tmpparam+"&searchname="+searchStr+"&searchType="+searchType).replace(/\+/g,"%2b").replace(/\#/g,"%23");
    }
    function subForm()
    {
    	$("#grid_currentpage").val(1);
    	sub();
    }
    
        function urlsubForm_fromindex(url)
    {
     	searchVal=url;
        searchVal=searchVal.replaceAll("=","@");
        searchStr=splitPersonMathchJob(url);
        savePersonSearch(searchStr);
        savePersonSearchVal(searchVal);
        document.location.href=encodeURI("search/searchJob.joinren?"+url+"&searchname="+searchStr+"&searchType=0").replace(/\+/g,"%2b");
    }
    
    function urlsubForm(url)
    {
     	searchVal=url;
        searchVal=searchVal.replaceAll("=","@");
        searchStr=splitPersonMathchJob(url);
        savePersonSearch(searchStr);
        savePersonSearchVal(searchVal);
        document.location.href=encodeURI("searchJob.joinren?"+url+"&searchname="+searchStr+"&searchType=0").replace(/\+/g,"%2b");
    }
    //验证搜索表单
    function checkSearchForm()
    {
    	var checkstring="";
    	if($("#position_level").val()!=""){
        	checkstring+=+$("#position_level").val();
        }
        if($("#industry").val()!=""){
        	checkstring+=+$("#industry").val();
        	
        }
        if($("#work_area").val()!=""){
        	checkstring+=$("#work_area").val();
        }
        if($("#keyword").val()!="" && $("#keyword").val()!="结果中包含关键词"){
        	checkstring+=$("#keyword").val();
        }
        if(trim(checkstring)=="")
        {
        	alert("请输入关键字，或者选择职位类别/行业背景/工作地点!");
        	return false;
        }
        else
        {
        	return true;
        }
    }
    
function splitPersonSearch(str)
{  
	if(str=="")return;
	var  s=str.split("&");
	var tmp;
	for(var i=0,j=0;i<s.length;i++)
	{
	if(s[i]=="")continue;
     tmp=s[i].split("=");
     if(tmp.length==2){
     
     if("1"==tmp[0]){
     	continue;
       }
   	 if("position_level"==tmp[0]){
   	   $("#position_level").val(tmp[1]);
       $("#txtCat").val(getTopStr(traversalPosition(tmp[1]),10));
       continue;
     }
     if("work_area"==tmp[0]){
       $("#work_area").val(tmp[1]);
       $("#txtLoc").val(getTopStr(traversalArea(tmp[1]),10));
       continue;
     }
     if("industry"==tmp[0]){
       $("#industry").val(tmp[1]);
       $("#txtInd").val(getTopStr(traversalInd(tmp[1]),10));
       continue;
      }
     if("comp_nature"==tmp[0])
     {
     	new selectComm('comp_nature',tmp[1],'searchjob_select2_w159');
     	continue;
     } 
     if("comp_scope"==tmp[0])
     {
     	new selectComm('comp_scope',tmp[1],'searchjob_select2_w159');
     	continue;
     } 
     if("salary"==tmp[0])
     {
     	new selectComm('salary',tmp[1],'searchjob_select2_w159');
     	continue;
     } 
     if("work_years"==tmp[0])
     {
     	new selectComm('work_years',tmp[1],'searchjob_select2_w159');
     	continue;
     } 
     if("education"==tmp[0])
     {
     	new selectComm('education',tmp[1],'searchjob_select2_w159');
     	continue;
     } 
     if("marriage"==tmp[0])
     {
     	new selectComm('marriage',tmp[1],'searchjob_select2_w83');
     	continue;
     } 
     if("update_date"==tmp[0])
     {
     	new selectComm('update_date',tmp[1],'searchjob_select2_w159');
     	continue;
     } 
     if("keyword"==tmp[0])
     {
       $("#keyword").val(tmp[1]);
       continue;
     }
     if("keyword_except"==tmp[0])
     {
       $("#keyword_except").val(tmp[1]);
       continue;
     }
     if("allowinterpay"==tmp[0])
     {	 
       	 if(tmp[1]==1)
       	 {
       	 	$("#allowinterpay").attr("checked",true);
       	 }
       	 else
       	 {
       	 	$("#allowinterpay").attr("checked",false);
       	 }
       	 continue;
     }
       if("sex"==tmp[0])
       {
        if(tmp[1]==99)
        {
        	$("#sex1").attr("checked",99);
        }
        else if(tmp[1]==100)
        {
        	$("#sex2").attr("checked",100);
        }
        else
        {
        	$("#sex1").attr("checked",0);
        	$("#sex2").attr("checked",0);
        }
       	 continue;
       }
      if("worknature"==tmp[0])
       {
       	  if(tmp[1]==0)
       	  {
       	  	$("#worknature1").attr("checked",false);
        	$("#worknature2").attr("checked",false);
       	  }
       	  else if(tmp[1]==24)
       	  {
       	  	$("#worknature1").attr("checked",true);
        	$("#worknature2").attr("checked",false);
       	  }
       	  else if(tmp[1]==25)
       	  {
       	  	 $("#worknature1").attr("checked",false);
             $("#worknature2").attr("checked",true);
       	  }
       	  else
       	  {
       	  	 $("#worknature1").attr("checked",true);
             $("#worknature2").attr("checked",true);
       	  }
       	  continue;
       }  
       if("keywordtype"==tmp[0]){
        $("#keyscope_"+tmp[1]).attr("checked",tmp[1]);
        continue;
       }
                              
	 }
	}
	return true;
}
    
    function cleanForm()
    {
        if($("#keyword").val()!="" && $("#keyword").val()!="结果中包含关键词"){        	 
        	 $("#keyword").val("结果中包含关键词");
        }
        if($("#work_area").val()!=""){
        	$("#work_area").val("");
        	$("#txtLoc").val("请选择工作地点");
        }
        if($("#position_level").val()!=""){
        	$("#position_level").val("");
        	$("#txtCat").val("请选择职业类别");
        }
        if($("#industry").val()!=""){
        	$("#industry").val("");
        	$("#txtInd").val("请选择行业类别");
        }
       if($("#keyword_except").val()!="" && $("#keyword_except").val()!="输入排除词"){
      		$("#keyword_except").val("输入排除词");
        }
        if($("#comp_nature").val()!=0){
       		$("#comp_nature").val("0");
        }
        if($("#comp_scope").val()!=0){
        	$("#comp_scope").val("0");
        }
        if($("#salary").val()!=0){
        	$("#salary").val("0");

        }
        if($("#work_years").val()!=0){
        	$("#work_years").val("0");
        }
        if($("#education").val()!=0){
        	$("#education").val("0");

        }
        if($("#marriage").val()!=0){
        	$("#marriage").val("0");

        }
        if($("#update_date").val()!=0){
        	$("#update_date").val(0);
        }
        $("#worknature1").attr("checked",true);
        $("#worknature2").attr("checked",false);
        $("#allowinterpay").attr("checked",true);
        $("#sex1").attr("checked",0);
        $("#sex2").attr("checked",0);
        $("#keyscope_1").attr("checked",1);
        $("#keyscope_2").attr("checked",0);
        $("#keyscope_3").attr("checked",0);
        return ;
    }
  function checkPayWay()
 {
 	var s=$("#salary").val();
 	if(s!='0')
 	{
 		$("#allowinterpay").attr("checked",false);
 		$("#allowinterpay").attr("disabled","disabled");	
 	}
 	else
 	{
 		$("#allowinterpay").attr("checked",true);
 		$("#allowinterpay").attr("disabled","");	
 	}
 	return;
 }    
function splitPersonMathchJob(str)
{  
	var res="";
	var flag=0;
	if(str=="")return res;
	str=str.replaceAll('amp;','');
	var  s=str.split("&");
	var tmp;
	for(var i=0,j=0;i<s.length;i++)
	{
	if(s[i]=="")continue;
     tmp=s[i].split("=");
     if(tmp.length==2){
     
     if("1"==tmp[0]){
     	continue;
       }
     if("keyword"==tmp[0])
     {
       if(tmp[1]!="")
       {
       		res+=tmp[1];
       		flag=1;
       }
       continue;
     }
     if("keywordtype"==tmp[0]&&flag==1){
        if(res!="")
        {
        	var kt="(全文)";
        	if(tmp[1]==2)
        	{
        		kt="(职位)";
        	}
        	if(tmp[1]==2)
        	{
        		kt="(公司)";
        	}
        	res+=kt;
        }
        continue;
     }       
     if("work_area"==tmp[0]){
      
       if(res!="")
       {
       	res+="+"+traversalArea(tmp[1]);
       }
       else
       {
       	res+=traversalArea(tmp[1]);
       }
       continue;
     }  
   	 if("position_level"==tmp[0]){
        if(res!="")
       {
       	res+="+"+traversalPosition(tmp[1]);
       }
       else
       {
       	res+=traversalPosition(tmp[1]);
       }
       continue;
     }
	 if("industry"==tmp[0]){
       if(res!="")
       {
       	res+="+"+traversalInd(tmp[1]);
       }
       else
       {
       	res+=traversalInd(tmp[1]);
       }
       continue;
      }	
     if("keyword_except"==tmp[0])
     {
       res+="-"+tmp[1];
       continue;
     }
     if("comp_nature"==tmp[0])
     {
     	if(tmp[1]!=0)
     	res+="+"+transNameById('comp_nature',tmp[1]);
     	continue;
     } 
     if("comp_scope"==tmp[0])
     {
     	if(tmp[1]!=0)
     	res+="+"+transNameById('comp_scope',tmp[1]);
     	continue;
     } 
     if("salary"==tmp[0])
     {
     	if(tmp[1]!=0)
     	res+="+"+transNameById('salary',tmp[1]);
     	continue;
     } 
     if("work_years"==tmp[0])
     {
     	if(tmp[1]!=0)
     	res+="+"+transNameById('workyears',tmp[1]);
     	continue;
     } 
     if("education"==tmp[0])
     {
     	if(tmp[1]!=0)
     	res+="+"+transNameById('education',tmp[1]);
     	continue;
     } 
     if("marriage"==tmp[0])
     {
     	if(tmp[1]!=0)
     	res+="+"+transNameById('marriage',tmp[1]);
     	continue;
     } 
     if("update_date"==tmp[0])
     {
     	if(tmp[1]!=0)
     	res+="+"+transNameById('update_date',tmp[1]);
     	continue;
     } 
     if("allowinterpay"==tmp[0])
     {	 
       	 if(tmp[1]==1)
       	 {
       	 	res+="+面议";
       	 }
       	 continue;
     }
     if("sex"==tmp[0])
     {
       	 if(tmp[1]==99)
       	 {
       	 	res+="+"+"男";
       	 }
       	 if(tmp[1]==100)
       	 {
       	 	res+="+"+"女";
       	 }
       	 continue;
     }
     if("worknature"==tmp[0])
     {  	 
       	  continue;
     }                     
 }
}
	return res;
}   



        var line = 0;
        var cline= 0;
        function del(){
            if($("#newDiv")){
                $("#newDiv").remove();
                line = 0;
                cline= 0;
            }
        }
     	$(document).ready(function() {
            $(document.body).click(function(){
                del(line);
            });
           
            $(document).keydown(function(){
              if($("#newDiv")){
              var evt=arguments[0] || window.event;
              var keyCode = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
                    if(keyCode == 40){
                    	if(line<0)
                        {
                            	line==cline;	
                        }
                        $("#show_t tbody tr").eq(line).find("td").eq(0).css("backgroundColor", "#316AC4").css("color", "white");
                        $("#show_t tbody tr").eq(line).find("td").eq(1).css("backgroundColor", "#316AC4").css("color", "white");
                        $("#show_t tbody tr").eq(line < 0 ? 0 : line - 1).find("td").eq(0).css("backgroundColor", "white").css("color", "black");     
                        $("#show_t tbody tr").eq(line < 0 ? 0 : line - 1).find("td").eq(1).css("backgroundColor", "white").css("color", "green");    
                        line = (line == $("table tbody tr").length ? 0 : line + 1);
                       
                       //$("#keyword").val($("#show_t tbody tr").eq(line - 1).find("td").eq(0).html());
                      
                       
                    }else if(keyCode == 38){
                    	if(line>cline)
                            {
                            	line==0;	
                            }
                        line = (line == 0 ? $("#show_t tbody tr").length : line - 1);
                        $("#show_t tbody tr").eq(line).find("td").eq(0).css("backgroundColor", "#316AC4").css("color", "white");
                        $("#show_t tbody tr").eq(line).find("td").eq(1).css("backgroundColor", "#316AC4").css("color", "white");
                        $("#show_t tbody tr").eq(line > $("#show_t tbody tr").length ? 0 : line + 1).find("td").eq(0).css("backgroundColor", "white").css("color", "black");    
                        $("#show_t tbody tr").eq(line > $("#show_t tbody tr").length ? 0 : line + 1).find("td").eq(1).css("backgroundColor", "white").css("color", "green");                               
                       
                      // $("#keyword").val($("#show_t tbody tr").eq(line - 1).find("td").eq(0).html());
                        
                     
                    
                    }else if(keyCode == 13){
                       
                        $("#keyword").val($("#show_t tbody tr").eq(line - 1).find("td").eq(0).html());
                        del();
                    }
                    
                }   
            });
       		
            $("#keyword").bind("input propertychange", function(){
                del();
                var top = $("#keyword").offset().top;
                var left = $("#keyword").offset().left;
                var newDiv = $("<div/>").width($("#keyword").width()+2)
                    .css("position", "absolute")
                    .css("backgroundColor", "white")
                    .css("left", left)
                    .css("top", top + $("#keyword").height()+8)
                    .css("border", "1px solid #C0C0C0")
                    .css("border-top", "0px solid #C0C0C0")
                    .attr("id", "newDiv");
                var table = $("<table id='show_t' width='100%'/>")
                    .attr("cellpadding", "0")
                    .attr("cellspacing", "0").css("margin-bottom","7px");
                var tmpstr="";
                if(document.activeElement.id!="keyword")
                {
                	return;
                }
              if(trim($("#keyword").val())!=""&&trim($("#keyword").val())!="结果中包含关键词")
			        {
			        	tmpstr="keyword="+$("#keyword").val();
			        }
			        else
			        {
			        	return;
			        }
		        $.ajax({
	                url: "../interface/searchAwoke.joinren",
	                cache:false,
	                async:true,
	                contentType: "application/x-www-form-urlencoded",
	                datatype:'json',
	                data:tmpstr,
	                type: 'post',
	              beforeSend: function() {
	                },
	                error: function(request) {
	                	
	                },
	          success: function(msg) {
	      		if(msg==null)return;
        		json_result= JSON.parse(msg);
        		if(json_result.rows==null)
        		{
        			return;
        		}
        		 if(json_result.rows.length>0)
        		 {
            		cline=json_result.rows.length;
            		for(var i=0;i<json_result.rows.length;i++)
            		{
            			var tr = $("<tr/>").css("cursor", "pointer").mouseout(function(){
                            $(this).find("td").eq(0).css("backgroundColor", "white").css("color", "black");
                            $(this).find("td").eq(1).css("backgroundColor", "white").css("color", "green");
                        }).mouseover(function(){
                            $(this).find("td").eq(0).css("backgroundColor", "#316AC4").css("color", "white");
                             $(this).find("td").eq(1).css("backgroundColor", "#316AC4").css("color", "white");
                        }).click(function(){
                            $("#keyword").val($(this).find("td").eq(0).html());
                            del();
                        });
                        var td1 = $("<td/>").html(json_result.rows[i].keyword).css("fontSize", "12px")
                            .attr("align", "left").css("fontSize", "12px").css("padding-top",'4px')
                            .css("margin", "5 5 5 5");
                        var td2 = $("<td/>").html("约 " + json_result.rows[i].count + " 结果&nbsp;")
                            .attr("align", "right").css("fontSize", "12px").css("padding-top",'4px')
                            .css("color", "green").css("margin", "5 5 5 5");
                        tr.append(td1).append(td2);
                        table.append(tr);
            		}
                    newDiv.append(table);         	
        		 }
	        }
	     });
         $(document.body).append(newDiv);
                if($("#keyword").val() == ""&&$("#keyword").val()=="结果中包含关键词"){
                    $("#newDiv").remove();
                }
               window.onresize=notify;
				function notify()
				{
					  $("#newDiv").remove();
				}          
            });             
    });
    function MarkHighLight(obj,hlWords,cssClass){
    
     hlWords=AnalyzeHighLightWords(hlWords);
     
     if(obj==null || hlWords.length==0)
      return;
     if(cssClass==null)
      cssClass="C60A00_";
     MarkHighLightCore(obj,hlWords);
     function MarkHighLightCore(obj,keyWords){
      keyWords=keyWords.replace(/\+/g,"/+");
      var re=new RegExp(keyWords, "i"); 
         for(var i=0; i<obj.childNodes.length; i++){
          var childObj=obj.childNodes[i];
          if(childObj.nodeType==3){
           if(childObj.data.search(re)==-1)continue; 
           var reResult=new RegExp("("+keyWords+")", "gi"); 
           var objResult=document.createElement("span");
           objResult.innerHTML=childObj.data.replace(reResult,"<span class='"+cssClass+"'>$1</span>");            
           if(childObj.data==objResult.childNodes[0].innerHTML) continue; 
           obj.replaceChild(objResult,childObj);                    
          }else if(childObj.nodeType==1){
           MarkHighLightCore(childObj,keyWords);
          }
         }
     }     
     //----------分析关键词----------------------
     function AnalyzeHighLightWords(hlWords)
     {
      if(hlWords==null) return "";
      hlWords=hlWords.replace(/\s+/g,"|").replace(/\|+/g,"|");      
      hlWords=hlWords.replace(/(^\|*)|(\|*$)/g, "");
      
      if(hlWords.length==0) return "";
      var wordsArr=hlWords.split("|"); 
      
      if(wordsArr.length>1){
       var resultArr=BubbleSort(wordsArr);
       var result="";
       for(var i=0;i<resultArr.length;i++){
        result=result+"|"+resultArr[i];
       }       
       return result.replace(/(^\|*)|(\|*$)/g, "");

      }else{
       return hlWords;
      } 
     }    
//-----利用冒泡排序法把长的关键词放前面----- 
  function BubbleSort(arr){  
   var temp, exchange; 
   for(var i=0;i<arr.length;i++){   
    exchange=false;    
    for(var j=arr.length-2;j>=i;j--){    
     if((arr[j+1].length)>(arr[j]).length){     
      temp=arr[j+1]; arr[j+1]=arr[j]; arr[j]=temp;
      exchange=true;
     }
    }    
    if(!exchange)break;
   }
   return arr;   
  }
 
    }   
