

function getY(el) {
    var y = 0;
    for(var e = el; e; e = e.offsetParent)
        y += e.offsetTop;

    for(e = el.parentNode; e && e != document.body; e = e.parentNode)
        if (e.scrollTop) y -= e.scrollTop;

    return y;
}

// Get the X coordinate of the element e.
function getX(el) {
    var x = 0;
    while(el) {
        x += el.offsetLeft;
        el = el.offsetParent;
    }
    return x;
}
var Geometry = {};

Geometry.getWindowX = function() { return window.screenLeft || window.screenX; };
Geometry.getWindowY = function() { return window.screenTop || window.screenY; };
Geometry.getViewportWidth = function() {
    return window.innerWidth || 
        document.documentElement && document.documentElement.clientWidth || 
        document.body.clientWidth;
};
Geometry.getViewportHeight = function() {
    return window.innerHeight || 
        document.documentElement && document.documentElement.clientHeight || 
        document.body.clientHeight;
};
Geometry.getHorizontalScroll = function() {
    return window.pageXOffset || 
        document.documentElement.scrollLeft || 
        document.body.scrollLeft;
};
Geometry.getVerticalScroll = function() {
    return window.pageYOffset ||
        document.documentElement.scrollTop || 
        document.body.scrollTop;
};

Geometry.getDocumentHeight = function() {
    return (window.innerHeight && window.scrollMaxY) ?
        window.innerHeight + window.scrollMaxY : (document.body.scrollHeight > document.body.offsetHeight) ? 
                                                    document.body.scrollHeight : document.body.offsetHeight;
};

var oMenuTimer, cMenuTimer;
function ctrlOneStepMenu(ref, style, index, jobID,MoveX,MoveY,menuHeight,BtnHeight){
    var delay = 0;
    var menu = $("divOneStepMenu");
    if (style == "none"){
        hide();
    } else {
        show();
    }
    function show() {
        if (ref.id != "divOneStepMenu") {
            menu.onmouseover = function() {
                ctrlOneStepMenu(ref, 'block', index, jobID,MoveX,MoveY,menuHeight,BtnHeight);
            };
            menu.onmouseout = function(){
                ctrlOneStepMenu(ref, 'none', index, jobID,MoveX,MoveY,menuHeight,BtnHeight);
            };
        }
		
        var lnkApply = $("lnkOneStepApply");
        var lnkChooseCV = $("lnkChooseCV");
        var lnkAttachWordCV = $("lnkAttachWordCV");
        if (typeof jobID != "undefined"){
            lnkApply.onclick = function(){
                showOneStep(jobID, 1);
            };
            lnkChooseCV.onclick = function(){
                showOneStep(jobID,2);
            };
            lnkAttachWordCV.onclick = function(){
                showOneStep(jobID, 3);
            };
        }else{
            lnkApply.onclick = function(){
                showOneStep("", 1);
            };
            lnkChooseCV.onclick = function(){
                showOneStep("", 2);
            };
            lnkAttachWordCV.onclick = function(){
                showOneStep("", 3);
            };
        }
        if (cMenuTimer)
            window.clearTimeout(cMenuTimer);
        if (oMenuTimer)
            window.clearTimeout(oMenuTimer);
		if (typeof(menuHeight) == "undefined"){
		 menuHeight = 125;
		 }
       
        if ($("lnkAttachWordCV").style.display == "none")
            menuHeight = 87;
        if (typeof(jobID) != "undefined"){
            var availHeight = Geometry.getViewportHeight() - (getY(ref) -  Geometry.getVerticalScroll() + 42);
            with(menu.style){
				if (ref.id == "comTpletApplybtn090513_1" || ref.id == "comTpletApplybtn090513_2") {
					left = getX(ref) - 14+"px";
					
						//top = getY(ref) + 42+"px";
						top = getY(ref) + 30+"px";
						if (navigator.appName == "Netscape"){
							top = getY(ref) + 30+"px";
						}
					
					
				}else if (ref.id == "comTpletApplybtn090513_3" || ref.id == "comTpletApplybtn090513_4") {
					left = getX(ref) + 0 +"px";
					
						//top = getY(ref) + 42+"px";
						top = getY(ref) + 30+"px";
						if (navigator.appName == "Netscape"){
							top = getY(ref) + 30+"px";
						}
					
					
				}else{
					if (typeof(MoveX) != "undefined")
					{
						if (typeof(MoveY) == "undefined")
						{
								MoveY=0
						}
						left = getX(ref) + MoveX +"px";
					
						if (availHeight < menuHeight){
							if (typeof(BtnHeight) == "undefined")
							{
									BtnHeight = 30;
							}
							top = getY(ref) + 30-(menuHeight + BtnHeight)  + MoveY+ "px";
							if (navigator.appName == "Netscape"){
								top = getY(ref) + 30-(menuHeight + BtnHeight) + MoveY+ "px";
							}
						}else{
							top = getY(ref) + 30 + MoveY +"px";
							if (navigator.appName == "Netscape"){								
								top = getY(ref) + 30 + MoveY +"px";
							}
						}
					}else{
						left = getX(ref) - 135+"px";
						if (availHeight < menuHeight){
							top = getY(ref) + 42-(menuHeight + 43) + "px";
							if (navigator.appName == "Netscape"){
								top = getY(ref) + 22-(menuHeight + 43) + "px";
							}
						}else{
							//top = getY(ref) + 42+"px";
							top = getY(ref) + 22+"px";
							if (navigator.appName == "Netscape"){
								top = getY(ref) + 22+"px";
							}
						}
					
					}
						
					//width = 378+"px";
				}
            }
        }else{
            with(menu.style){
                left = getX(ref) - 130+"px";
                top = getY(ref) + 28+"px";
                //width = 378+"px";
            }
        }
        oMenuTimer = window.setTimeout(function(){
            menu.style.display = style;
        }, delay);
    }
    function hide() {
        if (oMenuTimer) {
            window.clearTimeout(oMenuTimer);
            oMenuTimer = null;
        }
        cMenuTimer = window.setTimeout(function(){
            menu.style.display = style;
        }, 0);
    }
}

