"use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var Virtuemart=window.Virtuemart||{};!function(i,u){u.isUpdatingContent=!1,u.recalculate=!1,u.setBrowserState=!0,u.updateContent=function(t,e){if(u.isUpdatingContent)return!1;u.isUpdatingContent=!0;var n="&";-1==t.indexOf("&")&&-1==t.indexOf("?")&&(n="?"),t+=n+"tmpl=component&format=html&dynamic=1",i(this).vm2front("startVmLoading"),i.ajax({url:t,dataType:"html",success:function(t){var n=i(t).filter("title").text(),n=(i("title").text(n),i(t).find(u.containerSelector));(n=n.length?n:i(t).filter(u.containerSelector)).length&&(u.container.html(n.html()),u.updateCartListener(),u.updateDynamicUpdateListeners(),u.updateImageEventListeners&&u.updateImageEventListeners(),u.updateChosenDropdownLayout&&u.updateChosenDropdownLayout(),"function"==typeof vm2tabs&&vm2tabs(i("#ui-tabs .tabs")),u.recalculate)&&i("form.js-recalculate").each(function(){var t;i(this).find(".product-fields").length&&!i(this).find(".no-vm-bind").length&&(t=i(this).find('input[name="virtuemart_product_id[]"]').val(),u.setproducttype(i(this),t))}),u.isUpdatingContent=!1,e&&"function"==typeof e&&e(),i(this).vm2front("stopVmLoading")},error:function(t){alert("Error updating page"),u.isUpdatingContent=!1,i(this).vm2front("stopVmLoading")},statusCode:{404:function(){u.isUpdatingContent=!1,i(this).vm2front("stopVmLoading"),alert("page not found")}}}),u.isUpdatingContent=!1},u.updateCartListener=function(){void 0!==u.product&&u.product(i(".product")),i("body").trigger("updateVirtueMartProductDetail")},u.updL=function(t){t.preventDefault();t=i(this).attr("href");u.setBrowserNewState(t),u.updateContent(t)},u.upd=function(t){t.preventDefault();var n=this;setTimeout(function(){var t=i(n).attr("url");null!=(t="value"!=t&&("undefined"!==_typeof(t)&&!1!==t||"undefined"!==_typeof(t=i(n).closest("form").attr("action"))&&!1!==t&&"#"!==t)?t:i(n).val())&&(t=t.replace(/amp;/g,""),u.setBrowserNewState(t),u.updateContent(t))},50)},u.updForm=function(t){var n,e=i("#checkoutForm"),o=e.attr("action"),r=("undefined"!==_typeof(o)&&!1!==o||(o=i(this).attr("url"),console.log("my form no action url, try attr url ",e),"undefined"!==_typeof(o)&&!1!==o)||(o="index.php?option=com_virtuemart&view=cart",console.log("my form no action url, tried attr url ",o)),"tmpl=component"),a=o;-1==a.indexOf(r)&&(-1==a.indexOf(n="&")&&-1==a.indexOf("?")&&(n="?"),a+=n+r),e.submit(function(){return u.isUpdatingContent||(u.isUpdatingContent=!0,i(this).vm2front("startVmLoading"),i.ajax({type:"POST",url:a,dataType:"html",data:e.serialize(),success:function(t){void 0!==window._klarnaCheckout&&window._klarnaCheckout(function(t){t.suspend()});var n=i(t).find(u.containerSelector);(n=n.length?n:i(t).filter(u.containerSelector)).length&&(u.container.html(n.html()),u.updateImageEventListeners&&u.updateImageEventListeners(),u.updateChosenDropdownLayout)&&u.updateChosenDropdownLayout(),jQuery("body").trigger("updateVirtueMartCartModule"),u.setBrowserNewState(o),u.isUpdatingContent=!1,i(this).vm2front("stopVmLoading"),void 0!==window._klarnaCheckout&&window._klarnaCheckout(function(t){t.resume()})},error:function(t){alert("Error updating cart"),u.isUpdatingContent=!1,i(this).vm2front("stopVmLoading")},statusCode:{404:function(){u.isUpdatingContent=!1,i(this).vm2front("stopVmLoading"),alert("page not found")}}})),!1})},u.updFormS=function(t){u.updForm(),i("#checkoutForm").submit()},u.updDynFormListeners=function(){i("#checkoutForm").find("*[data-dynamic-update=1]").each(function(t,n){var e=n.nodeName;n=i(n),"BUTTON"===e&&(n[0].onchange=null,n.off("click",u.updForm),n.on("click",u.updForm)),n[0].onchange=null,n.off("click",u.updFormS),n.on("click",u.updFormS)})};var e=!(u.updateDynamicUpdateListeners=function(){i("*[data-dynamic-update=1]").each(function(t,n){var e=n.nodeName;n=i(n),"A"===e?(n[0].onclick=null,n.off("click",u.updL),n.on("click",u.updL)):(n[0].onchange=null,n.off("change",u.upd),n.on("change",u.upd))})}),n=!1;u.setBrowserNewState=function(n){if(!u.setBrowserState)return!1;if(void 0!==window.onpopstate){var t={url:n};e=!0;try{history.pushState(t,"",n)}catch(t){return window.location.href=n,!1}}},u.browserStateChangeEvent=function(t){(e||null!=t.state||n)&&(n=!0,t=null==t.state?window.location.href:t.state.url,u.updateContent(t))},window.onpopstate=u.browserStateChangeEvent}(jQuery,Virtuemart);