// Global Routines
// Copyright Jonathan Fielding

function MessageBox(sMessage, sCaption, sType, ReturnRoutine){
	
	var tempContainer = document.getElementById("container");
	var divTag = document.createElement("div");
	var MessageWidth = 300;
	var	MsgBoxBorder = 10;
	var Width = GetWindowSize("Width");
	var Left = (Width - (MessageWidth + (MsgBoxBorder * 2))) / 2;
	var Buttons;

	var sMessageText = Rules(sMessage);

	if (sType == "YesNo"){
		//Enable Yes No Buttons
		var Response1 = "'Yes'";
		var Response2 = "'No'";
		Buttons = '<a href="#" onclick="' + ReturnRoutine + '('+ Response1 +');"><img src="images/yes.png"/></a><a href="#" onclick="' + ReturnRoutine + '('+ Response2 +');"><img src="images/no.png"/></a>';
	}
	else if (sType == "OkCancel"){
		//Enable OK Cancel Buttons
		Buttons = '<a href="#" onclick="' + ReturnRoutine + '('+ Response1 +');"><img src="images/ok.png"/></a><a href="#" onclick="' + ReturnRoutine + '('+ Response2 +');"><img src="images/cancel.png"/></a>';
	}
	else{
		//Default value if blank is enable OK button
		Buttons = '<a href="#" onclick="' + ReturnRoutine + '();"><img src="images/ok.png"/></a>';
	}

	//Set the DIV ID as the current subject
	divTag.id = "MsgBox";
	divTag.className ="MessageBox";
	divTag.style.width = MessageWidth;
	divTag.style.left = Left + 'px';
	tempContainer.appendChild(divTag);
	
	tempContainer = document.getElementById("MsgBox");
	divTag = document.createElement("div");
	divTag.id = "MsgBoxCaption" + sCaption;
	divTag.className ="MsgBoxCaption";
	divTag.innerHTML = sCaption;
	tempContainer.appendChild(divTag);
	
	tempContainer = document.getElementById("MsgBox");
	divTag = document.createElement("div");
	divTag.id = "MsgBoxText" + sCaption;
	divTag.className ="MsgBoxText";
	divTag.innerHTML = sMessageText;
	tempContainer.appendChild(divTag);
	
	tempContainer = document.getElementById("MsgBox");
	divTag = document.createElement("div");
	divTag.id = "MsgBoxButtons" + sCaption;
	divTag.className ="MsgBoxButtons";
	divTag.innerHTML = Buttons;
	
	tempContainer.appendChild(divTag);

}

function CloseMessageBox(){
	
	//Remove the Message Box
	var sChild = document.getElementById('MsgBox');
	sChild.parentNode.removeChild(sChild);
}

function GetWindowSize(sWanted){
	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 (sWanted=="Height")
	{
		return myHeight;
	}
	else if(sWanted=="Width")
	{
		return myWidth;
	}
	
}