/*
	This javascript function creates IE, Safari, and Mozilla compatible css pop-up windows.
	The css div with ID="popup" is called with "showOverlay('popup');" and hidden with "hideOverlay('popup');".
	The div you wish to be the popup should have the following properties:
		position: absolute;
		height: XXXpx; // insert correct height in pixels
		width: XXXpx; // insert correct width in pixels
		margin-top: 0px;
		margin-left: 0px;
		z-index: 15;
		display: none;
		// and of course any other styles
*/

function getSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		fullHeight = window.innerHeight + window.scrollMaxY;
		fullWidth = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		fullHeight = document.body.scrollHeight;
		fullWidth = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		fullHeight = document.body.offsetHeight;
		fullWidth = document.body.offsetWidth;
	}
	
	var wSize = new Array();
	wSize[0] = myHeight;
	wSize[1] = myWidth;
	wSize[2] = fullHeight;
	wSize[3] = fullWidth;
	
	return wSize;
}

function centerDiv(dId) {
	var wSize = new Array
	wSize = getSize();
	
	var dHeight = document.getElementById(dId).style.height;
	var dWidth = document.getElementById(dId).style.width;
	
	dHeight = dHeight.substring(0, dHeight.length - 2);
	dWidth = dWidth.substring(0, dWidth.length - 2);
	
	var newTop, newLeft;
	
	if (dHeight > wSize[0]) {
		dHeight = dHeight - 50 + 100;
		newTop = 50;
		newLeft = (wSize[1] - dWidth) / 2;
		if (dHeight > wSize[2]) {
			var tooLarge = 1;
		} else {
			var tooLarge = 0;
		}
	} else {
		newTop = (wSize[0] - dHeight) / 2;
		newLeft = (wSize[1] - dWidth) / 2;
		var tooLarge = 0;
	}
	
	document.getElementById(dId).style.marginTop = newTop + 'px';
	document.getElementById(dId).style.marginLeft = newLeft + 'px';
	
	return tooLarge;
}

function showOverlay(dId) {
	var wSize = new Array
	wSize = getSize();
	
	var tooLarge = centerDiv(dId);
	
	if (tooLarge == 0) {
		if (navigator.appName != 'Microsoft Internet Explorer') {
			document.getElementById('overlay_bg').style.height = wSize[2] + 'px';
			document.getElementById('overlay_bg').style.width = wSize[3] + 'px';
		}				
	} else {
		var extraHeight = document.getElementById(dId).style.height.substring(0, document.getElementById(dId).style.height.length - 2);
		extraHeight = extraHeight - 50 + 150;
		if (navigator.appName != 'Microsoft Internet Explorer') {
			document.getElementById('overlay_bg').style.height = extraHeight + 'px';
			document.getElementById('overlay_bg').style.width = wSize[3] + 'px';
		}
	}
	
	if (navigator.appName != 'Microsoft Internet Explorer') {
		document.getElementById('overlay_bg').style.visibility = "visible";
	}
	
	document.getElementById(dId).style.display = "block";
}

function hideOverlay(dId) {
	if (navigator.appName != 'Microsoft Internet Explorer') {
		document.getElementById('overlay_bg').style.height = '0px';
		document.getElementById('overlay_bg').style.width = '0px';
	
		document.getElementById('overlay_bg').style.visibility = "hidden";
	}
	
	document.getElementById(dId).style.display = "none";
}