//===========================================================================
// DCIProgressBar
// 
// Javascript Class that will create and display a "loading" dialog overtop of a webpage
//===========================================================================
function DCIProgressBar( strMessage )
{
	// Constants
	var m_nScrollBarWidth = 16;	// Rough Estimation of most scrollbars' width
	
	// DCIProgressBar parameters
	var m_strMessage;
	if( typeof(strMessage) == 'undefined' )
		m_strMessage = 'Loading...';
	else
		m_strMessage = strMessage;
	
	// Objects that are created by the DCIProgressBar
	var m_divProgress = null;
	var m_oBodyObj = null;

	//=======================================================================
	// CreateDisplay
	//
	// Creates the Progress Bar area
	//=======================================================================
	function CreateDisplay()
	{	
		// Progress/Loading bar - ensure there is only 1 per page
		if( !document.getElementById('dciProgress') )
			document.write('<div id="dciProgress" style="display: block; height: 30px; width: 300px; ' +
								'position: absolute; visibility: hidden; ' + 
								'border: 1px solid black; color: #000000; font-weight: bold; ' + 
								'background-color: #EFEFEF; padding: 0px; z-index: 5; vertical-align: middle;">' + 
								'<img src="' + g_strDCIPath + 'scripts/loading.gif" alt="Processing..." style="float: left; width: 30px; height: 30px;" />' + 
								'<div style="vertical-align: middle; margin: 5px 0px 5px 0px;">' + m_strMessage + '</div>' + 
							'</div>');
		
		m_divProgress = document.getElementById('dciProgress');
		
		// Save Reference to Standard 'Body' object acress browsers
		m_oBodyObj = (document.compatMode == 'CSS1Compat' ? document.documentElement : document.body);
	}
	
	//========================================================================
	// Center
	//
	// Centers the loading dialog to the center of the viewable area, and displays the graphic
	//========================================================================
	function Center()
	{
		var bInternetExplorer = (document.all && !window.opera);
		var bUsesDOM = document.getElementById;
		
		var nScrollTop = (bInternetExplorer ? m_oBodyObj.scrollTop : window.pageYOffset);
		var nScrollLeft = (bInternetExplorer ? m_oBodyObj.scrollLeft : window.pageXOffset);
		
		// Get the document dimensions
		var nDocWidth = (bInternetExplorer ? m_oBodyObj.clientWidth : window.innerWidth - m_nScrollBarWidth);
		var nDocHeight = (bInternetExplorer ? m_oBodyObj.clientHeight : window.innerHeight);
		
		// Get the full scroll height of the document
		var nDocHeightComplete = (m_oBodyObj.offsetHeight > m_oBodyObj.scrollHeight ? m_oBodyObj.offsetHeight : m_oBodyObj.scrollHeight);
		
		// Get the div object dimensions
		var nObjWidth = m_divProgress.offsetWidth;
		var nObjHeight = m_divProgress.offsetHeight;
		
		// Get the Top Position
		var nTopPosition = (nDocHeight > nObjHeight ? nScrollTop + (nDocHeight / 2) - (nObjHeight / 2) : nScrollTop + 10);
		
		// Set the Location
		m_divProgress.style.left = (nDocWidth / 2) - (nObjWidth / 2) + 'px';
		m_divProgress.style.top = Math.floor(parseInt(nTopPosition)) + 'px';
	}
	
	function start()
	{
		Center();
		m_divProgress.style.visibility = 'visible';
	}
	
	function stop()
	{
		m_divProgress.style.visibility = 'hidden';
	}
	
	function CleanUp()
	{
		m_divProgress = null;
	}
	
	function AddEventHandler( oObj, fpFunction, strEvent )
	{
		var strEvent = (window.addEventListener ? strEvent : 'on' + strEvent);
		
		// If object supports addEventListener, use that to add the event handler
		if( oObj.addEventListener )
			oObj.addEventListener(strEvent, fpFunction, false);
		else if( oObj.attachEvent )
			oObj.attachEvent(strEvent, fpFunction);
	}
	
	// Add Center call to Resize Event
	AddEventHandler(window, function() { if(m_divProgress.style.visibility == 'visible') Center(); }, 'resize');
	
	// Assign Functions to new Object
	this.CreateDisplay = CreateDisplay
	this.Center = Center;
	this.start = start;
	this.stop = stop;
	this.CleanUp = CleanUp;
	this.AddEventHandler = AddEventHandler;
	
	// Create the Display
	this.CreateDisplay();
	
}
