PageSourceSearch

https://p-tour.ru/js/main.js?20260901133800

js p-tour.ru collected 2026-10-09 21:52:54 UTC 91,889 bytes, 2,320 lines download raw bytes

1var datepicker_count = 2, $comagic_form;
2var dpOpts = {
3    dateFormat: 'dd.mm.yy',
4    numberOfMonths: 2,
5    minDate: 0,
6    beforeShow: function(el,inst){
7        var ds,df;
8
9        if ($(this).attr('data-period')){
10            ds = $(this).closest('form').find('input[name="from_' + $(this).attr('data-period') + '"]');
11            df = $(this).closest('form').find('input[name="to_' + $(this).attr('data-period') + '"]');
12        }
13
14        if (ds && ds.length && df && df.length && $(this).attr('name') == df.attr('name') && ds.val()){
15            $(this).datepicker('option','minDate',ds.val());
16        }
17    },
18    beforeShowDay: function(date){
19        var ds,df,date1,date2,now = new Date();
20        now.setHours(0,0,0,0);
21
22        if ($(this).attr('data-period')){
23            ds = $(this).closest('form').find('input[name="from_' + $(this).attr('data-period') + '"]').val();
24            df = $(this).closest('form').find('input[name="to_' + $(this).attr('data-period') + '"]').val();
25        }
26
27        if (!ds || !df) return [true,date.getTime() == now.getTime() ? 'date-today' : ''];
28
29        date1 = $.datepicker.parseDate('dd.mm.yy',ds);
30        date2 = $.datepicker.parseDate('dd.mm.yy',df);
31
32        if ((date.getTime() == date1.getTime()) || (date.getTime() == date2.getTime())) return [true,(date.getTime() == now.getTime() ? 'date-today ' : '') + 'first-last'];
33
34        return [true,(date.getTime() == now.getTime() ? ' date-today' : '') + (date1 && ((date.getTime() == date1.getTime()) || (date2 && date >= date1 && date <= date2)) ? ' dp-highlight' : '')];
35    },
36    onSelect: function(dateText,inst){
37        var ds,df,date1,date2;
38
39        if ($(this).attr('data-period')){
40            ds = $(this).closest('form').find('input[name="from_' + $(this).attr('data-period') + '"]');
41            df = $(this).closest('form').find('input[name="to_' + $(this).attr('data-period') + '"]');
42        }
43
44        if (!ds || !ds.length || !df || !df.length) return;
45
46        if ($(this).attr('name') == 'from_' + $(this).attr('data-period')){
47            date1 = $.datepicker.parseDate('dd.mm.yy',dateText);
48            date2 = $.datepicker.parseDate('dd.mm.yy',df.val());
49
50            if (!date2 || date1.getTime() > date2.getTime()) df.val(dateText);
51
52            ds.val(dateText).trigger('change');
53            df.datepicker('option','minDate',dateText);
54            window.setTimeout(function(){ df.datepicker('show'); },10);
55        }
56        else{
57            df.val(dateText).trigger('change');
58            df.datepicker('option','minDate',0);
59            if ($(this).closest('.steps-form__slide').find('.steps__next').length) $(this).closest('.steps-form__slide').find('.steps__next').trigger('click');
60        }
61    }
62}, cityOpts = {
63    serviceUrl: '/ajax/form/step_resorts/',
64    type: 'get',
65    dataType: 'json',
66    paramName: 'q',
67    minChars: 2,
68    autoSelectFirst: true,
69    preserveInput: true,
70    beforeRender: function(container, suggestions) {
71        var t = $(this).attr('data-class');
72        if (t && suggestions && suggestions.length) container.addClass(t);
73    },
74    formatResult: function (suggestion, currentValue) {
75        return '<span class="autocomplete-country-flag" title="' + suggestion.data.cntr + '" style="background-image:url(' + suggestion.data.flag + ');"></span><span class="autocomplete-city" data-id="' + suggestion.data.id + '">' + suggestion.value + '</span>';
76    },
77    onSearchComplete: function (query, suggestions) {
78        if (suggestions && suggestions.length) $(this).addClass('suggestions');
79        else $(this).removeClass('suggestions');
80    },
81    onHide: function (container) {
82        var $this = $(this),
83            $root = $this.closest('.js-autocomplete'),
84            $value = $root.find('.autocomplete-value'),
85            $thisval = $this.val(),
86            $valhtml = $value.html(),
87            $thisplace = $this.attr('placeholder');
88        if (!$this.is(':focus')){
89            autocompleteCityVal($this);
90            $this.removeClass('suggestions').trigger('blur');
91        }
92    },
93    onSelect: function (suggestion) {
94        var $this = $(this),
95            $root = $this.closest('.js-autocomplete'),
96            $value = $root.find('.autocomplete-value'),
97            $data = $root.find('.autocomplete-data');
98        $value.html(suggestion.value);
99        $this.val(suggestion.value);
100        $data.attr('title',suggestion.data.cntr).css('background-image','url(' + suggestion.data.flag + ')');
101        $root.find('input[name="resort_id"]').val(suggestion.data.id);
102        $root.find('input[name="country"]').val(suggestion.data.cntr);
103        if (suggestion.data.flag) $data.closest('.autocomplete-result').addClass('flag');
104        else $data.closest('.autocomplete-result').removeClass('flag');
105        $root.removeClass('focus');
106        if ($this.closest('.steps-form__slide').find('.steps__next').length) $this.closest('.steps-form__slide').find('.steps__next').trigger('click');
107    }
108}, fancyboxFormOpts = {
109    modal : false,
110    touch: false,
111    autoFocus : false,
112    trapFocus : false,
113    openEffect  : 'none',
114    closeEffect : 'none',
115    afterShow : function() {
116            if ($('.fancybox-container.fancybox-is-open .popup-steps').length){
117                $('.fancybox-container.fancybox-is-open .popup-steps .select2').each(function(){
118                    initSelect2($(this));
119                });
120                $('.fancybox-container.fancybox-is-open .popup-steps .input__dates input.single_date').each(function(){
121                    initDatepicker($(this));
122                });
123                $('.fancybox-container.fancybox-is-open .popup-steps .input__childs select').change(function(){
124                    var c = $(this).val();
125                    $(this).closest('form').find('.input-content-children-range select').each(function(idx){
126                        if (idx < c){
127                            $(this).prop('disabled',false);
128                        }
129                        else{
130                            $(this).val('').prop('disabled',true).trigger('change.select2');
131                        }
132                    });
133                });
134            }
135        $(document.body).addClass('fancybox-opened');
136    },
137    afterClose : function(instance, current, e) {
138        $(document.body).removeClass('fancybox-opened');
139        if (current.src == '#popup-steps') {
140            p_get_prev_step();
141            if (p_step == 5) {
142                p_step = 1;
143                p_next_step();
144            }
145        }
146    },
147    btnTpl : {
148        smallBtn   : '<button data-fancybox-close class="fancybox-close-small fancybox-close-r" title="{{CLOSE}}"></button>',
149    }
150};
151
152$(document).ready(function() {
153
154    $.validator.addMethod( "require_from_group", function( value, element, options ) {
155        var $fields = $( options[ 1 ], element.form ),
156            $fieldsFirst = $fields.eq( 0 ),
157            validator = $fieldsFirst.data( "valid_req_grp" ) ? $fieldsFirst.data( "valid_req_grp" ) : $.extend( {}, this ),
158            isValid = $fields.filter( function() {
159                return validator.elementValue( this );
160            } ).length >= options[ 0 ];
161
162        // Store the cloned validator for future validation
163        $fieldsFirst.data( "valid_req_grp", validator );
164
165        // If element isn't being validated, run each require_from_group field's validation rules
166        if ( !$( element ).data( "being_validated" ) ) {
167            $fields.data( "being_validated", true );
168            $fields.each( function() {
169                validator.element( this );
170            } );
171            $fields.data( "being_validated", false );
172        }
173        return isValid;
174    }, $.validator.format( "Введите телефон или e-mail" ) );
175
176    $.validator.addMethod( "email_cyr", function( value, element, options ) {
177        return this.optional( element ) || /^[a-zA-Zа-яА-ЯёЁ0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Zа-яА-ЯёЁ0-9](?:[a-zA-Zа-яА-ЯёЁ0-9-]{0,61}[a-zA-Zа-яА-ЯёЁ0-9])?(?:\.[a-zA-Zа-яА-ЯёЁ0-9](?:[a-zA-Zа-яА-ЯёЁ0-9-]{0,61}[a-zA-Zа-яА-ЯёЁ0-9])?)*$/.test( value );
178    }, $.validator.format( "Введите правильный email адрес" ) );
179
180    //sticky header
181    $(window).on("scroll touchmove", function () {
182        $('header').toggleClass('sticky', $(document).scrollTop() > 80);
183    });
184
185    $(".button").click(function(){
186        $(this).trigger("blur");
187    });
188
189    $("[data-fancybox]").fancybox({
190        modal : false
191    });
192
193    $("[data-fancybox-form]").fancybox(fancyboxFormOpts);
194
195    //menu hover
196    var timeout;
197    var timeout2;
198
199    $(".nav__menu").on({
200        mouseenter: function () {
201            var elem = $(this);
202            var sub = $(this).children(".nav__submenu");
203            if (timeout != null) { clearTimeout(timeout); }
204            if (timeout2 != null) {
205               clearTimeout(timeout2);
206               timeout2 = null;
207            }
208            timeout = setTimeout(function () {
209                if(!elem.hasClass("nav__menu--active")) {
210                    $(".nav__menu--active").children(".nav__submenu").slideUp(200);
211                    $(".nav__menu--active").removeClass("nav__menu--active");
212                }
213                if(sub.length && !elem.hasClass("nav__menu--active")) {
214
215                    if(sub.hasClass("nav__submenu-mobile-hidden") && $(".nav-block").hasClass("nav-block-mobile")) return;
216                    sub.slideDown(200, function(){
217                        elem.addClass("nav__menu--active");
218                    });
219                }
220            }, 300);
221        },
222        mouseleave: function () {
223            if (timeout != null) {
224               clearTimeout(timeout);
225               timeout = null;
226            }
227            if (timeout2 != null) { clearTimeout(timeout2); }
228            timeout2 = setTimeout(function () {
229                $(".nav__menu--active").children(".nav__submenu").slideUp(200);
230                $(".nav__menu--active").removeClass("nav__menu--active");
231            }, 300);
232        }
233    });
234
235    $(".nav__link").on("click",function(e){
236        var elem = $(this);
237        if($(".nav-block").hasClass("nav-block-mobile")) {
238            if (elem.parent().children(".nav__submenu").length && !elem.parent().children(".nav__submenu").hasClass("nav__submenu-mobile-hidden")) {
239                e.preventDefault();
240                e.stopPropagation();
241            }
242        }
243    });
244
245    //$(".input__phone").mask("+7 (999) 999-9999");
246
247    if ($.fn.mask) {
248
249        $('.input__phone').each(function() {
250
251            $.mask.definitions['h'] = "[0-69]";
252
253            $(this).mask('+7 (h99) 999-9999');
254        })
255    };
256
257    // Inline step form
258    if ($(".steps-form form").length)
259    $(".steps-form form").validate({
260          errorClass: "error",
261          rules: {
262            name:{
263                  required: true,
264                  minlength: 3,
265                  maxlength: 25
266              },
267              email: {
268                  require_from_group: [1, ".phone-email-group-steps"],
269                  email_cyr: true
270              },
271              phone: {
272                  require_from_group: [1, ".phone-email-group-steps"]
273              }
274          },
275          messages: {
276            name:{
277                  required: "Обязательно для заполнения",
278                  minlength: "Минимум 3 символа",
279                  maxlength: "Максимальное число символов - 25"
280              },
281              email:{
282                  require_from_group: "Введите телефон или e-mail",
283                  required: "Обязательно для заполнения",
284                  email_cyr: "Введите правильный email адрес"
285              },
286              phone: {
287                  require_from_group: "Введите телефон или e-mail",
288                  required: "Обязательно для заполнения"
289              }
290          }
291        });
292
293    $(".steps__next").on("click",function(){
294        var $block = $(this).closest('.steps-form');
295        if ($block.hasClass("disabled")) return;
296        $block.addClass("disabled");
297        get_prev_step($block);
298        step+=1;
299        next_step($block);
300    });
301
302    $(".steps__submit").on("click",function(){
303        var $this = $(this), $form = $this.closest('form'), $block = $this.closest('.steps-form');
304        $this.addClass("disabled");
305        if ($form.hasClass('js-disabled')) return false;
306        if (submit_form_callback($form)) {
307            $this.removeClass("disabled");
308            $block.addClass("disabled");
309            get_prev_step($block);
310            step+=1;
311            next_step($block);
312        }
313        else {
314            $this.removeClass("disabled");
315        }
316        return false;
317    });
318
319    $(".steps-form__main .steps__step-item").on("click",function(){
320        var $block = $(this).closest('.steps-form');
321        if ($block.hasClass("disabled")) return;
322        $block.addClass("disabled");
323        get_prev_step($block);
324        step = parseInt($(this).attr("slide_num"));
325        next_step($block);
326    });
327
328    $(".steps-form__show-comment-field").on("click",function(e){
329        e.preventDefault();
330        e.stopPropagation();
331        var text = $(this).text();
332        $(this).text(text == "Добавить комментарий" ? "Убрать комментарий" : "Добавить комментарий");
333        $(".steps-form__grid-item-comment-field").slideToggle(200);
334    });
335
336
337
338    //steps popup
339    if ($(".popup-steps form").length)
340    $(".popup-steps form").validate({
341          errorClass: "error",
342          rules: {
343            name:{
344                  required: true,
345                  minlength: 3,
346                  maxlength: 25
347              },
348              email: {
349                  require_from_group: [1, ".phone-email-group-popup"],
350                  email_cyr: true
351              },
352              phone: {
353                  require_from_group: [1, ".phone-email-group-popup"]
354              }
355          },
356          messages: {
357            name:{
358                  required: "Обязательно для заполнения",
359                  minlength: "Минимум 3 символа",
360                  maxlength: "Максимальное число символов - 25"
361              },
362              email:{
363                  require_from_group: "Введите телефон или e-mail",
364                  required: "Обязательно для заполнения",
365                  email_cyr: "Введите правильный email адрес"
366              },
367              phone: {
368                  require_from_group: "Введите телефон или e-mail",
369                  required: "Обязательно для заполнения"
370              }
371          }
372        });
373    $(".popup-steps-next").on("click",function(){
374        if ($(".popup-steps").hasClass("disabled")) return;
375        if (p_step==3) {
376            var $form = $(this).closest('form');
377            $form.find('.js-ages-label').removeClass('error-text');
378            $form.find('.js-age-select.error').each(function(){
379                $(this).removeClass('error').next('.select2-container').removeClass('error');
380            });
381            $form.find('.js-age-select:not(:disabled)').each(function() {
382                var $this = $(this);
383                if (!$this.val()){
384                    $this.addClass('error').next('.select2-container').addClass('error');
385                    $form.find('.js-ages-label').addClass('error-text');
386                }
387            });
388            if ($form.find('.js-ages-label.error-text').length) return;
389        }
390        if(p_step < 4) {
391            $(".popup-steps").addClass("disabled");
392            p_get_prev_step();
393            p_step+=1;
394            p_next_step();
395        } else {
396            popup_check();
397        }
398        return false;
399    });
400
401    $(".popup-steps-prev").on("click",function(){
402        if ($(".popup-steps").hasClass("disabled")) return;
403        $(".popup-steps").addClass("disabled");
404        p_get_prev_step();
405        p_step-=1;
406        p_next_step();
407    });
408
409    $(".popup-steps .steps__step-item").on("click",function(){
410        var p_next = parseInt($(this).attr("slide_num"));
411        if ($(".popup-steps").hasClass("disabled")) return;
412        if (p_step==3) {
413            var $form = $(this).closest('form');
414            $form.find('.js-ages-label').removeClass('error-text');
415            $form.find('.js-age-select.error').each(function(){
416                $(this).removeClass('error').next('.select2-container').removeClass('error');
417            });
418            $form.find('.js-age-select:not(:disabled)').each(function() {
419                var $this = $(this);
420                if (!$this.val()){
421                    $this.addClass('error').next('.select2-container').addClass('error');
422                    $form.find('.js-ages-label').addClass('error-text');
423                }
424            });
425            if ($form.find('.js-ages-label.error-text').length) return;
426        }
427        if(p_next == 4 & p_step==4) {
428            return;
429        } else if (p_next <= 4) {
430            $(".popup-steps").addClass("disabled");
431            p_get_prev_step();
432            p_step = parseInt($(this).attr("slide_num"));
433            p_next_step();
434        } else if(p_step == 4) {
435            popup_check();
436        } else {
437            return;
438        }
439    });
440
441    if ($('[data-fancybox-form][data-src="#popup-steps"][data-force-open]').length) {
442        $('[data-fancybox-form][data-src="#popup-steps"][data-force-open]').each(function() {
443            var $this = $(this), fo = parseInt($this.attr('data-force-open'));
444            if (isNaN(fo) || fo < 1) $this.trigger('click');
445            else window.setTimeout(function() { $this.trigger('click'); }, fo * 1000);
446        });
447    }
448
449    if ($("#timeout-popup").length) {
450        var appear = parseInt($("#timeout-popup").attr("data-appear"));
451        if (!isNaN(appear) && appear > 0) {
452            window.setTimeout(function() {
453                $(".timeout-popup[data-fancybox-form]").trigger("click");
454                var hide = parseInt($("#timeout-popup").attr("data-hide"));
455                if (!isNaN(hide) && hide > 0) $.cookie('timeout_form_hide',hide, { expires: hide, path: '/' });
456            }, appear * 1000);
457        }
458
459        $("#timeout-popup .button").on("click",function() {
460            var instance = $.fancybox.getInstance();
461            instance.$lastFocus.closest(".popup-form").find(".fancybox-close-small").trigger("click");
462        });
463    }
464
465    if ($("#timeout-yes-form").length)
466        $("#timeout-yes-form").validate({
467            submitHandler: function (form) {
468                if (submit_form_callback($("#timeout-yes-form"))) {
469                    $("#timeout-yes-form")[0].reset();
470                    $.fancybox.close(true);
471                    $(".success-link.timeout").trigger("click");
472                }
473          },
474          errorClass: "error",
475          rules: {
476              phone: {
477                  required: true
478              }
479          },
480          messages: {
481              phone: {
482                  required: "Обязательно для заполнения"
483              }
484          }
485        });
486    if ($("#timeout-no-form").length)
487        $("#timeout-no-form").validate({
488            submitHandler: function (form) {
489                if (submit_form_callback($("#timeout-no-form"))) {
490                    $("#timeout-no-form")[0].reset();
491                    $.fancybox.close(true);
492                    $(".success-link.timeout").trigger("click");
493                }
494          },
495          errorClass: "error",
496          rules: {
497              phone: {
498                  required: true
499              }
500          },
501          messages: {
502              phone: {
503                  required: "Обязательно для заполнения"
504              }
505          }
506        });
507    if ($("#callback1").length)
508        $("#callback1").validate({
509            submitHandler: function (form) {
510                if (submit_form_callback($("#callback1"))) {
511                    $("#callback1")[0].reset();
512                    $.fancybox.close();
513                    $(".sucess-link").trigger("click");
514                }
515          },
516          errorClass: "error",
517          rules: {
518            name:{
519                  required: true,
520                  minlength: 3,
521                  maxlength: 25
522              },
523              phone: {
524                  required: true
525              }
526          },
527          messages: {
528            name:{
529                  required: "Обязательно для заполнения",
530                  minlength: "Минимум 3 символа",
531                  maxlength: "Максимальное число символов - 25"
532              },
533              phone: {
534                  required: "Обязательно для заполнения"
535              }
536          }
537        });
538    if ($("#callback-form").length)
539        $("#callback-form").validate({
540            submitHandler: function (form) {
541                if (submit_form_callback($("#callback-form"))) {
542                    $("#callback-form")[0].reset();
543                    $.fancybox.close();
544                    $(".success-link.callback").trigger("click");
545                }
546          },
547          errorClass: "error",
548          rules: {
549              name: {
550                  required: true,
551                  minlength: 3,
552                  maxlength: 25
553              },
554              email: {
555                  require_from_group: [1, ".phone-email-group-callback"],
556                  email_cyr: true
557              },
558              phone: {
559                  require_from_group: [1, ".phone-email-group-callback"]
560              }
561          },
562          messages: {
563            name:{
564                  required: "Обязательно для заполнения",
565                  minlength: "Минимум 3 символа",
566                  maxlength: "Максимальное число символов - 25"
567              },
568              email:{
569                  require_from_group: "Введите телефон или e-mail",
570                  required: "Обязательно для заполнения",
571                  email_cyr: "Введите правильный email адрес"
572              },
573              phone: {
574                  require_from_group: "Введите телефон или e-mail",
575                  required: "Обязательно для заполнения"
576              }
577          }
578        });
579    if ($("#callback-hotel-form").length)
580        $("#callback-hotel-form").validate({
581            submitHandler: function (form) {
582                if (submit_form_callback($("#callback-hotel-form"))) {
583                    $("#callback-hotel-form")[0].reset();
584                    $.fancybox.close();
585                    $(".success-link.callback").trigger("click");
586                }
587          },
588          errorClass: "error",
589          rules: {
590              name: {
591                  required: true,
592                  minlength: 3,
593                  maxlength: 25
594              },
595              email: {
596                  require_from_group: [1, ".phone-email-group-callback"],
597                  email_cyr: true
598              },
599              phone: {
600                  require_from_group: [1, ".phone-email-group-callback"]
601              }
602          },
603          messages: {
604            name:{
605                  required: "Обязательно для заполнения",
606                  minlength: "Минимум 3 символа",
607                  maxlength: "Максимальное число символов - 25"
608              },
609              email:{
610                  require_from_group: "Введите телефон или e-mail",
611                  required: "Обязательно для заполнения",
612                  email_cyr: "Введите правильный email адрес"
613              },
614              phone: {
615                  require_from_group: "Введите телефон или e-mail",
616                  required: "Обязательно для заполнения"
617              }
618          }
619        });
620    if ($("#callphone-form").length)
621        $("#callphone-form").validate({
622            submitHandler: function (form) {
623                if (submit_form_callback($("#callphone-form"))) {
624                    $("#callphone-form")[0].reset();
625                    $.fancybox.close();
626                    $(".success-link.callback").trigger("click");
627                }
628          },
629          errorClass: "error",
630          rules: {
631              name: {
632                  required: true,
633                  minlength: 3,
634                  maxlength: 25
635              },
636              phone: {
637                  required: true
638              }
639          },
640          messages: {
641            name:{
642                  required: "Обязательно для заполнения",
643                  minlength: "Минимум 3 символа",
644                  maxlength: "Максимальное число символов - 25"
645              },
646              phone: {
647                  required: "Обязательно для заполнения"
648              }
649          }
650        });
651    if ($("#callback3").length)
652        $("#callback3").validate({
653            submitHandler: function (form) {
654                if (submit_form_callback($("#callback3"))) {
655                    $("#callback3")[0].reset();
656                    $.fancybox.close();
657                    $(".sucess-link").trigger("click");
658                }
659          },
660          errorClass: "error",
661          rules: {
662            name:{
663                  required: true,
664                  minlength: 3,
665                  maxlength: 25
666              },
667              email: {
668                  required: true,
669                  email_cyr: true
670              },
671              phone: {
672                  required: true
673              }
674          },
675          messages: {
676            name:{
677                  required: "Обязательно для заполнения",
678                  minlength: "Минимум 3 символа",
679                  maxlength: "Максимальное число символов - 25"
680              },
681              email:{
682                  required: "Обязательно для заполнения",
683                  email_cyr: "Введите правильный email адрес"
684              },
685              phone: {
686                  required: "Обязательно для заполнения"
687              }
688          }
689        });
690
691    if ($(".orange-form").length){
692        $(".orange-form").each(function(){
693            initOrangeForm($(this));
694        });
695    }
696
697    $(".popup-steps__show-comment").on("click",function(e){
698        e.preventDefault();
699        e.stopPropagation();
700        var text = $(this).text();
701        $(this).text(text == "Добавить комментарий" ? "Убрать комментарий" : "Добавить комментарий");
702        $(".popup-steps__comment-block").slideToggle(200);
703    });
704
705
706    //mobile menu
707    $('.mobile-menu-button').on('click', function(e){
708        e.preventDefault();
709        e.stopPropagation();
710        if($(this).hasClass('disabled')) return;
711        if($(this).hasClass('active')) {
712            $(this).addClass('disabled');
713            $(".nav-block").slideUp({
714                duration:400,
715                complete:function(){
716                    $(".mobile-menu-button").removeClass('active').removeClass('disabled'); ;
717                }
718            });
719        } else {
720            $(this).addClass('disabled');
721            $(".nav-block").slideDown({
722                duration:400,
723                complete:function(){
724                    $(".mobile-menu-button").addClass('active').removeClass('disabled');
725                }
726            });
727        }
728    });
729
730    initSlick();
731
732    if ($('.promo .promo-block').length > 1){
733        $('.promo').owlCarousel({
734            items:1,
735            loop:true,
736            autoHeight:true,
737            nav:true,
738            animateOut:'fadeOut',
739            autoplay:true,
740            autoplayTimeout:5000,
741            autoplayHoverPause:true,
742            navText:['<span class="icon icon__left-arrow"></span>','<span class="icon icon__right-arrow"></span>']
743        });
744    }
745    $('.content-slider').owlCarousel({
746        items:1,
747        loop:false,
748        autoHeight:true,
749        nav:true,
750        animateIn:'fadeIn',
751        animateOut:'fadeOut',
752        dots:false,
753        navText:['<span class="icon icon__left-arrow"></span>','<span class="icon icon__right-arrow"></span>']
754    });
755
756    $(document).on({
757        'click': function(){
758            var t = $(this).closest('.tabs-selector-block').attr('data-active');
759            if (!t || $(this).hasClass(t)) return false;
760
761            $(this).closest('.tabs-selector-block').find('.tabs-selector.' + t).removeClass(t);
762            $(this).addClass(t);
763
764            $(this).closest('.tabs-block').find('.tabs-content:visible').hide();
765            $(this).closest('.tabs-block').find('.tabs-content[data-tab="' + $(this).attr('data-tab') + '"]').slideDown();
766
767            if ($(this).attr('data-tab') === 'map') {
768                hotelMap.container.fitToViewport();
769            }
770
771            return false;
772        }
773    },'.tabs-selector');
774
775    $('[data-tabs-selector]').on('click', function(){
776        var $el = $('.tabs-selector[data-tab="' + $(this).attr('data-tabs-selector') + '"]');
777        if ($el.length) $el.trigger('click');
778    });
779
780    $(document).on({
781        'click': function(e){
782            var $this = $(this), $el = $(($this.attr('data-href') || $this.attr('href')));
783            if ($el.length == 1){
784                e.preventDefault();
785                $('html, body').stop().animate({ scrollTop: $el.offset().top - 65 }, 400);
786            }
787        }
788    }, '.js-slide-to');
789
790    $('.select2').each(function(){
791        if (!$(this).closest('.popup-steps').length){
792            initSelect2($(this));
793        }
794    });
795
796    $('.search-block__nights-up').click(function(){
797        $(this).toggleClass('active');
798        $(this).siblings('input[type=hidden]').prop('disabled', !$(this).is('.active'));
799    });
800
801    $(document).on({
802        'mouseover': function(){
803            var t = $(this).closest('.stars-select');
804            t.addClass('process');
805            window.setTimeout(function(){
806                t.removeClass('process');
807            },20);
808            $(this).trigger('mousemove');
809        },
810        'mouseout': function(){
811            var t = $(this).closest('.stars-select');
812            window.setTimeout(function(){
813                if (!t.hasClass('process'))
814                    $('.select2-drop .stars-select .icon__star.hover').removeClass('hover');
815            },10);
816        },
817        'mousemove': function(){
818            var t = $(this).index();
819            $('.select2-drop .stars-select .icon__star').each(function(i){
820                if (i > t) $(this).removeClass('hover');
821                else $(this).addClass('hover');
822            });
823        },
824        'click': function(){
825            $('.select2.select2-container--open').closest('.stars-content').addClass('show-star');
826            $('.select2.select2-container--open').prev('.select2:first').val($('.select2-drop .stars-select .icon__star.hover').length).trigger('change').select2('close');
827        }
828    }, '.select2-drop .stars-select .icon__star');
829    $(document).on({
830        'click': function(){
831            $('.select2.select2-container--open').closest('.stars-content').removeClass('show-star');
832            $('.select2.select2-container--open').prev('.select2:first').val('').trigger('change').select2('close');
833        }
834    }, '.select2-drop .stars-clear span');
835
836    $(document).on({
837        'click': function(){
838            var t = $(this).closest('.input-content').find('input');
839            t.val(t.val() ? parseInt(t.val())  + 1 : 1);
840            if (t.val() > 1) $(this).closest('.input-content').find('.icon__adults_down.disabled').removeClass('disabled');
841        }
842    },'.icon__adults_up');
843    $(document).on({
844        'click': function(){
845            if (!$(this).hasClass('disabled')){
846                var t = $(this).closest('.input-content').find('input');
847                if (t.val() > 1) t.val(t.val() - 1);
848                if (t.val() < 2) $(this).addClass('disabled');
849            }
850        }
851    },'.icon__adults_down');
852
853    $('.input__dates input.single_date').each(function(){
854        if (!$(this).closest('.popup-steps').length){
855            initDatepicker($(this));
856        }
857    });
858    $(document).on({
859        'change': function(){
860            var t = $(this).closest('form').find('.input__dates input.input');
861            t.val(t.closest('form').find('input[name="from_' + t.attr('data-period') + '"]').val().substr(0,5) + ' – ' + t.closest('form').find('input[name="to_' + t.attr('data-period') + '"]').val().substr(0,5));
862        }
863    },'.input__dates input.single_date');
864    $(document).on({
865        'focus': function(){
866            $(this).closest('form').find('input[name="from_' + $(this).attr('data-period') + '"]').datepicker('show');
867        }
868    },'.input__dates input.input');
869
870    function initCheckBox() {
871    $('input[type="checkbox"]').each(function(){
872        if (!$(this).parent().hasClass('checkbox')){
873            $(this).wrap('<span class="checkbox"></span>');
874            if ($(this).is(':checked')) $(this).parent().addClass('checked');
875        }
876        $(this).change(function(){
877            if ($(this).is(':checked')) $(this).parent().addClass('checked');
878            else $(this).parent().removeClass('checked');
879        });
880        if (!$(this).parents('label').length) $(this).parent().click(function(){
881            $(this).find('input[type="checkbox"]').trigger('click');
882        });
883    });
884    }
885    initCheckBox();
886
887    $('form .input-content-children-range').each(function(){
888        $(this).closest('form').find('.search-block__adults select').change(function(){
889            var c = $(this).val() % 10;
890            $(this).closest('form').find('.input-content-children-range select').each(function(idx){
891                if (idx < c){
892                    $(this).prop('disabled',false);
893                }
894                else{
895                    $(this).val('').prop('disabled',true).trigger('change.select2');
896                }
897            });
898        });
899    });
900
901    $('.js-autocomplete.search-all-cities input').each(function(){
902        $(this).click(function(){
903            if ($(this).hasClass('suggestions')) $(this).autocomplete('hide');
904        }).focus(function(){
905            var $this = $(this),txt = $this.val();
906            $this.val('');
907            window.setTimeout(function(){
908                $this.val(txt);
909            },0);
910        }).blur(function(){
911            autocompleteCityVal($(this));
912            $(this).removeClass('suggestions').closest('.js-autocomplete').removeClass('focus');
913        }).autocomplete(cityOpts);
914    });
915
916    $(document).on({
917        'click': function(){
918            var $this = $(this),
919                $root = $this.closest('.js-autocomplete'),
920                $input = $root.find('input:first');
921            $root.addClass('focus');
922            $input.trigger('focus');
923            return false;
924        }
925    }, '.js-autocomplete .autocomplete-result');
926    $(document).on({
927        blur: function(){
928            var $this = $(this),
929                $root = $this.closest('.js-autocomplete');
930            if (!$this.hasClass('suggestions')) $root.removeClass('focus');
931        }
932    }, '.js-autocomplete input');
933
934    $(document).on({
935        'change': function(){
936            var t = $(this).closest('form').find('select[name="resort"]');
937            if (t.length){
938                if (t.attr('data-ajax')) return false;
939                t.val('').attr('data-ajax','1').find('option[value!=""]').remove();
940                $.ajax({
941                    url: '/ajax/form/step_country_resorts/',
942                    data: 'cid=' + $(this).val(),
943                    cache: true,
944                    dataType: 'json',
945                    timeout: 10000,
946                    type: 'post',
947                    error: function(xhr,status,err) {
948                        console.log(status || err ? ('Ошибка списка курортов: ' + (status ? status + (status && err ? ' / ' : '') : '')) + (err ? err : '') : 'Неизвестная ошибка списка курортов');
949                        t.attr('data-ajax','');
950                    },
951                    success: function(data) {
952                        if (data['err']) console.log('Ошибка списка курортов: ' + data['err']);
953                        else
954                        {
955                            var o = '',x = 0;
956                            for (x = 0; x < data.length; x++) o += '<option value="' + data[x]['id'] + '">' + data[x]['title'] + '</option>';
957                            if (o.length) t.html(t.html() + o);
958                        }
959                        t.attr('data-ajax','');
960                    }
961                });
962                return false;
963            }
964        }
965    },'form select[name="country"]');
966
967    /**
968     * Таймер поискового прогресс-бара
969     */
970    var timerId;
971
972    // Кнопка запуска поиска
973    $('#sletat_search_form .button__find-tours, #extended_search_form .button__find-tours').on('click', function() {
974
975        var $form = $(this).closest('form');
976
977        $form.find('.js-ages-label').removeClass('error-text');
978        $form.find('.js-age-select.error').each(function(){
979            $(this).removeClass('error').next('.select2-container').removeClass('error');
980        });
981        $form.find('.js-age-select:not(:disabled)').each(function(){
982            var $this = $(this);
983            if (!$this.val()){
984                $this.addClass('error').next('.select2-container').addClass('error');
985                $form.find('.js-ages-label').addClass('error-text');
986            }
987        });
988        if ($form.find('.js-ages-label.error-text').length) return false;
989
990        // сбрасываем предущий поиск
991        $('.hotels').html('');
992        clearInterval(timerId);
993
994        // прогресс бар
995        $('#tour_search_progress').addClass('search-progress--show');
996        $('#tour_search_time').hide();
997        
998        $('html, body').stop().animate({
999            scrollTop: $('#tour_search_progress').offset().top - $('.header__top-menu').height() - 30
1000        }, 500);
1001        
1002        var level = 0, v = 0.8, a = 0.005; // позиция (0-99), скорость изменения (позиций за кадр), замедление (позиций/кадр за кадр)
1003        timerId = setInterval(function(){
1004            a += 0.000031; v -= v*a; level += v;
1005            $('#tour_search_progress .search-progress__bar').css('width', level+'%');
1006            $('#tour_search_progress .search-progress__percent').text(Math.round(level) + '%');
1007            if (level > 99) {
1008                clearInterval(timerId);
1009            }
1010        }, 25);
1011
1012        var auto_start = $('.button__find-tours').attr('data-auto-start');
1013        if (auto_start) {
1014            $form.find('select[name="resort_sid"]').prop('disabled', true);
1015            $form.find('input[name="resort_sid"]').prop('disabled', false);
1016        }
1017        var form_data = $form.serializeArray();
1018        if (auto_start) {
1019            $form.find('select[name="resort_sid"]').prop('disabled', false);
1020            $form.find('input[name="resort_sid"]').prop('disabled', true);
1021        }
1022        $('.button__find-tours').attr('data-auto-start','');
1023        $form.find('input[name="auto_start"]').val('');
1024        if ($('.hotels.js-nocache').length) {
1025            form_data.push({"name" : "nocache", "value" : 1});
1026        }
1027
1028        $.get(
1029            $form.attr('data-ajax') || $form.attr('action'),
1030            form_data,
1031            function(data) {
1032
1033                var is_scroll = true;
1034                if ($form.attr('id') == 'extended_search_form' && (!data || data.length < 1600)) {
1035                    $('html, body').stop().animate({
1036                        scrollTop: $form.find('.js-yestours').parent().offset().top - $('.header__top-menu').height() - 30
1037                    }, 200);
1038                    is_scroll = false;
1039                    $form.find('.js-yestours').stop().slideUp(200);
1040                    $form.find('.js-notours').stop().slideDown(200).find('input:disabled').attr('disabled', false);
1041                }
1042
1043                if (data) {
1044                    $('.hotels').removeClass('hotels--holder js-nocache').html(data).show();
1045                    $('#geo_notours_form').hide();
1046                }
1047
1048                $('.orange-form:not(.valid_set)').each(function(){
1049                    $(this).find(".input__phone").mask("+7 (999) 999-9999");
1050                    initOrangeForm($(this));
1051                    $(this).find("[data-fancybox-form]").fancybox(fancyboxFormOpts);
1052                });
1053
1054                initCheckBox();
1055
1056                // clear progrees bar
1057                clearInterval(timerId);
1058                $('#tour_search_progress').removeClass('search-progress--show');
1059
1060                // init image slider
1061                initSlick();
1062
1063                window.setTimeout(function(){
1064                    if (
1065                        is_scroll && (
1066                            (auto_start && $form.attr('data-scroll-auto') > 0) ||
1067                            (!auto_start && $form.attr('data-scroll-user') > 0)
1068                        )
1069                    ) {
1070                        $('html, body').stop().animate({
1071                            scrollTop: $('.hotels').offset().top - $('.header__top-menu').height() - 30
1072                        }, 500);
1073                    }
1074
1075                    if (!data) {
1076                        $('.hotels').hide();
1077                        $('#geo_notours_form').show();
1078                    }
1079                },10);
1080            },
1081            'html'
1082        );
1083
1084        return false;
1085    });
1086
1087    /**************** Basket Garantetour Widget ***************************/
1088    if (/iPad|iPhone|iPod/i.test(window && window.navigator && window.navigator.userAgent ? String(window.navigator.userAgent) : '')) {
1089        $('#basket__frame').closest('.basket-frame__wrapper').addClass('basket-frame__wrapper-ios');
1090    }
1091    // Open buttons handler
1092    $('.hotels, #hotel_tours, .hot-tours').on('click', '.basket-frame-link', function() {
1093        
1094        if ( ! $('#basket__frame').hasClass('opened')) {
1095            
1096            if ($(this).parents('.hotel-block').length) {
1097            
1098                $('html, body').stop().animate({scrollTop: $(this).parents('.hotel-block').offset().top - 80 }, 200, 'swing');
1099            }
1100            
1101            $('.inner-wrap-full.content-block').css('z-index', 999999);
1102            
1103            $('#basket__frame').attr('src', $(this).attr('data-href') || $(this).attr('href'));
1104            $('#basket__frame').fadeIn(100).addClass('opened').closest('.basket-frame__wrapper-ios').show();
1105            $('body').css("overflow", "hidden");
1106            $('.header__top-menu').hide();
1107        }
1108        return false;
1109    });
1110
1111    // Listener for cross-domain Basket Garantour widget content
1112    function receiveBasketMessage(event) {
1113
1114        if (event.origin !== "https://basket.garantetour.ru") {
1115            return;
1116        }
1117
1118        if (event.data === 'close' && $('#basket__frame').hasClass('opened')) {
1119            
1120            $('.inner-wrap-full.content-block').css('z-index', 1);
1121            
1122            $('#basket__frame').fadeOut(100,function(){ $('#basket__frame').closest('.basket-frame__wrapper-ios').hide(); }).removeClass('opened');
1123            $('#basket__frame').attr('src', 'https://basket.garantetour.ru/preload');
1124            $('body').css("overflow", "visible");
1125            $('.header__top-menu').show();
1126            return;
1127        }
1128
1129        if (typeof(event.data == 'object' && event.data.cmd === 'scrollTop')) {
1130            window.setTimeout(function(){$('#basket__frame').closest('.basket-frame__wrapper-ios').scrollTop(event.data.val);},250);
1131        }
1132
1133        if (event.data && event.data.indexOf("http") === 0) {
1134            window.location.href = event.data;
1135        }
1136
1137    }
1138    window.addEventListener("message", receiveBasketMessage, false);
1139    /**************** Basket Garantetour Widget ***************************/
1140
1141    // Кнопка догрузки результатов поиска "Показать еще"
1142    $('.hotels').on('click', '.show-all__hotels .button', function() {
1143
1144        $(this).parent().remove();
1145
1146        var query_data = [];
1147        query_data.push({name: "request_id", value: $(this).parent().attr("data-request-id")});
1148        query_data.push({name: "skip_results", value: $(this).parent().attr("data-skip")});
1149        query_data.push({name: "country_sid", value: $('.search-block select[name=country_sid]').val()});
1150
1151        $.get(
1152            $(this).attr('href'),
1153            query_data,
1154            function(data) {
1155                $('.hotels').append(data);
1156                initSlick();
1157            },
1158            'html'
1159        );
1160
1161        return false;
1162    });
1163
1164    // Кнопка "Показать еще туры отеля" в результатах поиска
1165    $('.hotels').on('click', '.show-more-tours a', function() {
1166
1167        var $block = $(this).parents('.short-other');
1168
1169        $block.find('.short-other__row:hidden:lt(3)').show();
1170
1171        if ( ! $block.find('.short-other__row:hidden').length) {
1172            $block.find('.show-more-tours').hide();
1173            $block.find('.show-all-tours').show();
1174        }
1175
1176        return false;
1177    });
1178
1179
1180    // Кнопка в форме на главной (переход на страницу с раширенной формой и автостарт поиска)
1181    $('#mainpage_search_form .button__find-tours').on('click', function() {
1182        var $form = $(this).parents('form');
1183        $form.find('input[name=auto_start]').val(1);
1184        $form.submit();
1185        return false;
1186    });
1187
1188
1189    // Кнопка "Расширенный поиск" в стандартных формах (переход на страницу с раширенной формой без автостарта)
1190    $('.search-block__full-link').on('click', function() {
1191        var $form = $(this).closest('form');
1192        $form.attr('action', $(this).attr('href'));
1193        $form.find('input[name=auto_start]').val(0);
1194        $form.submit();
1195        return false;
1196    });
1197
1198    // Кнопка "Изменить параметры поиска" в расширененой форме поиска
1199    $('.js-no2yes').on('click', function() {
1200        var $form = $(this).closest('form');
1201        $form.find('.js-yestours').stop().slideDown(200);
1202        $form.find('.js-notours').stop().slideUp(200).find('input:disabled').attr('disabled', true);
1203
1204        $('html, body').stop().animate({
1205            scrollTop: $form.offset().top - $('.header__top-menu').height() - 30
1206        }, 200);
1207
1208        return false;
1209    });
1210
1211    // Форма заявки при отсутствии туров
1212    if ($("#geo_notours_form").length)
1213    $("#geo_notours_form").validate({
1214        submitHandler: function (form) {
1215            if (submit_form_callback($("#geo_notours_form"))) {
1216                $("#geo_notours_form")[0].reset();
1217                $("#geo_notours_form select.select2").each(function(){
1218                    $(this).trigger('change.select2');
1219                });
1220                $("#geo_notours_form .childrens-dropdown__item__delete").each(function(){
1221                    $(this).trigger("click");
1222                });
1223                $(".sucess-link").trigger("click");
1224            }
1225        },
1226        errorClass: "error",
1227        rules: {
1228            name:{
1229                required: true,
1230                minlength: 3,
1231                maxlength: 25
1232            },
1233            email: {
1234                require_from_group: [1, ".phone-email-group-notours"],
1235                email_cyr: true
1236            },
1237            phone: {
1238                require_from_group: [1, ".phone-email-group-notours"],
1239            }
1240        },
1241        messages: {
1242            name:{
1243                required: "Обязательно для заполнения",
1244                minlength: "Минимум 3 символа",
1245                maxlength: "Максимальное число символов - 25"
1246            },
1247            email:{
1248                require_from_group: "Введите телефон или e-mail",
1249                required: "Обязательно для заполнения",
1250                email_cyr: "Введите правильный email адрес"
1251            },
1252            phone: {
1253                require_from_group: "Введите телефон или e-mail",
1254                required: "Обязательно для заполнения"
1255            }
1256        }
1257    });
1258
1259    // Форма заявки при отсутствии туров
1260    if ($("#extended_search_form").length)
1261    $("#extended_search_form").validate({
1262        submitHandler: function (form) {
1263            if (submit_form_callback($("#extended_search_form"))) {
1264                $("#extended_search_form")[0].reset();
1265                $("#extended_search_form select.select2").each(function(){
1266                    $(this).trigger('change.select2');
1267                });
1268                $("#extended_search_form .childrens-dropdown__item__delete").each(function(){
1269                    $(this).trigger("click");
1270                });
1271                $(".sucess-link").trigger("click");
1272            }
1273        },
1274        errorClass: "error",
1275        rules: {
1276            name:{
1277                required: true,
1278                minlength: 3,
1279                maxlength: 25
1280            },
1281            email: {
1282                require_from_group: [1, ".phone-email-group-search"],
1283                email_cyr: true
1284            },
1285            phone: {
1286                require_from_group: [1, ".phone-email-group-search"],
1287            }
1288        },
1289        messages: {
1290            name:{
1291                required: "Обязательно для заполнения",
1292                minlength: "Минимум 3 символа",
1293                maxlength: "Максимальное число символов - 25"
1294            },
1295            email:{
1296                require_from_group: "Введите телефон или e-mail",
1297                required: "Обязательно для заполнения",
1298                email_cyr: "Введите правильный email адрес"
1299            },
1300            phone: {
1301                require_from_group: "Введите телефон или e-mail",
1302                required: "Обязательно для заполнения"
1303            }
1304        }
1305    });
1306
1307    // Кнопка показа комментария
1308    $('.show-comment-link').on('click', function() {
1309        var $form = $(this).parents('form');
1310        var $comment = $form.find('.search-block-comment');
1311        var $wrapper = $(this).parents('.show-comment-wrapper');
1312        $($wrapper).addClass('show-comment-wrapper--hidden');
1313        $($comment).slideToggle(300);
1314        return false;
1315    });
1316    // Скрытие и показ нового блока!!!
1317    $('.button__find-tours').on('click', function() {
1318//        $('.button__find-tours').addClass('button__find-tours--hidden');
1319        $('.search-block__change-param').removeClass('search-block__change-param--hidden');
1320        $('.search-block-full--two-part').removeClass('bottom-hidden');
1321        $('.search-block-full__bottom').slideToggle(300);
1322        if ($('.search-block__change-param').length) {
1323            var changeParamTop = $('.search-block__change-param').offset().top - 80;
1324            $('body,html').stop().animate({
1325                scrollTop: changeParamTop
1326              }, 300);
1327        }
1328        return false;
1329    });
1330
1331    $('.search-block__change-param-link').on('click', function() {
1332//        $('.button__find-tours').removeClass('button__find-tours--hidden');
1333        $('.search-block__change-param').addClass('search-block__change-param--hidden');
1334        $('.search-block-full--two-part').addClass('bottom-hidden');
1335        $('.search-block-full__bottom').slideToggle(300);
1336        return false;
1337    });
1338
1339    // Автостарт поиска
1340    if ($('.search-block input[name=auto_start]').length > 0 && $('.search-block input[name=auto_start]').val() === '1' && !$('.hotels').text()) {
1341        $('.button__find-tours').attr('data-auto-start','1').click();
1342    }
1343
1344    // показать еще курорты
1345    $(".sidebar__block-expand").on('click', '.show-all__link', function(e) {
1346        e.preventDefault();
1347        e.stopPropagation();
1348        $(this).closest(".sidebar__block-expand").find(".list").find(".list__item").each(function(index,element){
1349            if(index>=10) $(this).slideToggle(200);
1350        });
1351        $(this).text($(this).text() == 'Показать еще' ? 'Скрыть' : 'Показать еще');
1352    });
1353
1354
1355    // Обновление списка курортов в поисковых формах при выборе страны
1356    $('select[name=country_sid]').on('change', function() {
1357
1358        var $select = $(this).parents('form').find('select[name=resort_sid]');
1359        $select.find('option').remove();
1360        $select.append('<option value="" selected="selected">Все курорты</option>');
1361
1362        $.get(
1363            '/ajax/search/json_resorts/',
1364            {'country_sid': $(this).val()},
1365            function (data) {
1366                $.each(data, function(key, obj) {
1367                    var option = document.createElement("option");
1368                    option.setAttribute("value", obj.id);
1369                    option.innerText = obj.name;
1370                    $select.append(option);
1371                });
1372            },
1373            'json'
1374        );
1375    });
1376
1377
1378    // Обновление списка отелей в расширенной форме
1379    $('#extended_search_form select[name=country_sid], #extended_search_form select[name=resort_sid], #extended_search_form select[name=stars]').on('change', function() {
1380
1381        var $form = $('#extended_search_form');
1382        var $select = $form.find('ul.search-hotel__list');
1383
1384        $form.find('input[name=hotel_filter]').val('');
1385        $select.find('li').remove();
1386
1387        $.get(
1388            '/ajax/search/json_hotels/', {
1389                'country_sid': $form.find('select[name=country_sid]').val(),
1390                'resort_sid': $form.find('select[name=resort_sid]').val(),
1391                'stars': $form.find('select[name=stars]').val()
1392            },
1393            function (data) {
1394
1395                if (data.length > 2000) {
1396                    $select.html('<li>Чтобы выбрать отели, сперва выберите курорт</li>');
1397                    return;
1398                }
1399                $.each(data, function(key, obj) {
1400                    var li = document.createElement("li");
1401                    li.innerHTML = '<label class="search-hotel__label"><span class="checkbox"><input type="checkbox" name="hotels[]" value="'
1402                        + obj.sletat_id + '" class="search-hotel__check"></span>' + obj.name + '</label>';
1403                    $select.append(li);
1404                });
1405                $select.find('input[type="checkbox"]').each(function(){
1406                    $(this).change(function(){
1407                        if ($(this).is(':checked')) $(this).parent().addClass('checked');
1408                        else $(this).parent().removeClass('checked');
1409                    });
1410                });
1411            },
1412            'json'
1413        );
1414
1415    });
1416
1417    // Поиск по названию отеля (расширенная форма)
1418    $('#extended_search_form input[name=hotel_filter]').on('input', function() {
1419
1420        var search_str = $(this).val().toLowerCase();
1421
1422        /*
1423        if (search_str.length < 3) {
1424            $('.search-hotel__list li').show();
1425            return;
1426        }
1427        */
1428
1429        $('.search-hotel__list li').each(function(){
1430            if ($(this).text().toLowerCase().indexOf(search_str) === -1) {
1431                $(this).find('input[type=checkbox]').prop('checked', false).trigger('change');
1432                $(this).hide();
1433            }
1434            else {
1435                $(this).show();
1436            }
1437        });
1438
1439    });
1440
1441
1442    // Селекты фильтра на страницах со списками отелей
1443    $('#hotels_filter select').on('change', function() {
1444        
1445        location.href = $('option:selected', this).data('url');
1446        
1447        return false;
1448    });
1449
1450
1451    // Загрузка туров на странице отеля
1452    if ($('#hotel_tours').length) {
1453
1454        var $this = $('#hotel_tours');
1455
1456        if ($this.attr('data-url') && $this.attr('data-hotel-sid')) {
1457
1458            // прогресс бар
1459            $('#tour_search_progress').addClass('search-progress--show');
1460            $('#tour_search_time').hide();
1461            $('html, body').stop().animate({
1462                scrollTop: $('#tour_search_progress').offset().top - $('.header__top-menu').height() - 30
1463            }, 500);
1464            var level = 0, v = 0.8, a = 0.005; // позиция (0-99), скорость изменения (позиций за кадр), замедление (позиций/кадр за кадр)
1465            timerId = setInterval(function(){
1466                a += 0.000031; v -= v*a; level += v;
1467                $('#tour_search_progress .search-progress__bar').css('width', level+'%');
1468                $('#tour_search_progress .search-progress__percent').text(Math.round(level) + '%');
1469                if (level > 99) {
1470                    clearInterval(timerId);
1471                }
1472            }, 25);
1473
1474            $.get(
1475                $this.attr('data-url'),
1476                $this.hasClass('js-nocache') ? {hotel_sid: $this.attr('data-hotel-sid'),nocache: 1} : {hotel_sid: $this.attr('data-hotel-sid')},
1477                function(data) {
1478                    if (data) {
1479                        $this.html(data);
1480                        setTimeout(function($this) {
1481                            $this.removeClass('hotels--holder').show();
1482                            $('#geo_notours_form').hide();
1483                        }, 20, $this);
1484                    }
1485                    else {
1486                        $this.hide();
1487                        $('#geo_notours_form').show();
1488                    }
1489                    // clear progrees bar
1490                    clearInterval(timerId);
1491                    $('#tour_search_progress').removeClass('search-progress--show');
1492                },
1493                'html'
1494            );
1495        }
1496    }
1497/*
1498    $(".hotel-rate-reviews").on("click",function(e){
1499        var $dest = $(".tabs-selector[data-tab='reviews']");
1500        if ($dest.length){
1501            e.preventDefault();
1502            e.stopPropagation();
1503            $dest.trigger("click");
1504            $("html,body").stop().animate({scrollTop:$dest.offset().top - $('.header__top-menu').height() - 30},300);
1505            return false;
1506        }
1507    });
1508*/
1509    // Загрузка туров на странице отеля
1510    if ($('.reviews__inner').length) {
1511
1512        (function(){
1513            var $this = $('.reviews__inner');
1514
1515            $.get(
1516                $this.attr('data-url'),
1517                {hotel_sid: $this.attr('data-hotel-sid')},
1518                function(data) {
1519                    if (data) {
1520                        $this.html(data);
1521                    }
1522                },
1523                'html'
1524            );
1525        })();
1526
1527        $(document).on({
1528            "click": function(e){
1529                e.preventDefault();
1530                e.stopPropagation();
1531                var el = $(this);
1532                var targ = el.closest(".reviews");
1533                var text = $(this).text();
1534                if(!targ.length) return;
1535                var tabs = el.closest('.tabs-block').find('.tabs-selector-block');
1536                var tab_index = el.closest(".tabs-content").index();
1537                el.text(text == "Показать еще отзывы" ? "Свернуть" : "Показать еще отзывы");
1538                if(targ.hasClass("active")) {
1539                    if (targ.children(".review").length > 3) {
1540                        if ($(window).scrollTop() > tabs.offset().top - $('.header__top-menu').height() - 5 + $(window).height()) {
1541                            $("html,body").stop().animate({scrollTop:tabs.offset().top - $('.header__top-menu').height() - 5},300);
1542                        }
1543
1544                        targ.children(".review").each(function(index,element) {
1545                            if(index>3) {
1546                                $(this).slideUp(300,function(){
1547                                    targ.removeClass("active");
1548                                    tabs.parent().parent().find('.tab-wrap').css('height', tabs.parent().parent().find('.tab-wrap').children("div").eq(tab_index).height());
1549                                });
1550                            }
1551                        });
1552                    }
1553                } else {
1554                    targ.children(".review").each(function(index,element) {
1555                        $(this).slideDown(300,function(){
1556                            targ.addClass("active");
1557                            tabs.parent().parent().find('.tab-wrap').css('height', tabs.parent().parent().find('.tab-wrap').children("div").eq(tab_index).height());
1558                        });
1559                    });
1560                }
1561            }
1562        }, ".reviews__all");
1563
1564        //full review
1565        $(document).on({
1566            "click": function(e){
1567                e.preventDefault();
1568                e.stopPropagation();
1569                if ($(this).closest(".review").find(".review__text-full").length) {
1570                    var tabs = $(this).closest('.tabs-block').find('.tabs-selector-block');
1571                    var tab_index = $(this).closest(".tabs-content").index();
1572                    if ($(this).text() === 'Читать полностью') {
1573                        $(this).text('Свернуть');
1574                    }
1575                    else {
1576                        $(this).text('Читать полностью');
1577                    }
1578                    $(this).closest(".review").find(".review__text-full").slideToggle(200,function() {
1579                        tabs.parent().parent().find('.tab-wrap').css('height', tabs.parent().parent().find('.tab-wrap').children("div").eq(tab_index).height());
1580                    });
1581                    $(this).closest(".review").find(".review__text").toggle();
1582
1583                    if ($(this).text() === 'Читать полностью' && $(window).scrollTop() > $(this).closest(".review").offset().top - $('.header__top-menu').height() - 5) {
1584                        $("html,body").stop().animate({scrollTop:$(this).closest(".review").offset().top - $('.header__top-menu').height() - 5},100);
1585                    }
1586                }
1587            }
1588        }, ".reviews__inner .review__link");
1589    }
1590
1591    // Показать больше туров на странице отелей
1592/*
1593    $('#hotel_tours').on('click', '.show-all__link', function() {
1594
1595        $('.other-tours__row:hidden:lt(5)').show();
1596
1597        if ( ! $('.other-tours__row:hidden').length) {
1598            $('.show-all__link').hide();
1599        }
1600
1601        return false;
1602    });
1603*/
1604    // Подгрузка новостей в разделе Новости
1605    $('.news-block .show-all__news .button').click(function(){
1606        if ($(this).closest('.show-all__news').hasClass('disabled')) return false;
1607
1608        var $this = $(this), $holder = $this.closest('.show-all__news');
1609        $holder.addClass('disabled');
1610
1611        $.ajax({
1612            url: '/ajax/news/',
1613            data: 'offset=' + $(this).attr('data-offset'),
1614            cache: false,
1615            dataType: 'json',
1616            timeout: 10000,
1617            type: 'post',
1618            error: function(xhr,status,err) {
1619                console.log(status || err ? ('Ошибка списка новостей: ' + (status ? status + (status && err ? ' / ' : '') : '')) + (err ? err : '') : 'Неизвестная ошибка списка новостей');
1620                $holder.removeClass('disabled');
1621            },
1622            success: function(data) {
1623                if (data['err']) console.log('Ошибка списка новостей: ' + data['err']);
1624                else
1625                {
1626                    if (data['html']){
1627                        $holder.closest('.news-block').find('.news-block__row').append(data['html']);
1628                    }
1629                    $this.attr('data-offset', data['offset']);
1630                    if (!data['more']) $holder.fadeOut();
1631                }
1632                $holder.removeClass('disabled');
1633            }
1634        });
1635
1636        return false;
1637    });
1638
1639    $(document).on({
1640        'click': function(){
1641            var t = $(this).closest('.hotel-block').find('.short-other');
1642            if (t.is(':hidden')){
1643                t.stop().slideDown(300,function(){
1644                    $(this).closest('.hotel-block').addClass('hotel-block--active');
1645                });
1646            }
1647            else{
1648                $(this).closest('.hotel-block').addClass('hotel-block--active');
1649            }
1650
1651            return false;
1652        }
1653    },'.hotel-block__show-other');
1654    $(document).on({
1655        'click': function(){
1656            var t = $(this).closest('.hotel-block').find('.short-other');
1657            if (t.is(':visible')){
1658                t.stop().slideUp(300,function(){
1659                    $(this).closest('.hotel-block').removeClass('hotel-block--active');
1660                });
1661            }
1662            else{
1663                $(this).closest('.hotel-block').removeClass('hotel-block--active');
1664            }
1665
1666            return false;
1667        }
1668    },'.hotel-block__hide-other');
1669
1670    $(document).on({
1671        'click': function(){
1672            var $root = $(this).closest('.expand-block__item'),$cont = $root.find('.expand-block__content');
1673            if ($cont.length){
1674                if ($cont.is(':visible')){
1675                    $cont.stop().slideUp(300,function(){
1676                        $cont.css('z-index','');
1677                        $root.removeClass('opened');
1678                    });
1679                }
1680                else{
1681                    var z = 0;
1682                    $('.expand-block__content:visible').each(function(){
1683                        var $this = $(this);
1684                        if ($this.css('z-index') > z) z = $this.css('z-index');
1685                        $this.stop().slideUp(300,function(){
1686                            $this.css('z-index','');
1687                            $this.closest('.expand-block__item').removeClass('opened');
1688                        });
1689                    });
1690                    $cont.css('z-index',z + 1).stop().slideDown(300,function(){
1691                        $root.addClass('opened');
1692                    });
1693                }
1694
1695                return false;
1696            }
1697        },
1698    },'.expand-block__button');
1699    $(document).on('click', function(e){
1700        var $cont = $(e.target);
1701        if ($cont.hasClass('expand-block__item') || $cont.closest('.expand-block__item').length) return;
1702        $cont = $('.expand-block__item .expand-block__content:visible');
1703        $cont.each(function(){
1704            $(this).closest('.expand-block__item').find('.expand-block__button').trigger('click');
1705        });
1706    });
1707
1708
1709    $(document).on({
1710        'click': function(){
1711            var t = $(this).parent().find('.kids__dropdown');
1712            $(this).find('.input__kids').addClass('active');
1713            t.slideDown(200);
1714        }
1715    },'.input__kids');
1716
1717    $("body").on('click', function (e) {
1718        if ($(e.target).closest('.kids__dropdown').length == 0) {
1719            $('.kids__dropdown').slideUp(100);
1720            $('.input__kids').removeClass('active');
1721        }
1722    });
1723
1724    $(document).on({
1725        'click': function(){
1726            var $el = $(this).closest('.search-block__child').find('.input__kids ');
1727            $el.closest('.search-block__child').find('.select2').css('display','block');
1728            $(this).parent().remove();
1729            $el.val($el.closest('form').find('input[name="ages[]"]').length);
1730        }
1731    },'.childrens-dropdown__item__delete');
1732
1733
1734    $(window).resize(function() {
1735        checkResize();
1736    });
1737    window.onorientationchange = function() {
1738        checkResize();
1739    };
1740    checkResize();
1741
1742
1743    $(document).on({
1744        'change': function(){
1745            $(this).closest('form').find('input.nullable[name="hotels[]"]').each(function(){
1746                $(this).remove();
1747            });
1748        }
1749    }, 'select[name="resort_sid"]');
1750    $(document).on({
1751        'change': function(){
1752            $(this).closest('form').find('input.nights.nullable').each(function(){
1753                $(this).val('');
1754            });
1755        }
1756    }, 'select[name="nights"]');
1757
1758}); // $(document).ready()
1759
1760
1761function checkResize (){
1762    var browserMaxWidth = parseInt($('head').css('max-width'), 10);
1763    if(browserMaxWidth<=1100) {
1764        $(".steps-form__sidebar").addClass("steps-form__sidebar-mobile").addClass("steps-form__main").removeClass("steps-form__sidebar");
1765    } else {
1766        $(".steps-form__sidebar-mobile").addClass("steps-form__sidebar").removeClass("steps-form__main").removeClass("steps-form__sidebar-mobile");
1767    }
1768
1769    if(browserMaxWidth<=1190) {
1770        $(".nav-block").addClass("nav-block-mobile");
1771    } else {
1772        $(".nav-block").removeClass("nav-block-mobile").removeAttr("style");
1773        $(".mobile-menu-button").removeClass("active").removeAttr("style");
1774    }
1775
1776    if (browserMaxWidth <= 800) {
1777      datepicker_count = $(".single_date").datepicker("option", "numberOfMonths");
1778      if (datepicker_count > 1) {
1779       $(".single_date").datepicker("option", { numberOfMonths: 1 });
1780       dpOpts['numberOfMonths'] = 1;
1781      }
1782    } else {
1783      datepicker_count = $(".single_date").datepicker("option", "numberOfMonths");
1784      if (datepicker_count == 1) {
1785        $(".single_date").datepicker("option", { numberOfMonths: 2 });
1786        dpOpts['numberOfMonths'] = 2;
1787      }
1788    }
1789    if (browserMaxWidth <= 650) {
1790      if ($('.album-slider--desktop').hasClass("slick-slider")) $('.album-slider--desktop').slick('unslick');
1791      if($('.album-slider--mobile').length & !$('.album-slider--mobile').hasClass("slick-slider")) {
1792        $('.album-slider--mobile').slick({
1793            dots: false,
1794            arrows: true,
1795            infinite: true,
1796            fade: true,
1797            speed: 500,
1798            slidesToShow: 1,
1799            adaptiveHeight: true,
1800            prevArrow: '<a href="#" class="show-all__prev"><span class="icon icon__left-arrow"></span></a>',
1801            nextArrow: '<a href="#" class="show-all__next"><span class="icon icon__right-arrow"></span></a>'
1802        });
1803        }
1804
1805    } else {
1806        if($('.album-slider--desktop').length & !$('.album-slider--desktop').hasClass("slick-slider")) {
1807        $('.album-slider--desktop').slick({
1808            dots: false,
1809            arrows: true,
1810            infinite: true,
1811            fade: true,
1812            speed: 500,
1813            slidesToShow: 1,
1814            adaptiveHeight: true,
1815            prevArrow: '<a href="#" class="show-all__prev"><span class="icon icon__left-arrow"></span></a>',
1816            nextArrow: '<a href="#" class="show-all__next"><span class="icon icon__right-arrow"></span></a>'
1817        });
1818    }
1819      if ($('.album-slider--mobile').hasClass("slick-slider")) $('.album-slider--mobile').slick('unslick');
1820    }
1821}
1822function formProgress($frm,prc,dur){
1823    var t = $frm.closest('.form-holder').find('.form-progress');
1824    if (t.length){
1825        $frm.closest('.form-holder').find('.form-not-found:visible').hide();
1826        prc = parseInt(prc);
1827        if (isNaN(prc) || prc < 0) prc = 0;
1828        else if (prc > 100) prc = 100;
1829        dur = parseInt(dur);
1830        if (isNaN(dur) || dur < 0) dur = 1000;
1831        if (t.is(':visible')){
1832            var $counter = t.find('.form-progress-counter');
1833            t.find('.form-progress-bar').stop().animate({'width':prc + '%'},{
1834                'duration':dur,
1835                'step':function(now,fx){
1836                    $counter.text(Math.round(now) + '%');
1837                },
1838                'complete':function(){
1839                    $counter.text(prc + '%');
1840                }
1841            });
1842        }
1843        else{
1844            t.find('.form-progress-bar').css('width',prc + '%');
1845            t.stop().slideDown(200).find('.form-progress-counter').text(prc + '%');
1846        }
1847    }
1848}
1849function formNotFound($frm,to){
1850    var t = $frm.closest('.form-holder').find('.form-not-found');
1851    if (t.length){
1852        $frm.closest('.form-holder').find('.form-progress:visible').hide();
1853        to = parseInt(to);
1854        if (isNaN(to) || to < 0) to = 0;
1855
1856        if (to){
1857            if (t.is(':hidden')) t.stop().slideDown();
1858            window.setTimeout(function(){
1859                if (t.is(':visible')) t.stop().slideUp();
1860            },to * 1000);
1861        }
1862        else{
1863            t.stop().slideToggle();
1864        }
1865    }
1866}
1867function autocompleteCityVal($el){
1868    var $this = $el,
1869        $root = $this.closest('.js-autocomplete'),
1870        $value = $root.find('.autocomplete-value'),
1871        $thisval = $this.val(),
1872        $valhtml = $value.html(),
1873        $thisplace = $this.attr('placeholder');
1874    if (!$this.is(':focus')){
1875        if ($thisval){
1876            if ($valhtml != $thisplace && $thisval != $valhtml) $this.val($valhtml);
1877        }
1878        else{
1879            $value.html($thisplace).closest('.autocomplete-result').removeClass('flag');
1880            $root.find('input[type="hidden"]').val('');
1881        }
1882    }
1883}
1884function initSelect2($el){
1885    if ($el.closest('.stars-content').length){
1886        $el.select2({
1887            minimumResultsForSearch: Infinity,
1888            dropdownCssClass: 'select2-drop stars-drop',
1889            templateResult: select2FormatState
1890        }).on('select2:opening',function(){
1891            $el.closest('.stars-content').addClass('select2-open');
1892        }).on('select2:open',function(){
1893            var t = $el.closest('.stars-content').find('.stars-dropdown');
1894            if (t.length){
1895                $('.select2-drop.stars-drop').html(t.html());
1896                t = $el.val() || 0;
1897                for (var x = 0; x < 5; x++){
1898                    if (x < t) $('.select2-drop .stars-select .icon__star:eq(' + x + ')').addClass('active');
1899                    else $('.select2-drop .stars-select .icon__star:eq(' + x + ')').removeClass('active');
1900                }
1901            }
1902        }).on('select2:closing',function(){
1903            $el.closest('.stars-content').removeClass('select2-open');
1904        });
1905        if (parseInt($el.val())){
1906            $el.closest('.stars-content').addClass('show-star');
1907        }
1908        else{
1909            $el.closest('.stars-content').removeClass('show-star');
1910        }
1911    }
1912    else if ($el.closest('.search-block__child').length && $el.closest('#mainpage_search_form, #sletat_search_form, #geo_notours_form').length){
1913        $el.select2({
1914            minimumResultsForSearch: Infinity,
1915            dropdownCssClass: 'select2-drop select2-filter',
1916            templateResult: select2FormatState
1917        }).on('select2:select',function(e){
1918            var data = e.params.data;
1919            var $cont = $el.closest('.kids__dropdown');
1920            var $main = $cont.parent().find('.input__kids');
1921
1922            if(1||data['id']!=0) {
1923                $cont.prepend(
1924                    '<div class="childrens-dropdown__item input">' +
1925                    '<div class="childrens-dropdown__item__txt">' +
1926                    '<input type="hidden" name="ages[]" value="' + data['id'] + '">' +
1927                    data['text'] +
1928                    '</div>' +
1929                    '<div class="childrens-dropdown__item__delete"></div>' +
1930                    '</div>');
1931            }
1932            if ($cont.find('div.childrens-dropdown__item.input').length > 2){
1933                $cont.find('.select2:not(.select2-hidden-accessible)').css('display','none');
1934            }
1935
1936            $main.val($main.closest('form').find('input[name="ages[]"]').length);
1937            $el.val(0).trigger('change');
1938
1939        });
1940    }
1941    else if ($el.closest('.input-filter').length){
1942        $el.select2({
1943            minimumResultsForSearch: Infinity,
1944            dropdownCssClass: 'select2-drop select2-filter',
1945            templateResult: select2FormatState
1946        });
1947    }
1948    else if ($el.closest('.input-content-children-range').length){
1949        $el.select2({
1950            minimumResultsForSearch: Infinity,
1951            dropdownCssClass: 'select2-drop select2-drop-short',
1952            templateResult: select2FormatState
1953        }).on('select2:select',function(e){
1954            if (!$el.hasClass('js-age-select')) return;
1955            var $form = $el.closest('form');
1956            if ($el.hasClass('error')){
1957                $el.removeClass('error').next('.select2-container').removeClass('error');
1958                if (!$form.find('.js-age-select.error').length) $form.find('.js-ages-label').removeClass('error-text');
1959            }
1960        });
1961    }
1962    else if ($el.closest('.search-block__input-label').length){
1963        $el.select2({
1964            minimumResultsForSearch: Infinity,
1965            dropdownCssClass: 'select2-drop select2-drop-small select2-drop-label',
1966            templateResult: select2FormatState
1967        });
1968    }
1969    else{
1970        $el.select2({
1971            minimumResultsForSearch: Infinity,
1972            dropdownCssClass: 'select2-drop',
1973            templateResult: select2FormatState
1974        });
1975    }
1976}
1977function select2FormatState(state) {
1978
1979    var flag = $(state.element).attr('data-flag');
1980    return flag ? $('<div class="select2-country"><span class="select2-country-flag" title="' + state.text + '" style="background-image:url(' + flag + ');"></span><span class="select2-name">' + state.text + '</span></div>') : state.text;
1981}
1982function initDatepicker($el){
1983    $el.datepicker(dpOpts);
1984}
1985function initSlick(){
1986    if($('.tour-slider:not(.slick-initialized)').length) {
1987        $('.tour-slider:not(.slick-initialized)').slick({
1988            dots: false,
1989            arrows: true,
1990            infinite: true,
1991            speed: 500,
1992            slidesToShow: 1,
1993            adaptiveHeight: false,
1994            prevArrow: '<div class="photo__controls hotel-block__photo-controls photo__controls-left"></div>',
1995            nextArrow: '<div class="photo__controls hotel-block__photo-controls photo__controls-right"></div>'
1996        });
1997    }
1998    if($('.hotel-slider:not(.slick-initialized)').length) {
1999        $('.hotel-slider:not(.slick-initialized)').slick({
2000            dots: false,
2001            arrows: true,
2002            infinite: true,
2003            speed: 500,
2004            slidesToShow: 1,
2005            adaptiveHeight: false,
2006            prevArrow: '<div class="photo__controls hotel-block__photo-controls photo__controls-left"></div>',
2007            nextArrow: '<div class="photo__controls hotel-block__photo-controls photo__controls-right"></div>'
2008        });
2009    }
2010}
2011function initOrangeForm($frm){
2012    if (!$frm.hasClass('valid_set')){
2013        $frm.addClass('valid_set');
2014        $frm.validate({
2015            submitHandler: function (form) {
2016                var result = submit_form_callback($(form));
2017                if (result === true) {
2018                    $(form)[0].reset();
2019                    if ($(form).find("input[name='form_id'][value='help_form']").length){
2020                        $(".success-link.help_form").trigger("click");
2021                    }
2022                    else{
2023                        $(".sucess-link1").trigger("click");
2024                    }
2025                }
2026            },
2027            errorClass: "error",
2028            rules: {
2029                name:{
2030                    required: true,
2031                    minlength: 3,
2032                    maxlength: 25
2033                },
2034                email: {
2035                    require_from_group: [1, ".phone-email-group-orange"],
2036                    email_cyr: true
2037                },
2038                phone: {
2039                    require_from_group: [1, ".phone-email-group-orange"]
2040                }
2041            },
2042            messages: {
2043                name:{
2044                    required: "Обязательно для заполнения",
2045                    minlength: "Минимум 3 символа",
2046                    maxlength: "Максимальное число символов - 25"
2047                },
2048                email:{
2049                    require_from_group: "Введите телефон или e-mail",
2050                    email_cyr: "Введите правильный email адрес"
2051                },
2052                phone: {
2053                    require_from_group: "Введите телефон или e-mail",
2054                }
2055            }
2056        });
2057    }
2058}
2059
2060/**
2061 * Submits a form via ajax
2062 * @param {jQuery} $form
2063 * @returns {Boolean} Validation status
2064 */
2065function submit_form_callback($form) {
2066
2067    $comagic_form = $form;
2068
2069    if ($form.valid()) {
2070        if ($form.find('input[name="cb-result"]').length) {
2071            if (typeof(Comagic) == 'object'){
2072                $form.find('[type="submit"]').prop('disabled',true);
2073                $form.attr('data-comagic-fail',null);
2074                Comagic.sitePhoneCall({phone: $form.find('input[name=phone]').val()}
2074, callbackphone);
2075                $form.attr('data-comagic-timeout',window.setTimeout(function(){
2076                    alert('Comagic callback error');
2077                    $form.attr('data-comagic-fail','1');
2078                    $form.removeClass('js-disabled').find('[type="submit"]').prop('disabled',false);
2079                    $form.find('.js-submit-btn').each(function() {
2080                        if (this.tagName.toLowerCase() == 'input' || this.tagName.toLowerCase() == 'button') $(this).prop('disabled',false);
2081                        else $(this).removeClass('disabled');
2082                    });
2083                }, 20000));
2084            }
2085            else {
2086                alert('Comagic init error');
2087            }
2088        }
2089        else {
2090            $form.addClass('js-disabled').find('[type="submit"]').prop('disabled',true);
2091            $form.find('.js-submit-btn').each(function() {
2092                if (this.tagName.toLowerCase() == 'input' || this.tagName.toLowerCase() == 'button') $(this).prop('disabled',true);
2093                else $(this).addClass('disabled');
2094            });
2095            send_form_callback($form);
2096        }
2097    }
2098    return false;
2099
2100}
2101
2102// Callback from comagic
2103function callbackphone(obj){
2104    window.clearTimeout($comagic_form.attr('data-comagic-timeout'));
2105    if ($comagic_form.attr('data-comagic-fail')) {
2106        $comagic_form.attr('data-comagic-fail',null);
2107        return false;
2108    }
2109    $comagic_form.find('input[name="cb-result"]').val(obj['success'] ? 'Success' : 'Fail');
2110    $comagic_form.find('input[name="cb-status"]').val(obj['result'] ? obj['result']['status'] : 'No data');
2111    send_form_callback($comagic_form);
2112}
2113
2114// Send callback form
2115function send_form_callback($form) {
2116
2117    var recaptchav3 = $('#recaptchav3'), gtoken;
2118
2119    if (recaptchav3.length) {
2120        gtoken = $form.find('[name="gtoken"]');
2121        if (gtoken.length && !gtoken.val()) {
2122            setTimeout(function() { send_form_callback($form); }, 500);
2123            return false;
2124        }
2125
2126        if (!gtoken.length) {
2127            gtoken = $('<input type="hidden" name="gtoken">').appendTo($form);
2128
2129            grecaptcha.ready(function(){
2130                grecaptcha.execute(recaptchav3.attr('data-key'), {action: 'submit'}).then(function(token) {
2131                    gtoken.val(token);
2132                });
2133            });
2134
2135            setTimeout(function() { send_form_callback($form); }, 500);
2136            return false;
2137        }
2138    }
2139
2140    var formData = $form.serializeArray(), goal = $form.attr('data-goal'), yaCtr, x;
2141    formData.push({"name" : "url", "value" : window.location.href});
2142    if (recaptchav3.length && gtoken) gtoken.remove();
2143
2144    if (goal) {
2145        for (x in window) if (x.substr(0,9) == 'yaCounter') yaCtr = window[x];
2146        if (typeof(yaCtr) == 'object') {
2147            yaCtr.reachGoal(goal);
2148        }
2149    }
2150
2151    $.post(
2152        $form.attr('action'),  formData,  function( data ) {
2153            $form[0].reset();
2154            var success = $form.attr('data-success');
2155            if (success == 'steps') {
2156                window.setTimeout(function(){ $form.find('select[name="country"]').trigger('change'); },100);
2157                p_get_prev_step();
2158                p_step+=1;
2159                p_next_step();
2160            }
2161            else if (success == 'geo_notours_form') {
2162                $("#geo_notours_form")[0].reset();
2163                $("#geo_notours_form select.select2").each(function(){
2164                    $(this).trigger('change.select2');
2165                });
2166                $("#geo_notours_form .childrens-dropdown__item__delete").each(function(){
2167                    $(this).trigger("click");
2168                });
2169                $(".success-link:first").trigger("click");
2170            }
2171            else if ($form.find("input[name='form_id'][value='help_form']").length) {
2172                $(".success-link.help_form").trigger("click");
2173            }
2174            else {
2175                $.fancybox.close(true);
2176                $(".success-link" + (success ? "." + success : "") + ":first").trigger("click");
2177            }
2178            $form.removeClass('js-disabled').find('[type="submit"]').prop('disabled',false);
2179            $form.find('.js-submit-btn').each(function() {
2180                if (this.tagName.toLowerCase() == 'input' || this.tagName.toLowerCase() == 'button') $(this).prop('disabled',false);
2181                else $(this).removeClass('disabled');
2182            });
2183        }, 'json'
2184    ).fail(function( $xhr ) {
2185        alert( 'Ajax error: ' + ( $xhr.responseJSON ? $xhr.responseJSON.error : ( $xhr.statusText ? $xhr.statusText : $xhr.responseText ) ) );
2186        $form.removeClass('js-disabled').find('[type="submit"]').prop('disabled',false);
2187        $form.find('.js-submit-btn').each(function() {
2188            if (this.tagName.toLowerCase() == 'input' || this.tagName.toLowerCase() == 'button') $(this).prop('disabled',false);
2189            else $(this).removeClass('disabled');
2190        });
2191    });
2192}
2193
2194var step=1;
2195var prev_slide;
2196
2197function get_prev_step($block) {
2198    $block.find('.steps-form__slide').each(function(index, element){
2199        if(step == $(element).attr("slide_num")) prev_slide = $(element) ;
2200    });
2201}
2202
2203function next_step($block) {
2204    switch(step) {
2205      case 4:
2206        $block.find(".steps").fadeOut(300);
2207        $block.find(".steps-form__h3").fadeOut(300);
2208        prev_slide.fadeOut(300, function(){
2209            $block.find('.steps-form__slide--4').fadeIn(300, function(){$block.removeClass("disabled");});
2210        });
2211        break;
2212
2213      case 3:
2214        prev_slide.fadeOut(300, function(){
2215            $block.find('.steps-form__slide--3').fadeIn(300, function(){$block.removeClass("disabled");});
2216            $block.find(".steps").removeClass("steps--1 steps--2").addClass("steps--3");
2217        });
2218        break;
2219
2220      case 2:
2221        prev_slide.fadeOut(300, function(){
2222            $block.find('.steps-form__slide--2').fadeIn(300, function(){$block.removeClass("disabled");});
2223            $block.find(".steps").removeClass("steps--1 steps--3").addClass("steps--2");
2224        });
2225        break;
2226
2227      default:
2228        prev_slide.fadeOut(300, function(){
2229            $block.find('.steps-form__slide--1').fadeIn(300, function(){$block.removeClass("disabled");});
2230            $block.find(".steps").removeClass("steps--2 steps--3").addClass("steps--1");
2231        });
2232        break;
2233    }
2234}
2235
2236var p_step=1;
2237var p_prev_slide;
2238function popup_check() {
2239    var $form = $(".popup-steps form");
2240    if ($form.hasClass('js-disabled')) return;
2241    if (submit_form_callback($form)) {
2242        $(".popup-steps").addClass("disabled");
2243    }
2244}
2245
2246function p_get_prev_step() {
2247    $('.popup-steps__slide').each(function(index, element){
2248        if(p_step == $(element).attr("slide_num")) p_prev_slide = $(element) ;
2249    });
2250}
2251
2252function p_next_step() {
2253    switch(p_step) {
2254      case 5:
2255        $(".popup-steps__steps").fadeOut(300);
2256        $(".popup-steps__controls").fadeOut(300);
2257        p_prev_slide.fadeOut(300, function(){
2258            $('.popup-steps__slide5').fadeIn(300, function(){$(".popup-steps").removeClass("disabled");});
2259        });
2260        break;
2261
2262      case 4:
2263        p_prev_slide.fadeOut(300, function(){
2264            $('.popup-steps__slide4').fadeIn(300, function(){$(".popup-steps").removeClass("disabled");});
2265            $('.popup-steps-prev').fadeIn(300);
2266            $(".popup-steps__steps").removeClass("steps--1").removeClass("steps--2").removeClass("steps--3").addClass("steps--4");
2267        });
2268        break;
2269
2270      case 3:
2271        p_prev_slide.fadeOut(300, function(){
2272            $('.popup-steps__slide3').fadeIn(300, function(){$(".popup-steps").removeClass("disabled");});
2273            $('.popup-steps-prev').fadeIn(300);
2274            $(".popup-steps__steps").removeClass("steps--1").removeClass("steps--2").removeClass("steps--4").addClass("steps--3");
2275        });
2276        break;
2277
2278      case 2:
2279        p_prev_slide.fadeOut(300, function(){
2280            $('.popup-steps__slide2').fadeIn(300, function(){$(".popup-steps").removeClass("disabled");});
2281            $('.popup-steps-prev').fadeIn(300);
2282            $(".popup-steps__steps").removeClass("steps--1").removeClass("steps--3").removeClass("steps--4").addClass("steps--2");
2283
2284        });
2285        break;
2286
2287      default:
2288        p_prev_slide.fadeOut(300, function(){
2289            $('.popup-steps__slide1').fadeIn(300, function(){$(".popup-steps").removeClass("disabled");});
2290            $(".popup-steps__steps").removeClass("steps--2").removeClass("steps--3").removeClass("steps--4").addClass("steps--1");
2291            $('.popup-steps-prev').fadeOut(300);
2292            $('.popup-steps__slide5').fadeOut(300);
2293            $(".popup-steps__steps").fadeIn(300);
2294            $(".popup-steps__controls").fadeIn(300);
2295        });
2296        break;
2297    }
2298}
2299
2300function addFav() {
2301    var isWebkit, isMac;
2302    var UA = navigator.userAgent.toLowerCase();
2303    var title = document.title;
2304    var url = document.location;
2305
2306    // Webkit (Chrome, Opera), Mac
2307    if ( (isMac = (UA.indexOf('mac') != -1)) || (isWebkit = (UA.indexOf('webkit') != -1)) ){
2308        alert('Нажмите "' + (isMac ? 'Command/Cmd' : 'Ctrl') + ' + D" для добавления страницы в закладки');
2309        return false;
2310    }
2311
2312    // IE
2313    if (window.external) {
2314        window.external.AddFavorite(url, title);
2315        return false;
2316    }
2317
2318
2319    return false;
2320}

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.