// JavaScript Document

var shadeData = new Array();

function addToCart()
{
	lLstShade = window.document.getElementById("lstShadeName");
	lItemId = lLstShade.options[lLstShade.options.selectedIndex].value;
	
	
	if(shadeData[lItemId][4]!="1")
	{
		alert("This item is not in stock.");
		return false;
	}
	
	lItemQty = window.document.getElementById("txtProdQty").value;
	lItemQty = parseInt(lItemQty);
	lItemQty = (isNaN(lItemQty)?0:lItemQty);

	if(lItemQty <= 0)
	{
		alert("Please enter a quantity.");
		return false;
	}        
	
	if(lItemQty > 4)
	{
		alert("We're sorry, orders are limited to no more that 4 units of any item.");
		return false;
	}
	
	oUserSku = window.document.getElementById("sku");
	oUserSku.value = lItemId+"|"+lItemQty; 
	
	window.document.frmUserItem.action="https://shop.chanel.com/Cart.aspx";
	
	window.document.frmUserItem.submit();
}


function shadeListSelected(pShadeList)
{
	selectShade(pShadeList.options[pShadeList.options.selectedIndex].value);
}

function selectShade(pSKUId)
{
	var oItemPrice = window.document.getElementById("txtItemPrice"); 
	oItemPrice.value = shadeData[pSKUId][2];
	
	
	var texturedImg = window.document.getElementById("texturedShadeImg");
	var texturedImgNm = window.document.getElementById("texturedShadeImgNm");
	
	//texturedImgNm.value = shadeData[pSKUId][1];
	texturedImgNm.innerHTML = shadeData[pSKUId][1];
	
	
		var swatchImages = window.document.getElementsByName("colorSwatch");
	var swatchSKU = "";
	var swatchSRC = "";

	window.document.getElementById("texturedShadeImg").style.backgroundColor= '#' + shadeData[pSKUId][3];
	window.document.getElementById("texturedShadeImg").style.height= '50px';
	window.document.getElementById("texturedShadeImg").style.width= '50px';

	for(i=0; i < swatchImages.length; i++)
	{
		swatchSKU = (swatchImages[i].id).replace(/colorSwatch/gi,"");
		swatchSRC = swatchImages[i].src;
		swatchSRC_OFF = swatchSRC.replace(/_over\.gif/gi,"_off.gif");
		swatchSRC_OVER = swatchSRC.replace(/_off\.gif/gi,"_over.gif");
		
		if(swatchSKU == "["+pSKUId+"]")
		{
			swatchImages[i].src = swatchSRC_OVER;
		}
		else
		{
			swatchImages[i].src = swatchSRC_OFF; 
		}
	}
	
	
	var shadeNmListBox = window.document.getElementById("lstShadeName");
	for(i=0; i < shadeNmListBox.options.length; i++)
	{
		if(shadeNmListBox.options[i].value == pSKUId)
		{
			shadeNmListBox.options.selectedIndex = i;
			break;
		}
	}
	
	oAddToCartBtn = window.document.getElementById("btnAddToCart");
	oProdQtyTxt = window.document.getElementById("txtProdQty");
	if(shadeData[pSKUId][4]!="1")
	{
		oProdQtyTxt.value = 0;
		oProdQtyTxt.style.display="none";
		oAddToCartBtn.src = "images/common/shared/outofstock.jpg";
	}
	else
	{
		oProdQtyTxt.value = "";
		oProdQtyTxt.style.display = "block";
		oAddToCartBtn.src = "images/common/shared/addbag.jpg";
	}
	
}

function prePopulateSKU(pSKU) {
    lList = document.getElementById("lstShadeName");
    sLen = lList.length;
    for (var i = 0; i < sLen; i++) {
        if(lList[i].value == pSKU) {
            lList[i].selected = "selected";
        }
    }
}
shadeData["154136"] = new Array("3145891541366","Arlequin","$27.00","e4bfa5","1");
shadeData["154138"] = new Array("3145891541380","Courtisane","$27.00","e17081","1");
shadeData["188413"] = new Array("3145891884135","Giggle","$27.00","A14A44","1");
shadeData["188418"] = new Array("3145891884180","Unity","$27.00","BB7D7E","1");
shadeData["188404"] = new Array("3145891884043","Spark","$27.00","cf6674","1");
shadeData["188402"] = new Array("3145891881029","Brilliance","$27.00","E1B2BA","1");
shadeData["188403"] = new Array("3145891884036","Glaze","$27.00","D8B6Bf","1");
shadeData["154106"] = new Array("3145891541069","Myriade","$27.00","a4473d","1");
shadeData["154107"] = new Array("3145891541076","Equinoxe","$27.00","9e6157","1");
shadeData["154108"] = new Array("3145891541083","Constellation","$27.00","ed965c","1");
shadeData["154112"] = new Array("3145891541120","Waterlilly (Limited Edition)","$27.00","d05964","1");
shadeData["154119"] = new Array("3145891541199","Wild Rose","$27.00","9f6c6b","1");
shadeData["154121"] = new Array("3145891541212","Beige Guitare","$27.00","ddae85","1");
shadeData["154122"] = new Array("3145891541229","Nebula","$27.00","d07396","1");
shadeData["154126"] = new Array("3145891541267","Silex (Limited Edition)","$27.00","f37c81","1");
shadeData["154128"] = new Array("3145891541281","Météore","$27.00","b66d71","1");
shadeData["154131"] = new Array("3145891541311","Mica","$27.00","f59aad","1");
shadeData["154132"] = new Array("3145891541328","Mirage","$27.00","9a524f","1");
shadeData["154147"] = new Array("3145891541472","Bel Air (Limited Edition)","$27.00","c26779","1");
shadeData["154190"] = new Array("3145891884029","Blizzard","$27.00","9d5f52","1");
shadeData["154217"] = new Array("3145891542172","Red Shine","$27.00","a3193f","1");
shadeData["154420"] = new Array("3145891544206","Pin-Up","$27.00","faae8e","1");
shadeData["154630"] = new Array("3145891546309","Pagoda","$27.00","D68B7C","1");
shadeData["154640"] = new Array("3145891546408","Sunset Gold","$27.00","DC9360","1");
shadeData["154830"] = new Array("3145891548303","Magnifique","$27.00","D78899","1");
shadeData["154840"] = new Array("3145891548402","Imaginaire","$27.00","B46588","1");
shadeData["154876"] = new Array("3145891548761","Seashell","$27.00","F5CDAD","1");
shadeData["154886"] = new Array("3145891548860","Coral Reef","$27.00","EE987C","1");
shadeData["154896"] = new Array("3145891548969","Rose Sand","$27.00","ECA0B3","1");
shadeData["154906"] = new Array("3145891549065","Summer Plum","$27.00","CF97A4","1");
shadeData["154930"] = new Array("3145891549300","Paillettes","$27.00","eea2a7","1");
shadeData["154940"] = new Array("3145891549409","Sundress","$27.00","E9B4A3","1");
shadeData["154960"] = new Array("3145891549607","Iris","$27.00","eaa686","1");
shadeData["154980"] = new Array("3145891549805","Galactic","$27.00","dddcbb","1");
selectShade("154136")
