// JavaScript Document
// Author: Mike Lipman
// Date: 2/22/2010

// Function Name: pricingOutTab
// Purpose: Change the background color of the tab
// Input:	oObj - tab in the table
// Output:	none
function pricingOutTab(oObj)
{
	// Do nothing if the user hovers over the currently selected tab
	if ((oObj.style.backgroundColor == '#ffffff') || (oObj.style.backgroundColor == 'rgb(255, 255, 255)'))
	{
		oObj.style.backgroundColor = '#eeefce';
	}
}

// Function Name: pricingOverTab
// Purpose: Change the background color of the tab
// Input:	oObj - tab in the table
// Output:	none
function pricingOverTab(oObj)
{
	// the first time the tab is hovered over, the backgroundColor is blank
	if (oObj.style.backgroundColor == '')
	{
		// see which pricing radio button has been selected
		if (oObj.innerHTML.indexOf('Prepaid') >= 0)
		{
			oObj.style.backgroundColor = '#ffffff';
		}
		else
		{
			if (oObj.innerHTML.indexOf('Prepaid') < 0)
			{
				oObj.style.backgroundColor = '#c1bb00';
				oObj.style.cursor = 'default';
			}
			else
			{
				oObj.style.cursor = 'default';
			}
		}
	}
	else
	{
		if ((oObj.style.backgroundColor == '#eeefce') || (oObj.style.backgroundColor == 'rgb(238, 239, 206)'))
		{
			oObj.style.backgroundColor = '#ffffff';
		}
		else
		{
			oObj.style.cursor = 'default';
		}
	}
}

// Function Name: setPricingTabSelected
// Purpose: Changes the display of the second set of tabs to acknowledge that the user has clicked on one of the tabs
// Input:	iNum - ordinal number of the selected tab
// Output:	none
function setPricingTabSelected(shown, hidden)
{
	// The ID is retrieved by looking at the number at the end of the 'hidden' div ID.
	// Due to issues with the App Detail page, the index of the 'shown' div is converted to match that of the 'hidden' div
	var index = hidden.replace(/[A-z]*/,'');
	shown = shown.replace(/[0-9]+/,'') + index;
	
	// First, simulate the outTab behavior of the previously selected tab
	var shownTab = document.getElementById(shown);
	var hiddenTab = document.getElementById(hidden);
	
	if ((hiddenTab != null) && (shownTab != null))
	{
		hiddenTab.style.position = 'relative';
		hiddenTab.style.top = '0em';
		hiddenTab.style.paddingBottom = '0.5em';
		hiddenTab.style.color = '#000000';
		hiddenTab.style.backgroundColor = '#eeefce';
		hiddenTab.style.cursor = 'pointer';
		hiddenTab.style.borderBottomColor = '#cccccc';
		
		shownTab.style.position = 'relative';
		shownTab.style.top = '-0.5em';
		shownTab.style.paddingBottom = '1em';
		shownTab.style.color = '#ffffff';
		shownTab.style.backgroundColor = '#c1bb00';
		shownTab.style.cursor = 'default';
		shownTab.style.borderBottomColor = '#c1bb00';
		
		if (shown.indexOf('eeAppList') >= 0)
		{
			if (shown.indexOf('eeAppListPricingContract') >= 0)
			{
				document.getElementById('eeAppListPricingContractInfo' + index).style.display = 'block';
				document.getElementById('eeAppListPricingPrepaidInfo' + index).style.display = 'none';
			}
			else
			{
				document.getElementById('eeAppListPricingContractInfo' + index).style.display = 'none';
				document.getElementById('eeAppListPricingPrepaidInfo' + index).style.display = 'block';
				document.getElementById('eeAppListPricingPrepaidTab' + index).style.backgroundColor = '#c1bb00';
			}
		}
		else
		{
			if (shown.indexOf('eeAppDetail') >= 0)
			{
				if (shown.indexOf('eeAppDetailPricingContract') >= 0)
				{
					document.getElementById('eeAppDetailPricingContractInfo' + index).style.display = 'block';
					document.getElementById('eeAppDetailPricingPrepaidInfo' + index).style.display = 'none';
				}
				else
				{
					document.getElementById('eeAppDetailPricingContractInfo' + index).style.display = 'none';
					document.getElementById('eeAppDetailPricingPrepaidInfo' + index).style.display = 'block';
					document.getElementById('eeAppDetailPricingPrepaidTab' + index).style.backgroundColor = '#c1bb00';
				}
			}
		}
	}
}

function setAppListGlobalSelector()
{
	var oObj = document.getElementById('eeAppListSelectorContract');
	var i = 1;
	var bLoop = true;
	
	if (oObj != null)
	{
		while (bLoop)
		{
			if (document.getElementById('eeAppListPricingContractTabContent' + i) != null)
			{
				if (document.getElementById('eeAppListPricingPrepaidTabContent' + i) != null)
				{
					if (oObj.checked)
					{
						setPricingTabSelected('eeAppListPricingContractTabContent' + i,'eeAppListPricingPrepaidTabContent' + i);
					}
					else
					{
						setPricingTabSelected('eeAppListPricingPrepaidTabContent' + i,'eeAppListPricingContractTabContent' + i);
					}
				}
				
				i++;
			}
			else
			{
				bLoop = false;
			}
		}
	}
}