var swatchDisabledClassName="swatchDisabled";var swatchSelectedClassName="swatchSelected";var swatchMouseOverClassName="swatchMouseOver";var swatchImageEmwaClassName="swatchImageEMWA";var swatchImageEmwaMouseOverClassName="swatchImageEMWAMouseOver";var BuyBoxObj=Class.create({initialize:function(parentData,elmToAttach,form,debug){this.debug=debug!=undefined?debug:false;this.parentData=parentData;this.buyBox=elmToAttach;this.form=form;this.currentColor="";this.currentSize="";this.currentColorInfo=undefined;this.currentSwatch="";this.swatches=this.buyBox.select(".swatchImage").map(Element.extend);this.denomDropdown=$("denominationDropDown");this.swatchCount=this.swatches.length;this.quantity=this.buyBox.select(".childQuantity").map(Element.extend)[0];this.itemNumToAdd=this.buyBox.select(".FormItemNum").map(Element.extend)[0];this.sizeDropDown=this.buyBox.select(".sizeDropDown").map(Element.extend)[0];this.swatchInfo=this.buyBox.select(".swatchColorInfo").map(Element.extend)[0];this.multiDropDown=this.buyBox.select(".multiDropdownItems").map(Element.extend)[0];this.itemAsinInput=this.getItemAsinInput();this.swatchText=new Object();this.setupPrice();this.setupSize();if(this.swatches!=undefined&&this.swatches.length>0){this.setupSwatches()}else{if(this.denomDropdown!=undefined&&this.denomDropdown.length>0){this.setupGiftCard()}}this.changeSize();this.changeSizeStyle();this.attachEvents()},attachEvents:function(){if(this.sizeDropDown!=undefined){Event.observe(this.sizeDropDown,"change",function(event){this.changeSizeStyle()}.bindAsEventListener(this))}},changeSizeStyle:function(){if(this.sizeDropDown!=undefined){this.sizeDropDown.style.color=this.sizeDropDown[this.sizeDropDown.selectedIndex].style.color}},changeScarcityMessage:function(){if(this.currentColorInfo!=undefined){var scarcityMessageDiv=this.buyBox.select(".scarcityMessage").map(Element.extend)[0];var scarcityMessage=this.currentColorInfo.getScarcityMessage();if((scarcityMessage!=undefined)&&(scarcityMessageDiv!=undefined)){scarcityMessageDiv.innerHTML=scarcityMessage}}},changeDenom:function(){var price=$("denominationDropDown").value;var asinInfo=this.parentData.getPriceAsin(price);var asin=asinInfo.getAsin();this.itemAsinInput.value=asin},changePrice:function(asin){if(this.currentColorInfo!=undefined&&this.currentColorInfo.getPriceLabel()!=""){if(this.priceBlock!=undefined){this.priceBlock.innerHTML="";var ourPrice=document.createElement("span");if(this.priceToInt(this.currentColorInfo.getPriceLabel())<this.priceToInt(this.origPrice.value)){var label=new Element("span",{"class":"label"}).update(this.salePrice.text);var price=new Element("span",{"class":"price"}).update(this.currentColorInfo.getPriceLabel());ourPrice=new Element("span",{"class":"salePrice"});ourPrice.appendChild(label);ourPrice.appendChild(price);this.priceBlock.appendChild(ourPrice);var regPrice=document.createElement("span");var regLabel=new Element("span",{"class":"label"}).update(this.origPrice.text);var regPriceValue=new Element("span",{"class":"price"}).update(this.origPrice.value);regPrice=new Element("span",{"class":"origPrice"});regPrice.appendChild(regLabel);regPrice.appendChild(regPriceValue);this.priceBlock.appendChild(regPrice)}else{var price=new Element("span",{"class":"price"}).update(this.currentColorInfo.getPriceLabel());ourPrice=new Element("span",{"class":"ourPrice"});ourPrice.appendChild(price);this.priceBlock.appendChild(ourPrice)}}}},priceToInt:function(price){if(price){price=price.replace(/\$/,"");return parseInt(price)}else{return 0}},changeAvailabilityMessage:function(isEmwaEnabled,currentAsin){if(isEmwaEnabled){$("emwaMessage_"+currentAsin).show();$("productAvailabilityMessageEMWA").show();$("productAvailabilityMessage").hide()}else{$("emwaMessage_"+currentAsin).hide();$("productAvailabilityMessageEMWA").hide();$("productAvailabilityMessage").show()}},changeSize:function(){this.updateSwatchDisplay();var currentAsin=this.parentData.getCurrentAsinData().getAsin();if(this.sizeDropDown!=undefined&&this.sizeDropDown.value!=undefined&&this.sizeDropDown.value!=""){try{this.currentColorInfo=this.parentData.getSizeColorAsin(this.sizeDropDown.value,this.currentColor);var isEmwaButtonEnabled=true;if(this.currentColorInfo!=undefined){this.changePrice();this.form.fire("page:RemoveImportant",{currentAsin:currentAsin});isEmwaButtonEnabled=this.isEmwa(this.currentColorInfo)}else{for(var i=0;i<this.swatches.length;++i){var color=this.swatches[i][1].alt;var colorInfo=this.parentData.getSizeColorAsin(this.sizeDropDown.value,color);isEmwaButtonEnabled=isEmwaButtonEnabled&&this.isEmwa(colorInfo)}}this.quantity.disabled=isEmwaButtonEnabled;if(isEmwaButtonEnabled){addClassForElement(this.currentSwatch,swatchImageEmwaClassName);this.buyBox.fire("page:"+currentAsin+"EmwaButtonEnable",{asinInfo:this.currentColorInfo,parentBuybox:this.buyBox})}else{if(this.currentColorInfo!=undefined){this.itemAsinInput.value=this.currentColorInfo.getAsin();this.buyBox.fire("page:"+currentAsin+"EmwaButtonDisable",{currentColorInfo:""});this.buyBox.fire("page:"+currentAsin+"ButtonEnable",{currentColorInfo:this.currentColorInfo});this.buyBox.fire("page:ButtonEnable",{currentColorInfo:this.currentColorInfo})}}this.changeScarcityMessage();this.changeAvailabilityMessage(isEmwaButtonEnabled,currentAsin)}catch(e){}}else{try{this.currentColorInfo=this.parentData.getColor(this.currentColor);var isEmwaButtonEnabled=this.isEmwa(this.currentColorInfo)||((this.currentColor=="")&&(this.parentData.isAllChildrenEMWA()));if(isEmwaButtonEnabled){if(this.currentColor!=""){addClassForElement(this.currentSwatch,swatchImageEmwaClassName)}this.buyBox.fire("page:"+currentAsin+"EmwaButtonEnable",{currentColorInfo:"",parentBuybox:this.buyBox})}else{this.buyBox.fire("page:"+currentAsin+"ButtonDisable",{currentColorInfo:""});this.buyBox.fire("page:"+currentAsin+"EmwaButtonDisable",{currentColorInfo:""});this.buyBox.fire("page:ButtonDisable",{currentColorInfo:""})}if(this.quantity!=undefined){this.quantity.disabled=isEmwaButtonEnabled}this.changeAvailabilityMessage(isEmwaButtonEnabled,currentAsin)}catch(e){}}},changeSwatch:function(swatchType,swatch,colorHash,sizeDropDown){this.swatches.each(function(swatch){swatch=swatch[1];if(swatch.alt==this.currentColor){removeClassForElement(swatch,swatchSelectedClassName);removeClassForElement(swatch,swatchMouseOverClassName);this.updateSwatchTitle(this.swatchTypeColorMapping[swatch.alt],selectColor);this.updateSwatchText(swatch.alt)}}.bind(this));var currentAsin=this.parentData.getCurrentAsinData().getAsin();addClassForElement($(swatch),swatchSelectedClassName);this.buyBox.fire("page:RemoveImportant",{currentAsin:currentAsin});this.currentSwatchType=swatchType;this.currentSwatch=$(swatch);this.currentColor=swatch.alt;this.currentColorInfo=this.parentData.getColor(this.currentColor);this.rewriteSize(colorHash.getSizes());swatch.fire("page:"+currentAsin+"RewriteImage",{colorHash:colorHash});this.changeSize();this.updateSwatchTitle(swatchType,swatch.alt);this.updateSwatchText(swatch.alt);this.changePrice();try{sortSizeRefinementOptions(sizeDropDown)}catch(e){}},getCurrentColor:function(){return this.currentColor},getSelectedAsin:function(){return this.currentColorInfo},getItemAsinInput:function(){var formItemAsin=this.buyBox.select(".FormItemAsin").map(Element.extend)[0];if(formItemAsin==undefined){formItemAsin=new Element("input",{"class":"FormItemAsin",type:"hidden",name:"item.0.asin",value:""});this.form.appendChild(formItemAsin);formItemAsin=this.buyBox.select(".FormItemAsin").map(Element.extend)[0]}return formItemAsin},hoverSwatch:function(swatchType,swatch,colorHash){var swatchClasses=getClassForElement(swatch);if(swatchClasses.indexOf(swatchImageEmwaClassName)!=-1||swatchClasses.indexOf(swatchImageEmwaMouseOverClassName)!=-1){addClassForElement($(swatch),swatchImageEmwaMouseOverClassName)}else{addClassForElement($(swatch),swatchMouseOverClassName)}swatch.fire("page:"+this.parentData.getCurrentAsinData().getAsin()+"UpdateMainImage",{colorHash:colorHash});this.updateSwatchTitle(swatchType,swatch.alt);this.updateSwatchText(swatch.alt)},returnSwatch:function(swatchType,swatch,colorHash){if(swatch.alt!=this.currentColor){removeClassForElement(swatch,swatchMouseOverClassName);removeClassForElement(swatch,swatchImageEmwaMouseOverClassName);colorHash=this.currentColorInfo!=undefined?this.currentColorInfo:this.parentData.getCurrentAsinData()}swatch.fire("page:"+this.parentData.getCurrentAsinData().getAsin()+"UpdateMainImage",{colorHash:colorHash});var swatchColor=(this.currentColor!=""&&this.swatchColorRowMapping[this.currentColor]==this.swatchColorRowMapping[swatch.alt])?this.currentColor:selectColor;this.updateSwatchTitle(swatchType,swatchColor);this.updateSwatchText(swatch.alt)},updateSwatchDisplay:function(){this.swatches.each(function(swatch){var isDisableColor=false;if(this.sizeDropDown!=undefined&&this.sizeDropDown.value!=undefined&&this.sizeDropDown.value!=""){var color=swatch[1].alt;var asin=this.parentData.getSizeColorAsin(this.sizeDropDown.value,color);isDisableColor=(asin==undefined||asin=="")}if(isDisableColor){addClassForElement(swatch[1],swatchDisabledClassName)}else{removeClassForElement(swatch[1],swatchDisabledClassName)}}.bind(this))},setupGiftCard:function(){sortSizeRefinementOptions($("denominationDropDown"),0);this.changeDenom();$("denominationDropDown").onchange=function(){this.changeDenom()}.bind(this);$("addItemMainFormFloating").onsubmit=function(){return this.validateGiftCard()}.bind(this)},setupSwatches:function(){var sizeDropDown=this.sizeDropDown;this.sizeDropDown.onchange=function(){this.changeSize()}.bind(this);try{this.swatchCount=0;this.swatches=new Array();this.swatchTitle=new Object();this.swatchColorRowMapping=new Object();this.swatchTypeColorMapping=new Object();this.buyBox.select(".regularPriceSwatches",".salePriceSwatches").each(function(type){var swatchType=type.className.replace("colors ","").replace("Swatches","");if(swatchType.indexOf("swatchRow")!=-1){swatchType=swatchType.substring(0,swatchType.indexOf(" swatchRow"))}this.swatchTitle[swatchType]=selectColor;type.select(".swatchImage").map(Element.extend).each(function(swatch){var swatchItem=new Array();swatchItem[0]=swatchType;swatchItem[1]=swatch;this.swatches.push(swatchItem);this.swatchCount++;var color=swatch.alt;swatch.onmouseover=function(){this.hoverSwatch(swatchType,swatch,this.parentData.getColor(color))}.bind(this);swatch.onclick=function(){this.changeSwatch(swatchType,swatch,this.parentData.getColor(color),sizeDropDown)}.bind(this);swatch.onmouseout=function(){this.returnSwatch(swatchType,swatch,this.parentData.getColor(color))}.bind(this);var swatchRow=type.className;if(swatchRow.indexOf("swatchRow")!=-1){swatchRow=swatchRow.substr(swatchRow.indexOf("swatchRow"));swatchRow=swatchRow.replace("swatchRow","");this.swatchColorRowMapping[color]=swatchRow}else{this.swatchColorRowMapping[color]=""}this.swatchTypeColorMapping[color]=swatchType;var colorSizes=this.parentData.getColor(color).getSizes();var isAllEmwa=true;for(var i=0;i<colorSizes.length;++i){isAllEmwa=isAllEmwa&&this.isEmwa(this.parentData.getSizeColorAsin(colorSizes[i],color));if(!isAllEmwa){break}}if(isAllEmwa){addClassForElement($(swatch),swatchImageEmwaClassName)}}.bind(this))}.bind(this));if(this.swatchCount>1){this.updateSwatchText();sortSizeRefinementOptions(sizeDropDown)}else{var swatch=this.swatches[0];this.changeSwatch(swatch[0],swatch[1],this.parentData.getColor(swatch[1].alt),sizeDropDown)}}catch(e){}},setupSize:function(){var size=this.sizeDropDown;if(size!=undefined){var buyableSizes=this.parentData.sizeList.getSizes();for(var i=1;i<size.options.length;++i){var isSizeBuyable=false;for(var j=0;j<buyableSizes.length;++j){if(this.sizeDropDown.options[i].value==buyableSizes[j]){isSizeBuyable=true;break}}if(isSizeBuyable){var isAllColorsEmwa=true;for(var j=0;j<this.swatches.length;++j){var colorInfo=this.parentData.getSizeColorAsin(this.sizeDropDown.options[i].value,this.swatches[j].alt);if(!this.isEmwa(colorInfo)){isAllColorsEmwa=false;break}}if(isAllColorsEmwa){size.options[i].style.color="red"}}else{size.remove(i);--i}}}},setupPrice:function(){this.priceBlock=this.buyBox.select(".priceBlock").map(Element.extend)[0];if(this.priceBlock!=undefined){this.salePrice={};this.origPrice={};this.ourPrice={};this.hasSale=false;try{this.salePrice.value="$0";this.salePrice.text="";this.salePrice.container=this.priceBlock.select(".salePrice").map(Element.extend)[0];if(this.salePrice.container!=undefined){this.salePrice.label=this.salePrice.container.select(".label").map(Element.extend)[0];this.salePrice.price=this.salePrice.container.select(".price").map(Element.extend)[0];this.salePrice.value=new String(this.salePrice.price.innerHTML);this.salePrice.text=new String(this.salePrice.label.innerHTML);this.hasSale=true}}catch(e){}try{this.origPrice.value="$0";this.origPrice.text="";this.origPrice.container=this.priceBlock.select(".origPrice").map(Element.extend)[0];if(this.origPrice.container!=undefined){this.origPrice.label=this.origPrice.container.select(".label").map(Element.extend)[0];this.origPrice.price=this.origPrice.container.select(".price").map(Element.extend)[0];this.origPrice.value=new String(this.origPrice.price.innerHTML);this.origPrice.text=new String(this.origPrice.label.innerHTML)}}catch(e){}try{this.ourPrice.container=this.priceBlock.select(".ourPrice").map(Element.extend)[0];if(this.ourPrice.container!=undefined){this.ourPrice.price=this.ourPrice.container.select(".price").map(Element.extend)[0];this.ourPrice.value=new String(this.ourPrice.price.innerHTML)}}catch(e){}}},getSwatchTextDiv:function(swatchType,color){if(this.swatchText[color]==undefined){if(this.swatchColorRowMapping[color]!=undefined){this.swatchText[color]=this.buyBox.select("."+swatchType+"SwatchInfo"+this.swatchColorRowMapping[color]).map(Element.extend)[0]}}return this.swatchText[color]},updateSwatchText:function(color){if(this.swatchTypeColorMapping[color]!=undefined){var swatchType=this.swatchTypeColorMapping[color];var swatchDiv=this.getSwatchTextDiv(swatchType,color);if(swatchDiv!=undefined){swatchDiv.innerHTML=this.swatchTitle[swatchType];if(swatchType=="salePrice"){if(this.swatchTitle[swatchType]!=selectColor){swatchDiv.addClassName("maroonSale")}else{swatchDiv.removeClassName("maroonSale")}}}}},updateSwatchTitle:function(swatch,color){for(var swatchType in this.swatchTitle){this.swatchTitle[swatchType]=selectColor}if(this.currentSwatchType!=undefined&&this.currentColor!=undefined){this.swatchTitle[this.currentSwatchType]=this.currentColor}this.swatchTitle[swatch]=color},rewriteSize:function(newList){var size=this.sizeDropDown;size.disabled=false;var selectASizeText=size.options[0].text;var selectedText=size.options[size.options.selectedIndex].text;size.options.length=0;size.options[0]=new Option(selectASizeText,"");for(i=0;i<newList.length;i++){var currentOption=size.options[(i+1)]=new Option(newList[i],newList[i]);currentOption.selected=(currentOption.text==selectedText);var asinData=this.parentData.getSizeColorAsin(newList[i],this.currentColor);if(this.isEmwa(asinData)){currentOption.style.color="red"}}if(newList.length==1){size.options[1].selected=true;this.changeSize()}this.changeSizeStyle()},validate:function(){if(this.swatches!=undefined&&this.swatches!=""){return this.validateBuyBox()}else{if(this.denomDropdown!=undefined&&this.denomDropdown!=""){return this.validateGiftCard()}else{return true}}},isBuyable:function(){if(this.swatches!=undefined&&this.swatches!=""){return true}else{if(this.denomDropdown!=undefined&&this.denomDropdown!=""){return true}else{return false}}},validateGiftCard:function(){this.changeDenom();return true},validateBuyBox:function(){var validForm=false;if(this.getCurrentColor()!=""&&this.sizeDropDown.value!=""&&this.getSelectedAsin()!=""&&this.quantity.value>0){validForm=true}return validForm},writeBuyInformation:function(){if(this.isBuyable()){if(this.validate()){this.changeSize()}else{this.removeInputs()}}else{this.removeInputs()}},removeInputs:function(){try{this.itemAsinInput.remove();this.itemNumToAdd.remove();if(this.quantity.value==0){this.quantity.remove()}if(this.denomDropdown!=undefined&&this.denomDropdown!=""){this.denomDropdown.disabled=true}if(this.sizeDropDown!=undefined&&this.sizeDropDown!=""){this.sizeDropDown.disabled=true}if(this.multiDropDown!=undefined&&this.multiDropDown!=""){this.multiDropDown.disabled=true}}catch(e){}},isEmwa:function(asinData){if(asinData!=undefined){return(asinData.getEMWAEnabled()&&asinData.getOutOfStock()&&(asinData.getOfferId()==undefined||asinData.getOfferId()==""))}else{return true}}});
