jQuery(function($){var nbt_ajaxcart_load={block:function($el){$el.block({message:null,overlayCSS:{background:'#fff',opacity:0.6}});},unblock:function($el){$el.unblock();}}
var nbt_ajaxcart={init:function(){$(window).load(function(){nbt_ajaxcart.load_cal();});if($('body').hasClass('single-product')){if($('[name="variation_id"]').length||$('[name="add-to-cart"]').length){$(document).on('submit','.single-product form.cart',this.add_to_cart);}}
$(document).on('added_to_cart',this.added_to_cart);$(document).on('click','.nbt-ajax-cart-icon',this.show_ajaxcart_popup);$(document).on('click','.nbt-ajax-cart-popup .remove',this.remove_to_cart);$(document).mouseup(function(e)
{if($(".nbt-ajax-cart").length){var container=$(".nbt-ajax-cart-popup");var icon=$(".nbt-ajax-cart-icon");if(!container.is(e.target)&&container.has(e.target).length===0&&!icon.is(e.target)&&icon.has(e.target).length===0)
{container.hide();container.removeClass('open');container.closest('.nbt-ajax-cart').removeClass('active');}}});$(document).on('click','.button.product_type_simple',this.trigger_add_to_cart);},trigger_add_to_cart:function(event){event.preventDefault();var $this=$(this);$this.block({message:null,overlayCSS:{background:'#fff',opacity:0.5,cursor:'none'}});var product_data=[];product_data.push({name:'action',value:'nbt_add_to_cart'});product_data.push({name:'add-to-cart',value:$this.attr('data-product_id')});product_data.push({name:'quantity',value:1});$.ajax({url:nbt_solutions.ajax_url,data:$.param(product_data),type:'POST',datatype:'json',success:function(response){$this.unblock();if(response.fragments){$(document.body).trigger('added_to_cart',[response.fragments]);if(response.fragments.ajax_completed!=undefined){Cookies.set('ajax_count',response.fragments.ajax_count);nbt_ajaxcart.notification(response.fragments.title);}else{alert('You can\'t add to cart this product!');}}else{alert('You can\'t add to cart this product!');}
$(".cart_list").mCustomScrollbar({theme:"dark"});},error:function(){alert('There was an error when processing data, please try again !');nbt_ajaxcart_load.unblock($li);}});},load_cal:function(){if($(".nbt-ajax-cart").length){var $width=$(window).width()-300;$('.nbt-ajax-cart').each(function(){var $wrap=$(this);var position=$wrap.offset();if($width<position.left){$wrap.find(".nbt-ajax-cart-popup").addClass('nbt-ajaxcart-right');$wrap.find(".nbt-ajax-cart-popup").css({right:'-20px'});}else{$wrap.find(".nbt-ajax-cart-popup").addClass('nbt-ajaxcart-left');$wrap.find(".nbt-ajax-cart-popup").css({left:0});}});}},show_ajaxcart_popup:function(){var $el=$(this).closest('.nbt-ajax-cart-icon').next();var $wrap=$(this).closest('.nbt-ajax-cart');if($el.hasClass('open')){$el.hide();$el.removeClass('open');$wrap.removeClass('active');}else{$el.show();$el.addClass('open');$wrap.addClass('active');nbt_ajaxcart.load_cal();$wrap.find(".cart_list").mCustomScrollbar({theme:"dark"});}},add_to_cart:function(event){if(nbt_ajaxcart_params.enable_ajax!='yes'){return;}
event.preventDefault();var product_data=$(this).serializeArray();var btn_submit=$(this).find('button[type="submit"]');if(btn_submit.attr('name')&&btn_submit.attr('name')=='add-to-cart'&&btn_submit.attr('value')){product_data.push({name:'add-to-cart',value:btn_submit.attr('value')});}
product_data.push({name:'action',value:'nbt_add_to_cart'});if(Cookies.get('ajax_count')==undefined){Cookies.set('ajax_count',nbt_ajaxcart_params.ajax_count);}
nbt_ajaxcart_load.block(btn_submit);$.ajax({url:nbt_ajaxcart_params.wc_ajax_url.toString().replace('%%endpoint%%','nbt_add_to_cart'),data:$.param(product_data),type:'POST',datatype:'json',success:function(response){if(response.fragments){$(document.body).trigger('added_to_cart',[response.fragments,btn_submit]);if(response.fragments.ajax_completed!=undefined){btn_submit.prop('disabled',false);nbt_ajaxcart_load.unblock(btn_submit);Cookies.set('ajax_count',response.fragments.ajax_count);nbt_ajaxcart.notification(response.fragments.title);}else{btn_submit.prop('disabled',true);nbt_ajaxcart_load.unblock(btn_submit);alert('You can\'t add to cart this product!');}}
$(".cart_list").mCustomScrollbar({theme:"dark"});},error:function(){alert('There was an error when processing data, please try again !');nbt_ajaxcart_load.unblock($li);}});},added_to_cart:function(event,fragments,btn_submit){},remove_to_cart:function(){var $this=$(this).closest('li');var $wrap=$(this).closest('.nbt-ajax-cart');nbt_ajaxcart_load.block($wrap.find('.nbt-ajax-cart-popup'));var product_data=[];product_data.push({name:'action',value:'nbt_remove_cart'});product_data.push({name:'product_id',value:$(this).attr('data-product_id')});product_data.push({name:'variation_id',value:$(this).attr('data-variation_id')});$.ajax({url:nbt_solutions.ajax_url,data:$.param(product_data),type:'POST',datatype:'json',success:function(response){if(response.fragments){$wrap.find('.nbt-ajax-cart-count, .counter-number').text(response.fragments.ajax_count);$wrap.find('div.nbt-ajax-cart-popup').replaceWith(response.fragments.ajax_popup);nbt_ajaxcart.load_cal();$wrap.find(".cart_list").mCustomScrollbar({theme:"dark"});}
nbt_ajaxcart_load.unblock($wrap.find('.nbt-ajax-cart-popup'));},error:function(){alert('There was an error when processing data, please try again !');nbt_ajaxcart_load.unblock();}});return false;},notification:function(content){$('.ajaxcart-notification').remove();$('body').append('<div id="growls" class="ajaxcart-notification default" style="top: '+nbt_ajaxcart_params.top_notification+'px;"><div class="growl growl-notice growl-medium"><div class="growl-message"><div class="growl-close">×</div>'+content+'</div></div>');$('.ajaxcart-notification').hide().show('slow').delay(2000).hide('slow');}}
nbt_ajaxcart.init();});
var x=false;jQuery(function($){var nbtcs_frontend={init:function(){$('.variations_form').addClass('swatches-support');$('.variations_form').on('click','.swatch',this.select_attributes);$('.variations_form').on('click','.reset_variations',this.reset_attributes);$(document).ajaxComplete(this.ajax_quick_view);$(document).ajaxStop(function(){x=false;});},ajax_quick_view:function(event,request,settings){if(!x&&typeof(settings.data)=="string"&&settings.data&&settings.data.includes("action=yith_load_product_quick_view")){nbtcs_frontend.init();x=true;}},select_attributes:function(){var selected=[];var $el=$(this);var attr=$el.closest('.nbtcs-swatches');var $select=attr.prev().find('select'),$nbtcs_swatches=$el.closest('.nbtcs-swatches'),attribute_name=$select.data('attribute_name')||$select.attr('name'),value=$el.attr('data-value');$select.trigger('focusin');if(!$select.find('option[value="'+value+'"]').length){$el.siblings('.swatch').removeClass('selected');$select.val('').change();$('.variations_form').trigger('tawcvs_no_matching_variations',[$el]);return;}
clicked=attribute_name;if(selected.indexOf(attribute_name)===-1){selected.push(attribute_name);}
if($el.hasClass('swatch-radio')){$select.val(value);}else{if($el.hasClass('selected')){$select.val('');$el.removeClass('selected');delete selected[selected.indexOf(attribute_name)];}else{$el.addClass('selected').siblings('.selected').removeClass('selected');$select.val(value);}}
$select.change();},select_attributes_radio:function(){var $el=$(this);alert(2);},reset_attributes:function(){$(this).closest('.variations_form').find('.swatch.selected').removeClass('selected');$(this).closest('.variations_form').find('[type="radio"]').prop('checked',false);selected=[];}}
nbtcs_frontend.init();});
jQuery(document).ready(function($){var x=false;var nbtou_load={block:function($el){$el.block({message:null,overlayCSS:{background:'#fff',opacity:0.6}});},unblock:function($el){$el.unblock();}}
var nbtfaq_js={init:function(){$(document).on('click','.nbt-faq-title',this.faq_triggle);},faq_triggle:function(e){e.preventDefault();if($(this).hasClass('active')){$(this).removeClass('active');$(this).closest('li').find('.nbt-faq-content').slideUp();}else{$(this).addClass('active');$(this).closest('li').find('.nbt-faq-content').slideDown();}}}
nbtfaq_js.init();});;(function($){$(document).ready(function(){"use strict";var items=$('.nbcs-list-items'),item=$('.nbcs-list-items li'),first_item=$('.nbcs-list-items li:first-child'),checkbox=items.find('input'),total_price_wrap=$('.nbcs-price-box'),total_price_class=total_price_wrap.find('.nbcs-display-total-price'),total_price_html=total_price_class.find('.amount');Number.prototype.format=function(n,x){var re='(\\d)(?=(\\d{'+(x||3)+'})+'+(n>0?'\\.':'$')+')';return this.toFixed(Math.max(0,~~n)).replace(new RegExp(re,'g'),'$1,');};var get_total=function(total){var html='';if(nb_fbt.currency_pos==='left'){html=nb_fbt.currency_symbol+total.format(2);}
else if(nb_fbt.currency_pos==='left_space'){html=nb_fbt.currency_symbol+' '+total.format(2);}
else if(nb_fbt.currency_pos==='right'){html=total.format(2)+nb_fbt.currency_symbol;}
else if(nb_fbt.currency_pos==='right_space'){html=total.format(2)+' '+nb_fbt.currency_symbol;}
return html;};checkbox.on('change',function(){var t=$(this),id=t.attr('id'),total_price_attr=total_price_class.attr('data-total-price'),product_price=t.attr('data-price'),to_show=[],checked=items.find('input:checked'),thumb=$('.nbcs-list-images li.nbcs-thumb[data-rel="'+id+'"]'),plus_icon=$('li.nbcs-plus-icon'),total=0;t.parents('li').toggleClass('unchecked');checked.each(function(i){to_show[i]=this.id;total+=parseFloat($(this).attr('data-price'));});total_price_class.attr('data-total-price',total);thumb.fadeToggle();if(to_show.length==0||to_show.length==1){plus_icon.fadeOut();}
else if(to_show.length==item.length){plus_icon.fadeIn();}
else if(id=='offeringID_0'){if(to_show[0]!=id){$('li.nbcs-plus-icon[data-rel="'+to_show[0]+'"]').fadeOut();}
else
{thumb.next(plus_icon).fadeIn();}}
else if(to_show[0]==id||to_show[0]==thumb.next(plus_icon).data('rel')){thumb.next(plus_icon).fadeToggle();}
else{thumb.prev(plus_icon).fadeToggle();}
total_price_html.html(get_total(total));var combox_checked=checked.length;if(combox_checked==0){total_price_wrap.hide();}
else{total_price_wrap.show();}
if(combox_checked<=3){total_price_wrap.removeClass('clear-price-box');}
else{total_price_wrap.addClass('clear-price-box');}});var variations_form=$('form.variations_form');if(variations_form.length==1)
{$(document).on('change','table.variations select',function(){var target=document.body;var config={childList:true,subtree:true,attributes:true,characterData:true};observer.observe(target,config);setTimeout(function(){observer.disconnect();},1000);});var variations_data=JSON.parse($('form.variations_form').attr('data-product_variations'));var observer=new MutationObserver(function(mutationRecords,observer){mutationRecords.forEach(function(mutation){var first_id=$('.variations tr:first-child select').attr('id');if(mutation.attributeName=='current-image'){var select_id=mutation.target[0].id,image_id=$('.variations_form').attr('current-image');if(select_id==first_id&&image_id){var new_variation_data={};$.each(variations_data,function(i){$.each(variations_data[i],function(key,val){if(key=='image_id'&&val==image_id){new_variation_data[i]=variations_data[i];}});});var new_thumb='',new_srcset='',new_price=0,new_price_html='',new_variation_id=0;$.each(new_variation_data,function(k){new_thumb=new_variation_data[k].image.thumb_src;new_srcset=new_variation_data[k].image.srcset;new_price=new_variation_data[k].display_price;new_price_html=new_variation_data[k].price_html;new_variation_id=new_variation_data[k].variation_id;});if(new_thumb!=''&&new_srcset!=''){$('.nbcs-list-images li:first-child a img').attr('src',new_thumb).attr('srcset',new_srcset);}
var total_price=total_price_class.attr('data-total-price'),first_combo_box=first_item.find('input[name="cb-item[]"]'),first_input=first_item.find('input[name="offeringID[]"]'),first_product_price=first_combo_box.attr('data-price'),first_product_price_html=first_item.find('.amount'),new_total_price=parseFloat(total_price)-parseFloat(first_product_price)+parseFloat(new_price);if(!first_item.hasClass('unchecked')){total_price_html.html(get_total(new_total_price));total_price_class.attr('data-total-price',new_total_price);}
first_combo_box.attr('data-price',new_price).val(new_variation_id);first_product_price_html.html(new_price_html);first_input.val(new_variation_id).removeClass().addClass('offeringID-'+new_variation_id);}}});});}})}(jQuery));
jQuery(function($){var nb_checkout_load={block:function($el){$el.block({message:null,overlayCSS:{background:'#fff',opacity:0.6}});},unblock:function($el){$el.unblock();}}
var $supports_html5_storage=true,cart_hash_key=wc_cart_fragments_params.cart_hash_key;try{$supports_html5_storage=('sessionStorage'in window&&window.sessionStorage!==null);window.sessionStorage.setItem('wc','test');window.sessionStorage.removeItem('wc');window.localStorage.setItem('wc','test');window.localStorage.removeItem('wc');}catch(err){$supports_html5_storage=false;}
function set_cart_creation_timestamp(){if($supports_html5_storage){sessionStorage.setItem('wc_cart_created',(new Date()).getTime());}}
function set_cart_hash(cart_hash){if($supports_html5_storage){localStorage.setItem(cart_hash_key,cart_hash);sessionStorage.setItem(cart_hash_key,cart_hash);}}
var $fragment_refresh={url:wc_cart_fragments_params.wc_ajax_url.toString().replace('%%endpoint%%','get_refreshed_fragments'),type:'POST',success:function(data){if(data&&data.fragments){$.each(data.fragments,function(key,value){$(key).replaceWith(value);});if($supports_html5_storage){sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(data.fragments));set_cart_hash(data.cart_hash);if(data.cart_hash){set_cart_creation_timestamp();}}
$(document.body).trigger('wc_fragments_refreshed');}}};var nb_one_checkout={_init:function(){$(document).on('click','.nb-checkout-row .remove',this.remove_cart);$(document).on('click','.nb-checkout-row .restore-item',this.restore_item);$(document).on('change','.shop-table_responsive .input-text.qty',this.change_qty);$(document).on('click','.nb-qty-plus',nb_one_checkout.qty_plus);$(document).on('click','.nb-qty-minus',nb_one_checkout.qty_minus);this.woocommerce();},woocommerce:function(){$('.product-quantity .quantity').each(function(){$(this).append('<div class="qty-buttons"> <span class="quantity-icon nb-qty-plus"></span> <span class="quantity-icon nb-qty-minus"></span></div>');});},change_qty:function(){var qty=$(this).val();;nb_one_checkout.re_calculator(qty,$(this).closest('.cart_item').attr('id'));},qty_plus:function(){var parent=$(this).closest('.quantity');var qty=parseInt($('input.qty',parent).val())+1;$('input.qty',parent).val(qty);nb_one_checkout.re_calculator(qty,$(this).closest('.cart_item').attr('id'));},qty_minus:function(){var parent=$(this).closest('.quantity');if(parseInt($('input.qty',parent).val())>1){var qty=parseInt($('input.qty',parent).val())-1;$('input.qty',parent).val(qty);nb_one_checkout.re_calculator(qty,$(this).closest('.cart_item').attr('id'));}},refresh_cart_fragment:function(){$.ajax($fragment_refresh);},re_calculator:function(qty,id){nb_checkout_load.block($('.shop_table'));$.ajax({url:nbt_solutions.ajax_url,type:'POST',data:{'action':'nb_solution_change_qty','qty':qty,'cart_item_key':id},success:function(rs){if(rs.complete!=undefined){$('#'+id).find('.product-subtotal').html(rs.price);$('.cart-subtotal > td:last-child').html(rs.subtotal);$('.order-total > td:last-child').html(rs.total);nb_checkout_load.unblock($('.shop_table'));}else{nb_checkout_load.unblock($('.shop_table'));}
nb_one_checkout.refresh_cart_fragment();}});},remove_cart:function(e){e.preventDefault();nb_checkout_load.block($('.shop_table'));var cart_item_key=$(this).closest('tr').attr('id');$.ajax({url:nbt_solutions.ajax_url,type:'POST',data:{'action':'nb_solution_remove','cart_item_key':cart_item_key},success:function(rs){if(rs.complete!=undefined){if(rs.empty!=undefined){$('.nb-checkout-row').html('<div class="nb-checkout-col-12">'+rs.cart_template+'</div>');nb_one_checkout.refresh_cart_fragment();}else{$('#nb-checkout-cart').html(rs.cart_template);$('#message-nb-checkout').html('<div class="woocommerce-message">'+rs.message+'</div>');nb_one_checkout.re_calculator(0,cart_item_key);nb_one_checkout.woocommerce();$(document.body).trigger('wc_fragments_refreshed');}}else{nb_checkout_load.unblock($('.shop_table'));}}});},restore_item:function(e){e.preventDefault();var cart_item_key=$(this).attr('data-id');$.ajax({url:nbt_solutions.ajax_url,type:'POST',data:{'action':'nb_solution_restore','cart_item_key':cart_item_key},success:function(rs){if(rs.complete!=undefined){$('#nb-checkout-cart').html(rs.cart_template);$('#message-nb-checkout').html('<div class="woocommerce-message">'+rs.message+'</div>');}},complete:function(){}});}}
if($('body').hasClass('nb-woocommerce-checkout')){nb_one_checkout._init();}});
jQuery(document).ready(function($){var x=false;var nbtpdf_js={init:function(){$(document).on('click','.btn-pdf-preview',this.save_id);},save_id:function(){if($(this).hasClass('active')){$(this).next().slideUp();$(this).removeClass('active');}else{$(this).next().slideDown();$(this).addClass('active');}}}
nbtpdf_js.init();});
jQuery(function($){var $el=$('.variations_form');var pm_load={block:function(){$el.block({message:null,overlayCSS:{background:'#fff',opacity:0.6}});},unblock:function(){$el.unblock();}}
var pm_frontend={init:function(){$(document).on('click','.pure-table .price',this.selected_price);$(document).on('change','table.un-variations tr:visible select',this.change_attr);this.autoload_pm();Tippy('.tippy',{animation:'scale',duration:200,arrow:true,position:'bottom'});},autoload_pm:function(){if($('#single-product_variations').length){var $product_variations=$('#single-product_variations').attr('data-product_variations');var $product_attr=$('#single-product_variations').attr('data-attr');var $product_count=$('#single-product_variations').attr('data-count');$.ajax({url:nbt_solutions.ajax_url,data:{action:'pm_autoload',security:$('[name="security"]').val(),product_id:$('[name="add-to-cart"]').val(),un_attr:$.parseJSON($product_variations),attr:$.parseJSON($product_attr),count:$product_count,suffix:$('.un-variations').attr('data-suffix')},type:'POST',success:function(response){pm_load.unblock();$('body').append(response);},error:function(){}});}},change_attr:function(){var $this=$(this).val();pm_load.block();var $total=$('table.un-variations tr:visible select').length;var optionVal={};var pmid='';var count=0;$('table.un-variations tr:visible select').each(function(index){if($(this).val()){var $id=$(this).closest('select').attr('id');var $val=$(this).val();optionVal[$id]=$val;pmid+=$id+$val;count+=1;}});if($this&&$total==count){if($('#wppm-'+md5(pmid)).length){var $autoload_pm=$('#wppm-'+md5(pmid)).html();setTimeout(function(){pm_load.unblock();$('.load-table-pm').html($autoload_pm);Tippy('.tippy',{animation:'scale',duration:200,arrow:true,position:'bottom'});},500);console.log('Có');}else{console.log('Không');$.ajax({url:nbt_solutions.ajax_url,data:{action:'pm_load_matrix',security:$('[name="security"]').val(),product_id:$('[name="add-to-cart"]').val(),attr:optionVal},type:'POST',datatype:'json',success:function(response){var rs=JSON.parse(response);if(rs.complete!=undefined){$('.price_attr').remove();$('.table-responsive, [name="price_attr"], [name="security"]').remove();$('.load-table-pm').html(rs.return);Tippy('.tippy',{animation:'scale',duration:200,arrow:true,position:'bottom'});}
pm_load.unblock();},error:function(){alert('There was an error when processing data, please try again !');}});}}else{$('.table-responsive').remove();pm_load.unblock();}},selected_price:function(){var price=$(this).html();var total_length=$("form.variations_form select").length;if($('.pure-table td.price').not($(this)).hasClass('selected')){$('.pure-table td.price.selected').removeAttr('style');}
$('.pure-table .price').removeClass('selected');$(this).addClass('selected');var $attr=$(this).attr('data-attr');$.each(JSON.parse($attr),function(key,pm){$('#'+pm.name).val(pm.value);$('#nbtcs-'+pm.name+' .swatch').removeClass('selected');$('#nbtcs-'+pm.name+' [data-value="'+pm.value+'"]').addClass('selected');});var stuff=[];$("form.variations_form select").each(function(index){if($(this).is('[data-attribute_name]')){$(this).addClass('pm-select');if($(this).val()){stuff.push($(this).val());}}});$('form.variations_form select.pm-select').trigger('change');if(nbt_solutions.is_scroll){$('html,body').animate({scrollTop:$("form.variations_form").find('[type="submit"]').offset().top-150},'slow');}}}
if($(".pure-table").length>0){pm_frontend.init();}});
jQuery(document).ready(function($){var x=false;var nbtou_load={block:function($el){$el.block({message:null,overlayCSS:{background:'#fff',opacity:0.6}});},unblock:function($el){$el.unblock();}}
var nbtou_js={init:function(){$(document).on('dragover','.nbt-upload-zone',this.dragover_files);$(document).on('dragleave','.nbt-upload-zone',this.dragleave_files);$(document).on('drop','.nbt-upload-zone',this.drop_files);$(document).on('click','.nbt-oupload-target',this.click_files);$(document).on('change','.nbt-upload-input',this.change_files);$(document).on('click','.nbt-icon-cancel',this.remove_files);$(document).on('click','.toggle-order-upload',this.toggle_order_upload);$(document).on('click','.nbt-ou-fast button',this.show_order_upload);if($('#nbt-order-upload').length>0){var useAjax=false===$('form.variations_form').data('product_variations');if(useAjax){$(document).ajaxComplete(function(event,xhr,options){if(typeof(options.url)=="string"&&options.url.includes("get_variation")){if(xhr.status==200){nbtou_js.change_variations_ajax();}}});}else{$(document).on('change','.variations select',this.change_variations);}}
if($('body').hasClass('single-product')){nbtou_js.change_variations();}
if($('.nbt-ou-fast').length){$('#nbt-orderupload-popup').remove();$('body').append('<div id="nbt-orderupload-popup" class="white-popup mfp-hide"><h2>'+nbt_solutions.nbt_ou_label+'</h2><div class="nbt-orderupload-popup-wrapper"></div></div>');}
this.require_upload();},change_variations_ajax:function(){var currentVariations='';$('form.variations_form .variations select').each(function(){var attribute_name=$(this).data('attribute_name')||$(this).attr('name');var value=$(this).val()||'';currentVariations+=attribute_name+value;});$('#nb-orderupload-wrapper').show();nbtou_load.block($('form.variations_form'));$.ajax({url:nbt_solutions.ajax_url,data:{action:'nbt_ou_variations_show',variation_id:md5(currentVariations)},type:'POST',datatype:'json',success:function(response){nbtou_load.unblock($('form.variations_form'));$('.nbt-oupload-body').html('');if(response.complete!=undefined&&response.tpl!=''){$('.nbt-oupload-body').html(response.tpl);if($('.nbt-oupload-body .nbt-file').length>3){$('.nbt-oupload-output .nbt-oupload-body').slimScroll({height:'184px'});}}else{$('.nbt-oupload-body').removeAttr('style');$(".nbt-oupload-output .nbt-oupload-body").slimScroll({destroy:true});}},error:function(){nbtou_load.unblock($('form.variations_form'));}});},change_variations:function(){var count=$('.variations select').length;var selected=0;$('.variations select').each(function(index){if($(this).val()){selected+=1;}});if(count==selected){$('#nb-orderupload-wrapper').show();nbtou_load.block($('form.variations_form'));var $form=$('form.variations_form'),variationData=$form.data('product_variations'),attributeFields=$form.find('.variations select'),currentVariations='';attributeFields.each(function(){var attribute_name=$(this).data('attribute_name')||$(this).attr('name');var value=$(this).val()||'';currentVariations+=attribute_name+value;});$.ajax({url:nbt_solutions.ajax_url,data:{action:'nbt_ou_variations_show',variation_id:md5(currentVariations)},type:'POST',datatype:'json',success:function(response){nbtou_load.unblock($('form.variations_form'));$('.nbt-oupload-body').html('');if(response.complete!=undefined&&response.tpl!=''){$('.nbt-oupload-body').html(response.tpl);if($('.nbt-oupload-body .nbt-file').length>3){$('.nbt-oupload-output .nbt-oupload-body').slimScroll({height:'184px'});}else{nbtou_js.destroy_upload();}}else{nbtou_js.destroy_upload();}},error:function(){nbtou_load.unblock($('form.variations_form'));}});}else{if(nbtou.require_variation){$('#nb-orderupload-wrapper').hide();}}},destroy_upload:function(){$('.nbt-oupload-body').removeAttr('style');$(".nbt-oupload-output .nbt-oupload-body").slimScroll({destroy:true});},toggle_order_upload:function(){var $div=$(this).closest('.nbt-show-files');if($(this).hasClass('active')){$div.find('ul').slideUp();$(this).removeClass('active');}else{$div.find('ul').slideDown();$(this).addClass('active');}},show_order_upload:function(e){e.preventDefault();nbtou_load.block($('.shop_table'));var product_fast=$(this).closest('.nbt-ou-fast');var product_id=product_fast.attr('id').replace("nbt-upload-cart-","");$.ajax({url:nbt_solutions.ajax_url,data:{action:'nbt_ou_show',product_id:product_id},type:'POST',datatype:'json',success:function(response){if(response.complete!=undefined){$('#nbt-orderupload-popup .nbt-orderupload-popup-wrapper').html(response.tpl);}},complete:function(){nbtou_load.unblock($('.shop_table'));$.magnificPopup.open({items:{src:'#nbt-orderupload-popup'},type:'inline',midClick:true,mainClass:'mfp-fade',closeOnBgClick:false,callbacks:{open:function(){var $current_window=$(window).width()-50;var $width_table=$('.price-matrix-table').width()+60;if($width_table>500&&$current_window>$width_table){$('#price-matrix-popup').css({"maxWidth":$width_table});}}}});},error:function(){alert('There was an error when processing data, please try again !');}});},require_upload:function(){if(nbtou.require_upload&&$('body').hasClass('has-order-upload')){var $file=$('.nbt-oupload-body .nbt-file').length;var $file_success=$('.nbt-oupload-body .nbt-file.success').length;if($file==$file_success&&$file!=0){$('.single_add_to_cart_button').prop('disabled',false);}else{$('.single_add_to_cart_button').prop('disabled',true);}}},dragover_files:function(e){e.preventDefault();e.stopPropagation();$(this).addClass('dragover');},dragleave_files:function(e){e.preventDefault();e.stopPropagation();$(this).removeClass('dragover');},drop_files:function(e){e.preventDefault();e.stopPropagation();$(this).removeClass('dragover');nbtou_js.triggerCallback(e);},binarySearch:function(items,value){return items.indexOf(value);},triggerCallback:function(e){var show_error=false;var $product_id=$('[name="add-to-cart"]').val();var files;if(e.originalEvent.dataTransfer){files=e.originalEvent.dataTransfer.files;}else if(e.target){files=e.target.files;}
var fail_filename='';$.each(files,function(key,file){var extension=file.name.replace(/^.*\./,'').toLowerCase();if(nbtou_js.binarySearch(nbtou.file_extension,extension)<0){fail_filename+=file.name.toLowerCase()+', ';files=jQuery.grep(files,function(k,value){return value!=key;});}});var number_files=files.length;if(number_files>nbtou.file_of_number){var file_of_number=nbtou.label_numfiles.replace("%s",nbtou.file_of_number);alert(file_of_number);show_error=true;}
if(fail_filename&&!show_error){var label_restrict=nbtou.label_restrict.replace("%s",fail_filename.slice(', ',-2));alert(label_restrict);}
if(!show_error){if(typeof nbt_solutions!=='undefined'&&nbt_solutions.customer_id!=undefined){customer_id=nbt_solutions.customer_id;}else{customer_id=nbtou.customer_id;}
var data=new FormData(),timestamp=new Date().getUTCMilliseconds(),currentVariations='',$html='';for(var i=0;i<files.length;i++){var attr_id=md5(timestamp+i);data.append("nbt_id[]",attr_id);$html+='<div id="'+md5(customer_id+files[i].name)+'" attr-id="'+attr_id+'" class="nbt-file"><div class="nbt-file-left">';if(files[i].type.indexOf('image/')===0){$html+='<img width="50" src="'+URL.createObjectURL(files[i])+'" />';}
$html+='</div><div class="nbt-file-right">';$html+='<div class="name">'+files[i].name+' <i class="nbt-icon-cancel"></i></div><div class="size"> '+nbtou_js.calcSize(files[i].size)+'</div><div class="nbt-ou-msg" style="display: none;"></div></div>';$html+='</div>';}
$('.nbt-oupload-body').append($html);if($('.nbt-oupload-output .nbt-oupload-body .nbt-file').length>3){$('.nbt-oupload-output .nbt-oupload-body').slimScroll({height:'184px'});}
data.append("action","nbt_order_upload");data.append("product_id",$product_id);$.each(files,function(key,value){data.append("nbt_files[]",value);});if(typeof nbt_solutions!=='undefined'&&nbt_solutions.ajax_url!=undefined){ajax_url=nbt_solutions.ajax_url;}else{ajax_url=nbtou.ajax_url;}
$('form.variations_form .variations select').each(function(){var attribute_name=$(this).data('attribute_name')||$(this).attr('name');var value=$(this).val()||'';currentVariations+=attribute_name+value;});if($('.variation_id').length>0){data.append("variation_id",md5(currentVariations));}
nbtou_load.block($('#nbt-order-upload'));$.ajax({url:ajax_url,type:'POST',data:data,cache:false,dataType:'json',processData:false,contentType:false,xhr:function(){var xhr=new window.XMLHttpRequest();var started_at=new Date();xhr.upload.addEventListener("progress",function(evt){if(evt.lengthComputable){var loaded=evt.loaded;var total=evt.total;var seconds_elapsed=(new Date().getTime()-started_at.getTime())/1000;var bytes_per_second=seconds_elapsed?loaded/seconds_elapsed:0;var Kbytes_per_second=bytes_per_second/1000;var remaining_bytes=total-loaded;var seconds_remaining=seconds_elapsed?remaining_bytes/bytes_per_second:'calculating';jQuery('.timeRemaining').html('');jQuery('.timeRemaining').append(Math.round(seconds_remaining));$('.progress').show();$('.progress').find('.progress-bar').css('width',Math.round((evt.loaded/evt.total)*100)+"%");}},false);return xhr;},success:function(data,textStatus,jqXHR){nbtou_load.unblock($('#nbt-order-upload'));if(data.msg!=undefined){alert(data.msg);return;}
$.each(data.response,function(index,value){if(value.complete!=undefined){$('.progress').hide();$('#'+index).addClass('success');}else{if(data.fake!=undefined&&typeof data.fake[index]!='undefined'){$('.nbt-file[attr-id="'+index+'"] .nbt-ou-msg').show();$('.nbt-file[attr-id="'+index+'"]').addClass('error');$('.nbt-file[attr-id="'+index+'"] .nbt-ou-msg').html(value);}else{$('#'+index+' .nbt-ou-msg').show();$('#'+index).addClass('error');$('#'+index+' .nbt-ou-msg').html(value);}}});nbtou_js.require_upload();}});}},click_files:function(){var isUpload=true;if(nbtou.file_of_number!=undefined&&$('.nbt-oupload-output .nbt-oupload-body .nbt-file').length>=nbtou.file_of_number){var isUpload=false;var file_of_number=nbtou.label_numfiles.replace("%s",nbtou.file_of_number);alert(file_of_number);}
if(nbtou.require_variation&&$('.single_add_to_cart_button.disabled').length>0){var isUpload=false;alert(nbtou.label_variation);}
if(isUpload){$('.nbt-upload-input').val('');$('.nbt-upload-input').trigger('click');}},change_files:function(e){nbtou_js.triggerCallback(e);nbtou_js.require_upload();},calcSize:function(nBytes){if(nBytes==0){return{size:'',label:''}}
for(var aMultiples=["Kb","Mb","Gb","Tb","Pb","Eb","Zb","Yb"],nMultiple=0,nApprox=nBytes/1024;nApprox>1000;nApprox/=1000,nMultiple++){}
return nApprox.toFixed(2)+' '+aMultiples[nMultiple];},remove_files:function(){var $li=$(this).closest('.nbt-file'),$id=$li.attr('id'),currentVariations='';nbtou_load.block($('#nbt-order-upload'));if(typeof nbt_solutions!=='undefined'&&nbt_solutions.ajax_url!=undefined){ajax_url=nbt_solutions.ajax_url;}else{ajax_url=nbtou.ajax_url;}
var variation_id=0;if($('.variation_id').length>0){var variation_id=$('.variation_id').val();}
var isValid=true;if($li.hasClass("error")){var $id=$li.attr('attr-id');isValid=false;}
$('form.variations_form .variations select').each(function(){var attribute_name=$(this).data('attribute_name')||$(this).attr('name');var value=$(this).val()||'';currentVariations+=attribute_name+value;});$.ajax({url:ajax_url,data:{action:'nbt_ou_remove',product_id:$('[name="add-to-cart"]').val(),variation_id:md5(currentVariations),file:$id,valid:isValid},type:'POST',datatype:'json',success:function(rs){nbtou_load.unblock($('#nbt-order-upload'));if(rs.complete!=undefined){$('#'+rs.file_id).remove();nbtou_js.require_upload();}else{if(isValid){$('#'+rs.file_id).remove();}else{$('.nbt-file[attr-id="'+rs.file_id+'"]').remove();}}
if($('.nbt-oupload-body .nbt-file').length<3){$('.nbt-oupload-body').removeAttr('style');$(".nbt-oupload-output .nbt-oupload-body").slimScroll({destroy:true});}else{$('.nbt-oupload-output .nbt-oupload-body').slimScroll({height:'184px'});}},error:function(){alert('There was an error when processing data, please try again !');nbtou_load.unblock($('#nbt-order-upload'));}});return false;}}
nbtou_js.init();var picker='file',oauthToken,driveclientId=nbtou.g_drive_clientid,driveapiKey=nbtou.g_drive_apikey,dropboxApi=nbtou.dropbox_apikey,boxApi=nbtou.box_apikey,service_order=['drive','upload'],service_list={'drive':1,'upload':1},origin=window.location.protocol+'//'+window.location.host;var ol_services_js={init:function(){this.support();this.bind_functions();},bind_functions:function(){$(document).on('click','#add-g-drive',this.g_drive_handler);$(document).on('click','#add-button-no-api',this.no_api_handle);$(document).on('click','#add-dropbox',this.dropbox_handler);$(document).on('click','#add-box',this.box_handler);$(document).on('click','.tablinks',function(event){event.preventDefault();$('.ou-tabcontent > div').css('display','none');$('.ou-tab > button').removeClass('activated');$(this).addClass('activated');var tab_rel=$(this).attr('tab-rel');$('.ou-tabcontent '+'#'+tab_rel).fadeIn('slow');});},support:function(){if(driveapiKey&&driveclientId){$("head").append("<script type='text/javascript' src='https://apis.google.com/js/api.js'></script>");}
if(dropboxApi){$("head").append("<script type='text/javascript' src='https://www.dropbox.com/static/api/2/dropins.js'></script>");}
if(boxApi){$("head").append("<script type='text/javascript' src='https://app.box.com/js/static/select.js'></script>");}},g_drive_handler:function(){picker='file';ol_services_js.load_gapi();},load_gapi:function(){if(!oauthToken){gapi.load('auth',{'callback':ol_services_js.onAuthApiLoad});gapi.load('picker',1);}
else{ol_services_js.open_file_picker();}},onAuthApiLoad:function(){window.gapi.auth.authorize({'client_id':driveclientId,'scope':['https://www.googleapis.com/auth/drive'],},ol_services_js.callback_auth_result);},open_file_picker:function(){var picker=new google.picker.PickerBuilder().setOrigin(origin).setOAuthToken(oauthToken).setCallback(ol_services_js.picker_callback);picker.addView(new google.picker.DocsView().setIncludeFolders(true));picker.addView(new google.picker.DocsUploadView().setIncludeFolders(true));picker.build().setVisible(true);},callback_auth_result:function(authResult){if(authResult&&!authResult.error){oauthToken=authResult.access_token;ol_services_js.open_file_picker();}},picker_callback:function(data){if(data[google.picker.Response.ACTION]==google.picker.Action.PICKED){driverDocs=data[google.picker.Response.DOCUMENTS];var driver_url=driverDocs[0].url;var driver_name=driverDocs[0].name;var driver_id=driverDocs[0].id;ol_services_js.process_file(driver_url,driver_name,driver_id);}},process_file:function(os_url,os_name,os_id){if(typeof nbt_solutions!=='undefined'&&nbt_solutions.ajax_url!=undefined){ajax_url=nbt_solutions.ajax_url;}else{ajax_url=nbtou.ajax_url;}
var product_id=$('[name="add-to-cart"]').val();var variation_id=0;if($('.variation_id').length>0){var variation_id=$('.variation_id').val();}
$.ajax({url:ajax_url,type:'POST',dataType:'json',data:{action:'nbt_order_upload',os_url:os_url,os_name:os_name,os_id:os_id,product_id:product_id,variation_id:variation_id,attached_from_outsoure:1},beforeSend:function(){nbtou_load.block($('#from_online_services'));},success:function(response){nbtou_load.unblock($('#from_online_services'));var $html='';$html+='<div id="'+os_id+'" class="nbt-file success">';$html+='<div class="nbt-file-left file-icon"><i class="fa fa-file-o fa-3x" aria-hidden="true"></i></div>';$html+='<div class="nbt-file-right">';$html+='<div class="name">'+os_name+' <i class="nbt-icon-cancel"></i></div><div class="nbt-ou-msg" style="display: none;"></div></div>';$html+='</div>';$('.nbt-oupload-body').append($html);nbtou_js.require_upload();},error:function(){alert('There was an error when processing data, please try again !');nbtou_load.unblock($('#nbt-order-upload'));}})},no_api_handle:function(){tb_show("NO API","#TB_inline?inlineId=g-drive-popup-wrap",null);ol_services_js.popup_position();return false;},dropbox_handler:function(event){event.preventDefault();Dropbox.init({appKey:dropboxApi});Dropbox.choose({linkType:"preview",multiselect:false,success:function(files){var dbFile=files[0];var dbURL=dbFile.link.replace("?dl=0","");var dbFileName=dbFile.name;var dbFileID=dbFile.id;ol_services_js.process_file(dbURL,dbFileName,dbFileID);}});},box_handler:function(){var boxoptions={clientId:boxApi,linkType:'shared',multiselect:false};var boxSelect=new BoxSelect(boxoptions);boxSelect.launchPopup();boxSelect.success(function(response){var boxFile=response[0];var boxURL=boxFile.url;var boxFileName=boxFile.name;var boxFileID=boxFile.id;ol_services_js.process_file(boxURL,boxFileName,boxFileID);});},popup_position:function(){var tbWindow=$('#TB_window');var width=$(window).width();var H=$(window).height();var W=(1080<width)?1080:width;if(tbWindow.size()){tbWindow.width(W-50).height(H-45);$('#TB_ajaxContent').css({'width':'100%','height':'100%','padding':'0'});tbWindow.css({'margin-left':'-'+parseInt(((W-50)/2),10)+'px'});if(typeof document.body.style.maxWidth!='undefined')
tbWindow.css({'top':'20px','margin-top':'0'});$('#TB_title').css({'background-color':'#fff','color':'#cfcfcf'});};}}
ol_services_js.init();});