/*
	This functions assumes that there is a div with an id specifically called 'overlay_message'.
	If there is more than one message on a page you can solve for that by doing the following:
		1. Call the div with the id 'overlay_message_uniquename' where uniquename is whatever you want to call it.
		2. when you call the page_overlay for that message, send the "uniquename" as an argument.  Ex:
			page_overlay('uniquename');
*/

function page_overlay(extra_name) {

	var top_padding = 100;

	var message_name = 'overlay_message' + (typeof extra_name != 'undefined' ? '_' + extra_name : '');

	page_dimensions = get_page_dimensions();
	var myHeight = page_dimensions[0];
	var myWidth = page_dimensions[1];

	scroll_dimensions = get_scroll();
	var scrOfX = scroll_dimensions[0];
	var scrOfY = scroll_dimensions[1];
	
	// create the overlay if it doesn't already exist
	if(!document.getElementById('overlay_gray')) {
		var gray = 	document.createElement('div');
		gray.setAttribute('id','overlay_gray');
		gray.className = 'overlay_gray';
		gray.style.display = 'none';
		document.body.appendChild(gray);
	}
	
	document.getElementById('overlay_gray').style.height = myHeight + "px";
	document.getElementById('overlay_gray').style.width = myWidth + "px";
	
	// Get the padding from the top, with the scroll if needed
	if(scrOfY != 0) { top_padding += scrOfY; }

	document.getElementById('overlay_gray').style.display = '';
	document.getElementById(message_name).style.display = '';
	
	// Get the center of the page, minus the length of the overlay_message box
	message_width = Math.floor(document.getElementById(message_name).offsetWidth / 2);
	left_padding = Math.floor(myWidth / 2) - message_width;
	
	document.getElementById(message_name).style.top = top_padding + "px";
	document.getElementById(message_name).style.left = left_padding + "px";
	
}

function get_page_dimensions() {
	
	// This specifically finds the height of the entire internal window (the page) that you are currently in.
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		height = window.innerHeight + window.scrollMaxY;
		width = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		height = document.body.scrollHeight;
		width = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		height = document.body.offsetHeight;
		width = document.body.offsetWidth;
  	}
	return [ height, width ];
}

function get_scroll() {
  var x_scroll = 0, y_scroll = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    y_scroll = window.pageYOffset;
    x_scroll = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    y_scroll = document.body.scrollTop;
    x_scroll = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    y_scroll = document.documentElement.scrollTop;
    x_scroll = document.documentElement.scrollLeft;
  }
  return [ x_scroll, y_scroll ];
}

//dtn: This is the revert for the Warning Overlay page... it turns it from the dark background back to the normal view.
function overlay_revert(message_name) {
	document.getElementById('overlay_gray').style.display = "none";
	document.getElementById(message_name).style.display = "none";
}
