﻿function LoginSubmit()
{
    if($("t").value=="")
    {
        alert("请选择用户类别");
        $("t").focus();
        return;
    }
    if($("u").value=="")
    {
        $("u").focus();
        alert("请输入用户名");
        return;
    }
    if($("p").value=="")
    {
        alert("请输入密码");
        $("p").focus();
        return;
    }
    var returl = QueryString("returl");
    AjaxMethod("/Login.ashx", "post", "u=" + escape($("u").value) + "&p=" + escape($("p").value) + "&t=" + escape($("t").value) + "&returl=" + returl, LoginCallBack);
}

function LoginCallBack(ajax)
{
    var domain = document.domain.toLowerCase().replace("www.", "");
    var retval = ajax.responseText;
    
    switch(retval)
    {
        case "N1":
            alert("参数错误！");
            break;
        case "N2":
            alert("登录失败，错误的用户名或密码！");
            break;
        case "N3":
            alert("登录失败");
            break;
        case "Y1":
            top.location.href="http://ehr." + domain;
            break;
        case "FailureResume":
            top.location.href = "http://myjob." + domain + "/resume.aspx";
            break;
        case "PersonLogined":
            top.location.href = "http://myjob." + domain;
            break;
        default:
            if(retval.split(":")[0]=="Redir"){top.location.href=retval.substring(retval.indexOf(":")+1);return;}
            alert("未知的消息");
            break;
    }
}

function Reg()
{
    if($("t").value=="")
    {
        alert("请选择用户类别");
        $("t").focus();
        return;
    }
    if($("t").value=="C")
        top.location.href = "/Company_Reg.aspx";
    else
        top.location.href = "/Person_Reg.aspx";
}

function getPass()
{
    if($("t").value=="")
    {
        alert("请选择用户类别");
        $("t").focus();
        return;
    }
       wopen("/password.aspx?" + $("t").value,450,300,400,300);
}

function KeyPress(e)
{
    if(!e)e=event;
    if(e.keyCode==13)
    {
        LoginSubmit();
        if(document.all)
            e.returnValue  = false;
        else
            e.preventDefault();
        return false;
    }
}
//获取用户IP
function GUIP(id)
{
	//缓存
    if(!window.Cache)
    {
        window.Cache = new Object();
    }
    if(window.Cache[id]!=null)
    {
	    alert(window.Cache[id]);
    }
    else
    {
        AjaxMethod("/Ajax.ashx?method=getUserIP", "post", "id=" + id, GUIPCallBack, id);
    }
}
//获取用户IP
function GUIPCallBack(ajax, id)
{
    alert(ajax.responseText);
    window.Cache[id] = ajax.responseText;
}
//登录信息
function LoginInfo()
{
    if(getCookie("P")!=null || getCookie("C")!=null)
        AjaxMethod("/Ajax.ashx", "get", "method=LoginInfo", function(ajax){$("Info").innerHTML=ajax.responseText;$("Info").style.lineHeight="25px"});
    $("Info").style.display="";
}
//企业更新查看次数
function ComVT()
{
    var Point=location.href.split("\#")[1];ID=QueryString("id");
    if(ID!="")
    {
        if(Point==undefined){AjaxMethod("/Ajax.ashx", "get", "method=InitLookTimes&p=&id=" + ID, null);}
        else{AjaxMethod("/Ajax.ashx", "get", "method=InitLookTimes&p=" + Point + "&id=" + ID, null);}
    }
    if(Point!=undefined){Event.observe(window, "load", function(){ComFocus(Point);}, false);}
    Event.observe(window, "load", scroll, false);
    Event.observe(window, "scroll", scroll, true);
    Event.observe(window, "resize", scroll, true);
}
//聚焦
function ComFocus(id)
{
    if(window.lastObject)window.lastObject.className = "job_end";
    if($("j" + id)){$("j" + id).className = "job_ing";
    window.lastObject = $("j" + id);}
}
function scroll()
{
    var pos = getAbsolutePosition($("main"));
    var pos1 = getAbsolutePosition($("nav1"));
    if(document.documentElement.scrollTop>pos.top && pos1.height<document.documentElement.offsetHeight)
    {
        $("nav1").style.top =  document.documentElement.scrollTop + "px";
    }
    $("nav1").style.left =  (pos.left + pos.width - 10) + "px";
}
//个人更新查看次数
function UserVT()
{
    var ID=QueryString("id");
    if(ID!="")
    {
        AjaxMethod("/Ajax.ashx?method=UserViewTimes", "post", "id=" + ID, null);
    }
}
function A(id)
{
    __getAreaNameFromValue(id);
}
function S(id)
{
    __getSysCodeFromValue(id);
}

function getCookie(name)
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return getCookieVal (j);

        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}