function showOneStep(jobID, applyType){
    $("divOneStepMenu").style.display = "none";
    if (jobID == ""){
        alert("请选择您要申请的职位！");
        return ;
    }
    with($("mask").style) {
        width = document.body.clientWidth + "px";
        height = Geometry.getDocumentHeight() + "px";
        display = "";
    }
    var oneStep = $("divOneStep");
    with(oneStep.style) {
        display = "";
        left = Geometry.getViewportWidth() / 2-285+"px";
        top = Geometry.getVerticalScroll() + 120+"px";
    }
    var frmOneStep = $("frmOneStep");
	var urlstr = "";
    if (applyType == 2) {
        urlstr = "http://my.veryeast.cn/JobApply/JobApplyWindow.asp?jobID="+jobID+"&drandom=" + Math.random(); 
    } else if(applyType == 3) {

	} else {
		urlstr = "http://my.veryeast.cn/JobApply/JobApply.asp?jobID="+jobID+"&drandom=" + Math.random(); 
    }
	if (checkLogin()){
        frmOneStep.src = urlstr;
	}else{
        frmOneStep.src = "http://my.veryeast.cn/JobApply/UserLoginJobApply.asp?Done="+urlstr; 
	}
}
function checkLogin(){
	var loginUserId = getCookie("UserId");
	var loginUserName = getCookie("UserName");

	if(!(loginUserId != null && loginUserId != 0 && loginUserId != "0" && loginUserName != "")){
		return false;
	}
	return true;
}
function hideOneStep(){
    $("mask").style.display = "none";
    $("divOneStep").style.display = "none";
    var frmOneStep = $("frmOneStep");
    frmOneStep.onreadystatechange = null;
    frmOneStep.src = "";
}
function FavMulit(){
	var s = choose();

	if (s == ""){
		return ;
	}

    with($("mask").style) {
        width = document.body.clientWidth + "px";
        height = Geometry.getDocumentHeight() + "px";
        display = "";
    }
    var oneStep = $("divOneStep");
    with(oneStep.style) {
        display = "";
        left = Geometry.getViewportWidth() / 2-285+"px";
        top = Geometry.getVerticalScroll() + 120+"px";
    }
    var frmOneStep = $("frmOneStep");
	
	var urlstr = "http://my.veryeast.cn/JobApply/SaveJobToFavorite.asp?layer=true&jobID="+s+"&drandom=" + Math.random(); 
	if (checkLogin()){
        frmOneStep.src = urlstr;
	}else{
        frmOneStep.src = "http://my.veryeast.cn/JobApply/UserLoginJobApply.asp?Done="+urlstr; 
	}
}
function ApplyMulitJobInfo(){
	var s = choose();
	if (s == ""){
		return ;
	}

    with($("mask").style) {
        width = document.body.clientWidth + "px";
        height = Geometry.getDocumentHeight() + "px";
        display = "";
    }
    var oneStep = $("divOneStep");
    with(oneStep.style) {
        display = "";
        left = Geometry.getViewportWidth() / 2-285+"px";
        top = Geometry.getVerticalScroll() + 120+"px";
    }
    var frmOneStep = $("frmOneStep");
	
	var urlstr = "http://my.veryeast.cn/JobApply/JobApplyWindow.asp?jobID="+s+"&drandom=" + Math.random(); 
	if (checkLogin()){
        frmOneStep.src = urlstr;
	}else{
        frmOneStep.src = "http://my.veryeast.cn/JobApply/UserLoginJobApply.asp?Done="+urlstr; 
	}
}
function choose(){
	var s="";
	for(var i=0;i<thisForm.elements.length;i++){
		var e=thisForm.elements[i];
		if(e.name=="selectedid")
			if(e.checked){
				s=s+e.value+",";
			}
	}
	if(s!=""){
		 s=s.substring(0,s.length-1);
	}else{
		  alert("请至少选者一项职位");
		  return s;
	}
    //alert(s);
	return s;
}