!function(a){a(document).ready(function(){function b(b){var c=a(".summary.entry-summary > .cart"),e=a(".devvn_prod_variable .cart",b);a("select, input, textarea",c).each(function(){var b=a(this).attr("name"),c=a(this).val();a('[name="'+b+'"]',e).val(c)}),e.trigger("check_variations"),d(b)}function c(b){var c=a(".summary.entry-summary > .cart"),e=a(".devvn_prod_variable .cart",b);a("select, input, textarea",e).each(function(){var b=a(this).attr("name"),d=a(this).val();a('[name="'+b+'"]',c).val(d)}),c.trigger("check_variations"),d(b)}function d(b){var c=a(".devvn_prod_variable .cart",b).data("product_variations"),d=a('.devvn_prod_variable input[name="quantity"]',b).val(),f=a('.devvn_prod_variable input[name="variation_id"]',b).val(),g=total=ship=0,h=a("#enable_ship",b).val()||0;h&&a(".popup_quickbuy_shipping_calc",b).length>0&&a('.popup_quickbuy_shipping_calc input[name="shipping_method[0]"]',b).length>0&&(ship=parseInt(a('.popup_quickbuy_shipping_calc input[name="shipping_method[0]"]:checked',b).data("cost")),ship||1!=a('.popup_quickbuy_shipping_calc input[name="shipping_method[0]"]',b).length||(ship=parseInt(a('.popup_quickbuy_shipping_calc input[name="shipping_method[0]"]',b).data("cost")))),c?a(c).each(function(a,b){b.variation_id==f&&b.variation_is_active&&b.variation_is_visible&&(g=b.display_price)}):g=a(".devvn_prod_variable",b).data("simpleprice"),total=g*d+ship,a(".popup_quickbuy_total_calc",b).html(e(total.toFixed(0),0,"",".")+" "+devvn_quickbuy_array.currency_format)}function e(a,b,c,d){b=devvn_quickbuy_array.num_decimals,c=devvn_quickbuy_array.price_decimal,a=(a+"").replace(/[^0-9+\-Ee.]/g,"");var e=isFinite(+a)?+a:0,f=isFinite(+b)?Math.abs(b):0,g="undefined"===typeof d?",":d,h="undefined"===typeof c?".":c,i="",j=function(a,b){var c=Math.pow(10,b);return""+Math.round(a*c)/c};return i=(f?j(e,f):""+Math.round(e)).split("."),i[0].length>3&&(i[0]=i[0].replace(/\B(?=(?:\d{3})+(?!\d))/g,g)),(i[1]||"").length0&&0==a("body .devvn_prod_variable .quantity.buttons_added .screen-reader-text").length&&a("body .devvn_prod_variable .quantity.buttons_added").append(''),a("body .devvn-popup-quickbuy").each(function(){var b=a(this),c=a(".devvn_cusstom_info",b);c.validate({rules:{"customer-name":{required:!0,maxlength:100},"customer-phone":{required:{depends:function(){return a(this).val(a.trim(a(this).val())),!0}},vietnamphone:!0},"customer-quan":{required:function(){var c=a("#require_district").val();return 1==c?!0:!1}},"customer-xa":{required:function(){var c=a("#require_village").val();return 1==c?!0:!1}},"customer-address":{required:function(){var c=a("#require_address").val();return 1==c?!0:!1}},"customer-email":{required:function(b){var c=a(b).data("required");return 1==c?!0:!1},customemail:!0}},messages:{"customer-name":"H\u1ecd t\xean l\xe0 b\u1eaft bu\u1ed9c","customer-phone":"S\u1ed1 \u0111i\u1ec7n tho\u1ea1i l\xe0 b\u1eaft bu\u1ed9c","customer-email":"\u0110\u1ecba ch\u1ec9 Email l\xe0 b\u1eaft bu\u1ed9c","customer-quan":"H\xe3y ch\u1ecdn qu\u1eadn/huy\u1ec7n","customer-xa":"H\xe3y ch\u1ecdn x\xe3/ph\u01b0\u1eddng/th\u1ecb tr\u1ea5n","customer-address":"H\xe3y nh\u1eadp \u0111\u1ecba ch\u1ec9 c\u1ee5 th\u1ec3 nh\u01b0 s\u1ed1 nh\xe0 ho\u1eb7c x\xf3m."},errorLabelContainer:a(".devvn_quickbuy_mess",c)});var e=a("#enable_ship",b).val()||0;if(a("#devvn_city",b).length>0){var f=!1,g=a("#prod_nonce",b).val(),h=0;a('button.single_add_to_cart_button[name="add-to-cart"]',b).length>0&&(h=parseInt(a('button.single_add_to_cart_button[name="add-to-cart"], thisForm').val())),a("#devvn_city",b).on("change",function(c){var i=c.val;if(i||(i=a("#devvn_city option:selected",b).val()),i&&!f){var j=a(".devvn_prod_variable .cart",b).serialize();a.ajax({type:"post",dataType:"json",url:devvn_quickbuy_array.ajaxurl,data:{action:"quickbuy_load_diagioihanhchinh",matp:i,getvalue:1,product_info:j,nonce:g,prod_id:h},context:this,beforeSend:function(){a(".popup-customer-info",b).addClass("popup_loading"),f=!0},success:function(c){if(a("#devvn_district",b).html(""),a("#devvn_ward",b).html(''),c.success){var g=c.data.list_district,h=new Option("Qu\u1eadn/huy\u1ec7n","");a("#devvn_district",b).append(h),a.each(g,function(c,d){var e=new Option(d.name,d.maqh);a("#devvn_district",b).append(e)}),e&&c.data.shipping&&a(".popup_quickbuy_shipping_calc",b).html(c.data.shipping)}f=!1,a(".popup-customer-info",b).removeClass("popup_loading"),d(b)}})}}),a("#devvn_district",b).length>0&&a("#devvn_district",b).on("change",function(c){var i=c.val;i||(i=a("#devvn_district option:selected",b).val());var j=a("#devvn_city option:selected",b).val();if(i&&!f){var k=a(".devvn_prod_variable .cart",b).serialize();a.ajax({type:"post",dataType:"json",url:devvn_quickbuy_array.ajaxurl,data:{action:"quickbuy_load_diagioihanhchinh",matp:j,maqh:i,getvalue:2,product_info:k,nonce:g,prod_id:h},context:this,beforeSend:function(){a(".popup-customer-info",b).addClass("popup_loading"),f=!0},success:function(c){if(a("#devvn_ward",b).html(""),c.success){var g=c.data.list_district,h=new Option("X\xe3/ph\u01b0\u1eddng","");a("#devvn_ward",b).append(h),a.each(g,function(c,d){var e=new Option(d.name,d.xaid);a("#devvn_ward",b).append(e)}),e&&c.data.shipping&&a(".popup_quickbuy_shipping_calc",b).html(c.data.shipping)}f=!1,a(".popup-customer-info",b).removeClass("popup_loading"),d(b)}})}}),a(window).on("load",function(){a("#devvn_city",b).trigger("change")}),a(".devvn_prod_variable .cart",b).on("change",function(){if(e){var f=a("#devvn_district option:selected",b).val(),i=a("#devvn_city option:selected",b).val(),j=a(".devvn_prod_variable .cart",b).serialize();a.ajax({type:"post",dataType:"json",url:devvn_quickbuy_array.ajaxurl,data:{action:"quickbuy_load_diagioihanhchinh",matp:i,maqh:f,getvalue:1,product_info:j,nonce:g,prod_id:h},context:this,beforeSend:function(){a(".popup-customer-info",b).addClass("popup_loading")},success:function(c){c.success&&e&&c.data.shipping&&a(".popup_quickbuy_shipping_calc",b).html(c.data.shipping),a(".popup-customer-info",b).removeClass("popup_loading"),d(b)}})}})}a("#devvn_cusstom_info, .devvn_prod_variable .cart, input.variation_id",b).on("change",function(){d(b)})})}a(".devvn_buy_now").on("click",function(){var e=a(this).data("id"),g=a("#popup_content_"+e),h=a(".devvn-popup-content_"+e).hasClass("ghn_not_loaded");h?a.ajax({type:"post",dataType:"html",url:devvn_quickbuy_array.ajaxurl,data:{action:"devvn_form_quickbuy",prodid:e},context:this,beforeSend:function(){a(this).addClass("popup_loading")},success:function(h){a(".devvn-popup-content_"+e).html(h),a(".popup_quickbuy_shipping_calc").html(""),f(),a("#devvn_city",g).trigger("change"),d(g),"undefined"!==typeof wc_add_to_cart_variation_params&&a(".variations_form").each(function(){a(this).wc_variation_form()}),a("#popup_content_"+e).bPopup({speed:450,transition:"slideDown",zIndex:9999999,closeClass:"devvn-popup-close",onOpen:function(){b(g)},onClose:function(){a(".devvn-popup-content_"+e).html(""),c(g)}}),a(this).removeClass("popup_loading")},error:function(){a(this).removeClass("popup_loading")}}):a("#popup_content_"+e).bPopup({speed:450,transition:"slideDown",zIndex:9999999,closeClass:"devvn-popup-close",onOpen:function(){b(g);var c=a("#enable_ship",g).val()||0;c&&a(".popup_quickbuy_shipping_calc",g).length>0&&a('.popup_quickbuy_shipping_calc input[name="shipping_method[0]"]',g).length<=0&&a("#devvn_city",g).trigger("change")},onClose:function(){c(g)}})}),a.validator.addMethod("vietnamphone",function(a){return/^0+(\d{9,10})$/.test(a)},"S\u1ed1 \u0111i\u1ec7n tho\u1ea1i kh\xf4ng \u0111\xfang \u0111\u1ecbnh d\u1ea1ng."),a.validator.addMethod("customemail",function(a){return""==a?!0:/^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(a)},"\u0110\u1ecbnh d\u1ea1ng email kh\xf4ng \u0111\xfang."),f();var g=!1;a("body").on("click",".devvn-order-btn",function(){var b=a(this).closest(".devvn-popup-quickbuy"),c=a(".devvn_cusstom_info",b),d=a('.devvn_prod_variable .cart input[name="variation_id"]',b).val();if("string"==typeof d&&"0"!=d&&""!=d||"undefined"==typeof d)if(a(".devvn_prod_variable .out-of-stock",b).length>0)alert(devvn_quickbuy_array.out_of_stock_mess);else{if(!c.valid())return;var e=a("#prod_nonce",b).val(),f=a("#prod_id",b).val(),h=a("#devvn_cusstom_info",b).serialize(),i=a(".devvn_prod_variable .cart",b).serialize();g||a.ajax({type:"post",dataType:"json",url:devvn_quickbuy_array.ajaxurl,data:{action:"devvn_quickbuy",prod_id:f,customer_info:h,product_info:i,nonce:e},context:this,beforeSend:function(){g=!0,a(".devvn-order-btn",b).addClass("loading")},success:function(c){c.success?c.data.gotothankyou&&c.data.thankyou_link?window.location.href=c.data.thankyou_link:a(".devvn-popup-content",b).html(c.data.content):alert(devvn_quickbuy_array.popup_error),g=!1,a(".devvn-order-btn",b).removeClass("loading")},error:function(){alert(devvn_quickbuy_array.popup_error),g=!1,a(".devvn-order-btn",b).removeClass("loading")}})}else alert(wc_add_to_cart_variation_params.i18n_make_a_selection_text);return!1})})}(jQuery);