﻿

function pwGetViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}
function pwGetViewportWidth() {
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}

function show() {
var s
s = "网页可见区域宽clientWidth："+ window.document.body.clientWidth; 

s += "\r\n网页可见区域高clientHeight："+ window.document.body.clientHeight; 

s += "\r\n网页可见区域宽offsetWeight："+ window.document.body.offsetWeight +" (包括边线的宽)"; 

s += "\r\n网页可见区域高offsetHeight："+ window.document.body.offsetHeight +" (包括边线的高)"; 

s += "\r\n网页正文全文宽："+ window.document.body.scrollWidth; 

s += "\r\n网页正文全文高："+ window.document.body.scrollHeight; 

s += "\r\n网页被卷去的高："+ window.document.body.scrollTop; 

s += "\r\n网页被卷去的左："+ window.document.body.scrollLeft; 

s += "\r\n网页正文部分上："+ window.screenTop; 

s += "\r\n网页正文部分左："+ window.screenLeft; 

s += "\r\n屏幕分辨率的高："+ window.screen.height; 

s += "\r\n屏幕分辨率的宽："+ window.screen.width; 

s += "\r\n屏幕可用工作区高度："+ window.screen.availHeight; 

s += "\r\n屏幕可用工作区宽度："+ window.screen.availWidth; 

alert(s); 

}

var gPopupContainer = null;
var gPopFrame = null;
var gReturnFunc;
var gPopupIsShown = false;
var gHideSelects = false;

var gTabIndexes = new Array();
var gTabbableTags = new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME");	

function pwInit() {
	gPopupMask = document.getElementById("popupMask");
	gPopupContainer = document.getElementById("popup_Container_div");
	gPopFrame = document.getElementById("popup_Frame_iframe");	
	
	var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
	if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
		gHideSelects = true;
	}
	//pwSetTitle;
}
//cmAddEvent(window, "onload", pwInit);
//cmAddEvent(window, "resize", pwSetPos);
//cmAddEvent(window, "scroll", pwSetPos);
//window.onscroll = pwSetPos;
//window.onload=pwInit();
//window.onresize=pwSetPos();


function pwShow(url, width, height,nPos,returnFunc) {

	if(gPopupContainer==null){
		pwInit();
		
	}
	gPopupIsShown = true;
	pwDisableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	pwSetPos(width, height,nPos);
		
	var nTitleBarHeight = parseInt(document.getElementById("popup_TitleBar_div").offsetHeight, 10);
	if (navigator.product == 'Gecko') { width = width + 6; height = height+6; }

	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+nTitleBarHeight) + "px";
	gPopFrame.style.width =parseInt(document.getElementById("popup_TitleBar_div").offsetWidth, 10) + "px";
	gPopFrame.style.height = parseInt(height-0) + "px";
	gPopFrame.src = url;
	
	gReturnFunc = returnFunc;
	
	if (gHideSelects == true) {
		pwHideSelectBoxes();
	}
	
	//window.setTimeout("pwSetTitle();", 100);
}

var gi = 0;
function pwSetPos(width, height,nPos) {
	if(nPos==null){
		nPos=1;
	}
	
	if (gPopupIsShown == true) {
		if (width == null || isNaN(width)) {
			width = gPopupContainer.offsetWidth;
		}
		if (height == null) {
			height = gPopupContainer.offsetHeight;
		}
		
		var fullHeight = pwGetViewportHeight();
		var fullWidth = pwGetViewportWidth();

		if (fullWidth<980){
			fullWidth=980
		}
		var theBody = document.documentElement;
		
		//var scTop = parseInt(theBody.scrollTop,10);
		//var scLeft = parseInt(theBody.scrollLeft,10);
		var scTop =0;
		var scLeft = 0;
			
		gPopupMask.style.height = fullHeight + "px";
		gPopupMask.style.width = fullWidth + "px";
		gPopupMask.style.top = scTop + "px";
		gPopupMask.style.left = scLeft + "px";
		
		
		//alert(fullWidth);
		//window.status = gPopupMask.style.width + " " + gPopupMask.style.left + " " + gi++;
		
		
		//window.status =gPopupIsShown;		
		var nTitleBarHeight = parseInt(document.getElementById("popup_TitleBar_div").offsetHeight, 10);

		gPopupContainer.style.top = (scTop + ((fullHeight - (height+nTitleBarHeight)) / 2)) + "px";
		var nLeftOffset=0;
		switch(nPos){
		case 0: // 靠左
			nLeftOffset=0;	
			break;
		case 1: // 居中
			nLeftOffset=(fullWidth - width) / 2
			break;
		case 2: // 靠右
			nLeftOffset=(fullWidth - width)-25;	
			break;
		default:
			break;
		}
	
		gPopupContainer.style.left =  (scLeft + nLeftOffset) + "px";
		
		gPopupMask.style.height = document.body.clientHeight  + "px";
		//gPopupMask.style.width = document.body.clientWidth  + "px";
	}
	
}

