// 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["160700"] = new Array("3145891607000","Adorable","$30.00","cc5e6f","1");
shadeData["160620"] = new Array("3145891606201","Ardent (Limited Edition)","$30.00","b55b56","1");
shadeData["160580"] = new Array("3145891605808","Audace","$30.00","d92214","1");
shadeData["160090"] = new Array("3145891600902","Lover","$30.00","aa082c","1");
shadeData["160710"] = new Array("3145891607109","Fatale","$30.00","671f26","1");
shadeData["160780"] = new Array("3145891607802","Instinctive","$30.00","d69181","1");
shadeData["160140"] = new Array("3145891601404","Passion","$30.00","8d0e2a","1");
shadeData["160740"] = new Array("3145891607406","Comedia","$30.00","d9827e","1");
shadeData["160210"] = new Array("3145891602104","Exotic","$30.00","c64939","1");
shadeData["160610"] = new Array("3145891606102","Exaltation (Limited Edition)","$30.00","c14842","1");
shadeData["160020"] = new Array("3145891600209","Mystery","$30.00","5d2325","1");
shadeData["160031"] = new Array("3145891600315","Provocative","$30.00","c12a39","1");
shadeData["160040"] = new Array("3145891600407","Imagination","$30.00","d5665d","1");
shadeData["160050"] = new Array("3145891600506","Desirable","$30.00","c35969","1");
shadeData["160060"] = new Array("3145891600605","Silhouette","$30.00","753a32","1");
shadeData["160101"] = new Array("3145891601015","Attitude","$30.00","752f32","1");
shadeData["160111"] = new Array("3145891601114","Surprise","$30.00","6e3f4e","1");
shadeData["160171"] = new Array("3145891601718","Emotion","$30.00","b05145","1");
shadeData["160201"] = new Array("3145891602012","Voluptuous","$30.00","87262f","1");
shadeData["160260"] = new Array("3145891602609","Subtil","$30.00","CD5F74","1");
shadeData["160320"] = new Array("3145891603200","Crazed","$30.00","8B3C40","1");
shadeData["160330"] = new Array("3145891603309","Fabulous","$30.00","a2242a","1");
shadeData["160340"] = new Array("3145891603408","Libertine","$30.00","f37065","1");
shadeData["160360"] = new Array("3145891603606","36 Darling (Peach Pink) (Limited Edition)","$30.00","E3A3B1","1");
shadeData["160560"] = new Array("3145891605600","Exquise","$30.00","f48378","1");
shadeData["160590"] = new Array("3145891605907","Nude","$30.00","da6c46","1");
shadeData["160600"] = new Array("3145891606003","Vertige","$30.00","FF3F3F","1");
shadeData["160630"] = new Array("3145891606300","Curious","$30.00","a26451","1");
shadeData["160690"] = new Array("3145891606904","Mythic","$30.00","d29e8d","1");
shadeData["160720"] = new Array("3145891607208","Orientale","$30.00","8f3e2f","1");
shadeData["160730"] = new Array("3145891607307","Clandestine","$30.00","823639","1");
shadeData["160750"] = new Array("3145891607505","Amusing","$30.00","9c4a41","1");
shadeData["160760"] = new Array("3145891607604","Captive","$30.00","915047","1");
shadeData["160770"] = new Array("3145891607703","Intuitive","$30.00","ad6d62","1");
selectShade("160700")
