/**************************************************************
showPopWin function started crashing the browser consistently.
It was clunky even before it started crashing the browser.
It has now been completely rewritten.
***************************************************************/
function showPopWin(url, width, height, returnFunc, showCloseBox)
{
	document.getElementById('newpopupcontents').innerHTML = '';
	
	var locUrl = window.location.protocol + '//' + window.location.hostname + '/';
	
	movePopup();
	document.getElementById("newpopup").style.display = "block";
	document.body.onscroll = movePopup;
	window.onscroll = movePopup;
	
    var xmlHttpReq = false;
    if (window.XMLHttpRequest) {
        xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlHttpReq.open('GET', locUrl+url, true);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttpReq.onreadystatechange = function() {
        if (xmlHttpReq.readyState == 4) {
            document.getElementById('newpopupcontents').innerHTML = xmlHttpReq.responseText;
        }
    }
    xmlHttpReq.send(null);
}

function movePopup()
{
	var center_x
	var center_y;
	
	if(self.innerHeight)
	{
		center_x = self.innerWidth;
		center_y = self.innerHeight;
	}
	else if(document.documentElement && document.documentElement.clientHeight)
	{
		center_x = document.documentElement.clientWidth;
		center_y = document.documentElement.clientHeight;
	}
	else if(document.body)
	{
		center_x = document.body.clientWidth;
		center_y = document.body.clientHeight;
	}

	var scroll_x
	var scroll_y;
	
	if(self.pageYOffset)
	{
		scroll_x = self.pageXOffset;
		scroll_y = self.pageYOffset;
	}
	else if(document.documentElement && document.documentElement.scrollTop)
	{
		scroll_x = document.documentElement.scrollLeft;
		scroll_y = document.documentElement.scrollTop;
	}
	else if(document.body)
	{
		scroll_x = document.body.scrollLeft;
		scroll_y = document.body.scrollTop;
	}
	
	document.getElementById("newpopup").style.left = ((center_x - 250) / 2 + scroll_x) + "px";
	document.getElementById("newpopup").style.top = ((center_y - 200) / 2 + scroll_y) + "px";
}