function pwHide(callReturnFunc) {
	gPopupIsShown = false;
	pwRestoreTabIndexes();
	if (gPopupMask == null) {
		return;
	}
	gPopupMask.style.display = "none";	
	if (gPopupContainer == null) {
		return;
	}
	gPopFrame.src = 'about:blank';
	gPopupContainer.style.display = "none";
	if (callReturnFunc == true && gReturnFunc != null) {
		gReturnFunc(window.frames["popup_Frame_iframe"].returnVal);
	}
	if (gHideSelects == true) {
		pwDisplaySelectBoxes();
	}
}

function pwSetTitle() {
	
	//window.status=window.frames["popup_Frame_iframe"].document.title
	if (window.frames["popup_Frame_iframe"].document.title == null && window.frames["popup_Frame_iframe"].document.title =="无法找到该页") {
		window.setTimeout("pwSetTitle();",0);
	} else {
		document.getElementById("popup_TitleBar_Text").innerHTML = window.frames["popup_Frame_iframe"].document.title;
		document.getElementById("PrvePage").href="ssss";
		document.getElementById("PrvePage").title="aaa";
	}
	
}

function pwKeyDownHandler(e) {
    if (gPopupIsShown && e.keyCode == 9)  return false;
}
if (!document.all) {
	document.onkeypress = pwKeyDownHandler;
}

function pwDisableTabIndexes() {
	if (document.all) {
		var i = 0;
		for (var j = 0; j < gTabbableTags.length; j++) {
			var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) {
				gTabIndexes[i] = tagElements[k].tabIndex;
				tagElements[k].tabIndex="-1";
				i++;
			}
		}
	}
}

function pwRestoreTabIndexes() {
	if (document.all) {
		var i = 0;
		for (var j = 0; j < gTabbableTags.length; j++) {
			var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) {
				tagElements[k].tabIndex = gTabIndexes[i];
				tagElements[k].tabEnabled = true;
				i++;
			}
		}
	}
}

function pwHideSelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
				document.forms[i].elements[e].style.visibility="hidden";
			}
		}
	}
}

function pwDisplaySelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
			document.forms[i].elements[e].style.visibility="visible";
			}
		}
	}
}

if(window.addEventListener){ // Mozilla, Netscape, Firefox
	window.addEventListener('load', pwInit, false);
	window.addEventListener('onresize', pwSetPos, false);
	window.addEventListener('onscroll', pwSetPos, false);
	//window.frames["popup_Frame_iframe"].addEventListener('onload', alert("姓名不能为空!") , false);
} else { // IE
	window.attachEvent('load', pwInit);
	window.attachEvent('onresize', pwSetPos);
	window.attachEvent('onscroll', pwSetPos);
	//window.frames["popup_Frame_iframe"].addEventListener('onload', alert("姓名不能为空!"));
	
}

function showNews(ID,News){
    window.pwShow("/cn/newsshow.asp?news="+News+"&ID="+ID,700,400,1,null); 
}

function showRecruit(ID,News){
    window.pwShow("/cn/Recruitment/ShowRecruit.asp?news="+News+"&ID="+ID,700,400,1,null); 
}

function showPic(Pic,tit){
    window.pwShow("/cn/Company/ShowRy.asp?Pic="+Pic+"&tit="+tit,700,400,1,null); 
}

function RegisterRecruit(ID,News){
    window.pwShow("/cn/Recruitment/RegisterRecruit.asp?news="+News+"&ID="+ID,700,400,1,null);}
