﻿// JScript 文件
function $(id)
{
    return document.getElementById(id);
}
function temp(tagname)
{
    return document.documentElement.getElementsByTagName(tagname);
}
//全选
function chkAll(oCheckbox)
{
    $("HdnSelectedValues").value="";
    var num=document.getElementsByName("chk").length;

    for(i=0 ;i<num;i++)
    {
        document.getElementsByName("chk")[i].checked=oCheckbox.checked;
        if(i>0)
            AddRemoveValues(document.getElementsByName("chk")[i]);
    }
}
//单选
function AddRemoveValues(oChk)
{
    var hidden= $("HdnSelectedValues");
    var num=document.getElementsByName("chk").length;
    if(oChk.checked)
    {
        hidden.value+=","+oChk.value;
        if(!document.getElementsByName("chk")[0].checked && !document.getElementsByName("chk")[num-1].checked)
        {
            var chked=true;
            for(i=1;i<num-1;i++)
            {
                if(document.getElementsByName("chk")[i].checked==false)
                    chked=false;    
            }
            if(chked)
            {
                chkAll(oChk);
            }
        }
    }
    else
    {
        hidden.value=hidden.value.replace("," + oChk.value,"");
        document.getElementsByName("chk")[0].checked=oChk.checked;
        document.getElementsByName("chk")[num-1].checked=oChk.checked;
    }
}
//显示浮动层
function LoginOp(display,id)
{
    $("HdnChange").value=id;
    $('big_cont').style.display=display;
    if(document.body.clientHeight<=document.body.scrollHeight)
        $('big_cont').style.height=document.body.scrollHeight;
    else
        $('big_cont').style.height="621";
    $('e_container').style.display=display;
    $(id).style.display=display;
}
//隐藏浮动层
function unLoginOp(display)
{
    $('big_cont').style.display=display;
    $('e_container').style.display=display;
    $($("HdnChange").value).style.display=display;
}
//改变URL
function ChgUrl(oObj,content)
{
    var strUrl;
    var strUrlArray;
    if( $('HdnUrl').value.indexOf(oObj)<0)
    {
        if($('HdnUrl').value=="")
        {
            strUrl=oObj+"="+content;
        }
        else
        {
            strUrl=oObj+"="+content+";"+$('HdnUrl').value.substring(0,$('HdnUrl').value.lastIndexOf(';')).replace("undefined","");
        }
        strUrlArray=strUrl.split(';');
    }
    else
    {
        strUrlArray= $('HdnUrl').value.substring(0,$('HdnUrl').value.lastIndexOf(';')).split(';');
        for(i=0;i<strUrlArray.length;i++)
        {
            if(strUrlArray[i].indexOf(oObj)>=0)
            {
                strUrlArray[i]=oObj+"="+content;
            }
        }
    }
    return strUrlArray;
}
//处理";"
function ChgFH(stringUrl)
{
    var strUrlPro;
    var HdnValue;
    for(i=0;i<stringUrl.length;i++)
    {
        HdnValue+=stringUrl[i]+";";
        if(i==0)
        {
            strUrlPro=stringUrl[i];
        }
        else
        {
            strUrlPro+="|"+stringUrl[i];
        }
    }
    $('HdnUrl').value=HdnValue.replace("undefined","");
    return strUrlPro;
}
//选择层中内容改变URL
function ChangeUrl(oObj,content)
{
    document.location=winopen("search_job_result.htm?"+ChgFH(ChgUrl(oObj,content))+$('HdnSort').value);
}
//取消操作
function CannelUrl(oObj)
{  
    document.location=winopen("search_job_result.htm?"+ChgFH(ChgUrl(oObj,""))+$('HdnSort').value);  
}
//关键字
function inputKeyWord()
{
    var jobname=JStrim($('hrJobName').value);
    var coname=JStrim($('hrCoName').value);
    if(jobname!=""&&coname!="")
    {
        ChgFH(ChgUrl('JobName',jobname));
        ChangeUrl('CoName',coname);
    }
    if(jobname!=""&&coname=="")
    {
        ChgFH(ChgUrl('JobName',jobname));
        CannelUrl('CoName');
    }
    if(jobname==""&&coname!="")
    {
        ChgFH(ChgUrl('CoName',coname));
        CannelUrl('JobName');
    }
    if(jobname==""&&coname=="")
    {
        ChgFH(ChgUrl('JobName',""));
        CannelUrl('CoName');
    }
}
function winopen(oldUrl) 
{ 
    var newUrl,arrUrl; 
    if(typeof(oldUrl) == "undefined" || oldUrl == "") 
    { 
        retUrn ; 
    } 
    else 
    { 
        if(oldUrl.indexOf("?") == -1) 
        {  
            newUrl = oldUrl; 
        } 
        else 
        {
            newUrl = oldUrl.substring(0,oldUrl.indexOf("?")+1); 
            arrUrl = oldUrl.substring(oldUrl.indexOf("?")+1).split("|"); 
            for(var i =0;i<arrUrl.length;i++) 
            {
                newUrl += arrUrl[i].split("=")[0] + "=" + escape(arrUrl[i].split("=")[1]) + "|"; 
            }  
            newUrl = newUrl.substring(0,newUrl.length-1);
        } 
    } 
    return newUrl; 
}
//去掉空格
function JStrim(inputString) 
{ 
    if (typeof inputString != "string") 
    {
        return inputString; 
    } 
    var retValue = inputString; 
    var ch = retValue.substring(0, 1); 
    while (ch == " ") 
    {  
          //检查字符串开始部分的空格 
          retValue = retValue.substring(1, retValue.length); 
          ch = retValue.substring(0, 1); 
    } 
    ch = retValue.substring(retValue.length-1, retValue.length); 
    while (ch == " ") 
    { 
         //检查字符串结束部分的空格 
         retValue = retValue.substring(0, retValue.length-1); 
         ch = retValue.substring(retValue.length-1, retValue.length); 
    } 
    while (retValue.indexOf("  ") != -1) 
    {  
         //将文字中间多个相连的空格变为一个空格 
         retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);  
    } 
    return retValue; 
}
//替换样式
function ExchangeStyle(fatherid,id,display)
{
    for(i=1;i<$(fatherid).getElementsByTagName("div").length/4-(-1);i++)
    {
        $(id+i).style.display=display;
    }
}
//显示隐藏层
function showDiv(liid,ClassName)
{
    $(liid).className=ClassName;
}
//得到收藏
function GetPID()
{
    var PID;
    if($("HdnSelectedValues").value=="")
    {
        alert("请选择要收藏的职位！")
        PID=0;
    }
    else
    {
        var HdnByte=  $("HdnSelectedValues").value.substring(1).split(',');
        if(HdnByte.length>1)
        {   
            for(i=0;i<HdnByte.length-1;i++)
            {
                if(i==0)
                {
                    PID=HdnByte[i].split('|')[1];
                }
                else
                {
                    PID+=","+HdnByte[i].split('|')[1];
                }
            }
        }
        else
        {
            PID= $("HdnSelectedValues").value.substring(1).split('|')[1];
        }
    }
    return PID;
}
//浏览职位
function chkMoreUrl()
{
    var hidden= $("HdnSelectedValues");
    var num=hidden.value.substring(1).split(',').length;
    if(hidden.value!="")
    {
        if(num>1)
            document.location=winopen("viewMulit.aspx?vm="+hidden.value.substring(1));
        else
            document.location=winopen("view.aspx?CPID="+hidden.value.substring(1).split(',')[0].split('|')[0]+"&CUID="+hidden.value.substring(1).split(',')[0].split('|')[1]);
    }
    else
    {
        alert("请选择要浏览的职位！")
    }
}
//添加收藏
function AddPerFavour(PID)
{
    if(PID!=0)
    {
        document.location=winopen("SaveToPerFavour.aspx?PID="+PID+$('HdnSort').value);
    }
}
//翻页
function turnPage(strUrl)
{
    document.location=winopen(strUrl+$('HdnSort').value);
}
//换图
function turnImage(id)
{
    var hidSort=$("HdnSort").value;
    if($('HdnUrl').value.replace("undefined","")!="")
    {
        if(hidSort=="|sort=1")
        {
            $(id).src="img/list03.gif";
            $("HdnSort").value="|sort=0";
            document.location=winopen("search_job_result.htm?"+ChgFH($('HdnUrl').value.substring(0,$('HdnUrl').value.lastIndexOf(';')).split(';'))+$("HdnSort").value);
        }
        if(hidSort=="|sort=0")
        {
            $(id).src="img/list03.jpg";
            $("HdnSort").value="|sort=1";
            document.location=winopen("search_job_result.htm?"+ChgFH($('HdnUrl').value.substring(0,$('HdnUrl').value.lastIndexOf(';')).split(';'))+$("HdnSort").value);
        }
    }
}