
function $(_sId){return document.getElementById(_sId)}
function $F(_sId){return document.getElementById(_sId).value}
function chkdiv(divid){
	var chkid=document.getElementById(divid);
	if(chkid != null)
		{return true; }
	else 
		{return false; }
} 

function killErrors() 
{ return true;}

function jumpToLink(link, target) {
   /*
   if (link.indexOf("?") == -1)
	    link = link + "?smartID=" + Math.ceil(Math.random()*100000000000);
	else
	    link = link + "&smartID=" + Math.ceil(Math.random()*100000000000);
	*/
	
	if (target == null || target == "")
		location.href= link;
	else
		window.open(link, target)
}

window.onerror = killErrors;


function ResetValue(targ,selObj){

var thisvalue=selObj.options[selObj.selectedIndex].value;
if (thisvalue!="-1" && thisvalue!="") 
	$(targ).value=thisvalue;
	
}



//设置筛选条件折叠状态,status=0打开,status=1关闭,name=筛选条件名称
function SetFolderFilter(name, status)
{
    //过期时间为1年后
    var today = new Date();
    var year = today.getFullYear() + 1;
    var expires = new Date();
    expires.setFullYear(year);
    var path = '/';
    setCookie(name, status, expires, path);
}

function GetFolderFilter(name)
{
    var status = getCookie(name);
    if(status == null)
    {
        return 0;
    }
    else
    {
        return status;
    }
}

//得到地址栏传递参数的函数
function QueryString(href,qs)
{
    var s = location.href;
    if (href != "") s = href;
    s = s.replace("?","?&").split("&");
    var re = "";
    for(i=1;i<s.length;i++)
        if(s[i].indexOf(qs+"=")==0)
            re = s[i].replace(qs+"=","");
    return re;
}
/*
function LeftTreeEvent()
{
    var TreeCode = QueryString('treecode');
    if (TreeCode == null || TreeCode == "")
    {
        TreeCode = "1.2";
    }
    TreeCode = TreeCode.replace('#','');
    CodeArry = TreeCode.split('.');
    var tree = document.getElementById('tree' + CodeArry[0]);
    if (tree != null)
    {
        tree.style.display = "";
    }
    var node = document.getElementById(TreeCode);
    if (node != null)
    {
        node.className = "cur";
    }
    ShowTree('tree' + CodeArry[0]);
}
function ShowTree(tree)
{
    for (var i = 1; i <= 3; i++)
    {
        var TreeNum = tree.replace("tree","");
        var objTree = document.getElementById('tree' + i);
        if (objTree != null)
        {
            if (TreeNum != i)
            {
                objTree.style.display = "none";
                var obj = document.getElementById('menu' + i);
                if (obj != null)
                {
                    obj.className = "up";
                }
            }
            else
            {
                objTree.style.display = "";
                var obj = document.getElementById('menu' + i);
                if (obj != null)
                {
                    obj.className = "down";
                }
            }
        }
        
    }
}
//End 导航树
*/
//初始化导航树
function ChangeCurrent(tree,menu)
{
    var obj = document.getElementById(tree);
    if (obj != null)
    {
        obj.style.display = obj.style.display==""?"none":"";
        var TreeNum = tree.replace('resumetree','');
        for (var i = 1; i <=4; i++)
        {
            if (i != TreeNum)
            {
                var other = document.getElementById('resumetree' + i);
                if (other != null && obj.style.display=="")
                {
                    other.style.display = "none";
                }  
            }
        }
        var obj2 = document.getElementById(menu);
        if(obj2 != null)
        {
            if(obj2.className == "down")
            {
                obj2.className = "up";
            }
            else
            {
                obj2.className = "down";
            }
        }
    }
    
}
function InitNavigatorTree()
{
    var navParaName = 'navigator';
    var nav = document.getElementById('hidepart1');
    var list=nav.getElementsByTagName("A");
    var navList = new Array();
    var i, j;
    var n = 0;
    
    //设置所有导航链接的属性
    for(i = 0; i < list.length; i++)
    {
        if(list[i].parentNode == null)
        {
            continue;
        }
        
        if(list[i].parentNode.nodeName != 'LI')
        {
            continue;
        }
        
        if(list[i].href.indexOf('#') >= 0)
        {
            continue;
        }
        
        list[i].id = 'NavNode_' + n;
        navList[n] = list[i];
        n++;
        if(list[i].href.indexOf('&') > 0 || list[i].href.indexOf('?') > 0)
        {
            list[i].href += '&'+ navParaName +'=' + list[i].id;
        }
        else
        {
            /*NavNode_10 '全部应聘简历'的默认搜索是'发布中职位' */
            if(list[i].id == "NavNode_10")
            {
                list[i].href += '?Type=0&ApplyJobState=6&'+ navParaName +'=' + list[i].id;
            }
            else
            {
                list[i].href += '?'+ navParaName +'=' + list[i].id;
            }
        }
    }
    
    //将当前选中的节点置为选中状态
    var path = window.location.href;
    //特殊处理若干导航
    path = SpecialChangeURL(path);
    var index = path.indexOf(navParaName);
    var currentNode = null;
    if(index > 0)
    {
        var selID = path.substring(index + navParaName.length + 1, path.length);
        var selHref = document.getElementById(selID);
        
        SetCurrentClass(selHref);
        //设置Title
        //document.title = GetResumeLibName(selHref) + '·' + selHref.innerText + ' | 智聘系统';
        currentNode = selHref;
    }
    else
    {
        currentNode = FindMaxMatchLinkNode(path, navList, true);
        if(currentNode != null)
        {
            SetCurrentClass(currentNode);
            //设置Title
            //document.title = GetResumeLibName(currentNode) + '·' + currentNode.innerText + ' | 智聘系统';
        }
        else
        {
            var node0 = document.getElementById('NavNode_0');
            currentNode = node0;
            if(node0 != null)
            {
                SetCurrentClass(node0.parentNode);
                //设置Title
                //document.title = GetResumeLibName(node0) + '·' + node0.innerText + ' | 智聘系统';;
            }
        }
    }
    
    //关闭所有的树根
    CloseAllTreeRoot(nav);
    
    //打开当前树根
    if(currentNode != null)
    {
        var treeRoot = GetTreeRoot(currentNode);
        treeRoot.style.display = 'block';
    }
}

