(function(n){function r(i,r){n.ajax({type:"GET",url:t.url,data:r,success:function(r){r&&n(i).find(t.productBundleComponentVariantInfo).html(r.ContentHtml)}})}function i(i){var r=n(i).closest("form");n.ajax({type:"POST",url:t.bundlepriceurl,data:n(r).serialize(),success:function(t){t&&(n(i).empty(),n(i).append(t))}})}function u(i,r,u){n.ajax({type:"GET",url:t.validateProductTypeUrl,data:{productId:i,organisation:r},async:!1,success:function(n){u.text(n)}})}var t={productBundleAddToCartFormSelector:".js-bundle-add-to-cart-form",productBundleComponentVariantDropdownSelector:".js-product-bundle-component-variant-select",productBundleComponentVariantRadioSelector:".js-product-bundle-component-variant-radio",productBundleComponentVariantQuantitySelector:".quantity-select",productBundleComponentVariantQuantityTextField:".quantity-field",productBundleComponentSelector:".js-product-bundle-component",productBundleComponentVariantInfo:".js-product-bundle-component-variant-info",productBundleComponentAddButtonSelector:".product-bundle-component-add-button",productBundleComponentRecurringIntervalType:".js-variant-recurring-interval-type",productBundleComponentSellingMethod:".js-variant-selling-method",productBundleComponentVariantOptions:".js-variant-option",url:"/shoppingcart/ajaxgetbundlecomponentvariantdata",bundleDataUrl:"/shoppingcart/ajaxgetbundledata",availableStockUrl:"/Booking/AvailableSeats",bundlepriceurl:"/product/ajaxgetbundleprice",bundleModalFormButton:".btn-bundle-modal-ajax",bundleModalForm:".bundleModalAjax",validateProductTypeUrl:"",noSeatsAvailableString:"No seats available for this date",selectDateRequestString:"Please select a date"},f=function(f){function a(t,i){n(t).addClass("product-bundle-component-selected");n(i).html("Edit selection");var r=n(".product-bundle-component-selected").length;n("#productBundleComponentsAddedCount").html(r);s();p();y()}function o(){if(n("#bundleModal").length>0){var t=n(window).height()-120,i=n(window).width();i>1500?n(".bundle-modal-customise").css("max-height",t):n(".bundle-modal-customise").css("max-height","initial");equalHeights(n(".product-bundle-component h4"))}}function s(){n(".bundle-component-variant option, .color-select option, .size-select option").each(function(){(n(this).val()==="0"||n(this).val()==="")&&n(this).prop("disabled",!0)});n("#bundleAddToBasketError").hide();n(".product-bundle-modal-add-to-cart .product-bundle-add-to-cart-button").prop("disabled",!0);var t=n("#productBundleComponentsAddedCount").text(),i=n("#productBundleComponentsCount").text();n("#bundleConfirmChoices").is(":checked")?t===i?(n(".product-bundle-modal-add-to-cart .product-bundle-add-to-cart-button").removeAttr("disabled","disabled"),n("#bundleAddToBasketError").hide()):(n(".product-bundle-modal-add-to-cart .product-bundle-add-to-cart-button").attr("disabled","disabled"),n("#bundleAddToBasketError").show()):n(".product-bundle-modal-add-to-cart .js-add-to-cart-button").attr("disabled","disabled")}function v(){n(".bundle-modal-dialog-close").click(function(){n(".bundle-close-error").show();n(".bundle-modal-flex, .bundle-modal-dialog-close").hide()});n(".bundle-close-cancel").click(function(){n(".bundle-close-error").hide();n(".bundle-modal-flex, .bundle-modal-dialog-close").show()});n(".bundle-close").click(function(){location.reload()})}function y(){var t=0;n(".js-product-bundle-component-variant-info").each(function(){t+=n(this).find(".quantity-select").length>0?parseFloat(n(this).find("input[name$='VariantPriceDecimal']").val())*parseFloat(n(this).find(".quantity-select option:selected").text()):parseFloat(n(this).find("input[name$='VariantPriceDecimal']").val())*parseFloat(n(this).find(".quantity-field").val())});isNaN(t)&&(t=0);t=parseFloat(t).toFixed(2);n("#bundleTotalCost").html(t)}function e(t,i,r,u){n.ajax({type:"GET",url:r,data:i,success:function(i){i&&(n(t).empty(),n(t).append(i.ContentHtml),u&&(n(t).css("visibility","visible").css("display","none"),n(t).modal({backdrop:"static",keyboard:!1})),n(".js-whats-this").popover({html:!0,trigger:"hover focus"}))}})}function p(){var t="";n(".product-bundle-component-selected").each(function(){if(t+="<div class='bundle-list-item'>",t+="<strong>"+n(this).find("h4").text()+"<\/strong>",n(this).find(".bundle-component-variant").length>0&&(t+="<br />"+n(this).find(".bundle-component-variant option:selected").text()),n(this).find(".text-option-email").length>0){var i=n(this).find(".text-option-email-prompt").html();t+="<br />"+i+": "+n(this).find(".text-option-email").val()}n(this).find(".color-select").length>0&&(t+=" | "+n(this).find(".color-select option:selected").text());n(this).find(".size-select").length>0&&(t+=" | "+n(this).find(".size-select option:selected").text());n(this).find(".radio-group").length>0&&(t+=n(this).find(".radio-group input:checked").parent().parent().find(".radio-header").text(),n(this).find(".quantity-select").length>0&&(t+=" | "+n(this).find(".quantity-select option:selected").text()+" user(s)"));t+="<\/div>"});n("#productBundleCustomisationList").show();n("#productBundleCustomisationList").html(t)}function h(i,r){i!=null&&r!=null&&n.get(t.availableStockUrl,{variantId:i,attributeName:r},function(t){var r=n(".divStockAvailability_"+i);r.empty();r.append(t)})}t=n.extend(t,f);var c=[t.productBundleComponentVariantDropdownSelector,t.productBundleComponentVariantRadioSelector].join(),l=[t.productBundleComponentVariantQuantitySelector,t.productBundleComponentVariantQuantityTextField].join();n(document).on("change",l,function(){var r=parseInt(n(this).closest(t.productBundleAddToCartFormSelector).find("input[name$='AutoUpdateProductPrice']").val())==1,u=parseInt(n(this).closest(t.productBundleAddToCartFormSelector).find("input[name$='ProductIsDisplayedInPopup']").val())==1;r&&(u?i(n(this).closest(t.productBundleComponentSelector).parents(".bundle-modal-dialog").find(".bundle-price-container")):i(n(this).closest(t.productBundleComponentSelector).parents(".add-to-cart-wrap").find(".bundle-price-container")))});n(document).on("change",c,function(){var o=n(this).val(),u=n(this).closest(t.productBundleComponentSelector),c=n(u).attr("data-product-bundle-component-id"),l=n(u).attr("data-product-bundle-id"),a=n(u).attr("data-bundle-variant-id"),v=n(u).find("input[name='Template.Index']").val(),s=parseInt(n(this).closest(t.productBundleAddToCartFormSelector).find("input[name$='ProductIsDisplayedInPopup']").val())==1,y=parseInt(n(this).closest(t.productBundleAddToCartFormSelector).find("input[name$='AutoUpdateProductPrice']").val())==1,f,e;r(n(this).closest(t.productBundleComponentSelector),{variantId:o,productId:c,bundleID:l,bundleVariantID:a,componentIndex:v});y&&(s?i(n(this).closest(t.productBundleComponentSelector).parents(".bundle-modal-dialog").find(".bundle-price-container")):i(n(this).closest(t.productBundleComponentSelector).parents(".add-to-cart-wrap").find(".bundle-price-container")));s&&(f=n(".product-bundle-component-selected .product-bundle-add-to-cart-button"),n(f).length&&n(f).html("Edit Selection"));e=n(u).find(".color-select");n(e).length&&(n(u).find(".js-add-to-cart-errors").text(""),h(o,n(e).val()))});n(t.productBundleComponentAddButtonSelector).on("click",function(){var c=n(this).closest(t.productBundleComponentSelector),f=n(c).attr("data-product-bundle-component-id"),i=n(this).closest(t.productBundleComponentSelector).find(".js-add-to-cart-errors"),s,r,h;if(i.text(""),n(this).closest(t.productBundleComponentSelector).find(".text-option-email").length>0){var e=n(this).closest(t.productBundleComponentSelector).find(".text-option-email").val(),l=n("#requires-text-option-email-"+f).val(),o=n(this).closest(t.productBundleComponentSelector).find(".text-option-email-prompt").html();e===""&&l==="True"?i.text("Enter "+o.toLocaleLowerCase()+"!"):e.length>75?i.text(o+" is too long!"):u(f,e,i)}n(this).closest(t.productBundleComponentSelector).find(".color-select").length>0&&(s=n(this).closest(t.productBundleComponentSelector).find(".color-select option:selected").val(),r=n(this).closest(t.productBundleComponentSelector).find(".seats-available div").text(),r=r.replace("0 Seats Available","").trim(),s===""?i.text(t.selectDateRequestString):r===""&&i.text(t.noSeatsAvailableString));i.text()===""&&(h="#product-bundle-component-"+f,a(h,n(this)))});n(document).on("change",t.productBundleComponentSellingMethod,function(){var i=n(".bundle-product-desc").find(t.bundleModalForm),u=n(i).find("#ProductId").val(),f=n(this).val(),r=n('input[class="'+t.productBundleComponentVariantOptions.substring(1)+'"]:checked').val(),o=n("#variant-organisation-size-"+r).val(),s=n("#variant-recurring-interval-type-"+r).val(),h={productId:u,recurringIntervalTypeId:s,organisationSize:o,sellingMethod:f};e(i,h,t.bundleDataUrl)});n(document).on("change",t.productBundleComponentRecurringIntervalType,function(){var i=n(".bundle-product-desc").find(t.bundleModalForm),u=n(i).find("#ProductId").val(),f=n(this).val(),r=n('input[class="'+t.productBundleComponentVariantOptions.substring(1)+'"]:checked').val(),o=n("#variant-organisation-size-"+r).val(),s=n("#variant-selling-method-"+r).val(),h={productId:u,recurringIntervalTypeId:f,organisationSize:o,sellingMethod:s};e(i,h,t.bundleDataUrl)});n(document).on("change",t.productBundleComponentVariantOptions,function(){var o=parseInt(n(this).closest(t.productBundleAddToCartFormSelector).find("input[name$='ProductIsDisplayedInPopup']").val())==1,i=n(this).val();if(o){var r=n(".bundle-product-desc").find(t.bundleModalForm),u=n(r).find("#ProductId").val(),f={productId:u,variantId:i};e(r,f,t.bundleDataUrl)}else{var s=n("#variant-info-"+i),u=n("#ProductId").val(),f={productId:u,variantId:i},h=n(s).find(".add-to-cart-wrap");n(".variant-info").each(function(){n(this).find(".add-to-cart-wrap").empty()});e(h,f,t.bundleDataUrl)}});n(document).on("click",t.bundleModalFormButton,function(){var i=n(".bundle-product-desc").find(t.bundleModalForm),r=n(this).parent().find(".BundleId").val(),u=n(this).parent().find(".BundleVariantId").val(),f={productId:r,variantId:u};e(i,f,t.bundleDataUrl,!0)});n(document).on("change",".color-select",function(){n(this).closest(".js-product-bundle-component").find(".js-add-to-cart-errors").text("");var t=n(this).attr("id").replace("color-",""),i=n(this).val();h(t,i)});n(document).ready(function(){o();n(".btn-bundle-modal").click(function(){n("#bundleModal").css("visibility","visible").css("display","none");n("#bundleModal").modal({backdrop:"static",keyboard:!1})});s();n(".product-bundle-component-variant-format-type input").change(function(){n(".product-bundle-component-variant-format-type").removeClass("product-bundle-component-variant-format-type-selected");n(this).closest(".product-bundle-component-variant-format-type").addClass("product-bundle-component-variant-format-type-selected")});n("#bundleConfirmChoices").change(function(){s()});v()});n(window).on("load resize",function(){o()});n(window).resize(function(){o()})};n.bundleForm={initialize:f}})(adnsf$)