PageSourceSearch

https://purefilter.com/assets/js/main.js?v=6052

js purefilter.com collected 2026-10-08 10:09:10 UTC 147,750 bytes, 5,159 lines download raw bytes

1var tl = new TimelineLite();
2var winW = $(window).width();
3var galleryTop;
4var galleryThumbs;
5$(window).on("load", function () {
6  headerSetting();
7  reviewProgress();
8  calcNavW();
9  genHPage();
10  genHeight();
11  getBg();
12  boxTabSwith();
13
14  awardSlide();
15  compSlideFade();
16
17  genHBanner();
18
19  $(".dropify-review").dropify({
20    messages: {
21      default:
22        "ลากภาพมายังบริเวณนี้เพื่ออัพโหลด<br>หรือคลิกเพื่ออัพโหลด <span>jpg,  png,  gif (4:3 ratio size)  maximum width: 1200 px</span>",
23    },
24  });
25
26  $(".thumb-color-selector li label").click(function () {
27    var attrNamePic = $(this).attr("data-pic");
28    var attrSkuPrice = $(this).attr("data-sku-price");
29    var attrSkuPriceD = $(this).attr("data-sku-pd");
30    var attrSkuDis = $(this).attr("data-sku-dis");
31    $(this)
32      .closest(".thumb")
33      .find(".thumb-img > img")
34      .attr("src", "/" + attrNamePic);
35
36    let prod_card = $(this).closest(".thumb");
37    let prod_card_body = prod_card.find(".thumb-body");
38    let prod_group = prod_card_body.find(".group-price");
39
40    if (attrSkuPriceD) {
41      let sku_price = prod_group.find(".txt-price");
42      sku_price.html(attrSkuPriceD);
43    }
44
45    if (attrSkuPrice) {
46      let sku_dis = prod_group.find(".txt-discount");
47      sku_dis.html(attrSkuPrice);
48    }
49
50    if (attrSkuDis) {
51      let sku_dis_per = prod_group.find(".txt-discount-per");
52      sku_dis_per.html(attrSkuDis);
53    }
54  });
55
56  $(".close-stick-top").click(function () {
57    var dataHeader = $(".wrapper").attr("data-header");
58    if ((dataHeader = "menu-tr")) {
59      $(".wrapper").removeAttr("style");
60      $(".head-wrap").removeAttr("style");
61    } else if ((dataHeader = "default")) {
62      $(".wrapper").removeAttr("style");
63      $(".head-wrap").removeAttr("style");
64    }
65    $(this).closest(".sec-stick-top").fadeOut();
66    $(this).closest(".sec-stick-top").addClass("hide");
67    setTimeout(() => {
68      genHBanner();
69    }, 100);
70  });
71
72  $(".btn-swich-type").click(function () {
73    var switchType = $(this).attr("data-switch-type");
74
75    if (switchType == "login-email") {
76      $(".login-switch").hide();
77      $(".login-email").show();
78    } else if (switchType == "login-phone-number") {
79      $(".login-switch").hide();
80      $(".login-phone-number").show();
81    } else if (switchType == "login-reset-password") {
82      $(".login-switch").hide();
83      $(".login-reset-password").show();
84    } else if (switchType == "login-reset-success") {
85      $(".login-switch").hide();
86      $(".login-reset-success").show();
87    }
88  });
89
90  $(".sec-acc-group").each(function () {
91    if ($(this).find(".accor-list").hasClass("active")) {
92      $(this).find(".accor-list.active .accor-body").slideDown();
93    }
94
95    $(this)
96      .find(".accor-list .accor-head")
97      .click(function () {
98        if (!$(this).closest(".accor-list").hasClass("active")) {
99          $(this)
100            .closest(".box-accordion")
101            .find(".accor-list ")
102            .removeClass("active");
103          $(this)
104            .closest(".box-accordion")
105            .find(".accor-list .accor-body ")
106            .slideUp();
107
108          $(this).closest(".accor-list").addClass("active");
109          $(this).closest(".accor-list").find(".accor-body").slideDown();
110        } else {
111          $(this).parent().removeClass("active");
112          $(this).parent().find(".accor-body").slideUp();
113        }
114      });
115  });
116
117  if ($(".gallery-top").length > 0) {
118    galleryTop = new Swiper(".gallery-top", {
119      spaceBetween: 0,
120      navigation: {
121        nextEl: ".swiper-button-next",
122        prevEl: ".swiper-button-prev",
123      },
124    });
125  }
126
127  if ($(".gallery-thumbs").length > 0) {
128    galleryThumbs = new Swiper(".gallery-thumbs", {
129      spaceBetween: 10,
130      centeredSlides: true,
131      slidesPerView: 5,
132      touchRatio: 0.2,
133      slideToClickedSlide: true,
134      loop: false,
135
136      breakpoints: {
137        575: {
138          spaceBetween: 10,
139          slidesPerView: 5,
140        },
141        767: {
142          slidesPerView: 5,
143        },
144      },
145    });
146
147    galleryThumbs.controller.control = galleryTop;
148    galleryTop.controller.control = galleryThumbs;
149  }
150
151  if (window.location.hash) {
152    let hash = window.location.hash;
153    if ($(hash).length) {
154      $("html, body").animate(
155        {
156          scrollTop: $(hash).offset().top * 1.09,
157        },
158        1000,
159        ""
160      );
161    }
162  }
163});
164
165function changePicFiltered($this) {
166  var attrNamePic = $this.attr("data-pic");
167  var attrSkuPrice = $this.attr("data-sku-price");
168  var attrSkuPriceD = $this.attr("data-sku-pd");
169  var attrSkuDis = $this.attr("data-sku-dis");
170  $this
171    .closest(".thumb")
172    .find(".thumb-img > img")
173    .attr("src", "/" + attrNamePic);
174
175  let prod_card = $this.closest(".thumb");
176  let prod_card_body = prod_card.find(".thumb-body");
177  let prod_group = prod_card_body.find(".group-price");
178
179  if (attrSkuPriceD) {
180    let sku_price = prod_group.find(".txt-price");
181    sku_price.html(attrSkuPriceD);
182  }
183
184  if (attrSkuPrice) {
185    let sku_dis = prod_group.find(".txt-discount");
186    sku_dis.html(attrSkuPrice);
187  }
188
189  if (attrSkuDis) {
190    let sku_dis_per = prod_group.find(".txt-discount-per");
191    sku_dis_per.html(attrSkuDis);
192  }
193}
194
195function changeDetailPic($this) {
196  var index = $this.attr("data-galind");
197  galleryTop.slideTo(index);
198  galleryThumbs.slideTo(index);
199  if ($this.hasClass("prod-watfil")) {
200    var thumb_col_sel = $this.closest(".thumb-color-selector");
201    var prod_name_wrap = thumb_col_sel.siblings(".prod-name-wrap");
202    var prod_uniq_code = prod_name_wrap.find(".prod_uniq_code");
203    var prod_uniq_code_data = $this.attr("data-skuname");
204    prod_uniq_code.html(prod_uniq_code_data);
205
206    var attrSkuPrice = $this.attr("data-sku-price");
207    var attrSkuPriceD = $this.attr("data-sku-pd");
208    var attrSkuDis = $this.attr("data-sku-dis");
209
210    let prod_group = thumb_col_sel.siblings(".group-price");
211
212    if (attrSkuPriceD) {
213      let sku_price = prod_group.find(".txt-price");
214      sku_price.html(attrSkuPriceD);
215    }
216
217    if (attrSkuPrice) {
218      let sku_dis = prod_group.find(".txt-discount");
219      sku_dis.html(attrSkuPrice);
220    }
221
222    if (attrSkuDis) {
223      let sku_dis_per = prod_group.find(".txt-discount-per");
224      sku_dis_per.html(attrSkuDis);
225    }
226  }
227}
228
229$(".pure-filter .pure-filter-btn").click(function () {
230  $(".pure-filter").removeClass("active");
231  if (!$(this).hasClass("active")) {
232    $(".pure-filter ul").slideUp();
233    $(".pure-filter .pure-filter-btn").removeClass("active");
234    $(this).parent().addClass("active");
235  }
236  $(this).closest(".pure-filter").find("ul").slideToggle();
237  $(this).toggleClass("active");
238});
239
240$(".pure-filter:not(.select-check) ul li").click(function () {
241  $(this).parent().slideUp();
242  $(".pure-filter").removeClass("active");
243  $(this).parent().find("li").removeClass("active");
244  $(this).addClass("active");
245  var getTextData = $(this).text();
246  $(this).closest(".pure-filter").find(".pure-filter-btn").text(getTextData);
247});
248
249$(".btn-filter").click(function () {
250  var star = parseInt($(this).attr("data-type"));
251  var product_code = parseInt($(this).attr("data-pcode"));
252  var token = $(this)
253    .closest(".filter-review-wrap")
254    .find("input[name=token]")
255    .val();
256  if (!$(this).hasClass("active")) {
257    $(".box-filter-btn .btn-filter").removeClass("active");
258    $(this).toggleClass("active");
259  }
260
261  filterReview(star, product_code, token);
262});
263
264$(".btn-filter-promo").click(function () {
265  if (!$(this).hasClass("active")) {
266    $(".box-filter-btn .btn-filter").removeClass("active");
267    $(".pure-filter").find("ul").slideUp();
268    $(this).toggleClass("active");
269    $(this).closest(".pure-filter").find("ul").slideToggle();
270  } else {
271    $(this).removeClass("active");
272    $(this).closest(".pure-filter").find("ul").slideUp();
273  }
274});
275
276function loadMoreReview($this) {
277  var star = parseInt(
278    $(".box-filter-btn .btn.btn-filter.active").attr("data-type")
279  );
280  var product_code = parseInt($this.attr("data-pcode"));
281  var old_max_ind = parseInt($this.attr("data-maxind"));
282  var token = $this
283    .closest(".filter-review-wrap")
284    .find("input[name=token]")
285    .val();
286  loadMoreReviewAjax(star, product_code, old_max_ind, token);
287}
288
289$(function () {
290  if (winW < 992) {
291    $(document).on("scroll resize", function () {
292      var pixels = $(document).scrollTop();
293      var pageHeight = $(document).height() - $(window).height();
294      var progress = (100 * pixels) / pageHeight;
295
296      $(".scrollbar-progress").css("width", progress + "%");
297      $(".scrollbar-progress").css("transition", "none");
298
299      $(".scrollbar-progress").css("width", progress + "%");
300      $(".scrollbar-progress").css("transition", "none");
301    });
302  } else {
303    window.onscroll = () => {
304      onScroll();
305    };
306  }
307});
308
309var slideDel = $(".section-header").outerHeight() - 1;
310function onScroll(event) {
311  var scrollPosition = $(document).scrollTop() + slideDel + 10;
312
313  $(".subnav-list-isinfo a").each(function (index, value) {
314    if ($(this).closest(".tab-info").hasClass("show")) {
315      var currentLink = $(this);
316      var refElement = currentLink.attr("data-link");
317      var first_active = false;
318      var refElement_ID = "#" + refElement;
319      var subnavGroup = $(".box-subnav.show .subnav-group").outerWidth();
320      var boxSubNav = $(".box-subnav.show").outerWidth();
321      var boxSubNavCal = (boxSubNav - subnavGroup) / 2;
322      var progressLength = $(".subnav-list-isinfo").length;
323      var progressCal = $(".subnav-list-isinfo a.active").outerWidth();
324      var progressOrder = $(".subnav-list-isinfo a.active").attr("data-order");
325
326      if (
327        $(refElement_ID).offset().top <= scrollPosition &&
328        $(refElement_ID).offset().top + $(refElement_ID).height() >
329          scrollPosition
330      ) {
331        $(".subnav-list-isinfo a").removeClass("active");
332        currentLink.addClass("active");
333        if (progressOrder <= progressLength) {
334          var progress =
335            progressCal * progressOrder - progressCal / 2 + boxSubNavCal;
336        }
337
338        setTimeout(() => {
339          if (
340            progressOrder <= progressLength &&
341            $(document).scrollTop() < $("#smenu-" + progressLength).offset().top
342          ) {
343            $(".scrollbar-progress").css("width", progress + "px");
344          } else {
345            $(".scrollbar-progress").css("width", "100%");
346          }
347        }, 200);
348      } else {
349        currentLink.removeClass("active");
350      }
351
352      setTimeout(() => {
353        if (
354          $(".subnav-list-isinfo").find("a.active").length == 0 &&
355          $(document).scrollTop() < $("#smenu-" + 1).offset().top
356        ) {
357          $(".scrollbar-progress").css("width", "0px");
358        }
359      }, 400);
360    }
361  });
362
363  $(".subnav-list-isreview a").each(function (index, value) {
364    if ($(this).closest(".tab-review").hasClass("show")) {
365      var currentLink = $(this);
366      var refElement = currentLink.attr("data-link");
367      var first_active = false;
368      var refElement_ID = "." + refElement;
369      var subnavGroup = $(".box-subnav.show .subnav-group").outerWidth();
370      var boxSubNav = $(".box-subnav.show").outerWidth();
371      var boxSubNavCal = (boxSubNav - subnavGroup) / 2;
372      var progressLength = $(".subnav-list-isreview").length;
373      var progressCal = $(".subnav-list-isreview a.active").outerWidth();
374      var progressOrder = $(".subnav-list-isreview a.active").attr(
375        "data-order"
376      );
377      if (
378        $(refElement_ID).offset().top <= scrollPosition &&
379        $(refElement_ID).offset().top + $(refElement_ID).height() >
380          scrollPosition
381      ) {
382        $(".subnav-list-isreview a").removeClass("active");
383        currentLink.addClass("active");
384        if (progressOrder <= progressLength) {
385          var progress =
386            progressCal * progressOrder - progressCal / 2 + boxSubNavCal;
387        }
388        setTimeout(() => {
389          if (
390            progressOrder <= progressLength &&
391            $(document).scrollTop() <
392              $(".isreview-" + progressLength).offset().top
393          ) {
394            $(".scrollbar-progress-isreview").css("width", progress + "px");
395          }
396          if (progressOrder == progressLength) {
397            $(".scrollbar-progress-isreview").css("width", "100%");
398          }
399        }, 200);
400      } else {
401        currentLink.removeClass("active");
402      }
403
404      setTimeout(() => {
405        if (
406          $(".subnav-list-isreview").find("a.active").length == 0 &&
407          $(document).scrollTop() < $(".isreview-" + 1).offset().top
408        ) {
409          $(".scrollbar-progress-isreview").css("width", "0px");
410        }
411      }, 400);
412    }
413  });
414}
415
416function reviewProgress() {
417  var data_point = $(".review-point-cal").attr("data-count-review");
418  $(".review-point-cal .box-rate").each(function () {
419    var dataCountReview = $(this).attr("data-point");
420    $(this)
421      .find(".progress-point span")
422      .css("width", Math.round((dataCountReview / data_point) * 100) + "%");
423  });
424}
425
426isDeck = true;
427function checkResize() {
428  var winW = $(window).width();
429  boxTabSwith();
430  genHBanner();
431  calScroll();
432  compSlideFade();
433  setTimeout(() => {
434    awardSlide();
435  }, 100);
436
437  if (winW > 991) {
438    isDeck = true;
439  } else {
440    isDeck = false;
441  }
442
443  genHPage();
444  if (winW > 991) {
445    $("body").removeClass("menuClick");
446    $(".box-menu").removeAttr("style");
447  }
448  if (winW > 767) {
449    $(".comp-slide-button .swiper-button").removeAttr("style");
450  } else {
451    calHBtn();
452  }
453  getBg();
454
455  if (winW >= 1600 && winW <= 1920) {
456    genHeight("1920");
457  } else if (winW >= 1440 && winW < 1600) {
458    genHeight("1600");
459  } else if (winW >= 1200 && winW < 1440) {
460    genHeight("1440");
461  } else if (winW >= 992 && winW < 1200) {
462    genHeight("1200");
463  } else if (winW >= 768 && winW < 992) {
464    genHeight("768");
465  } else if (winW < 768) {
466    genHeight("");
467  } else if (winW > 1920 && winW < 2400) {
468    genHeight("2240");
469  } else if (winW > 2400) {
470    genHeight("2400");
471  }
472  // genHeight(winW);
473}
474
475async function calcNavW() {
476  $(".group-sub").each(function () {
477    var wPdH = $(this).find(".bg-sub-menu").offset();
478    var wPdHCal = wPdH.left + 50;
479    var winW = $(window).width();
480
481    if (winW == 1920) {
482      wPdHCal = 553.796;
483    } else if (winW == 1440) {
484      wPdHCal = 488.593;
485    } else if (winW == 1024) {
486      // alert(`test wwww`);
487      wPdHCal = 280;
488    }
489    console.log("winW: " + winW);
490    console.log("wPdHCal: " + wPdH);
491    $(this)
492      .find(".bg-sub-menu")
493      .css("transform", "translateX(-" + wPdHCal + "px)");
494  });
495  // return;
496}
497
498$(window).resize(function () {
499  checkResize();
500  calcNavW();
501  // console.log("resize");
502});
503
504var starWidth = 20;
505
506if (winW > 767) {
507  var starWidthCount = 30;
508} else {
509  var starWidthCount = 20;
510}
511
512$.fn.stars = function () {
513  return $(this).each(function () {
514    $(this).html(
515      $("<span />").width(
516        Math.max(0, Math.min(5, parseFloat($(this).html()))) * starWidth
517      )
518    );
519  });
520};
521$.fn.starsCount = function () {
522  return $(this).each(function () {
523    $(this).html(
524      $("<span />").width(
525        Math.max(0, Math.min(5, parseFloat($(this).html()))) * starWidthCount
526      )
527    );
528  });
529};
530
531$(document).ready(function () {
532  generateContent();
533  var addr_ship_length = $(".check-addr-length").attr("data-addr-length");
534  var addr_bill_length = $(".ckeck-bill-addr-length").attr("data-addr-length");
535  if (parseInt(addr_ship_length) > 0) {
536    $(".ship-addr-first").hide();
537  } else if (parseInt(addr_ship_length) == 0) {
538    $(".ship-addr-data").hide();
539  }
540
541  if (parseInt(addr_bill_length) > 0) {
542    $(".bill-addr-first").hide();
543  } else if (parseInt(addr_bill_length) == 0) {
544    $(".bill-addr-data").hide();
545  }
546
547  $(".loadpage").fadeOut();
548  window.scrollTo(0, 0);
549  $("span.stars").stars();
550  $("span.stars-count").starsCount();
551
552  $(".subnav-list a").click(function () {
553    var refElement = $(this).attr("data-link");
554    if ($(this).closest(".box-subnav.has-subnav").hasClass("tab-info")) {
555      $("html, body").animate(
556        {
557          scrollTop:
558            $("#" + refElement).offset().top -
559            $(".section-header").outerHeight(),
560        },
561        1000
562      );
563    } else {
564      $("html, body").animate(
565        {
566          scrollTop:
567            $("." + refElement).offset().top -
568            $(".section-header").outerHeight(),
569        },
570        1000
571      );
572    }
573  });
574  $(".btn-cart").click(function () {
575    if ($(this).hasClass("active")) {
576      // $(this).removeClass("active");
577    } else {
578      $(".box-field-lang").fadeOut();
579      $(".btn-lang").removeClass("active");
580      $(".box-field-search").fadeOut();
581      $(".btn-search").removeClass("active");
582    }
583
584    if (!$(".box-cart-product").hasClass("active")) {
585      $(".box-cart-product").addClass("active");
586      $(".box-cart-product").fadeIn();
587      $(".box-field-lang").fadeOut();
588      $(".btn-lang").removeClass("active");
589      $(".box-field-search").fadeOut();
590      $(".btn-search").removeClass("active");
591    } else if ($(".box-cart-product").hasClass("active")) {
592      $(".box-cart-product").removeClass("active");
593      $(".box-cart-product").fadeOut();
594    }
595  });
596  //////////////// //////////////// ////////////////
597  //////////// Dropdown Checkbox ///////////////
598  //////////////// //////////////// ////////////////
599  $(".dealer-filter-title").click(function () {
600    if (!$(this).closest(".btn-dealer-filter").hasClass("active")) {
601      $(this).closest(".btn-dealer-filter").addClass("active");
602      $(this).closest(".dealer-filter-check").find("ul.toggle").slideToggle();
603    } else {
604      $(this).closest(".dealer-filter-check").find("ul.toggle").slideUp();
605      setTimeout(() => {
606        $(this).closest(".btn-dealer-filter").removeClass("active");
607      }, 400);
608    }
609  });
610
611  $(".check-all").click(function () {
612    if ($(this).is(":checked")) {
613      $(this).closest(".toggle").find("li ul input").prop("checked", true);
614    } else {
615      $(this).closest(".toggle").find("li ul input").prop("checked", false);
616    }
617  });
618
619  //////////////// //////////////// ////////////////
620  //////////// search///////////////
621  //////////////// //////////////// ////////////////
622  $(".btn-search").click(function () {
623    if ($(this).hasClass("active")) {
624      $(this).removeClass("active");
625      $(".box-field-search").fadeOut();
626    } else {
627      $(this).addClass("active");
628      $(".box-field-search").fadeIn();
629      $(".box-cart-product").fadeOut();
630      // $(".btn-cart").removeClass("active");
631      $(".box-field-lang").fadeOut();
632      $(".box-field-lang").removeClass("active");
633    }
634  });
635
636  $(".btn-lang").click(function () {
637    if ($(this).hasClass("active")) {
638      $(this).removeClass("active");
639      $(".box-field-lang").fadeOut();
640    } else {
641      $(this).addClass("active");
642      $(".box-field-lang").fadeIn();
643      $(".box-cart-product").fadeOut();
644      // $(".btn-cart").removeClass("active");
645      $(".box-field-search").fadeOut();
646      $(".btn-search").removeClass("active");
647    }
648  });
649
650  $(".thumb-gallery").each(function () {
651    $(this)
652      .find(".image-popup-vertical-fit")
653      .magnificPopup({
654        type: "image",
655        mainClass: "mfp-with-zoom",
656        gallery: {
657          enabled: true,
658        },
659
660        zoom: {
661          enabled: true,
662
663          duration: 300, // duration of the effect, in milliseconds
664          easing: "ease-in-out", // CSS transition easing function
665
666          opener: function (openerElement) {
667            return openerElement.is("img")
668              ? openerElement
669              : openerElement.find("img");
670          },
671        },
672      });
673  });
674
675  var HeadH = $(".section-header").outerHeight();
676  var set_h = false;
677  $(window).scroll(function () {
678    if ($(this).scrollTop() > HeadH) {
679      set_h = true;
680    } else {
681      set_h = false;
682    }
683  });
684  var menuCheckSize = false;
685  var $setBody = $(".sub-menu-clone .menu-clone");
686
687  $(".btn-menu").click(function () {
688    // $(".btn-cart").removeClass("active");
689    $(".btn-search").removeClass("active");
690    $(".box-field-lang").removeClass("active");
691    $(".box-cart-product").fadeOut();
692    $(".box-field-search").fadeOut();
693    $(".box-field-lang").fadeOut();
694
695    var attrHeader = $(".wrapper").attr("data-header");
696    var attrColor = $(".wrapper").attr("data-menu-color");
697    if ($("body").hasClass("menuClick")) {
698      $(".box-menu").slideUp();
699      $("body").removeClass("menuClick");
700
701      if (attrHeader == "menu-tr") {
702        if (set_h == false) {
703          setTimeout(() => {
704            $(this).closest(".section-header").addClass("bgs-tr");
705          }, 400);
706        }
707      }
708      menuCheckSize = false;
709      setTimeout(function () {
710        startMenu();
711      }, 50);
712
713      $(this)
714        .closest(".section-header")
715        .find(".sub-menu-clone")
716        .removeClass("show-menu");
717      $setBody.html("");
718    } else {
719      setTimeout(() => {
720        $(".box-menu").slideDown();
721      }, 150);
722      $("body").addClass("menuClick");
723      $(this).closest(".sub-menu-clone").removeClass("show-menu");
724      $(this).closest(".section-header").removeClass("bgs-tr");
725      menuCheckSize = true;
726      setTimeout(function () {
727        startMenu();
728      }, 100);
729    }
730  });
731
732  function startMenu() {
733    if (menuCheckSize) {
734      $(".m-menu.has-sub").click(function () {
735        $(this).addClass("active");
736        subMenuClone();
737        $(".sub-menu-clone").addClass("show-menu");
738        var $holder = $(this).parents().find(".group-sub");
739        var $data = $holder.clone();
740        var $filteredData = "";
741        $filteredData = $data.find("ul.sub-nav");
742        $setBody.html($filteredData);
743      });
744    } else {
745    }
746  }
747
748  function subMenuClone() {
749    $(".back-menu").click(function () {
750      $(this).closest(".sub-menu-clone").removeClass("show-menu");
751      $setBody.html("");
752    });
753  }
754
755  $(".product-slide-tab").each(function () {
756    var slideProgress = new Swiper($(this).find(".swiper-container"), {
757      spaceBetween: 15,
758      slidesPerView: 4,
759      loop: false,
760      speed: 3000,
761      simulateTouch: true,
762
763      breakpoints: {
764        575: {
765          spaceBetween: 20,
766          slidesPerView: 1.2,
767        },
768        767: {
769          slidesPerView: 3,
770        },
771        991: {
772          slidesPerView: 3,
773        },
774        1119: {
775          simulateTouch: true,
776          slidesPerView: 3.2,
777        },
778      },
779    });
780  });
781
782  $(".slide-progress").each(function () {
783    var slideProgress = new Swiper($(this).find(".swiper-container"), {
784      navigation: {
785        nextEl: $(this).find(".swiper-button-next"),
786        prevEl: $(this).find(".swiper-button-prev"),
787      },
788      pagination: {
789        el: $(this).find(".swiper-pagination"),
790        type: "progressbar",
791      },
792      spaceBetween: 20,
793      slidesPerView: 4,
794      loop: false,
795      speed: 2000,
796      simulateTouch: true,
797
798      breakpoints: {
799        575: {
800          spaceBetween: 20,
801          slidesPerView: 1.2,
802        },
803        767: {
804          slidesPerView: 3,
805        },
806        991: {
807          slidesPerView: 3,
808        },
809        1119: {
810          simulateTouch: true,
811          slidesPerView: 3.2,
812        },
813      },
814    });
815
816    slideProgress.on("touchMove", function (event) {
817      var currentX = event.x;
818      var currentY = event.y;
819      gsap.to($(".customCursor"), 0.3, { x: currentX, y: currentY });
820    });
821  });
822
823  $(".slide-progress-auto").each(function () {
824    var slideProgressAuto = new Swiper($(this).find(".swiper-container"), {
825      navigation: {
826        nextEl: $(this).find(".swiper-button-next"),
827        prevEl: $(this).find(".swiper-button-prev"),
828      },
829      pagination: {
830        el: $(this).find(".swiper-pagination"),
831        type: "progressbar",
832      },
833      spaceBetween: 90,
834      slidesPerView: "auto",
835      loop: true,
836      speed: 2000,
837      simulateTouch: true,
838
839      breakpoints: {
840        575: {
841          spaceBetween: 20,
842          slidesPerView: "3",
843        },
844        767: {
845          spaceBetween: 20,
846          slidesPerView: "3",
847        },
848        991: {
849          slidesPerView: "auto",
850        },
851        1119: {
852          simulateTouch: true,
853          slidesPerView: "auto",
854        },
855      },
856    });
857
858    slideProgressAuto.on("touchMove", function (event) {
859      var currentX = event.x;
860      var currentY = event.y;
861      gsap.to($(".customCursor"), 0.3, { x: currentX, y: currentY });
862    });
863  });
864
865  $(".slide-progress-3col").each(function () {
866    var slideProgress3col = new Swiper($(this).find(".swiper-container"), {
867      pagination: {
868        el: $(this).find(".swiper-pagination"),
869        type: "progressbar",
870      },
871      slidesPerView: 2.2,
872      spaceBetween: 20,
873      loop: false,
874      speed: 2000,
875      simulateTouch: true,
876
877      breakpoints: {
878        575: {
879          spaceBetween: 20,
880          slidesPerView: 1.2,
881        },
882        767: {
883          slidesPerView: 1.6,
884        },
885        991: {
886          slidesPerView: 1.6,
887        },
888        1119: {
889          simulateTouch: true,
890          slidesPerView: 2.2,
891        },
892      },
893    });
894  });
895
896  $(".slide-review").each(function () {
897    var slideReview = new Swiper($(this).find(".swiper-container"), {
898      navigation: {
899        nextEl: $(this).closest(".sec-review").find(".swiper-button-next"),
900        prevEl: $(this).closest(".sec-review").find(".swiper-button-prev"),
901      },
902      pagination: {
903        el: $(this).find(".swiper-pagination"),
904      },
905      spaceBetween: 20,
906      slidesPerView: 1,
907      loop: false,
908      speed: 800,
909      simulateTouch: false,
910    });
911  });
912  $(".banner-ctm").each(function () {
913    var bannerCTM = new Swiper($(this).find(".swiper-container"), {
914      navigation: {
915        nextEl: $(this).find(".swiper-button-next"),
916        prevEl: $(this).find(".swiper-button-prev"),
917      },
918      pagination: {
919        el: $(this).find(".swiper-pagination"),
920        clickable: true,
921      },
922      slidesPerView: 1,
923      loop: false,
924      speed: 2000,
925      simulateTouch: true,
926    });
927  });
928
929  ///////////////AUDIO/////////////////
930  $(".sec-jingle").each(function () {
931    const audioPlayer = document.querySelector(".audio-player");
932    const audio = new Audio("assets/img/sound/yt5s.com - pure (128 kbps).mp3");
933
934    var durationTime;
935    audio.addEventListener(
936      "loadeddata",
937      () => {
938        audioPlayer.querySelector(".time .length").textContent =
939          getTimeCodeFromNum(audio.duration);
940        audio.volume = 0.5;
941        durationTimedurationTime = audio.duration;
942      },
943      false
944    );
945    //click on timeline to skip around
946    const timeline = audioPlayer.querySelector(".timeline");
947
948    timeline.addEventListener(
949      "click",
950      (e) => {
951        const timelineWidth = window.getComputedStyle(timeline).width;
952        const timeToSeek =
953          (e.offsetX / parseInt(timelineWidth)) * audio.duration;
954        audio.currentTime = timeToSeek;
955      },
956      false
957    );
958    //click volume slider to change volume
959    const volumeSlider = audioPlayer.querySelector(".controls .volume-slider");
960    volumeSlider.addEventListener(
961      "click",
962      (e) => {
963        const sliderWidth = window.getComputedStyle(volumeSlider).width;
964        const newVolume = e.offsetX / parseInt(sliderWidth);
965        audio.volume = newVolume;
966        audioPlayer.querySelector(".controls .volume-percentage").style.width =
967          newVolume * 100 + "%";
968      },
969      false
970    );
971
972    //check audio percentage and update time accordingly
973    var getTime;
974    setInterval(() => {
975      const progressBar = audioPlayer.querySelector(".progress");
976      progressBar.style.width =
977        (audio.currentTime / audio.duration) * 100 + "%";
978      audioPlayer.querySelector(".time .current b").textContent =
979        getTimeCodeFromNum(audio.currentTime);
980      getTime = getTimeCodeFromNum(audio.currentTime);
981    }, 500);
982
983    //toggle between playing and pausing on button click
984    const playBtn = audioPlayer.querySelector(".controls .toggle-play");
985
986    playBtn.addEventListener(
987      "click",
988      () => {
989        if (audio.paused) {
990          playBtn.classList.remove("play");
991          playBtn.classList.add("pause");
992          audio.play();
993        } else {
994          playBtn.classList.remove("pause");
995          playBtn.classList.add("play");
996          audio.pause();
997        }
998      },
999      false
1000    );
1001
1002    audioPlayer
1003      .querySelector(".volume-button")
1004      .addEventListener("click", () => {
1005        const volumeEl = audioPlayer.querySelector(".volume-container .volume");
1006        audio.muted = !audio.muted;
1007        if (audio.muted) {
1008          volumeEl.classList.remove("icono-volumeMedium");
1009          volumeEl.classList.add("icono-volumeMute");
1010        } else {
1011          volumeEl.classList.add("icono-volumeMedium");
1012          volumeEl.classList.remove("icono-volumeMute");
1013        }
1014      });
1015
1016    //turn 128 seconds into 2:08
1017    function getTimeCodeFromNum(num) {
1018      let seconds = parseInt(num);
1019      let minutes = parseInt(seconds / 60);
1020      seconds -= minutes * 60;
1021      const hours = parseInt(minutes / 60);
1022      minutes -= hours * 60;
1023
1024      if (hours === 0)
1025        return `${minutes}:${String(seconds % 60).padStart(2, 0)}`;
1026      return `${String(hours).padStart(
1027        2,
1028        0
1029      )}:${minutes}:${String(seconds % 60).padStart(2, 0)}`;
1030    }
1031  });
1032});
1033
1034$(".box-tab").each(function () {
1035  var checkData = $(this).find(".tab-btn.active").attr("data-tab-list");
1036  if ($(this).find(".tab-btn.active").hasClass("search")) {
1037    $(this)
1038      .closest(".wrapper")
1039      .find(".tab-list.accor-ref-" + checkData)
1040      .show();
1041  } else if ($(this).find(".tab-btn.active").hasClass("ac-sta-trak")) {
1042    $(this)
1043      .closest(".wrapper")
1044      .find(".tab-list.accor-ref-" + checkData)
1045      .show();
1046  } else if ($(this).find(".tab-btn.active").hasClass("faq")) {
1047    $(this)
1048      .closest(".wrapper")
1049      .find(".tab-list.accor-ref-" + checkData)
1050      .show();
1051  } else {
1052    $(this)
1053      .siblings(".tab-list.accor-ref-" + checkData)
1054      .show();
1055  }
1056});
1057
1058$(".box-tab ul li .tab-btn").click(function () {
1059  if (!$(this).hasClass("btn-not-active")) {
1060    var dataTabList = $(this).attr("data-tab-list");
1061    if (!$(this).closest(".box-tab").hasClass("under-line")) {
1062      var tabTitle = $(this).text();
1063      $(this).closest(".banner-wrap").find(".txt-content h1 b").text(tabTitle);
1064    }
1065
1066    if ($(this).hasClass("active")) {
1067    } else {
1068      $(this).closest(".box-tab").find(".tab-btn.active").removeClass("active");
1069      $(this).addClass("active");
1070      $(this).closest("form").find("input[name=billing_type]").val(dataTabList);
1071      if ($(this).hasClass("search")) {
1072        $(this).closest(".wrapper").find(".tab-list").hide();
1073        $(this)
1074          .closest(".wrapper")
1075          .find(".tab-list.accor-ref-" + dataTabList)
1076          .show();
1077      } else if ($(this).hasClass("ac-sta-trak")) {
1078        $(this).closest(".wrapper").find(".tab-list").hide();
1079        $(this)
1080          .closest(".wrapper")
1081          .find(".tab-list.accor-ref-" + dataTabList)
1082          .show();
1083      } else if ($(this).hasClass("faq")) {
1084        $(this).closest(".wrapper").find(".tab-list").hide();
1085        $(this)
1086          .closest(".wrapper")
1087          .find(".tab-list.accor-ref-" + dataTabList)
1088          .show();
1089      } else {
1090        $(this).closest(".box-tab").siblings(".tab-list").hide();
1091        $(this)
1092          .closest(".box-tab")
1093          .siblings(".tab-list.accor-ref-" + dataTabList)
1094          .show();
1095      }
1096    }
1097  }
1098});
1099
1100function boxTabSwith() {
1101  $(".box-tab-swith").each(function () {
1102    var checkData = $(this).find(".tab-btn.active").attr("data-tab-list");
1103    $(this)
1104      .closest(".swith-product")
1105      .find(".swith-list .swith-content-" + checkData)
1106      .show();
1107    if (winW > 991) {
1108      if (checkData == 0) {
1109        $(".tab-review").hide();
1110        $(".sec-scrollbar-progress-isreview").hide();
1111        $(".tab-info").show();
1112        $(".sec-scrollbar-progress").show();
1113
1114        $(".tab-review").removeClass("show");
1115        $(".tab-info").addClass("show");
1116      } else if (checkData == 1) {
1117        $(".tab-info").removeClass("show");
1118        $(".tab-review").addClass("show");
1119
1120        $(".tab-review").show();
1121        $(".sec-scrollbar-progress-isreview").show();
1122        $(".tab-info").hide();
1123        $(".sec-scrollbar-progress").hide();
1124      }
1125    }
1126  });
1127}
1128
1129if ($(".check-acc").length > 0) {
1130  $(".check-acc").each(function () {
1131    if ($(this).is(":checked")) {
1132      $(this).closest(".form-check").find(".acc-check-box").slideToggle();
1133      $(this).addClass("active");
1134    }
1135  });
1136}
1137$(".check-acc").click(function () {
1138  if ($(this).is(":checked") && !$(this).hasClass("active")) {
1139    $(".acc-check-box").slideUp();
1140    $(".check-acc").removeClass("active");
1141
1142    $(this).addClass("active");
1143    $(this).closest(".form-check").find(".acc-check-box").slideToggle();
1144  } else {
1145  }
1146});
1147
1148$(".box-tab-swith ul li .tab-btn").click(function () {
1149  var dataTabList = $(this).attr("data-tab-list");
1150  if ($(this).hasClass("active")) {
1151  } else {
1152    $(this)
1153      .closest(".box-tab-swith")
1154      .find(".tab-btn.active")
1155      .removeClass("active");
1156    $(this).addClass("active");
1157
1158    if (winW > 991) {
1159      if (dataTabList == 0) {
1160        $(".tab-review").hide();
1161        $(".sec-scrollbar-progress-isreview").hide();
1162        $(".tab-info").show();
1163        $(".sec-scrollbar-progress").show();
1164
1165        $(".tab-review").removeClass("show");
1166        $(".tab-info").addClass("show");
1167      } else if (dataTabList == 1) {
1168        $(".tab-info").removeClass("show");
1169        $(".tab-review").addClass("show");
1170
1171        $(".tab-review").show();
1172        $(".sec-scrollbar-progress-isreview").show();
1173        $(".tab-info").hide();
1174        $(".sec-scrollbar-progress").hide();
1175      }
1176    }
1177
1178    $(this).closest(".swith-product").find(".swith-content").hide();
1179    $(this)
1180      .closest(".swith-product")
1181      .find(".swith-list .swith-content-" + dataTabList)
1182      .show();
1183  }
1184});
1185
1186if (winW < 768) {
1187  $(".tab-search").click(function () {
1188    $(".tab-md-select ul").slideToggle();
1189  });
1190
1191  $(".tab-md-select li a").click(function () {
1192    var content_select = $(this).html();
1193    if (!$(this).hasClass("onbb-block-animation")) {
1194      $(".tab-search span").html(content_select);
1195      $(".tab-md-select ul").slideUp();
1196    }
1197  });
1198}
1199
1200$(".tab-user ul li a").click(function () {
1201  var dataTab = $(this).attr("data-tab");
1202  if (!$(this).hasClass("active")) {
1203    $(".tab-user ul li a").removeClass("active");
1204    $(".login-content").find(".tab-group").removeClass("active");
1205
1206    $(this).addClass("active");
1207    $(this)
1208      .closest(".login-content")
1209      .find(".tab-" + dataTab)
1210      .addClass("active");
1211  } else {
1212  }
1213});
1214
1215$(".view-pass").click(function () {
1216  if ($(this).hasClass("view-open")) {
1217    $(this).closest(".fw").find("input").attr("type", "password");
1218    $(this).removeClass("view-open");
1219  } else {
1220    $(this).closest(".fw").find("input").attr("type", "text");
1221    $(this).addClass("view-open");
1222  }
1223});
1224
1225$(".login-btn").click(function () {
1226  $(".box-delivery-detail").show();
1227  $(".box-delivery-form").hide();
1228  var classpopin = "popup-login";
1229  $("." + classpopin).fadeOut();
1230  var removeLock = $("body").prop("style");
1231  removeLock.removeProperty("overflow");
1232});
1233
1234function calScroll() {
1235  if ($(".box-form-scroll").length > 0) {
1236    $(".box-form-scroll").each(function () {
1237      setTimeout(() => {
1238        var maxH =
1239          $(this).closest(".popup-container").height() -
1240          $(".tab-user").outerHeight() -
1241          $(".box-user-title").outerHeight() -
1242          140;
1243        $(this).css("max-height", maxH + "px");
1244      }, 200);
1245    });
1246  }
1247}
1248
1249function genHBanner() {
1250  setTimeout(() => {
1251    if (
1252      $(".section-header").hasClass("bgs-tr") ||
1253      $(".section-header").hasClass("bgs-tr-scroll")
1254    ) {
1255      if (!$(".sec-stick-top").hasClass("hide")) {
1256        var getH = $(".sec-stick-top").outerHeight();
1257        $(".wrapper").css("padding-top", getH + "px");
1258        $(".head-wrap").css("top", getH + "px");
1259      }
1260    } else {
1261      var getH;
1262      if ($(".sec-stick-top").length > 0) {
1263        if (!$(".sec-stick-top").hasClass("hide")) {
1264          getH =
1265            $(".sec-stick-top").outerHeight() +
1266            $(".section-header").outerHeight();
1267        } else {
1268          getH = 0;
1269        }
1270      } else {
1271        getH = $(".section-header").outerHeight();
1272      }
1273      $(".wrapper").css("padding-top", getH + "px");
1274      $(".head-wrap").css("top", $(".sec-stick-top").outerHeight() + "px");
1275    }
1276  }, 100);
1277}
1278
1279function headerSetting() {
1280  var hearder = $(".section-header");
1281  var attrHeader = $(".wrapper").attr("data-header");
1282  var attrColor = $(".wrapper").attr("data-menu-color");
1283
1284  if (attrHeader == "menu-tr") {
1285    hearder.addClass("bgs-tr");
1286    hearder.addClass("bgs-tr-scroll");
1287    menuScroll();
1288    if (winW < 992) {
1289      $(".section-header.bgs-tr").addClass("nohover");
1290    }
1291  } else {
1292  }
1293  if (attrColor == "txt-primary") {
1294    hearder.addClass("txt-primary");
1295  }
1296}
1297
1298function compSlideFade() {
1299  $(".comp-slide-fade").each(function () {
1300    var thisComFade = $(this);
1301    var compSlideFade = new Swiper($(this).find(".comp-slide-fade-custom"), {
1302      effect: "fade",
1303      slidesPerView: 1,
1304      updateOnWindowResize: true,
1305      paginationClickable: true,
1306      allowTouchMove: false,
1307      loop: false,
1308
1309      speed: 1000,
1310      navigation: {
1311        nextEl: $(this).find(".swiper-button-next"),
1312        prevEl: $(this).find(".swiper-button-prev"),
1313      },
1314      pagination: {
1315        el: ".swiper-pagination",
1316        clickable: true,
1317      },
1318    });
1319
1320    compSlideFade.on("slideChange", function () {
1321      setTimeout(function () {
1322        var compSlideFade_animate = new TimelineLite();
1323        compSlideFade_animate.fromTo(
1324          $(".comp-slide-fade-custom .swiper-slide-active .box-imgbg"),
1325          2,
1326          { alpha: 0, x: 50 },
1327          { alpha: 1, x: 0, ease: Power3.easeOut, delay: 0.5 }
1328        );
1329      }, 100);
1330    });
1331
1332    $(this)
1333      .find(
1334        ".list-step-slide-content .step-item-" + (compSlideFade.activeIndex + 1)
1335      )
1336      .addClass("active");
1337
1338    compSlideFade.on("slideChange", function () {
1339      var stepItem = compSlideFade.activeIndex;
1340      thisComFade
1341        .find(".list-step-slide-content .step-item-content")
1342        .removeClass("active");
1343      thisComFade
1344        .find(".list-step-slide-content .step-item-" + (stepItem + 1))
1345        .addClass("active");
1346    });
1347  });
1348}
1349
1350function menuScroll() {
1351  var startSec = $("#start-section").outerHeight();
1352  $(window).scroll(function () {
1353    if ($(this).scrollTop() > 100) {
1354      $(".section-header.bgs-tr").removeClass("bgs-tr");
1355    } else {
1356      $(".section-header").addClass("bgs-tr");
1357    }
1358  });
1359}
1360
1361function calHBtn() {
1362  var allH = $(".comp-slide-button").outerHeight();
1363  var contentH = $(".banner-content").outerHeight();
1364  var imgH = $(".box-imgbg").outerHeight();
1365  $(".comp-slide-button .swiper-button").css("bottom", imgH / 2 + "px");
1366}
1367
1368function emailLogin($this) {
1369  var form = $this.closest("form");
1370  var wrapper = $this.closest(".wrapper");
1371  var ship_type_el = wrapper
1372    .find(".form-step.form-step-1")
1373    .find("input[name=transfer]:checked");
1374  var ship_type_val = ship_type_el.attr("data-trans");
1375
1376  form.find("input[name=ship_type]").val(ship_type_val);
1377  form.submit();
1378}
1379
1380function check_otp_login_page($this) {
1381  popout_name("popup-otp-cart");
1382  var popup_phone_login_form = $this
1383    .closest("body")
1384    .find(".login-content")
1385    .find(".login-phone-number")
1386    .closest("form");
1387  var wrapper = $this.closest("body").find(".wrapper");
1388  var ship_type_el = wrapper
1389    .find(".form-step.form-step-1")
1390    .find("input[name=transfer]:checked");
1391  var ship_type_val = ship_type_el.attr("data-trans");
1392  popup_phone_login_form.find("input[name=ship_type]").val(ship_type_val);
1393  popup_phone_login_form.submit();
1394}
1395
1396function check_otp_login($this) {
1397  var lang = $("html").attr("lang");
1398  var phone_number = $this
1399    .closest(".row")
1400    .find("input[name=phone_number]")
1401    .val();
1402  var otp_el = $this
1403    .closest("body")
1404    .find(".section-popup.popup-login-otp")
1405    .find(".otp-title");
1406  var otp_title_open = "<b>Please enter OTP sent to +66";
1407  if (lang == "th") {
1408    otp_title_open = "<b>กรุณากรอกรหัส OTP ที่ส่งไปยังเบอร์ +66";
1409  }
1410  var otp_title_close = "</b>";
1411  var otp_title =
1412    otp_title_open +
1413    phone_number[1] +
1414    phone_number[2] +
1415    " " +
1416    phone_number[3] +
1417    phone_number[4] +
1418    phone_number[5] +
1419    " " +
1420    phone_number[6] +
1421    phone_number[7] +
1422    phone_number[8] +
1423    phone_number[9] +
1424    otp_title_close;
1425  otp_el.empty();
1426  otp_el.html(otp_title);
1427  popin_name("popup-login-otp");
1428}
1429
1430function check_otp($this) {
1431  popout_name("popup-otp-cart");
1432  var popup_register_form = $this
1433    .closest("body")
1434    .find(".section-popup.popup-login")
1435    .find(".tab-group.tab-register")
1436    .find("form");
1437  var wrapper = $this.closest("body").find(".wrapper");
1438  var ship_type_el = wrapper
1439    .find(".form-step.form-step-1")
1440    .find("input[name=transfer]:checked");
1441  var ship_type_val = ship_type_el.attr("data-trans");
1442  popup_register_form.find("input[name=ship_type]").val(ship_type_val);
1443  popup_register_form.submit();
1444}
1445
1446function popin_otp_name(popin_name) {
1447  $(".section-popup").fadeOut();
1448  $("." + popin_name).fadeIn();
1449  document.body.style.overflow = "hidden";
1450}
1451
1452function popin_name(popin_name) {
1453  $(".section-popup").fadeOut();
1454  $("." + popin_name).fadeIn();
1455  document.body.style.overflow = "hidden";
1456}
1457
1458function popin(popin_name, thisData) {
1459  if (popin_name === "popup-edit-address-login") {
1460    getShipAddress(thisData);
1461  } else if (popin_name === "popup-edit-profile") {
1462    getMemberData(thisData);
1463  } else if (popin_name === "popup-edit-tax-invoice") {
1464    getTaxData(thisData);
1465  } else if (popin_name === "popup-cancel") {
1466    var popup_elem = $("body").find(".popup-cancel");
1467    popup_elem.find("input[name=order_id]").val(thisData.attr("data-orderid"));
1468    popup_elem
1469      .find("input[name=order_number]")
1470      .val(thisData.attr("data-ordernum"));
1471  }
1472
1473  $(".section-popup").fadeOut();
1474  $("." + popin_name).fadeIn();
1475  document.body.style.overflow = "hidden";
1476}
1477
1478function popout_name(popout_name) {
1479  var classpopin = popout_name;
1480  $("." + classpopin).fadeOut();
1481
1482  var removeLock = $("body").prop("style");
1483  removeLock.removeProperty("overflow");
1484}
1485
1486function popout(popout_name) {
1487  var classpopin = popout_name.attr("data-popup");
1488  $("." + classpopin).fadeOut();
1489
1490  var removeLock = $("body").prop("style");
1491  removeLock.removeProperty("overflow");
1492
1493  if (interval == false) {
1494  } else {
1495    clearInterval(interval);
1496    $(".count-end-resend").empty();
1497    $(".countdown").html("");
1498    $(".box-otp-form.inputs > input[type=number]").val("");
1499  }
1500}
1501
1502function popOtpBtn(thisPop) {
1503  var otp_el = thisPop.closest("body").find(".popup-otp");
1504  var lang = $("html").attr("lang");
1505  if (thisPop.hasClass("otp-track")) {
1506    var form = otp_el.find("form");
1507    form.attr(
1508      "action",
1509      window.location.origin + "/login/do_login_mobile_order_status"
1510    );
1511    var outside_parent = thisPop.parent().parent();
1512    var phone_number_el = outside_parent.find("input[type=tel]");
1513    var phone_number_wrel = phone_number_el.parent();
1514    var phone_number = phone_number_el.val();
1515  } else if (thisPop.hasClass("otp-login")) {
1516    var outside_parent = thisPop.parent().parent().parent();
1517    var phone_number_el = outside_parent.find("input[type=tel]");
1518    var phone_number_wrel = phone_number_el.parent();
1519    var phone_number = phone_number_el.val();
1520  } else if (thisPop.hasClass("otp-login-popup")) {
1521    var outside_parent = thisPop.parent().parent().parent();
1522    var phone_number_el = outside_parent.find("input[type=tel]");
1523    var phone_number_wrel = phone_number_el.parent();
1524    var phone_number = phone_number_el.val();
1525
1526    var wrapper = thisPop.closest("body").find(".wrapper");
1527    var ship_type_el = wrapper
1528      .find(".form-step.form-step-1")
1529      .find("input[name=transfer]:checked");
1530    var ship_type_val = ship_type_el.attr("data-trans");
1531    var form = thisPop.closest("form");
1532
1533    form.find("input[name=ship_type]").val(ship_type_val);
1534    thisPop
1535      .closest("body")
1536      .find(".popup-otp")
1537      .find(".otp-popup-form")
1538      .find("button.validate")
1539      .addClass("login-mob-popup");
1540  } else if (thisPop.hasClass(".prod-regis-otp")) {
1541    var outside_parent = thisPop.parent().parent().parent();
1542    var phone_number_el = outside_parent.find("input[type=tel]");
1543    var phone_number_wrel = phone_number_el.parent();
1544    var phone_number = phone_number_el.val();
1545  } else if (thisPop.hasClass("checkout-regis")) {
1546    var outside_parent = thisPop.closest("form");
1547    var phone_number_el = outside_parent.find("input[name=ship_phone_number]");
1548    var phone_number_wrel = phone_number_el.parent();
1549    var phone_number = phone_number_el.val();
1550  }
1551
1552  if (phone_number === "") {
1553    if (lang != "en") {
1554      phone_number_el.siblings(".validate").html("กรุณากรอกเบอร์โทรศัพท์");
1555    } else {
1556      phone_number_el
1557        .siblings(".validate")
1558        .html("Please enter your phone number");
1559    }
1560    phone_number_wrel.addClass("error");
1561  } else if (phone_number.length != 10) {
1562    if (lang != "en") {
1563      phone_number_el
1564        .siblings(".validate")
1565        .html("กรุณากรอกเบอร์โทรศัพท์ให้ครบ 10 หลัก");
1566    } else {
1567      phone_number_el
1568        .siblings(".validate")
1569        .html("Please enter a valid 10-digit phone number");
1570    }
1571    phone_number_wrel.addClass("error");
1572  } else {
1573    phone_number_wrel.removeClass("error");
1574    var otp_ti_el = otp_el.find(".otp-title");
1575    var otp_title_open = "<b>Please enter OTP sent to +66";
1576    if (lang == "th") {
1577      otp_title_open = "<b>กรุณากรอกรหัส OTP ที่ส่งไปยังเบอร์ +66";
1578    }
1579    var otp_title_close = "</b>";
1580    var otp_title =
1581      otp_title_open +
1582      phone_number[1] +
1583      phone_number[2] +
1584      " " +
1585      phone_number[3] +
1586      phone_number[4] +
1587      phone_number[5] +
1588      " " +
1589      phone_number[6] +
1590      phone_number[7] +
1591      phone_number[8] +
1592      phone_number[9] +
1593      otp_title_close;
1594    otp_ti_el.empty();
1595    otp_ti_el.html(otp_title);
1596
1597    if (thisPop.hasClass("otp-login")) {
1598      var otp_is_login =
1599        '<input type="hidden" name="otp-is-login" value="1"></input>';
1600      otp_el.find("form").prepend(otp_is_login);
1601    } else {
1602      var otp_is_login =
1603        '<input type="hidden" name="otp-is-login" value="0"></input>';
1604      otp_el.find("form").prepend(otp_is_login);
1605    }
1606
1607    otp_button =
1608      '<input type="hidden" name="otp-phone" value="' +
1609      phone_number +
1610      '"></input>';
1611    otp_el.find("form").prepend(otp_button);
1612
1613    popin(thisPop.attr("data-popup"), thisPop);
1614
1615    sendOtp(thisPop.closest("form"), otp_el);
1616    settimer("otp-login", "");
1617  }
1618}
1619
1620function popEditAddress(thisPop) {
1621  popin(thisPop.attr("data-popup"), thisPop);
1622}
1623function popAddAddress(thisPop) {
1624  popin(thisPop.attr("data-popup"), thisPop);
1625}
1626function popAddAddressLogin(thisPop) {
1627  popin(thisPop.attr("data-popup"), thisPop);
1628}
1629function popEditProfile(thisPop) {
1630  popin(thisPop.attr("data-popup"), thisPop);
1631}
1632function popSerial(thisPop) {
1633  popin(thisPop.attr("data-popup"), thisPop);
1634}
1635function popAddTax(thisPop) {
1636  popin(thisPop.attr("data-popup"), thisPop);
1637}
1638function popAddTaxLogin(thisPop) {
1639  popin(thisPop.attr("data-popup"), thisPop);
1640}
1641function popEditTaxAddress(thisPop) {
1642  popin(thisPop.attr("data-popup"), thisPop);
1643}
1644function popAddImgReview(thisPop) {
1645  popin(thisPop.attr("data-popup"), thisPop);
1646}
1647function popCartLogin(thisPop) {
1648  popin(thisPop.attr("data-popup"), thisPop);
1649}
1650
1651function popCancel(thisPop) {
1652  popin(thisPop.attr("data-popup"), thisPop);
1653}
1654
1655function validateCancel($this) {
1656  var form = $this.closest("form");
1657  var popup_body = form.find(".popup-body");
1658  var detail = popup_body.find("textarea[name=cancel-detail]");
1659  var type = popup_body.find("input.type:checked");
1660  validate = true;
1661  $(".form-check").removeClass("has-danger");
1662  $(".form-group").removeClass("has-danger");
1663  if (type.val() == 3) {
1664    var text = popup_body.find("input.other-report");
1665    if (text.val() === "") {
1666      validate = false;
1667      text.closest(".form-check").addClass("has-danger");
1668    }
1669  }
1670
1671  if (detail.val() === "") {
1672    validate = false;
1673    detail.closest(".form-group").addClass("has-danger");
1674  }
1675
1676  if (validate) {
1677    form.submit();
1678  }
1679}
1680
1681function validateShipAddress($this) {
1682  var validate = true;
1683  var form = $this.closest("form");
1684
1685  var add_name = form.find(".add_name").find("input[name=address_name]");
1686  var first = form.find(".first").find("input[name=first_name]");
1687  var last = form.find(".last").find("input[name=last_name]");
1688  var email = form.find(".email").find("input[name=email]");
1689  var phone = form.find(".phone").find("input[name=phone_number]");
1690  var add_detail = form.find(".add_detail").find("input[name=address_detail]");
1691  var prov = form.find(".prov").find("select");
1692  var dist = form.find(".dist").find("select");
1693  var sub_dis = form.find(".sub_dis").find("select");
1694  var zip = form.find(".zip").find("select");
1695
1696  add_name.closest(".add_name").removeClass("error");
1697  first.closest(".first").removeClass("error");
1698  last.closest(".last").removeClass("error");
1699  email.closest(".email").removeClass("error");
1700  phone.closest(".phone").removeClass("error");
1701  add_detail.closest(".add_detail").removeClass("error");
1702  prov.closest(".prov").removeClass("error");
1703  dist.closest(".dist").removeClass("error");
1704  sub_dis.closest(".sub_dis").removeClass("error");
1705  zip.closest(".zip").removeClass("error");
1706
1707  if (add_name.val() === "") {
1708    add_name.closest(".add_name").addClass("error");
1709    validate = false;
1710  }
1711  if (first.val() === "") {
1712    first.closest(".first").addClass("error");
1713    validate = false;
1714  }
1715  if (last.val() === "") {
1716    last.closest(".last").addClass("error");
1717    validate = false;
1718  }
1719  if (email.val() === "") {
1720    email.closest(".email").addClass("error");
1721    var e_pat = email.closest(".email").find(".validate");
1722    e_pat.empty();
1723    e_pat.html("กรุณากรอก E-Mail");
1724    email.closest(".email").addClass("error");
1725    validate = false;
1726  } else if (email.val() !== "" && !validEmail(email)) {
1727    validate = false;
1728  }
1729
1730  if (phone.val() === "") {
1731    phone.parent().parent().find(".validate").html("กรุณากรอกเบอร์โทรศัพท์");
1732    phone.closest(".phone").addClass("error");
1733    validate = false;
1734  } else if (phone.val().length != 10) {
1735    phone
1736      .parent()
1737      .parent()
1738      .find(".validate")
1739      .html("กรุณากรอกเบอร์โทรศัพท์ให้ครบ 10 หลัก");
1740    phone.closest(".phone").addClass("error");
1741    validate = false;
1742  }
1743
1744  if (add_detail.val() === "") {
1745    add_detail.closest(".add_detail").addClass("error");
1746    validate = false;
1747  }
1748
1749  if (prov.val() == 0) {
1750    prov.closest(".prov").addClass("error");
1751    validate = false;
1752  } else {
1753    if (dist.val() == "") {
1754      dist.closest(".dist").addClass("error");
1755      validate = false;
1756    } else {
1757      if (sub_dis.val() == "") {
1758        sub_dis.closest(".sub_dis").addClass("error");
1759        validate = false;
1760      } else {
1761        if (zip.val() == "") {
1762          zip.closest(".zip").addClass("error");
1763          validate = false;
1764        }
1765      }
1766    }
1767  }
1768
1769  if (validate) {
1770    if ($this.hasClass("add-ship-add-log")) {
1771      addShipAddressLogin($this);
1772    } else if ($this.hasClass("add-ship-addr")) {
1773      addShipAddress($this);
1774    }
1775  }
1776}
1777
1778function validateUpdateShipAddress($this) {
1779  var validate = true;
1780  var form = $this.closest("form");
1781
1782  var add_name = form.find(".add_name").find("input[name=address_name]");
1783  var first = form.find(".first").find("input[name=first_name]");
1784  var last = form.find(".last").find("input[name=last_name]");
1785  var email = form.find(".email").find("input[name=email]");
1786  var phone = form.find(".phone").find("input[name=phone_number]");
1787  var add_detail = form.find(".add_detail").find("input[name=address_detail]");
1788  var prov = form.find(".prov").find("select");
1789  var dist = form.find(".dist").find("select");
1790  var sub_dis = form.find(".sub_dis").find("select");
1791  var zip = form.find(".zip").find("select");
1792
1793  add_name.closest(".add_name").removeClass("error");
1794  first.closest(".first").removeClass("error");
1795  last.closest(".last").removeClass("error");
1796  email.closest(".email").removeClass("error");
1797  phone.closest(".phone").removeClass("error");
1798  add_detail.closest(".add_detail").removeClass("error");
1799  prov.closest(".prov").removeClass("error");
1800  dist.closest(".dist").removeClass("error");
1801  sub_dis.closest(".sub_dis").removeClass("error");
1802  zip.closest(".zip").removeClass("error");
1803
1804  if (add_name.val() === "") {
1805    add_name.closest(".add_name").addClass("error");
1806    validate = false;
1807  }
1808  if (first.val() === "") {
1809    first.closest(".first").addClass("error");
1810    validate = false;
1811  }
1812  if (last.val() === "") {
1813    last.closest(".last").addClass("error");
1814    validate = false;
1815  }
1816  if (email.val() === "") {
1817    email.closest(".email").addClass("error");
1818    var e_pat = email.closest(".email").find(".validate");
1819    e_pat.empty();
1820    e_pat.html("กรุณากรอก E-Mail");
1821    email.closest(".email").addClass("error");
1822    validate = false;
1823  } else if (email.val() !== "" && !validEmail(email)) {
1824    validate = false;
1825  }
1826
1827  if (phone.val() === "") {
1828    phone.parent().parent().find(".validate").html("กรุณากรอกเบอร์โทรศัพท์");
1829    phone.closest(".phone").addClass("error");
1830    validate = false;
1831  } else if (phone.val().length != 10) {
1832    phone
1833      .parent()
1834      .parent()
1835      .find(".validate")
1836      .html("กรุณากรอกเบอร์โทรศัพท์ให้ครบ 10 หลัก");
1837    phone.closest(".phone").addClass("error");
1838    validate = false;
1839  }
1840
1841  if (add_detail.val() === "") {
1842    add_detail.closest(".add_detail").addClass("error");
1843    validate = false;
1844  }
1845
1846  if (prov.val() == 0) {
1847    prov.closest(".prov").addClass("error");
1848    validate = false;
1849  } else {
1850    if (dist.val() == "") {
1851      dist.closest(".dist").addClass("error");
1852      validate = false;
1853    } else {
1854      if (sub_dis.val() == "") {
1855        sub_dis.closest(".sub_dis").addClass("error");
1856        validate = false;
1857      } else {
1858        if (zip.val() == "") {
1859          zip.closest(".zip").addClass("error");
1860          validate = false;
1861        }
1862      }
1863    }
1864  }
1865
1866  if (validate) {
1867    updateShipAddress($this);
1868  }
1869}
1870
1871function tax_invoice_nolog($this) {
1872  if ($this.prop("checked")) {
1873    $(".form-taxinv-nolog").show();
1874  } else {
1875    $(".form-taxinv-nolog").hide();
1876  }
1877}
1878
1879function tax_invoice_log($this) {
1880  if ($this.prop("checked")) {
1881    $(".form-taxinv-log").show();
1882  } else {
1883    $(".form-taxinv-log").hide();
1884  }
1885}
1886
1887function changeMap($this) {
1888  var lat = $this.attr("data-lat");
1889  var long = $this.attr("data-long");
1890  var src =
1891    "https://maps.google.com/maps?width=100%25&height=600&hl=en&q=" +
1892    lat +
1893    "," +
1894    long +
1895    "+(My%20Business%20Name)&t=&z=14&ie=UTF8&iwloc=B&output=embed";
1896  $this
1897    .closest(".order-list-dealer")
1898    .siblings(".order-list-map")
1899    .find("iframe")
1900    .attr("src", src);
1901}
1902
1903function popVideoBtn(thisVideo) {
1904  popin(thisVideo.attr("data-popup"));
1905  dataVideo = thisVideo.attr("data-video");
1906  $(".popup-video .click-to-play-video").trigger("click");
1907}
1908var player;
1909var dataVideo;
1910var interval = false;
1911$(document).ready(function () {
1912  $('[data-toggle="tooltip"]').tooltip();
1913  $("select").selectpicker();
1914
1915  $(".popup-video .click-to-play-video").click(function () {
1916    $(this).addClass("hidePreview");
1917    player = new YT.Player("player", {
1918      width: "100%",
1919      height: "100%",
1920      videoId: dataVideo,
1921      playerVars: {
1922        autoplay: 1,
1923        controls: 0,
1924        showinfo: 0,
1925        modestbranding: 1,
1926        iv_load_policy: 3,
1927      },
1928      events: {
1929        onReady: onPlayerReady,
1930        onStateChange: onPlayerStateChange,
1931      },
1932    });
1933  });
1934
1935  var tag = document.createElement("script");
1936  tag.src = "https://www.youtube.com/iframe_api";
1937  var firstScriptTag = document.getElementsByTagName("script")[0];
1938  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
1939
1940  function onPlayerReady(event) {
1941    event.target.playVideo();
1942  }
1943  function onPlayerStateChange(event) {
1944    if (event.data == YT.PlayerState.ENDED) {
1945      player.destroy();
1946      $(".popup-video .click-to-play-video").removeClass("hidePreview");
1947      $(".closeVideo").trigger("click");
1948    }
1949  }
1950  $(".closeVideo").click(function () {
1951    if (
1952      $(".popup-video .video-container.click-to-play-video").hasClass(
1953        "hidePreview"
1954      )
1955    ) {
1956      player.destroy();
1957      $(".popup-video .video-container.click-to-play-video").removeClass(
1958        "hidePreview"
1959      );
1960    }
1961  });
1962
1963  $(".box-product-list.product-list-tab").click(function () {
1964    $(".box-product-list.product-list-tab").removeClass("active");
1965    var data = $(this).attr("data-tab-product");
1966    $(this).addClass("active");
1967    $(".product-list").removeClass("active");
1968    $(".product-list-" + data).addClass("active");
1969  });
1970});
1971/////////////////////////////////////////
1972///////////// Upload Avatar /////////////
1973/////////////////////////////////////////
1974function imageUpload($this) {
1975  readURL($this);
1976}
1977
1978function readURL(input) {
1979  var avatar_validate = input
1980    .parent()
1981    .siblings(".txt-content")
1982    .find(".avatar-validate");
1983
1984  if (input[0].files[0].size <= 1048576) {
1985    if (input[0].files && input[0].files[0]) {
1986      avatar_validate.removeClass("error");
1987      var reader = new FileReader();
1988      var file = URL.createObjectURL(input[0].files[0]);
1989      reader.onload = function (e) {
1990        $("#imagePreviewPop").css("background-image", "url(" + file + ")");
1991        $("#imagePreviewPop").hide();
1992        $("#imagePreviewPop").fadeIn(650);
1993      };
1994      reader.readAsDataURL(input[0].files[0]);
1995    }
1996  } else {
1997    $("#imagePreviewPop").hide();
1998    input.val("");
1999    avatar_validate.addClass("error");
2000  }
2001}
2002
2003$(document).ready(function () {
2004  // Initially hide the element
2005  $(".stick-product-add").hide();
2006
2007  $(window).scroll(function () {
2008    sticky_download();
2009  });
2010});
2011
2012function sticky_download() {
2013  var height_win = $(window).height();
2014  if (
2015    $(window).scrollTop() <=
2016    500 +
2017      $(".section-header").outerHeight() +
2018      $(".product-detail").outerHeight() +
2019      $(".box-tab-swith").outerHeight() -
2020      height_win
2021  ) {
2022    $(".stick-product-add").fadeOut();
2023  } else {
2024    $(".stick-product-add").css({ "z-index": "8" });
2025    $(".stick-product-add").fadeIn();
2026  }
2027}
2028
2029function awardSlide() {
2030  $(".award-slide").each(function () {
2031    var awardSlide = new Swiper($(this).find(".swiper-container"), {
2032      slidesPerView: 4,
2033      loop: false,
2034      simulateTouch: false,
2035      slidesPerColumn: 2,
2036      spaceBetween: 20,
2037      breakpoints: {
2038        575: {
2039          slidesPerView: 1.4,
2040          slidesPerColumn: 1,
2041          spaceBetween: 0,
2042          centeredSlides: false,
2043        },
2044        767: {
2045          slidesPerView: 1.8,
2046          slidesPerColumn: 1,
2047          spaceBetween: 0,
2048          centeredSlides: true,
2049        },
2050        991: {
2051          slidesPerView: 3,
2052          slidesPerColumn: 3,
2053        },
2054      },
2055    });
2056  });
2057}
2058/* ================================================ */
2059/* SET SVG */
2060/* ================================================ */
2061svg();
2062function svg() {
2063  $("img.svg").each(function () {
2064    var $img = $(this);
2065    var imgID = $img.attr("id");
2066    var imgClass = $img.attr("class");
2067    var imgURL = $img.attr("src");
2068
2069    $.get(
2070      imgURL,
2071      function (data) {
2072        // Get the SVG tag, ignore the rest
2073        var $svg = $(data).find("svg");
2074
2075        // Add replaced image's ID to the new SVG
2076        if (typeof imgID !== "undefined") {
2077          $svg = $svg.attr("id", imgID);
2078        }
2079        // Add replaced image's classes to the new SVG
2080        if (typeof imgClass !== "undefined") {
2081          $svg = $svg.attr("class", imgClass + " replaced-svg");
2082        }
2083
2084        // Remove any invalid XML tags as per http://validator.w3.org
2085        $svg = $svg.removeAttr("xmlns:a");
2086
2087        // Check if the viewport is set, else we gonna set it if we can.
2088        if (
2089          !$svg.attr("viewBox") &&
2090          $svg.attr("height") &&
2091          $svg.attr("width")
2092        ) {
2093          $svg.attr(
2094            "viewBox",
2095            "0 0 " + $svg.attr("height") + " " + $svg.attr("width")
2096          );
2097        }
2098
2099        // Replace image with new SVG
2100        $img.replaceWith($svg);
2101      },
2102      "xml"
2103    );
2104  });
2105}
2106/* ================================================ */
2107/* SET CANVA ICON JSON */
2108/* ================================================ */
2109
2110var icon_containers = document.querySelectorAll("div.icon");
2111var icons = [];
2112
2113function buildIcons() {
2114  path_url = "assets/img/skin/";
2115  for (var i = 0; i < icon_containers.length; i++) {
2116    element = icon_containers[i];
2117    if (element.id !== "") {
2118      var params = {
2119        container: element,
2120        renderer: "svg",
2121        loop: false,
2122        autoplay: false,
2123        path: path_url + element.id + ".json",
2124      };
2125      var anim = bodymovin.loadAnimation(params);
2126      icons.push({
2127        anim: anim,
2128        element: element,
2129        isPlaying: false,
2130      });
2131    }
2132  }
2133}
2134
2135function complete(icon) {
2136  console.log(icon + " loopComplete");
2137}
2138
2139function newComplete() {
2140  console.log(" loopComplete");
2141}
2142
2143function startAnimation(anim, icon) {
2144  anim.setDirection(1);
2145  anim.goToAndStop(1);
2146  anim.play();
2147  // This seems to fire immediately, before the icon has completed its animation?
2148  // anim.addEventListener('loopComplete', complete(icon));
2149
2150  // Suggestion
2151  // https://github.com/bodymovin/bodymovin/issues/622#issuecomment-331753202
2152  anim.addEventListener("loopComplete", newComplete);
2153}
2154
2155buildIcons();
2156
2157// icons.forEach(function(value, id) {
2158// 	startAnimation(value.anim, id);
2159// 	value.element.addEventListener("click", function(e) {
2160// 		startAnimation(value.anim, id);
2161// 	});
2162// });
2163
2164// Suggestion from author
2165// https://github.com/bodymovin/bodymovin/issues/622#issuecomment-330108113
2166icons.forEach(function (value, id) {
2167  value.anim.addEventListener("DOMLoaded", function () {
2168    startAnimation(value.anim, id);
2169    value.element.addEventListener("click", function (e) {
2170      startAnimation(value.anim, id);
2171    });
2172  });
2173});
2174
2175function genHeight(widthCheckX) {
2176  // Generate Height
2177  var winW = $(window).width();
2178  var source = "";
2179  var storeWidthCheck = widthCheckX;
2180
2181  if ($(".banner-h").length > 0) {
2182    $(".banner-h").each(function (index, value) {
2183      var self_width = $(this).outerWidth();
2184      var widthCheck = storeWidthCheck;
2185      data_column = $(this).attr("data-column");
2186      var ar_gen = [];
2187      ar_gen[index] = $(this);
2188
2189      if (
2190        $(this).closest(".sec").hasClass("sec-banner-item") &&
2191        $(this).closest(".sec").hasClass("hero-banner")
2192      ) {
2193        var bannerW = 991;
2194        if (winW >= 768 && winW < 992) {
2195          widthCheck = 576;
2196        }
2197      } else {
2198        var bannerW = 767;
2199        widthCheck;
2200      }
2201
2202      if (winW > bannerW) {
2203        $(".got-color-font-by-bg-size").removeClass("txt-white");
2204        source = $(this).attr("data-image-desktop");
2205      } else {
2206        $(".got-color-font-by-bg-size").addClass("txt-white");
2207        source = $(this).attr("data-image-mobile");
2208      }
2209
2210      var column = data_column;
2211
2212      var height = "";
2213      if (source != "") {
2214        var ar_img = [];
2215        ar_img[index] = new Image();
2216        ar_img[index].onload = function () {
2217          window_width = $(window).width() / column;
2218          widthCheck = widthCheck / column;
2219
2220          // height = winW <= 768 ? this.height - 150 : this.height;
2221          height = this.height;
2222          // if (winW <= 768) {
2223          //   height =
2224          //     this.height - 150 > 375 ? this.height - 100 : this.height - 150;
2225          // } else {
2226          //   height = this.height;
2227          // }
2228          width = this.width;
2229          if (column > 1) {
2230            height = (self_width * height) / width;
2231          } else {
2232            if (widthCheck == "") {
2233              height = (window_width * height) / width;
2234            } else {
2235              height = (widthCheck * height) / width;
2236            }
2237          }
2238
2239          height = height + "px";
2240          // alert(height);
2241          if (ar_gen[index].closest(".sec").hasClass("sec-banner-item")) {
2242            ar_gen[index].css({ height: height });
2243          } else {
2244            ar_gen[index].css({ minHeight: height });
2245          }
2246        };
2247        ar_img[index].src = source;
2248      }
2249    });
2250  }
2251}
2252
2253getBg();
2254function getBg() {
2255  console.log("run");
2256
2257  var winW = $(window).width();
2258  if ($(".banner-bg").length > 0) {
2259    $(".banner-bg").each(function (index, value) {
2260      if (
2261        $(this).closest(".sec").hasClass("sec-banner-item") &&
2262        $(this).closest(".sec").hasClass("hero-banner")
2263      ) {
2264        var bannerW = 991;
2265      } else {
2266        var bannerW = 767;
2267      }
2268      if (winW > bannerW) {
2269        if ($(".banner-bg").length > 0) {
2270          var bg_desktop = $(this).attr("data-bg-desktop");
2271          var style = "";
2272
2273          if (bg_desktop != "") {
2274            style += "background-image:url('" + bg_desktop + "');";
2275          }
2276          $(this).attr("style", style);
2277        }
2278      } else {
2279        if ($(".banner-bg").length > 0) {
2280          var bg_mobile = $(this).attr("data-bg-mobile");
2281          var style = "";
2282          if (bg_mobile != "") {
2283            style += "background-image:url('" + bg_mobile + "');";
2284          }
2285          $(this).attr("style", style);
2286        }
2287      }
2288    });
2289  }
2290}
2291
2292$(document).ready(function () {
2293  $(".qty-select-product input").each(function (i, spinner) {
2294    if ($(this).data("type") === "text") {
2295      let index = $(this).data("spinner-index") || 0;
2296      let items = $(this).data("spinner-items");
2297
2298      $(this).val(items[index]);
2299    }
2300  });
2301
2302  function updateInputs(increment) {
2303    $(".qty-select-product input").each(function () {
2304      var input = $(this);
2305
2306      if (input.data("type") === "number") {
2307        let step = input.attr("step");
2308        let oldValue = input.val();
2309        let newValue =
2310          parseInt(oldValue) +
2311          (increment ? parseInt(step || 1) : -parseInt(step || 1));
2312
2313        let minValue = parseInt(input.attr("min"));
2314        if (newValue <= minValue) {
2315          input.val(minValue);
2316        } else {
2317          input.val(newValue);
2318        }
2319      } else if (input.data("type") === "text") {
2320        let oldIndex = input.data("spinner-index") || 0;
2321        let items = input.data("spinner-items");
2322        let newIndex = increment ? oldIndex + 1 : oldIndex - 1;
2323
2324        if (newIndex >= 0 && newIndex < items.length) {
2325          input.val(items[newIndex]);
2326          input.data("spinner-index", newIndex);
2327        } else if (input.data("spinner-loop")) {
2328          input.val(increment ? items[0] : items[items.length - 1]);
2329          input.data("spinner-index", increment ? 0 : items.length - 1);
2330        }
2331      }
2332    });
2333
2334    updatePrice();
2335  }
2336
2337  function formatNumber(number) {
2338    return number.toLocaleString("en-US", {
2339      minimumFractionDigits: 2,
2340      maximumFractionDigits: 2,
2341    });
2342  }
2343
2344  function updatePrice() {
2345    let quantity = parseInt($(".qty-select-product input").first().val());
2346    let originalPrice = parseFloat($("#original-price").data("price"));
2347    let discountType = $("#discount-type").val();
2348    let discountValue = parseFloat($("#discount-value").val());
2349    let discountedPrice;
2350
2351    if (discountType === "1") {
2352      discountedPrice = (originalPrice * (100 - discountValue)) / 100;
2353    } else if (discountType === "2") {
2354      discountedPrice = originalPrice - discountValue;
2355    } else {
2356      discountedPrice = originalPrice;
2357    }
2358
2359    let totalPrice = discountedPrice * quantity;
2360    $(".stick-price").text(formatNumber(totalPrice) + " " + currencySymbol);
2361    $(".stick-discount-price").text(
2362      formatNumber(originalPrice * quantity) + " " + currencySymbol
2363    );
2364  }
2365
2366  $(".qty-select-product .btn-increment.detail").click(function () {
2367    updateInputs(true);
2368  });
2369
2370  $(".qty-select-product .btn-decrement.detail").click(function () {
2371    updateInputs(false);
2372  });
2373
2374  updatePrice();
2375});
2376
2377genHPage();
2378
2379function genHPage() {
2380  if ($(".sec-genh").length > 0) {
2381    $(".sec-genh").each(function () {
2382      var headH = $(".section-header").outerHeight();
2383      var footerH = $(".footer").outerHeight();
2384      var winH = $(window).height();
2385      if (headH + footerH > winH / 2) {
2386        $(this).css("height", "auto");
2387      } else {
2388        var calWH = winH - (headH + footerH);
2389        $(this).css("height", calWH + "px");
2390      }
2391    });
2392  }
2393}
2394
2395/////////////// STEP FORM //////////
2396///////////////////////////////////
2397
2398function change_step($this) {
2399  $this
2400    .closest("body")
2401    .find(".wrapper")
2402    .find(".step-container ul li.step-2 .step-title")
2403    .removeClass("active");
2404  var wrapper = $this.closest("body").find(".wrapper");
2405  var data_step_elem = wrapper.find(".form-step-2");
2406  var token = wrapper.find("input[name=token]").val();
2407  var order_summary = data_step_elem.find(".order-summary");
2408
2409  var n_total_price = order_summary
2410    .find(".group-order")
2411    .find(".order-group-price")
2412    .find(".order-txt-total")
2413    .attr("data-top-price");
2414
2415  // console.log("n_total_price" +n_total_price)
2416
2417  var tax_value = order_summary
2418    .find(".order-group-price")
2419    .find(".tax")
2420    .attr("data-tax");
2421  var total_price = order_summary
2422    .find(".total-order")
2423    .find(".total-price")
2424    .attr("data-total");
2425
2426  var delivery_type = order_summary
2427    .find(".order-txt-price.text-trans-type")
2428    .attr("data-trans-type");
2429  var delivery_type_name = order_summary
2430    .find(".order-txt-price.text-trans-type")
2431    .html();
2432
2433  var tax_val = order_summary.find(".tax").attr("data-tax");
2434  order_summary.find(".tax").find(".tax-cost").html(tax_val);
2435
2436  var form_stem_elem = wrapper.find(".form-step-3");
2437  var order_summary = form_stem_elem.find(".order-summary");
2438  order_summary.find(".tax").attr("data-tax", tax_value);
2439
2440  var total_price_string = new Intl.NumberFormat("th-TH", {
2441    style: "currency",
2442    currency: "THB",
2443  }).format(total_price);
2444
2445  var n_total_price_string = new Intl.NumberFormat("th-TH", {
2446    style: "currency",
2447    currency: "THB",
2448    minimumFractionDigits: 0,
2449  }).format(n_total_price);
2450  order_summary.find(".order-txt-price.price").html(n_total_price_string);
2451
2452  order_summary
2453    .find(".order-txt-price.text-trans-type")
2454    .html(delivery_type_name);
2455  order_summary
2456    .find(".order-txt-price.text-trans-type")
2457    .attr("data-trans-type", delivery_type);
2458
2459  order_summary.find(".total-price").html(total_price_string);
2460  order_summary
2461    .find(".total-order")
2462    .find(".total-price")
2463    .attr("data-total", total_price_string);
2464
2465  loadOrder(token, order_summary);
2466  wrapper.find(".step-container ul li.step-2").addClass("check");
2467  wrapper.find(".step-container ul li.step-3 .step-title").addClass("active");
2468  wrapper.find(".form-step-2").hide();
2469  wrapper.find(".form-step-3").fadeIn();
2470}
2471
2472function cart_login_load_data() {
2473  var order_summary = $(".form-step-1").find(".order-summary");
2474  var tax_value = order_summary
2475    .find(".order-group-price")
2476    .find(".tax")
2477    .attr("data-tax");
2478  var total_price = order_summary
2479    .find(".total-order")
2480    .find(".total-price")
2481    .attr("data-total");
2482  var delivery_type = order_summary
2483    .find("input[name=transfer]:checked")
2484    .attr("data-trans");
2485  var delivery_type_elem = order_summary
2486    .find("input[name=transfer]:checked")
2487    .siblings("label")
2488    .find("span.top-label-text")
2489    .clone();
2490  delivery_type_elem.find(".top-label-inside-text").remove();
2491  var delivery_type_name = delivery_type_elem.html();
2492
2493  var form_stem_elem = $(".form-step-2");
2494  var order_summary = form_stem_elem.find(".order-summary");
2495
2496  order_summary.find(".tax").attr("data-tax", tax_value);
2497  order_summary.find(".tax").find(".tax-cost").html(tax_value);
2498  var total_price_string = new Intl.NumberFormat("th-TH", {
2499    style: "currency",
2500    currency: "THB",
2501  }).format(total_price);
2502  order_summary.find(".order-txt-price.price").html(total_price_string);
2503  order_summary
2504    .find(".order-txt-price.text-trans-type")
2505    .html(delivery_type_name);
2506  order_summary
2507    .find(".order-txt-price.text-trans-type")
2508    .attr("data-trans-type", delivery_type);
2509
2510  order_summary.find(".total-price").html(total_price_string);
2511  order_summary
2512    .find(".total-order")
2513    .find(".total-price")
2514    .attr("data-total", total_price);
2515}
2516
2517$(".btn-next").click(function () {
2518  var lang = $("html").attr("lang");
2519  var dataStep = $(this).attr("data-step");
2520  var step_1_validate = true;
2521  var step_2_validate = true;
2522  if (dataStep == 1) {
2523    var order_summary_el = $(this).siblings(".order-summary");
2524    var group_order = order_summary_el.find(".group-order");
2525    var trans_1 = group_order.find("#transfer_1").prop("checked");
2526    var trans_3 = group_order.find("#transfer_3").prop("checked");
2527
2528    if (trans_1 || trans_3) {
2529      $(".step-container").fadeIn();
2530      $(this)
2531        .closest(".wrapper")
2532        .find(
2533          ".step-container ul li.step-" + parseInt(dataStep) + " .step-title"
2534        )
2535        .removeClass("active");
2536    } else {
2537      if (lang == "th") {
2538        popup_message(
2539          (type = "error"),
2540          (message = ""),
2541          (title = "คำเตือน !\nกรุณาเลือกวิธีการจัดส่ง"),
2542          (timer = 3000),
2543          (timer_message = "ปิดหลังจาก 3 วินาที")
2544        );
2545      } else {
2546        popup_message(
2547          (type = "error"),
2548          (message = ""),
2549          (title = "Warning !\nPlease select the mode of delivery"),
2550          (timer = 3000),
2551          (timer_message = "The window will close in 3 seconds.")
2552        );
2553      }
2554
2555      step_1_validate = false;
2556    }
2557  } else {
2558    $(this)
2559      .closest(".wrapper")
2560      .find(".step-container ul li.step-" + parseInt(dataStep) + " .step-title")
2561      .removeClass("active");
2562  }
2563
2564  if (dataStep == 2) {
2565    var box_delivery_detail = $(this).parent().siblings(".box-delivery-detail");
2566    var delivery_detail_wrapper = box_delivery_detail.find(
2567      ".delivery-detail-wrapper"
2568    );
2569    var form_check_shipping = delivery_detail_wrapper.find(
2570      ".box-form-check.shipping"
2571    );
2572    var delivery_detail = form_check_shipping.find(
2573      "input[name=delivery_detail]"
2574    );
2575
2576    var deli_check = false;
2577    for (let index = 0; index < delivery_detail.length; index++) {
2578      const element = delivery_detail.eq(index);
2579
2580      if (element.prop("checked")) {
2581        deli_check = true;
2582        break;
2583      }
2584    }
2585
2586    var is_tax = box_delivery_detail
2587      .closest(".row")
2588      .parent()
2589      .find(".concent_2 > .box-form-check > input[name=is_taxinv_login]");
2590
2591    if (is_tax.prop("checked")) {
2592      var box_tax_detail = box_delivery_detail.find(".form-taxinv-log");
2593      var form_check_billing = box_tax_detail.find(".box-form-check.billing");
2594      var delivery_detail_vat = form_check_billing.find(
2595        "input[name=delivery_detail_vat]"
2596      );
2597      var bill_check = false;
2598      for (let index = 0; index < delivery_detail_vat.length; index++) {
2599        const element = delivery_detail_vat.eq(index);
2600        if (element.prop("checked")) {
2601          bill_check = true;
2602          break;
2603        }
2604      }
2605    }
2606
2607    if (!deli_check && !bill_check && is_tax.prop("checked")) {
2608      popup_message(
2609        (type = "error"),
2610        (message = ""),
2611        (title =
2612          "คำเตือน !\nกรุณาเลือกที่อยู่ในการจัดส่งและ ที่อยู่ใบกำกับภาษี"),
2613        (timer = 3000),
2614        (timer_message = "ปิดหลังจาก 3 วินาที")
2615      );
2616      step_2_validate = false;
2617    } else if (!deli_check && bill_check && is_tax.prop("checked")) {
2618      popup_message(
2619        (type = "error"),
2620        (message = ""),
2621        (title = "คำเตือน !\nกรุณาเลือกที่อยู่ในการจัดส่ง"),
2622        (timer = 3000),
2623        (timer_message = "ปิดหลังจาก 3 วินาที")
2624      );
2625      step_2_validate = false;
2626    } else if (deli_check && !bill_check && is_tax.prop("checked")) {
2627      popup_message(
2628        (type = "error"),
2629        (message = ""),
2630        (title = "คำเตือน !\nกรุณาเลือกที่อยู่ใบกำกับภาษี"),
2631        (timer = 3000),
2632        (timer_message = "ปิดหลังจาก 3 วินาที")
2633      );
2634      step_2_validate = false;
2635    } else if (!deli_check && !is_tax.prop("checked")) {
2636      popup_message(
2637        (type = "error"),
2638        (message = ""),
2639        (title = "คำเตือน !\nกรุณาเลือกที่อยู่ในการจัดส่ง"),
2640        (timer = 3000),
2641        (timer_message = "ปิดหลังจาก 3 วินาที")
2642      );
2643      step_2_validate = false;
2644    }
2645
2646    var order_summary_el = $(".form-step-1").find(".order-summary");
2647    var group_order = order_summary_el.find(".group-order");
2648    var trans_1 = group_order.find("#transfer_1").prop("checked");
2649    var trans_3 = group_order.find("#transfer_3").prop("checked");
2650
2651    // var paymentCod = $("#payment_check_1");
2652    // if (trans_3) {
2653    // 	paymentCod.prop("disabled", true);
2654    // }
2655  }
2656
2657  if (parseInt(dataStep) + 1 == 2 && step_1_validate) {
2658    var order_summary = $(this).siblings(".order-summary");
2659    var tax_value = order_summary.find(".tax").attr("data-tax");
2660    var n_total_price = order_summary
2661      .find(".group-order")
2662      .find(".order-group-price")
2663      .find(".order-txt-total")
2664      .attr("data-top-price");
2665
2666    var dis_price = order_summary
2667      .find(".group-order")
2668      .find(".order-group-price")
2669      .find(".order-txt-dis")
2670      .attr("data-dis-price");
2671
2672    var total_price = order_summary
2673      .find(".total-order")
2674      .find(".total-price")
2675      .attr("data-total");
2676    var delivery_type = order_summary
2677      .find("input[name=transfer]:checked")
2678      .attr("data-trans");
2679    var delivery_type_elem = order_summary
2680      .find("input[name=transfer]:checked")
2681      .siblings("label")
2682      .find("span.top-label-text")
2683      .clone();
2684    console.log("n_total_price 1 :" + n_total_price);
2685    console.log("dis_price 1 :" + dis_price);
2686
2687    console.log("total_price 1 :" + total_price);
2688
2689    delivery_type_elem.find(".top-label-inside-text").remove();
2690    var delivery_type_name = delivery_type_elem.html();
2691    var token = $(this).closest(".wrapper").find("input[name=token]").val();
2692
2693    var form_stem_elem = $(this)
2694      .closest(".wrapper")
2695      .find(".form-step-" + (parseInt(dataStep) + 1));
2696
2697    var order_summary = form_stem_elem.find(".order-summary");
2698
2699    order_summary.find(".tax").attr("data-tax", tax_value);
2700    order_summary.find(".tax").find(".tax-cost").html(tax_value);
2701    var total_price_string = new Intl.NumberFormat("th-TH", {
2702      style: "currency",
2703      currency: "THB",
2704      minimumFractionDigits: 0,
2705    }).format(total_price);
2706    total_price_string = total_price_string.replace("฿", "");
2707
2708    var n_total_price_string = new Intl.NumberFormat("th-TH", {
2709      style: "currency",
2710      currency: "THB",
2711      minimumFractionDigits: 0,
2712    }).format(n_total_price);
2713    n_total_price_string = n_total_price_string.replace("฿", "");
2714
2715    var dis_price_string = new Intl.NumberFormat("th-TH", {
2716      style: "currency",
2717      currency: "THB",
2718      minimumFractionDigits: 0,
2719    }).format(dis_price);
2720    dis_price_string = dis_price_string.replace("฿", "");
2721
2722    order_summary
2723      .find(".order-txt-price.price .n-price-txt")
2724      .html(n_total_price_string);
2725    order_summary
2726      .find(".group-order")
2727      .find(".order-group-price")
2728      .find(".order-txt-total")
2729      .attr("data-top-price", n_total_price);
2730
2731    order_summary
2732      .find(".order-txt-price.order-txt-dis .dis-txt")
2733      .html("-" + dis_price_string);
2734    order_summary
2735      .find(".group-order")
2736      .find(".order-group-price")
2737      .find(".order-txt-dis")
2738      .attr("data-dis-price", dis_price);
2739
2740    order_summary
2741      .find(".order-txt-price.text-trans-type")
2742      .html(delivery_type_name);
2743    order_summary
2744      .find(".order-txt-price.text-trans-type")
2745      .attr("data-trans-type", delivery_type);
2746
2747    order_summary.find(".total-price .price-txt").html(total_price_string);
2748    order_summary
2749      .find(".total-order")
2750      .find(".total-price")
2751      .attr("data-total", total_price);
2752
2753    loadOrder(token, order_summary);
2754    if ($(this).hasClass("validate")) {
2755      // CHECK CONDITION OTP IF SUCCESS HERE!!! //
2756      // Set item เพิ่มหน่วงเวลาหลังจากการเช็ค OTP ให้ผ่านก่อนค่อยเปิดฟอร์ม step ต่อไป //
2757      $(".section-popup").fadeOut();
2758      $("body").removeAttr("style");
2759      setTimeout(() => {
2760        $(this)
2761          .closest("body")
2762          .find(".wrapper")
2763          .find(".step-container ul li.step-" + parseInt(dataStep))
2764          .addClass("check");
2765        $(this)
2766          .closest("body")
2767          .find(".wrapper")
2768          .find(
2769            ".step-container ul li.step-" +
2770              (parseInt(dataStep) + 1) +
2771              " .step-title"
2772          )
2773          .addClass("active");
2774        $(this)
2775          .closest("body")
2776          .find(".wrapper")
2777          .find(".form-step-" + parseInt(dataStep))
2778          .hide();
2779        $(this)
2780          .closest("body")
2781          .find(".wrapper")
2782          .find(".form-step-" + (parseInt(dataStep) + 1))
2783          .fadeIn();
2784      }, 300);
2785    } else {
2786      // console.log('total_price_string f:'+total_price_string);
2787      // console.log('n_total_price_string f:'+n_total_price_string);
2788      $(this)
2789        .closest(".wrapper")
2790        .find(".step-container ul li.step-" + parseInt(dataStep))
2791        .addClass("check");
2792      $(this)
2793        .closest(".wrapper")
2794        .find(
2795          ".step-container ul li.step-" +
2796            (parseInt(dataStep) + 1) +
2797            " .step-title"
2798        )
2799        .addClass("active");
2800      $(this)
2801        .closest(".wrapper")
2802        .find(".form-step-" + parseInt(dataStep))
2803        .hide();
2804      $(this)
2805        .closest(".wrapper")
2806        .find(".form-step-" + (parseInt(dataStep) + 1))
2807        .fadeIn();
2808    }
2809  }
2810
2811  if (parseInt(dataStep) + 1 == 3 && step_2_validate) {
2812    var data_step_elem = $(this)
2813      .closest("body")
2814      .find(".form-step-" + parseInt(dataStep));
2815
2816    var order_summary = data_step_elem.find(".order-summary");
2817    var tax_value = order_summary
2818      .find(".order-group-price")
2819      .find(".tax")
2820      .attr("data-tax");
2821
2822    var n_total_price = order_summary
2823      .find(".group-order")
2824      .find(".order-group-price")
2825      .find(".order-txt-total")
2826      .attr("data-top-price");
2827
2828    var dis_price = order_summary
2829      .find(".group-order")
2830      .find(".order-group-price")
2831      .find(".order-txt-dis")
2832      .attr("data-dis-price");
2833
2834    var total_price = order_summary
2835      .find(".total-order")
2836      .find(".total-price")
2837      .attr("data-total");
2838
2839    var delivery_type = order_summary
2840      .find(".order-txt-price.text-trans-type")
2841      .attr("data-trans-type");
2842    var delivery_type_name = order_summary
2843      .find(".order-txt-price.text-trans-type")
2844      .html();
2845
2846    var form_stem_elem = $(this)
2847      .closest("body")
2848      .find(".wrapper")
2849      .find(".form-step-" + (parseInt(dataStep) + 1));
2850    var order_summary = form_stem_elem.find(".order-summary");
2851    order_summary.find(".tax").attr("data-tax", tax_value);
2852    order_summary.find(".tax").find(".tax-cost").html(tax_value);
2853    var total_price_string = new Intl.NumberFormat("th-TH", {
2854      style: "currency",
2855      currency: "THB",
2856      minimumFractionDigits: 0,
2857    }).format(total_price);
2858    total_price_string = total_price_string.replace("฿", "");
2859
2860    var n_total_price_string = new Intl.NumberFormat("th-TH", {
2861      style: "currency",
2862      currency: "THB",
2863      minimumFractionDigits: 0,
2864    }).format(n_total_price);
2865    n_total_price_string = n_total_price_string.replace("฿", "");
2866
2867    var dis_price_string = new Intl.NumberFormat("th-TH", {
2868      style: "currency",
2869      currency: "THB",
2870      minimumFractionDigits: 0,
2871    }).format(dis_price);
2872    dis_price_string = dis_price_string.replace("฿", "");
2873
2874    order_summary
2875      .find(".order-txt-price.price .price-txt")
2876      .html(n_total_price_string);
2877    order_summary
2878      .find(".group-order")
2879      .find(".order-group-price")
2880      .find(".order-txt-total")
2881      .attr("data-top-price", n_total_price);
2882
2883    order_summary
2884      .find(".order-txt-price.order-txt-dis .dis-txt")
2885      .html("-" + dis_price_string);
2886    order_summary
2887      .find(".group-order")
2888      .find(".order-group-price")
2889      .find(".order-txt-dis")
2890      .attr("data-dis-price", dis_price);
2891
2892    order_summary
2893      .find(".order-txt-price.text-trans-type")
2894      .html(delivery_type_name);
2895    order_summary
2896      .find(".order-txt-price.text-trans-type")
2897      .attr("data-trans-type", delivery_type);
2898
2899    order_summary.find(".total-price .price-txt").html(total_price_string);
2900    order_summary
2901      .find(".total-order")
2902      .find(".total-price")
2903      .attr("data-total", total_price_string);
2904
2905    var is_tax = $("input[name=is_taxinv_login]");
2906    var is_tax_valid = true;
2907    if (is_tax.length > 0) {
2908      if (is_tax.prop("checked")) {
2909        var inside = $(".box-form-check.billing.check-group").find(
2910          ".form-check"
2911        );
2912        if (inside.length == 0) {
2913          is_tax_valid = false;
2914        }
2915      }
2916    } else {
2917      is_tax = $("input[name=is_taxinv]");
2918      if (is_tax.prop("checked")) {
2919        var inside = $(".box-form-check.billing.check-group").find(
2920          ".form-check"
2921        );
2922        if (inside.length == 0) {
2923          is_tax_valid = false;
2924        }
2925      }
2926    }
2927
2928    if (is_tax_valid) {
2929      loadOrder(token, order_summary);
2930      if ($(this).hasClass("validate")) {
2931        // CHECK CONDITION OTP IF SUCCESS HERE!!! //
2932        // Set item เพิ่มหน่วงเวลาหลังจากการเช็ค OTP ให้ผ่านก่อนค่อยเปิดฟอร์ม step ต่อไป //
2933        $(".section-popup").fadeOut();
2934        $("body").removeAttr("style");
2935        setTimeout(() => {
2936          $(this)
2937            .closest("body")
2938            .find(".wrapper")
2939            .find(".step-container ul li.step-" + parseInt(dataStep))
2940            .addClass("check");
2941          $(this)
2942            .closest("body")
2943            .find(".wrapper")
2944            .find(
2945              ".step-container ul li.step-" +
2946                (parseInt(dataStep) + 1) +
2947                " .step-title"
2948            )
2949            .addClass("active");
2950          $(this)
2951            .closest("body")
2952            .find(".wrapper")
2953            .find(".form-step-" + parseInt(dataStep))
2954            .hide();
2955          $(this)
2956            .closest("body")
2957            .find(".wrapper")
2958            .find(".form-step-" + (parseInt(dataStep) + 1))
2959            .fadeIn();
2960        }, 300);
2961      } else {
2962        $(this)
2963          .closest(".wrapper")
2964          .find(".step-container ul li.step-" + parseInt(dataStep))
2965          .addClass("check");
2966        $(this)
2967          .closest(".wrapper")
2968          .find(
2969            ".step-container ul li.step-" +
2970              (parseInt(dataStep) + 1) +
2971              " .step-title"
2972          )
2973          .addClass("active");
2974        $(this)
2975          .closest(".wrapper")
2976          .find(".form-step-" + parseInt(dataStep))
2977          .hide();
2978        $(this)
2979          .closest(".wrapper")
2980          .find(".form-step-" + (parseInt(dataStep) + 1))
2981          .fadeIn();
2982      }
2983    } else {
2984      popup_message(
2985        (type = "error"),
2986        (message = ""),
2987        (title = "คำเตือน !\nกรุณาเพิ่มใบกำกับภาษี"),
2988        (timer = 3000),
2989        (timer_message = "ปิดหลังจาก 3 วินาที")
2990      );
2991    }
2992  }
2993});
2994
2995function checkEmailnPattern(email) {
2996  var value = email.val();
2997  var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
2998  var e_pat = email.siblings(".validate");
2999  email.parent().removeClass("error");
3000  if (!regex.test(value)) {
3001    email.parent().addClass("error");
3002    e_pat.empty();
3003    e_pat.html("กรุณากรอกรูปแบบ E-Mail ให้ถูกต้อง");
3004    return false;
3005  } else {
3006    return true;
3007  }
3008}
3009
3010function validEmail($this) {
3011  var value = $this.val();
3012  var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
3013  var e_pat = $this.closest(".email").find(".validate");
3014  $this.closest(".email").removeClass("error");
3015  if (!regex.test(value)) {
3016    $this.closest(".email").addClass("error");
3017    e_pat.empty();
3018    e_pat.html("กรุณากรอกรูปแบบ E-Mail ให้ถูกต้อง");
3019    return false;
3020  } else {
3021    return true;
3022  }
3023}
3024
3025function pageLogin($this) {
3026  var form = $this.closest("form");
3027  var email = form.find("input[name=username]");
3028  var password = form.find("input[name=password]");
3029  var is_valid = true;
3030  var token = form.find("input[name=token]").val();
3031
3032  if (email.val() === "") {
3033    var e_pat = email.siblings(".validate");
3034    e_pat.empty();
3035    e_pat.html("กรุณากรอก E-Mail");
3036    email.parent().addClass("error");
3037    is_valid = false;
3038  } else if (email.val() !== "" && !checkEmailnPattern(email)) {
3039    is_valid = false;
3040  }
3041
3042  if (password.val() === "") {
3043    is_valid = false;
3044    password.parent().addClass("error");
3045  }
3046
3047  if (is_valid) {
3048    checkLoginEmail(token, form);
3049  }
3050}
3051
3052function submitOrderNormal($this) {
3053  var form = $this.closest("form");
3054  //Payment Options
3055  // var request_3ds = "Y";             //For test purpose, disable 3DS
3056  var payment_option = form
3057    .find("input.active[name=payment]")
3058    .attr("data-payment-option");
3059  // //IPP Options
3060  // var ipp_interest_type = "M";       //Interest type
3061  payment_description = "purefilter";
3062
3063  var step = form
3064    .find(".form-step.form-step-2")
3065    .find(".order-summary .total-order");
3066
3067  var amount_val = step.find(".total-price").attr("data-total");
3068  var amount = form.find("input[name=amount]");
3069
3070  var payment_description_el = form.find("input[name=payment_description]");
3071  var cart_item_array_el = form.find("input[name=cart_item_array_json]");
3072  var payment_option_el = form.find("input[name=payment_option]");
3073  var shipping_type = form
3074    .find("input[name=transfer]:checked")
3075    .attr("data-trans");
3076  var shipping_type_el = form.find("input[name=shipping_type]");
3077
3078  shipping_type_el.val(shipping_type);
3079  payment_option_el.val(payment_option);
3080  // ipp_interest_type_el.val(ipp_interest_type);
3081  // request_3ds_el.val(request_3ds);
3082  payment_description_el.val(payment_description);
3083
3084  var step_3 = form.find(".form-step.form-step-3");
3085  var list_cart_prod_elem = step_3.find(".list-cart-product");
3086  var cart_item_array = [];
3087
3088  for (let index = 0; index < list_cart_prod_elem.length; index++) {
3089    const element = list_cart_prod_elem.eq(index);
3090    const cart_body_elem = element.find(".cart-body");
3091    const promotion_el = cart_body_elem.find(".promotion");
3092
3093    var product_code = cart_body_elem
3094      .find(".cart-title")
3095      .attr("data-item-code");
3096    var sku_id = cart_body_elem.find(".cart-title").attr("data-sku-id");
3097    var data_amount = cart_body_elem.find(".cart-qlt").attr("data-item-amount");
3098    var data_price = cart_body_elem.find(".cart-qlt").attr("data-item-price");
3099
3100    var data = {
3101      prod_code: product_code,
3102      sku_id: sku_id,
3103      quan: data_amount,
3104      price: data_price,
3105      is_promo_item: 0,
3106    };
3107    cart_item_array.push(data);
3108
3109    if (promotion_el.length > 0) {
3110      var product_code_promo = promotion_el.attr("data-promo-prod-code");
3111      var sku_id_promo = promotion_el.attr("data-promo-sku-id");
3112      var promo_id = promotion_el.attr("data-promo-id");
3113      var data_price_pro = promotion_el.attr("data-item-sku-price");
3114
3115      var data_promo = {
3116        prod_code: product_code_promo,
3117        sku_id: sku_id_promo,
3118        quan: data_amount,
3119        price: data_price_pro,
3120        is_promo_item: 1,
3121        promo_id: promo_id,
3122      };
3123      cart_item_array.push(data_promo);
3124    }
3125  }
3126
3127  var cart_item_array_json = JSON.stringify(cart_item_array);
3128  cart_item_array_el.val(cart_item_array_json);
3129  var twelve_digit = "";
3130  var amount_str = String(amount_val);
3131
3132  for (let index = 0; index < 12 - amount_val.length - 2; index++) {
3133    twelve_digit = twelve_digit + "0";
3134  }
3135  twelve_digit = twelve_digit + amount_str + "00";
3136  amount.val(twelve_digit);
3137
3138  var valid = true;
3139  if (payment_option === "CC" || payment_option === "I") {
3140    if (amount_val < 3000) {
3141      valid = false;
3142      popup_message(
3143        "warning",
3144        "ยอดขั้นต่ำ 3,000 บาทขึ้นไป",
3145        "ยอดชำระของท่าน<br>ไม่ถึงยอดขั้นตำในการชำระ",
3146        3000,
3147        "ปิดหลังจาก 3 วินาที"
3148      );
3149    }
3150  }
3151
3152  if (valid) {
3153    form.submit();
3154  }
3155}
3156
3157function submitOrder($this) {
3158  var form = $this.closest("form");
3159
3160  //Payment Options
3161
3162  // var request_3ds = "Y";             //For test purpose, disable 3DS
3163  var payment_option = form
3164    .find("input.active[name=payment]")
3165    .attr("data-payment-option");
3166
3167  if (
3168    payment_option === undefined ||
3169    payment_option === null ||
3170    payment_option === ""
3171  ) {
3172    return popup_message(
3173      "warning",
3174      "",
3175      "กรุณาเลือกวิธีชำระเงิน",
3176      3000,
3177      "ปิดหลังจาก 3 วินาที"
3178    );
3179  }
3180
3181  // //IPP Options
3182  // var ipp_interest_type = "M";       //Interest type
3183  payment_description = "purefilter";
3184
3185  var step = form
3186    .find(".form-step.form-step-2")
3187    .find(".order-summary .total-order");
3188  var amount_val = step.find(".total-price").attr("data-total");
3189
3190  var amount = form.find("input[name=amount]");
3191  var payment_description_el = form.find("input[name=payment_description]");
3192  var is_tax_el = form.find("input[name=is_tax]");
3193  var address_array_el = form.find("input[name=address_array_json]");
3194  var order_data_array_el = form.find("input[name=order_data_array_json]");
3195  var cart_item_array_el = form.find("input[name=cart_item_array_json]");
3196  var payment_option_el = form.find("input[name=payment_option]");
3197  var shipping_type = form
3198    .find("input[name=transfer]:checked")
3199    .attr("data-trans");
3200  var shipping_type_el = form.find("input[name=shipping_type]");
3201  var shipping_id = form
3202    .find("input.shipping[name=delivery_detail]:checked")
3203    .attr("data-ship-id");
3204  var billing_id = form
3205    .find("input.billing[name=delivery_detail_vat]:checked")
3206    .attr("data-bill-id");
3207  var prefix = form.find("input[name=prefix]").val();
3208  var code = form.find("input[name=code]").val();
3209  var is_tax = $("input[name=is_taxinv_login]").prop("checked");
3210  is_tax_el.val(is_tax);
3211  shipping_type_el.val(shipping_type);
3212  payment_option_el.val(payment_option);
3213  // ipp_interest_type_el.val(ipp_interest_type);
3214  // request_3ds_el.val(request_3ds);
3215  payment_description_el.val(payment_description);
3216
3217  var address_array = [{ shipping_id: shipping_id, billing_id: billing_id }];
3218  var address_array_json = JSON.stringify(address_array);
3219
3220  var order_data_array = [{ prefix: prefix, code: code }];
3221  var order_data_array_json = JSON.stringify(order_data_array);
3222
3223  var step_3 = form.find(".form-step.form-step-3");
3224  var list_cart_prod_elem = step_3.find(".list-cart-product");
3225  var cart_item_array = [];
3226
3227  for (let index = 0; index < list_cart_prod_elem.length; index++) {
3228    const element = list_cart_prod_elem.eq(index);
3229    const cart_body_elem = element.find(".cart-body");
3230    const promotion_el = cart_body_elem.find(".promotion");
3231
3232    var product_code = cart_body_elem
3233      .find(".cart-title")
3234      .attr("data-item-code");
3235    var sku_id = cart_body_elem.find(".cart-title").attr("data-sku-id");
3236    var data_amount = cart_body_elem.find(".cart-qlt").attr("data-item-amount");
3237    var data_price = cart_body_elem.find(".cart-qlt").attr("data-item-price");
3238
3239    var data = {
3240      prod_code: product_code,
3241      sku_id: sku_id,
3242      quan: data_amount,
3243      price: data_price,
3244      is_promo_item: 0,
3245    };
3246    cart_item_array.push(data);
3247
3248    if (promotion_el.length > 0) {
3249      var product_code_promo = promotion_el.attr("data-promo-prod-code");
3250      var sku_id_promo = promotion_el.attr("data-promo-sku-id");
3251      var promo_id = promotion_el.attr("data-promo-id");
3252      var data_price_pro = promotion_el.attr("data-item-sku-price");
3253
3254      var data_promo = {
3255        prod_code: product_code_promo,
3256        sku_id: sku_id_promo,
3257        quan: data_amount,
3258        price: data_price_pro,
3259        is_promo_item: 1,
3260        promo_id: promo_id,
3261      };
3262      cart_item_array.push(data_promo);
3263    }
3264  }
3265
3266  var cart_item_array_json = JSON.stringify(cart_item_array);
3267
3268  address_array_el.val(address_array_json);
3269  order_data_array_el.val(order_data_array_json);
3270  cart_item_array_el.val(cart_item_array_json);
3271
3272  var twelve_digit = "";
3273  var amount_str = String(amount_val);
3274
3275  for (let index = 0; index < 12 - amount_val.length - 2; index++) {
3276    twelve_digit = twelve_digit + "0";
3277  }
3278  twelve_digit = twelve_digit + amount_str + "00";
3279  amount.val(twelve_digit);
3280  var valid = true;
3281
3282  // if (payment_option === "CC" || payment_option === "I") {
3283  // 	if (amount_val < 3000) {
3284  // 		valid = false;
3285  // 		popup_message(
3286  // 			"warning",
3287  // 			"ยอดขั้นต่ำ 3,000 บาทขึ้นไป",
3288  // 			"ยอดชำระของท่าน<br>ไม่ถึงยอดขั้นตำในการชำระ",
3289  // 			3000,
3290  // 			"ปิดหลังจาก 3 วินาที"
3291  // 		);
3292  // 	}
3293  // }
3294
3295  // onbb-comment ปิดจากสไลด์คุณแคท วันที่ 8/5/67 ปิดการชำระยอดขั้นต่ำ
3296
3297  if (valid) {
3298    $(".loadpage").show();
3299    form.submit();
3300  }
3301}
3302
3303function validateConcent2($this) {
3304  validate = true;
3305  var form = $this.closest("form");
3306  var concent_2 = form.find("input[name=concent_2]");
3307  concent_2.closest(".concent_2").removeClass("error");
3308
3309  if (!concent_2.is(":checked")) {
3310    validate = false;
3311    concent_2.closest(".concent_2").addClass("error");
3312  }
3313  if (validate) {
3314    form.submit();
3315  }
3316}
3317
3318function validateChangePass($this) {
3319  var form = $this.closest("form");
3320  var password = form.find("input[name=password]");
3321  var password_re = form.find("input[name=password_re]");
3322  $(".form-control").removeClass("is-invalid");
3323  is_valid = true;
3324  if (password.val() === "") {
3325    is_valid = false;
3326    password.addClass("is-invalid");
3327    password.closest(".pass").find(".validate").html("กรุณากรอกรหัสผ่าน");
3328  } else if (password.val().length < 6) {
3329    is_valid = false;
3330    password.addClass("is-invalid");
3331    password
3332      .closest(".pass")
3333      .find(".validate")
3334      .html("กรุณากรอกรหัสผ่านมากกว่า 6 ตัวอักษร");
3335  } else {
3336    if (password_re.val() === "") {
3337      is_valid = false;
3338      password_re.addClass("is-invalid");
3339      password_re
3340        .closest(".pass-re")
3341        .find(".validate")
3342        .html("กรุณากรอกรหัสผ่านยืนยัน");
3343    } else {
3344      if (
3345        password.val() !== "" &&
3346        password_re.val() !== "" &&
3347        password.val() !== password_re.val()
3348      ) {
3349        is_valid = false;
3350        password_re.addClass("is-invalid");
3351        password_re
3352          .closest(".pass-re")
3353          .find(".validate")
3354          .html("รหัสผ่านยืนยันไม่ตรงกัน");
3355      }
3356    }
3357  }
3358
3359  if (is_valid) {
3360    form.submit();
3361  }
3362}
3363
3364function popup_message_cart(
3365  type = "success",
3366  message = "บันทึกข้อมูลเรียบร้อย",
3367  title = "สำเร็จ !",
3368  timer = 0,
3369  timer_message = "ปิดหลังจาก 2 วินาที",
3370  token = "",
3371  product_code = 0,
3372  sku_id = 0,
3373  amount = 0
3374) {
3375  var lang = $("html").attr("lang");
3376  var textg1 = "The window will close in ";
3377  var textg2 = " seconds.";
3378  if (lang == "th") {
3379    textg1 = "หน้าต่างจะปิดใน ";
3380    textg2 = " วินาที";
3381  }
3382  if (timer > 0) {
3383    message += " (" + timer_message + ")";
3384    Swal.fire({
3385      icon: type,
3386      title: title,
3387      text: message,
3388      timer: timer,
3389      showConfirmButton: false,
3390      html: textg1 + "<strong></strong>" + textg2,
3391      willOpen: () => {
3392        Swal.showLoading();
3393        timerInterval = setInterval(() => {
3394          Swal.getHtmlContainer().querySelector("strong").textContent = (
3395            Swal.getTimerLeft() / 1000
3396          ).toFixed(0);
3397        }, 100);
3398      },
3399      willClose: () => {
3400        clearInterval(timerInterval);
3401      },
3402    }).then((result) => {
3403      if (
3404        result.dismiss === Swal.DismissReason.timer ||
3405        result.dismiss == Swal.DismissReason.backdrop ||
3406        result.dismiss == Swal.DismissReason.esc ||
3407        result.dismiss == Swal.DismissReason.close
3408      ) {
3409        console.log("I was closed by the timer");
3410        var cart_tl = new TimelineLite();
3411        var cart_icon = $("body .box-header .header-button.btn-cart");
3412        cart_tl.fromTo(
3413          cart_icon,
3414          1,
3415          { scaleX: 1.2, scaleY: 1.2, ease: Power3.easeOut },
3416          { scaleX: 1, scaleY: 1, ease: Power1.easeOut },
3417          0
3418        );
3419        cart_icon.addClass("active");
3420      }
3421    });
3422  } else {
3423    Swal.fire({
3424      type: type,
3425      icon: type,
3426      title: title,
3427      text: message,
3428    });
3429  }
3430}
3431
3432function popup_message(
3433  type = "success",
3434  message = "บันทึกข้อมูลเรียบร้อย",
3435  title = "สำเร็จ !",
3436  timer = 0,
3437  timer_message = "ปิดหลังจาก 2 วินาที"
3438) {
3439  var lang = $("html").attr("lang");
3440  var textg1 = "The window will close in ";
3441  var textg2 = " seconds.";
3442  if (lang == "th") {
3443    textg1 = "หน้าต่างจะปิดใน ";
3444    textg2 = " วินาที";
3445  }
3446  if (timer > 0) {
3447    message += " (" + timer_message + ")";
3448    Swal.fire({
3449      icon: type,
3450      title: title,
3451      text: message,
3452      timer: timer,
3453      showConfirmButton: false,
3454      html: textg1 + "<strong></strong>" + textg2,
3455      willOpen: () => {
3456        Swal.showLoading();
3457        timerInterval = setInterval(() => {
3458          Swal.getHtmlContainer().querySelector("strong").textContent = (
3459            Swal.getTimerLeft() / 1000
3460          ).toFixed(0);
3461        }, 100);
3462      },
3463      willClose: () => {
3464        clearInterval(timerInterval);
3465      },
3466    }).then((result) => {
3467      if (
3468        result.dismiss === Swal.DismissReason.timer ||
3469        result.dismiss == Swal.DismissReason.backdrop ||
3470        result.dismiss == Swal.DismissReason.esc ||
3471        result.dismiss == Swal.DismissReason.close
3472      ) {
3473        console.log("I was closed by the timer");
3474      }
3475    });
3476  } else {
3477    Swal.fire({
3478      type: type,
3479      icon: type,
3480      title: title,
3481      text: message,
3482    });
3483  }
3484}
3485
3486function popup_message_delete(popuptype, token, $this) {
3487  var lang = $("html").attr("lang");
3488  var textg00 = "Are you sure you want to delete the data?";
3489  var textg11 = "Cancel";
3490  var textg22 = "Confirm";
3491  if (lang == "th") {
3492    textg00 = "คุณแน่ใจในการลบข้อมูล ?";
3493    textg11 = "ยกเลิก";
3494    textg22 = " ยืนยัน";
3495  }
3496  Swal.fire({
3497    title: textg00,
3498    text: "",
3499    icon: "warning",
3500    cancelButtonText: textg11,
3501    confirmButtonText: textg22,
3502    showCancelButton: true,
3503  }).then((result) => {
3504    if (result.isConfirmed) {
3505      if (popuptype === "ship") {
3506        var address_id = parseInt($this.attr("data-id"));
3507        $.ajax(base_url + "api/delete_shipping_address", {
3508          method: "GET",
3509          data: {
3510            token: token,
3511            address_id: address_id,
3512          },
3513          beforeSend: function () {},
3514        }).done(function (data) {
3515          var form_check = $this.closest(".form-check");
3516          form_check.remove();
3517          reloadShipAddressLogin($this);
3518        });
3519      } else if (popuptype === "bill") {
3520        var address_id = parseInt($this.attr("data-id"));
3521        $.ajax(base_url + "api/delete_billing_address", {
3522          method: "GET",
3523          data: {
3524            token: token,
3525            address_id: address_id,
3526          },
3527          beforeSend: function () {},
3528        }).done(function (data) {
3529          var form_check = $this.closest(".form-check");
3530          form_check.remove();
3531          reloadBillAddressLogin($this);
3532        });
3533      }
3534    }
3535  });
3536}
3537
3538document.addEventListener("DOMContentLoaded", function (event) {
3539  function OTPInput() {
3540    const inputs = document.querySelectorAll("#otp-normal > *[id]");
3541
3542    for (let i = 0; i < inputs.length; i++) {
3543      inputs[i].addEventListener("keydown", function (event) {
3544        if (event.key === "Backspace") {
3545          inputs[i].value = "";
3546          if (i !== 0) inputs[i - 1].focus();
3547        } else {
3548          let allow_key = [
3549            "1",
3550            "2",
3551            "3",
3552            "4",
3553            "5",
3554            "6",
3555            "7",
3556            "8",
3557            "9",
3558            "10",
3559            "0",
3560          ];
3561          if (
3562            i === inputs.length - 1 &&
3563            inputs[i].value !== "" &&
3564            inputs[i].value.length < 1
3565          ) {
3566            return true;
3567          } else if (
3568            i === inputs.length - 1 &&
3569            inputs[i].value !== "" &&
3570            inputs[i].value.length == 1
3571          ) {
3572            event.preventDefault();
3573          } else {
3574            if (allow_key.includes(event.key)) {
3575              inputs[i].value = event.key;
3576              if (i !== inputs.length - 1) inputs[i + 1].focus();
3577              event.preventDefault();
3578            } else {
3579              event.preventDefault();
3580            }
3581          }
3582        }
3583      });
3584    }
3585  }
3586  OTPInput();
3587
3588  function SerialInput() {
3589    const inputs = document.querySelectorAll(
3590      "#register-product-serial .form-group > *[id]"
3591    );
3592
3593    for (let i = 0; i < inputs.length; i++) {
3594      inputs[i].addEventListener("keydown", function (event) {
3595        if (event.key === "Backspace") {
3596          inputs[i].value = "";
3597          if (i !== 0) inputs[i - 1].focus();
3598        } else {
3599          if (i === inputs.length - 1 && inputs[i].value !== "") {
3600            return true;
3601          } else if (event.keyCode > 47 && event.keyCode < 58) {
3602            inputs[i].value = event.key;
3603            if (i !== inputs.length - 1) inputs[i + 1].focus();
3604            event.preventDefault();
3605          } else if (event.keyCode > 95 && event.keyCode < 106) {
3606            inputs[i].value = event.key;
3607            if (i !== inputs.length - 1) input
3607s[i + 1].focus();
3608            event.preventDefault();
3609          } else if (event.keyCode > 64 && event.keyCode < 91) {
3610            inputs[i].value = event.key;
3611            if (i !== inputs.length - 1) inputs[i + 1].focus();
3612            event.preventDefault();
3613          }
3614        }
3615      });
3616    }
3617  }
3618  SerialInput();
3619
3620  function InstallInput() {
3621    const inputs = document.querySelectorAll(
3622      "#register-product-install .form-group > *[id]"
3623    );
3624
3625    for (let i = 0; i < inputs.length; i++) {
3626      inputs[i].addEventListener("keydown", function (event) {
3627        if (event.key === "Backspace") {
3628          inputs[i].value = "";
3629          if (i !== 0) inputs[i - 1].focus();
3630        } else {
3631          if (i === inputs.length - 1 && inputs[i].value !== "") {
3632            return true;
3633          } else if (event.keyCode > 47 && event.keyCode < 58) {
3634            inputs[i].value = event.key;
3635            if (i !== inputs.length - 1) inputs[i + 1].focus();
3636            event.preventDefault();
3637          } else if (event.keyCode > 95 && event.keyCode < 106) {
3638            inputs[i].value = event.key;
3639            if (i !== inputs.length - 1) inputs[i + 1].focus();
3640            event.preventDefault();
3641          } else if (event.keyCode > 64 && event.keyCode < 91) {
3642            inputs[i].value = event.key;
3643            if (i !== inputs.length - 1) inputs[i + 1].focus();
3644            event.preventDefault();
3645          }
3646        }
3647      });
3648    }
3649  }
3650  InstallInput();
3651});
3652
3653document.addEventListener("DOMContentLoaded", function (event) {
3654  function serialInputSerial() {
3655    const inputs = document.querySelectorAll(
3656      "#register-product-serial > *[id]"
3657    );
3658    for (let i = 0; i < inputs.length; i++) {
3659      inputs[i].addEventListener("keydown", function (event) {
3660        if (event.key === "Backspace") {
3661          inputs[i].value = "";
3662          if (i !== 0) inputs[i - 1].focus();
3663        } else {
3664          if (i === inputs.length - 1 && inputs[i].value !== "") {
3665            return true;
3666          } else if (event.keyCode > 47 && event.keyCode < 58) {
3667            inputs[i].value = event.key;
3668            if (i !== inputs.length - 1) input
3668s[i + 1].focus();
3669            event.preventDefault();
3670          } else if (event.keyCode > 95 && event.keyCode < 106) {
3671            inputs[i].value = event.key;
3672            if (i !== inputs.length - 1) inputs[i + 1].focus();
3673            event.preventDefault();
3674          } else if (event.keyCode > 64 && event.keyCode < 91) {
3675            inputs[i].value = event.key;
3676            if (i !== inputs.length - 1) inputs[i + 1].focus();
3677            event.preventDefault();
3678          }
3679        }
3680      });
3681    }
3682  }
3683  serialInputSerial();
3684});
3685
3686document.addEventListener("DOMContentLoaded", function (event) {
3687  function serialInputInstall() {
3688    const inputs = document.querySelectorAll(
3689      "#register-product-install> *[id]"
3690    );
3691
3692    for (let i = 0; i < inputs.length; i++) {
3693      inputs[i].addEventListener("keydown", function (event) {
3694        if (event.key === "Backspace") {
3695          inputs[i].value = "";
3696          if (i !== 0) inputs[i - 1].focus();
3697        } else {
3698          if (i === inputs.length - 1 && inputs[i].value !== "") {
3699            return true;
3700          } else if (event.keyCode > 47 && event.keyCode < 58) {
3701            inputs[i].value = event.key;
3702            if (i !== inputs.length - 1) inputs[i + 1].focus();
3703            event.preventDefault();
3704          } else if (event.keyCode > 95 && event.keyCode < 106) {
3705            inputs[i].value = event.key;
3706            if (i !== inputs.length - 1) inputs[i + 1].focus();
3707            event.preventDefault();
3708          } else if (event.keyCode > 64 && event.keyCode < 91) {
3709            inputs[i].value = event.key;
3710            if (i !== inputs.length - 1) inputs[i + 1].focus();
3711            event.preventDefault();
3712          }
3713        }
3714      });
3715    }
3716  }
3717  serialInputInstall();
3718});
3719
3720$(window).on("load", function () {
3721  tl.from($(".head-wrap"), 1, { alpha: 1, y: -120, ease: Power3.easeOut }, 0);
3722  tl.from($(".hero-banner"), 1, { alpha: 0, ease: Power3.easeIn }, 0.4);
3723  tl.from(
3724    $(".hero-banner .txt-content h1"),
3725    2,
3726    { alpha: 0, y: 100, ease: Power3.easeOut },
3727    1
3728  );
3729  tl.from(
3730    $(".hero-banner .txt-content p"),
3731    2,
3732    { alpha: 0, y: 100, ease: Power3.easeOut },
3733    1.1
3734  );
3735  tl.from(
3736    $(".hero-banner .txt-content .btn.primary"),
3737    2,
3738    { alpha: 0, y: 100, ease: Power3.easeOut },
3739    1.2
3740  );
3741  tl.from(
3742    $(".hero-banner .txt-content img:first-child"),
3743    2,
3744    { alpha: 0, y: 100, ease: Power3.easeOut },
3745    1.4
3746  );
3747  tl.from(
3748    $(".banner-pagination"),
3749    2,
3750    { alpha: 0, y: 100, ease: Power3.easeOut },
3751    1.6
3752  );
3753  tl.from(
3754    $(".hero-banner .txt-content.btn-line-block"),
3755    2,
3756    { alpha: 0, y: 100, ease: Power3.easeOut },
3757    1.7
3758  );
3759  tl.from(
3760    $(".hero-banner .item-img"),
3761    2,
3762    { alpha: 0, y: 100, ease: Power3.easeOut },
3763    1.2
3764  );
3765
3766  tl.from(
3767    $(".auto-animate"),
3768    2,
3769    { alpha: 0, y: 100, ease: Power3.easeOut },
3770    1.8
3771  );
3772
3773  tl.from(
3774    $(".auto-progress-animate .txt-content h3"),
3775    2,
3776    { ease: Power3.easeOut, alpha: 0, y: 100, delay: 0.2 },
3777    1.4
3778  );
3779  tl.from(
3780    $(".auto-progress-animate .txt-content h2"),
3781    2,
3782    { ease: Power3.easeOut, alpha: 0, y: 100, delay: 0.3 },
3783    1.4
3784  );
3785  tl.from(
3786    $(".auto-progress-animate .txt-content p"),
3787    2,
3788    { ease: Power3.easeOut, alpha: 0, y: 100, delay: 0.4 },
3789    1.4
3790  );
3791
3792  tl.from(
3793    $(".auto-progress-animate .slide-progress .swiper-container"),
3794    2,
3795    { ease: Power3.easeOut, alpha: 0, x: 50, delay: 0.6 },
3796    1.4
3797  );
3798  tl.from(
3799    $(".auto-progress-animate .rzbffff"),
3800    2,
3801    { ease: Power3.easeOut, alpha: 0, y: 100, delay: 0.4 },
3802    1.4
3803  );
3804});
3805
3806var sizeMonitor;
3807Resize();
3808function Resize() {
3809  var winW = $(window).width();
3810  if (winW >= 1920) {
3811    sizeMonitor = "desktop";
3812  } else {
3813    sizeMonitor = "mobile";
3814  }
3815}
3816
3817var controller = $.superscrollorama({
3818  reverse: false,
3819  playoutAnimations: false,
3820  offset: 10000,
3821});
3822
3823$(document).ready(function () {
3824  $(".sec").each(function (index, value) {
3825    if ($(this).hasClass("product-slide")) {
3826      gsap.from($(this).find(".txt-content h2"), {
3827        duration: 1,
3828        ease: "power3.out",
3829        opacity: 0,
3830        y: 100,
3831        delay: 0.1,
3832      });
3833      gsap.from($(this).find(".row"), {
3834        duration: 1,
3835        ease: "power3.out",
3836        opacity: 0,
3837        y: 100,
3838        delay: 1.5,
3839      });
3840    }
3841    if (!$(this).hasClass("auto-progress-animate")) {
3842      if ($(this).hasClass("sec-slide-progress")) {
3843        gsap.from($(this).find(".txt-content h3"), {
3844          duration: 1,
3845          ease: "power3.out",
3846          opacity: 0,
3847          y: 100,
3848          delay: 0.1,
3849        });
3850        gsap.from($(this).find(".txt-content h2"), {
3851          duration: 1,
3852          ease: "power3.out",
3853          opacity: 0,
3854          y: 100,
3855          delay: 0.3,
3856        });
3857        gsap.from($(this).find(".txt-content p"), {
3858          duration: 1,
3859          ease: "power3.out",
3860          opacity: 0,
3861          y: 100,
3862          delay: 0.4,
3863        });
3864        gsap.from($(this).find(".slide-progress .swiper-container"), {
3865          duration: 2,
3866          ease: "power3.out",
3867          opacity: 0,
3868          x: 50,
3869          delay: 0.6,
3870        });
3871        gsap.from($(this).find(".rzbffff"), {
3872          duration: 1,
3873          ease: "power3.out",
3874          opacity: 0,
3875          y: 100,
3876          delay: 0.4,
3877        });
3878      }
3879    }
3880    if ($(this).hasClass("sec-standard")) {
3881      controller.addTween(
3882        $(this),
3883        TweenMax.from($(this).find(".container .txt-content h2"), 2, {
3884          ease: Power3.easeOut,
3885          alpha: 0,
3886          y: 100,
3887          delay: 0.1,
3888        }),
3889        0,
3890        0
3891      );
3892      controller.addTween(
3893        $(this),
3894        TweenMax.from($(this).find(".thumb-group .thumb-txt "), 2, {
3895          ease: Power3.easeOut,
3896          alpha: 0,
3897          y: 100,
3898          delay: 0.7,
3899        }),
3900        0,
3901        0
3902      );
3903      controller.addTween(
3904        $(this),
3905        TweenMax.from($(this).find(".thumb-group .thumb-img "), 2, {
3906          ease: Power3.easeOut,
3907          alpha: 0,
3908          y: 100,
3909          delay: 0.5,
3910        }),
3911        0,
3912        0
3913      );
3914    }
3915    if ($(this).hasClass("sec-certificate")) {
3916      controller.addTween(
3917        $(this),
3918        TweenMax.from($(this), 2, {
3919          ease: Power3.easeOut,
3920          alpha: 0,
3921          scale: 1.2,
3922          delay: 0,
3923        }),
3924        0,
3925        0
3926      );
3927      controller.addTween(
3928        $(this),
3929        TweenMax.from($(this).find(".thumb-txt"), 2, {
3930          ease: Power3.easeOut,
3931          alpha: 0,
3932          y: 200,
3933          delay: 0.7,
3934        }),
3935        0,
3936        0
3937      );
3938    }
3939    if ($(this).hasClass("sec-review")) {
3940      controller.addTween(
3941        $(this),
3942        TweenMax.from($(this).find(".thumb-group .thumb-img "), 1, {
3943          ease: Power3.easeOut,
3944          alpha: 0,
3945          y: 150,
3946          delay: 0.5,
3947        }),
3948        0,
3949        0
3950      );
3951      controller.addTween(
3952        $(this),
3953        TweenMax.from($(this).find(".txt-content"), 1, {
3954          ease: Power3.easeOut,
3955          alpha: 0,
3956          y: 200,
3957          delay: 0.1,
3958        }),
3959        0,
3960        0
3961      );
3962      controller.addTween(
3963        $(this),
3964        TweenMax.from(
3965          $(this).find(".thumb-group .thumb-txt .thumb-title "),
3966          1,
3967          { ease: Power3.easeOut, alpha: 0, y: 100, delay: 0.4 }
3968        ),
3969        0,
3970        0
3971      );
3972      controller.addTween(
3973        $(this),
3974        TweenMax.from($(this).find(".thumb-group .thumb-txt .thumb-rate "), 1, {
3975          ease: Power3.easeOut,
3976          alpha: 0,
3977          y: 100,
3978          delay: 0.5,
3979        }),
3980        0,
3981        0
3982      );
3983      controller.addTween(
3984        $(this),
3985        TweenMax.from(
3986          $(this).find(".thumb-group .thumb-txt .thumb-subtitle "),
3987          1,
3988          { ease: Power3.easeOut, alpha: 0, y: 100, delay: 0.6 }
3989        ),
3990        0,
3991        0
3992      );
3993      controller.addTween(
3994        $(this),
3995        TweenMax.from(
3996          $(this).find(".thumb-group .thumb-txt .thumb-gallery"),
3997          1,
3998          { ease: Power3.easeOut, alpha: 0, y: 100, delay: 0.7 }
3999        ),
4000        0,
4001        0
4002      );
4003      controller.addTween(
4004        $(this),
4005        TweenMax.from(
4006          $(this).find(".thumb-group .thumb-txt .thumb-profile"),
4007          1,
4008          { ease: Power3.easeOut, alpha: 0, y: 100, delay: 0.8 }
4009        ),
4010        0,
4011        0
4012      );
4013      controller.addTween(
4014        $(this),
4015        TweenMax.from(
4016          $(this).find(".thumb-group .thumb-txt .thumb-box-product"),
4017          1,
4018          { ease: Power3.easeOut, alpha: 0, y: 100, delay: 0.9 }
4019        ),
4020        0,
4021        0
4022      );
4023    }
4024    if ($(this).hasClass("after-service")) {
4025      controller.addTween(
4026        $(this),
4027        TweenMax.from($(this).find(".txt-content h2"), 1, {
4028          ease: Power3.easeOut,
4029          alpha: 0,
4030          y: 50,
4031          delay: 0.1,
4032        }),
4033        0,
4034        0
4035      );
4036      controller.addTween(
4037        $(this),
4038        TweenMax.from($(this).find(".txt-content .btn"), 1, {
4039          ease: Power3.easeOut,
4040          alpha: 0,
4041          y: 50,
4042          delay: 0.2,
4043        }),
4044        0,
4045        0
4046      );
4047
4048      controller.addTween(
4049        $(this),
4050        TweenMax.from($(this).find(".card-body .card-title"), 1, {
4051          ease: Power3.easeOut,
4052          alpha: 0,
4053          y: 150,
4054          delay: 0.1,
4055        }),
4056        0,
4057        0
4058      );
4059      controller.addTween(
4060        $(this),
4061        TweenMax.from($(this).find(".card-body .card-txt"), 1, {
4062          ease: Power3.easeOut,
4063          alpha: 0,
4064          y: 150,
4065          delay: 0.2,
4066        }),
4067        0,
4068        0
4069      );
4070      controller.addTween(
4071        $(this),
4072        TweenMax.from($(this).find(".card-body .btn"), 1, {
4073          ease: Power3.easeOut,
4074          alpha: 0,
4075          y: 150,
4076          delay: 0.3,
4077        }),
4078        0,
4079        0
4080      );
4081      controller.addTween(
4082        $(this),
4083        TweenMax.from($(this).find(".box-card.text-incard img"), 1, {
4084          ease: Power3.easeOut,
4085          alpha: 0,
4086          delay: 0,
4087        }),
4088        0,
4089        0
4090      );
4091    }
4092
4093    if (!$(this).hasClass("auto-animate")) {
4094      if ($(this).hasClass("sec-acc-group")) {
4095        controller.addTween(
4096          $(this),
4097          TweenMax.from($(this).find(".txt-content h2"), 2, {
4098            ease: Power3.easeOut,
4099            alpha: 0,
4100            y: 150,
4101            delay: 0.1,
4102          }),
4103          0,
4104          0
4105        );
4106        controller.addTween(
4107          $(this),
4108          TweenMax.from($(this).find(".box-accordion"), 2, {
4109            ease: Power3.easeOut,
4110            alpha: 0,
4111            y: 150,
4112            delay: 0.3,
4113          }),
4114          0,
4115          0
4116        );
4117        controller.addTween(
4118          $(this),
4119          TweenMax.from($(this).find(".tab-content"), 2, {
4120            ease: Power3.easeOut,
4121            alpha: 0,
4122            y: 150,
4123            delay: 0.3,
4124          }),
4125          0,
4126          0
4127        );
4128        controller.addTween(
4129          $(this),
4130          TweenMax.from($(this).find(".txt-content.btn-line-block "), 2, {
4131            ease: Power3.easeOut,
4132            alpha: 0,
4133            y: 200,
4134            delay: 0.5,
4135          }),
4136          0,
4137          0
4138        );
4139      }
4140    }
4141
4142    if ($(this).hasClass("sec-jingle")) {
4143      controller.addTween(
4144        $(this),
4145        TweenMax.from($(this).find(".txt-content"), 1, {
4146          ease: Power3.easeOut,
4147          alpha: 0,
4148          y: 150,
4149          delay: 0.3,
4150        }),
4151        0,
4152        0
4153      );
4154      controller.addTween(
4155        $(this),
4156        TweenMax.from($(this).find(".audio-player"), 1, {
4157          ease: Power3.easeOut,
4158          alpha: 0,
4159          y: 150,
4160          delay: 0.5,
4161        }),
4162        0,
4163        0
4164      );
4165    }
4166    if ($(this).hasClass("sec-howto-care")) {
4167      controller.addTween(
4168        $(this),
4169        TweenMax.from($(this).find(".txt-content h2"), 1, {
4170          ease: Power3.easeOut,
4171          alpha: 0,
4172          y: 150,
4173          delay: 0.1,
4174        }),
4175        0,
4176        0
4177      );
4178      controller.addTween(
4179        $(this),
4180        TweenMax.from($(this).find(".thumb-txt"), 1, {
4181          ease: Power3.easeOut,
4182          alpha: 0,
4183          y: 150,
4184          delay: 0.3,
4185        }),
4186        0,
4187        0
4188      );
4189      controller.addTween(
4190        $(this),
4191        TweenMax.from($(this).find(".thumb-img"), 1, {
4192          ease: Power3.easeOut,
4193          alpha: 0,
4194          y: 150,
4195          delay: 0.4,
4196        }),
4197        0,
4198        0
4199      );
4200    }
4201
4202    if ($(this).hasClass("banner-overlab")) {
4203      controller.addTween(
4204        $(this),
4205        TweenMax.from($(this).find("picture img"), 2, {
4206          ease: Power3.easeOut,
4207          alpha: 0,
4208          scale: 1.2,
4209          delay: 0,
4210        }),
4211        0,
4212        0
4213      );
4214      controller.addTween(
4215        $(this),
4216        TweenMax.from($(this).find(".txt-content"), 1, {
4217          ease: Power3.easeOut,
4218          alpha: 0,
4219          y: 100,
4220          delay: 0.7,
4221        }),
4222        0,
4223        0
4224      );
4225    }
4226
4227    if ($(this).hasClass("sec-standard-award")) {
4228      controller.addTween(
4229        $(this),
4230        TweenMax.from($(this).find(".txt-content"), 1, {
4231          ease: Power3.easeOut,
4232          alpha: 0,
4233          y: 100,
4234          delay: 0.5,
4235        }),
4236        0,
4237        0
4238      );
4239      controller.addTween(
4240        $(this),
4241        TweenMax.from($(this).find(".row.justify-content-center"), 1, {
4242          ease: Power3.easeOut,
4243          alpha: 0,
4244          y: 100,
4245          delay: 0.7,
4246        }),
4247        0,
4248        0
4249      );
4250    }
4251
4252    if ($(this).hasClass("sec-consult")) {
4253      controller.addTween(
4254        $(this),
4255        TweenMax.from($(this).find(".txt-content h2"), 1, {
4256          ease: Power3.easeOut,
4257          alpha: 0,
4258          y: 200,
4259          delay: 0.5,
4260        }),
4261        0,
4262        0
4263      );
4264      controller.addTween(
4265        $(this),
4266        TweenMax.from($(this).find(".txt-content.btn-line-block"), 1, {
4267          ease: Power3.easeOut,
4268          alpha: 0,
4269          y: 200,
4270          delay: 0.7,
4271        }),
4272        0,
4273        0
4274      );
4275    }
4276    if (!$(this).hasClass("auto-animate")) {
4277      if ($(this).hasClass("help-product-service")) {
4278        controller.addTween(
4279          $(this),
4280          TweenMax.from($(this), 2, {
4281            ease: Power3.easeOut,
4282            alpha: 0,
4283            y: -320,
4284            delay: 0.1,
4285          }),
4286          0,
4287          0
4288        );
4289      }
4290    }
4291    if (!$(this).hasClass("auto-animate")) {
4292      if ($(this).hasClass("sec-content")) {
4293        controller.addTween(
4294          $(this),
4295          TweenMax.from($(this).find(".thumb-txt .thumb-txt-h"), 1, {
4296            ease: Power3.easeOut,
4297            alpha: 0,
4298            y: 200,
4299            delay: 0.1,
4300          }),
4301          0,
4302          0
4303        );
4304        controller.addTween(
4305          $(this),
4306          TweenMax.from($(this).find(".thumb-txt .thumb-txt-p"), 1, {
4307            ease: Power3.easeOut,
4308            alpha: 0,
4309            y: 200,
4310            delay: 0.5,
4311          }),
4312          0,
4313          0
4314        );
4315        controller.addTween(
4316          $(this),
4317          TweenMax.from($(this).find(".thumb-txt .thumb-txt-a"), 1, {
4318            ease: Power3.easeOut,
4319            alpha: 0,
4320            y: 200,
4321            delay: 0.6,
4322          }),
4323          0,
4324          0
4325        );
4326        controller.addTween(
4327          $(this),
4328          TweenMax.from($(this).find(".thumb-img"), 1, {
4329            ease: Power3.easeOut,
4330            alpha: 0,
4331            y: 200,
4332            delay: 0.5,
4333          }),
4334          0,
4335          0
4336        );
4337        controller.addTween(
4338          $(this),
4339          TweenMax.from($(this).find(".txt-content"), 1, {
4340            ease: Power3.easeOut,
4341            alpha: 0,
4342            y: 200,
4343            delay: 0.1,
4344          }),
4345          0,
4346          0
4347        );
4348      }
4349    }
4350
4351    if ($(this).hasClass("thumb-video")) {
4352      controller.addTween(
4353        $(this),
4354        TweenMax.from($(this).find(".txt-content"), 1, {
4355          ease: Power3.easeOut,
4356          alpha: 0,
4357          y: 200,
4358          delay: 0.4,
4359        }),
4360        0,
4361        0
4362      );
4363      controller.addTween(
4364        $(this),
4365        TweenMax.from($(this).find(".thumb"), 1, {
4366          ease: Power3.easeOut,
4367          alpha: 0,
4368          y: 200,
4369          delay: 0.5,
4370        }),
4371        0,
4372        0
4373      );
4374    }
4375
4376    if (!$(this).hasClass("auto-animate")) {
4377      if ($(this).hasClass("group-product")) {
4378        controller.addTween(
4379          $(this),
4380          TweenMax.from($(this).find(".group-filter"), 1, {
4381            ease: Power3.easeOut,
4382            alpha: 0,
4383            y: 100,
4384            delay: 0.4,
4385          }),
4386          0,
4387          0
4388        );
4389        controller.addTween(
4390          $(this),
4391          TweenMax.from($(this).find(".fw.list-icon"), 1, {
4392            ease: Power3.easeOut,
4393            alpha: 0,
4394            y: 100,
4395            delay: 0.4,
4396          }),
4397          0,
4398          0
4399        );
4400        controller.addTween(
4401          $(this),
4402          TweenMax.from($(this).find(".txt-content h2"), 1, {
4403            ease: Power3.easeOut,
4404            alpha: 0,
4405            y: 100,
4406            delay: 0.2,
4407          }),
4408          0,
4409          0
4410        );
4411        controller.addTween(
4412          $(this),
4413          TweenMax.from($(this).find(".txt-content a"), 1, {
4414            ease: Power3.easeOut,
4415            alpha: 0,
4416            y: 100,
4417            delay: 0.3,
4418          }),
4419          0,
4420          0
4421        );
4422        controller.addTween(
4423          $(this),
4424          TweenMax.from($(this).find(".group-product-list"), 1, {
4425            ease: Power3.easeOut,
4426            alpha: 0,
4427            y: 100,
4428            delay: 0.6,
4429          }),
4430          0,
4431          0
4432        );
4433      }
4434    }
4435
4436    if ($(this).hasClass("sec-banner")) {
4437      controller.addTween(
4438        $(this),
4439        TweenMax.from($(this), 2, {
4440          ease: Power3.easeOut,
4441          alpha: 0,
4442          scale: 1.2,
4443          delay: 0,
4444        }),
4445        0,
4446        0
4447      );
4448      controller.addTween(
4449        $(this),
4450        TweenMax.from($(this).find("item-img"), 1, {
4451          ease: Power3.easeOut,
4452          alpha: 0,
4453          y: 100,
4454          delay: 0.2,
4455        }),
4456        0,
4457        0
4458      );
4459      controller.addTween(
4460        $(this),
4461        TweenMax.from($(this).find(".item-content"), 1, {
4462          ease: Power3.easeOut,
4463          alpha: 0,
4464          y: 100,
4465          delay: 0.2,
4466        }),
4467        0,
4468        0
4469      );
4470    }
4471
4472    if ($(this).hasClass("sec-banner-normal")) {
4473      controller.addTween(
4474        $(this),
4475        TweenMax.from($(this).find("picture img"), 1, {
4476          ease: Power3.easeOut,
4477          alpha: 0,
4478          scale: 1.2,
4479          delay: 0,
4480        }),
4481        0,
4482        0
4483      );
4484      controller.addTween(
4485        $(this),
4486        TweenMax.from($(this).find(".txt-content"), 1, {
4487          ease: Power3.easeOut,
4488          alpha: 0,
4489          y: 100,
4490          delay: 0.2,
4491        }),
4492        0,
4493        0
4494      );
4495    }
4496    if ($(this).hasClass("sec-search-dealer")) {
4497      controller.addTween(
4498        $(this),
4499        TweenMax.from($(this).find(".txt-content h2"), 1, {
4500          ease: Power3.easeOut,
4501          alpha: 0,
4502          y: 100,
4503          delay: 0.2,
4504        }),
4505        0,
4506        0
4507      );
4508      controller.addTween(
4509        $(this),
4510        TweenMax.from($(this).find(".box-search-dealer"), 1, {
4511          ease: Power3.easeOut,
4512          alpha: 0,
4513          y: 100,
4514          delay: 0.4,
4515        }),
4516        0,
4517        0
4518      );
4519      controller.addTween(
4520        $(this),
4521        TweenMax.from($(this).find(".txt-content a"), 1, {
4522          ease: Power3.easeOut,
4523          alpha: 0,
4524          y: 100,
4525          delay: 0.5,
4526        }),
4527        0,
4528        0
4529      );
4530    }
4531    if ($(this).hasClass("sec-banner-overlay")) {
4532      controller.addTween(
4533        $(this),
4534        TweenMax.from($(this).find("picture img"), 1, {
4535          ease: Power3.easeOut,
4536          alpha: 0,
4537          scale: 1.2,
4538          delay: 0,
4539        }),
4540        0,
4541        0
4542      );
4543      controller.addTween(
4544        $(this),
4545        TweenMax.from($(this).find(".box-overlay-img"), 1, {
4546          ease: Power3.easeOut,
4547          alpha: 0,
4548          y: 100,
4549          delay: 0.2,
4550        }),
4551        0,
4552        0
4553      );
4554      controller.addTween(
4555        $(this),
4556        TweenMax.from($(this).find(".box-overlay-content"), 1, {
4557          ease: Power3.easeOut,
4558          alpha: 0,
4559          y: 100,
4560          delay: 0.4,
4561        }),
4562        0,
4563        0
4564      );
4565    }
4566
4567    if ($(this).hasClass("sec-step-product")) {
4568      controller.addTween(
4569        $(this),
4570        TweenMax.from($(this).find(".bg-step picture img"), 2, {
4571          ease: Power3.easeOut,
4572          alpha: 0,
4573          scale: 1.2,
4574          delay: 0,
4575        }),
4576        0,
4577        0
4578      );
4579      controller.addTween(
4580        $(this),
4581        TweenMax.from($(this).find(".txt-content:not(.banner-content) h2"), 1, {
4582          ease: Power3.easeOut,
4583          alpha: 0,
4584          y: 100,
4585          delay: 0.2,
4586        }),
4587        0,
4588        0
4589      );
4590      controller.addTween(
4591        $(this),
4592        TweenMax.from($(this).find(".txt-content:not(.banner-content) p"), 1, {
4593          ease: Power3.easeOut,
4594          alpha: 0,
4595          y: 100,
4596          delay: 0.3,
4597        }),
4598        0,
4599        0
4600      );
4601      controller.addTween(
4602        $(this),
4603        TweenMax.from($(this).find(".comp-slide-fade .banner-content"), 1, {
4604          ease: Power3.easeOut,
4605          alpha: 0,
4606          x: -100,
4607          delay: 0.5,
4608        }),
4609        0,
4610        0
4611      );
4612      controller.addTween(
4613        $(this),
4614        TweenMax.from($(this).find(".comp-slide-fade .box-imgbg"), 1, {
4615          ease: Power3.easeOut,
4616          alpha: 0,
4617          x: 50,
4618          delay: 0.6,
4619        }),
4620        0,
4621        0
4622      );
4623      controller.addTween(
4624        $(this),
4625        TweenMax.from($(this).find(".list-step-slide-content"), 1, {
4626          ease: Power3.easeOut,
4627          alpha: 0,
4628          y: 100,
4629          delay: 0.8,
4630        }),
4631        0,
4632        0
4633      );
4634    }
4635
4636    if ($(this).hasClass("sec-knowledge")) {
4637      controller.addTween(
4638        $(this),
4639        TweenMax.from($(this).find(".border-b"), 1, {
4640          ease: Power3.easeOut,
4641          alpha: 0,
4642          y: 100,
4643          delay: 0.2,
4644        }),
4645        0,
4646        0
4647      );
4648      controller.addTween(
4649        $(this),
4650        TweenMax.from($(this).find(".col-12.col-md-3.col-lg-3"), 1, {
4651          ease: Power3.easeOut,
4652          alpha: 0,
4653          x: -100,
4654          delay: 0.4,
4655        }),
4656        0,
4657        0
4658      );
4659      controller.addTween(
4660        $(this),
4661        TweenMax.from($(this).find(".col-12.col-md-6.col-lg-6"), 1, {
4662          ease: Power3.easeOut,
4663          alpha: 0,
4664          x: 100,
4665          delay: 0.5,
4666        }),
4667        0,
4668        0
4669      );
4670    }
4671    if ($(this).hasClass("sec-info")) {
4672      controller.addTween(
4673        $(this),
4674        TweenMax.from($(this).find(".txt-content h2"), 1, {
4675          ease: Power3.easeOut,
4676          alpha: 0,
4677          y: 100,
4678          delay: 0.2,
4679        }),
4680        0,
4681        0
4682      );
4683      controller.addTween(
4684        $(this),
4685        TweenMax.from($(this).find(".col-12.col-md-12.col-lg-6"), 1, {
4686          ease: Power3.easeOut,
4687          alpha: 0,
4688          y: 100,
4689          delay: 0.4,
4690        }),
4691        0,
4692        0
4693      );
4694    }
4695  });
4696});
4697
4698///////////////////////////////////////
4699// ////////// ratingStar ///////////
4700///////////////////////////////////////
4701
4702function ratingStar(star) {
4703  star.click(function () {
4704    var stars = $(".ratingW").find("li");
4705    stars.removeClass("on");
4706    var thisIndex = $(this).parents("li").index();
4707    for (var i = 0; i <= thisIndex; i++) {
4708      stars.eq(i).addClass("on");
4709    }
4710    $(this)
4711      .closest("form")
4712      .find("input[name=star]")
4713      .val(thisIndex + 1);
4714    putScoreNow(thisIndex + 1);
4715  });
4716}
4717
4718function putScoreNow(i) {
4719  $(".scoreNow").html(i);
4720}
4721
4722$(function () {
4723  if ($(".ratingW").length > 0) {
4724    ratingStar($(".ratingW li a"));
4725  }
4726});
4727///////////////////////////////////////
4728///////////// Verify area /////////////
4729///////////////////////////////////////
4730function verifySerialReg($this) {
4731  var form = $this.closest("form");
4732  var serialnum = form.find(".serialnum");
4733  var phone_number = form.find("input[name=phone_number_serial]");
4734  var valid = true;
4735  var serial_count = 0;
4736  form.find(".form-group").removeClass("has-danger");
4737
4738  if (serialnum.val() == "") {
4739    valid = false;
4740    serialnum.parent().addClass("has-danger");
4741  }
4742
4743  if (phone_number.val() === "") {
4744    valid = false;
4745    phone_number.parent().addClass("has-danger");
4746  }
4747
4748  if (phone_number[0].value.length === 10) {
4749    valid = true;
4750  } else {
4751    valid = false;
4752    phone_number.parent().addClass("has-danger");
4753  }
4754
4755  if (valid) {
4756    verifySerialExists($this);
4757  }
4758}
4759
4760///////////////////////////////////////
4761// ////////// Count textarea ///////////
4762///////////////////////////////////////
4763
4764///////////////////////////////////////
4765// ////////// Muti Add Image ///////////
4766///////////////////////////////////////
4767
4768$(document).ready(function () {
4769  if (window.File && window.FileList && window.FileReader) {
4770    $("#files").on("change", function (e) {
4771      var files = e.target.files,
4772        filesLength = files.length;
4773      for (var i = 0; i < filesLength; i++) {
4774        var f = files[i];
4775        var fileReader = new FileReader();
4776        fileReader.onload = function (e) {
4777          var file = e.target;
4778          $(
4779            '<div class="img-thumb-wrapper card">' +
4780              '<img class="img-thumb" src="' +
4781              e.target.result +
4782              '" title="' +
4783              file.name +
4784              '"/>' +
4785              '<span class="remove remove-img-review"><img class="svg" src="/assets/img/skin/remove-img.svg"></span>' +
4786              "</div>"
4787          ).insertBefore(".box-add-img-review");
4788          $(".remove").click(function () {
4789            $(this).parent(".img-thumb-wrapper").remove();
4790          });
4791        };
4792        fileReader.readAsDataURL(f);
4793      }
4794      $(".popout").trigger("click");
4795    });
4796  } else {
4797    alert("Your browser doesn't support to File API");
4798  }
4799
4800  // $('input[type=text],input[type=password],input[type=email],input[type=tel]').on("cut copy paste",function(e) {
4801  //   e.preventDefault();
4802  // });
4803});
4804
4805function generateContent() {
4806  var editor_elem = $(".ohm-content");
4807  var editor_count = editor_elem.length;
4808
4809  for (let editor_ind = 0; editor_ind < editor_count; editor_ind++) {
4810    const content = editor_elem.eq(editor_ind);
4811
4812    if (json[editor_ind] !== "") {
4813      var data = JSON.parse(json[editor_ind]);
4814
4815      var row_count = data.length;
4816
4817      for (let row_index = 0; row_index < row_count; row_index++) {
4818        if (data[row_index][0] === "col") {
4819          var row_data_count = data[row_index].length;
4820          var array_col_data = [];
4821
4822          for (
4823            let row_data_ind = 4;
4824            row_data_ind < row_data_count;
4825            row_data_ind++
4826          ) {
4827            const col_data = data[row_index][row_data_ind];
4828            array_col_data.push(col_data);
4829          }
4830          if (parseInt(data[row_index][3][0]) == 0) {
4831            var col1 = data[row_index][1];
4832            var col2 = data[row_index][2];
4833            createCol(content, col1, col2);
4834          } else if (parseInt(data[row_index][3][0]) == 1) {
4835            var col1 = data[row_index][1];
4836            var col2 = data[row_index][2];
4837            createFullCol(content, col1, col2, data[row_index][3]);
4838          }
4839
4840          var col_data_count = array_col_data.length;
4841          if (parseInt(data[row_index][3][0]) == 0) {
4842            // 66 48 84 length 2
4843            for (
4844              let col_data_index = 0;
4845              col_data_index < col_data_count;
4846              col_data_index++
4847            ) {
4848              const col_data = array_col_data[col_data_index];
4849
4850              const data_count = col_data.length;
4851
4852              for (let data_index = 0; data_index < data_count; data_index++) {
4853                if (col_data[data_index][0] === "dropify") {
4854                  if (col_data_index == 0) {
4855                    createContentImage(
4856                      content,
4857                      row_index,
4858                      col_data[data_index],
4859                      "l",
4860                      data_count
4861                    );
4862                  } else if (col_data_index == 1) {
4863                    createContentImage(
4864                      content,
4865                      row_index,
4866                      col_data[data_index],
4867                      "r",
4868                      data_count
4869                    );
4870                  }
4871                } else if (col_data[data_index][0] === "summernote") {
4872                  if (col_data_index == 0) {
4873                    createContentText(
4874                      content,
4875                      row_index,
4876                      col_data[data_index],
4877                      "l"
4878                    );
4879                  } else if (col_data_index == 1) {
4880                    createContentText(
4881                      content,
4882                      row_index,
4883                      col_data[data_index],
4884                      "r"
4885                    );
4886                  }
4887                }
4888              }
4889            }
4890          } else if (parseInt(data[row_index][3][0]) == 1) {
4891            /* bg is full check if summernote is on left or right */
4892            for (
4893              let col_data_index = 0;
4894              col_data_index < col_data_count;
4895              col_data_index++
4896            ) {
4897              const col_data = array_col_data[col_data_index];
4898              const data_count = col_data.length;
4899
4900              for (let data_index = 0; data_index < data_count; data_index++) {
4901                if (col_data[data_index][0] === "dropify") {
4902                  if (col_data_index == 0) {
4903                    createContentImage(
4904                      content,
4905                      row_index,
4906                      col_data[data_index],
4907                      "l",
4908                      data_count
4909                    );
4910                  } else if (col_data_index == 1) {
4911                    createContentImage(
4912                      content,
4913                      row_index,
4914                      col_data[data_index],
4915                      "r",
4916                      data_count
4917                    );
4918                  }
4919                } else if (col_data[data_index][0] === "summernote") {
4920                  if (col_data_index == col_data_count - 1) {
4921                    createContentText(
4922                      content,
4923                      row_index,
4924                      col_data[data_index],
4925                      "r"
4926                    );
4927                  } else {
4928                    createContentText(
4929                      content,
4930                      row_index,
4931                      col_data[data_index],
4932                      "l"
4933                    );
4934                  }
4935                }
4936              }
4937            }
4938          }
4939        }
4940      }
4941    }
4942  }
4943}
4944
4945function fullCont(elem, ind, data, summer_data, side) {
4946  var lang = $("html").attr("lang");
4947  var summernote_data = summer_data[1];
4948  var summernote_data_count = summernote_data.length;
4949  var lang_data = "";
4950  for (let index = 0; index < summernote_data_count; index++) {
4951    const data = summernote_data[index];
4952    if (data[0] === lang) {
4953      lang_data = data[1];
4954      break;
4955    }
4956  }
4957
4958  html = "";
4959
4960  html +=
4961    '<div class="box-thumb fw position-relative text-left text-start mb-0">';
4962  html += "<picture>";
4963  html +=
4964    '<source media="(max-width:767.98px)" srcset="/' +
4965    upload +
4966    "/" +
4967    data[3] +
4968    "/" +
4969    data[2] +
4970    '">';
4971  html +=
4972    '<img class="fw" src="/' +
4973    upload +
4974    "/" +
4975    data[3] +
4976    "/" +
4977    data[1] +
4978    '" alt="" style="transform: translate(0px, 0px); opacity: 1;">';
4979  html += "</picture>";
4980  html += '<div class="container container-1360">';
4981  if (side === "r") {
4982    html += '<div class="content-abs content-abs-cr">';
4983  } else if (side === "l") {
4984    html += '<div class="content-abs content-abs-cl">';
4985  }
4986  html +=
4987    '<div class="thumb-txt " style="transform: translate(0px, 0px); opacity: 1;">';
4988  html +=
4989    '<div class="txt-content" style="transform: translate(0px, 0px); opacity: 1;">';
4990  html += lang_data;
4991  html += "</div>";
4992  html += "</div>";
4993  html += "</div>";
4994  html += "</div>";
4995  html += "</div>";
4996
4997  elem.append(html);
4998}
4999
5000function createCol(content_elem, col1, col2) {
5001  html = "";
5002  html += '<div class="container container-1360">';
5003  html += '<div class="row box-banner-overlay">';
5004
5005  html += '<div class="col-md-' + col1 + ' col-12 left">';
5006  html += "</div>";
5007
5008  html += '<div class="col-md-' + col2 + ' col-12 right">';
5009  html += "</div>";
5010
5011  html += "</div>";
5012  html += "</div>";
5013
5014  content_elem.append(html);
5015}
5016
5017function createFullCol(content_elem, col1, col2, bg_data) {
5018  html = "";
5019  html += '<div class="box-banner-overlay cpst-y fw">';
5020
5021  html += "<picture>";
5022  html +=
5023    '<source media="(max-width:767.98px)" srcset="/' +
5024    upload +
5025    "/" +
5026    bg_data[3] +
5027    "/" +
5028    bg_data[2] +
5029    '">';
5030  html +=
5031    '<img src="/' + upload + "/" + bg_data[3] + "/" + bg_data[1] + '" alt="">';
5032  html += "</picture>";
5033  html += '<div class="container container-1360 position-relative">';
5034  html += '<div class="row cont-abs">';
5035
5036  html += '<div class="col-md-' + col1 + ' col-12 left">';
5037  html += "</div>";
5038
5039  html += '<div class="col-md-' + col2 + ' col-12 right">';
5040  html += "</div>";
5041
5042  html += "</div>";
5043  html += "</div>";
5044
5045  html += "</div>";
5046  content_elem.append(html);
5047}
5048
5049function createContentImage(elem, ind, data, side, data_arr_len) {
5050  html = "";
5051  html += '<img src="/' + upload + "/" + data[1] + "/" + data[2] + '" alt="">';
5052
5053  var parent_element = elem.find(".row").eq(ind);
5054
5055  if (side === "l") {
5056    parent_element.find(".left").append(html);
5057    if (data_arr_len == 1) {
5058      parent_element.find(".left").addClass("ohm-img-align");
5059    }
5060  } else if (side === "r") {
5061    parent_element.find(".right").append(html);
5062    if (data_arr_len == 1) {
5063      parent_element.find(".right").addClass("ohm-img-align");
5064    }
5065  }
5066}
5067
5068function createContentText(elem, ind, data, side) {
5069  html = "";
5070  var lang = $("html").attr("lang");
5071  var summernote_data = data[1];
5072  var summernote_data_count = summernote_data.length;
5073  var lang_data = "";
5074  for (let index = 0; index < summernote_data_count; index++) {
5075    const data = summernote_data[index];
5076    if (data[0] === lang) {
5077      lang_data = data[1];
5078      break;
5079    }
5080  }
5081
5082  html += '<div class="txt-content cont-fix-ps-2">';
5083  html += lang_data;
5084  html += "</div>";
5085
5086  var parent_element = elem.find(".box-banner-overlay").eq(ind);
5087  if (side === "l") {
5088    parent_element.find(".left").append(html);
5089    if (!parent_element.find(".left").hasClass("ohm-text-align")) {
5090      parent_element.find(".left").addClass("ohm-text-align");
5091    }
5092  } else if (side === "r") {
5093    parent_element.find(".right").append(html);
5094    if (!parent_element.find(".right").hasClass("ohm-text-align")) {
5095      parent_element.find(".right").addClass("ohm-text-align");
5096    }
5097  }
5098}
5099
5100function submitReportProduct($this) {
5101  var form = $this.closest("form");
5102  var isValid = true;
5103
5104  form.find(".form-text.validate").hide();
5105
5106  var name = form.find('input[name="name"]').val();
5107  if (name.trim() === "") {
5108    form.find('input[name="name"]').siblings(".form-text.validate").show();
5109    isValid = false;
5110  }
5111
5112  var phoneNumber = form.find('input[name="phone_number"]').val();
5113  var phoneRegex = /^\d{10}$/;
5114  if (!phoneRegex.test(phoneNumber)) {
5115    form
5116      .find('input[name="phone_number"]')
5117      .siblings(".form-text.validate")
5118      .show();
5119    isValid = false;
5120  }
5121
5122  var orderId = form.find('input[name="order_id"]').val();
5123  if (orderId && !/^PURE\d+$/.test(orderId)) {
5124    form.find('input[name="order_id"]').siblings(".form-text.validate").show();
5125    isValid = false;
5126  }
5127
5128  var problemTypeChecked =
5129    form.find('input[name^="problem_type_"]:checked').length > 0;
5130  if (!problemTypeChecked) {
5131    form.find(".problem-type-error").show();
5132    isValid = false;
5133  }
5134
5135  var otherText = form.find('input[name="other_text"]').val();
5136  if (
5137    form.find('input[name="problem_type_2"]').is(":checked") &&
5138    otherText.trim() === ""
5139  ) {
5140    form
5141      .find('input[name="other_text"]')
5142      .siblings(".form-text.validate")
5143      .show();
5144    isValid = false;
5145  }
5146
5147  var problemDetail = form.find('textarea[name="problem_detail"]').val();
5148  if (problemDetail.trim() === "") {
5149    form
5150      .find('textarea[name="problem_detail"]')
5151      .siblings(".form-text.validate")
5152      .show();
5153    isValid = false;
5154  }
5155
5156  if (isValid) {
5157    form.submit();
5158  }
5159}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.