// ---------------------------
// Legal
// ---------------------------
// CastleBusyBox Control
// Castle Rock Software, LLC
// by Mark Wagner
// http://www.crsw.com
//
// Version: 1.2
//
// Copyright 2004, 2005 Castle Rock Software, LLC
// No warranty express or implied.

// ---------------------------
// General Notes
// ---------------------------
// The BusyBox javascript has been written so the BusyBox javascript
// control can be used with or without the Castle.BusyBox .NET control.

// ---------------------------
// Constructor
// ---------------------------
// BusyBox class constructor
// Arguments:
//   id - id of the IFrame tag to use.
//   varName - name of the variable this instance of the busy box is assigned to.
function BusyBox(idWait, idSearch, varName)
{
	// Initialize object
	this.idWait = idWait;
	this.idSearch= idSearch;
	this.Enabled = true;
	
	// Retain the name of the instantiated object variable so that we can animate 
	// using the setTimeout statement
	this.VarName = varName;
	
	// Get reference to the IFrame object
	this.SearchDiv = document.getElementById(this.idSearch);
	this.WaitDiv = document.getElementById(this.idWait);
	
	// Hide the busy box
	this.Hide();
}

// IsVisible:
// Returns a boolean value representing the visibility state for the busy box.
BusyBox.prototype.IsVisible = function()
{
	var ifrm = document.getElementById(this.idWait);
	
	if( ifrm.style.display != "none" && ifrm.style.width > 0 )
		return true;
	else
		return false;
}


// Hide:
// Hides the busy box making it invisible to the user.
BusyBox.prototype.Hide = function()
{	
	// Hide the busy box.
	this.WaitDiv.style.display = "none";
	//this.WaitDiv.style.width = 0;
	//this.WaitDiv.style.height = 0;
	
	// Show other
	this.SearchDiv.style.display = "";
	//this.SearchDiv.style.width = 0;
	//this.SearchDiv.style.height = 0;
}

// Show:
// This function displays the busy box to the user.  This function centers the 
// busy dialog box, makes it visible, and starts the animation.  This function 
// will typically be called by the body event.
//
// Example:
//		<body onbeforeunload="busyBox.Show();" >
BusyBox.prototype.Show = function()
{
	if( !this.Enabled )
		return;

	if( this.IsVisible() )
		return;	
	
	// Set the busy box to be visible and make sure it is on top of all other controls.	
	this.WaitDiv.style.display = "block";
	this.WaitDiv.style.zIndex = "999999";
	
	this.SearchDiv.style.display = "none";
	//this.SearchDiv.style.zIndex = "999999";

  document.body.style.cursor = 'wait';
	
}

// --------------------------------
// Class Methods
// --------------------------------

// IsBrowserIE:
// Returns true if the executing browser it a Microsoft Internet Explorer browser.
BusyBox.IsBrowserIE = function()
{
	try
	{ return (window.navigator.userAgent.indexOf("MSIE ") > 0); }
	catch(x)
	{ return false; }
}

// IsBrowserNS:
// Returns true if the executing browser it a Netscape browser.
BusyBox.IsBrowserNS = function()
{
	try
	{ return (window.navigator.userAgent.indexOf("Netscape") > 0); }
	catch(x)
	{ return false; }
}

// IsBrowserFirefox:
// Returns true if the executing browser it a Firefox browser.
BusyBox.IsBrowserFirefox = function()
{
	try
	{ return (window.navigator.userAgent.indexOf("Firefox") > 0); }
	catch(x)
	{ return false; }
}

// IsBrowserFirefox:
// Returns true if the executing browser it a Firefox browser.
BusyBox.IsBrowserOpera = function()
{
	try
	{ return (window.navigator.userAgent.indexOf("Opera") > 0); }
	catch(x)
	{ return false; }
}
