jQuery(function(r){var n,l,_=window.wc_avatax_frontend;function a(){r("form.woocommerce-checkout .woocommerce-checkout-review-order-table tr.fee , div.cart-collaterals table.shop_table_responsive tr.fee").each(function(){-1!=r(this).html().indexOf("Retail Delivery Fee")&&r(this).remove()})}function t(){var a={action:"wc_avatax_revalidate_customer_address_on_addresschange",nonce:_.address_validation_nonce};r.ajax({type:"POST",async:!1,url:_.ajax_url,data:a,dataType:"json",success:function(a){console.log(a)}})}r(document).on("change","form.woocommerce-checkout .country_select",function(){var a;if(r("#wc-avatax-address-validation").hide(),r(this).is("#billing_country")){if(r("#ship-to-different-address-checkbox").is(":checked"))return;a=r('.wc_avatax_validate_address[data-address-type="billing"]')}else a=r('.wc_avatax_validate_address[data-address-type="shipping"]');-1<r.inArray(r(this).val(),null!=_?_.address_validation_countries:[])?r(a).show():r(a).hide()}),r(document).on("change","form.woocommerce-checkout #ship-to-different-address-checkbox",function(){r(this).is(":checked")&&"billing"!=_.tax_based_on?(r('.wc_avatax_validate_address[data-address-type="billing"]').hide(),r('.wc_avatax_validate_address[data-address-type="shipping"]').show()):r(this).is(":checked")&&"billing"==_.tax_based_on?(r('.wc_avatax_validate_address[data-address-type="billing"]').show(),r('.wc_avatax_validate_address[data-address-type="shipping"]').hide()):-1<r.inArray(r("#billing_country").val(),null!=_?_.address_validation_countries:[])&&r('.wc_avatax_validate_address[data-address-type="billing"]').show(),t()}),r(document).on("change","form.woocommerce-checkout #billing_wc_avatax_vat_id",function(){r(document.body).trigger("update_checkout")}),a(),r(document).on("updated_checkout",function(){a()}),r("form.woocommerce-checkout .country_select").change(),r("form.woocommerce-checkout #ship-to-different-address-checkbox").change(),r("form.woocommerce-checkout #billing_wc_avatax_vat_id").change(),r(document).on("click","#place_order",function(a){var e;0<r(".wc_avatax_validate_address").length&&(!l||null!=(null==(e=r("input#"+l.type+"_address_1").val())?void 0:e.trim())&&r("input#"+l.type+"_address_1").val()!=l[l.type+"_address_1"]||null!=(null==(e=r("input#"+l.type+"_address_2").val())?void 0:e.trim())&&r("input#"+l.type+"_address_2").val()!=l[l.type+"_address_2"]||null!=(null==(e=r("#"+l.type+"_city").val())?void 0:e.trim())&&r("#"+l.type+"_city").val().trim()!=l[l.type+"_city"]||null!=(null==(e=r("#"+l.type+"_state").val())?void 0:e.trim())&&r("#"+l.type+"_state").val().trim()!=l[l.type+"_state"]||null!=(null==(e=r("#"+l.type+"_country").val())?void 0:e.trim())&&r("#"+l.type+"_country").val().trim()!=l[l.type+"_country"]||null!=(null==(e=r("input#"+l.type+"_postcode").val())?void 0:e.trim())&&r("input#"+l.type+"_postcode").val().trim()!=l[l.type+"_postcode"])&&(r("#wc-avatax-address-validation").hide(),t())}),_.cart_contains_only_virtual_zero&&r(".wc_avatax_validate_address").hide(),r(".wc_avatax_validate_address").on("click",function(a){if(_.cart_contains_only_virtual_zero)return a.preventDefault(),!1;l=null,n=this,a.preventDefault();var t,e,d,o,c,s,i=r("form.woocommerce-checkout"),a=(1!==i.data()["blockUI.isBlocked"]&&i.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),t=r(this).data("address-type"),a=r("input#"+t+"_address_1").val(),e=r("input#"+t+"_address_2").val(),d=r("#"+t+"_city").val(),o=r("#"+t+"_state").val(),c=r("#"+t+"_country").val(),s=r("input#"+t+"_postcode").val(),{action:"wc_avatax_validate_customer_address",nonce:_.address_validation_nonce,type:t,address_1:a,address_2:e,city:d,state:o,country:c,postcode:s});r.ajax({type:"POST",url:_.ajax_url,data:a,dataType:"json",success:function(a){var e=!1;200===a.code?(r.each(a.address,function(a,e){r("#"+a).val(e).trigger("change")}),e='<div id="wc-avatax-address-validation" class="wc-avatax-address-validation-result wc-avatax-address-validation-success">'+_.i18n.address_validated+"</div>",(l=a.address).type=t):a.error&&(e=a.error,r(document.body).trigger("checkout_error")),e&&(r(".woocommerce-error, .woocommerce-message, .wc-avatax-address-validation-result").remove(),r(n).css("margin-bottom","20px").after(e)),i.unblock(),r(document.body).trigger("update_checkout")}})})});