PageSourceSearch

https://hube.kz/templates/hube/js/scripts.js?v=5.0.6

js hube.kz collected 2026-10-02 18:48:32 UTC 71,683 bytes, 2,774 lines download raw bytes

1function setTranslateText($this) {
2  var note = $this.data("note");
3
4  if (note in translate) {
5    note = translate[note];
6  }
7
8  $this.html(note).removeAttr("data-note");
9}
10
11function setTranslateChildText($parent) {
12  $("[data-note]", $parent).each(function () {
13    setTranslateText($(this));
14  });
15}
16
17function getSearchResults() {
18  $(".search_results").hide();
19  $(".search_results").html("");
20  $.ajax({
21    type: "POST",
22    data: { action: "quick_search", search: q },
23    success: function (data) {
24      var res = $.parseJSON(data);
25      if (res.return !== "") {
26        $(".search_results").html(res.return);
27        $(".search_results").show();
28      } else {
29        $(".searcfh_results").hide();
30      }
31    },
32  });
33}
34
35function lazy() {
36  $(".lazyimage").lazy({
37    effect: "fadeIn",
38    visibleOnly: false,
39    threshold: 200,
40    delay: 200,
41    afterLoad: function (element) {
42      element.attr("style", "");
43      element.removeClass("lazyimage");
44    },
45  });
46}
47
48function masks() {
49  $("input.phone").off();
50  $("input.phone, input[name=phone]").inputmask("+7-999-999-99-99");
51  $(".confirm").off();
52  $(".confirm").inputmask("9999");
53  $(".mask-card-number").off();
54  $(".mask-card-number").inputmask("9999 9999 9999 9999 9999", { placeholder: " " });
55  $(".mask-card-cvv").off();
56  $(".mask-card-cvv").inputmask("9999", { placeholder: " " });
57  $(".mask-card-exp").off();
58  $(".mask-card-exp").inputmask("99", { placeholder: " " });
59  $(".mask-card-cardholder").off();
60  $(".mask-card-cardholder").inputmask({ regex: "[a-zA-Z- ]*", casing: "upper" });
61}
62
63function doPrepay() {
64  var amount = $("#prepay_amount").val();
65  var name = $("#prepay_name").val();
66  $.ajax({
67    type: "POST",
68    data: { action: "prepay", amount: amount, name: name },
69    success: function (data) {
70      var res = $.parseJSON(data);
71      if (res.result == 1) {
72        $("#prepay_btn").attr("href", res.href);
73        $("#prepay_btn").show();
74      } else {
75        $("#prepay_btn").hide();
76      }
77    },
78  });
79}
80
81function showSearch() {
82  $("#mobile_search").toggle();
83  $("#mobile_search .search_input").focus();
84}
85
86function hiddenSearch() {
87  $("#mobile_search").hide(0);
88}
89
90function showFullOne() {
91  $("#basic-menu-nav").toggle();
92  $("#full-one").toggle();
93}
94
95function showLanguage() {
96  $("#basic-menu-nav").toggle();
97  $("#language-one").toggle();
98}
99
100function showCities() {
101  $("#basic-menu-nav").toggle();
102  $("#city-one").toggle();
103}
104
105function cartStep(id, el) {
106  var ok = 1;
107
108  $("#order_form .step-current input, #order_form .step-current textarea").each(function () {
109    if ($(this).prop("required")) {
110      var value = $(this).val();
111      if (value == "") {
112        $(this).addClass("err");
113        ok = 0;
114      } else if (typeof value == "undefined") {
115        $(this).addClass("err");
116        ok = 0;
117      } else {
118        $(this).removeClass("err");
119      }
120    }
121  });
122
123  if (!ok) {
124    $("#order_form input").focus();
125    return false;
126  }
127
128  if (id === "the_list_of_deliveries" && el) {
129    var rawGa4 = $(el).attr("data-ga4-begin-checkout");
130    if (rawGa4) {
131      try {
132        var ga4CheckoutData = JSON.parse(rawGa4);
133
134        window.dataLayer = window.dataLayer || [];
135        window.dataLayer.push({ ecommerce: null });
136        window.dataLayer.push({
137          event: "begin_checkout",
138          ecommerce: ga4CheckoutData
139        });
140      } catch (e) {
141        console.log("begin_checkout parse error", e);
142      }
143    }
144  }
145
146  $(".step-current").removeClass("step-current");
147
148  $(".step_point").each(function () {
149    var this_id = $(this).attr("id");
150    if (id == this_id) {
151      $(this).show();
152      $(this).addClass("step-current");
153    } else {
154      $(this).hide();
155    }
156  });
157
158  $("html, body").animate(
159    {
160      scrollTop: parseInt($("#" + id).offset().top) - 50
161    },
162    200
163  );
164}
165
166function plusRate(id) {
167  $.ajax({
168    type: "POST",
169    data: { action: "rate", id: id, where: "plus" },
170    success: function (data) {
171      var res = $.parseJSON(data);
172      if (res.result == 1) {
173        var current = parseInt(
174          $('.comment-rate[data-id="' + id + '"]')
175            .find(".the_rate")
176            .html()
177        );
178        current++;
179        $('.comment-rate[data-id="' + id + '"]')
180          .find(".the_rate")
181          .html(current);
182      }
183    },
184  });
185}
186
187function minusRate(id) {
188  $.ajax({
189    type: "POST",
190    data: { action: "rate", id: id, where: "minus" },
191    success: function (data) {
192      var res = $.parseJSON(data);
193      if (res.result == 1) {
194        var current = parseInt(
195          $('.comment-rate[data-id="' + id + '"]')
196            .find(".the_rate")
197            .html()
198        );
199        current--;
200        $('.comment-rate[data-id="' + id + '"]')
201          .find(".the_rate")
202          .html(current);
203      }
204    },
205  });
206}
207
208var timer = 0;
209var q = "";
210var close = 1;
211
212function untoggleAll() {
213  $(".filter-vars").show();
214}
215
216// функция проверки ширины
217function is_width(width) {
218  return window.matchMedia("(max-width: " + width + "px)").matches;
219}
220
221if (is_width(767) && $(".div_to_load_products").length) {
222  var lastScrollTop = 0,
223    $body = $("body");
224
225  $body.addClass("is_catalog");
226
227  window.addEventListener(
228    "scroll",
229    function () {
230      var st = window.pageYOffset || document.documentElement.scrollTop;
231      if (st > lastScrollTop) {
232        $body.attr("data-scroll_dir", "down");
233      } else {
234        $body.attr("data-scroll_dir", "up");
235      }
236
237      lastScrollTop = st <= 0 ? 0 : st;
238    },
239    false
240  );
241}
242
243$(document).ready(function () {
244  masks();
245  favShow();
246
247  /*$.getScript('https://kaspi.kz/kaspibutton/widget/ks-wi_ext.js', function () {
248        ksWidgetInitializer.reinit()
249    })*/
250
251  if (!is_width(1199)) {
252    var $window = $(window),
253      $header = $(".header-fixed"),
254      headerTop = $(".header-wrap").height();
255
256    $window.scroll(function () {
257      scroll_header_fixed($header, headerTop);
258    });
259  }
260
261  var $notes = $(".note-load[data-note]");
262  if ($notes.length) {
263    $notes.each(function () {
264      setTranslateText($(this));
265    });
266  }
267
268  $("body").on("click", ".btn-fast-buy", function () {
269    var id = $(this).attr("data-id");
270
271    $("#one_click_product").val(id);
272    reachGoal("ym_goal_open_kupit_v_1_klik");
273  });
274
275  /*$('body').on('blur', '.credit-kaspi iframe', function () {
276    })
277
278    $('body').on('click', function () {
279    })*/
280
281  /*$('.hover-nav li>a').on('mouseenter', function() {
282        var $this  = $(this),
283            $promo = $this.next('.hover-nav');
284        
285        if (!$promo.length) {
286            return false;
287        } 
288        
289        $('#hover_sub_menu .paster__').html( $promo.html() );
290        $('#hover_sub_menu').show(100);
291    });
292    
293    $('.hover-nav li>a').on('mouseleave', function(e) {        
294        if (!$(e.relatedTarget).hasClass('nav-advert')) {
295            $('#hover_sub_menu').hide(0);    
296        }        
297    });
298    */
299  $("body").on("click", ".how-pick-bike", function () {
300    $.fancybox.open($("#pick_bike"));
301  });
302
303  $("#mobile_nav .fav-block").click(function () {
304    $(".product-in-btn-price .fav").trigger("click");
305  });
306
307  $(".faq .faq-question").click(function () {
308    var $faq = $(this).closest(".faq");
309
310    if ($faq.hasClass("open")) {
311      $faq.removeClass("open");
312    } else {
313      $faq.closest(".faqs").find(".faq.open").removeClass("open");
314
315      $faq.addClass("open");
316    }
317  });
318
319  $(".spoiler-button").click(function () {
320    var $this = $(this),
321      next = $this.data("next");
322
323    $this.closest(".spoiler").toggleClass("active");
324
325    $this.data("next", $this.text());
326    $this.text(next);
327  });
328
329  $("#mobile_nav #slide_menu .hover-parent > a i").click(function () {
330    var $closest = $(this).closest("li");
331
332    if ($("ul li", $closest).length) {
333      $closest.toggleClass("active");
334      return false;
335    }
336  });
337
338  $(".sorter, .period-selector").click(function () {
339    $(this).toggleClass("active");
340  });
341
342  $(".filter_mobile .side-heading").click(function () {
343    $(".filter_mobile").hide(0);
344  });
345
346  $("#prepay_name, #prepay_amount").keyup(function () {
347    doPrepay();
348  });
349
350  action = "click";
351
352  if ($(window).width() < 999) {
353    //action = 'touchstart';
354  }
355
356  $(".city-sel").on(action, function () {
357    var oldCity = Cookies.get("city"),
358      newCity = $(this).data("city"),
359      url = window.location.pathname,
360      exec = ["/sitemap", "/cart", "/done", "/favourites", "/difference", "/lk", "/search"];
361
362    Cookies.set("city", newCity);
363
364    if ("/" == url) {
365      url = url + newCity;
366    } else if (oldCity == "catalog") {
367      url = "/" + newCity + url;
368    } else if (oldCity && -1 == $.inArray(url, exec)) {
369      url = url.replace(new RegExp(oldCity, "i"), newCity);
370    } else {
371      window.location.reload();
372      return;
373    }
374
375    //console.log(url)
376
377    window.location.href = url;
378  });
379
380  if ($(window).width() < 1200) {
381    $(".filter_main:not(.filter_mobile)").remove();
382  } else {
383    $(".filter_main.filter_mobile").remove();
384  }
385
386  $(".filter_header").on("click", function () {
387    $(this).closest(".list-group").find(".filter-vars").toggle();
388  });
389  $(".search_input").keyup(function () {
390    q = this.value;
391    getSearchResults();
392  });
393
394  $(".search_input").focusout(function () {
395    if (close == 1) {
396      $(".search_results").hide();
397    }
398  });
399  $(".search_input").focusin(function () {
400    var content = $(".search_results").html();
401    if ($.trim(content) !== "") {
402      $(".search_results").show();
403    }
404  });
405  $(".search_results")
406    .mouseover(function () {
407      close = 0;
408    })
409    .mouseout(function () {
410      close = 1;
411    });
412});
413
414var pressedKeys = [];
415
416window.onload = function () {
417  ui_inputs();
418};
419
420$(".credit_btn_apply").click(function () {
421  $this = $(this);
422
423  creditApply($this.attr("data-product"), $this.attr("data-period"));
424
425  reachGoal("ym_goal_rassrochka_form");
426});
427
428function creditApply(id, period) {
429  $("#credit_product").val(id);
430  $("#period").val(period);
431
432  $.fancybox.open($("#credit_form"), {
433    autoScale: true,
434    transitionIn: "elastic",
435    transitionOut: "elastic",
436    speedIn: 500,
437    speedOut: 300,
438    autoDimensions: true,
439    centerOnScroll: true,
440    padding: 0,
441    beforeShow: function (instance, current) {
442      setTranslateChildText($(current.src));
443    },
444  });
445}
446
447function showCartMessage(content) {
448  $("#addedtocart .pop-up-form").html(content);
449  $.fancybox.open($("#addedtocart"), {
450    autoScale: true,
451    transitionIn: "elastic",
452    transitionOut: "elastic",
453    speedIn: 500,
454    speedOut: 300,
455    autoDimensions: true,
456    centerOnScroll: true,
457    padding: 0,
458  });
459  setTimeout(function () {
460    startTheOwl($("#addedtocart .owl-carousel"));
461  }, 500);
462}
463
464var clicked_load = 0;
465$(window).scroll(function () {
466  if ($("#load_more").length > 0) {
467    var load = $("#load_more");
468    var current = $(window).height() + $(document).scrollTop();
469    var offset = parseInt(load.offset().top);
470    var do_click = parseInt(offset + 150);
471    var no_click = parseInt(offset - 150);
472
473    /*
474        if (offset !== clicked_load) {
475            if (no_click < current) {
476                if (do_click > current) {
477                    clicked_load = offset;
478                    
479                    load.click();
480                    load.hide();
481                }
482            }
483        }
484        */
485  }
486
487  if ($(this).scrollTop() > 100) {
488    if ($(".back-to-top").is(":hidden")) {
489      $(".back-to-top").css({ opacity: 1 }).fadeIn("slow");
490    }
491  } else {
492    $(".back-to-top").stop(true, false).fadeOut("fast");
493  }
494});
495
496function subscribe(btn) {
497  var holder = $(btn).closest(".sub-block");
498  var email = holder.find(".email").val();
499  var ok = 1;
500
501  if (holder.find("#checkbox").length) {
502    if (!holder.find("#checkbox").is(":checked")) {
503      ok = 0;
504    }
505  }
506  keys = pressedKeys.join(",");
507  if (ok == 1) {
508    $.ajax({
509      type: "POST",
510      data: { keys: keys, email: email, action: "subs" },
511      success: function (data) {
512        var obj = jQuery.parseJSON(data);
513        if (obj.result == 1) {
514          holder.html(obj.message);
515        }
516      },
517    });
518  }
519}
520
521$(document).ready(function () {
522  $(".brand-holder").on("click", function () {
523    $(".brand-holder").removeClass("active");
524    var desc = $(this).find(".brand-desc-content").html();
525
526    $("#brand-description-block").html(desc);
527    $(this).addClass("active");
528  });
529
530  if ($(".article").length) {
531    var ToC = "<nav role='navigation' class='table-of-contents'><span>Содержание:</span><ul>";
532    var newLine, el, title, link, subel, subtitle, subid, id, sublink;
533    var i = 0;
534
535    var add = 0;
536    $(".article h2").each(function () {
537      add = 1;
538      el = $(this);
539      title = el.text();
540      id = el.attr("id");
541      if (typeof id == "undefined") {
542        id = "h2" + i;
543        $(this).attr("id", id);
544      }
545      link = "#" + id;
546
547      newLine = "<li><a href='" + link + "'>" + title + "</a>";
548
549      ToC += newLine;
550
551      var j = 0;
552      var subs = "";
553      $(this)
554        .nextAll()
555        .each(function () {
556          if (this.tagName == "H2") {
557            return false;
558          } else {
559            if (this.tagName == "H3") {
560              subel = $(this);
561              subtitle = subel.text();
562              subid = subel.attr("id");
563              if (typeof subid == "undefined") {
564                subid = "h3" + j;
565                $(this).attr("id", subid);
566              }
567              sublink = "#" + subid;
568
569              subs += "<li><a href='" + sublink + "'>" + subtitle + "</a></li>";
570              j++;
571            }
572          }
573        });
574
575      if (subs !== "") {
576        ToC += "<ul>" + subs + "</ul>";
577      }
578
579      ToC += "</li>";
580      i++;
581    });
582
583    ToC += "</ul>" + "</nav>";
584
585    if (add == 1) {
586      ///$(".article").prepend(ToC);
587    }
588  }
589
590  $('[data-toggle="popover"]').popover();
591  $(document).mouseup(function (e) {
592    var container = $(".popover-content");
593    container.off();
594    if (!container.is(e.target) && container.has(e.target).length === 0) {
595      $('[data-toggle="popover"]').popover("hide");
596    }
597  });
598
599  $("#the_slider").carousel();
600
601  $(".ui_input").bind("keyup change", function (e) {
602    val = $(this).val();
603    val = val.replace(/./g, "*");
604    val = $.trim(val);
605    if (val.length > 0) {
606      if (!$(this).closest(".ui_label_group").hasClass("ui_has_value")) {
607        $(this).closest(".ui_label_group").addClass("ui_has_value");
608      }
609    } else {
610      if ($(this).closest(".ui_label_group").hasClass("ui_has_value")) {
611        $(this).closest(".ui_label_group").removeClass("ui_has_value");
612      }
613    }
614  });
615  $(".lazy").Lazy({
616    scrollDirection: "vertical",
617    effect: "fadeIn",
618    visibleOnly: true,
619    onError: function (element) {
620      console.log("error loading " + element.data("src"));
621    },
622  });
623  $("body").bind("keypress", function (e) {
624    pressedKeys[pressedKeys.length] = e.keyCode;
625  });
626  $('input[type="submit"]').bind("click", function (e) {
627    pressedKeys[pressedKeys.length] = "clicked_submit";
628  });
629
630  $(".carousel").carousel();
631
632  $(".search_input").bind("keypress", function (e) {
633    if (e.keyCode == 13) {
634      e.preventDefault();
635      id = $(this).closest("form").attr("id");
636      searchIt(id);
637    }
638  });
639
640  $(".btn-nav").on("click tap", function () {
641    hiddenSearch();
642    $(".nav-content").toggleClass("showNav hideNav").removeClass("hidden");
643    $(this).toggleClass("animated");
644  });
645
646  $(".toggle_button").on("click tap", function () {
647    var what = $(this).attr("what");
648    $("." + what).slideToggle("fast", function () {});
649  });
650
651  $(".search_cat").on("click", function () {
652    if ($(".search_cat").hasClass("open")) {
653      $(".search_cat").removeClass("open");
654    } else {
655      $(".search_cat").addClass("open");
656    }
657  });
658
659  $(".shorty_more").on("click", function () {
660    $("html, body").animate(
661      {
662        scrollTop: $("#desc_line").offset().top,
663      },
664      1000
665    );
666  });
667
668  $(".brand-nav").on("click", function () {
669    var link = $(this).attr("href");
670    $("html, body").animate(
671      {
672        scrollTop: $(link).offset().top,
673      },
674      1000
675    );
676  });
677
678  $(".zoomer").click(function () {
679    $("#launch_the_show").click();
680  });
681
682  loadDifferentCarousel();
683
684  $(".ajax_submit_reload").submit(function (e) {
685    e.preventDefault();
686    showPreloader();
687    id = $(this).attr("id");
688    keys = pressedKeys.join(",");
689    var m_method = $(this).attr("method");
690    var m_action = $(this).attr("action");
691    var m_data = $(this).serialize();
692    $.ajax({
693      type: m_method,
694      url: m_action,
695      data: m_data + "&keys=" + keys,
696      success: function (data) {
697        var obj = jQuery.parseJSON(data);
698        $("#" + id + "_result").html(obj.message);
699        if (obj.result == 1) {
700          track("form_submit");
701          location.reload();
702        } else {
703          hidePreloader();
704          $("#" + id + "_result").focus();
705        }
706      },
707      error: function (jqXHR, exception) {
708        var msg = "";
709        if (jqXHR.status === 0) {
710          msg = "Not connect.\n Verify Network.";
711        } else if (jqXHR.status == 404) {
712          msg = "Requested page not found. [404]";
713        } else if (jqXHR.status == 500) {
714          msg = "Internal Server Error [500].";
715        } else if (exception === "parsererror") {
716          msg = "Requested JSON parse failed.";
717        } else if (exception === "timeout") {
718          msg = "Time out error.";
719        } else if (exception === "abort") {
720          msg = "Ajax request aborted.";
721        } else {
722          msg = "Uncaught Error.\n" + jqXHR.responseText;
723        }
724        console.log(msg);
725      },
726    });
727  });
728
729  $(".order-calling").click(function () {
730    reachGoal("ym_goal_call");
731  });
732
733  $(".ajax_submit").submit(function (e) {
734    e.preventDefault();
735    showPreloader();
736    var $this = $(this);
737    var id = $this.attr("id");
738    keys = pressedKeys.join(",");
739    var m_method = $this.attr("method");
740    var m_action = $this.attr("action");
741    var m_data = $this.serialize();
742
743
744    $.ajax({
745      type: m_method,
746      url: m_action,
747      data: m_data + "&keys=" + keys,
748      success: function (data) {
749        var obj = jQuery.parseJSON(data);
750        $("#" + id + "_result").html(obj.message);
751        hidePreloader();
752        $("#" + id + "_result").focus();
753
754        if (obj.result == 1) {
755          track("form_submit");
756        }
757
758        if (typeof obj.url != "undefined") {
759          window.open(obj.url, "_blank");
760        }
761
762        if ($this.is("#credit_apply")) {
763          reachGoal("ym_goal_rassrochka_sent");
764        }
765
766        if ($this.is("#one-click-buy")) {
767          reachGoal("ym_goal_send_kupit_v_1_klik");
768        }
769        if ($this.is("#contacts_form")) {
770          track("send_support");
771        }
772        if ($this.is("#order_this_product")) {
773          track("send_on_request");
774        }
775        if ($this.is("#the_recall_form")) {
776          reachGoal("ym_goal_confirm_call");
777        }
778      },
779    });
780  });
781
782  $("input.phone").keydown(function (event) {
783    if (
784      event.keyCode == 46 ||
785      event.keyCode == 8 ||
786      event.keyCode == 9 ||
787      event.keyCode == 27 ||
788      event.keyCode == 13 ||
789      (event.keyCode == 65 && event.ctrlKey === true) ||
790      (event.keyCode >= 35 && event.keyCode <= 39)
791    ) {
792      return;
793    } else {
794      // If it's not a number stop the keypress
795      if (
796        event.shiftKey ||
797        ((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105))
798      ) {
799        event.preventDefault();
800      }
801    }
802  });
803});
804
805dynamicFunctions();
806
807function startTheOwl(the_carousel) {
808  if (the_carousel.attr("thumbs") != undefined) {
809    var th = true;
810  } else {
811    var th = false;
812  }
813
814  var items_count = parseInt(the_carousel.find(".item").length);
815  var loop = the_carousel.attr("loop");
816  var margin = parseInt(the_carousel.attr("margin"));
817  var zero = parseInt(the_carousel.attr("zero"));
818  var six = parseInt(the_carousel.attr("six"));
819  var ten = parseInt(the_carousel.attr("ten"));
820
821  if (items_count > ten) {
822    var nav_ten_state = true;
823  } else {
824    var nav_ten_state = false;
825  }
826  if (items_count > six) {
827    var nav_six_state = true;
828  } else {
829    var nav_six_state = false;
830  }
831  if (items_count > zero) {
832    var nav_zero_state = true;
833  } else {
834    var nav_zero_state = false;
835  }
836
837  the_carousel.on("initialized.owl.carousel", function (e) {
838    updateNumbers(e.page.index, e.page.count, the_carousel);
839  });
840
841  the_carousel.owlCarousel({
842    thumbs: th,
843    thumbImage: th,
844    thumbContainerClass: "owl-thumbs",
845    thumbItemClass: "owl-thumb-item",
846    margin: margin,
847    loop: true,
848    freeDrag: false,
849    responsiveClass: true,
850    slideBy: "page",
851    responsive: {
852      0: {
853        items: zero,
854        pagination: false,
855        nav: nav_zero_state,
856        navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
857      },
858      600: {
859        items: six,
860        pagination: false,
861        nav: nav_six_state,
862        navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
863      },
864      1000: {
865        items: ten,
866        pagination: false,
867        nav: nav_ten_state,
868        navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
869      },
870    },
871  });
872  the_carousel.on("changed.owl.carousel", function (e) {
873    updateNumbers(e.page.index, e.page.count, the_carousel);
874  });
875}
876
877function updateNumbers(index, total, the_carousel) {
878  if (parseInt(total) > 1) {
879    var current = parseInt(index) + 1;
880    the_carousel.find(".carousel-counter").remove();
881    the_carousel.append('<div class="carousel-counter"><strong>' + current + "/</strong>" + total + "</div>");
882  }
883}
884
885function showPreloader() {
886  $("#preloader").show();
887}
888
889function hidePreloader() {
890  $("#preloader").hide();
891}
892
893function showFilterOnMobile() {
894  $("#filter_main").removeClass("hidden-xs");
895  $("#filter_main").removeClass("hidden-sm");
896  $("#filter_show_button").addClass("hidden-xs");
897  $("#filter_show_button").addClass("hidden-sm");
898}
899
900function cartSum(sum, amount) {
901  if (sum > 0) {
902    if ($("#cart_li").hasClass("inactive")) {
903      $("#cart_li").removeClass("inactive");
904    }
905  }
906  if (!isNaN(sum)) {
907    sum = thousandSeparator(sum);
908  }
909  $(".my_cart_sum").html(sum);
910  $(".my_cart_count").html(amount);
911  $(".cart_total_sum").html(sum);
912}
913
914$(".scroll-top").click(function () {
915  $("body,html").animate({ scrollTop: 0 }, 1000);
916});
917
918$(".to-desc").click(function () {
919  var link = $(this).attr("href");
920  var posi = $(link).offset().top;
921  $("body,html").animate({ scrollTop: posi }, 700);
922});
923
924function showMeSomething(id, group) {
925  $.ajax({
926    type: "POST",
927    data: { id: id, action: "preview", group: group, local: "<?=$link_local;?>" },
928    success: function (data) {
929      var obj = jQuery.parseJSON(data);
930      $(".the_preview").html(obj.preview);
931      $.fancybox("#product_preview", { padding: 0 });
932    },
933  });
934}
935
936function askAboutProduct(id, cat) {
937  $("#product_question #question_product").val(id);
938  $("#product_question #question_cat").val(cat);
939
940  setTranslateChildText($("#product_question"));
941}
942
943$('[data-toggle="tooltip"]').tooltip({ container: "body", html: true, trigger: "click" });
944
945$(".popup_image").fancybox({
946  padding: "0",
947});
948
949$(".gal_loader").fancybox({
950  padding: 0,
951  helpers: {
952    title: {
953      type: "outside",
954    },
955    thumbs: {
956      width: 50,
957      height: 50,
958    },
959  },
960});
961
962$(".service_gallery").fancybox();
963
964$(".give-us-your-feedback").click(function () {
965  $(".leave-feedback").slideToggle("slow", function () {
966    // Animation complete.
967  });
968  $(".hide-button").slideToggle("slow", function () {
969    // Animation complete.
970  });
971});
972
973function productComment(id) {
974  setTranslateChildText($("#leave_product_feed"));
975  $("#leave_product_feed").find("#product-id").val(id);
976}
977
978function showDelVariants() {
979  $('input[name="delivery"]').prop("checked", false);
980  $("#togglable_deliveries_table").toggle("3000");
981  $("#togglable_deliveries_button").toggle("3000");
982  $("#delivery_info_block").empty();
983  $("#order_form_to_submit").empty();
984}
985
986function showHiddenFilter(what, show, hide) {
987  $(what).slideToggle("fast", function () {});
988  $(show).show();
989  $(hide).hide();
990}
991function exit() {
992  $.ajax({
993    type: "post",
994    data: { action: "logout" },
995    success: function (data) {
996      location.reload();
997    },
998  });
999}
1000
1001function changeView(type) {
1002  $.ajax({
1003    type: "post",
1004    data: { action: "change_view", view_type: type },
1005    success: function (data) {
1006      if (type == "list") {
1007        $(".product_card").each(function () {
1008          $(this).removeClass("col-md-4");
1009          $(this).removeClass("col-sm-6");
1010          $(this).addClass("col-xs-12");
1011        });
1012        $(".product-col").each(function () {
1013          $(this).addClass("list");
1014          $(this).addClass("clearfix");
1015        });
1016        $("#list_view").addClass("active");
1017        $("#grid_view").removeClass("active");
1018      } else {
1019        $(".product_card").each(function () {
1020          $(this).removeClass("col-xs-12");
1021          $(this).addClass("col-md-4");
1022          $(this).addClass("col-sm-6");
1023        });
1024        $(".product-col").each(function () {
1025          $(this).removeClass("list");
1026          $(this).removeClass("clearfix");
1027        });
1028        $("#grid_view").addClass("active");
1029        $("#list_view").removeClass("active");
1030      }
1031    },
1032  });
1033}
1034
1035$(".del-toggle").click(function () {
1036  $("#del-open").slideToggle("slow", function () {});
1037});
1038
1039$(".pay-toggle").click(function () {
1040  $("#pay-open").slideToggle("slow", function () {});
1041});
1042
1043$(".war-toggle").click(function () {
1044  $("#war-open").slideToggle("slow", function () {});
1045});
1046
1047function product_showcase(obj) {
1048  $("#gallery_main_holder").html(
1049    '<a id="launch_the_show" onclick="timeToView(\'' +
1050      obj +
1051      '\')"><img class="img-responsive" id="full-screen-image" src="' +
1052      obj +
1053      '"></a>'
1054  );
1055  $(".little_image").each(function () {
1056    $(this).attr("class", "image_holder item");
1057  });
1058  document.getElementById(obj).className = "image_holder item activated";
1059}
1060
1061function showAllChars() {
1062  $(".filterable").each(function () {
1063    $(this)
1064      .find(".diff-table")
1065      .each(function (index) {
1066        $(this).show();
1067      });
1068  });
1069  $(".all_chars").hide();
1070  $(".diff_chars").show();
1071}
1072
1073function showDiffChars() {
1074  var chars = [];
1075  var shown = [];
1076  $(".filterable-data").each(function () {
1077    $(this)
1078      .find(".diff-table")
1079      .each(function (index) {
1080        var html = $(this).html();
1081        if (typeof chars[index] !== "undefined") {
1082          if (chars[index] !== html) {
1083            shown.push(index);
1084          }
1085        } else {
1086          chars[index] = html;
1087        }
1088      });
1089  });
1090
1091  $(".filterable").each(function () {
1092    $(this)
1093      .find(".diff-table")
1094      .each(function (index) {
1095        if ($.inArray(index, shown) == -1) {
1096          $(this).hide();
1097        }
1098      });
1099  });
1100
1101  $(".all_chars").show();
1102  $(".diff_chars").hide();
1103}
1104
1105function timeToView(src) {
1106  $("[href^='" + src + "']").click();
1107}
1108
1109function diff_delete(id, group) {
1110  $.ajax({
1111    type: "post",
1112    data: { action: "difference", id: id, group: group },
1113    success: function (data) {
1114      location.reload();
1115    },
1116  });
1117}
1118
1119function diff_delete_all() {
1120  $.ajax({
1121    type: "post",
1122    data: { action: "difference", id: "all" },
1123    success: function (data) {
1124      location.reload();
1125    },
1126  });
1127}
1128
1129function orderproduct(obj, obj2, obj3) {
1130  $("#order_this_product_result").html("");
1131  $("#order-product .form-header").html(obj2);
1132  $("#order_product").val(obj);
1133  $("#order_cat").val(obj3);
1134}
1135
1136function one_click_buy(obj, obj2, obj3) {
1137  $("#one-click-buy_result").html("");
1138  // $('#order-product .form-header').html(obj2);
1139  $("#one_click_product").val(obj);
1140  $("#one_click_cat").val(obj3);
1141}
1142
1143$(".show_filter").click(function () {
1144  if (document.getElementById("filter_main").className == "hidden-xs") {
1145    document.getElementById("filter_main").className = "visible-xs";
1146  } else {
1147    document.getElementById("filter_main").className = "hidden-xs";
1148  }
1149});
1150
1151function desc(obj) {
1152  $(obj).slideToggle("slow", function () {});
1153}
1154
1155function isNumeric(n) {
1156  return !isNaN(parseFloat(n)) && isFinite(n);
1157}
1158
1159function add2cart(obj, obj2, obj3, group) {
1160  if ($("input").is("#add_to_cart_input-" + obj)) {
1161    sum = $("#add_to_cart_input-" + obj).val();
1162    max = $("#add_to_cart_input-" + obj).attr("max");
1163    min = $("#add_to_cart_input-" + obj).attr("min");
1164    if (parseInt(sum) > parseInt(max)) {
1165      sum = max;
1166    }
1167    if (parseInt(sum) < parseInt(min)) {
1168      sum = 1;
1169    }
1170  } else {
1171    sum = 1;
1172  }
1173
1174  if ($(".product_options").length) {
1175    product = $(".product_options").data("id");
1176    if (obj == product) {
1177      options = "";
1178      $(".product_options select").each(function () {
1179        value = $(this).val();
1180        if (!isNaN(parseFloat(value)) && isFinite(value)) {
1181          options = options + $(this).val() + ",";
1182        }
1183      });
1184      options = options.slice(0, -1);
1185    } else {
1186      options = "";
1187    }
1188  } else {
1189    options = "";
1190  }
1191
1192  $.ajax({
1193    type: "post",
1194    data: {
1195      action: "add2cart",
1196      id: obj,
1197      type: obj2,
1198      options: options,
1199      amount: sum,
1200      group: group
1201    },
1202    success: function (data) {
1203      var returned = jQuery.parseJSON(data);
1204
1205      showCartMessage(returned.cart.popcontent);
1206
1207      if (returned.cart.discount > 0) {
1208        cartSum(returned.cart.sum_with_discount, returned.cart.count);
1209      } else {
1210        cartSum(returned.cart.sum, returned.cart.count);
1211      }
1212
1213      $("#cart_button, .informater").fadeTo(100, 0.1).fadeTo(200, 1.0);
1214      quickReadCart();
1215
1216      var ga4Item = {
1217        item_name: String(returned.cart.product.title || ""),
1218        item_id: String(returned.cart.product.art || returned.cart.product.id || ""),
1219        price: Number(returned.cart.product.price || 0),
1220        quantity: Number(sum)
1221      };
1222
1223      if (returned.cart.product.brand && returned.cart.product.brand.title) {
1224        ga4Item.item_brand = String(returned.cart.product.brand.title);
1225      }
1226
1227      if (returned.cart.product.group_title) {
1228        ga4Item.item_category = String(returned.cart.product.group_title);
1229      }
1230
1231      window.dataLayer = window.dataLayer || [];
1232      window.dataLayer.push({ ecommerce: null });
1233      window.dataLayer.push({
1234        event: "add_to_cart",
1235        ecommerce: {
1236          currency: "KZT",
1237          value: Number(returned.cart.product.price || 0) * Number(sum),
1238          items: [ga4Item]
1239        }
1240      });
1241
1242      /*
1243      dataLayer.push({
1244        ecommerce: {
1245          add: {
1246            products: [
1247              {
1248                name: returned.cart.product.title,
1249                id: String(returned.cart.product.id),
1250                price: String(returned.cart.product.price),
1251                brand: returned.cart.product.brand?.title,
1252                category: returned.cart.product.group_title,
1253                quantity: Number(sum)
1254              }
1255            ]
1256          }
1257        }
1258      });
1259      */
1260    }
1261  });
1262}
1263
1264function quickReadCart() {
1265  $.ajax({
1266    type: "post",
1267    data: { action: "quick_cart" },
1268    success: function (data) {
1269
1270      var returned = jQuery.parseJSON(data);
1271
1272      $(".the-short-cart").html(returned.answer.insides);
1273      cartSum(returned.answer.sum, returned.answer.amount);
1274      startTheOwl($(".the-short-cart .owl-carousel"));
1275
1276      var ga4Items = [];
1277
1278      $(".the-short-cart .item").each(function (index) {
1279        var $item = $(this);
1280
1281        var itemName = $.trim($item.find(".caption h4").first().text());
1282        var itemHref = $item.find("a[href]").first().attr("href") || "";
1283        var itemId = "";
1284        var price = 0;
1285        var quantity = 1;
1286
1287        var hrefMatch = itemHref.match(/\/(\d+)(?:\/|$)/);
1288        if (hrefMatch && hrefMatch[1]) {
1289          itemId = hrefMatch[1];
1290        }
1291
1292        var priceText = $.trim($item.find(".price-new").first().text());
1293
1294        var priceMatch = priceText.match(/([\d\s]+)\s*[^\d]*x\s*(\d+)/i);
1295
1296        if (priceMatch) {
1297          price = Number(String(priceMatch[1]).replace(/\s+/g, ""));
1298          quantity = Number(priceMatch[2]);
1299        } else {
1300          var fallbackNumbers = priceText.match(/\d+/g);
1301          if (fallbackNumbers && fallbackNumbers.length) {
1302            price = Number(fallbackNumbers[0]);
1303          }
1304        }
1305
1306        if (itemName) {
1307          ga4Items.push({
1308            item_name: itemName,
1309            item_id: itemId || itemName,
1310            price: price || 0,
1311            quantity: quantity || 1,
1312            index: index + 1
1313          });
1314        }
1315      });
1316
1317
1318      if (ga4Items.length) {
1319        window.dataLayer = window.dataLayer || [];
1320        window.dataLayer.push({ ecommerce: null });
1321        window.dataLayer.push({
1322          event: "view_cart",
1323          ecommerce: {
1324            currency: "KZT",
1325            value: Number(returned.answer.sum || 0),
1326            items: ga4Items
1327          }
1328        });
1329      } else {
1330      }
1331    }
1332  });
1333}
1334
1335function orderinfo(obj) {
1336  $.ajax({
1337    type: "post",
1338    data: { action: "order-ajax", order: obj, local: "<?=$link_local;?>" },
1339    success: function (responce) {
1340      document.getElementById("order-" + obj).innerHTML = responce;
1341    },
1342  });
1343}
1344
1345function selectOption(btn, value_id) {
1346  var value_id = value_id;
1347  $("#filter_" + value_id).prop("checked", true);
1348  if ($(btn).hasClass("imagecheck-holder")) {
1349    $(btn).closest(".option-variants").find(".imagecheck-holder").removeClass("active_one");
1350    $(btn).addClass("active_one");
1351  }
1352
1353  if ($(btn).data("url") && typeof $(btn).data("url") != "undefined") {
1354    history.pushState({}, null, $(btn).data("url"));
1355  }
1356
1357  var chosen_products = $(btn).data("products");
1358  var products_array = [];
1359  var values_array = [];
1360  var options_block = $(".product-options");
1361  options_block.find(".option-variants").each(function () {
1362    var products = $(this).find("input:checked").data("products");
1363    var value = $(this).find("input:checked").val();
1364    products_array.push(products);
1365    values_array.push(value);
1366  });
1367
1368  $.ajax({
1369    type: "POST",
1370    data: {
1371      action: "reload-options",
1372      products: products_array,
1373      values: values_array,
1374      chosen: value_id,
1375      chosen_products: chosen_products,
1376    },
1377    success: function (data) {
1378      var obj = jQuery.parseJSON(data);
1379      if (obj.result == 1) {
1380        $("#product-inner-data").html(obj.content);
1381        dynamicFunctions();
1382        ksWidgetInitializer.reinit();
1383      }
1384    },
1385  });
1386}
1387
1388function imageCheck(check) {
1389  if (
1390    !$("#imagecheck-" + check)
1391      .closest(".imagecheck-holder")
1392      .hasClass("active_one")
1393  ) {
1394    $("#imagecheck-" + check)
1395      .closest(".imagecheck-holder")
1396      .addClass("active_one");
1397    $("#check-" + check).prop("checked", true);
1398  } else {
1399    $("#imagecheck-" + check)
1400      .closest(".imagecheck-holder")
1401      .removeClass("active_one");
1402    $("#check-" + check).prop("checked", false);
1403  }
1404}
1405
1406$(".range_slider").each(function (index) {
1407  var minimum = $(this).attr("minimum");
1408  var maximum = $(this).attr("maximum");
1409  var from_start = $(this).attr("from_start");
1410  var to_end = $(this).attr("to_end");
1411  var special = $(this).attr("special");
1412  var postfixing = $(this).attr("postfixing");
1413  var naming = $(this).attr("name");
1414  var id = $(this).attr("title_id");
1415  var input_holder = $(this).closest(".filter-group").find(".slider-inputs");
1416  $(this).ionRangeSlider({
1417    min: minimum,
1418    max: maximum,
1419    from: from_start,
1420    to: to_end,
1421    type: "double",
1422    onStart: function (data) {
1423      input_holder.find(".slider-start").val(data.from);
1424      input_holder.find(".slider-end").val(data.to);
1425    },
1426    onChange: function (data) {
1427      if (special == "price_slider") {
1428        $("#min-price-filter").val(data.from);
1429        $("#max-price-filter").val(data.to);
1430        input_holder.find(".slider-start").val(data.from);
1431        input_holder.find(".slider-end").val(data.to);
1432      } else {
1433        min = minimum;
1434        max = maximum;
1435        property = naming;
1436        min_value = data.from;
1437        max_value = data.to;
1438        if (min_value == min && max_value == max) {
1439          $("#check-" + naming).prop("checked", false);
1440        } else {
1441          $("#check-" + naming).prop("checked", true);
1442        }
1443        $.ajax({
1444          type: "POST",
1445          data: { action: "number_filter", property: naming, min: min_value, max: max_value },
1446          success: function (data) {
1447            var obj = jQuery.parseJSON(data);
1448            $("#check-" + naming).attr("name", obj.result);
1449          },
1450        });
1451        input_holder.find(".slider-start").val(data.from);
1452        input_holder.find(".slider-end").val(data.to);
1453      }
1454    },
1455    onUpdate: function (data) {
1456      if (special == "price_slider") {
1457        $("#min-price-filter").val(data.from);
1458        $("#max-price-filter").val(data.to);
1459        input_holder.find(".slider-start").val(data.from);
1460        input_holder.find(".slider-end").val(data.to);
1461      } else {
1462        min = minimum;
1463        max = maximum;
1464        property = naming;
1465        min_value = data.from;
1466        max_value = data.to;
1467        if (min_value == min && max_value == max) {
1468          $("#check-" + naming).prop("checked", false);
1469        } else {
1470          $("#check-" + naming).prop("checked", true);
1471        }
1472        $.ajax({
1473          type: "POST",
1474          data: { action: "number_filter", property: naming, min: min_value, max: max_value },
1475          success: function (data) {
1476            var obj = jQuery.parseJSON(data);
1477            $("#check-" + naming).attr("name", obj.result);
1478          },
1479        });
1480        input_holder.find(".slider-start").val(data.from);
1481        input_holder.find(".slider-end").val(data.to);
1482      }
1483      prequeryFilter(id);
1484    },
1485    onFinish: function (data) {
1486      if (special == "price_slider") {
1487        prequeryFilter(id);
1488      } else {
1489        min = minimum;
1490        max = maximum;
1491        property = naming;
1492        min_value = data.from;
1493        max_value = data.to;
1494        $.ajax({
1495          type: "POST",
1496          data: { action: "number_filter", property: naming, min: min_value, max: max_value },
1497          success: function (data) {
1498            var obj = jQuery.parseJSON(data);
1499            $("#check-" + naming).attr("name", obj.result);
1500            prequeryFilter(id);
1501          },
1502        });
1503      }
1504    },
1505  });
1506
1507  var range = $(this).data("ionRangeSlider");
1508  input_holder.find(".slider-start").on("change", function () {
1509    var value = $(this).val();
1510    if (parseInt(value) >= parseInt(minimum)) {
1511      range.update({
1512        from: value,
1513      });
1514      if (parseInt(range.result.to) < parseInt(value)) {
1515        range.update({
1516          to: value,
1517        });
1518      }
1519    } else {
1520      input_holder.find(".slider-end").val(minimum);
1521    }
1522  });
1523
1524  input_holder.find(".slider-end").on("change", function () {
1525    var value = $(this).val();
1526    if (parseInt(value) <= parseInt(maximum)) {
1527      range.update({
1528        to: value,
1529      });
1530      if (parseInt(range.result.from) < parseInt(value)) {
1531        range.update({
1532          from: value,
1533        });
1534      }
1535    } else {
1536      input_holder.find(".slider-end").val(maximum);
1537    }
1538  });
1539});
1540
1541function product_option_query(id) {
1542  image = $("#" + id)
1543    .find(":selected")
1544    .attr("data-id");
1545  if (image !== "-") {
1546    image = parseInt(image) - 1;
1547    $("#product_showcase").owlCarousel("to", image);
1548    $(".owl-thumb-item").eq(image).click();
1549  }
1550  options = "";
1551  $(".product_options select").each(function () {
1552    value = $(this).val();
1553    if (!isNaN(parseFloat(value)) && isFinite(value)) {
1554      options = options + $(this).val() + ",";
1555    }
1556  });
1557  options = options.slice(0, -1);
1558  $.ajax({
1559    type: "POST",
1560    data: { action: "options-ajax", options: options },
1561    success: function (data) {
1562      var obj = jQuery.parseJSON(data);
1563      if (obj.result == 1) {
1564        if (parseInt(obj.price) > 0) {
1565          $("#this_product_price").html(obj.price);
1566          if ($("#your_price_in_int").length != 0) {
1567            $("#your_price_in_int").html(obj.your_price);
1568          }
1569        }
1570      }
1571    },
1572  });
1573}
1574
1575function thousandSeparator(str) {
1576  var parts = (str + "").split("."),
1577    main = parts[0],
1578    len = main.length,
1579    output = "",
1580    i = len - 1;
1581
1582  while (i >= 0) {
1583    output = main.charAt(i) + output;
1584    if ((len - i) % 3 === 0 && i > 0) {
1585      output = " " + output;
1586    }
1587    --i;
1588  }
1589
1590  if (parts.length > 1) {
1591    output += "." + parts[1];
1592  }
1593  return output;
1594}
1595
1596function load_more(start, page) {
1597  var $next = $(".pagination-block .active").closest("li").next("li").find("a");
1598
1599  if ("undefined" == typeof $next) {
1600    return false;
1601  }
1602
1603  $.get($next.attr("href"), function (response) {
1604    var $response = $(response);
1605
1606    $(".div_to_load_products").append($response.find(".div_to_load_products").html());
1607
1608    $(".refresh_pagination").html($response.find(".refresh_pagination").html());
1609
1610    $(".refresh_load_more").html($response.find(".refresh_load_more").html());
1611
1612    lazy();
1613  });
1614
1615  /*$.ajax({
1616     type: "POST",
1617     cache:true,
1618     data: {action:'load_more',start:start, p:page},
1619     success:function (data) {           
1620        var obj = jQuery.parseJSON(data);
1621
1622        $('.div_to_load_products').append(obj.inside);
1623
1624        $('.refresh_pagination').html(obj.pagination);
1625        $('.refresh_load_more').html(obj.load_more);
1626        
1627        lazy();
1628        
1629
1630     }
1631   });*/
1632}
1633
1634function changeUrl(key, value) {
1635  url = getGet();
1636  clean_url = url["clean"];
1637  delete url["clean"];
1638  url["p"] = key + "=" + value;
1639  gets = implode(url);
1640  href = clean_url + "?" + gets;
1641  window.history.pushState(null, null, href);
1642}
1643
1644function difference(id, group) {
1645  $.ajax({
1646    type: "post",
1647    data: { action: "difference", id: id, group: group },
1648    success: function (data) {
1649      var obj = jQuery.parseJSON(data);
1650      if (obj.result == 1) {
1651        $("[data-diff=" + id + "]").each(function () {
1652          if ($(this).closest("a").hasClass("active")) {
1653            $(this).closest("a").removeClass("active");
1654            alert("Товар удален из списка сравнения");
1655          } else {
1656            $(this).closest("a").addClass("active");
1657            alert("Товар добавлен в список сравнения");
1658          }
1659        });
1660        if ($("#difference_li").hasClass("inactive")) {
1661          $("#difference_li").removeClass("inactive");
1662          alert("Товар удален из списка сравнения");
1663        } else {
1664          if (obj.count == 0) {
1665            $("#difference_li").addClass("inactive");
1666            alert("Товар добавлен в список сравнения");
1667          }
1668        }
1669
1670        $(".compare-amount").html(obj.count);
1671      }
1672    },
1673  });
1674}
1675
1676function fav_delete(id, group) {
1677  fav(id, group);
1678  location.reload();
1679}
1680
1681// карты
1682// maps();
1683
1684// var maps = [];
1685
1686// function updateMap(id, position, marker) {
1687//   ymaps.ready(init);
1688
1689//   function init() {
1690//     // Создание карты.
1691//     if (typeof maps[id] == "undefined") {
1692//       maps[id] = new ymaps.Map(id, {
1693//         center: position,
1694//         zoom: 15,
1695//       });
1696//     } else {
1697//       maps[id].setCenter(position, 15);
1698//     }
1699
1700//     if (typeof marker != "undefined") {
1701//       placemark = new ymaps.Placemark(marker.latLng, {
1702//         //balloonContent: marker.label,
1703//         hintContent: marker.label,
1704//       });
1705
1706//       maps[id].geoObjects.add(placemark);
1707//     }
1708//   }
1709
1710//   /*DG.then(function () {
1711//         if (typeof maps[id] == 'undefined') {
1712//             maps[id] = DG.map(id, {
1713//                 center: position,
1714//                 zoom: 16
1715//             });
1716//         } else {
1717//             maps[id].setView(position, 16);
1718//         }
1719
1720//         if (typeof marker != 'undefined') {
1721//             DG.marker(marker.latLng, marker).addTo(maps[id]);
1722//         }            
1723//     });  */
1724// }
1725
1726// function setMaps($maps) {
1727//   $maps.each(function () {
1728//     var $this = $(this);
1729//     var id = $this.attr("id");
1730//     var position = [$this.data("lat"), $this.data("lng")];
1731
1732//     updateMap(id, position, {
1733//       latLng: position,
1734//       label: $this.data("title"),
1735//     });
1736//   });
1737// }
1738
1739// function maps() {
1740//   var $body = $("body");
1741
1742//   setMaps($(".the_map:visible"));
1743
1744//   $body.on("shown.bs.collapse", "#collapse-city_1", function () {
1745//     setMaps($(".the_map:visible"));
1746//   });
1747
1748//   $body.on("shown.bs.collapse", "#collapse-subs", function () {
1749//     var $this = $(".location_picker.active");
1750//     var id = "subs_map";
1751//     var position = [$this.data("lat"), $this.data("lng")];
1752
1753//     updateMap(id, position, {
1754//       latLng: position,
1755//       label: $this.data("title"),
1756//     });
1757
1758//     $(".location_picker.active").trigger("click");
1759//   });
1760
1761//   $(".location_picker").on("click", function () {
1762//     var $this = $(this);
1763//     $(".location_picker").removeClass("active");
1764
1765//     var adress = $this.data("adress");
1766//     $("#sub_adress").html(adress);
1767
1768//     var worktime = $this.data("worktime");
1769//     $("#sub_worktime").html(worktime);
1770
1771//     var position = [$this.data("lat"), $this.data("lng")];
1772
1773//     updateMap("subs_map", position, {
1774//       latLng: position,
1775//       label: $this.data("adress"),
1776//     });
1777
1778//     $this.addClass("active");
1779//   });
1780// }
1781// конец карт
1782
1783function fav_delete_all() {
1784  $.ajax({
1785    type: "post",
1786    data: { action: "favourite", id: "all" },
1787    success: function (data) {
1788      location.reload();
1789    },
1790  });
1791}
1792
1793function fav(id, group) {
1794  $.ajax({
1795    type: "post",
1796    data: { action: "favourite", id: id, group: group },
1797    success: function (data) {
1798      var obj = jQuery.parseJSON(data);
1799
1800      $(".favourity-block .informater-value").text(obj.count);
1801
1802      if (obj.result == 1) {
1803        $("[data-fav=" + id + "]").each(function () {
1804          if ($(this).closest("a").hasClass("active")) {
1805            $(this).closest("a").removeClass("active");
1806            $("#mobile_nav .fav-block").removeClass("active");
1807          } else {
1808            $(this).closest("a").addClass("active");
1809            $("#mobile_nav .fav-block").addClass("active");
1810
1811            alert("Товар добавлен в избранное");
1812          }
1813        });
1814      }
1815    },
1816  });
1817}
1818
1819function getGet(all_vars = 0) {
1820  var $_GET = {};
1821  var url = {};
1822  document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
1823    function decode(s) {
1824      return decodeURIComponent(s.split("+").join(" "));
1825    }
1826
1827    $_GET[decode(arguments[1])] = decode(arguments[2]);
1828  });
1829
1830  $.each($_GET, function (key, value) {
1831    if (typeof value !== "undefined" && value != "") {
1832      if (all_vars == 1) {
1833        url[key] = key + "=" + value;
1834      } else {
1835        if (key !== "p") {
1836          url[key] = key + "=" + value;
1837        }
1838      }
1839    }
1840  });
1841
1842  urling = window.location.href.split("?");
1843
1844  url["clean"] = urling[0];
1845
1846  return url;
1847}
1848
1849function implode(array) {
1850  var gets = "";
1851  $.each(array, function (index, value) {
1852    gets = gets + array[index] + "&";
1853  });
1854  gets = gets.substring(0, gets.length - 1);
1855  return gets;
1856}
1857function sortCat(sort) {
1858  url = getGet(1);
1859  clean_url = url["clean"];
1860  delete url["clean"];
1861  url["sort"] = "sort=" + sort;
1862
1863  var gets = implode(url);
1864
1865  document.location.href = clean_url + "?" + gets;
1866}
1867
1868function queryFilter() {
1869  url = getGet();
1870
1871  clean_url = url["clean"];
1872  delete url["clean"];
1873
1874  var brands = "";
1875  $("#brandsquery input:checkbox:checked").each(function () {
1876    brands = brands + $(this).attr("name") + ",";
1877  });
1878  brands = brands.slice(0, -1);
1879  if (typeof brands !== "undefined" && brands != "") {
1880    url["brands-filter"] = "brands-filter=" + brands;
1881  } else {
1882    delete url["brands-filter"];
1883  }
1884
1885  var filter = "";
1886  var holder = "";
1887  if ($(window).width() > 1199) {
1888    holder = $(".filter_main:not(.filter_mobile)");
1889  } else {
1890    holder = $(".filter_main.filter_mobile");
1891  }
1892
1893  holder.find(".filtersquery").each(function () {
1894    $(this)
1895      .find("input:checkbox:checked")
1896      .each(function () {
1897        filter = filter + $(this).attr("name") + ",";
1898      });
1899  });
1900  filter = filter.slice(0, -1);
1901
1902  if (typeof filter !== "undefined" && filter != "") {
1903    url["filter"] = "filter=" + filter;
1904  } else {
1905    delete url["filter"];
1906  }
1907
1908  url["min-price"] = "min-price=" + $("#min-price-filter").val();
1909  url["max-price"] = "max-price=" + $("#max-price-filter").val();
1910  url["start-price"] = "start-price=" + $("#price-filter").attr("minimum");
1911  url["finish-price"] = "finish-price=" + $("#price-filter").attr("maximum");
1912
1913  var gets = implode(url);
1914
1915  document.location.href = clean_url + "?" + gets;
1916}
1917
1918function prequeryFilter(selected_filter) {
1919  url = getGet();
1920
1921  clean_url = url["clean"];
1922  delete url["clean"];
1923
1924  var brands = "";
1925  $("#brandsquery input:checkbox:checked").each(function () {
1926    brands = brands + $(this).attr("name") + ",";
1927  });
1928  brands = brands.slice(0, -1);
1929  if (typeof brands !== "undefined" && brands != "") {
1930    url["brands-filter"] = "brands-filter=" + brands;
1931  } else {
1932    delete url["brands-filter"];
1933  }
1934
1935  var filter = "";
1936  $(".filtersquery input:checkbox:checked").each(function () {
1937    filter = filter + $(this).attr("name") + ",";
1938  });
1939  filter = filter.slice(0, -1);
1940  if (typeof filter !== "undefined" && filter != "") {
1941    url["filter"] = "filter=" + filter;
1942  } else {
1943    delete url["filter"];
1944  }
1945
1946  url["min-price"] = "min-price=" + $("#min-price-filter").val();
1947  url["max-price"] = "max-price=" + $("#max-price-filter").val();
1948  url["start-price"] = "start-price=" + $("#price-filter").attr("minimum");
1949  url["finish-price"] = "finish-price=" + $("#price-filter").attr("maximum");
1950  url["pre_filter"] = "pre_filter=execute";
1951
1952  var gets = implode(url);
1953
1954  $(".filter_main").addClass("active");
1955
1956  $.get(clean_url + "?" + gets, function (data) {
1957    $("#pre_amount").html('<img src="/template/js/fancybox/fancybox_loading.gif"/>');
1958    $(".result").html(data);
1959    var obj = jQuery.parseJSON(data);
1960    $(".pre_button").remove();
1961    $("#products2see").html(" (" + obj.products + ")");
1962
1963    if ($("#" + selected_filter).length) {
1964      $("#" + selected_filter).append(obj.rendered);
1965    } else if ($("#filter_" + selected_filter).length) {
1966      $("#filter_" + selected_filter)
1967        .closest(".list-group")
1968        .find(".filter_header")
1969        .append(obj.rendered);
1970    }
1971  });
1972}
1973
1974function resetFilter() {
1975  url = getGet();
1976  link = url["clean"] + "?";
1977  if (typeof url["search"] !== "undefined" && url["search"] != "") {
1978    link = link + url["search"];
1979  }
1980  if (typeof url["search_cats"] !== "undefined" && url["search_cats"] != "") {
1981    link = link + url["search_cats"];
1982  }
1983  if (typeof url["sort"] !== "undefined" && url["sort"] != "") {
1984    link = link + url["sort"];
1985  }
1986  if (link.substr(link.length - 1) == "?") {
1987    link = link.slice(0, -1);
1988  }
1989  document.location.href = link;
1990}
1991
1992function searchIt(id) {
1993  cat = "";
1994  $("#" + id + " input:checkbox:checked").each(function () {
1995    cat = cat + $(this).attr("value") + ",";
1996  });
1997  cat = cat.slice(0, -1);
1998
1999  if (cat.length > 0) {
2000    $("#" + id + " .search_cats").val(cat);
2001  } else {
2002    $("#" + id + " .search_cats").remove();
2003  }
2004
2005  $("#" + id + " .search_cat_id").each(function () {
2006    $(this).remove();
2007  });
2008
2009  $("#" + id).submit();
2010}
2011
2012$(".main-toggler").hover(
2013  function () {
2014    $("#unfocused").stop(true, true).fadeIn(1000);
2015  },
2016  function () {
2017    $("#unfocused").stop(true, true).fadeOut(200);
2018  }
2019);
2020
2021function quickFromCart(id) {
2022  $.ajax({
2023    type: "post",
2024    data: { action: "update_cart", action_type: "quick_remove", id: id },
2025    success: function (data) {
2026      quickReadCart();
2027      if ($("#the_list_of_products_in_cart").length > 0) {
2028        readCart();
2029      }
2030    },
2031  });
2032}
2033
2034function openCart() {
2035  if ($("#top-cart").hasClass("opened")) {
2036    $("#top-cart").removeClass("opened");
2037    $("#mobile-cart-button-open").removeClass("hide-it");
2038    $("#mobile-cart-button-close").addClass("hide-it");
2039  } else {
2040    if ($("#slide_menu").hasClass("showNav")) {
2041      $(".btn-nav").click();
2042    }
2043    $("#mobile-cart-button-open").addClass("hide-it");
2044    $("#mobile-cart-button-close").removeClass("hide-it");
2045    $("#top-cart").addClass("opened");
2046  }
2047}
2048$(document).mouseup(function (e) {
2049  if ($("#top-cart").hasClass("opened")) {
2050    var container = $("#top-cart");
2051
2052    if (
2053      !container.is(e.target) && // if the target of the click isn't the container...
2054      container.has(e.target).length === 0
2055    ) {
2056      // ... nor a descendant of the container
2057      openCart();
2058    }
2059  }
2060});
2061
2062$(".search_form").submit(function () {
2063  $input = $(".search_input", $(this));
2064
2065  if ("" == $input.val()) {
2066    $input.focus();
2067    return false;
2068  }
2069});
2070
2071$(document).on("click", ".search_form .dropdown-menu", function (e) {
2072  e.stopPropagation();
2073});
2074
2075function readCart() {
2076  showPreloader();
2077  $.ajax({
2078    type: "post",
2079    data: { action: "update_cart", action_type: "read_cart" },
2080    success: function (data) {
2081      if ($('input[name="delivery"]').is(":checked")) {
2082        showDelVariants();
2083      }
2084
2085      var returned = jQuery.parseJSON(data);
2086      if (returned.cart.sum == 0) {
2087        location.reload();
2088      }
2089
2090      $("#the_list_of_products_in_cart").empty();
2091      $("#the_list_of_products_in_cart").append(returned.cart.products);
2092      startTheOwl($("#the_list_of_products_in_cart .owl-carousel"));
2093      $("#the_cart_totals").html(returned.cart.totals);
2094      $("#pay_block").html(returned.cart.pay_block);
2095      $("#del_block").html(returned.cart.del_block);
2096
2097      quickReadCart();
2098      ui_inputs();
2099    },
2100  });
2101  hidePreloader();
2102}
2103
2104function finalWithDelivery(price) {
2105  showPreloader();
2106  $.ajax({
2107    type: "post",
2108    data: { update_cart: "1", final_cart: "1", price: price },
2109    success: function (data) {
2110      var returned = jQuery.parseJSON(data);
2111      $(".cart_counts").html(returned.finals);
2112      ui_inputs();
2113    },
2114  });
2115  hidePreloader();
2116}
2117
2118function plus_product(id) {
2119  $.ajax({
2120    type: "post",
2121    data: { action: "update_cart", action_type: "add_one_to_cart", id: id },
2122    success: function (data) {
2123      readCart();
2124    },
2125  });
2126}
2127
2128function minus_product(id) {
2129  $.ajax({
2130    type: "post",
2131    data: { action: "update_cart", action_type: "minus_one_to_cart", id: id },
2132    success: function (data) {
2133      readCart();
2134    },
2135  });
2136}
2137
2138function removeFromCart(id) {
2139  $.ajax({
2140    type: "POST",
2141    data: { action: "update_cart", action_type: "remove_from_cart", id: id },
2142    success: function (data) {
2143      readCart();
2144    },
2145  });
2146}
2147
2148function updateAmount(id) {
2149  amount = $("#" + id + "-amount").val();
2150  $.ajax({
2151    type: "post",
2152    data: { action: "update_cart", action_type: "change_amount", id: id, amount: amount },
2153    success: function (data) {
2154      readCart();
2155    },
2156  });
2157}
2158
2159function loadDelivery(id) {
2160  if (id == 6) {
2161    $("#pay-1").closest(".owl-item").hide();
2162  } else {
2163    $("#pay-1").closest(".owl-item").show();
2164  }
2165  $.ajax({
2166    type: "post",
2167    data: { action: "update_cart", action_type: "delivery", delivery: id },
2168    success: function (data) {
2169      var returned = jQuery.parseJSON(data);
2170      $("#the_cart_totals").html(returned.cart.totals);
2171      $("#togglable_deliveries_table").toggle("3000");
2172      $("#togglable_deliveries_button").toggle("3000");
2173      $("#delivery_info_block").html(returned.cart.info);
2174      $("#order_form_to_submit").html(returned.cart.form);
2175      ui_inputs();
2176    },
2177  });
2178}
2179
2180$("body").on("keyup keydown change", ".ui_input", function () {
2181  val = $(this).val();
2182  val = val.replace(/./g, "*");
2183  val = $.trim(val);
2184  if (val.length > 0) {
2185    if (!$(this).closest(".ui_label_group").hasClass("ui_has_value")) {
2186      $(this).closest(".ui_label_group").addClass("ui_has_value");
2187    }
2188  } else {
2189    if ($(this).closest(".ui_label_group").hasClass("ui_has_value")) {
2190      $(this).closest(".ui_label_group").removeClass("ui_has_value");
2191    }
2192  }
2193});
2194
2195function ui_inputs() {
2196  $(".ui_input").each(function () {
2197    val = $(this).val();
2198    val = val.replace(/./g, "*");
2199    val = $.trim(val);
2200    if (val.length > 0) {
2201      if (!$(this).closest(".ui_label_group").hasClass("ui_has_value")) {
2202        $(this).closest(".ui_label_group").addClass("ui_has_value");
2203      }
2204    } else {
2205      if ($(this).closest(".ui_label_group").hasClass("ui_has_value")) {
2206        $(this).closest(".ui_label_group").removeClass("ui_has_value");
2207      }
2208    }
2209  });
2210}
2211
2212function cityInput() {
2213  var MIN_LENGTH = 3;
2214  var city = $("#city_choose").val();
2215  if (city.length >= MIN_LENGTH) {
2216    var delivery = $("#city_choose_delivery").val();
2217    $.ajax({
2218      type: "post",
2219      data: { action: "update_cart", action_type: "get_city", delivery: delivery, city: city },
2220      success: function (data) {
2221        var obj = jQuery.parseJSON(data);
2222        $("#city_list").html(obj.cities);
2223      },
2224    });
2225  }
2226}
2227
2228function calculateDelivery(id, title = "") {
2229  $("#calc_results").empty();
2230  var delivery = $("#city_choose_delivery").val();
2231  if ($("#delivery_type").length > 0) {
2232    var type = $("#delivery_type").val();
2233  } else {
2234    var type = "";
2235  }
2236  $.ajax({
2237    type: "post",
2238    data: {
2239      action: "update_cart",
2240      action_type: "calculate_delivery",
2241      delivery: delivery,
2242      city: id,
2243      title: title,
2244      type: type,
2245    },
2246    success: function (data) {
2247      var obj = jQuery.parseJSON(data);
2248      if (obj.answer.length > 0) {
2249        $("#calc_results").html('<div class="answer-the-form success filled">' + obj.answer + "</div>");
2250      }
2251      $("#the_cart_totals").html(obj.totals);
2252    },
2253  });
2254}
2255
2256function getThePrice(id) {
2257  amount = parseInt($("#" + id).val());
2258  $.ajax({
2259    type: "post",
2260    data: { action: "get_the_price", id: id, amount: amount },
2261    success: function (data) {
2262      var obj = jQuery.parseJSON(data);
2263      $("#the_price-" + obj.id).html(obj.price);
2264      var sum = thousandSeparator(parseInt(amount) * parseFloat(obj.price));
2265      $('.the_price_d[data-product="' + obj.id + '"]').html(sum);
2266    },
2267  });
2268}
2269
2270function changeThisPrice(id) {
2271  getThePrice(id);
2272}
2273
2274function plusAmount(id) {
2275  amount = parseInt($("." + id).val());
2276  new_amount = amount + 1;
2277  $("." + id).val(new_amount);
2278  getThePrice(id);
2279}
2280
2281function minusAmount(id) {
2282  amount = parseInt($("." + id).val());
2283  if (amount > 1) {
2284    new_amount = amount - 1;
2285    $("." + id).val(new_amount);
2286    getThePrice(id);
2287  }
2288}
2289
2290function russianPost() {
2291  $("#calc_results").empty();
2292  var delivery = $("#city_choose_delivery").val();
2293  var zip = $("#rp_zip").val();
2294  $.ajax({
2295    type: "post",
2296    data: { action: "update_cart", action_type: "calculate_delivery", delivery: delivery, zip: zip },
2297    success: function (data) {
2298      var obj = jQuery.parseJSON(data);
2299      if (obj.answer.length > 0) {
2300        $("#calc_results").html('<div class="answer-the-form success filled">' + obj.answer + "</div>");
2301      }
2302      $("#the_cart_totals").html(obj.totals);
2303    },
2304  });
2305}
2306
2307function crediter() {
2308  $(".period-variant").on("click", function () {
2309    var parent = $(this).closest(".credit-row");
2310    $(".period-variant").removeClass("selected");
2311
2312    var monthly = $(this).data("monthly");
2313    var period = $(this).data("period");
2314    var title = $(this).data("title");
2315
2316    parent.find("#variant_holder").html(period);
2317    parent.find("#credit_sum").html(monthly);
2318    parent.find("#credit_title").html(title);
2319
2320    parent.find(".credit_btn_apply").attr("data-period", period);
2321
2322    parent.find(this).addClass("selected");
2323  });
2324}
2325
2326function hackyHref() {
2327  $(".hacky_href").on("click", function (e) {
2328    e.preventDefault();
2329    var href = $(this).data("href");
2330    window.location.href = href;
2331  });
2332}
2333
2334function dynamicFunctions() {
2335  hackyHref();
2336
2337  crediter();
2338  $(".forms_in").fancybox({
2339    helpers: {
2340      overlay: {
2341        locked: false,
2342      },
2343    },
2344    autoSize: false,
2345    padding: 0,
2346  });
2347
2348  fakewaffle.responsiveTabs(["xs", "sm"]);
2349
2350  $(".owl-carousel").each(function (index) {
2351    startTheOwl($(this));
2352  });
2353
2354  var $sync1 = $("#sync1"),
2355    $sync2 = $("#sync2"),
2356    flag = false,
2357    duration = 300;
2358
2359  $sync1
2360    .owlCarousel({
2361      items: 1,
2362      margin: 10,
2363      nav: false,
2364      dots: false,
2365      animateOut: "fadeOut",
2366    })
2367    .on("changed.owl.carousel", function (e) {
2368      if (!flag) {
2369        flag = true;
2370        $sync2.trigger("to.owl.carousel", [e.item.index, duration, true]);
2371        $(".owl-thumbs .item").removeClass("activated");
2372        $(".owl-thumbs .item").eq(e.item.index).addClass("activated");
2373        flag = false;
2374      }
2375    });
2376
2377  $sync2
2378    .owlCarousel({
2379      items: 3,
2380      nav: true,
2381      margin: 10,
2382      center: false,
2383      dots: false,
2384      navRewind: false,
2385      navText: ['<i class="fa fa-angle-left"></i>', '<i class="fa fa-angle-right"></i>'],
2386      animateOut: "slideOutUp",
2387      animateIn: "slideInUp",
2388    })
2389    .on("click", ".owl-item", function () {
2390      $(".owl-thumbs .item").removeClass("activated");
2391      $(this).find(".item").addClass("activated");
2392      $sync1.trigger("to.owl.carousel", [$(this).index(), duration, true]);
2393    })
2394    .on("changed.owl.carousel", function (e) {});
2395
2396  // lightGallery is now loaded on demand (see scripts.tpl); guard against it
2397  // not being present yet - the on-demand loader performs the real init.
2398  if ($.fn.lightGallery) {
2399    $(".product-gallery").lightGallery({ selector: ".gallery_link", thumbnail: false, hash: false });
2400  }
2401
2402  lazy();
2403}
2404
2405function finalize() {
2406  var form = $("#order_form");
2407  var data = form.serialize();
2408  var payment = $("input[name=payment]:checked").val();
2409  var delivery = $("input[name=delivery]:checked").val();
2410
2411  if ($("#bonuses").length > 0) {
2412    var bonuses = $("#bonuses").val();
2413  } else {
2414    var bonuses = "";
2415  }
2416
2417  if ($("#coupon").length > 0) {
2418    var coupon = $("#coupon").val();
2419  } else {
2420    var coupon = "";
2421  }
2422
2423  var ok = 1;
2424  $("#order_form input, #order_form textarea").each(function () {
2425    if ($(this).prop("required")) {
2426      var value = $(this).val();
2427      if (value == "") {
2428        $(this).addClass("err");
2429        ok = 0;
2430      } else if (typeof value == "undefined") {
2431        $(this).addClass("err");
2432        ok = 0;
2433      } else {
2434        $(this).removeClass("err");
2435      }
2436    }
2437  });
2438
2439  var gift = 0;
2440  if ($(".gifts-block").length > 0) {
2441    gift = $("input[name=free-gift]:checked").val();
2442  }
2443
2444  if (typeof gift == "undefined") {
2445    gift = 0;
2446  }
2447  if (gift == "undefined") {
2448    gift = 0;
2449  }
2450
2451  if (ok == 1) {
2452    showPreloader();
2453
2454    $.ajax({
2455      type: "post",
2456      data: {
2457        action: "update_cart",
2458        action_type: "finalize",
2459        inputs: data,
2460        payment: payment,
2461        delivery: delivery,
2462        bonuses: bonuses,
2463        coupon: coupon,
2464        gift: gift,
2465      },
2466      success: function (data) {
2467        var obj = jQuery.parseJSON(data);
2468        if (obj.result == 1) {
2469          window.location.href = obj.link;
2470        } else {
2471              var id = $("#form_" + obj.object)
2472            .closest(".step_point")
2473            .attr("id");
2474          cartStep(id);
2475          $("#form_" + obj.object).focus();
2476        }
2477        hidePreloader();
2478      },
2479    });
2480  } else {
2481    $("#order_form input").focus();
2482  }
2483}
2484
2485// яндекс.цели при нажатии
2486/*$body.on('click', '[class*="ym_goal_"]', function () {
2487    if ('function' == typeof ym) {
2488        var $this = $(this);
2489
2490        for (var goal in ymGoals) {
2491            if ($this.hasClass(goal)) {
2492                reachGoal(goal);
2493            }
2494        }
2495    }
2496})
2497*/
2498
2499// яндекс.цель
2500function reachGoal(goal) {
2501  var ymGoals = {
2502    ym_goal_rassrochka_form: "rassrochka_form", // Кнопка “В рассрочку”
2503    ym_goal_rassrochka_sent: "rassrochka_sent", // Отправить данные
2504    ym_goal_open_kupit_v_1_klik: "open_kupit_v_1_klik", // Кнопка "Купить в 1 клик"
2505    ym_goal_send_kupit_v_1_klik: "send_kupit_v_1_klik", // Отправка данных
2506    ym_goal_call: "call", // Кнопка заказать звонок
2507    ym_goal_confirm_call: "confirm_call", // Отправка заявки
2508  };
2509
2510  if (goal in ymGoals) {
2511    ym(52143727, "reachGoal", ymGoals[goal]);
2512  }
2513
2514  reachGoalGoogle(goal);
2515}
2516
2517// google.аналитик
2518function reachGoalGoogle(goal) {
2519  var ymGoals = {
2520    ym_goal_rassrochka_form: "/virtual/rassrochka_form", // Кнопка “В рассрочку”
2521    ym_goal_rassrochka_sent: "/virtual/rassrochka_sent", // Отправить данные
2522    ym_goal_open_kupit_v_1_klik: "/virtual/open_kupit_v_1_klik", // Кнопка "Купить в 1 клик"
2523    ym_goal_send_kupit_v_1_klik: "/virtual/send_kupit_v_1_klik", // Отправка данных
2524    ym_goal_call: "/virtual/call", // Кнопка заказать звонок
2525    ym_goal_confirm_call: "/virtual/confirm_call", // Отправка заявки
2526  };
2527
2528  if (goal in ymGoals) {
2529    //ga('send', 'event', ymGoals[goal]);
2530    ga(ga.getAll()[0].get("name") + ".send", "pageview", ymGoals[goal]);
2531  }
2532}
2533
2534// закрепление/открепление меню при скроллинге
2535function scroll_header_fixed($block, blockTop) {
2536  let scrollTop = $(window).scrollTop();
2537
2538  if (scrollTop > blockTop && !$block.hasClass("fix")) {
2539    $block.addClass("fix");
2540  } else if (scrollTop <= blockTop && $block.hasClass("fix")) {
2541    $block.removeClass("fix");
2542  }
2543}
2544
2545// функция проверки ширины
2546function is_width(width) {
2547  return window.matchMedia("(max-width: " + width + "px)").matches;
2548}
2549
2550function favShow() {
2551  var $fav = $(".product-in-btn-price .fav");
2552
2553  if (!$fav.length) {
2554    return false;
2555  }
2556
2557  var $hFav = $("#mobile_nav .fav-block");
2558
2559  $hFav.addClass("show");
2560
2561  if ($fav.hasClass("active")) {
2562    $hFav.addClass("active");
2563  }
2564}
2565
2566function loadDifferentCarousel() {
2567  var $products = $("#diff_products");
2568  var $chars = $("#diff_chars");
2569  var $moving = false;
2570
2571  $products.on("initialized.owl.carousel", function (e) {
2572    if (e.item.count <= e.page.size) {
2573      $products.find(".owl-next").hide();
2574      $products.find(".owl-prev").hide();
2575    }
2576  });
2577
2578  $products.owlCarousel({
2579    margin: 0,
2580    loop: false,
2581    responsiveClass: true,
2582    responsive: {
2583      0: {
2584        items: 1,
2585        pagination: false,
2586        nav: true,
2587        navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
2588      },
2589      600: {
2590        items: 2,
2591        pagination: false,
2592        nav: true,
2593        navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
2594      },
2595      1000: {
2596        items: 3,
2597        pagination: false,
2598        nav: true,
2599        navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
2600      },
2601    },
2602  });
2603
2604  $chars.owlCarousel({
2605    margin: 0,
2606    loop: false,
2607    responsiveClass: true,
2608    responsive: {
2609      0: {
2610        items: 1,
2611        pagination: false,
2612        nav: false,
2613      },
2614      600: {
2615        items: 2,
2616        pagination: false,
2617        nav: false,
2618      },
2619      1000: {
2620        items: 3,
2621        pagination: false,
2622        nav: false,
2623      },
2624    },
2625  });
2626
2627  $products.on("changed.owl.carousel", function (e) {
2628    if ($moving == false) {
2629      $moving = true;
2630      $chars.trigger("to.owl.carousel", [e.item.index, 300, true]);
2631      $moving = false;
2632    }
2633    if (e.item.count > e.page.size) {
2634      $products.find(".owl-next").show();
2635      $products.find(".owl-prev").show();
2636
2637      $products.find(".owl-next").removeClass("disabled");
2638      $products.find(".owl-prev").removeClass("disabled");
2639
2640      if (e.item.index == 0) {
2641        $products.find(".owl-prev").addClass("disabled");
2642      }
2643
2644      if (e.item.index + e.page.size == e.item.count) {
2645        $products.find(".owl-next").addClass("disabled");
2646      }
2647    } else {
2648      $products.find(".owl-next").hide();
2649      $products.find(".owl-prev").hide();
2650    }
2651  });
2652
2653  $chars.on("changed.owl.carousel", function (e) {
2654    if ($moving == false) {
2655      $moving = true;
2656      $products.trigger("to.owl.carousel", [e.item.index, 300, true]);
2657      $moving = false;
2658    }
2659  });
2660}
2661
2662// функция проверки ширины
2663function is_width(width) {
2664  return window.matchMedia("(max-width: " + width + "px)").matches;
2665}
2666
2667$(".lazyx").lazy({
2668  effect: "fadeIn",
2669  threshold: 50,
2670});
2671
2672$('[name="delivery"]').change(function () {
2673  $(".field-address").attr("data-type", $(this).val());
2674  $(".field-address input").focus();
2675});
2676
2677if (is_width(920)) {
2678  startTheOwl($(".owl-blog-mob"));
2679}
2680
2681$(".delivery-data-block .forms_in.btn-main").on("click", function () {
2682  track("open_support");
2683});
2684$(".btn.btn-cart.btn-order").on("click", function () {
2685  track("open_on_request");
2686});
2687
2688let w = setInterval(function () {
2689  if (document.querySelector(".credit-row.grid_credit.credit-kaspi")) {
2690// removed debug log 2026-09-04
2691    if (document.querySelector(".credit-row.grid_credit.credit-kaspi .ks-widget")) {
2692    document.querySelector(".credit-row.grid_credit.credit-kaspi .ks-widget").onclick = function () {
2693      ym(52143727, "reachGoal", "kaspikz");
2694      ga(ga.getAll()[0].get("name") + ".send", "pageview", "/virtual/kaspikz");
2695    };
2696    clearInterval(w);
2697    }
2698  }
2699}, 4000);
2700
2701function track(event) {
2702  if (event) {
2703    if ("undefined" !== typeof Ya && "undefined" !== typeof Ya._metrika) {
2704      $.each(Ya._metrika.counters, function (key, counter) {
2705        counter.reachGoal(event, { URL: document.location.href });
2706      });
2707    }
2708    if ("undefined" !== typeof ga) {
2709      ga(ga.getAll()[0].get("name") + ".send", "pageview", "/virtual/" + event);
2710    }
2711  }
2712}
2713
2714function getGa4CheckoutData() {
2715  var raw = $("#ga4_checkout_data").attr("data-ga4-checkout");
2716  if (!raw) return null;
2717
2718  try {
2719    return JSON.parse(raw);
2720  } catch (e) {
2721    console.log("GA4 checkout data parse error", e);
2722    return null;
2723  }
2724}
2725
2726function pushGa4ShippingInfo() {
2727  var checkoutData = getGa4CheckoutData();
2728  var $checked = $('input[name="delivery"]:checked');
2729
2730  if (!checkoutData || !$checked.length) return;
2731
2732  var shippingLabel = $('label[for="' + $checked.attr("id") + '"]').text().trim();
2733
2734  window.dataLayer = window.dataLayer || [];
2735  window.dataLayer.push({ ecommerce: null });
2736  window.dataLayer.push({
2737    event: "add_shipping_info",
2738    ecommerce: {
2739      currency: checkoutData.currency,
2740      value: checkoutData.value,
2741      shipping_tier: shippingLabel,
2742      items: checkoutData.items
2743    }
2744  });
2745}
2746
2747function pushGa4PaymentInfo() {
2748  var checkoutData = getGa4CheckoutData();
2749  var $checked = $('input[name="payment"]:checked');
2750
2751  if (!checkoutData || !$checked.length) return;
2752
2753  var paymentLabel = $('label[for="' + $checked.attr("id") + '"]').text().trim();
2754
2755  window.dataLayer = window.dataLayer || [];
2756  window.dataLayer.push({ ecommerce: null });
2757  window.dataLayer.push({
2758    event: "add_payment_info",
2759    ecommerce: {
2760      currency: checkoutData.currency,
2761      value: checkoutData.value,
2762      payment_type: paymentLabel,
2763      items: checkoutData.items
2764    }
2765  });
2766}
2767
2768$("body").on("change", 'input[name="delivery"]', function () {
2769  pushGa4ShippingInfo();
2770});
2771
2772$("body").on("change", 'input[name="payment"]', function () {
2773  pushGa4PaymentInfo();
2774});

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.