Object.extend(Date.prototype,{addMonths:function(b){var a=this.getDate();this.setDate(1);this.setMonth(this.getMonth()+b);var c=this.getMonth();this.setDate(a);if(this.getMonth()!=c){this.setDate(0)}return this},toShortDateString:function(d,b){d=d||"mdy";var a=this.getDate().toString();var c=(this.getMonth()+1).toString();if(b){if(a<10){a="0"+a}if(c<10){c="0"+c}}switch(d){case ("ymd"):return this.getFullYear()+"/"+c+"/"+a;case ("dmy"):return a+"/"+c+"/"+this.getFullYear();default:return c+"/"+a+"/"+this.getFullYear()}},toShortTimeString:function(){var b=(this.getHours()>11)?"PM":"AM";var a=(this.getHours()<12)?(this.getHours()==0?12:this.getHours()):(this.getHours()==12?12:this.getHours()-12);a=a.toString();var c=(this.getMinutes()<10)?"0"+this.getMinutes().toString():this.getMinutes().toString();return a+":"+c+" "+b}});if(typeof String.prototype.trim==="undefined"){String.prototype.trim=function(){return this.replace(/^\s+/).replace(/\s+$/)}}var NAC=(NAC||{});NAC.Commerce=(NAC.Commerce||{});NAC.Commerce.Address=Class.create();NAC.Commerce.Address.prototype={initialize:function(c,a,b){this.oBillingFields=c;this.oShippingFields=a;this.setup(b)},setup:function(b){if(!$(b)){setTimeout(this.setup.bind(this,b),10)}else{this.oCopyCheck=$(b);this.oCopyCheck.observe("click",this.onCopyCheckClick.bindAsEventListener(this));for(var c in this.oBillingFields){if(this.oBillingFields.hasOwnProperty(c)){var a=this.oBillingFields[c]=$(this.oBillingFields[c]);if(a.type.toLowerCase().indexOf("select")>=0){a.observe("change",this.onSelectChange.bind(this,c))}else{a.observe("focus",this.onInputFocus.bind(this,c));a.observe("blur",this.onInputBlur.bindAsEventListener(this))}}}for(var c in this.oShippingFields){if(this.oShippingFields.hasOwnProperty(c)){this.oShippingFields[c]=$(this.oShippingFields[c])}}this.onCopyCheckClick()}},matchInput:function(b){var c=this.oBillingFields[b];var a=this.oShippingFields[b];if(c.type.toLowerCase().indexOf("select")>=0){a.selectedIndex=c.selectedIndex}else{a.value=c.value}},onCopyCheckClick:function(){for(var c in this.oBillingFields){if(this.oBillingFields.hasOwnProperty(c)){var a=this.oBillingFields[c];var b=this.oShippingFields[c];if(this.oCopyCheck.checked){this.matchInput(c);b.disabled="disabled"}else{b.disabled="";b.value=""}}}},onSelectChange:function(a){if(this.oCopyCheck.checked){this.matchInput(a)}},onDocumentPress:function(a){this.matchInput(a)},onInputFocus:function(a){if(this.oCopyCheck.checked&&!this.fOnPress){this.fOnPress=this.onDocumentPress.bind(this,a);document.observe("keypress",this.fOnPress)}},onInputBlur:function(){if(this.oCopyCheck.checked&&this.fOnPress){this.fOnPress();Event.stopObserving(document,"keypress",this.fOnPress);this.fOnPress=null}}};var NAC=(NAC||{});NAC.Commerce=(NAC.Commerce||{});NAC.Commerce.Cart=Class.create();NAC.Commerce.Cart.prototype={initialize:function(b,a){this.sId=b;this.aRows=a;this.setup()},setup:function(){if(!$(this.sId)||(this.aRows.length>0&&!$(this.aRows[this.aRows.length-1].sDomId))){setTimeout(this.setup.bind(this),10)}else{this.oDom=$(this.sId);this.hDom={body:this.oDom.down("tbody"),empty:this.oDom.down("tfoot"),checkout:this.oDom.down(".checkout"),itemCount:this.oDom.down(".itemCount"),subtotal:this.oDom.down(".subtotal")};NAC.Commerce.Ajax.Cart.getFullCart(function(b,a){if(b.bSuccess){this.oCart=a;this.oCouponManager=new NAC.Commerce.CartCouponManager(this.oDom.down(".adder"),a,this.onCouponChange.bind(this))}else{alert(b.sReason)}}.bind(this));if(this.aRows.length==0){this.setEmptyCart(true)}else{this.setEmptyCart(false);this.aRows.each(function(a){a.oDom=$(a.sDomId);a.oQuantityObserver=new Form.Element.Observer(a.oDom.down(".quantity"),0.5,this.onQuantityChange.bind(this,a));a.fonRemoveClick=this.onRemoveClick.bind(this,a);Event.observe(a.oDom.down(".remove"),"click",a.fonRemoveClick)}.bind(this))}}},setEmptyCart:function(a){if(a){this.hDom.checkout.disabled="disabled";this.hDom.empty.show();this.hDom.body.hide()}else{this.hDom.checkout.disabled="";this.hDom.empty.hide();this.hDom.body.show()}},destroyRow:function(a){this.aRows=this.aRows.without(a);if(a.oDom){Event.stopObserving(a.oDom.down(".remove"),"click",a.fonRemoveClick)}a.oDom.parentNode.removeChild(a.oDom);a.oDom=null},refresh:function(a){this.oCouponManager.refresh(a);this.oCart=a;this.updateCartTotal();this.setEmptyCart(this.aRows==0)},updateCartTotal:function(){this.hDom.itemCount.innerHTML=this.oCart.ItemCount+(this.oCart.ItemCount==1?" item":" items");new Effect.Highlight(this.hDom.itemCount,{endcolor:"#FFFFFF",restorecolor:"#FFFFFF"});this.hDom.subtotal.innerHTML=this.oCart.TaxableTotal;new Effect.Highlight(this.hDom.subtotal,{endcolor:"#FFFFFF",restorecolor:"#FFFFFF"})},onCouponChange:function(a){this.oCart=a;this.updateCartTotal()},onQuantityChange:function(a,b,d){if(d===""){this.hDom.checkout.disabled="disabled";return}var c;try{c=parseInt(d);if(isNaN(c)||c<0){throw new Error()}}catch(f){this.hDom.checkout.disabled="disabled";alert("You must enter a positive number in the Quantity field.");return}if(c==0){this.onRemoveClick(a)}else{NAC.Commerce.Ajax.Cart.updateItemQuantity(a.sItemId,c,function(g,e){if(g.bSuccess){this.hDom.checkout.disabled="";a.oDom.down(".total").innerHTML=e;new Effect.Highlight(a.oDom.down(".total"),{endcolor:"#FFFFFF",restorecolor:"#FFFFFF"});NAC.Commerce.Ajax.Cart.getFullCart(function(i,h){if(i.bSuccess){this.refresh(h)}else{alert(i.sReason)}}.bind(this))}else{alert(g.sReason)}}.bind(this))}},onRemoveClick:function(a){NAC.Commerce.Ajax.Cart.updateItemQuantity(a.sItemId,0,function(b){if(b.bSuccess){this.destroyRow(a);NAC.Commerce.Ajax.Cart.getFullCart(function(d,c){if(d.bSuccess){this.refresh(c)}else{alert(d.sReason)}}.bind(this))}else{alert(b.sReason)}}.bind(this))}};var NAC=(NAC||{});NAC.Commerce=(NAC.Commerce||{});NAC.Commerce.CartCouponManager=Class.create();NAC.Commerce.CartCouponManager.prototype={initialize:function(b,a,c){this.oAdder=b;this.oCart=a;this.fOnChange=c;this.setup()},setup:function(){this.hDom={apply:this.oAdder.down(".apply"),promo:this.oAdder.down(".promo")};Event.observe(this.hDom.apply,"click",this.onApplyClick.bindAsEventListener(this));this.buildCouponsDom()},addCouponDomToPage:function(b,a){b.oDom=this.getCouponDom(b);this.oAdder.parentNode.insertBefore(b.oDom,this.oAdder);if(b.Removable){b.fOnClick=this.onRemoveClick.bind(this,b);Event.observe(b.oDom.down(".remove"),"click",b.fOnClick)}},buildCouponsDom:function(){var a=this.cartHasExclusiveCoupon();if(a){this.addCouponDomToPage(a,0);Element.hide(this.oAdder)}else{this.oCart.Coupons.each(function(c,b){this.addCouponDomToPage(c,b)}.bind(this));Element.show(this.oAdder)}},cartHasExclusiveCoupon:function(){if(this.oCart){for(var a=0;a<this.oCart.Coupons.length;a++){if(this.oCart.Coupons[a].Exclusive){return this.oCart.Coupons[a]}}}return false},destroyCouponsDom:function(){this.oCart.Coupons.each(function(a){if(a.oDom){if(a.Removable){try{Event.stopObserving(a.oDom.down(".remove"),"click",a.fOnClick)}catch(b){}}if(a.oSeparatorDom){a.oSeparatorDom.parentNode.removeChild(a.oSeparatorDom)}a.oDom.parentNode.removeChild(a.oDom);a.oDom=null}}.bind(this))},getCouponDom:function(a){var b=new Element("tr").insert(new Element("td",{style:"text-align:left;"}).update(a.Description)).insert(new Element("td",{style:"text-align:right;"}).insert(new Element("span",{style:"font-weight:bold;color:#f00"}).update("-"+a.Discount)));if(a.Removable){b.firstChild.appendChild(document.createTextNode(" "));b.firstChild.appendChild(new Element("a",{href:"javascript:void(0);","class":"remove ncCartControlText"}).update("remove"))}return b},refresh:function(b,a){this.destroyCouponsDom();this.oCart=b;this.buildCouponsDom();if(a){this.fOnChange(b)}},onApplyClick:function(){var a=$F(this.hDom.promo).trim();if(a==""){alert("You must enter a coupon code.")}else{NAC.Commerce.Ajax.Cart.addCouponToCart(a,function(c,b){if(c.bSuccess){this.refresh(b,true)}else{alert(c.sReason)}}.bind(this))}},onRemoveClick:function(a){NAC.Commerce.Ajax.Cart.removeCouponFromCart(a.Id,function(c,b){if(c.bSuccess){this.refresh(b,true)}else{alert(oStats.sReason)}}.bind(this))}};var NAC=(NAC||{});NAC.Commerce=(NAC.Commerce||{});NAC.Commerce.CartEnsurer=Class.create();NAC.Commerce.CartEnsurer.prototype={initialize:function(a){this.iPeriod=a*1000;this.onExecute()},onExecute:function(){NAC.Commerce.Ajax.Utilities.ensureCart(function(b,a){if(b.bSuccess){if(!a){alert("The contents of your cart have been updated to reflect a change in supply. Please inspect your cart carefully after the page has reloaded.");window.location.href=window.location.href}setTimeout(this.onExecute.bind(this),this.iPeriod)}else{alert(b.sReason)}}.bind(this))}};var NAC=(NAC||{});NAC.Commerce=(NAC.Commerce||{});NAC.Commerce.Checkout=Class.create();NAC.Commerce.Checkout.prototype={initialize:function(a,c,d,b){this.sId=a;this.sPaymentId=c;this.sOrderId=d;this.sProcessingId=b;this.setup()},setup:function(){if(!$(this.sId)){setTimeout(this.setup.bind(this),10)}else{this.oDom=$(this.sId);this.oPayment=$(this.sPaymentId);this.oOrder=$(this.sOrderId);this.oProcessing=$(this.sProcessingId);this.hDom={shipping:this.oDom.down(".shippingList"),validation:this.oDom.down(".validation"),vendor:this.oDom.down(".vendor"),firstName:this.oDom.down(".firstName"),lastName:this.oDom.down(".lastName"),account:this.oDom.down(".account"),month:this.oDom.down(".month"),year:this.oDom.down(".year"),cvc:this.oDom.down(".cvc")};this.oOrder.observe("click",this.onOrderClick.bindAsEventListener(this))}},togglePage:function(a){if(a){this.oDom.show();this.oProcessing.hide()}else{this.oDom.hide();this.oProcessing.show()}},showValidation:function(b){var a=new Element("ul",{"class":"ncErrorSummary"});b.each(function(c){a.insert(new Element("li").update(c))});this.hDom.validation.update(a);this.hDom.validation.show()},validatePaymentInput:function(){var a=[];if($F(this.hDom.vendor).trim()===""){a.push("Account vendor is required")}if($F(this.hDom.firstName).trim()===""){a.push("First name is required")}if($F(this.hDom.lastName).trim()===""){a.push("Last name is required")}if($F(this.hDom.account).trim()===""){a.push("Account number is required")}if($F(this.hDom.month).trim()===""||$F(this.hDom.year).trim()==""){a.push("Expiration date is required")}if($F(this.hDom.cvc).trim()===""){a.push("Security code is required")}if(a.length>0){this.showValidation(a);return false}else{this.hDom.validation.hide();return true}},onOrderClick:function(){if(this.validatePaymentInput()){this.togglePage(false);NAC.Commerce.Ajax.Checkout.doCheckout($F(this.hDom.vendor).trim(),$F(this.hDom.firstName).trim(),$F(this.hDom.lastName).trim(),$F(this.hDom.account).trim(),$F(this.hDom.month).trim(),$F(this.hDom.year).trim(),$F(this.hDom.cvc).trim(),$F(this.hDom.shipping).trim(),function(b,a){if(b.bSuccess){window.location=a}else{this.togglePage(true);this.showValidation([b.sReason])}}.bind(this))}}};var NAC=(NAC||{});NAC.Commerce=(NAC.Commerce||{});NAC.Commerce.DetailsView=Class.create();NAC.Commerce.DetailsView.prototype={reChoose:/^\s*$/,initialize:function(h,f,g,e,d,c,b,a){this.sProductId=h;this.aElementLists=f;this.sQuantityId=g;this.sEachId=e;this.sEachPriceId=d;this.sCartButtonId=c;this.sNoStockId=b;this.oMiniCart=a;this.sCurrItemId="";this.setup()},setup:function(){this.aElementLists.each(function(a){Event.observe(a.sId,"change",this.onElementListChange.bind(this,a))}.bind(this));Event.observe(this.sCartButtonId,"click",this.onCartButtonClick.bind(this))},onElementListChange:function(a){var c=true;var b="";this.aElementLists.each(function(d){if(this.reChoose.test($F(d.sId))){c=false;throw $break}else{b+=(b=="")?d.sName+"="+$F(d.sId):"&"+d.sName+"="+$F(d.sId)}}.bind(this));if(!c){$(this.sCartButtonId).disabled="disabled";Element.hide(this.sEachId);Element.hide(this.sNoStockId);this.sCurrItemId=""}else{NAC.Commerce.Ajax.ProductDetails.isMaskAvailable(this.sProductId,b,function(d,e){if(d.bSuccess){if(e.Available){$(this.sCartButtonId).disabled="";$(this.sEachPriceId).innerHTML=e.Price;Element.show(this.sEachId);Element.hide(this.sNoStockId);this.sCurrItemId=e.ItemId}else{$(this.sCartButtonId).disabled="disabled";Element.hide(this.sEachId);Element.show(this.sNoStockId);this.sCurrItemId=""}}else{alert(d.sReason)}}.bind(this))}},onCartButtonClick:function(){var b;try{b=parseInt($F(this.sQuantityId));if(b<1){throw $break}}catch(a){alert("You must enter a valid Quantity.");return}NAC.Commerce.Ajax.Cart.addItemToCart(this.sCurrItemId,b,function(f,e){if(f.bSuccess){$(this.sQuantityId).value="1";this.oMiniCart.updateDom(e,true);var d=$(this.sCartButtonId);var c=d.value;if(!d.disabled){d.disabled="disabled";d.value="Item Added";setTimeout(function(){d.disabled="";d.value=c},3000)}}else{alert(f.sReason)}}.bind(this))}};var NAC=(NAC||{});NAC.Commerce=(NAC.Commerce||{});NAC.Commerce.ImageView=Class.create();NAC.Commerce.ImageView.prototype={initialize:function(b,a,c){this.sId=b;this.sMainId=a;this.aThumbnails=c;this.setup()},setup:function(){if(this.aThumbnails.length>1){this.aThumbnails.each(function(a){Event.observe($(a.DomId),"click",this.onThumbClick.bind(this,a))}.bind(this))}},onThumbClick:function(a){$(this.sMainId).src=a.FullUrl}};var NAC=(NAC||{});NAC.Commerce=(NAC.Commerce||{});NAC.Commerce.MiniCart=Class.create();NAC.Commerce.MiniCart.prototype={initialize:function(c,b,a){this.sId=c;this.sCountId=b;this.sPriceId=a;this.setup()},setup:function(){if(!$(this.sId)||!$(this.sCountId)||!$(this.sPriceId)){setTimeout(this.setup.bind(this),10)}else{this.oCountDom=$(this.sCountId);this.oPriceDom=$(this.sPriceId);this.synchronize(false)}},synchronize:function(a){NAC.Commerce.Ajax.Cart.getMiniCart(function(c,b){if(c.bSuccess){this.updateDom(b,a)}else{alert(c.sReason)}}.bind(this))},updateDom:function(a,b){this.oCountDom.innerHTML=a.ItemCount+" Items";this.oPriceDom.innerHTML="("+a.TotalPrice+")";if(b){new Effect.Highlight(this.sId,{endcolor:"#FFFFFF",restorecolor:"#FFFFFF"})}}};var NAC=(NAC||{});NAC.Commerce=(NAC.Commerce||{});NAC.Commerce.OrderSummary=Class.create();NAC.Commerce.OrderSummary.prototype={initialize:function(a){this.sId=a;this.setup()},setup:function(){if(!$(this.sId)){setTimeout(this.setup.bind(this),10)}else{this.oDom=$(this.sId);this.hDom={shippingList:this.oDom.down("select.shippingList"),shippingPrice:this.oDom.down("span.shippingPrice"),totalPrice:this.oDom.down("span.totalPrice")};this.hDom.shippingList.observe("change",this.onShippingChange.bindAsEventListener(this))}},onShippingChange:function(){var a=$F(this.hDom.shippingList);NAC.Commerce.Ajax.Checkout.getShippingCost(a,function(b,c){if(b.bSuccess){this.hDom.shippingPrice.innerHTML=c[0];new Effect.Highlight(this.hDom.shippingPrice,{endcolor:"#FFFFFF",restorecolor:"#FFFFFF"});this.hDom.totalPrice.innerHTML=c[1];new Effect.Highlight(this.hDom.totalPrice,{endcolor:"#FFFFFF",restorecolor:"#FFFFFF"})}else{alert(b.sReason)}}.bind(this))}};