function FindMaxMatchLinkNode(href, navList, deep)
{
    var linkNode = null;
    if(href == '')
    {
        return null;
    }
    
    for(i = 0; i < navList.length; i++)
    {
        if(navList[i].href.length < href.length)
        {
            continue;
        }
        
        if(navList[i].href.substring(0, href.length).toLowerCase() == href.toLowerCase())
        {
            linkNode = navList[i];
            return linkNode; 
        }
    }

    var index = href.lastIndexOf('&');
    if(index <= 0)
    {
        index = href.lastIndexOf('?');
    }
    
    var newDeep = true;
    var newHref = href;
    if(index <= 0 && deep == false)
    {
        return null;
    }
    else if(index <= 0 && deep == true)
    {
        newDeep = false;
        newHref = href.substring(0, index);
    }
    else
    {
        newHref = href.substring(0, index);
    }
    linkNode = FindMaxMatchLinkNode(newHref, navList, newDeep);
    return linkNode;
}

//找出一个导航树链接所在的简历库名称
function GetResumeLibName(link)
{
    var parentDiv = GetParentDiv(link);
    if(parentDiv == null)
    {
        return '';
    }
    
    return parentDiv.childNodes[0].innerText;
}

function GetParentDiv(node)
{
    if(node == null)
    {
        return null;
    }

    if(node.parentNode.tagName == 'DIV')
    {
        return node.parentNode;
    }
    
    return GetParentDiv(node.parentNode);
}

//找出一个导航连接所在的树根
function GetTreeRoot(node)
{
    if(node == null)
    {
        return null;
    }

    if(node.parentNode.tagName == 'UL' && node.parentNode.id.indexOf('resumetree') >= 0)
    {
        return node.parentNode;
    }
    
    return GetTreeRoot(node.parentNode);
}

//关闭所有的树根
function CloseAllTreeRoot(nav)
{
    var list=nav.getElementsByTagName("UL");
    var i;
    for(i = 0; i < list.length; i++)
    {
        var ul = list[i];
        if(ul.id.indexOf('resumetree') >= 0)
        {
            ul.style.display = 'none';
        }
    }
}

