NRT.namespace("Tab");
/* ##########################################################################################################################

Namespace : NRT.Tab
Classes   : Tab
Summary	  : This file contains all the scripts to handle the entire client side functionality for the
tab control. 
Copyright : (c) 2006 NRT Inc. All rights reserved.

RevisionHistory: 
-------------------------------------------------------------------------------------------------------------------------
Date		Name		Description
-------------------------------------------------------------------------------------------------------------------------
11/06/2006	dlawless	Initial Creation

###########################################################################################################################*/
0

// Global Variables
var _oTab;

NRT.Tab = function()
{
	var _sourceName = null; 		// The source control name used for this tab control
	var _tabs = null; 			// Tab Caption | DIV Tag to display | Tab Click Event | * (Default Selected Tab)
	var _tabAlign = null; 		// Align Tab
	var _tabSelected = null; 	// Selected Tab
	var _tabDivSelected = null;     // Selected Div Tab
	var _previousTabId = null; 	// Prevoius Tab Id

	return {
		/*******************************************************************************************************************
		*									P U B L I C   P R O P E R T I E S
		*******************************************************************************************************************/
		/*==================================================================================
		Property	: sourceName
		Summary		: Returns the tab control's source control name.
		Author		: Dale Lawless
		Create Date	: 12/08/2006
		====================================================================================*/
		sourceName: function()
		{
			return _sourceName;
		},

		/*==================================================================================
		Property	: setSourceName
		Summary		: Sets the tab control's source control name.
		Author		: Dale Lawless
		Create Date	: 12/08/2006
		====================================================================================*/
		setSourceName: function(name)
		{
			_sourceName = name;
		},

		/*==================================================================================
		Property	: tabs
		Summary		: Returns the tab array property.
		Author		: Dale Lawless
		Create Date	: 11/27/2006
		====================================================================================*/
		tabs: function()
		{
			return _tabs;
		},

		/*==================================================================================
		Property	: setTabs
		Summary		: Sets the tab array property.
		Author		: Dale Lawless
		Create Date	: 11/27/2006
		====================================================================================*/
		setTabs: function(value)
		{
			_tabs = value;
		},

		/*==================================================================================
		Property	: _tabAlign
		Summary		: Returns the tab alignment property.
		Author		: Dale Lawless
		Create Date	: 11/27/2006
		====================================================================================*/
		tabAlign: function()
		{
			return _tabAlign;
		},

		/*==================================================================================
		Property	: setTabAlign
		Summary		: Sets the alignment property for the tab.
		Author		: Dale Lawless
		Create Date	: 11/27/2006
		====================================================================================*/
		setTabAlign: function(value)
		{
			_tabAlign = value;
		},

		/*==================================================================================
		Property	: tabSelected
		Summary		: Returns the tab id that was selected.
		Author		: Dale Lawless
		Create Date	: 08/10/2006
		====================================================================================*/
		tabSelected: function()
		{
			return _tabSelected;
		},

		/*==================================================================================
		Property	: tabSelected
		Summary		: Returns the tab id that was selected.
		Author		: Dale Lawless
		Create Date	: 08/10/2006
		====================================================================================*/
		tabDivSelected: function()
		{
			return _tabDivSelected;
		},

		/*==================================================================================
		Property	: setTabSelected
		Summary		: Sets the id of the tab to be selected.
		Author		: Dale Lawless
		Create Date	: 08/10/2006
		====================================================================================*/
		setTabSelected: function(value)
		{
			_tabSelected = value;
		},

		/*==================================================================================
		Property	: setTabDivSelected
		Summary		: Sets the id of the tab to be selected.
		Author		: Jason Barringer
		Create Date	: 08/10/2006
		====================================================================================*/
		setTabDivSelected: function(value)
		{
			_tabDivSelected = value;
		},

		/*==================================================================================
		Property	: currentTabId
		Summary		: Returns the current tab id.
		Author		: Dale Lawless
		Create Date	: 11/28/2006
		====================================================================================*/
		previousTabId: function()
		{
			return _previousTabId;
		},

		/*==================================================================================
		Property	: setCurrentTabId
		Summary		: Sets the current tab id.
		Author		: Dale Lawless
		Create Date	: 11/28/2006
		====================================================================================*/
		setPreviousTabId: function(id)
		{
			_previousTabId = id;
		},


		/*******************************************************************************************************************
		*									P U B L I C   M E T H O D S
		*******************************************************************************************************************/
		/*==================================================================================
		Method		: changeTabStyle
		Summary		: Changes the tab style.
		Author		: Dale Lawless
		Create Date	: 11/19/2006
		====================================================================================*/
		changeTabStyle: function(evt, tabId)
		{
			var oTab = document.getElementById('litab' + tabId);

			try
			{
				if (oTab !== null && typeof oTab !== 'undefined')
				{
					switch (evt)
					{
						case 0:
							if (this.tabSelected() !== tabId)
							{
								jQuery("#litab" + tabId + " a").attr("class", "ps-tab");
							}
							return;

						case 2:
							jQuery("#litab" + tabId + " a").attr("class", "ps-tab ps-tab-active");
							this.setTabSelected(tabId);
							return;
					}
				}
			}
			catch (err)
			{
				_oErrorHandler.Error('NRT.Tab.changeTabStyle', _oErrorHandler.ERRORTYPE_JS, err);
				return;
			}
		},

		/*==================================================================================
		Method		: load
		Summary		: Tab Caption | DIV Tag to display | Tab Click Event | * (Default Selected Tab)
		Author		: Karl Beyer
		Create Date	: 02/06/2010
		====================================================================================*/
		load: function()
		{
			var sHTML;
			var i;
			var tab;
			var divTabButtons;

			try
			{
				sHTML = "<div class=\"ps-tabs\">\n<ul id=\"ulTabs\">\n";
				sHTML += "<li><a class=\"ps-tab ps-tab-left\"><span></span></a></li>"

				for (i = 0; i < _tabs.length; i += 1)
				{
					tab = _tabs[i].split("|");
					sHTML += "<li id=\"litab" + i + "\" >"; // onclick=\"_oTab.tabClick(" + i + ");" + tab[2] + "\">";
					sHTML += "<a href=\"javascript:_oTab.tabClick(" + i + ");" + tab[2] + "\" class=\"ps-tab\"><span>" + tab[0] + "</span></a></li>";
				}

				sHTML += "</ul>";
				sHTML += "</div>";

				divTabButtons = NRT.Utility.getElementByTagNameAndID('div_Tabs', 'DIV');
				divTabButtons.innerHTML = sHTML;

				// show default tab by looking for the asterick in the tab array.
				for (i = 0; i < _tabs.length; i += 1)
				{
					tab = _tabs[i].split("|");

					if (tab[3] === "*")
					{
						this.tabClick(i);
						break;
					}
				}
			}
			catch (err)
			{
				_oErrorHandler.Error('NRT.Tab.load', _oErrorHandler.ERRORTYPE_JS, err);
				return;
			}
		},

		/*==================================================================================
		Method		: tabClick
		Summary		: Click event for tab to show the correct div tag.
		Author		: Dale Lawless
		Create Date	: 11/06/2006
		====================================================================================*/
		tabClick: function(tabId)
		{
			var tab;
			var prevTabId;
			var prevTab;
			var divPrevious;
			var divCurrent;

			try
			{
				// Sets the specified tab on.
				this._tabOn(tabId);
				this._clearSelectedTab();
				tab = _tabs[tabId].split("|");
				this.setTabDivSelected(tab[1]);

				// Hide the previous tabs div
				prevTabId = this.previousTabId();

				if (prevTabId !== null)
				{
					prevTab = _tabs[prevTabId].split("|");
					divPrevious = document.getElementById(prevTab[1]);

					if (divPrevious !== null)
					{
						divPrevious.style.display = 'none';
					}
				}

				// Show the clicked tab's div
				divCurrent = document.getElementById(tab[1]);

				if (divCurrent !== null)
				{
					divCurrent.style.display = '';
				}

				// Set the current tab id
				this.setPreviousTabId(tabId);
			}
			catch (err)
			{
				_oErrorHandler.Error('NRT.Tab.tabClick', _oErrorHandler.ERRORTYPE_JS, err);
				return;
			}
		},


		/*******************************************************************************************************************
		*								P R I V A T E   M E T H O D S
		*******************************************************************************************************************/
		/*==================================================================================
		Method		: _clearSelectedTab
		Summary		: Clears the previous selected tab.
		Author		: Dale Lawless
		Create Date	: 11/22/2006
		====================================================================================*/
		_clearSelectedTab: function()
		{
			var i;
			// Sets all the tabs off.
			for (i = 0; i < _tabs.length; i += 1)
			{
				this._tabOff(i);
			}
		},

		/*==================================================================================
		Method		: _tabOff
		Summary		: Changes the tab style to off.
		Author		: Dale Lawless
		Create Date	: 11/06/2006
		====================================================================================*/
		_tabOff: function(tabId)
		{
			this.changeTabStyle(0, tabId);
		},

		/*==================================================================================
		Method		: _tabOn
		Summary		: Changes the tab style to on (Selected).
		Author		: Dale Lawless
		Create Date	: 11/06/2006
		====================================================================================*/
		_tabOn: function(tabId)
		{
			this.changeTabStyle(2, tabId);
		}
	};
} ();

_oTab = NRT.Tab;

