/**
 * @classDescription 获取滚动条上边距
 * @author ice deng
 * @return (Array)
 */
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
};
/**
 * @classDescription 获取窗口大小
 * @author ice deng
 * @return (Array)
 */
function getPageSize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	var pageHeight,pageWidth;
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,xScroll) 
	return arrayPageSize;
};
/**
 * @classDescription 加载提示窗口
 * @author ice deng
 * eg:
 *	LoadingShow("<div style=\"color:#ffffff;\">i--------------test..........</div>",true);
 */
function divShow(str){
	this.Html = str;//"<div style=\"width:300px;height:300px;background:red\"><button onclick='divShowClose()'>x</button></div>";
	//是否做页面遮罩，默认为是
	if(arguments.length >0){
		this.IsOverlay = arguments[0];
	}else{
		this.IsOverlay = true;
	}
	//判断是否已经存在加载提示
	if(document.getElementById("LoadingDataPopUpWindows")){
		document.getElementById("LoadingDataPopUpWindows_data").innerHTML = this.Html;
		return;
	}
	var body = document.getElementsByTagName("body").item(0);
	//创建遮罩
	var overlay = document.createElement("div");
	overlay.setAttribute("id","LoadingDataPopUpWindows");
	overlay.style.position = "absolute";
	overlay.style.top = "0px";
	overlay.style.left = "0px";
	overlay.style.zIndex = "6000";
	overlay.style.width = "0px";
	overlay.style.height = "0px";
	overlay.style.display = "none";
	if(this.IsOverlay){
		overlay.style.backgroundColor = "#000";
		if(!!(window.attachEvent && !window.opera)){
			overlay.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=30)";
		}else{
			overlay.style.opacity = 0.3;
		}
	}
	body.appendChild(overlay);

	var _iframe = document.createElement("iframe");
	_iframe.frameBorder = 0;
	_iframe.style.backgroundColor="transparent";
	_iframe.setAttribute("id","LoadingDataPopUpWindows_data_iframe");
	if(!!(window.attachEvent && !window.opera)){
		_iframe.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
	}else{
		_iframe.style.opacity = "0";
	}
	_iframe.style.width="100%";
	_iframe.style.display = "none";

	overlay.appendChild(_iframe);
	//创建显示层
	var showData = document.createElement("div");
	showData.setAttribute("id","LoadingDataPopUpWindows_data");
	showData.style.position = "absolute";
	showData.style.top = "0px";
	showData.style.left = "0px";
	showData.style.zIndex = "6010";
	//showData.style.width = "217px";
	//showData.style.height = "20px";
	//showData.style.color = "#000000";
	//showData.style.display = "none";

	showData.innerHTML = this.Html;

	body.appendChild(showData);
    
	//定位
	setPosition();
    
}

function setPosition()
{
	var showData = document.getElementById("LoadingDataPopUpWindows_data");
	var overlay =  document.getElementById("LoadingDataPopUpWindows");
	var _iframe =  document.getElementById("LoadingDataPopUpWindows_data_iframe");
	if(!showData||!overlay)
	{
		return;
	}
	//定位
	var pageSize = getPageSize();
	var showDataHeight = 0;
	var showDataWidht = 0;
	showDataHeight = parseInt(showData.offsetHeight);
	showDataWidht = parseInt(showData.offsetWidth);
	var overlayWidth = 0;
	var overlayHeight = 0;
	var overlayTop = 0;
	var overlayLeft = 0;
	var showDataTop = 0;
	var showDataLeft = 0;
	if(this.IsOverlay){
		overlayWidth = pageSize[4];
		overlayHeight = pageSize[1];
		showDataTop =  (getPageScroll()[1]+pageSize[3]/2 - showDataHeight/2);
		showDataLeft =  (pageSize[0]/2 - showDataWidht/2);
		showDataLeft = showDataLeft + showDataWidht > pageSize[0] ? 0 : showDataLeft;
	}else{
		overlayWidth = showDataWidht;
		overlayHeight = showDataHeight;
		overlayTop = (getPageScroll()[1]+pageSize[3]/2 - showDataHeight/2);
		overlayLeft = (pageSize[0]/2 - showDataWidht/2);
		overlayLeft = overlayLeft + showDataWidht > pageSize[0] ? 0 : overlayLeft;
		showDataTop = overlayTop;
		showDataLeft = overlayLeft;
	}
	overlay.style.width = overlayWidth + "px";
	overlay.style.height = overlayHeight + "px";
	_iframe.style.width = overlayWidth + "px";
	_iframe.style.height = overlayHeight + "px";
	overlay.style.top = overlayTop + "px";
	overlay.style.left = overlayLeft + "px";
	showData.style.top =  showDataTop+"px";
	showData.style.left =  showDataLeft+"px";
	_iframe.style.display = "block";
	overlay.style.display = "block";
	showData.style.display = "block";
}

function divShowClose(){
	var obj = document.getElementById("LoadingDataPopUpWindows");
	var objC = document.getElementById("LoadingDataPopUpWindows_data");
	if(!!obj)obj.parentNode.removeChild(obj);
	if(!!objC)objC.parentNode.removeChild(objC);
}

window.onresize = function()
{
   setPosition();
}
window.onscroll = function()
{
   setPosition();
}
