function skuPicker(skusArray,idPrefix,type,imgArray,checkAddToBag) { var that = this; this.skusArray = skusArray; this.imagesArray = imgArray; this.defaultColor = this.imagesArray[0]; this.idPrefix = idPrefix; this.type = type; this.hasWidth = false; this.hasSize = false; this.selectionStates = null; this.detailViewer = null; this.selectedImageType = "Main"; this.checkAddToBag = checkAddToBag; this.MiniCart = null; this.hasSale = false; this.LAST_ADDED_ITEM=null; var that = this; this.init = function() { this.checkErrorMessageArea(); this.checkIfHasWidthSize(); this.fixSmallSizeBug(); this.BAG = "BAG"; for (var img in this.imagesArray) { new Image().src = this.imagesArray[img].PD[this.selectedImageType]; } this.initVariantPrices(); switch(this.type) { case 'productLocator': this.submitProdLoc = new submitProductLocator(this); this.submitProdLoc.init(); break; case 'productDetail': break; case 'quickView': break; } this.selectDefaultColor(); this.selectionStates = new skuPickingLogic(this); this.selectionStates.init(); this.selectionStates.selectedColor = this.defaultColor; this.selectionStates.availForColor(); this.selectionStates.fillPreselections(); this.createMiniCart(); this.printViewMoreLinks(that.defaultColor); this.printEnlargeViewMoreLinks(that.defaultColor); this.selectionStates.selectIfSingle(); this.selectionStates.setMessage(); this.selectionStates.highLightSelection(); this.initImageTypeSelectors(); if (this.checkAddToBag == true) { this.initAddToBagButton(); } } this.selectDefaultColor = function() { var defaultImg = that.imagesArray._default.PD[that.selectedImageType]; var defaultColor; var backupDefaultColor = null; var defaultHasNoAvailability = true; for (var img in that.imagesArray) { if(defaultImg.indexOf(img) != -1) { defaultColor = img; break; } } for (sku in that.skusArray) { // check to make sure default is available if (backupDefaultColor == null && that.skusArray[sku].availability != "NOT_AVAILABLE") { backupDefaultColor = that.skusArray[sku].color_code; // grab an available color just in case } if(that.skusArray[sku].color_code == defaultColor && that.skusArray[sku].availability != "NOT_AVAILABLE"){ defaultHasNoAvailability = false; break; } } if(defaultHasNoAvailability){ defaultColor = backupDefaultColor; } that.defaultColor = defaultColor; } this.printViewMoreLinks = function(selectedColorCode) { var dataContainer = $$('#viewsMenu input.viewMoreData'); var viewMoreLinks = this.getViewMoreLinksData(selectedColorCode, dataContainer); for (var i = 0; i < viewMoreLinks.length; i++) { var element = '' + viewMoreLinks[i]['type'] + ''; element += (i + 1) != viewMoreLinks.length ? '|' : ''; if (skuPickerConstants.viewMoreLinksBefore == true) { $('heading').insert({before: element}); } else { var divider = $$('#viewsMenu .dividerBar'); if (!divider || divider.length == 0) { $('heading').insert({after: element}); } else { divider[divider.length - 1].insert({after: element}); } } } } this.highlightSelectedImageType = function() { var that = this; $$('#viewsMenu span.imageTypeSelector,#enlargeDesc .imageTypeSelector').each(function(element) { var elText = element.textContent ? element.textContent: (element.innerText ? element.innerText : null); if (elText != null && that.selectedImageType ==elText.replace('|','')) { element.addClassName('selected'); } else { element.removeClassName('selected'); } }); } this.printEnlargeViewMoreLinks = function(selectedColorCode) { var dataContainer = $$('#enlargeDesc input.viewMoreData'); var viewMoreLinks = this.getViewMoreLinksData(selectedColorCode, dataContainer); for (var i = 0; i < viewMoreLinks.length; i++) { var element = '' + viewMoreLinks[i]['type'] + ''; element += (i + 1) != viewMoreLinks.length ? ' | ' : ''; $('enlargeDesc').insert({bottom: element}); } } this.getViewMoreLinksData = function(selectedColorCode, dataContainer) { var viewMoreLinks = new Array(); var viewMoreLinksCount = 0; for (var i = 0; i < dataContainer.length; i++) { if(dataContainer[i] != null) { var element = dataContainer[i].value; var splitEl = element.split('|'); var colorCode = (splitEl.length >= 1) ? splitEl[0] : ''; var imageType = (splitEl.length >= 2) ? splitEl[1] : ''; if((colorCode == selectedColorCode) && (imageType != null)) { viewMoreLinks[viewMoreLinksCount] = new Object(); viewMoreLinks[viewMoreLinksCount]['type'] = imageType; viewMoreLinksCount++; } } } return viewMoreLinks; } this.fixSmallSizeBug = function() { for (var sku in that.skusArray) { if(that.skusArray[sku].size == 'S') { that.skusArray[sku].size = "_S"; } } var sizes = $$('.'+that.idPrefix+'CARTsize'); var i=0; for(i=0; i' + '
'; //emh.innerHTML = '
'; if($('quickViewImgHolder')) $('quickViewImgHolder').appendChild(emh); } if(!$(that.idPrefix + "inTheCart")) { var itc = document.createElement('div'); itc.id="inTheCart"; itc.className="inTheCart"; itc.innerHTML='
' + '
THIS ITEM HAS BEEN ADDED TO YOUR BAG
' + '
'; //itc.innerHTML='
THIS ITEM HAS BEEN ADDED TO YOUR BAG
'; if($('quickViewImgHolder')) $('quickViewImgHolder').appendChild(itc); } } this.createMiniCart = function () { var a= 0; miniCart=null; miniCart = { form: null, ajaxAction: null, ajaxWishAction: null, viewer: null, picker: null, clicked: null, initialize: function() { var addToCartButton = $('addToCartButton'); if (window.$('addToWishListButton') && $('addToWishListButton').id == 'addToWishListButton') var addToWishListButton = $('addToWishListButton'); if (addToCartButton != null) { this.MiniCart = true; this.form = addToCartButton.form; this.ajaxAction = this.form.ajaxAction.value; this.ajaxWishAction = this.form.ajaxWishListAction.value; if(that.type != "quickView") this.viewer = new easyViewer('ShopBag'); addToCartButton.onclick = this.buttonHandler; if (addToWishListButton != null) { addToWishListButton.onclick = this.wishButtonHandler; } } }, ajaxSuccess: function(transport) { var response = transport.responseText; /*var tmp = document.createElement('div'); tmp.innerHTML = response; //document.body.appendChild(tmp);*/ var splitted = response.split('$$$SPLITHERE$$$'); $('shoppingBagMain').innerHTML=splitted[0];//.update(splitted[0]); if (minicartConstants.easyViewerAddToBag == true) { $('ShopBagContent').innerHTML=splitted[1];//.update(splitted[1]); if ($('shopBagAction')) { $('shopBagAction').show(); } miniCart.viewer.show(); } else { $('inTheCartText').innerHTML="THIS ITEM HAS BEEN ADDED TO YOUR "+miniCart.clicked; if ($('inTheCart')) { $('inTheCart').style.display = 'block'; } var data = 'picker.LAST_ADDED_ITEM = function(color,width,size){if(color == "'+picker.selectionStates.selectedColor+'" && size == "'+picker.selectionStates.selectedSize+'" && width == "'+picker.selectionStates.selectedWidth+'")return true; return false; }'; eval('(' + data + ')' ); } //alert('running mine'); document.body.style.cursor='default'; // site scroll to top window.scrollTo(0,0); }, addToCart: function() { if (this.form.pid.value != '' && this.form.availability.value != '' && this.form.availability.value != 'NOT_AVAILABLE') { document.body.style.cursor='wait'; this.clicked = 'BAG'; new Ajax.Request(this.ajaxAction, {method:'post', postBody: Form.serialize(this.form), onSuccess: this.ajaxSuccess, onFailure: function() {alert('failure');document.body.style.cursor='default';}}); } else { picker.selectionStates.setMessage('force'); } }, addToWishList: function() { if (this.form.pid.value != '' && this.form.availability.value != '' && this.form.availability.value != 'NOT_AVAILABLE') { document.body.style.cursor='wait'; this.clicked = 'WISHLIST'; new Ajax.Request(this.ajaxWishAction, {method:'post', postBody: Form.serialize(this.form), onSuccess: this.ajaxSuccess, onFailure: function() {alert('failure');document.body.style.cursor='default';}}); } else { picker.selectionStates.setMessage('force'); } }, createCart : function() { document.createElement('div'); dive.innerHTML = "me"; }, buttonHandler: function() { miniCart.addToCart(); return false; }, wishButtonHandler: function() { miniCart.addToWishList(); return false; } } } } function skuPickingLogic(parent) { var that = this; this.skuPicker = parent; this.rolledOut = true; this.uniqueColors = new Array(); this.uniqueWidths = new Array(); this.uniqueSizes = new Array(); this.selectedColor = -1;this.selectedWidth = -1;this.selectedSize = -1; this.prevSelectedColor = -1;this.prevSelectedWidth = -1;this.prevSelectedSize = -1; this.rollOverButtonClassName = '';this.rollOverColorDescription = '';this.rollOverImg = ''; this.rollOverInTheCartTextDisplay = 'none'; this.init = function () { var colors = $$('.'+this.skuPicker.idPrefix+'CARTchip'); var widths = $$('.'+this.skuPicker.idPrefix+'CARTwidth'); var sizes = $$('.'+this.skuPicker.idPrefix+'CARTsize'); var i=0; for(i=0; i 1) { var last = ' and ' + msg[ msg.length-1 ]; var rest = msg.slice(0, msg.length-1); acc2 = rest.join(', ').concat(last); } else { acc2 = msg; } $(that.skuPicker.idPrefix+'locErrText').style.color = ''; $(that.skuPicker.idPrefix+'locErrText').style.backgroundColor = ''; $(that.skuPicker.idPrefix+'locErrText').innerHTML = 'Please select a ' + acc2 + '.'; /* var message = ""; if(that.selectedWidth!=-1) { message = "You have selected width " + that.selectedWidthName + ', please select a ' + acc2 + '.'; } else if(that.selectedSize != -1) { message = "You have selected size " + that.selectedSizeName + ', please select a ' + acc2 + '.'; } else { message = 'Please select a ' + acc2 + '.'; } $(that.skuPicker.idPrefix+'locErrText').innerHTML = message; */ if(force) { $(that.skuPicker.idPrefix+'locErrText').style.color = skuPickerConstants.forceColor; $(that.skuPicker.idPrefix+'locErrText').style.backgroundColor = skuPickerConstants.forceBackgroundColor; } } } // function for product inventory IN STOCK or NOT AVAILABLE this.addTo = function () { for (var sku in that.skuPicker.skusArray) { if($(that.skuPicker.idPrefix+'pid').value == sku){ var msgAvailability = that.skuPicker.skusArray[sku].availability; $(that.skuPicker.idPrefix+'availability').value = msgAvailability; } } } this.loadValidUPC = function () { var valid = false; for (var sku in that.skuPicker.skusArray) { if(that.skuPicker.skusArray[sku].color_code == that.selectedColor && (!that.skuPicker.hasWidth || that.skuPicker.skusArray[sku].width == that.selectedWidth) && (!that.skuPicker.hasSize || that.skuPicker.skusArray[sku].size == that.selectedSize)) { valid = true; $(that.skuPicker.idPrefix+'pid').value = sku; that.addTo(); } } if(!valid) { $(that.skuPicker.idPrefix+'pid').value = ''; that.populateAll(); } } this.populateAll = function() { var i; for(i=0; i