function getCookieVal (offset)
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return decodeURI(document.cookie.substring(offset, endstr));
}
function getAllAreaCode(code)
{
    var myName = __getAreaCodesName(code);
    var myCode = __getAreaCodesID(code);
    var retName = [], retCode = [];
    
    for(var i=1;i<myCode.length;i++)
    {
        if(myCode[i].substr(4)=="00")
        {
            var tmp = __getAreaCodesName(myCode[i]);
            for(var j=1;j<tmp.length;j++)
                tmp[j] = "　" + tmp[j];
            retName = retName.concat(tmp);
            retCode = retCode.concat(__getAreaCodesID(myCode[i]))
        }
        else
        {
            retName = retName.concat(new Array(myName[i]));
            retCode = retCode.concat(new Array(myCode[i]));
        }
    }
    retName.unshift(myName[0]);retCode.unshift(myCode[0]);
    return {"Name":retName, "Code":retCode};
}
function SearchSub()
{
    var t = $("ST").value;
    var k = $("SK").value;
    var s = $("SS").value;
    var a = $("SA").value;
    var qu = new Array();
    if(k!="")
    {
        qu[qu.length]="k=" + escape(k.trim());
    }
    if(s!="")
    {
        qu[qu.length]="s=" + s;
    }
    if(a!="")
    {
        qu[qu.length]="a=" + a;
    }
    var url = "";
    switch(t)
    {
        case "J":
            url = "/jobList.aspx";
            break;
        case "P":
            url = "/resumeList.aspx";
            break;
        case "C":
            url = "/companyList.aspx";
            break;
    }
    top.location.href = url + "?" + qu.join("&");
}

function SearchChange(v)
{
    switch(v)
    {
        case "J":
            Forms.initDropList($("SS"),__getSysCodesName("18000"),__getSysCodesID("18000"),QueryString("s"),"职位类别不限","");
            break;
        case "P":
            Forms.initDropList($("SS"),__getSysCodesName("13000"),__getSysCodesID("13000"),QueryString("s"),"专业类别不限","");
            break;
        case "C":
            Forms.initDropList($("SS"),__getSysCodesName("19000"),__getSysCodesID("19000"),QueryString("s"),"行业类别不限","");
            break;
    }
}

function setCss(id, css)
{
    if(css == undefined)css="i_navy_ing";
    if($(id))$(id).className = css;
}

//原QZRC
function createDiv()
{
	var oDiv = document.getElementById("tips");
	if(oDiv==null)
	{
		oDiv = document.createElement("DIV");
		oDiv.id="tips";
		oDiv.style.border="#858585 1px solid";
		oDiv.style.position="absolute";
		oDiv.style.backgroundColor = "#FFFFF1";
		oDiv.style.padding = "5px";
		oDiv.style.color="#333333";
		oDiv.style.lineHeight = "150%";
		document.body.appendChild(oDiv);
		oDiv.style.width = "230px";
		oDiv.style.zIndex = 1000;
	}
	return oDiv;
}
function showJobs(e, id)
{
    if(document.readyState!="complete")return;
	var oDiv = createDiv();
	if(!window.Cache)window.Cache = new Object();
	var x = 0, y = 0;
    if(document.all){x = e.x; y = e.y;}else{x = e.clientX; y = e.clientY;}
    window.E = {x:x, y:y};
	if(window.Cache["C_" + id]!=null)
	{
	    showJobsCallBack(window.Cache["C_" + id], id);
	}
	else
	{
        AjaxMethod("/Ajax.ashx?method=getJobs", "post", "id=" + id, showJobsCallBack, id);
    }
}
function showJobsCallBack(ajax, id)
{
	if(document.readyState!="complete")return;
	var e = window.E || window.event;
	var oDiv = createDiv();
	var inp = typeof(ajax)=="object"?ajax.responseText:ajax;
	oDiv.innerHTML = inp;
	oDiv.style.display = "";
	var docWidth = document.documentElement.scrollWidth;
	var docHeight = document.documentElement.scrollTop;
	var x = e.x,y = e.y;
	if(!e.x)
	{
	    x = e.clientX;y = e.clientY;
	}
	if(oDiv.offsetWidth + x + 30 >= docWidth)
	{
		oDiv.style.left = (docWidth - oDiv.offsetWidth - 30) + "px";
		oDiv.style.top = (y + docHeight + 25) + "px";
	}
	else
	{
		oDiv.style.left = (x + 10) + "px";
		oDiv.style.top = (y + docHeight) + "px";
	}
	window.Cache["C_" + id] = inp;
}
function hideTip()
{
	var oDiv = document.getElementById("tips");
	if(oDiv)
	{
		oDiv.style.display = "none";
	}
}
