/// <reference path="jquery-1.3.2-vsdoc2.js" />
/* ##########################################################################################################################

Class       : Progress.js
Summary	    : Contains all the scripts to handle the error handling functionality.
Copyright   : (c) 2006 NRT Inc. All rights reserved.
Comments    : This class currently makes use of the Microsoft Ajax Library and jQuery Libary.
: The reference above is for intellisense purposes only and probably should be removed for release.
Depends     : This class requires and makes use of the progress.css file for styling. 
RevisionHistory: 
-------------------------------------------------------------------------------------------------------------------------
Date		Name		Description
-------------------------------------------------------------------------------------------------------------------------
11/30/2006	tanderson	Initial Creation
02/16/2010  jhickman    Modified
###########################################################################################################################*/

Progress =
    $(document).ready(function()
    {
    	Sys.require([Sys.components.modalPopup], function()
    	{
    		$('#showProgress').modalPopup({
    			id: "modalProgress",
    			PopupControlID: "popProgress",
    			BackgroundCssClass: "progress_Shadow",
    			Drag: false,
    			shown: Progress.fn.modalShown,
    			hidden: Progress.fn.modalHidden,
    			repositionMode: "RepositionOnWindowResizeAndScroll"
    		});
    	});
    });

Progress.fn = function()
{
	return {
		// Initialize members
		MessageText: 'Please Wait.',
		DetailMessageText: 'Loading...',
		_ContentTop: '<div class="progress_Padding"><div class="progress_image"><IMG height="32" class="progress_MsgImage" src="/NRTProducts/include/images/progress.gif" width="32" border="0" /></div><div class="progress_MsgBody"><div class="progress_MsgCell"><p class="progress_MsgMain">',
		_ContentMiddle: '</p></div><div style="clear:both;"></div><div class="progress_MsgDetailCell"><p class="progress_MsgDetail">',
		_ContentBottom: '</p></div></div></div>',
		//per metro -- true (_nLeft = n px)/false (_nLeft = 0 px)
		_hasSetLeft: false,
		_setLeft: 0,

		_left: 0,
		_top: 0,
		_width: 250,
		_height: 80,
		_isVisible: false,
		_hideAttempts: 0,
		_hideTimeoutTimer: null,

		modalShown: function()
		{
			Progress.fn._isVisible = true;
		},
		modalHidden: function()
		{
			Progress.fn._isVisible = false;
		},

		getIsVisible: function()
		{
			return Progress.fn._isVisible;
		},

		/*==================================================================================
		Method		: show
		Summary		: function to populate and show progress box
		Author		: TSA
		Create Date	: 2007.10.18
		====================================================================================*/
		//public function
		show: function(eType, bCustom, sCustomMsg)
		{
			//don't cover up a previous box
			if (Progress.fn._isVisible == true)
				return;

			Progress.fn._isVisible = true;

			var tmpCentered = this._bCentered;
			var defWidth = 540;
			var height = this._height + "px";
			var width = this._width + "px";

			try
			{
				if (arguments.length > 0)
				{
					this.DetailMessageText = this._getDetailMessageText(eType, bCustom, sCustomMsg);
				}

				var progressLayout = this._ContentTop + this.MessageText + this._ContentMiddle + this.DetailMessageText + this._ContentBottom;

				Sys.require([Sys.components.modalPopup, Sys.Application], function()
				{

					var modalProgress = $find('modalProgress');

					if (modalProgress)
					{
						var popProgress = $get('popProgress');
						popProgress.style.width = width;
						popProgress.innerHTML = progressLayout;
						modalProgress.show();
					}
					else { return; }
				});
			}
			catch (err)
			{
				_oErrorHandler.Error('Progress.fn.show', _oErrorHandler.ERRORTYPE_JS, err);
			}
		},

		/*==================================================================================
		Method		: hide
		Summary		: functions to hide progress box
		Author		: TSA
		Create Date	: 2007.10.18
		====================================================================================*/
		//public function
		hide: function()
		{
			try
			{
				// Hide the Panel
				//Progress.hide();
				var modalProgress = $find('modalProgress');
				if (modalProgress)
				{
					if (Progress.fn._hideTimeOutTimer != null)
					{
						clearInterval(Progress.fn._hideTimeoutTimer);
						Progress.fn._hideTimeoutTimer = null;
						Progress.fn._hideAttempts = 0;
					}
					modalProgress.hide();
				}
				else
				{
					if (Progress.fn._hideTimeoutTimer == null)
						Progress.fn._hideTimeoutTimer = setInterval(Progress.fn.hide, 500);
					else
					{
						Progress.fn._hideAttempts += 1;

						if (Progress.fn._hideAttempts > 3)
						{
							clearInterval(Progress.fn._hideTimeoutTimer);
							Progress.fn._hideAttempts = 0;
							Progress.fn._isVisible = false;
						}
					}
				}

				return;
			}
			catch (err)
			{
				clearInterval(Progress.fn._hideTimeoutTimer);
				Progress.fn._hideTimeoutTimer = null
				Progress.fn._hideAttempts = 0;
				Progress.fn._isVisible = false;
				_oErrorHandler.Error('Progress.fn.hide', _oErrorHandler.ERRORTYPE_JS, err);
			}
		},

		//private method
		_getDetailMessageText: function(eType, bCustom, sCustomMsg)
		{
			var sTmpMessage = '';

			try
			{
				if (bCustom)
				{
					sTmpMessage = sCustomMsg;

				} else
				{
					//get message by eMode
					switch (eType)
					{
						case 'plotmap':
							sTmpMessage = ' Loading properties in map';
							break;

						case 'map':
							sTmpMessage = ' Loading map results';
							break;

						case 'list':
							sTmpMessage = ' Loading list results';
							break;

						case 'sort':
							sTmpMessage = ' Re-sorting by<br>' + sCustomMsg;
							break;

						case 'page':
							sTmpMessage = ' Loading page ' + sCustomMsg;
							break;

						case 'resize':
							sTmpMessage = ' Resizing to<br>' + sCustomMsg + ' listings per page';
							break;

						case 'group':
							sTmpMessage = ' Loading group<br>' + sCustomMsg;
							break;

						case 'search':
							sTmpMessage = ' Searching';
							break;

						default:
							sTmpMessage = ' Loading';

					}
				}
				return sTmpMessage;
			}
			catch (err)
			{
				throw err;
			}
		}
	};
} ();

