var msgDivTag = "msgDiv"; // Default
var msgBodyTag = "msgBody"; // Default
var divWidth = 300;
var divHeight = 170;
var msgTitle = "Message"; // Default
var msgStylePrefix = "BLUE"; // Default
var dragableElementClass = "dragable"; // Default
var jtbLogoLocation = "";
var placeholderLocation = "";
var underlayDivTag = "underlayDiv"; //Default
var includeLogo = false;


function showMessage(msg){
	setWinPosition();
	
	if(navigator.appName == "Microsoft Internet Explorer"){
		document.getElementById(msgBodyTag).innerHTML = msg;
		document.getElementById(msgDivTag).style.display = "block";
	}else{
		alert(msg);
	}
}	

function hideMessage(){		
	document.getElementById(msgDivTag).style.display = "none";	
}

function setWinPosition(){

	var div = document.getElementById(msgDivTag);
	var posLeft = 0;
	var posTop = 0;	
	var pageWidth = document.body.scrollWidth;
	var pageHeight = document.body.clientHeight;	
	var currentTopPosition = document.body.scrollTop;		

	posLeft = (pageWidth - divWidth) / 2;	
	posTop = ((pageHeight - divHeight) / 2) + currentTopPosition;

	div.style.position = "absolute";
	div.style.left = posLeft;
	div.style.top = posTop;	

	if(navigator.appName == "Microsoft Internet Explorer"){				
		var underlayDiv = document.getElementById(underlayDivTag);
		underlayDiv.style.zIndex = div.style.zIndex - 1;  		        
		underlayDiv.style.position = "absolute";
		underlayDiv.style.left = 0;
		underlayDiv.top = 0;
		underlayDiv.style.display="block";
	}

}

function setTitle(title){
	if(title != "") msgTitle = title;
}

function setMsgDivTag(tagName){
	if(tagName != "") msgDivTag = tagName;
}

function setUnderlayDivTag(tagName){
	if(tagName != "") underlayDivTag = tagName;
}

function setMsgBodyTag(tagName){
	if(tagName != "") msgBodyTag = tagName;
}

function setDivWidth(width){
	if(width != "") divWidth = width;
}

function setDivHeight(height){
	if(height != "") divHeight = height;
}

function setIncludeLogo(include){
	includeLogo = true;
}

function initMessageDiv(){
	document.write(generateMessageDiv());		
 	document.write(generateUnderlayDiv());			

}

function setMsgStylePrefix(className){
	if(className != "") msgStylePrefix = className;
}

function setJTBLogoLocation(location){
	if(location != "") jtbLogoLocation = location;
}

function setPlaceholderLocation(location){
	if(location != "") placeholderLocation = location;
}

function generateMessageDiv(){	

	var html = "";

	html += '<div id="' + msgDivTag + '" name="' + msgDivTag + '" class="' + dragableElementClass + '">';
	html += '<tr style="background-color:#8AB7FF;">';
	html += '<table border="0" cellspacing="0" cellpadding="3" width="' + divWidth + '" height="' + divHeight + '" class="' + msgStylePrefix + 'msgtable">';
	// Title
	html += '<tr class="' + msgStylePrefix + 'msgtitle">';
	html += '<td align="left" width="50">';

	if(includeLogo) {
		html += '<img src="' + jtbLogoLocation + '" width="50" height="30">';
	}else{
		html += '<img src="' + placeholderLocation + '" width="50" height="30">';
	}
	html += '</td>';

	html += '<td align="center" width="90%" height="20"><b>' + msgTitle + '</b></td>';
	html += '<td align="left" width="50"><img src="' + placeholderLocation + '" width="50" height="5"></td></tr>';
	// Message body
	html += '<tr><td align="center" colspan=3>';
	html += '<table border="0" cellspacing="0" cellpadding="0" class="' + msgStylePrefix + 'msgbody">';
	html += '<tr><td width="20"></td>';
	html += '<td id="' + msgBodyTag + '" name="' + msgBodyTag + '"></td>';
	html += '<td width="20"></td></tr>';
	html += '</table></td></tr>';
	// Close button
	html += '<tr><td align="center" width="100%" height="20" colspan="3">';
	html += '<a href="#" onClick="javascript:hideMessage();return false;" class="' + msgStylePrefix + 'msgbutton">close</a></td></tr>';
	html += '</div>';

	return html;	

}	

function generateUnderlayDiv(){
	var html = "";
	html += '<iframe id="' + underlayDivTag + '" name="' + underlayDivTag + '" frameborder="0" src="javascript:false;" width="' + divWidth + '" height="' + divHeight + '" background="blue" style="position:absolute;display:none;"></iframe>';
	return html;
}
