// JavaScript Document

/* ========================================================= */
/*                                                           */
/* This function defines a image modal window                */
/*                                                           */
/* ========================================================= */
var modalWindow = 
{
	parent:"body",
	windowId:null,
	content:null,
	width:null,
	height:null,
	confirmButtons:null,

	close:function()
	{
		$(".modal-window").remove();
		$(".modal-overlay").remove();
	},

	open:function(title,msgType)
	{
		var currentWidth = 600;
		var modal = "";
		if(!isNaN(this.height))
		{
			this.height = this.height + "px";
		}
		if(!isNaN(this.width))
		{
			currentWidth = this.width;
			this.width = this.width + "px";
		}
		modal += "<div class=\"modal-overlay\"></div>";
		modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "; height:" + this.height + "; margin-top:-275px; margin-left:-" + (currentWidth / 2) + "px;\">";
		modal += this.content;
		modal += "</div>";	

		$(this.parent).append(modal);

		if (msgType == 1)   // Red window
		{
			// add title div at top of modal window
			$(".modal-window").prepend("<div class=\"topModalDiv colorRed modalTitle\"><img src=\"/messageStack/images/imgMsgRed.gif\" \/>&nbsp;&nbsp;" + title + "<\/div>");
			
			// add OK div at bottom of modal window
			$(".modal-window").append("<div class=\"ok-modal\"><a href=\"javascript:;\" class=\"button\" title=\"OK\">OK<\/a><\/div>");
			
			// add close functionality to OK div
			$(".ok-modal").click(function(){modalWindow.close();});
			
			// add red border around modal window
			$(".modal-window").addClass("redModal-window");
		}
		else if (msgType == 2)   // Blue window
		{
			$(".modal-window").addClass("blueModal-window");
		}
		else if (msgType == 3)   // Green window, close button functionality
		{
			// add title div at top of modal window
			$(".modal-window").prepend("<div class=\"topModalDiv\"><h4 id=\"titleText\" class=\"colorGreen\">" + title + "<\/h4><a class=\"close-window\"></a><\/div>");

			// add close button right after title div; close button will be on same line as title
			$(".close-window").append("<img src=\"\/application\/images\/butFormCloseSmall.png\"\/>");

			// add click functionality to close button to close the modal window
			$(".close-window").click(function(){modalWindow.close();});

			$(".modal-window").addClass("greenModal-window");

			// add spacer div at bottom of modal window
//			$(".modal-window").append("<div class=\"spacerDiv\"><\/div>");
		}
		else if (msgType == 4)   // Orange window
		{
			// add title div at time of modal window
			$(".modal-window").prepend("<div class=\"topModalDiv colorOrange modalTitle\"><img src=\"/messageStack/images/imgMsgOrange.gif\" \/>&nbsp;&nbsp;" + title + "<\/div>");
			
			$(".modal-window").addClass("orangeModal-window");
			$(".modal-window").append(this.confirmButtons);
		}

		$(".modal-overlay").click(function(){modalWindow.close();});

	}
};


/* ========================================================= */
/*                                                           */
/* This function opens a modal window with                   */
/* an iframe for the data.                                   */
/*                                                           */
/* ========================================================= */
var openImgModal = function(msgType,pagePath,title,wWidth,wHeight)
{
	modalWindow.windowId = "imgModal";
	modalWindow.width = wWidth;
	modalWindow.height = wHeight;
	modalWindow.content = "<iframe width='100%' height='85%' frameborder='0' scrolling='auto' allowtransparency='true' src='" + pagePath + "'></iframe>";
	modalWindow.open(title,msgType);
};

/* ========================================================= */
/*                                                           */
/* This function opens a modal window with                   */
/* a div for the data.                                       */
/*                                                           */
/* ========================================================= */
var openMsgModal = function(msgType,msgTitle,msgString,msgWidth,msgHeight,msgButtons)
{
	modalWindow.windowId = "msgModal";
	modalWindow.width = msgWidth;
	modalWindow.height = msgHeight;
	modalWindow.content = "<div>" + msgString + "</div>";
	modalWindow.confirmButtons = msgButtons;
	modalWindow.open(msgTitle,msgType);
};

/* ========================================================= */
/*                                                           */
/* This function opens a modal window for comfirmation       */
/*                                                           */
/* ========================================================= */
var openConfirmModal = function(msgType,msgTitle,msgString,msgWidth,msgHeight,msgConfirm)
{
	modalWindow.windowId = "confirmModal";
	modalWindow.width = msgWidth;
	modalWindow.height = msgHeight;
	modalWindow.content = "<div>" + msgString + "</div>";
	modalWindow.confirmButtons = msgConfirm;
	modalWindow.open(msgTitle,msgType);
};

