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;
	}	
	
	// 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) 
	return arrayPageSize;
}

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;
}

var divWidth;
var divHeight;

var borderWidth = 40;
var borderHeight = 40;

function JSPOP_open(html, w, h, closeOnclick) {
	window.location = "#jspop";
	divWidth = w;
	divHeight = h;
	jspopDiv = document.createElement("div");
	overlayImg = document.createElement("img");
	overlayImg.id = "overlay";
	overlayImg.src = "images/ipwg-overlay.png";
	document.body.style.margin="0px";
	overlayImg.style.position = "absolute";
	overlayImg.style.left = "0px";
	overlayImg.style.top = "0px";
	overlayImg.style.display = "block";
	if (closeOnclick)
		overlayImg.onclick = function() { JSPOP_close(); };
	containerDiv = document.createElement("div");
	containerDiv.style.position = "absolute";
	containerDiv.style.backgroundColor = "#FFFFFF";
	containerDiv.style.width = divWidth + borderWidth + "px";
	containerDiv.style.height = divHeight + borderHeight + "px";
	containerDiv.style.textAlign = "right";
	containerDiv.innerHTML = '<img src="images/ipwg-close.gif" onclick="JSPOP_close()">';
	contentDiv = document.createElement("div");
	contentDiv.style.position = "absolute";
	contentDiv.innerHTML = html;
	contentDiv.style.left = "20px";
	contentDiv.style.top = "20px";
	if (closeOnclick)
		contentDiv.onclick = function() { JSPOP_close(); };
	containerDiv.appendChild(contentDiv);
	jspopDiv.appendChild(overlayImg);
	jspopDiv.appendChild(containerDiv);
	document.body.appendChild(jspopDiv);
	window.onresize = function() { JSPOP_update(); }
	JSPOP_update();
//	if (onJspopOpen)
//		onJspopOpen();
}

function JSPOP_update() {
	getPageSize();
	getPageScroll();
	overlayImg.style.width = "100%";
	overlayImg.style.height = arrayPageSize[1] + "px";
	var containerDivLeft = arrayPageSize[2] / 2 - (divWidth + borderWidth) / 2;
	var containerDivTop = arrayPageSize[3] / 2 + arrayPageScroll[1] - (divHeight + borderHeight) / 2;
	if (containerDivLeft < 0)
		containerDivLeft = 0;
	if (containerDivTop < 0)
		containerDivTop = 0;
	containerDiv.style.left = containerDivLeft + "px";
	containerDiv.style.top = containerDivTop + "px";
}

function JSPOP_close() {
	jspopDiv.innerHTML = "";
	jspopDiv.parentNode.removeChild(jspopDiv);
	window.onresize = null;
//	if (onJspopClose)
//		onJspopClose();
}
function openImage(src, w, h) {
	JSPOP_open('<img src="' + src + '" />', w, h, true);
}