/*
	Author: Mitch R.
	Creation Date: September 14, 2004
	Comments: Functions for creating a informative status to display for long
	processes.
*/

// This will show the Context Help for the specific Section-Code Combination
function ShowHelp(helpSection, helpCode) {
	var scrHeight = screen.availHeight - 30;
	var scrWidth  = (screen.availWidth >> 1) - 4;
	window.open("help.aspx?Section=" + helpSection + "&Code=" + helpCode, "", 
				"width=" + scrWidth + ", height=" + scrHeight + ", top = 0, left = " + scrWidth);
}

//This will show a popup without having ties to the current object
function ShowPopup(popupMenu, width, height, isModal)
{
	var top = (window.document.body.scrollHeight - (height)) / 2;
	var left = (window.document.body.scrollWidth - (width)) / 2;
	
	popupMenu.show(left, top, width, height,window.document.body);
	popupMenu.document.body.style.cursor = "wait";
}
//This will set the page into help mode
function SetHelpMode()
{	
	for(var counter = 0; counter < document.all.length; counter++)
	{
		document.all[counter].style.cursor = "help";
	}	
}
//This will show a help popup without being in help mode
function ShowHelpPopupByButtonClick(controlId)
{	
	var control = document.getElementById(controlId);
	var top = event.y;
	var left = event.x;
	control.firstChild.firstChild.firstChild.firstChild.noWrap = false;
	control.firstChild.firstChild.firstChild.firstChild.width = 180;
	control.firstChild.firstChild.firstChild.firstChild.className = "WRAP";
	control.style.position = "absolute";
	control.style.display="";
	control.style.width = 180;
	var _height = control.offsetHeight;
	control.style.display="none";
	control.Status.PopupMenu.show(left, top, 180, _height, window.document.body);
	control.Status.PopupMenu.document.body.style.cursor = "help";
}
//This will show a help popup
function ShowHelpPopup(controlId)
{	
	//Only show the help if the mouse is in help mode.
	if(window.document.body.style.cursor == "help")
	{
		var control = document.getElementById(controlId);
		var top = event.y;
		var left = event.x;

		control.Status.PopupMenu.show(left, top, 180, 95,window.document.body);
		
		for(var counter = 0; counter < document.all.length; counter++)
		{
			document.all[counter].style.cursor = "";
		}
	}
}

//This will hide the popup
function HidePopup(popupMenu)
{
	popupMenu.hide();
	//Set the cursor back to normal
	popupMenu.document.body.style.cursor = "normal";
	window.document.body.style.cursor = "normal";
}

/*
	Will create an instance of the GeoMessage control.
*/
function CreateGeoMessage(contentId, width, height, autoShow, isModal)
{
	var content = document.getElementById(contentId);
	var geoMessage = new GeoMessage(content, width, height);
	//Do we display on load?
	if(autoShow)
	{
		//Do we make the popup modal or normal?
		if(isModal)
		{
			geoMessage.ShowModalPopup();
		}
		else
		{
			geoMessage.ShowNormalPopup();
		}
	}
}

/*
	GeoMessage is a client-side Javascript Object for
	use to display popup status windows.
*/
function GeoMessage(content, width, height)
{
	this.PopupMenu = null;
	this.PopupBody = null;
	this.CreatePopup = CreatePopup;
	this.ShowNormalPopup = ShowNormalPopup;
	this.ShowModalPopup = ShowModalPopup;
	this.Height = height;
	this.Width = width;
	this.TimerId = null;
	this.HidePhasedPopup = HidePhasedPopup;
	this.HideNormalPopup = HideNormalPopup;
	
	//We will create the popup within the constructor.
	this.CreatePopup();
	
	//This will create an instance of the popup
	function CreatePopup()
	{
		this.PopupMenu = window.createPopup();
		this.PopupBody = this.PopupMenu.document.body;
		this.PopupBody.innerHTML = content.outerHTML;
		this.PopupBody.children[0].style.visibility = "visible";
		this.PopupBody.children[0].style.verticalAlign = "middle";
		this.PopupBody.children[0].style.display = "block";
		content.Status = this;
	}
	
	//This will hide a popup, and release the timer
	//if one exists in a 2 second interval
	function HideNormalPopup()
	{
		HidePopup(this.PopupMenu);
	}

	//This will hide a popup, and release the timer
	//if one exists in a 2 second interval
	function HidePhasedPopup()
	{
		var popUpMenu = this.PopupMenu;
		var timerId = this.TimerId;
		var sleepTimerId = 0;
		var funct = function(){ HidePopup(popUpMenu); window.clearInterval(timerId); window.clearInterval(sleepTimerId);};
		sleepTimerId = window.setInterval(funct, 2400);
	}
	
	//This will keep the window overtop of the current 
	//window always
	function ShowModalPopup()
	{
		var left = this.Left;
		var top = this.Top;
		var popUpMenu = this.PopupMenu;
		var width = this.Width;
		var height = this.Height;
		
		var funct = function(){ ShowPopup(popUpMenu, width, height, true)};
		this.TimerId = window.setInterval(funct, 1);
	}
	
	//This will display the popup, assuming it is not null
	function ShowNormalPopup()
	{
		ShowPopup(this.PopupMenu, this.Width, this.Height, false);
	}
}


