jQuery(function(g){if("undefined"==typeof wc_checkout_params)return!1;var v={updateTimer:!(g.blockUI.defaults.overlayCSS.cursor="default"),dirtyInput:!1,selectedPaymentMethod:!1,xhr:!1,$order_review:g("#order_review"),$checkout_form:g("form.checkout"),init:function(){g(document.body).bind("update_checkout",this.update_checkout),g(document.body).bind("init_checkout",this.init_checkout),this.$checkout_form.on("click",'input[name="payment_method"]',this.payment_method_selected),g(document.body).hasClass("woocommerce-order-pay")&&this.$order_review.on("click",'input[name="payment_method"]',this.payment_method_selected),this.$checkout_form.attr("novalidate","novalidate"),this.$checkout_form.on("submit",this.submit),this.$checkout_form.on("input validate change",".input-text, select, input:checkbox",this.validate_field),this.$checkout_form.on("update",this.trigger_update_checkout),this.$checkout_form.on("change",'select.shipping_method, input[name^="shipping_method"], #ship-to-different-address input, .update_totals_on_change select, .update_totals_on_change input[type="radio"], .update_totals_on_change input[type="checkbox"]',this.trigger_update_checkout),this.$checkout_form.on("change",".address-field select",this.input_changed),this.$checkout_form.on("change",".address-field input.input-text, .update_totals_on_change input.input-text",this.maybe_input_changed),this.$checkout_form.on("keydown",".address-field input.input-text, .update_totals_on_change input.input-text",this.queue_update_checkout),this.$checkout_form.on("change","#ship-to-different-address input",this.ship_to_different_address),this.$checkout_form.find("#ship-to-different-address input").change(),this.init_payment_methods(),"1"===wc_checkout_params.is_checkout&&g(document.body).trigger("init_checkout"),"yes"===wc_checkout_params.option_guest_checkout&&g("input#createaccount").change(this.toggle_create_account).change()},init_payment_methods:function(){var e=g(".woocommerce-checkout").find('input[name="payment_method"]');1===e.length&&e.eq(0).hide(),v.selectedPaymentMethod&&g("#"+v.selectedPaymentMethod).prop("checked",!0),0===e.filter(":checked").length&&e.eq(0).prop("checked",!0),1'+e.messages+""):c.prepend(e),c.find(".input-text, select, input:checkbox").trigger("validate").blur(),v.scroll_to_notices()}v.init_payment_methods(),g(document.body).trigger("updated_checkout",[e])}else window.location.reload()}})}},submit:function(){v.reset_update_checkout_timer();var e=g(this);if(e.is(".processing"))return!1;!1!==e.triggerHandler("checkout_place_order")&&!1!==e.triggerHandler("checkout_place_order_"+v.get_payment_method())&&(e.addClass("processing"),1!==e.data()["blockUI.isBlocked"]&&e.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),g.ajaxSetup({dataFilter:function(e,t){if("json"!==t)return e;if(v.is_valid_json(e))return e;var o=e.match(/{"result.*}/);return null===o?console.log("Unable to fix malformed JSON"):v.is_valid_json(o[0])?(console.log("Fixed malformed JSON. Original:"),console.log(e),e=o[0]):console.log("Unable to fix malformed JSON"),e}}),g.ajax({type:"POST",url:wc_checkout_params.checkout_url,data:e.serialize(),dataType:"json",success:function(e){try{if("success"!==e.result)throw"failure"===e.result?"Result failure":"Invalid response";-1===e.redirect.indexOf("https://")||-1===e.redirect.indexOf("http://")?window.location=e.redirect:window.location=decodeURI(e.redirect)}catch(t){if(!0===e.reload)return void window.location.reload();!0===e.refresh&&g(document.body).trigger("update_checkout"),e.messages?v.submit_error(e.messages):v.submit_error('
'+wc_checkout_params.i18n_checkout_error+"
")}},error:function(e,t,o){v.submit_error('
'+o+"
")}}));return!1},submit_error:function(e){g(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),v.$checkout_form.prepend('
'+e+"
"),v.$checkout_form.removeClass("processing").unblock(),v.$checkout_form.find(".input-text, select, input:checkbox").trigger("validate").blur(),v.scroll_to_notices(),g(document.body).trigger("checkout_error")},scroll_to_notices:function(){var e=g(".woocommerce-NoticeGroup-updateOrderReview, .woocommerce-NoticeGroup-checkout");e.length||(e=g(".form.checkout")),g.scroll_to_notices(e)}},e={init:function(){g(document.body).on("click","a.showcoupon",this.show_coupon_form),g(document.body).on("click",".woocommerce-remove-coupon",this.remove_coupon),g("form.checkout_coupon").hide().submit(this.submit)},show_coupon_form:function(){return g(".checkout_coupon").slideToggle(400,function(){g(".checkout_coupon").find(":input:eq(0)").focus()}),!1},submit:function(){var t=g(this);if(t.is(".processing"))return!1;t.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var e={security:wc_checkout_params.apply_coupon_nonce,coupon_code:t.find('input[name="coupon_code"]').val()};return g.ajax({type:"POST",url:wc_checkout_params.wc_ajax_url.toString().replace("%%endpoint%%","apply_coupon"),data:e,success:function(e){g(".woocommerce-error, .woocommerce-message").remove(),t.removeClass("processing").unblock(),e&&(t.before(e),t.slideUp(),g(document.body).trigger("update_checkout",{update_shipping_method:!1}))},dataType:"html"}),!1},remove_coupon:function(e){e.preventDefault();var t=g(this).parents(".woocommerce-checkout-review-order"),o=g(this).data("coupon");t.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var c={security:wc_checkout_params.remove_coupon_nonce,coupon:o};g.ajax({type:"POST",url:wc_checkout_params.wc_ajax_url.toString().replace("%%endpoint%%","remove_coupon"),data:c,success:function(e){g(".woocommerce-error, .woocommerce-message").remove(),t.removeClass("processing").unblock(),e&&(g("form.woocommerce-checkout").before(e),g(document.body).trigger("update_checkout",{update_shipping_method:!1}),g("form.checkout_coupon").find('input[name="coupon_code"]').val(""))},error:function(e){wc_checkout_params.debug_mode&&console.log(e.responseText)},dataType:"html"})}},t={init:function(){g(document.body).on("click","a.showlogin",this.show_login_form)},show_login_form:function(){return g("form.login, form.woocommerce-form--login").slideToggle(),!1}},o={init:function(){g(document.body).on("click","a.woocommerce-terms-and-conditions-link",this.toggle_terms)},toggle_terms:function(){if(g(".woocommerce-terms-and-conditions").length)return g(".woocommerce-terms-and-conditions").slideToggle(function(){var e=g(".woocommerce-terms-and-conditions-link");g(".woocommerce-terms-and-conditions").is(":visible")?(e.addClass("woocommerce-terms-and-conditions-link--open"),e.removeClass("woocommerce-terms-and-conditions-link--closed")):(e.removeClass("woocommerce-terms-and-conditions-link--open"),e.addClass("woocommerce-terms-and-conditions-link--closed"))}),!1}};v.init(),e.init(),t.init(),o.init()});