/****************************************************************
 * clsStatusMsg		written 05/14/2002 DF Denes
 *
 *					This class encapsulates the control and
 *					display of a status messages, either on the
 *					the status bar or in a modeless dialog box.
 *					This class works in conjunction with the 
 *					StatusMsg.asp page (both of which must be
 *					in the same folder).
 *					
 *					Private functions and properties are prefixed
 *					with an underscore
 ****************************************************************/

StatusMsg							= function()
{
	this.useDialog					= false;
	this.title						= 'Loading';
	this.width						= 350;
	this.height						= 100;
	this.bgColor					= 'lightgrey';

	this._path						= '/scripts/includes';
	this._dialog					= null;
	this._dotTimerStatusBar			= null;
	this._doneTimerStatusBar		= null;

	return this;
}
StatusMsg.prototype					= new Object();

/**************************************************************
 * show				Shows the status message
 *	input:			dialog title
 *					message text
 *					Use Dialog
 *						true: show dialog box
 *						false: show status message
 *					dialog box width, height
 **************************************************************/
StatusMsg.prototype.show			= function(strTitle, strBody, bUseDialog, nWidth, nHeight)
{
	this.title						= this._getValue(strTitle, 		this.title);
	var vBody						= this._getValue(strBody, 		'Initializing');
	this.useDialog					= this._getValue(bUseDialog,	this.useDialog);
	this.width						= this._getValue(nWidth, 		this.width);
	this.height						= this._getValue(nHeight, 		this.height);
	if (this.useDialog)
		this._open(vBody);
	else
		this._updateStatusBar(vBody);
}

/**************************************************************
 * hide				Hides (closes) the dialog or clears the
 *					status message
 **************************************************************/
StatusMsg.prototype.hide			= function()
{
	if (this.useDialog)
	{
		if (this._isOpen())
		{
			this._dialog.close();
			this._dialog			= null;
		}
	}
	else
		this._clearStatusBar();
}

/**************************************************************
 * updateStatus		Updates the status message
 **************************************************************/
StatusMsg.prototype.updateStatus	= function(strBody)
{
	var vBody						= this._getValue(strBody, '');
	if (this.useDialog)
	{
		if (this._isOpen())
		{
			try			{this._dialog.updateStatus(vBody);}
			catch(e)	{}
		}
	}
	else
		this._updateStatusBar(vBody);
}

/**************************************************************
 * completeStatus	Issue the completion message and dismiss
 *					it after a time delay
 **************************************************************/
StatusMsg.prototype.completeStatus	= function()
{
	if (this.useDialog)
	{
		if (this._isOpen())
		{
			try			{this._dialog.completeStatus();}
			catch(e)	{}
		}
	}
	else
		this._completeStatusBar()
}

/**************************************************************
 * _open				Open the dialog box
 *						(only if it isn't already open)
 **************************************************************/
StatusMsg.prototype._open			= function(strBody)
{
	if (!this._isOpen())
	{
		var strURL					= this._path 		+ '/StatusMsg.asp';
		strURL					   += '?Title=' 		+ this.title;
		strURL					   += '&Body=' 			+ this._getValue(strBody);
		strURL					   += '&bgColor=' 		+ escape(this.bgColor);

		var strFeatures				= 'dialogWidth:' 	+ this.width 	+ 'px;';
		strFeatures				   += 'dialogHeight:'	+ this.height 	+ 'px;';
		strFeatures				   += 'center:yes;';
		strFeatures				   += 'help:no;';
		strFeatures				   += 'resizable:no;';
		strFeatures				   += 'scrolling:no;';
		strFeatures				   += 'status:no;';

		this._dialog				= showModelessDialog(strURL, clsStatusMsg, strFeatures);
		this._dialog.focus();
	}
}

/**************************************************************
 * _isOpen				Is the message display open?
 **************************************************************/
StatusMsg.prototype._isOpen			= function()
{
	if (this.useDialog)
	{
		if (this._dialog != null)
			return true;
	}
	else
		return true;
}

/**************************************************************
 * _getValue			Get a value -- use the requested
 *						default value if missing or empty.
 **************************************************************/
StatusMsg.prototype._getValue		= function(Value, DefaultValue)
{
	var vDefaultValue				= DefaultValue;
	if (typeof(vDefaultValue) == 'undefined')
		vDefaultValue				= '';
	if (vDefaultValue == null)
		vDefaultValue				= '';

	var vValue						= Value;
	if (typeof(vValue) == 'undefined')
		vValue						= vDefaultValue;
	if (vValue == null)
		vValue						= vDefaultValue;
	
	return vValue;
}

/**************************************************************
 * _updateStatusBar			Update the status bar message
 **************************************************************/
StatusMsg.prototype._updateStatusBar		= function(Value)
{
	this._clearTimersStatusBar();
	window.status							= Value;
	this._dotTimerStatusBar					= window.setInterval('clsStatusMsg._addDotsStatusBar()', '500', 'JavaScript');
}

/**************************************************************
 * _completeStatus	Issue the completion status message and
 *					it after a time delay
 **************************************************************/
StatusMsg.prototype._completeStatusBar		= function()
{
	this._clearTimersStatusBar();
	if (window.status.length > 0)
		window.status					   += ' Done.';
	this._doneTimerStatusBar				= window.setTimeout('clsStatusMsg._clearStatusBar()', '2000', 'JavaScript');
}

/**************************************************************
 * _addDotsStatusBar	Add dots to status message
 *						(called on an interval timer)
 **************************************************************/
StatusMsg.prototype._addDotsStatusBar		= function()
{
	window.status						   += '.';
}

/**************************************************************
 * _clearStatusBar		Clear the status message
 *						(called on an timeout timer)
 **************************************************************/
StatusMsg.prototype._clearStatusBar			= function()
{
	this._clearTimersStatusBar();
	window.status							= '';
}

/**************************************************************
 * _clearTimerStatusBar		Clear timers used for status mesages
 **************************************************************/
StatusMsg.prototype._clearTimersStatusBar	= function()
{
	if (this._doneTimerStatusBar != null)
	{
		window.clearTimeout(this._doneTimerStatusBar);
		this._doneTimerStatusBar			= null;
	}
	if (this._dotTimerStatusBar != null)
	{
		window.clearInterval(this._dotTimerStatusBar);
		this._dotTimerStatusBar				= null;
	}
}

var clsStatusMsg = new StatusMsg();	// instantiate this class automatically
