//this function returns an array of the window height and width
function windowSize() {
	var winY = Geometry.getWindowY();
	var winX = Geometry.getWindowX();


	var height = Math.max(Math.max(Geometry.getWindowY(), Geometry.getViewportHeight()),Math.max(Geometry.getVerticalScroll(), Geometry.getDocumentHeight()));

	var width = Math.max(Math.max(Geometry.getWindowX(), Geometry.getViewportWidth()),Math.max(Geometry.getHorizontalScroll(), Geometry.getDocumentWidth()));

	var returnValue = Array();
	returnValue['height'] = height;
	returnValue['width'] = width;
	return returnValue;
}

//Function to create a transparent layer over all of the existing web page
function displayBackground(x, y) {

	objBody 			= document.body;
	objDiv 				= document.createElement("DIV");
	objDiv.style.width 	= x + 'px';
	objDiv.style.height = y + 'px';

	objDiv.className 	= "transparentBackground";

	objTxt = document.createTextNode("                     ");
	objDiv.appendChild(objTxt);

	objDiv.setAttribute('id','tempBackground');
	objBody.appendChild(objDiv);
}

//this function creates the message to display.
//There are 5 arguments passed to it
//	1. The message to display
//	2. The width of the box
//	3. The height of the box
//	4. The total available width of the window
//	5. The total available height of the window
function displayMessage(strMessage, x, y, x2, y2) {

	//Initialize scalar variables
	var topBuffer 					= 0;
	if(document.all) { topBuffer = 225; }
	var intTop 						= ((y2 - y) / 2) + topBuffer;
	var intLeft 					= ((x2 - x) / 2);

	//Initialize object variables
	var objBody						= document.body;
	var objMsg 						= document.createElement("DIV");
	var objMsgShadow 				= document.createElement("DIV");
	var objTxt1						= strMessage;
	var objTxt2						= strMessage.cloneNode(true);

	//Style the message object
	objMsg.style.width 				= x + 'px';
	//objMsg.style.height		 		= y + 'px';
	objMsg.style.left 				= intLeft + 'px';
	objMsg.style.top 				= intTop + 'px';
	objMsg.className 				= "modalMessage";

	//Style the message shadow object
	objMsgShadow.style.width 		= x + 'px';
	//objMsgShadow.style.height 		= y + 'px';
	objMsgShadow.style.left 		= (intLeft + 10) + 'px';
	objMsgShadow.style.top 			= (intTop + 10) + 'px';
	objMsgShadow.className 			= "modalMessageShadow";

	//Set the ID attributes for the message, and it's shadow
	objMsg.setAttribute('id', 'modalMessage');
	objMsgShadow.setAttribute('id', 'modalMessageShadow');

	//var alertString = objMsg.style.left + '\n' + objMsg.style.top + '\n======================\n' + objMsgShadow.style.left + '\n' + objMsgShadow.style.top;

	//Append the objects to each other, then the body
	objMsgShadow.appendChild(objTxt1);
	objMsg.appendChild(objTxt2);
	objBody.appendChild(objMsgShadow);
	objBody.appendChild(objMsg);
}

//Function to display the alert message
function displayModalMessage(strMessage) {
	if(document.getElementById("modalMessage") == null) {

		var windowDims 		= windowSize();



		displayBackground(windowDims['width'], windowDims['height']);
		displayMessage(strMessage, 400, 400, windowDims['width'], windowDims['height']);
		displayCloseButton("Close", 'modalMessage');

		return false;
	}
}

//Function to display the close button for the dialog box
//this function recieves 2 arguments
//	1. The text of the close button
//	2. The id of the object to add the close button to
function displayCloseButton(strTxt, strId)
{
	objBtn = document.createElement("DIV");

	objTxt = document.createTextNode(strTxt);
	objBtn.appendChild(objTxt);
	objBtn.onclick = function(){closeDialogBox()};

	objBtn.className = 'closeButton';

	objBind = document.getElementById(strId);
	objBind.appendChild(objBtn);
}
function closeDialogBox() {
	objBody 			= document.body;
	objBox 				= document.getElementById("modalMessage");
	objBoxShadow 		= document.getElementById("modalMessageShadow");
	objBackground 		= document.getElementById("tempBackground");

	objBody.removeChild(objBoxShadow);
	objBody.removeChild(objBackground);
	objBody.removeChild(objBox);
}