//特殊处理几个导航(这些页面在导航树上没有，因此需要使用最匹配的导航替换)
function SpecialChangeURL(path)
{
    if(path.indexOf('Favorite/AttachmentResult.aspx') > 0)
    {
        return path.replace('Favorite/AttachmentResult.aspx', 'Favorite/Search.aspx');
    }
    else if(path.indexOf('MyApplyResume/SearchResult.aspx?Type=0&ApplyJobState=255&ApplyJob=0') > 0)
    {
        return path.replace('MyApplyResume/SearchResult.aspx?Type=0&ApplyJobState=255&ApplyJob=0', 'MyApplyResume/SearchResult.aspx');
    }
    else if(path.indexOf('MyApplyResume/AttachmentResult.aspx?Type=1&ApplyJobState=255&ApplyJob=0') > 0)
    {
        return path.replace('MyApplyResume/AttachmentResult.aspx?Type=1&ApplyJobState=255&ApplyJob=0', 'MyApplyResume/SearchResult.aspx');
    }
    else if(path.indexOf('MyApplyResume/SearchResult.aspx?Type=0&ApplyJobState=4') > 0)
    {
        return path.replace('MyApplyResume/SearchResult.aspx?Type=0&ApplyJobState=4', 'MyApplyResume/SearchResult.aspx?Type=0&ApplyJobState=1');
    }
    else if(path.indexOf('MyApplyResume/AttachmentResult.aspx?Type=1&ApplyJobState=4') > 0)
    {
        return path.replace('MyApplyResume/AttachmentResult.aspx?Type=1&ApplyJobState=4', 'MyApplyResume/SearchResult.aspx?Type=0&ApplyJobState=1');
    }
    else if(path.indexOf('MyApplyResume/AttachmentResult.aspx?Type=1') > 0)
    {
        return path.replace('MyApplyResume/AttachmentResult.aspx?Type=1', 'MyApplyResume/SearchResult.aspx?Type=0');
    }
    else if(path.indexOf('MyApplyResume/ResumeListByStatus.aspx') > 0 && path.indexOf('&pageIndex=') > 0 && path.indexOf('&pageSize=') > 0)
    {
        var t = QueryString(path,'pageIndex');
        var s = QueryString(path,'pageSize');
        path = path.replace('&pageIndex=' + t,'').replace('&pageSize=' + s,'') + "&pageIndex=" + t + "&pageSize=" + s;
        var y = QueryString(path,'resumeType');
        if (y == 1)
        {
			path = path.replace('resumeType=' + y,'resumeType=0');
        }
        return path;
        
    }
	else if(path.indexOf('MyApplyResume/ResumeListByStatus.aspx') > 0 && path.indexOf('&pageindex=') > 0 && path.indexOf('&pageSize=') > 0)
    {
        var t = QueryString(path,'pageindex');
        var s = QueryString(path,'pageSize');
        path = path.replace('&pageindex=' + t,'').replace('&pageSize=' + s,'') + "&pageindex=" + t + "&pageSize=" + s;
        var y = QueryString(path,'resumeType');
        if (y == 1)
        {
			path = path.replace('resumeType=' + y,'') + "&resumeType=0";
        }
        return path;
        
    }
    else if(path.indexOf('MyApplyResume/ResumeListByStatus.aspx') > 0 && path.indexOf('&pageindex=') > 0)
    {
        var t = QueryString(path,'pageindex');
        path = path.replace('&pageindex=' + t,'') + "&pageindex=" + t;
        
        var y = QueryString(path,'resumeType');
        if (y == 1)
        {
			path = path.replace('resumeType=' + y,'') + "&resumeType=0";
        }
        return path;
    }
    else if(path.indexOf('MyApplyResume/ResumeListByStatus.aspx?resumeType=1') > 0)
    {
        return path.replace('MyApplyResume/ResumeListByStatus.aspx?resumeType=1', 'MyApplyResume/ResumeListByStatus.aspx?resumeType=0');
    }
    else if(path.indexOf('ResumeCenter/ResumeListByStatus.aspx') > 0 && path.indexOf('&pageIndex=') > 0 && path.indexOf('&pageSize=') > 0)
    {
        var t = QueryString(path,'pageIndex');
        var s = QueryString(path,'pageSize');
        var y = QueryString(path,'type');
        path = path.replace('&pageIndex=' + t,'').replace('&pageSize=' + s,'') + "&pageIndex=" + t + "&pageSize=" + s;
        if (y == 1)
        {
			path = path.replace('type=' + y,'type=0');
        }
        return path;
    }
    else if(path.indexOf('ResumeCenter/ResumeListByStatus.aspx') > 0 && path.indexOf('&pageindex=') > 0 && path.indexOf('&pageSize=') > 0)
    {
        var t = QueryString(path,'pageindex');
        var s = QueryString(path,'pageSize');
        var y = QueryString(path,'type');
        path = path.replace('&pageindex=' + t,'').replace('&pageSize=' + s,'') + "&pageindex=" + t + "&pageSize=" + s;
        if (y == 1)
        {
			path = path.replace('type=' + y,'type=0');
        }
        return path;
    }
    else if(path.indexOf('ResumeCenter/ResumeListByStatus.aspx') > 0 && path.indexOf('&pageindex=') > 0)
    {
        var t = QueryString(path,'pageindex');
        path = path.replace('&pageindex=' + t,'') + "&pageindex=" + t;
        var y = QueryString(path,'type');
        if (y == 1)
        {
			path = path.replace('type=' + y,'type=0');
        }
        return path;
    }
    else if(path.indexOf('ResumeCenter/ResumeListByStatus.aspx?type=1') > 0)
    {
        return path.replace('ResumeCenter/ResumeListByStatus.aspx?type=1', 'ResumeCenter/ResumeListByStatus.aspx?type=0');
    }
    else if(path.indexOf('ResumeCenter/SearchResult.aspx?ApplyJob=0') > 0)
    {
        return path.replace('ResumeCenter/SearchResult.aspx', 'ResumeCenter/Search.aspx');
    }
    else if(path.indexOf('MyApplyResume/AttachmentResult.aspx') > 0)
    {
        return path.replace('MyApplyResume/AttachmentResult.aspx', 'MyApplyResume/SearchResult.aspx');
    }
    ;
    return path;
}

//设置当前高亮LI标签
function SetCurrentClass(li)
{
    if(li.className.indexOf('cur') > 0)
    {
        
    }
    else if(li.className != '')
    {
        li.className = li.className + ' cur';
    }
    else
    {
        li.className = 'cur';
    }
}

//设置筛选状态Div移开光标后消失
function OnSetStatusDivMouseOut(obj)
{
    obj.style.display = 'none';
}

function OnSetStatusDivMouseOver(obj)
{
    obj.style.display = 'block';
}
