/**


ITEM DRILL DOWN - GET THE LOOK 


**/


function SortItems()
{
	var numOfItems = GetNumberOfItems();
	var categoryArray = CreateCategoryArray(numOfItems);
	
	SortCategoryArray(numOfItems, categoryArray);
}

function GetNumberOfItems()
{
	var numOfItems = document.getElementsByTagName("dfn").length;
	
	return numOfItems;
}

function CreateCategoryArray(numOfItems)
{
	var categoryArray = new Array(numOfItems);
	
	for (i=0; i<numOfItems; i++)
	{
		categoryArray[i] = GetCategoryType(i);
	}
	
	return categoryArray;
}

function GetCategoryType(position)
{
	var type = document.getElementsByTagName("dfn")[position].innerHTML;

	return type;
}

function SortCategoryArray(numOfItems, categoryArray)
{
	var type = "";
	var moveRowFromPosition = 0;
	var moveRowBeforePosition = 1;
	
	for (i=0; i < numOfItems; i++)
	{
		type = categoryArray[i];
	
		switch (type)
		{
			case "Face":
				MoveRowTo("facecontainer", moveRowFromPosition, moveRowBeforePosition);
				break;
			
			case "Eyes":
				MoveRowTo("eyescontainer", moveRowFromPosition, moveRowBeforePosition);
				break;
			
			case "Lips":
				MoveRowTo("lipscontainer", moveRowFromPosition, moveRowBeforePosition);
				break;
			
			default:
		}
	}
	
}

function MoveRowTo(tableId, moveRowFromPosition, moveRowBeforePosition)
{
	var tbody = document.getElementById(tableId).getElementsByTagName("tbody")[0];
	var itemToMove = document.getElementById("itemcontainer").rows[document.getElementById("itemcontainer").rows.length-1].getElementsByTagName("table")[0].rows[moveRowFromPosition];
	var itemReference = document.getElementById(tableId).rows[moveRowBeforePosition];
	
	tbody.insertBefore(itemToMove, itemReference);
}

function DefaultSelectLists()
{
	var numOfSelects = document.getElementsByTagName("select").length;
	
	for(i=0; i<numOfSelects; i++)
	{
		var numOfOptions = document.getElementsByTagName("select")[i].options.length;
		
		if(numOfOptions == 2)
		{
			document.getElementsByTagName("select")[i].selectedIndex = 1;
		}
	}
}



/**


ITEM DRILL DOWN - GIFT CERTIFICATES


**/


function RemoveShadesFields()
{
	document.getElementById("custcol5_fs_lbl").innerHTML="";
	document.getElementById("custcol5_fs").innerHTML="";
}

function ChangeGiftCertificate(itemId)
{
	document.getElementById("buyid").value=itemId;
}

function ModifyAddToCartImage()
{
	var original = document.getElementById("buyid").parentNode.parentNode.getElementsByTagName("img")[1].parentNode.innerHTML;
	
	document.getElementById("buyid").parentNode.parentNode.getElementsByTagName("img")[1].parentNode.innerHTML = "<img border=\"0\" align=\"absmiddle\" onkeypress=\"window.event.cancelBubble=true;\" onclick=\"if (CheckGiftValue() && document.forms['form2605'].onsubmit())  document.forms['form2605'].submit();;return false;\" alt=\"Add to cart\" src=\"/site/NewSiteFiles/New%20Folder%20(4)/4c1.jpg\"/>";
}

function DisplayAddToCartModalWindow()
{
	document.getElementById('addingItemsToCartFinish').style.visibility= '';
	setTimeout("document.getElementById('addingItemsToCartFinish').style.visibility= 'hidden';", 2000);
}

function CheckGiftValue()
{
	var selection = document.getElementById("giftCertificiates").selectedIndex;
	
	if (selection == 0)
	{
		alert("You must select a value");
		return false;
	}
	
	DisplayAddToCartModalWindow();
	return true;
}