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; var that = this; this.init = function() { 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 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