// JavaScript Document
// Author: Mike Lipman
// Date: 7/18/2008

var gPhoneSelected = '';	// Image file name of the current Phone selected

// Function Name: buildPhoneList
// Purpose: Based on the value of the option selected, the specific phone array is read to display the appropriate information
// Input:	oObj - The select object that has an option selected
// Output:	none
function buildPhoneList(oObj)
{
	var sSelectedVal = oObj.options[oObj.selectedIndex].value;
	//alert("sSelectedVal"+sSelectedVal);
	var iCounter = -1;
	var iMod = -1;
	var sDivStr = "<table class=\"eeHowToDownloadPhoneTable\">";	// table that will make up the entirety of the <div>
	var list1 = "<ul class=\"eeHowToDownloadPhoneList\">";	// first column of the table
	var list2 = "<ul class=\"eeHowToDownloadPhoneList\">";	// second column of the table
	var list3 = "<ul class=\"eeHowToDownloadPhoneList\">";	// third column of the table
	var bEmpty = true;	// will be set to false if there is at least one phone that can be displayed
	var sName = '';		// phone model name
	var iNum = -1;		// easyedge phone Image ID
	var sPic = '';		// image name
	
	// When the option value selected is "all", go through all phones in all arrays to build the phone lists
	if (sSelectedVal == "all")
	{
		// Iterate over the array or arrays, which houses every phone
		
		for (i = 0; i < allArr[0].length; i++)
		{
			// Iterate over a specific manufacturer phone array
			
			for (j = 0; j < allArr[0][i].length; j++)
			{
				// The modulo operator is used to ensure that all 3 lists have a proportionate number of items
				bEmpty = false;
				iCounter = iCounter + 1;
				iMod = iCounter % 3;
				//sName = allArr[i][j].substring(0, allArr[i][j].indexOf(","));
				//sPic = allArr[i][j].substring((allArr[i][j].indexOf(",") + 1),allArr[i][j].lastIndexOf(","));
				//iNum = allArr[i][j].substring(allArr[i][j].lastIndexOf(",") + 1);
				
				if (iMod == 0)
				{
					list1 = list1 + allArr[0][i][j];
				}
				else
				{
					if (iMod == 1)
					{
						list2 = list2 + allArr[0][i][j];
					}
					else
					{
						list3 = list3 + allArr[0][i][j];
					}
				}
			}
		}
	}
	// A specific phone manufacturer was selected
	else
	{
	    	    
		// Iterate over a specific sub-array in the larger array
		for (i = 0; i < allArr[0][sSelectedVal].length; i++)
		{
		    
			bEmpty = false;
			iCounter = iCounter + 1;
			iMod = iCounter % 3;
			//sName = allArr[sSelectedVal][i].substring(0, allArr[sSelectedVal][i].indexOf(","));
			//sPic = allArr[sSelectedVal][i].substring((allArr[sSelectedVal][i].indexOf(",") + 1),allArr[sSelectedVal][i].lastIndexOf(","));
			//iNum = allArr[sSelectedVal][i].substring(allArr[sSelectedVal][i].lastIndexOf(",") + 1);
			
			if (iMod == 0)
			{
				list1 = list1 + allArr[0][sSelectedVal][i];
			}
			else
			{
				if (iMod == 1)
				{
					list2 = list2 + allArr[0][sSelectedVal][i];
				}
				else
				{
					list3 = list3 + allArr[0][sSelectedVal][i];
				}
			}
		}
	}
	
	if (bEmpty)
	{
		document.getElementById('eeHowToDownloadModel').innerHTML = "<div class=\"eeHowToDownloadNoPhones\">There are no <strong>easy</strong>edge<sup>SM</sup> phones available for the chosen manufacturer.<br />Please select a different manufacturer.</div>";
	}
	else
	{
		sDivStr = sDivStr + "<tr><td>" + list1 + "</td><td>" + list2 + "</td><td>" + list3 + "</td></tr></table>";
		document.getElementById('eeHowToDownloadModel').innerHTML = sDivStr;
	}
}

// Function Name: showDownloadImage
// Purpose: Highlight the option and remove any verbiage along with the current graphic from the phone image area
// Input: 	oObj - the option object that will have its color changed
//			iNum - the phone ID to be used for retrieving the image from uscellular.com
// Output: 	None
function showDownloadImage(sStr)
{
	document.getElementById('eeHowToDownloadImageHeading').style.backgroundColor = '#7090B8';
	document.getElementById('eeHowToDownloadImageAreaText').style.display = 'none';
	
	if (document.getElementById('eeHowToDownloadGraphic').src.indexOf(sStr) < 0)
	{
		document.getElementById('eeHowToDownloadGraphic').src = sStr;
	}
}

// Function Name: revertColor
// Purpose: De-highlight the Phone Model option that is being left and show the selected Phone (if applicable)
// Input: 	oObj - the option object that will have its color changed
// Output: 	None
function revertImage()
{
	if (gPhoneSelected != '')
	{
		document.getElementById('eeHowToDownloadGraphic').src = gPhoneSelected;
	}
}

// Function Name: displayInstructions
// Purpose: Show the download instructions for the selected phone and save the phone ID
// Input: 	oObj - the option object that will have its value examined to determine which download step graphic to display
//			iNum - the phone ID to be used for retrieving the image from uscellular.com
// Output: 	None
function displayInstructions(iNum)
{
   
	//gPhoneSelected = sStr;
	document.getElementById('eeHowToDownloadGraphicInstructions').innerHTML = '';
	if (iNum == 1)
	{
		document.getElementById('eeHowToDownloadSteps').src = '/uscellular/images/easyedge/howTo_Steps_mShop_3.jpg';
	}
	else
	{
		document.getElementById('eeHowToDownloadSteps').src = '/uscellular/images/easyedge/steps_myt.gif';
	}
}