"use strict";var AddToCartFromRecommendationsViewModel=function(){var n=this,t="/MyTradeMe/Buy/ShoppingCart.aspx",u=!1,f=!1,e=new ShoppingCartItemRepository,i,r;n.onClick=function(n){if(!f){if(u){location.href=t;return}e.addItemToCart(n,1,r,i)}},i=function(t){n.ShowErrorMessage(t.statusText),n.isAttemptingToSavetoCart=!1},r=function(){n.isSavedtoCart=!0,n.isAttemptingToSavetoCart=!1,location.href=t}},AddToCartFromRecommendationsViewModel=function(){var n=this,t="/MyTradeMe/Buy/ShoppingCart.aspx",u=!1,f=!1,e=new ShoppingCartItemRepository,i,r;n.onClick=function(n){if(!f){if(u){location.href=t;return}e.addItemToCart(n,1,r,i)}},i=function(){n.isAttemptingToSavetoCart=!1},r=function(){n.isSavedtoCart=!0,n.isAttemptingToSavetoCart=!1,location.href=t}},ShoppingCartViewModel=function(n,t,i){var r=this,u;r.deliveryAddressViewModel=i,u=new ShoppingCartItemRepository,ko.mapping.fromJS(n,{shoppingCartItemGroups:{create:function(n){return new ShoppingCartItemGroupViewModel(n.data,u,t,i)}}},r),r.subTotal=ko.computed(function(){var n=0;return ko.utils.arrayForEach(r.shoppingCartItemGroups(),function(t){var i=parseFloat(t.subTotal());isNaN(i)||(n+=i)}),n}),r.shippingTotal=ko.computed(function(){var n=0;return ko.utils.arrayForEach(r.shoppingCartItemGroups(),function(t){var i=parseFloat(t.shippingSubTotal());isNaN(i)||(n+=i)}),n}),r.showTotalShippingSubTotal=ko.observable(),r.shippingTotalGreaterThanZero=ko.computed(function(){r.showTotalShippingSubTotal(r.shippingTotal()>0)}),r.total=ko.computed(function(){return r.shippingTotal()+r.subTotal()}),r.itemCount=ko.computed(function(){var n=0;return ko.utils.arrayForEach(r.shoppingCartItemGroups(),function(t){ko.utils.arrayForEach(t.cartItems(),function(t){t.hasBeenRemoved()||n++})}),n}),r.showEmptyCart=ko.computed(function(){return r.itemCount()===0}),r.permanentlyRemoveItem=function(n){n.isRemoving(!0),ko.utils.arrayForEach(r.shoppingCartItemGroups(),function(t){t!=undefined&&t.cartItems.indexOf(n)>=0&&(t.cartItems.remove(n),t.cartItems().length===0&&r.shoppingCartItemGroups.remove(t))})},r.allShippingSelected=ko.computed(function(){var n=ko.utils.arrayFirst(r.shoppingCartItemGroups(),function(n){return n.shippingPromotion.hasQualifiedForPromotion()?!1:ko.utils.arrayFirst(n.cartItems(),function(n){return!n.shippingOptionsViewModel.hasShippingSelected()&&!n.hasExceptionError()})});return n===null}).extend({notify:"always"}),r.hasAnyWarnings=ko.computed(function(){return ko.utils.arrayFirst(r.shoppingCartItemGroups(),function(n){return ko.utils.arrayFirst(n.cartItems(),function(n){return n.hasWarningError()||n.hasExceptionError()})})}).extend({notify:"always"}),r.hasAnyInternationalSellers=ko.computed(function(){var n=ko.utils.arrayFirst(r.shoppingCartItemGroups(),function(n){return n.isInternationalSeller()});return n!==null&&n!==undefined&&n.subTotal()+n.shippingSubTotal()>=r.internationalSellerCustomsWarningMessageLimit()})},BaseRepository=function(n){var u=n,t={json:"json",xml:"xml",html:"html"},i={post:"POST",get:"GET"},r=this;r.post=function(n,r,f,e){jQuery.ajax({type:i.post,url:u+n,data:r,success:f,error:e,dataType:t.json,cache:!1})},r.get=function(n,r,f,e){jQuery.ajax({type:i.get,url:u+n,data:r,success:f,error:e,dataType:t.json})},r.getHTML=function(n,r,u,f){jQuery.ajax({type:i.get,url:n,data:r,success:function(n){var t=new DOMParser;u(t.parseFromString(n,"text/html"))},error:f,dataType:t.html})},r.getCache=function(n,r,f){jQuery.ajax({type:i.get,url:u+n,cache:r,success:f,dataType:t.json})}},GtmShoppingCartRepository=function(){var n=this;n.pushRemoveFromCartToDataLayer=function(n){if(n&&n.gtmShoppingCartViewModel){var t={event:"removeFromCart",ecommerce:{remove:{products:[{name:n.listingTitle(),id:n.listingId(),price:n.price(),brand:n.gtmShoppingCartViewModel.brand(),category:n.gtmShoppingCartViewModel.category(),quantity:n.quantity(),dimension41:n.gtmShoppingCartViewModel.mCat(),dimension42:n.gtmShoppingCartViewModel.newOrUsed(),dimension43:n.gtmShoppingCartViewModel.storeName(),dimension44:n.gtmShoppingCartViewModel.subtitle(),dimension45:n.gtmShoppingCartViewModel.sellerId(),dimension46:n.gtmShoppingCartViewModel.mustPickUp(),dimension48:n.gtmShoppingCartViewModel.sellerLocation(),dimension49:n.gtmShoppingCartViewModel.freeShipping()}]}}};n.cartId()>0&&(t.cartId=n.cartId()),dataLayer.push(t)}},n.pushAddToCartToDataLayer=function(n){if(n&&n.gtmShoppingCartViewModel){var t={event:"addToCart",ecommerce:{add:{products:[{name:n.listingTitle,id:n.listingId,price:n.price,brand:n.gtmShoppingCartViewModel.brand,category:n.gtmShoppingCartViewModel.category,quantity:n.quantity,dimension41:n.gtmShoppingCartViewModel.mCat,dimension42:n.gtmShoppingCartViewModel.newOrUsed,dimension43:n.gtmShoppingCartViewModel.storeName,dimension44:n.gtmShoppingCartViewModel.subtitle,dimension45:n.gtmShoppingCartViewModel.sellerId,dimension46:n.gtmShoppingCartViewModel.mustPickUp,dimension48:n.gtmShoppingCartViewModel.sellerLocation,dimension49:n.gtmShoppingCartViewModel.freeShipping}]}}};n.cartId>0&&(t.cartId=n.cartId),dataLayer.push(t)}}},ShoppingCartItemRepository=function(){var n=this,t=new GtmShoppingCartRepository;n.prototype=new BaseRepository("/API/Ajax/ShoppingCart/"),n.handlers={add:"AddToShoppingCart.ashx",update:"UpdateShoppingCartItemQuantity.ashx",remove:"RemoveFromShoppingCart.ashx",getDetails:"GetCartDetails.ashx",updateShipping:"UpdateShoppingCartItemShipping.ashx",updatePromotionalShipping:"UpdatePromotionalShipping.ashx"},n.removeItemFromCart=function(i,r,u){n.prototype.post(n.handlers.remove,{cartItemId:i.cartItemId(),listingId:i.listingId()},function(n){r(n,i),t.pushRemoveFromCartToDataLayer(i)},function(n){u(n)})},n.updateItemQuantityInCart=function(t,i,r){n.prototype.post(n.handlers.update,{cartItemId:t.cartItemId(),listingId:t.listingId(),quantity:t.quantity()},function(n){i(n)},function(n){r(n)})},n.updateShoppingCartItemShipping=function(t,i,r,u){n.prototype.post(n.handlers.updateShipping,{cartItemId:t.cartItemId(),listingId:t.listingId(),quantity:t.quantity(),shippingPrice:i.value.price(),shippingDetails:i.value.description()},function(n){r(n,t)},function(n){u(n,t)})},n.updatePromotionalShipping=function(t,i,r,u){n.prototype.post(n.handlers.updatePromotionalShipping,{sellerId:t,shippingPrice:i.value.price(),shippingDetails:i.value.description()},function(n){r(n,i)},function(n){u(n)})},n.addItemToCart=function(i,r,u,f){var e=TradeMe.getParameterByName("rsqid");n.prototype.post(n.handlers.add,{id:i,quantity:r,referringSqid:e},function(n){u(n),t.pushAddToCartToDataLayer(n)},function(n){f(n)})},n.undoRemoveItemFromCart=function(i,r,u,f){n.prototype.post(n.handlers.add,{id:i,quantity:r,returnItem:!0},function(n){u(n),t.pushAddToCartToDataLayer(n)},function(n){f(n)})},n.getDetails=function(t){n.prototype.getCache(n.handlers.getDetails,!1,function(n){t(n)})}},ShoppingCartItemGroupViewModel=function(n,t,i,r){var u=this;u.deliveryAddressViewModel=r,ko.mapping.fromJS(n,{cartItems:{create:function(n){return new ShoppingCartItemViewModel(n.data,t,i,r)}},shippingPromotion:{create:function(i){return new ShippingPromotionViewModel(i.data,u,t,n.sellerId)}}},u),u.memberListingLink=ko.observable("/Members/Listings.aspx?member="+u.sellerId()),u.memberFeedbackLink=ko.observable("/Members/Feedback.aspx?member="+u.sellerId()),u.aVLink=ko.observable("/mytrademe/addressverified/default.aspx"),u.subTotal=ko.computed(function(){var n=0;return ko.utils.arrayForEach(u.cartItems(),function(t){var i=parseFloat(t.subTotal());isNaN(i)||(n+=i)}),n}),u.shippingSubTotal=ko.computed(function(){var n=0;return ko.utils.arrayForEach(u.cartItems(),function(t){var i=parseFloat(t.shippingSubTotal());isNaN(i)||(n+=i)}),n}),u.hasExcludedItems=ko.computed(function(){return u.excludedItems().length>0}),u.items=ko.computed(function(){return ko.utils.arrayFilter(u.cartItems(),function(n){return!u.shippingPromotion.hasActiveShippingPromotion()||u.shippingPromotion.hasActiveShippingPromotion()&&!n.isExcludedFromCombinedShippingOffer()})}),u.excludedItems=ko.computed(function(){return ko.utils.arrayFilter(u.cartItems(),function(n){return u.shippingPromotion.hasActiveShippingPromotion()&&n.isExcludedFromCombinedShippingOffer()})})},ShoppingCartItemViewModel=function(n,t,i,r){var u=this,o,s,h;u.cartItemRepository=t,u.taxesViewModel=new TaxesViewModel(n.buyNowTaxAmountIfNzAddress,n.buyNowTaxAmountApplied,n.price,r),o=function(n){ko.mapping.fromJS(n,{price:{create:function(n){return ko.observable(n.data.toFixed(2))}},shippingOptionChoiceViewModel:{create:function(n){u.shippingOptionsViewModel===undefined?u.shippingOptionsViewModel=new ShoppingCartItemShippingOptionsViewModel(n.data,u,u.taxesViewModel):u.shippingOptionsViewModel.updateShippingOptions(n.data)}}},u)},o(n),u.isRemoving=ko.observable(!1),u.hasBeenRemoved=ko.observable(!1),u.hadErrorBefore=ko.observable(!1),u.listingLink=ko.observable("/Browse/Listing.aspx?id="+u.listingId()),u.relistingLink=ko.observable("/Browse/Listing.aspx?id="+u.relistedItemId());var c=function(){i&&i()},f=function(){location.href="/Members/Login.aspx?url="+location.pathname},l=function(n){e(n.itemError),o(n),u.shippingOptionsViewModel.resetShippingOptions(),n.itemError.hasFailed||(u.hasBeenRemoved(!1),u.isRemoving(!1))},a=function(n){location.href=n.redirectLocation},v=function(n){u.hasBeenRemoved(!0),e(n)},e=function(n){n.hasFailed&&n.redirectToShoppingCart&&n.errorLevel===1&&n.redirectLocation!==undefined?a(n):(u.hasBeenRemoved()||(u.itemError.hasFailed(n.hasFailed),u.itemError.errorLevel(n.errorLevel),u.itemError.errorMessage(n.errorMessage)),c())};u.updateItemShipping=function(n){u.hasBeenRemoved()||u.cartItemRepository.updateShoppingCartItemShipping(u,n,e,f)},u.removeItem=function(n){n.isRemoving(!0),n.shippingOptionsViewModel.showShippingOptions(!1),u.hadErrorBefore(n.hasExceptionError()),t.removeItemFromCart(n,v,f)},u.undoRemove=function(){u.hasBeenRemoved()&&u.cartItemRepository.undoRemoveItemFromCart(u.listingId(),u.quantity(),l,f)},s=function(n,t){var i=isNaN(parseInt(t))?0:parseInt(t);i!==n.quantity()&&(n.quantity(i),u.cartItemRepository.updateItemQuantityInCart(n,e,f))},h=function(){return!u.isMql()&&u.quantity()>1},u.price=ko.computed(function(){return u.taxesViewModel.priceIncTax()}),u.hasErrorFromServerOnly=ko.computed(function(){return!u.hadErrorBefore()&&u.hasExceptionError()}),u.hasVariants=ko.computed(function(){return u.variantDescriptors().length>0}),u.hasTaxes=ko.computed(function(){return u.showTaxes}),u.hasShippingPrice=ko.computed(function(){return u.shippingSubTotal()>0}),u.shippingSubTotal=ko.computed(function(){if(u.hasExceptionError()||u.hasBeenRemoved())return 0;var n=u.shippingOptionsViewModel.selectedShippingMethod();return n===null?0:n.isFlatRateShipping()?n.price():n.price()*u.quantity()}),u.subTotal=ko.computed(function(){return u.hasExceptionError()||u.hasBeenRemoved()?0:u.price()*u.quantity()}),u.hasExceptionError=ko.computed(function(){return u.itemError.errorLevel()===1}),u.hasWarningError=ko.computed(function(){return u.itemError.errorLevel()===2}),u.hasAnyError=ko.computed(function(){return u.hasWarningError()||u.hasExceptionError()}),u.hasClosingMessage=ko.computed(function(){return u.closingMessage().length>0}),u.showQuantity=ko.computed(function(){return h()||u.isMql()}),u.adjustableQuantity=ko.computed({read:function(){return u.quantity()},write:function(n){s(u,n)}}).extend({throttle:300}),u.hasRelistedLink=ko.computed(function(){return u.relistedItemId()!=0&&u.hasExceptionError()})},ShoppingCartItemShippingOptionsViewModel,TaxesViewModel,ShippingPromotionViewModel,ShippingOptionsViewModel,ShippingOptionViewModel,ValidationErrorsViewModel,ValidatorViewModel,CarouselViewModel,DeliveryAddressViewModel;ShoppingCartItemShippingOptionsViewModel=function(n,t,i){var r=this,f=t,h={checked:"",isSelected:!1,isUnselectedOption:!0,value:{description:"Select shipping",price:0,id:-1,isPickup:!1}},o="I intend to pick-up";r.taxesViewModel=i,r.unselectedObservable=new ShippingOptionViewModel(h,n.isFlatShippingCharge,t.quantity,function(){return!1},i);var u=function(n){return n===null||n===undefined},e=function(){var n=ko.utils.arrayFirst(r.shippingChoices(),function(n){return n.isSelected()});return u(n)?r.unselectedObservable:n},s=function(n){ko.mapping.fromJS(n,{shippingChoices:{create:function(r){return new ShippingOptionViewModel(r.data,n.isFlatShippingCharge,t.quantity,function(){return!1},i)}},validationErrorsViewModel:{create:function(n){return new ValidationErrorsViewModel(n.data)}}},r),e()===r.unselectedObservable&&r.shippingChoices.unshift(r.unselectedObservable)};s(n),r.cartItemId=ko.computed(function(){return f.cartItemId()}),r.disabledShippingSelection=ko.observable(!1),r.selectedShippingMethod=ko.observable(e()).extend({validate:function(){return r.validationErrorsViewModel.getValidationResult([r.validationErrorsViewModel.errorTypes.shippingOptionInvalid])}}),r.resetShippingOptions=function(){r.selectedShippingMethod(e())},r.shippingMethodChange=function(){if(u(r.selectedShippingMethod()))f.updateItemShipping(r.unselectedObservable);else{var n=ko.utils.arrayFirst(r.shippingChoices(),function(n){return n.completeDescription()===r.unselectedObservable.completeDescription()});n&&r.shippingChoices.shift(),f.updateItemShipping(r.selectedShippingMethod())}},r.showShippingOptions=ko.observable(!1),r.setShippingPromotion=function(n,t){f.isExcludedFromCombinedShippingOffer()||(r.disabledShippingSelection(n),n?(r.showShippingOptions(!1),u(t)||r.selectedShippingMethod(t)):r.isShippingSelectable()||e()!==r.unselectedObservable||f.hasExceptionError()||r.shippingChoices()[0].completeDescription()===o||(r.selectedShippingMethod(r.shippingChoices()[0]),f.updateItemShipping(r.selectedShippingMethod())))},r.updateShippingOptions=function(n){s(n)},r.hasShippingSelected=ko.computed(function(){var n=r.selectedShippingMethod();return u(n)?!1:!n.isUnselectedOption()}),r.isEveryShippingChoiceFree=ko.computed(function(){var n=ko.utils.arrayFirst(r.shippingChoices(),function(n){return n.price()>0});return u(n)}),r.showSelectedShippingOptionSubTotal=ko.computed(function(){var n=r.selectedShippingMethod();return u(n)?0:n.value&&n.price()>0}),r.isShippingSelectable=ko.computed(function(){var t=1,i=ko.utils.arrayFirst(r.shippingChoices(),function(n){return n.completeDescription()===r.unselectedObservable.completeDescription()}),n;if(i&&(t=2),n=r.shippingChoices().length>t,!n&&i){if(r.shippingChoices()[1].completeDescription()===o)return!0;r.shippingChoices.shift()}return n}),r.toggleShowShippingOptions=function(){r.disabledShippingSelection()||r.showShippingOptions(!r.showShippingOptions())},r.selectedShippingOptionId=ko.computed(function(){var n=r.selectedShippingMethod();return u(n)?r.unselectedObservable.value.id():n.value.id()}),r.selectedShippingOptionSubTotal=ko.computed(function(){var n=r.selectedShippingMethod();return u(n)?0:n.isFlatRateShipping()?n.price():n.price()*t.quantity()})},TaxesViewModel=function(n,t,i,r){var u=this;u.deliveryAddressViewModel=r,u.price=i,u.buyNowTaxAmountIfNzAddress=n,u.buyNowTaxAmountApplied=t,u.buyNowPriceExclusive=t?i-n:i,u.showGST=ko.computed(function(){var t,n;return u.buyNowTaxAmountIfNzAddress===0?!1:u.deliveryAddressViewModel===undefined?u.buyNowTaxAmountApplied:(t=u.deliveryAddressViewModel.selectedDeliveryAddressId(),t&&(n=ko.utils.arrayFirst(u.deliveryAddressViewModel.deliveryAddressProfiles(),function(n){var i=n.value.deliveryProfileId.value();return i!==null&&i!==undefined?i.toString()===t.toString():!1})),n===null||n===undefined)?u.buyNowTaxAmountApplied:n.value.physicalAddress.country()==="New Zealand"}),u.priceIncTax=ko.computed(function(){return u.buyNowTaxAmountIfNzAddress===0?u.price:u.showGST()?u.buyNowPriceExclusive+u.buyNowTaxAmountIfNzAddress:u.buyNowPriceExclusive})},ShippingPromotionViewModel=function(n,t,i,r){var u=this,h,f;u.sellerGroup=t,ko.mapping.fromJS(n,{},u),u.userHasOverridenPickupAll=ko.observable(u.haveChosenPickupForAllItems()),u.showPromotionInformation=ko.observable(!1),u.isPickUpSelectedForAllItems=ko.observable(u.haveChosenPickupForAllItems()),u.userHasSelectedAPromotionOffer=ko.observable(!1),u.haveAllCartItemsGotPickUpOption=ko.observable(u.haveAllItemsGotPickUpOption());var c={checked:"",isSelected:!1,isUnselectedOption:!0,value:{description:"Free shipping within New Zealand",price:0,id:3,isPickup:!1}},l={checked:"",isSelected:!1,isUnselectedOption:!0,value:{description:"I intend to pick-up",price:0,id:0,isPickup:!1}},e=new ShippingOptionViewModel(c,!1,function(){return 1},function(){return!1}),o=new ShippingOptionViewModel(l,!1,function(){return 1},function(){return!1}),a=function(n){return n<=0&&u.hasActiveShippingPromotion()},v=function(){var n=u.isPickUpSelectedForAllItems()?o:e;ko.utils.arrayForEach(u.sellerGroup.items(),function(t){t.shippingOptionsViewModel.setShippingPromotion(!0,n)})},y=function(){ko.utils.arrayForEach(u.sellerGroup.items(),function(n){n.shippingOptionsViewModel.setShippingPromotion(!1)})},s=function(){var n=ko.utils.arrayFirst(u.sellerGroup.items(),function(n){if(n.hasBeenRemoved())return!1;var t=ko.utils.arrayFirst(n.shippingOptionsViewModel.shippingChoices(),function(n){return n.value.id()===2});return t===null});return n===null},p=function(){location.href="/Members/Login.aspx?url="+location.pathname},w=function(n,t){ko.utils.arrayForEach(u.sellerGroup.items(),function(n){n.hasBeenRemoved()||n.shippingOptionsViewModel.selectedShippingMethod(t)})};u.allItemsHavePickUpOption=ko.computed(function(){return s()}),u.hasQualifiedForPromotion=ko.computed(function(){var t=u.thresholdType()===u.shippingPromotionThresholdTypes.price()?u.priceForPromotion():u.itemsForPromotion(),n=a(t);return n?(v(),u.userHasOverridenPickupAll()&&(s()||u.isPickUpSelectedForAllItems(!1))):(u.isPickUpSelectedForAllItems(!1),y()),u.showPromotionInformation(!1),n}),u.showPickUpCheckBox=ko.computed(function(){return u.hasQualifiedForPromotion()&&u.allItemsHavePickUpOption()}),u.hasNotQualifiedForPromotion=ko.computed(function(){return!u.hasQualifiedForPromotion()}),u.hasActiveShippingPromotion=ko.computed(function(){return u.isActive()&&u.thresholdType()!==u.shippingPromotionThresholdTypes.none()}),u.priceForPromotion=ko.computed(function(){var n=u.thresholdValue();return ko.utils.arrayForEach(u.sellerGroup.cartItems(),function(t){var i=parseFloat(t.subTotal());isNaN(i)||t.hasBeenRemoved()||t.hasExceptionError()||t.isExcludedFromCombinedShippingOffer()||(n-=i)}),n}),u.itemsForPromotion=ko.computed(function(){var n=u.thresholdValue();return ko.utils.arrayForEach(u.sellerGroup.cartItems(),function(t){var i=parseFloat(t.subTotal());isNaN(i)||t.hasBeenRemoved()||t.hasExceptionError()||t.isExcludedFromCombinedShippingOffer()||(n-=t.quantity())}),n}),u.isPromotionTypePrice=ko.computed(function(){return u.thresholdType()===u.shippingPromotionThresholdTypes.price()}),u.isPromotionTypeItem=ko.computed(function(){return u.thresholdType()===u.shippingPromotionThresholdTypes.item()}),u.toggleShowPromotionInformation=function(){u.showPromotionInformation(!u.showPromotionInformation())},u.setCombinedShippingOnAllItems=function(){u.userHasOverridenPickupAll(!0);var n=u.isPickUpSelectedForAllItems()?o:e;return i.updatePromotionalShipping(r,n,w,p),!0};var b=" from this seller to qualify for free shipping.",k="Add {number} {selected}item{s}",d="Spend {money} on {selected}items",g="Congratulations, you have qualified for free shipping from this seller.";u.promotionMessage=ko.computed(function(){if(u.hasQualifiedForPromotion())return g;var n=u.isPromotionTypePrice()?d:k,t=u.hasExcludedListings()?"selected ":"";return n=n.replace("{s}",u.itemsForPromotion()<=1?"":"s"),n=u.isPromotionTypeItem()?n.replace("{number}",h(u.itemsForPromotion())):n.replace("{money}",f("$"+u.priceForPromotion().toFixed(2))),n=n.replace("{selected}",t),n+b}),h=function(n){var t=n,i=["none","one","two","three","four","five","six","seven","eight","nine"];return n<10&&(t=i[n]),f(t)},f=function(n){var t=ko.utils.arrayFirst(u.sellerGroup.cartItems(),function(n){return!n.hasBeenRemoved()&&!n.isExcludedFromCombinedShippingOffer()&&!n.hasExceptionError()});return t!==null&&t!==undefined&&(n+=" more"),n}},ShippingOptionsViewModel=function(n,t,i,r,u){var f=this,e,o;f.showTyreFittingServiceOption=r.isEnabled&&!r.unableToRetrieveInstallers,f.pricePerTyre=r.pricePerTyre,f.useTyreFittingService=ko.observable(n.useTyreFittingService),f.useTyreFittingService.subscribe(function(n){n&&f.selectedShippingOption(e)}),f.loyaltyPurchaseViewModel=t,f.taxesViewModel=u,f.shouldApplyLoyaltyShipping=ko.computed(function(){return f.loyaltyPurchaseViewModel.listingHasLoyaltyShipping||f.loyaltyPurchaseViewModel.isAnyOptionSelected()}),ko.mapping.fromJS(n,{shippingChoices:{create:function(t){return new ShippingOptionViewModel(t.data,n.isFlatShippingCharge,i,f.shouldApplyLoyaltyShipping,u)}},validationErrorsViewModel:{create:function(n){return new ValidationErrorsViewModel(n.data)}}},f),e={isFlatRateShipping:ko.observable(f.isFlatShippingCharge()),value:{price:ko.observable(0),id:ko.observable(-1),isPickup:ko.observable(!1)},price:function(){return 0}},o=function(){var n=ko.utils.arrayFirst(f.shippingChoices(),function(n){return n.isSelected()});return n!==null&&n!==undefined?n:e},f.getAvailableShippingOptions=ko.computed(function(){var n=undefined;return f.shouldApplyLoyaltyShipping()?(n=f.shippingChoices().filter(function(n){return n.value.isPickup()||n.price()>0}),f.selectedShippingOption!==undefined&&f.selectedShippingOption().value.id()!==-1&&n.indexOf(f.selectedShippingOption())===-1&&f.selectedShippingOption(e)):n=f.shippingChoices,n}),f.selectOption=function(n){return f.useTyreFittingService(!1),ko.utils.arrayForEach(f.shippingChoices(),function(t){t.isSelected(t.value.id()===n.value.id())}),!0},f.selectedShippingOption=ko.observable(o()).extend({validate:function(){return f.validationErrorsViewModel.getValidationResult([f.validationErrorsViewModel.errorTypes.shippingOptionInvalid])}}),f.isEveryShippingChoiceFree=ko.computed(function(){var n=ko.utils.arrayFirst(f.shippingChoices(),function(n){return n.price()>0});return n===null||n===undefined}),f.showSelectedShippingOptionSubTotal=ko.computed(function(){return f.selectedShippingOption.isSelected&&f.selectedShippingOption.price>0}),f.highlightShippingOptions=ko.computed(function(){return f.shouldApplyLoyaltyShipping()&&f.selectedShippingOption().isSelected===undefined})},ShippingOptionViewModel=function(n,t,i,r,u){var f=this,e,o;ko.mapping.fromJS(n,{},f),f.taxesViewModel=u,f.isFlatRateShipping=ko.observable(t),f.isUnselectedOption=ko.observable(n.isUnselectedOption===!0),f.shouldApplyLoyaltyShipping=r,e=function(){return f.price()>0?"$"+f.price().toFixed(2):""},o=function(){return f.value.price()>0&&i()>1&&!f.isFlatRateShipping()?" per item - ":f.value.price()>0&&f.isFlatRateShipping()?" - ":f.value.price()>0?" - ":""},f.price=ko.computed(function(){return f.value.price()===0?0:f.taxesViewModel.showGST()?f.value.priceExclusiveOfTax()+f.value.taxAmount():f.value.priceExclusiveOfTax()}),f.completeDescription=ko.computed(function(){return f.shouldApplyLoyaltyShipping()?f.value.description():e()+o()+f.value.description()}),f.completeDescriptionText=ko.computed(function(){return f.shouldApplyLoyaltyShipping()?f.value.description():e()+o()+f.value.description()})},ValidationErrorsViewModel=function(n){var t=this,i,r;ko.mapping.fromJS(n,{copy:["errorLevels","errorTypes","validationErrors"]},t),i=function(n){return ko.utils.arrayFilter(t.validationErrors,function(t){return t.level===n})},t.hasFatalErrors=function(){return t.fatalErrors().length>0},t.hasWarnings=function(){return t.warningErrors().length>0},t.hasInputErrors=function(){return t.inputErrors().length>0},t.hasCancellationInfo=function(){return t.cancellationInfo().length>0},t.hasOnlyValidationErrors=function(){return t.isValid()&&!t.hasFatalErrors()},t.isValid=function(){return t.validationErrors.length===0},t.warningErrors=function(){return i(t.errorLevels.warning)},t.inputErrors=function(){return i(t.errorLevels.invalidInput)},t.fatalErrors=function(){return i(t.errorLevels.fatal)},t.cancellationInfo=function(){return i(t.errorLevels.cancelled)},r=function(n){return ko.utils.arrayFirst(t.validationErrors,function(t){return t.errorMessageType.value===n})},t.getErrorsOfType=function(n){var t=[];return ko.utils.arrayForEach(n,function(n){var i=r(n);i!==undefined&&i!==null&&t.push(i)}),t},t.getValidationResult=function(n){var i=t.getErrorsOfType(n);return i.length>0?new ValidationResult(!1,i[0].message):new ValidationResult(!0)}},ValidatorViewModel=function(n){var t=this,i=ko.observableArray(n),r;t.hasAnyFatalErrors=ko.computed(function(){var n=ko.utils.arrayFirst(i(),function(n){return n.hasFatalErrors()});return n!==undefined&&n!==null}),t.hasAnyWarnings=ko.computed(function(){var n=ko.utils.arrayFirst(i(),function(n){return n.hasWarnings()});return n!==undefined&&n!==null}),t.hasAnyInputErrors=ko.computed(function(){var n=ko.utils.arrayFirst(i(),function(n){return n.hasInputErrors()});return n!==undefined&&n!==null}),t.hasAnyInformationErrors=ko.computed(function(){var n=ko.utils.arrayFirst(i(),function(n){return n.hasCancellationInfo()});return n!==undefined&&n!==null}),t.areAllValid=ko.computed(function(){var n=ko.utils.arrayFirst(i(),function(n){return n.validationErrors.length>0});return n===undefined||n===null}),t.hasOnlyValidationErrors=ko.computed(function(){return!t.areAllValid()&&!t.hasAnyFatalErrors()&&!t.hasAnyInformationErrors()}),t.hasOnlyInformationErrors=ko.computed(function(){return!t.areAllValid()&&!t.hasAnyFatalErrors()&&!t.hasAnyWarnings()&&!t.hasAnyInputErrors()}),r=function(n){var t=ko.observableArray();return ko.utils.arrayForEach(i(),function(i){ko.utils.arrayPushAll(t(),n(i))}),t()},t.fatalTitle=ko.computed(function(){var n=ko.utils.arrayFirst(i(),function(n){return n.hasFatalErrors()});return n!==undefined&&n!==null?n.fatalErrors()[0].title:"Your payment was declined"}),t.firstFatalMessage=ko.computed(function(){var n=ko.utils.arrayFirst(i(),function(n){return n.hasFatalErrors()});return n!==undefined&&n!==null?n.fatalErrors()[0].message:""}),t.informationTitle=ko.computed(function(){var n=ko.utils.arrayFirst(i(),function(n){return n.hasCancellationInfo()});return n!==undefined&&n!==null?n.cancellationInfo()[0].title:"Your payment was declined"}),t.firstInfoMessage=ko.computed(function(){var n=ko.utils.arrayFirst(i(),function(n){return n.hasCancellationInfo()});return n!==undefined&&n!==null?n.cancellationInfo()[0].message:""}),t.inputErrors=ko.computed(function(){var t=r(function(n){return n.inputErrors()}),n=[];return t.filter(function(t){return n.indexOf(t.message)==-1&&n.push(t.message)})}),t.warnings=ko.computed(function(){return r(function(n){return n.warningErrors()})}),t.addValidationViewModel=function(n,t){ko.utils.arrayForEach(i(),function(n){if(n&&n.hasInputErrors()){var r=ko.utils.arrayFirst(n.inputErrors(),function(n){return t&&t.indexOf(n.errorMessageType.name)>-1});r&&i().splice($.inArray(n,i()),1)}}),n.hasInputErrors()&&i.push(n)}},CarouselViewModel=function(n){var t=this,r=n,i=ko.observable(0);t.left=ko.observable(0),t.hasNext=ko.computed(function(){return i()<r-1}),t.hasPrevious=ko.computed(function(){return i()>0}),t.clickNext=function(){if(t.hasNext()){var n=t.left();t.left(n-100),i(i()+1)}},t.clickPrevious=function(){if(t.hasPrevious()){var n=t.left();t.left(n+100),i(i()-1)}}},DeliveryAddressViewModel=function(n,t,i,r){function h(n){var t="invalidPhoneNumber",i=n.errorTypes[t];return n.validationErrors.some(function(n){return n.errorMessageType.value===i})}var u=this,f=1e3,e,o,s;ko.mapping.fromJS(n,{deliveryAddressProfiles:{create:function(n){return new DeliveryAddressProfilesViewModel(n.data)}},deliveryInstructions:{create:function(n){return ko.observable(n.data===null?"":n.data).extend({maxLength:f})}},deliveryInstructionsRemainingCharacters:{create:function(){return ko.computed(function(){var n=u.deliveryInstructions();return f-n.length})}},validationErrorsViewModel:{create:function(n){return new ValidationErrorsViewModel(n.data)}},phonePrefix:{create:function(n){return ko.observable(n.data===null?"":n.data)}},phoneNumber:{create:function(n){return ko.observable(n.data===null?"":n.data)}}},u),e=function(){var n=ko.utils.arrayFirst(u.deliveryAddressProfiles(),function(n){return n.isSelected()});return n!==undefined&&n!==null?n.value.deliveryProfileId.value().toString():-1},u.anyListingLiableForGST=ko.computed(function(){return r}),u.hasReachedCharacterLimit=ko.computed(function(){return u.deliveryInstructions().length>=f}),u.hasSavedDeliveryAddresses=ko.computed(function(){return u.deliveryAddressProfiles().length>0}),u.hasDeliveryInstructions=ko.computed(function(){return u.deliveryInstructionsRemainingCharacters()<f}),u.hasPhoneNumber=function(){return u.phoneNumber().length>0},u.showDeliveryInstructions=ko.observable(function(){return u.hasDeliveryInstructions()||u.hasPhoneNumber()||h(u.validationErrorsViewModel)}()),o=function(n,t,i){return new DeliveryAddressProfilesViewModel({checked:"",isSelected:!1,value:{buyerName:t.name(),dateCreated:"",deliveryProfileId:{value:n},messageToSeller:null,phoneNumber:{number:u.phoneNumber===undefined?"":u.phoneNumber(),prefix:u.phonePrefix===undefined?"":u.phonePrefix()},physicalAddress:{city:i?t.autoComplete.selectedSuggestion.city():t.city(),country:i?"New Zealand":t.country(),line1:i?t.autoComplete.selectedSuggestion.streetAddress1():t.address1(),line2:i?t.autoComplete.selectedSuggestion.streetAddress2():"",postcode:i?t.autoComplete.selectedSuggestion.postCode():t.postcode(),suburb:i?t.autoComplete.selectedSuggestion.suburb():t.suburb()},addressrightId:i?t.autoComplete.selectedSuggestion.addressrightId():"",autoCompletedAddressId:i?t.autoComplete.selectedSuggestion.addressId():""}})},s=function(n,t,i){u.deliveryAddressProfiles.push(o(parseInt(n),t,i))},u.addAddressViewModel=new AddAddressViewModel(n,s,{button:{text:"Add delivery address"}},!0,undefined,undefined,!0,t,i),u.selectedDeliveryAddressId=ko.observable(e()).extend({validate:function(){return u.validationErrorsViewModel.getValidationResult([u.validationErrorsViewModel.errorTypes.noDeliveryAddressForDelivery])}}),u.clearSelectedDeliveryAddress=function(){u.selectedDeliveryAddressId(-1),u.deliveryInstructions(""),u.phoneNumber(""),u.phonePrefix("")},u.selectedPhoneNumber=ko.observable(u.phoneNumber()).extend({validate:function(){return u.validationErrorsViewModel.getValidationResult([u.validationErrorsViewModel.errorTypes.noPhoneNumber,u.validationErrorsViewModel.errorTypes.invalidPhoneNumber])}}),u.toggleDeliveryInstructions=function(){u.showDeliveryInstructions(!u.showDeliveryInstructions())}}