//<script language="javascript">
// The message object is used to display a "popup" window using division instead of a new window.
//
// The message creates the following HTML objects:
//		msgBox - outside wrapper for popup message
//		msgTitle - title for popup message
//		msgContent - content/message for popup message
//		msgSrc - iframe used for loading content from file.  The file loaded must contain a "msgContent" division.
//
//	The message object requires the following CSS objects:
//  	.message - defines how the message box should look
//		#msgTitle - defines how the title should be formatted
//    #msgContent - defines how the content should be formatted.
//    .msgButton - defines how the close button should be formatted
// 
// The message popup is called using the showMessage() function.
//		showMessage (title,content,x,y)	
//		showMessage (title,content,object)
//		showMessage (title,division,x,y)
//		showMessage	(title,division,object)
//		showMessage (title,document,x,y)
//		showMessage	(title,document,object)
//		showMessage	(title,document,object,relX,relY)
//where
//    title is a html formatted title to display for the popup.
//		content is a html formatted content to display for the popup.
//		x is the x screen coordinate where the left end of the popup should be.
//		y is the y screen coordinate where to center the content.
//		object is the name of an object to use for determining the x,y coordinates.
//		division is the name of a division on the page containing the content for the popup.
//		document is the name of a document containing the content for the popup.  The document must contain a msgContent division.
//		relX is the number of pixels left or right relative to the object to place the popup.
//		relY is the number of pixels up or down relative to the object to place the popup.
//
//finally
//The message object can be accessed directly using the following methods.
//		alignToObject(object,x,y)
//		setMessage(html formatted text);
//		setMessageFromDiv(name of division or file);
//		setTitle(html formatted text);
//		setXY(x,y);
//		show();
//		hide();
//

function Message() {
	this.init();
}

function Message_init(){
	this.content = "";
	this.title = "";
	this.x = "";
	this.y = "";
	this.isHidden = true;
	this.iFrameInited = false;
	
	document.writeln ("<div id=\"msgBox\" class=\"message\">");
	document.writeln ("<div id=\"msgTitle\"></div>");
	document.writeln ("<div id=\"msgCloseWindow\"><a href=\"close\" onClick=\"hideMessage();return false\" class=\"msgCloseButton\">X</a></div>");
	document.writeln ("<div id=\"msgContent\"></div>")
	document.writeln ("<div style=\"text-align:center\">&nbsp;<br><a href=\"close\" onclick=\"hideMessage();return false\" class=\"msgButton\">Close</a></div>");
	document.writeln ("</div>");
	document.writeln ("<div id=\"msgSrc\"></div>");
   
	this.popup = document.getElementById("msgBox");
	this.msgSrc = document.getElementById("msgSrc");
	this.msgContent = document.getElementById("msgContent");
	this.msgTitle = document.getElementById("msgTitle")
}

function Message_alignToObject(obj,x,y){
	var left = 0;
	var top = 0;

   var p = obj;
   while (p != null) {
   	left = left + p.offsetLeft;
		top = top + p.offsetTop;
		p = p.offsetParent;
	}
	
	if ((isNaN(x)) && (isNaN(y))){
		this.x = left;
		this.y = top - this.popup.offsetHeight/2;
	} else {
		this.x = left + x;
		this.y = top + y;
	}
}
	
function Message_setMessage(text){
	this.content = text;
	this.msgContent.innerHTML = this.content;
}

function Message_setMessageFromDiv(division){
	var x = document.getElementById(division);
	if (x != null) {
		this.content = document.getElementById(division).innerHTML;
		this.msgContent.innerHTML = this.content;
	} else {
		this.msgSrc.innerHTML = "<IFRAME style=\"visibility:hidden\" scrolling=\"no\" width=\"0\" height=\"0\" SRC=\"" + division + "\" border=\"0\"></IFRAME>"; 
	}
}

function Message_setTitle(text){
	this.title = text;
	this.msgTitle.innerHTML = this.title;
}

function Message_setXY(x,y){
	this.x = x;
	this.y = y;
}

function Message_hide(){
	this.isHidden = true;
	this.popup.style.visibility="hidden";
}

function Message_show(){
	with (this.popup){
		this.popup.style.visibility="hidden";
		this.popup.style.top=this.y + "px";
		this.popup.style.left=this.x + "px";
		this.popup.style.visibility="visible";
		this.popup.style.zIndex=99;
	}
	this.isHidden = false;
}

Message.prototype.init = Message_init;
Message.prototype.alignToObject = Message_alignToObject;
Message.prototype.setMessage = Message_setMessage;
Message.prototype.setMessageFromDiv = Message_setMessageFromDiv;
Message.prototype.setTitle = Message_setTitle;
Message.prototype.setXY = Message_setXY;
Message.prototype.show = Message_show;
Message.prototype.hide = Message_hide;

var message = new Message();

function showMessage(arg1, arg2, arg3, arg4, arg5){
	message.hide();
	message.setTitle(arg1);
	message.setMessage("&nbsp;");

	if (arg2.indexOf(" ") == "-1") {
		message.setMessageFromDiv(arg2);
	} else {
		message.setMessage(arg2);
	}

	if ((arg4 == null) || (arg5 != null)) {
//		try {
			var x = document.getElementById(arg3);
			if (x != null) {
				message.alignToObject(x,arg4,arg5);
				message.show();
			}
//		} 
//		catch (e) {
//			alert("Invalid object " + arg3);
//		}
	} else {
		message.setXY(arg3,arg4);
		message.show();
	}
}

function hideMessage(){
	message.hide();
}

function updateMessage(html){
	message.setMessage(html);
	message.show();
}

//</script>