
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;
}

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 pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x' || keycode == 27 || keycode == 88) hideModal();
}

function listenKey () {
	document.onkeypress = getKey;
}
	

function revealModal(headingContent, bodyContent, objModalWidth, objModalHeight)
{
	var objModalBackground = document.getElementById('modalBackground');
	var objModalContainer = document.getElementById('modalContainer');
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	var yStart = arrayPageScroll[1];
	
	objModalBackground.style.height = arrayPageSize[1] + 'px';
	objModalBackground.style.width = arrayPageSize[0] + 'px';
	objModalBackground.style.display = 'block';
	
	var objModalArea = document.getElementById('modalArea');
	objModalArea.style.width = objModalWidth;
	objModalArea.style.height = objModalHeight;
	
	document.getElementById('modalHeadingContent').innerHTML = headingContent;
	document.getElementById('modalBodyContent').innerHTML = bodyContent;

	var modalContainerTop = (arrayPageSize[3] / 2) - (objModalHeight / 2);
	var modalContainerLeft = ((arrayPageSize[2] / 2) - (objModalWidth / 2));

	objModalContainer.style.top = (modalContainerTop < 0) ? "0px" : modalContainerTop + yStart + "px";
	objModalContainer.style.left = (modalContainerLeft < 0) ? "0px" : modalContainerLeft + "px";
	
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		pause(250);
	} 

	objModalContainer.style.display = 'block';
	
   window.onscroll = function () {
   	objModalContainer.style.top = document.body.scrollTop+modalContainerTop;
   };
	
	// Check for 'x' keypress
	//listenKey();
}
	

function hideModal()
{
	objModalBackground = document.getElementById('modalBackground');
	objModalContainer = document.getElementById('modalContainer');

	objModalBackground.style.display = 'none';
	objModalContainer.style.display = 'none';

	document.onkeypress = '';
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

document.write('<div id="modalBackground"></div>',
	'<div id="modalContainer"><div id="modalArea">' 
	+ '<table class="modalHeader" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td class="modalHeaderLeft"></td><td class="modalHeaderCenter" id="modalHeadingContent"></td><td class="modalHeaderCenter" id="modalHeadingContentExit" align="right"><a href="javascript:hideModal();"><img src="/images/1x1clear.gif" class="modalHeaderExitImg"></a></td><td class="modalHeaderRight"></td></tr></table>'
	+ '<table class="bodyfont" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td class="modalBodyTopleft"></td><td class="modalBodyTop"></td><td class="modalBodyTopRight"></td></tr><tr><td class="modalBodyLeft"></td><td class="modalBody" id="modalBodyContent"></td><td class="modalBodyRight"></td></tr><tr><td class="modalBodyBottomLeft"></td><td class="modalBodyBottom"></td><td class="modalBodyBottomRight"></td></tr></table>'
	+ '</div></div>');

