
function getPageSize(){
	var xScroll, yScroll;

	/* if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else */ 
	if (document.documentElement.scrollHeight) { // all but Explorer Mac
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	} else if (document.body.scrollHeight) { // safari
		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;
	}

	/* if (window.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = window.innerWidth;
		}
		windowHeight = window.innerHeight;
		scrollHeight = window.pageYOffset;
		scrollWidth = window.pageXOffset;
	} else */ if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
		scrollHeight = document.documentElement.scrollTop;
		scrollWidth = document.documentElement.scrollLeft;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
		scrollHeight = document.body.scrollTop;
		scrollWidth = document.body.scrollLeft;
	}
	
	// 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, scrollWidth, scrollHeight)
	return arrayPageSize;
}
var always_resize = false;
isIE = (navigator.appVersion.toLowerCase().indexOf("msie") != -1);
if (isIE) {
	ieVersion = parseInt(navigator.appVersion.substring(navigator.appVersion.toLowerCase().indexOf("msie") + 5));
	if (isNaN(ieVersion)) ieVersion = parseInt(navigator.appVersion);
	isIE7 = (ieVersion >= 7);
}

function resize_overlay() {
	var el0 = document.getElementById('overLayIframe');
	var el1 = document.getElementById('overLay');
	var el2 = document.getElementById('divPopup');

	el0.style.zIndex = 100000;
	el1.style.zIndex = 100001;
	el2.style.zIndex = 100002;
	
	if (el1.style.display == "block" || always_resize) {
		pagesize = getPageSize();
		
		el0.style.width = pagesize[0] + "px";
		el0.style.height = pagesize[1] + "px";
		el0.style.display = "block";

		el1.style.width = pagesize[0] + "px";
		el1.style.height = pagesize[1] + "px";
		el1.style.display = "block";
		el1.style.cursor = "not-allowed";
	
		el2.style.top = -10000 + "px";
		el2.style.left = -10000 + "px";
		el2.style.display = "block";
		
		if (isIE && !isIE7) {
			//scrolling with the rest of the page
			 el2.style.top = (pagesize[3] - el2.offsetHeight) / 2 + pagesize[5] + "px"; 
//			el2.style.top = '40px';
			el2.style.left = (pagesize[2] - el2.offsetWidth) / 2 + pagesize[4] + "px";
		} else {
			//fixed
			el2.style.top = (pagesize[3] - el2.offsetHeight) / 3 + "px";
			//el2.style.top = "100px";
			//el2.style.top = '40px';
			el2.style.left = (pagesize[2] - el2.offsetWidth) / 2 + "px";
			// el2.style.position = "fixed";
		}
	}
	return false;
}

function DoShowPopup(width, height){
	var el0 = document.getElementById('overLayIframe');
	var el1 = document.getElementById('overLay');
	var el2 = document.getElementById('divPopup');
	if(!width) width ='664px';
	if(!height) height ='600px';
	el2.style.width=width;
	el2.style.height=height;	

	if (el2.style.display == "block") {
			el0.style.display = "none";
			el1.style.display = "none";
			el2.style.display = "none";
		if (arguments.length > 0 && arguments[0] == "reload") {
			location.reload();
		}
	} else {
		always_resize = true;
		always_resize = resize_overlay();
	}
}
