var QSC=QSC||{};QSC.apps=QSC.apps||{};QSC.apps.product=QSC.apps.product||{};QSC.apps.product.options=function(a){QSC.util.loadClassConfig(this,a,{optionsList:[],availMap:{},priceEl:"listPrice",adjPriceEl:"adjustedPrice",adjPriceContainerEl:"adjustedPriceItem",qtyElName:"quantity",submitElName:"submit",availStatusEl:"prodAvailStatus",availQtyEl:"prodAvailQty",formEl:"addToCartForm",feedback:true,createHTML:false,userPrefNoDefaultOption:false,container:null,beanPrefix:null});this.optionsList=[];this.configurationsTree={};this.invalidConfigurationObj=null;this.formEl=null;this.priceEl=null;this.adjPriceEl=null;this.adjPriceContainerEl=null;this.qtyEl=null;this.submitEl=null;this.availStatusEl=null;this.availQtyEl=null;var b=this;$(function(){b.init()})};QSC.apps.product.options.prototype.init=function(){this.initOptions();this.loadConfigurationsTree();this.retrieveFeedbackElements();this.initConfigurableOptions();this.updateTotalPrice()};QSC.apps.product.options.prototype.initOptions=function(){for(var b=0,a=this.config.optionsList.length;b<a;b++){this.initOption(this.config.optionsList[b])}this.config.optionsList=null};QSC.apps.product.options.prototype.loadConfigurationsTree=function(){var c=this.config.availMap.items;this.invalidConfigurationObj=this.config.availMap["default"];for(var g=0,b=c.length;g<b;g++){var a=c[g],h=a.key.split(","),e=this.configurationsTree;for(var f=0,d=h.length-1;f<d;f++){if(!e[h[f]]){e[h[f]]={}}e=e[h[f]]}e[h[h.length-1]]=a}this.config.availMap=null};QSC.apps.product.options.prototype.initOption=function(c){var b;switch(c.optionType){case"DROPDOWN":b=QSC.apps.product.options.option.dropdown;break;case"TEXT":b=QSC.apps.product.options.option.text;break;case"CHECKBOX":b=QSC.apps.product.options.option.checkbox;break}c.parent=this;c.index=this.optionsList.length;c.formEl=this.config.formEl;c.createHTML=this.config.createHTML;c.container=this.config.container;c.beanPrefix=this.config.beanPrefix;c.userPrefNoDefaultOption=this.config.userPrefNoDefaultOption;var a=new b(c);this.optionsList.push(a)};QSC.apps.product.options.prototype.getPriceChange=function(){var b=0,d=false;for(var c=0,a=this.optionsList.length;c<a;c++){optionPriceChange=this.optionsList[c].getPriceChange();if(optionPriceChange!=0){b+=optionPriceChange;d=true}}if(d){return b}return false};QSC.apps.product.options.prototype.updateTotalPrice=function(){if(!this.config.feedback){return}var b=this.getPriceChange();if(b===false){this.toggleAdjPrice(false);return}var a=this.config.price+b;a=Math.max(a,0);this.toggleAdjPrice(true,a)};QSC.apps.product.options.prototype.toggleAdjPrice=function(b,a){if(b){QSC.util.setText(this.adjPriceEl,QSC.util.formatCurrency(a));$(this.adjPriceContainerEl).show();$(this.priceEl).addClass("strike")}else{$(this.adjPriceContainerEl).hide();$(this.priceEl).removeClass("strike")}};QSC.apps.product.options.prototype.retrieveFeedbackElements=function(){if(!this.config.feedback){return}this.formEl=QSC.util.getElement(this.config.formEl);this.priceEl=QSC.util.getElement(this.config.priceEl);this.adjPriceEl=QSC.util.getElement(this.config.adjPriceEl);this.adjPriceContainerEl=QSC.util.getElement(this.config.adjPriceContainerEl);this.availStatusEl=QSC.util.getElement(this.config.availStatusEl);this.availQtyEl=QSC.util.getElement(this.config.availQtyEl);this.qtyEl=this.formEl[this.config.qtyElName];this.submitEl=this.formEl[this.config.submitElName]};QSC.apps.product.options.prototype.validate=function(){for(var b=0,a=this.optionsList.length;b<a;b++){if(!this.optionsList[b].validate()){return false}}return true};QSC.apps.product.options.prototype.initConfigurableOptions=function(){var c=this.getConfigurableOptions();if(c.length==0){return}var b=c[0],a=this.getCurrentConfigurationsTreeBranchOptionValueIds(c,0);b.updateOptionValuesDisplayed(a);$(this.formEl).bind("submit",this,this.updateConfigurableOnSubmit)};QSC.apps.product.options.prototype.updateConfigurableOnSubmit=function(c){var d=c.data;var b=d.getConfigurableOptions();var a=d.getCurrentConfigurationsTreeBranch(b);if(!a.key){alert("Please select a valid configuration.  If this problem persists, please contact customer support.");return false}if(d.formEl&&d.formEl.configOptionKey){d.formEl.configOptionKey.value=a.key}return true};QSC.apps.product.options.prototype.updateConfigurableOptions=function(d){var e=this.getConfigurableOptions();var c=d.getSelectedOptionValue();if(!c){this.toggleAllItemsAfterOption(d,false);this.updateAvailability(this.invalidConfigurationObj);return}var b=e.length;for(;b>0;b--){if(e[b-1].config.optionId==d.config.optionId){b--;break}}if(b==(e.length-1)){this.toggleAllItemsAfterOption(d,true);var a=this.getCurrentConfigurationsTreeBranch(e);this.updateAvailability(a);return}var f=e[++b];var a=this.getCurrentConfigurationsTreeBranchOptionValueIds(e,b);f.updateOptionValuesDisplayed(a);f.enable()};QSC.apps.product.options.prototype.getCurrentConfigurationsTreeBranchOptionValueIds=function(d,c){var a=this.getCurrentConfigurationsTreeBranch(d,c),b=[];for(var e in a){b.push(e)}return b};QSC.apps.product.options.prototype.getCurrentConfigurationsTreeBranch=function(d,c){if(typeof(c)=="undefined"){c=d.length}var b=this.configurationsTree;for(var a=0;a<c;a++){var e=d[a].getCurrentOptionValueId();if(!b[e]){return{}}b=b[e]}return b};QSC.apps.product.options.prototype.getConfigurableOptions=function(){var d=[];for(var c=0,a=this.optionsList.length;c<a;c++){var b=this.optionsList[c];if(b.isConfigurable()){d.push(b)}}return d};QSC.apps.product.options.prototype.updateAvailability=function(a){if(!this.config.feedback){return}if(this.availStatusEl){QSC.util.setText(this.availStatusEl,a.status)}if(this.availQtyEl){if(a.quantity){QSC.util.setText(this.availQtyEl,a.quantity);$(this.availQtyEl).closest("tr").show()}else{$(this.availQtyEl).closest("tr").hide()}}};QSC.apps.product.options.prototype.toggleAllItemsAfterOption=function(f,b){var g=(b?"enable":"disable"),e=!b,h=false;for(var c=0,a=this.optionsList.length;c<a;c++){var d=this.optionsList[c];if(this.optionsList[c]==f){h=true}else{if(h){d[g]()}}}if(this.config.feedback){this.qtyEl.disabled=e;this.submitEl.disabled=e}};QSC.apps.product.options.option=QSC.apps.product.options.option||{};QSC.apps.product.options.option.base=function(a){QSC.util.loadClassConfig(this,a,{createHTML:false,container:null,mainContClass:"product-option clear-fix",labelClass:"product-option-label",optionContClass:"product-option-subcontainer",optionalContClass:"product-option-optional",inputContClass:"product-option-input",asteriskClass:"product-option-asterisk",formEl:"addToCartForm",beanPrefix:"",parent:null});this.inputEl=null;this.inputContainer=null;this.optionalEl=null;this.optionValuesList=[];this.container=null;this.mainContainer=null;this.optionsContainer=null;this.labelContainer=null;this.init()};QSC.apps.product.options.option.base.prototype.init=function(){this.loadOptionValues();if(this.config.createHTML){this.createHTML()}else{this.formEl=QSC.util.getElement(this.config.formEl);this.retrieveInputEl();this.retrieveOptionalEl()}this.attachEvents();this.toggleInputContainerVisibility()};QSC.apps.product.options.option.base.prototype.loadOptionValues=function(){if(!this.config.valueMap){return}for(var b=0,a=this.config.valueMap.length;b<a;b++){var c=new this.config.optionValueClass(this.config.valueMap[b]);this.optionValuesList.push(c)}};QSC.apps.product.options.option.base.prototype.retrieveInputEl=function(){this.inputEl=this.formEl["selectedOption("+this.config.optionId+")"]};QSC.apps.product.options.option.base.prototype.retrieveOptionalEl=function(){if(this.config.optionRequired){return}this.optionalEl=this.formEl["checkedOptional("+this.config.optionId+")"];this.inputContainer=QSC.util.getElement("checkedOptionalContainer("+this.config.optionId+")")};QSC.apps.product.options.option.base.prototype.attachEvents=function(){this.attachInputElChangeEvent();this.attachOptionalElChangeEvent()};QSC.apps.product.options.option.base.prototype.attachInputElChangeEvent=function(){var a=this;$(this.inputEl).bind("change",function(){a.inputElChangeEvent()})};QSC.apps.product.options.option.base.prototype.attachOptionalElChangeEvent=function(){var a=this;if(this.optionalEl){$(this.optionalEl).bind("click",function(){a.optionalElChangeEvent()})}};QSC.apps.product.options.option.base.prototype.inputElChangeEvent=function(){if(this.config.configurable){this.config.parent.updateConfigurableOptions(this)}this.config.parent.updateTotalPrice()};QSC.apps.product.options.option.base.prototype.optionalElChangeEvent=function(){this.toggleInputContainerVisibility();this.config.parent.updateTotalPrice()};QSC.apps.product.options.option.base.prototype.toggleInputContainerVisibility=function(){if(this.config.optionRequired){return}if(this.optionalEl.checked){this.inputContainer.style.display=""}else{this.inputContainer.style.display="none"}};QSC.apps.product.options.option.base.prototype.getPriceChange=function(){return 0};QSC.apps.product.options.option.base.prototype.getOptionalElPriceChange=function(){if(this.optionalEl&&this.optionalEl.checked){return this.config.optionPriceInc}return 0};QSC.apps.product.options.option.base.prototype.isConfigurable=function(){return this.config.configurable};QSC.apps.product.options.option.base.prototype.enable=function(){this.enableInputEl();if(!this.config.optionRequired){this.enableOptionalEl()}};QSC.apps.product.options.option.base.prototype.disable=function(){this.disableInputEl();if(!this.config.optionRequired){this.disableOptionalEl()}};QSC.apps.product.options.option.base.prototype.enableInputEl=function(){this.inputEl.disabled=false};QSC.apps.product.options.option.base.prototype.disableInputEl=function(){this.inputEl.disabled=true};QSC.apps.product.options.option.base.prototype.enableOptionalEl=function(){this.optionalEl.disabled=false};QSC.apps.product.options.option.base.prototype.disableOptionalEl=function(){this.optionalEl.disabled=true};QSC.apps.product.options.option.base.prototype.createHTML=function(){this.container=this.config.container;this.mainContainer=document.createElement("DIV");this.mainContainer.className=this.config.mainContClass;var a=document.createElement("INPUT");a.type="hidden";a.name=this.getBeanPrefix()+"optionId";a.value=this.config.optionId;this.mainContainer.appendChild(a);this.createLabel();this.optionsContainer=document.createElement("DIV");this.optionsContainer.className=this.config.optionContClass;this.inputContainer=document.createElement("DIV");this.inputContainer.className=this.config.inputContClass;if(!this.config.optionRequired){this.createOptionalEl()}this.createAsterisk();this.createInputEl();this.optionsContainer.appendChild(this.inputContainer);this.mainContainer.appendChild(this.optionsContainer);this.container.appendChild(this.mainContainer)};QSC.apps.product.options.option.base.prototype.createAsterisk=function(){var a=document.createElement("SPAN");a.className=this.config.asteriskClass;QSC.util.setText(a,"*");if(this.config.optionRequired){this.labelContainer.appendChild(a)}else{this.inputContainer.appendChild(a)}};QSC.apps.product.options.option.base.prototype.getBeanPrefix=function(){return this.config.beanPrefix+"options["+this.config.index+"]."};QSC.apps.product.options.option.base.prototype.createLabel=function(){var a=document.createElement("DIV");a.className=this.config.labelClass;QSC.util.setText(a,this.config.optionLabel);this.labelContainer=a;this.mainContainer.appendChild(this.labelContainer)};QSC.apps.product.options.option.base.prototype.createOptionalEl=function(){var b=document.createElement("DIV");b.className=this.config.optionalContClass;var a=document.createElement("INPUT");a.type="checkbox";a.name=this.getBeanPrefix()+"checkedOptional";a.value="yes";if(this.config.checkedOptional){a.checked=a.defaultChecked=true}var c=document.createElement("SPAN");QSC.util.setText(c,(this.config.optionPriceInc!=0?this.config.optionPriceIncLabel:""));b.appendChild(a);b.appendChild(c);this.optionalEl=a;this.optionsContainer.appendChild(b)};QSC.apps.product.options.option.base.prototype.createInputEl=function(){};QSC.apps.product.options.option.base.prototype.validate=function(){if(!this.config.optionRequired&&!this.optionalEl.checked){return true}if(!this.validateInputEl()){return false}return true};QSC.apps.product.options.option.base.prototype.validateInputEl=function(){};QSC.apps.product.options.option.dropdown=function(a){QSC.util.loadClassConfig(this,a,{optionValueClass:QSC.apps.product.options.optionValue.dropdown});QSC.apps.product.options.option.dropdown.superclass.constructor.call(this,a)};QSC.util.extend(QSC.apps.product.options.option.dropdown,QSC.apps.product.options.option.base);QSC.apps.product.options.option.dropdown.prototype.getPriceChange=function(){var a=0;if(this.config.optionRequired||this.optionalEl.checked){var b=this.getSelectedOptionValue();if(b){a+=b.getPriceChange()}}a+=this.getOptionalElPriceChange();return a};QSC.apps.product.options.option.dropdown.prototype.getSelectedOptionValue=function(){var d=this.inputEl.value;for(var b=0,a=this.optionValuesList.length;b<a;b++){var c=this.optionValuesList[b];if(d==c.getValue()){return c}}return null};QSC.apps.product.options.option.dropdown.prototype.getCurrentOptionValueId=function(){var a=this.getSelectedOptionValue();if(a==null){return null}return a.getId()};QSC.apps.product.options.option.dropdown.prototype.updateOptionValuesDisplayed=function(b){var d=this.getCurrentOptionValueId();this.clearOptionValues();this.createDefaultOption();for(var c=0,a=b.length;c<a;c++){var e=b[c];this.drawOptionValue(e,(d==e))}this.config.parent.updateConfigurableOptions(this)};QSC.apps.product.options.option.dropdown.prototype.clearOptionValues=function(){for(var b=0,a=this.inputEl.options.length;b<a;b++){this.inputEl.remove(0)}};QSC.apps.product.options.option.dropdown.prototype.drawOptionValue=function(c,b){var a=this.getOptionValueById(c);this.inputEl.options[this.inputEl.options.length]=a.createHTML(b)};QSC.apps.product.options.option.dropdown.prototype.getOptionValueById=function(b){for(var a=0;a<this.optionValuesList.length;a++){if(this.optionValuesList[a].getId()==b){return this.optionValuesList[a]}}return null};QSC.apps.product.options.option.dropdown.prototype.disableInputEl=function(){this.inputEl.selectedIndex=0;this.inputEl.disabled=true};QSC.apps.product.options.option.dropdown.prototype.createDefaultOption=function(){if(!this.config.configurable&&this.config.userPrefNoDefaultOption){return}this.inputEl.options[this.inputEl.options.length]=new Option("Select","")};QSC.apps.product.options.option.dropdown.prototype.createInputEl=function(){var c=document.createElement("SELECT");c.name=this.getBeanPrefix()+"value";this.inputEl=c;this.createDefaultOption();for(var a=0;a<this.optionValuesList.length;a++){var b=this.config.value==this.optionValuesList[a].getValue();c.options[c.options.length]=this.optionValuesList[a].createHTML(b)}this.inputContainer.appendChild(c)};QSC.apps.product.options.option.dropdown.prototype.validateInputEl=function(){if(this.getSelectedOptionValue()==null){this.inputEl.focus();alert('Please select a valid product Option for "'+this.config.optionLabel+'"');return false}return true};QSC.apps.product.options.option.dropdown.prototype.createAsterisk=function(){if(!this.config.configurable&&this.config.userPrefNoDefaultOption){return}QSC.apps.product.options.option.dropdown.superclass.createAsterisk.call(this)};QSC.apps.product.options.option.text=function(a){QSC.apps.product.options.option.text.superclass.constructor.call(this,a)};QSC.util.extend(QSC.apps.product.options.option.text,QSC.apps.product.options.option.base);QSC.apps.product.options.option.text.prototype.createInputEl=function(){var a=document.createElement("INPUT");a.type="text";a.name=this.getBeanPrefix()+"value";a.size=a.maxLength=this.config.maxChars;a.value=this.config.value||"";this.inputContainer.appendChild(a);this.inputEl=a};QSC.apps.product.options.option.text.prototype.getPriceChange=function(){var a=0;a+=this.getOptionalElPriceChange();return a};QSC.apps.product.options.option.text.prototype.validateInputEl=function(){if(this.inputEl.value.length<this.config.minChars||this.inputEl.value.length>this.config.maxChars){this.inputEl.focus();alert("Please enter a value between "+this.config.minChars+" and "+this.config.maxChars+' characters for "'+this.config.optionLabel+'"');return false}return true};QSC.apps.product.options.option.checkbox=function(a){a.optionRequired=true;QSC.apps.product.options.option.checkbox.superclass.constructor.call(this,a)};QSC.util.extend(QSC.apps.product.options.option.checkbox,QSC.apps.product.options.option.base);QSC.apps.product.options.option.checkbox.prototype.createInputEl=function(){var a=document.createElement("INPUT");a.type="checkbox";a.name=this.getBeanPrefix()+"checkedOptional";a.value="yes";var b=document.createElement("SPAN");QSC.util.setText(b,(this.config.optionPriceInc!=0?this.config.optionPriceIncLabel:""));this.inputContainer.appendChild(a);this.inputContainer.appendChild(b);this.inputEl=a};QSC.apps.product.options.option.checkbox.prototype.attachInputElChangeEvent=function(){var a=this;$(this.inputEl).bind("click",function(){a.inputElChangeEvent()})};QSC.apps.product.options.option.checkbox.prototype.retrieveInputEl=function(){this.inputEl=this.formEl["checkedOptional("+this.config.optionId+")"]};QSC.apps.product.options.option.checkbox.prototype.getPriceChange=function(){if(this.inputEl.checked){return this.config.optionPriceInc}return 0};QSC.apps.product.options.option.checkbox.prototype.validateInputEl=function(){};QSC.apps.product.options.optionValue=QSC.apps.product.options.optionValue||{};QSC.apps.product.options.optionValue.base=function(a){QSC.util.loadClassConfig(this,a,{})};QSC.apps.product.options.optionValue.base.prototype.getValue=function(){return this.config.value};QSC.apps.product.options.optionValue.base.prototype.getId=function(){return this.config.id};QSC.apps.product.options.optionValue.base.prototype.getPriceChange=function(){return this.config.priceAdj};QSC.apps.product.options.optionValue.dropdown=function(a){QSC.apps.product.options.optionValue.dropdown.superclass.constructor.call(this,a)};QSC.util.extend(QSC.apps.product.options.optionValue.dropdown,QSC.apps.product.options.optionValue.base);QSC.apps.product.options.optionValue.dropdown.prototype.createHTML=function(b){var a=document.createElement("OPTION");a.text=this.config.text;a.value=this.config.value;if(b==true){a.selected=true}return a};