PageSourceSearch

https://boatcharter.fo/wp-content/themes/wprentals/js/control.js?ver=1.0

js boatcharter.fo collected 2026-10-08 21:28:05 UTC 172,597 bytes, 5,258 lines download raw bytes

1/*global $, jQuery, ajaxcalls_vars, document, control_vars, window, map, setTimeout, Modernizr, Blazy, location, google, options, wprentals_show_pins, wpestate_show_login_form, adv_search_click, wpestate_restart_js_after_ajax,start_filtering_ajax,  start_filtering_ajax_map, wpestate_toggleStreetView, wpestate_show_capture, wpestate_new_open_close_map*/
2var has_transparent = 0;
3var componentForm; 
4var price_array;
5var my_custom_curr_symbol = wprentals_getCookie("my_custom_curr_symbol");
6var my_custom_curr_coef = parseFloat(
7  wprentals_getCookie("my_custom_curr_coef"),
8  10
9);
10var my_custom_curr_pos = parseFloat(
11  wprentals_getCookie("my_custom_curr_pos"),
12  10
13);
14var my_custom_curr_cur_post = wprentals_getCookie("my_custom_curr_cur_post");
15var my_custom_curr_label = wprentals_getCookie("my_custom_curr");
16var my_custom_curr_symbol2 = decodeURIComponent(
17  wprentals_getCookie("my_custom_curr_symbol2")
18);
19var login_modal_type = 1;
20var scroll_trigger = 0;
21var show_daterange_picker_custom_mess = "no";
22
23const longmonths = Array.from({ length: 12 }, (_, m) =>
24  new Date(2019, m, 1).toLocaleString(control_vars.datepick_lang, {
25    month: "long",
26  })
27);
28const dayNamesShort_long = Array.from({ length: 7 }, (_, d) =>
29  new Date(2019, 6, d).toLocaleString(control_vars.datepick_lang, {
30    weekday: "short",
31  })
32);
33const dayNamesShort = new Array();
34
35dayNamesShort_long.forEach(wpestate_trim_daynames);
36function wpestate_trim_daynames(value) {
37  dayNamesShort.push(value.substring(0, 2));
38}
39
40jQuery(window).bind("load", function () {
41  wpestate_lazy_load_carousel_property_unit();
42});
43
44function wprentals_getCookie(cname) {
45  "use strict";
46  var name, ca, i, c;
47  name = cname + "=";
48  ca = document.cookie.split(";");
49  for (i = 0; i < ca.length; i = i + 1) {
50    c = ca[i];
51    while (c.charAt(0) === " ") c = c.substring(1);
52    if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
53  }
54  return "";
55}
56
57function wprentals_splash_slider() {
58  "use strict";
59  if (jQuery("#splash_slider_wrapper").length > 0) {
60  }
61}
62
63(function ($) {
64  "use strict";
65  $.fn.nodoubletapzoom = function () {
66    $(this).bind("touchstart", function preventZoom(e) {
67      var t2 = e.timeStamp,
68        t1 = $(this).data("lastTouch") || t2,
69        dt = t2 - t1,
70        fingers = e.originalEvent.touches.length;
71      $(this).data("lastTouch", t2);
72      if (!dt || dt > 500 || fingers > 1) return; // not double-tap
73
74      e.preventDefault(); // double tap - prevent the zoom
75      // also synthesize click events we just swallowed up
76      $(this).trigger("click").trigger("click");
77    });
78  };
79})(jQuery);
80
81var widgetId1, widgetId2, widgetId3, widgetId4;
82
83var wpestate_onloadCallback = function () {
84  "use strict";
85  // Renders the HTML element with id 'example1' as a reCAPTCHA widget.
86  // The id of the reCAPTCHA widget is assigned to 'widgetId1'.
87
88  if (document.getElementById("capthca_register")) {
89    widgetId1 = grecaptcha.render("capthca_register", {
90      sitekey: control_vars.captchakey,
91      theme: "light",
92    });
93    grecaptcha.reset();
94  }
95
96  if (document.getElementById("mobile_register_menu")) {
97    widgetId2 = grecaptcha.render("mobile_register_menu", {
98      sitekey: control_vars.captchakey,
99      theme: "light",
100    });
101  }
102
103  if (document.getElementById("widget_register_menu")) {
104    widgetId3 = grecaptcha.render("widget_register_menu", {
105      sitekey: control_vars.captchakey,
106      theme: "light",
107    });
108  }
109
110  if (document.getElementById("capthca_register_sh")) {
111    widgetId4 = grecaptcha.render("capthca_register_sh", {
112      sitekey: control_vars.captchakey,
113      theme: "light",
114    });
115  }
116};
117
118jQuery(window).scroll(function ($) {
119  "use strict";
120  var scroll = jQuery(window).scrollTop();
121
122  if (control_vars.stiky_search === "yes") {
123    wpestate_adv_search_sticky(scroll);
124  } else {
125    wpestate_header_sticky(scroll);
126  }
127});
128
129function wpestate_header_sticky(scroll) {
130  "use strict";
131  if (scroll >= 10) {
132    if (!Modernizr.mq("only all and (max-width: 1025px)")) {
133      jQuery(".logo").addClass("miclogo");
134
135      if (!jQuery(".header_wrapper").hasClass("is_half_map")) {
136        jQuery(".header_wrapper").addClass("navbar-fixed-top");
137        jQuery(".master_header").addClass("navbar-fixed-top-master");
138        jQuery(".header_wrapper").addClass("customnav");
139
140        if (jQuery(".header_wrapper").hasClass("transparent_header")) {
141          has_transparent = 1;
142          jQuery(".header_wrapper").removeClass("transparent_header");
143          if (control_vars.transparent_logo !== "") {
144            if (control_vars.normal_logo !== "") {
145              jQuery(".logo img").attr("src", control_vars.normal_logo);
146            } else {
147              jQuery(".logo img").attr(
148                "src",
149                control_vars.path + "/img/logo.png"
150              );
151            }
152          }
153        }
154      }
155
156      jQuery(".barlogo").show();
157      jQuery("#user_menu_open").hide();
158      jQuery("#wpestate_header_shoping_cart").hide();
159    }
160    jQuery(".backtop").addClass("islive");
161  } else {
162    jQuery(".header_wrapper").removeClass("navbar-fixed-top");
163    jQuery(".master_header").removeClass("navbar-fixed-top-master");
164    jQuery(".header_wrapper").removeClass("customnav");
165
166    if (has_transparent === 1) {
167      jQuery(".header_wrapper").addClass("transparent_header");
168      if (control_vars.transparent_logo !== "") {
169        jQuery(".logo img").attr("src", control_vars.transparent_logo);
170      }
171    }
172
173    jQuery(".backtop").removeClass("islive");
174    jQuery(".contactformwrapper").addClass("hidden");
175    jQuery(".barlogo").hide();
176    jQuery("#user_menu_open").hide();
177    jQuery("#wpestate_header_shoping_cart").hide();
178    jQuery(".logo").removeClass("miclogo");
179  }
180}
181
182function wpestate_adv_search_sticky(scroll) {
183  "use strict";
184
185  if (scroll > 20) {
186    if (jQuery(".has_header_type4").length <= 0) {
187      if (jQuery(".estate_property-template-default").length === 0) {
188        jQuery(".master_header").hide();
189      }
190    } else {
191      jQuery(".top_bar_wrapper").hide();
192    }
193  } else {
194    jQuery(".master_header,.top_bar_wrapper").show();
195  }
196
197  if (wpestate_isScrolledIntoView(scroll) && scroll_trigger === 0) {
198    // jQuery('#search_wrapper').addClass('sticky_adv');
199  }
200
201  if (scroll_trigger !== 0) {
202    if (scroll < scroll_trigger) {
203      jQuery("#search_wrapper")
204        .removeClass("sticky_adv")
205        .removeClass("sticky_adv_anime");
206    } else if (scroll > scroll_trigger - 40 && scroll < scroll_trigger + 100) {
207      jQuery("#search_wrapper").addClass("sticky_adv_anime");
208    } else if (scroll > scroll_trigger) {
209      jQuery("#search_wrapper").removeClass("sticky_adv_anime");
210      jQuery("#search_wrapper").addClass("sticky_adv");
211    }
212  }
213}
214
215function wpestate_isScrolledIntoView(scroll) {
216  "use strict";
217  if (jQuery("#search_wrapper").length > 0) {
218    var elemTop = parseInt(jQuery("#search_wrapper").offset().top);
219    var elemHeight = parseInt(jQuery("#search_wrapper").height());
220    elemHeight = 0;
221
222    if (elemTop + elemHeight + 3 < scroll) {
223      return true;
224    } else {
225      if (scroll_trigger === 0) {
226        scroll_trigger = elemTop + elemHeight + 30;
227      }
228      return false;
229    }
230  }
231}
232
233jQuery("#google_map_prop_list_sidebar").scroll(function () {
234  "use strict";
235  var scroll = jQuery("#google_map_prop_list_sidebar").scrollTop();
236  if (scroll >= 110) {
237    jQuery("#advanced_search_map_list_hidden").show();
238    jQuery("#advanced_search_map_list").removeClass("move_to_fixed");
239  } else {
240    jQuery("#advanced_search_map_list_hidden").hide();
241  }
242});
243
244jQuery(window).resize(function () {
245  "use strict";
246  jQuery("#mobile_menu").hide("10");
247});
248
249Number.prototype.format = function (n, x) {
250  "use strict";
251  var re;
252  re = "\\d(?=(\\d{" + (x || 3) + "})+" + (n > 0 ? "\\." : "$") + ")";
253  return this.toFixed(Math.max(0, ~~n)).replace(new RegExp(re, "g"), "$&,");
254};
255
256function wpestate_show_capture_vertical() {
257  "use strict";
258
259  var position, slideno, slidedif, tomove, curentleft, position;
260  jQuery("#googleMapSlider").hide();
261  position = parseFloat(
262    jQuery("#carousel-listing .carousel-inner .active").index(),
263    10
264  );
265  jQuery("#carousel-indicators-vertical  li").removeClass("active");
266  jQuery("#carousel-listing  .caption-wrapper span").removeClass("active");
267  jQuery(
268    "#carousel-listing  .caption-wrapper span[data-slide-to='" +
269      position +
270      "'] "
271  ).addClass("active");
272  jQuery(
273    "#carousel-listing  .caption-wrapper span[data-slide-to='" +
274      position +
275      "'] "
276  ).addClass("active");
277
278  jQuery(
279    "#carousel-indicators-vertical  li[data-slide-to='" + position + "'] "
280  ).addClass("active");
281
282  slideno = position + 1;
283
284  slidedif = slideno * 92;
285
286  if (slidedif > 338) {
287    tomove = 338 - slidedif;
288    tomove = tomove;
289    jQuery("#carousel-indicators-vertical").css("top", tomove + "px");
290  } else {
291    position = jQuery("#carousel-indicators-vertical")
292      .css("top", tomove + "px")
293      .position();
294    curentleft = position.top;
295
296    if (curentleft < 0) {
297      tomove = 0;
298      jQuery("#carousel-indicators-vertical").css("top", tomove + "px");
299    }
300  }
301}
302
303function wpestate_owner_insert_book(button) {
304  "use strict";
305
306  var extra_options,
307    fromdate,
308    todate,
309    listing_edit,
310    nonce,
311    ajaxurl,
312    comment,
313    booking_guest_no,
314    action_function,
315    to_be_paid,
316    price;
317  ajaxurl = control_vars.admin_url + "admin-ajax.php";
318
319  if (jQuery("#start_hour_wrapper_list").length > 0) {
320    // we have per hour
321    var fromdate_base = jQuery("#start_date").val();
322    fromdate =
323      fromdate_base + " " + jQuery("#start_hour_no_wrapper").attr("data-value");
324    todate =
325      fromdate_base + " " + jQuery("#end_hour_no_wrapper").attr("data-value");
326  } else {
327    fromdate = jQuery("#start_date").val();
328    todate = jQuery("#end_date").val();
329  }
330
331  listing_edit = jQuery("#listing_edit").val();
332  comment = jQuery("#book_notes").val();
333  booking_guest_no = jQuery("#booking_guest_no_wrapper").attr("data-value");
334
335  var booking_adults = booking_guest_no;
336  var booking_childs = 0;
337  var booking_infants = 0;
338
339  if (jQuery(".guest_no_hidden").length > 0) {
340    booking_guest_no = parseInt(jQuery(".guest_no_hidden").val(), 10);
341    booking_adults = parseInt(jQuery(".steper_value_adults").html(), 10);
342    booking_childs = parseInt(jQuery(".steper_value_childs").html(), 10);
343    booking_infants = parseInt(jQuery(".steper_value_infants").html(), 10);
344  }
345
346  extra_options = "";
347  jQuery(".cost_row_extra input").each(function () {
348    if (jQuery(this).is(":checked")) {
349      if (
350        !isNaN(jQuery(this).attr("data-key")) &&
351        typeof jQuery(this).attr("data-key") != undefined
352      ) {
353        extra_options = extra_options + jQuery(this).attr("data-key") + ",";
354      }
355    }
356  });
357
358  action_function = "wpestate_ajax_add_booking";
359
360  if (document.getElementById("submit_booking_front_instant")) {
361    action_function = "wpestate_ajax_add_booking_instant";
362  }
363  var nonce = jQuery("#wprentals_add_booking").val();
364
365  jQuery.ajax({
366    type: "POST",
367    url: ajaxurl,
368    data: {
369      action: action_function,
370      fromdate: fromdate,
371      todate: todate,
372      listing_edit: listing_edit,
373      comment: comment,
374      booking_guest_no: booking_guest_no,
375      extra_options: extra_options,
376      booking_adults: booking_adults,
377      booking_childs: booking_childs,
378      booking_infants: booking_infants,
379      security: nonce,
380    },
381    success: function (data) {
382      jQuery(".has_future").each(function () {
383        jQuery("#start_date, #end_date").val("");
384        jQuery("#booking_guest_no_wrapper").html(
385          control_vars.guest_any + '<span class="caret caret_filter"></span>'
386        );
387      });
388
389      if (action_function == "wpestate_ajax_add_booking_instant") {
390        if (document.getElementById("submit_booking_front_instant")) {
391          if (property_vars.logged_in === "no") {
392            window.location.href = data;
393          } else {
394            if (jQuery("#booking_form_request").hasClass("is_shortcode1")) {
395              var instantBookingModal = jQuery("#instant_booking_modal");
396              instantBookingModal.detach().appendTo("body");
397            }
398
399            jQuery("#instant_booking_modal .modal-body").html(data);
400            jQuery("#instant_booking_modal").modal({
401              backdrop: "static",
402              keyboard: false,
403            });
404            wpestate_create_payment_action();
405          }
406        }
407      } else {
408        jQuery("#booking_form_request_mess")
409          .empty()
410          .removeClass("book_not_available")
411          .text(control_vars.bookconfirmed);
412      }
413
414      wpestate_redo_listing_sidebar();
415
416      if (button.attr("id") === "submit_booking_front_instant") {
417        button.val(property_vars.instant_booking);
418      } else {
419        button.val(property_vars.book_now);
420      }
421      button.prop("disabled", false);
422    },
423    error: function (errorThrown) {},
424  });
425}
426
427function wpestate_redo_listing_sidebar() {
428  // 638
429
430  return;
431}
432
433function wprentals_check_booking_valability(button) {
434  "use strict";
435
436  var book_from, book_to, listing_edit, ajaxurl, internal;
437  internal = 0;
438  book_from = jQuery("#start_date").val();
439  book_to = jQuery("#end_date").val();
440  listing_edit = jQuery("#listing_edit").val();
441  ajaxurl = control_vars.admin_url + "admin-ajax.php";
442
443  if (jQuery("#start_hour_wrapper_list").length > 0) {
444    // we have per hour
445    var fromdate_base = book_from;
446    book_from =
447      fromdate_base + " " + jQuery("#start_hour_no_wrapper").attr("data-value");
448    //  book_from            =   wpestate_convert_selected_days(book_from);
449    book_to =
450      fromdate_base + " " + jQuery("#end_hour_no_wrapper").attr("data-value");
451    //book_to              =   wpestate_convert_selected_days(book_to);
452  } else {
453    book_from = jQuery("#start_date").val();
454    book_to = jQuery("#end_date").val();
455  }
456
457  var nonce = jQuery("#wprentals_add_booking").val();
458  jQuery.ajax({
459    type: "POST",
460    url: ajaxurl,
461    data: {
462      action: "wpestate_ajax_check_booking_valability",
463      book_from: book_from,
464      book_to: book_to,
465      listing_id: listing_edit,
466      internal: internal,
467      security: nonce,
468    },
469    success: function (data) {
470      if (data.trim() === "run") {
471        wpestate_owner_insert_book(button);
472      } else if (data === "stopcheckinout") {
473        jQuery("#booking_form_request_mess")
474          .empty()
475          .addClass("book_not_available")
476          .text(control_vars.stopcheckinout);
477      } else if (data === "stopcheckin") {
478        jQuery("#booking_form_request_mess")
479          .empty()
480          .addClass("book_not_available")
481          .text(control_vars.stopcheckin);
482      } else if (data === "stopdays") {
483        jQuery("#booking_form_request_mess")
484          .empty()
485          .addClass("book_not_available")
486          .text(control_vars.mindays);
487      } else {
488        jQuery("#booking_form_request_mess")
489          .empty()
490          .addClass("book_not_available")
491          .text(control_vars.bookdenied);
492      }
493
494      if (data.trim() !== "run") {
495        if (button.attr("id") === "submit_booking_front_instant") {
496          button.val(property_vars.instant_booking);
497        } else {
498          button.val(property_vars.book_now);
499        }
500        button.prop("disabled", false);
501      }
502    },
503    error: function (errorThrown) {},
504  });
505}
506
507function wpestate_show_instant_book_modal() {}
508
509function wpestate_owner_insert_book_internal() {
510  "use strict";
511
512  var fromdate,
513    todate,
514    listing_edit,
515    nonce,
516    ajaxurl,
517    comment,
518    booking_guest_no,
519    hour_from,
520    hour_to;
521  ajaxurl = control_vars.admin_url + "admin-ajax.php";
522  fromdate = jQuery("#start_date_owner_book").val();
523  todate = jQuery("#end_date_owner_book").val();
524
525  listing_edit = jQuery("#listing_edit").val();
526  comment = jQuery("#book_notes").val();
527  booking_guest_no = jQuery("#booking_guest_no_wrapper").attr("data-value");
528
529  if (jQuery(".guest_no_hidden").length > 0) {
530    booking_guest_no = parseInt(jQuery(".guest_no_hidden").val(), 10);
531  }
532
533  var nonce = jQuery("#wprentals_add_booking").val();
534
535  jQuery.ajax({
536    type: "POST",
537    url: ajaxurl,
538    data: {
539      action: "wpestate_ajax_add_booking",
540      fromdate: fromdate,
541      todate: todate,
542      listing_edit: listing_edit,
543      comment: comment,
544      booking_guest_no: booking_guest_no,
545      confirmed: 1,
546      security: nonce,
547    },
548    success: function (data) {
549      jQuery(".has_future").each(function () {
550        jQuery(this).removeClass("calendar-reserved-stop");
551        jQuery(this).removeClass("calendar-reserved-start");
552        jQuery(this).removeClass("calendar-reserved-stop-visual");
553        jQuery(this).removeClass("calendar-reserved-start-visual");
554        jQuery("#owner_reservation_modal").modal("hide");
555
556        jQuery(".booking-calendar-wrapper-in .calendar-selected").removeClass(
557          "calendar-selected"
558        );
559        jQuery("#book_dates").empty().text(ajaxcalls_vars.reserve);
560        jQuery("#book_notes").val("");
561      });
562      jQuery("#booking_form_request_mess")
563        .empty()
564        .text(control_vars.bookconfirmed);
565    },
566    error: function (errorThrown) {},
567  });
568}
569
570function wpestate_check_booking_valability_internal() {
571  "use strict";
572
573  var book_from, book_to, listing_edit, ajaxurl, internal, hour_from, hour_to;
574  jQuery("#book_dates").empty().text(ajaxcalls_vars.saving);
575  book_from = jQuery("#start_date_owner_book").val();
576  book_to = jQuery("#end_date_owner_book").val();
577  var nonce = jQuery("#wprentals_add_booking").val();
578
579  listing_edit = jQuery("#listing_edit").val();
580  ajaxurl = control_vars.admin_url + "admin-ajax.php";
581  internal = 1;
582  jQuery.ajax({
583    type: "POST",
584    url: ajaxurl,
585    data: {
586      action: "wpestate_ajax_check_booking_valability_internal",
587      book_from: book_from,
588      book_to: book_to,
589      listing_id: listing_edit,
590      internal: internal,
591      security: nonce,
592    },
593    success: function (data) {
594      if (data.trim() === "run") {
595        wpestate_owner_insert_book_internal();
596      } else {
597        jQuery("#book_dates").empty().text(ajaxcalls_vars.reserve);
598      }
599    },
600    error: function (errorThrown) {},
601  });
602}
603
604componentForm = {
605  establishment: "long_name",
606  street_number: "short_name",
607  route: "long_name",
608  locality: "long_name",
609  administrative_area_level_1: "long_name",
610  administrative_area_level_2: "long_name",
611  country: "long_name",
612  postal_code: "short_name",
613  postal_code_prefix: "short_name",
614  neighborhood: "long_name",
615  natural_feature: "long_name",
616};
617
618function wpestate_convert_selected_days_reverse(date) {
619  // // from yy-mm-dd to - to whatever
620  var from, return_date;
621
622  if (control_vars.date_format === "yy-mm-dd") {
623    //default
624    return date;
625  } else if (control_vars.date_format === "yy-dd-mm") {
626    from = date.split("-");
627    return_date = from[0] + "-" + from[2] + "-" + from[1];
628    return return_date;
629  } else if (control_vars.date_format === "dd-mm-yy") {
630    from = date.split("-");
631    return_date = from[2] + "-" + from[1] + "-" + from[0];
632    return return_date;
633  } else if (control_vars.date_format === "mm-dd-yy") {
634    from = date.split("-");
635    return_date = from[1] + "-" + from[2] + "-" + from[0];
636    return return_date;
637  } else if (control_vars.date_format === "dd-yy-mm") {
638    from = date.split("-");
639    return_date = from[2] + "-" + from[0] + "-" + from[1];
640    return return_date;
641  } else if (control_vars.date_format === "mm-yy-dd") {
642    from = date.split("-");
643    return_date = from[1] + "-" + from[0] + "-" + from[2];
644    return return_date;
645  }
646}
647
648function wpestate_convert_selected_days(date) {
649  var from, return_date, date_format;
650
651  if (property_vars.book_type === "2") {
652    date_format = control_vars.date_format.toUpperCase() + " HH:mm";
653  } else {
654    date_format = control_vars.date_format.toUpperCase();
655  }
656
657  var new_date_format = date_format.replace("YY", "YYYY");
658
659  if (property_vars.book_type === "2") {
660    var return_date = moment(date, new_date_format).format("YYYY-MM-DD HH:mm");
661  } else {
662    var return_date = moment(date, new_date_format).format("YYYY-MM-DD");
663  }
664
665  return return_date;
666}
667
668function wpestate_convert_selected_days_simple_add_days(date, days) {
669  var date_format = control_vars.date_format.toUpperCase();
670  var new_date_format = date_format.replace("YY", "YYYY");
671  var return_date = moment(date, new_date_format).add(days, "days");
672
673  return_date = moment(return_date).format(new_date_format);
674  return return_date;
675}
676
677function wpestate_convert_selected_days_simple(date) {
678  var from, return_date;
679
680  var date_format = control_vars.date_format.toUpperCase();
681  var new_date_format = date_format.replace("YY", "YYYY");
682  var return_date = moment(date, new_date_format).format("DD-MM-YYYY");
683
684  return return_date;
685}
686
687function wpestate_UTC_addDays(date, days) {
688  var result = new Date(date);
689  var now_utc = new Date(
690    result.getUTCFullYear(),
691    result.getUTCMonth(),
692    result.getUTCDate(),
693    result.getUTCHours(),
694    result.getUTCMinutes(),
695    result.getUTCSeconds()
696  );
697  var new_day = parseFloat(result.getUTCDate()) + 1 + parseFloat(days);
698  now_utc.setDate(new_day);
699  return now_utc;
700}
701
702function wpestaste_check_in_out_enable(in_date, out_date) {
703  "use strict";
704  wpestaste_check_in_out_enable_new(in_date, out_date);
705  return;
706}
707
708/**
709 * Is the Check-Out field locked?
710 *
711 * Reads Booking > Calendar Settings > "Lock the Check-Out field?". Defaults to
712 * locked, so a site whose options predate this setting behaves the same as a
713 * fresh install.
714 */
715function wprentals_checkout_is_locked() {
716  "use strict";
717  return typeof control_vars === "undefined" || control_vars.lock_checkout !== "no";
718}
719
720/**
721 * Prepare a Check-Out field.
722 *
723 * There is one daterangepicker per date pair and it belongs to the Check-In
724 * input. The Check-Out box only ever re-opened that calendar, and re-opening it
725 * mid-selection discards the arrival date the guest already picked, because
726 * daterangepicker's hide() reverts an unfinished range to its previous values.
727 *
728 * Locked   - the field is inert and greyed, so both dates are picked in the one
729 *            calendar and the arrival date cannot be lost.
730 * Unlocked - the field still opens the calendar, but the mousedown that used to
731 *            trigger hide() is stopped, so the arrival date survives either way.
732 */
733function wprentals_setup_checkout_field(in_date, out_date) {
734  "use strict";
735  var out_field = jQuery("#" + out_date);
736
737  if (!out_field.length) {
738    return;
739  }
740
741  if (wprentals_checkout_is_locked()) {
742    // Show it as an output, not a control: greyed, not typeable, not in the tab
743    // order, and carrying a hint so a guest who does aim at it is told where to
744    // pick the date instead of meeting a box that silently does nothing.
745    out_field
746      .attr("readonly", "readonly")
747      .attr("tabindex", "-1")
748      .attr("aria-readonly", "true")
749      .addClass("wprentals_checkout_locked")
750      .off("click");
751
752    // Hint on hover. The placeholder is deliberately left alone: it is the
753    // field's label, and replacing it with an instruction leaves the guest unable
754    // to tell which box is Check-Out.
755    //
756    // A real element rather than the native title attribute, for two reasons:
757    // the browser tooltip cannot be styled, and it only fires over the input
758    // itself - the wrapper is a little larger and carries the calendar icon, so
759    // hovering the icon or the padding would show nothing.
760    if (typeof control_vars !== "undefined" && control_vars.checkout_locked_hint) {
761      var hint = control_vars.checkout_locked_hint;
762      var wrapper = out_field.parent();
763
764      // Screen readers get the hint through the field itself.
765      out_field.attr("aria-label", (out_field.attr("placeholder") || "") + ". " + hint);
766
767      // Guard against a second run binding a duplicate tooltip to the same field.
768      if (wrapper.length && !wrapper.hasClass("wprentals_checkout_locked_wrap")) {
769        wrapper
770          .addClass("wprentals_checkout_locked_wrap")
771          .append(
772            jQuery("<span/>", {
773              class: "wprentals_checkout_tip",
774              "aria-hidden": "true",
775              text: hint,
776            })
777          );
778      }
779    }
780
781    return;
782  }
783
784  // Unlocked: keep the field usable, but stop daterangepicker's document-level
785  // mousedown watcher from seeing the click and hiding (and reverting) the picker.
786  out_field.on("mousedown touchend", function (e) {
787    e.stopPropagation();
788  });
789
790  out_field.on("click", function () {
791    // The picker binds toggle() to the Check-In input, so re-triggering a click
792    // while the calendar is open would close it instead of leaving it alone.
793    var picker = jQuery("#" + in_date).data("daterangepicker");
794
795    if (!picker || !picker.isShowing) {
796      jQuery("#" + in_date).trigger("click");
797    }
798  });
799}
800
801function wpestaste_check_in_out_enable_new(in_date, out_date) {
802  show_daterange_picker_custom_mess = "yes";
803  var today, prev_date, read_in_date;
804  today = new Date();
805  date_format = control_vars.date_format.toUpperCase();
806
807  // Build the moment.js format from the theme's configured date format. Without
808  // this the calendar falls back to moment's active locale format, which swaps
809  // day and month whenever a translation plugin sets a non-English locale.
810  var drp_date_format = control_vars.date_format.toUpperCase().replace("YY", "YYYY");
811
812  today = moment(today).format(drp_date_format);
813  jQuery("#" + in_date).attr("readonly", "readonly");
814
815  var options = {
816    singleDatePicker: false,
817    autoApply: true,
818    alwaysShowCalendars: true,
819    autoUpdateInput: false,
820    minDate: today,
821    locale: {
822      // Tell daterangepicker which format the theme speaks, so minDate is
823      // parsed with it instead of moment.localeData().longDateFormat("L").
824      format: drp_date_format,
825      daysOfWeek: dayNamesShort,
826      monthNames: longmonths,
827    },
828
829    isCustomDate: "isCustomDate_wpstate",
830  };
831
832  if (
833    in_date === "booking_from_date" &&
834    jQuery("#contact_for_reservation").length === 0
835  ) {
836    options.parentEl = "#contact_owner_modal";
837  }
838
839  var date_format = control_vars.date_format.toUpperCase();
840  date_format = date_format.replace("YY", "YYYY");
841
842  var in_date_front = jQuery("#" + in_date);
843  var out_date_front = jQuery("#" + out_date);
844
845  jQuery("#" + in_date).daterangepicker(options, function (start, end, label) {
846    jQuery("#" + out_date).removeAttr("disabled");
847    start_date = start.format(date_format);
848    end_date = end.format(date_format);
849
850    in_date_front.val(start_date);
851    out_date_front.val(end_date);
852    // .val() fires no event, so tell the locked-field handler the date landed.
853
854    if (jQuery("#google_map_prop_list_sidebar").length > 0) {
855      wpestate_start_filtering_ajax_map(1);
856    }
857  });
858
859  jQuery("#" + in_date).on("click", function () {
860    jQuery(".daterangepicker").css("margin-top", "7px");
861  });
862
863  // Both dates are chosen in the single calendar bound to Check-In. The Check-Out
864  // box has no picker of its own - it only re-opens that calendar.
865  wprentals_setup_checkout_field(in_date, out_date);
866
867  jQuery("#" + out_date).on("click", function () {
868    // Nothing to position when the field is locked.
869    if (wprentals_checkout_is_locked()) {
870      return;
871    }
872
873    var parent = jQuery(this).parent().parent().parent();
874    var parent2 = jQuery(this).parent().parent().parent().parent();
875
876    if (parent.hasClass("adv-search-2") || parent2.hasClass("adv-search-5")) {
877      jQuery(".daterangepicker").css("margin-top", "59px");
878    }
879    if (parent2.hasClass("adv-search-5")) {
880      jQuery(".daterangepicker").css("margin-top", "69px");
881    }
882  });
883}
884
885function isCustomDate_wpstate(date) {
886  return "maca";
887}
888
889function wpestate_booking_calendat_get_price(unixtime1_key, display_price) {
890  var return_price;
891  return_price = "";
892
893  if (!isNaN(my_custom_curr_pos) && my_custom_curr_pos !== -1) {
894    // if we have custom curency
895    if (my_custom_curr_cur_post === "before") {
896      if (price_array[unixtime1_key] === undefined) {
897        if (display_price === "") {
898          // we DONT have weekend price
899          display_price = control_vars_property.default_price;
900        }
901        if (parseFloat(price_per_guest_from_one, 10) === 1) {
902          display_price = parseFloat(extra_price_per_guest, 10);
903        }
904        display_price =
905          wpestate_replace_plus(decodeURIComponent(my_custom_curr_label)) +
906          String(Math.round(display_price * my_custom_curr_coef));
907      } else {
908        if (display_price === "") {
909          // we DONT have weekend price
910          display_price = price_array[unixtime1_key];
911        }
912        if (parseFloat(price_per_guest_from_one, 10) === 1) {
913          display_price =
914            mega_details[unixtime1_key]["period_extra_price_per_guest"];
915        }
916        display_price =
917          wpestate_replace_plus(decodeURIComponent(my_custom_curr_label)) +
918          String(Math.round(display_price * my_custom_curr_coef));
919      }
920    } else {
921      if (price_array[unixtime1_key] === undefined) {
922        if (display_price === "") {
923          // we DONT have weekend price
924          display_price = control_vars_property.default_price;
925        }
926        if (parseFloat(price_per_guest_from_one, 10) === 1) {
927          display_price = parseFloat(extra_price_per_guest, 10);
928        }
929
930        display_price =
931          String(Math.round(display_price * my_custom_curr_coef)) +
932          wpestate_replace_plus(decodeURIComponent(my_custom_curr_label));
933      } else {
934        if (display_price === "") {
935          // we DONT have weekend price
936          display_price = price_array[unixtime1_key];
937        }
938        if (parseFloat(price_per_guest_from_one, 10) === 1) {
939          display_price =
940            mega_details[unixtime1_key]["period_extra_price_per_guest"];
941        }
942        display_price =
943          String(Math.round(display_price * my_custom_curr_coef)) +
944          wpestate_replace_plus(decodeURIComponent(my_custom_curr_label));
945      }
946    }
947  } else {
948    // we don't have custom curency
949
950    if (control_vars.where_curency === "before") {
951      if (price_array[unixtime1_key] === undefined) {
952        if (display_price === "") {
953          // we DONT have weekend price
954          display_price = control_vars_property.default_price;
955        }
956        display_price =
957          wpestate_replace_plus(decodeURIComponent(control_vars.curency)) +
958          display_price;
959        //return [true, "freetobook wpestate_calendar"+reservation_class+" date"+unixtime1_key, wpestate_replace_plus ( decodeURIComponent ( control_vars.curency ) ) + display_price ];
960      } else {
961        if (display_price === "") {
962          // we DONT have weekend price
963          display_price = price_array[unixtime1_key];
964        }
965        display_price =
966          wpestate_replace_plus(decodeURIComponent(control_vars.curency)) +
967          String(display_price);
968        //return [true, "freetobook wpestate_calendar"+reservation_class+" date"+unixtime1_key, wpestate_replace_plus ( decodeURIComponent ( control_vars.curency ) ) +  String(display_price) ];
969      }
970    } else {
971      if (price_array[unixtime1_key] === undefined) {
972        if (display_price === "") {
973          // we DONT have weekend price
974          display_price = control_vars_property.default_price;
975        }
976        display_price =
977          display_price +
978          wpestate_replace_plus(decodeURIComponent(control_vars.curency));
979        //return [true, "freetobook wpestate_calendar"+reservation_class+" date"+unixtime1_key,display_price +  wpestate_replace_plus ( decodeURIComponent ( control_vars.curency ) ) ];
980      } else {
981        if (display_price === "") {
982          // we DONT have weekend price
983          display_price = price_array[unixtime1_key];
984        }
985        display_price =
986          String(display_price) +
987          wpestate_replace_plus(decodeURIComponent(control_vars.curency));
988        // return [true, "freetobook wpestate_calendar"+reservation_class+" date"+unixtime1_key, String(display_price)+ wpestate_replace_plus( decodeURIComponent ( control_vars.curency ) ) ];
989      }
990    }
991  }
992
993  if (parseFloat(price_per_guest_from_one, 10) === 1) {
994    if (!isNaN(my_custom_curr_pos) && my_custom_curr_pos !== -1) {
995      var to_show = parseFloat(extra_price_per_guest, 10) * my_custom_curr_coef;
996      if (my_custom_curr_cur_post === "before") {
997        display_price =
998          control_vars.from +
999          " " +
1000          wpestate_replace_plus(decodeURIComponent(my_custom_curr_label)) +
1001          to_show.toFixed(0);
1002      } else {
1003        display_price =
1004          control_vars.from +
1005          " " +
1006          to_show.toFixed(0) +
1007          wpestate_replace_plus(decodeURIComponent(my_custom_curr_label));
1008      }
1009    } else {
1010      if (control_vars.where_curency === "before") {
1011        display_price =
1012          control_vars.from +
1013          " " +
1014          wpestate_replace_plus(decodeURIComponent(control_vars.curency)) +
1015          parseFloat(extra_price_per_guest, 10);
1016      } else {
1017        display_price =
1018          control_vars.from +
1019          " " +
1020          parseFloat(extra_price_per_guest, 10) +
1021          wpestate_replace_plus(decodeURIComponent(control_vars.curency));
1022      }
1023    }
1024  }
1025
1026  return display_price;
1027}
1028
1029
1030
1031
1032/**
1033 * WPEstate: Geolocation Radius Slider + Place Search (REST API)
1034 * -------------------------------------------------------------
1035 * Handles:
1036 * - jQuery UI radius slider
1037 * - Manual geolocation input with autocomplete (using Google Places REST v1)
1038 * - Circle update and map re-fit after radius or location changes
1039*/
1040
1041async function wpestate_enable_slider_radius(slider_name, low_val, max_val, now_val) {
1042  if (jQuery("#" + slider_name).length > 0) {
1043    jQuery("#" + slider_name).slider({
1044      range: true,
1045      min: parseFloat(low_val),
1046      max: parseFloat(max_val),
1047      value: parseFloat(now_val),
1048      range: "max",
1049      slide: function (event, ui) {
1050        jQuery("#geolocation_radius").val(ui.value);
1051        jQuery(".radius_value").text(ui.value + " " + control_vars.geo_radius_measure);
1052      },
1053      stop: function (event, ui) {
1054        if (placeCircle) {
1055          const radius =
1056            control_vars.geo_radius_measure === "miles" ? ui.value * 1609.34 : ui.value * 1000;
1057          placeCircle.setRadius(radius);
1058          map.fitBounds(placeCircle.getBounds());
1059          wpestate_start_filtering_ajax_map(1);
1060        }
1061      },
1062    });
1063  }
1064
1065  jQuery("#geolocation_search").on("change", function () {
1066    if (jQuery(this).val() === "") {
1067      jQuery("#geolocation_lat").val("");
1068      jQuery("#geolocation_long").val("");
1069      if (placeCircle) {
1070        placeCircle.setMap(null);
1071        placeCircle = "";
1072      }
1073    }
1074  });
1075
1076  const input = document.getElementById("geolocation_search");
1077  if (!input) return;
1078
1079  const dropdown = document.createElement("ul");
1080  dropdown.className = "wpestate-autocomplete-results";
1081  input.parentNode.style.position = "relative";
1082  input.parentNode.appendChild(dropdown);
1083
1084  let controller = null;
1085
1086  input.addEventListener("input", async function () {
1087    const query = input.value.trim();
1088    if (query.length < 3) {
1089      dropdown.style.display = "none";
1090      return;
1091    }
1092
1093    if (controller) controller.abort();
1094    controller = new AbortController();
1095
1096    try {
1097      const res = await fetch("https://places.googleapis.com/v1/places:autocomplete", {
1098        method: "POST",
1099        signal: controller.signal,
1100        headers: {
1101          "Content-Type": "application/json",
1102          "X-Goog-Api-Key": control_vars.google_api_key,
1103          "X-Goog-FieldMask":
1104            "suggestions.placePrediction.text,suggestions.placePrediction.placeId",
1105        },
1106        // force English place names, matching the language=en the Maps JS API
1107        // was loaded with before the switch to the Places REST API
1108        body: JSON.stringify({ input: query, languageCode: "en" }),
1109      });
1110
1111      const data = await res.json();
1112      const suggestions = data.suggestions || [];
1113      dropdown.innerHTML = "";
1114      if (!suggestions.length) {
1115        dropdown.style.display = "none";
1116        return;
1117      }
1118
1119      suggestions.forEach((item) => {
1120        const text = item.placePrediction.text.text;
1121        const li = document.createElement("li");
1122        li.textContent = text;
1123        li.className = "wpestate-autocomplete-item";
1124        li.addEventListener("click", () =>
1125          handlePlaceSelect(item.placePrediction.placeId, text)
1126        );
1127        dropdown.appendChild(li);
1128      });
1129
1130      dropdown.style.display = "block";
1131    } catch (err) {
1132      if (err.name !== "AbortError") console.error(err);
1133    }
1134  });
1135
1136  document.addEventListener("click", (e) => {
1137    if (!dropdown.contains(e.target) && e.target !== input) {
1138      dropdown.style.display = "none";
1139    }
1140  });
1141
1142  async function handlePlaceSelect(placeId, text) {
1143    input.value = text;
1144    dropdown.style.display = "none";
1145
1146    try {
1147      // languageCode=en keeps the selected address in English, the same as the
1148      // autocomplete list above it
1149      const res = await fetch(`https://places.googleapis.com/v1/places/${placeId}?languageCode=en`, {
1150        method: "GET",
1151        headers: {
1152          "X-Goog-Api-Key": control_vars.google_api_key,
1153          "X-Goog-FieldMask":
1154            "id,formattedAddress,displayName,location,viewport,addressComponents",
1155        },
1156      });
1157
1158      const place = await res.json();
1159      if (!place.location) return;
1160
1161      const lat = place.location.latitude;
1162      const lng = place.location.longitude;
1163
1164      jQuery("#geolocation_lat").val(lat);
1165      jQuery("#geolocation_long").val(lng);
1166
1167      if (typeof google === "object" && map) {
1168        const position = new google.maps.LatLng(lat, lng);
1169        if (!placeCircle) {
1170          placeCircle = new google.maps.Circle({
1171            strokeColor: "#4285F4",
1172            strokeOpacity: 0.8,
1173            strokeWeight: 2,
1174            fillColor: "#4285F4",
1175            fillOpacity: 0.15,
1176            map: map,
1177            center: position,
1178            radius:
1179              parseFloat(jQuery("#geolocation_radius").val()) *
1180              (control_vars.geo_radius_measure === "miles" ? 1609.34 : 1000),
1181          });
1182        } else {
1183          placeCircle.setCenter(position);
1184        }
1185        map.fitBounds(placeCircle.getBounds());
1186      }
1187
1188      wpestate_start_filtering_ajax_map(1);
1189    } catch (err) {
1190      console.error("Place details fetch failed:", err);
1191    }
1192  }
1193}
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217function wpestate_enable_slider_radius2(slider_name, low_val, max_val, now_val) {
1218  if (jQuery("#" + slider_name).length > 0) {
1219    jQuery("#" + slider_name).slider({
1220      range: true,
1221      min: parseFloat(low_val),
1222      max: parseFloat(max_val),
1223      value: parseFloat(now_val),
1224      range: "max",
1225      slide: function (event, ui) {
1226        jQuery("#geolocation_radius").val(ui.value);
1227        jQuery(".radius_value").text(
1228          ui.value + " " + control_vars.geo_radius_measure
1229        );
1230      },
1231      stop: function (event, ui) {
1232        if (placeCircle != "") {
1233          if (control_vars.geo_radius_measure === "miles") {
1234            placeCircle.setRadius(ui.value * 1609.34);
1235          } else {
1236            placeCircle.setRadius(ui.value * 1000);
1237          }
1238          map.fitBounds(placeCircle.getBounds());
1239          wpestate_start_filtering_ajax_map(1);
1240        }
1241      },
1242    });
1243  }
1244
1245  jQuery("#geolocation_search").on("change", function () {
1246    if (jQuery(this).val() === "") {
1247      jQuery("#geolocation_lat").val("");
1248      jQuery("#geolocation_long").val("");
1249      if (placeCircle != "") {
1250        placeCircle.setMap(null);
1251        placeCircle = "";
1252      }
1253    }
1254  });
1255
1256  if (jQuery("#geolocation_search").length > 0) {
1257    if (
1258      typeof google === "object" &&
1259      typeof google.maps === "object" &&
1260      parseInt(mapbase_vars.wprentals_places_type) == 1
1261    ) {
1262      var input, defaultBounds, autocomplete_normal;
1263      input = document.getElementById("geolocation_search");
1264      defaultBounds = new google.maps.LatLngBounds(
1265        new google.maps.LatLng(-90, -180),
1266        new google.maps.LatLng(90, 180)
1267      );
1268      var options = {
1269        bounds: defaultBounds,
1270        types: ["geocode"],
1271        // types: ['(regions)'],
1272      };
1273
1274      autocomplete_normal = new google.maps.places.Autocomplete(input, options);
1275
1276      if (
1277        control_vars.limit_country === "yes" &&
1278        control_vars.limit_country_select != ""
1279      ) {
1280        autocomplete_normal.setComponentRestrictions({
1281          country: [control_vars.limit_country_select],
1282        });
1283      }
1284
1285      google.maps.event.addListener(
1286        autocomplete_normal,
1287        "place_changed",
1288        function () {
1289          initial_geolocation_circle_flag = 0;
1290          var place = autocomplete_normal.getPlace();
1291          var place_lat = place.geometry.location.lat();
1292          var place_lng = place.geometry.location.lng();
1293
1294          jQuery("#geolocation_lat").val(place_lat);
1295          jQuery("#geolocation_long").val(place_lng);
1296
1297          wpestate_start_filtering_ajax_map(1);
1298        }
1299      );
1300    }
1301  }
1302}
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332function wpestate_enable_slider(
1333  slider_name,
1334  price_low,
1335  price_max,
1336  amount,
1337  my_custom_curr_pos,
1338  my_custom_curr_symbol,
1339  my_custom_curr_cur_post,
1340  my_custom_curr_coef,
1341  my_custom_curr_label
1342) {
1343  "use strict";
1344  var price_low_val, price_max_val, temp_min, temp_max;
1345  price_low_val = parseFloat(jQuery("#" + price_low).val(), 10);
1346  price_max_val = parseFloat(jQuery("#" + price_max).val(), 10);
1347
1348  var slider_min = control_vars.slider_min;
1349  var slider_max = control_vars.slider_max;
1350  if (!isNaN(my_custom_curr_pos) && my_custom_curr_pos !== -1) {
1351    slider_min = parseFloat(slider_min * my_custom_curr_coef, 10);
1352    slider_max = parseFloat(slider_max * my_custom_curr_coef, 10);
1353  }
1354
1355  var parent = jQuery("#" + slider_name)
1356    .parent()
1357    .parent();
1358  var component_price_min;
1359  var component_price_max;
1360  var dropdown_parent;
1361  var dropdown_label;
1362  var component_label_value;
1363  if (parent.hasClass("wpestate-price-popoup-wrapper")) {
1364    component_price_min = parent.find("#component_" + price_low);
1365    component_price_max = parent.find("#component_" + price_max);
1366
1367    var dropdown_parent = parent.parent().find(".dropdown-toggle");
1368    dropdown_label = parent.find(".price_label_component");
1369  }
1370
1371  jQuery("#" + slider_name).slider({
1372    range: true,
1373    min: parseFloat(slider_min),
1374    max: parseFloat(slider_max),
1375    values: [price_low_val, price_max_val],
1376    slide: function (event, ui) {
1377      jQuery("#" + price_low).val(ui.values[0]);
1378      jQuery("#" + price_max).val(ui.values[1]);
1379      temp_min = ui.values[0].format();
1380      temp_max = ui.values[1].format();
1381
1382      if (!isNaN(my_custom_curr_pos) && my_custom_curr_pos !== -1) {
1383        temp_min = ui.values[0];
1384        temp_max = ui.values[1];
1385
1386        if (my_custom_curr_cur_post === "before") {
1387          jQuery("#" + amount).text(
1388            wpestate_replace_plus(decodeURIComponent(my_custom_curr_label)) +
1389              " " +
1390              temp_min.format() +
1391              " " +
1392              control_vars.to +
1393              " " +
1394              wpestate_replace_plus(decodeURIComponent(my_custom_curr_label)) +
1395              " " +
1396              temp_max.format()
1397          );
1398          if (parent.hasClass("wpestate-price-popoup-wrapper")) {
1399            component_price_min.val(
1400              wpestate_replace_plus(decodeURIComponent(my_custom_curr_symbol)) +
1401                " " +
1402                temp_min
1403            );
1404            component_price_max.val(
1405              wpestate_replace_plus(decodeURIComponent(my_custom_curr_symbol)) +
1406                " " +
1407                temp_max
1408            );
1409            component_label_value =
1410              "" +
1411              wpestate_replace_plus(decodeURIComponent(my_custom_curr_symbol)) +
1412              " " +
1413              wpestate_formatNumber_short(ui.values[0]) +
1414              " - " +
1415              wpestate_replace_plus(decodeURIComponent(my_custom_curr_symbol)) +
1416              " " +
1417              wpestate_formatNumber_short(ui.values[1]);
1418
1419            dropdown_parent.text(component_label_value);
1420            dropdown_label.val(component_label_value);
1421          }
1422        } else {
1423          jQuery("#" + amount).text(
1424            temp_min.format() +
1425              " " +
1426              wpestate_replace_plus(decodeURIComponent(my_custom_curr_label)) +
1427              " " +
1428              control_vars.to +
1429              " " +
1430              temp_max.format() +
1431              " " +
1432              wpestate_replace_plus(decodeURIComponent(my_custom_curr_label))
1433          );
1434          if (parent.hasClass("wpestate-price-popoup-wrapper")) {
1435            component_price_min.val(
1436              temp_min +
1437                " " +
1438                wpestate_replace_plus(decodeURIComponent(my_custom_curr_symbol))
1439            );
1440            component_price_max.val(
1441              temp_max +
1442                " " +
1443                wpestate_replace_plus(decodeURIComponent(my_custom_curr_symbol))
1444            );
1445            component_label_value =
1446              wpestate_formatNumber_short(ui.values[0]) +
1447              " " +
1448              wpestate_replace_plus(decodeURIComponent(my_custom_curr_symbol)) +
1449              " - " +
1450              wpestate_formatNumber_short(ui.values[1]) +
1451              " " +
1452              wpestate_replace_plus(decodeURIComponent(my_custom_curr_symbol));
1453
1454            dropdown_parent.text(component_label_value);
1455            dropdown_label.val(component_label_value);
1456          }
1457        }
1458      } else {
1459        if (control_vars.where_curency === "before") {
1460          jQuery("#" + amount).text(
1461            wpestate_replace_plus(decodeURIComponent(control_vars.curency)) +
1462              " " +
1463              ui.values[0].format() +
1464              " " +
1465              control_vars.to +
1466              " " +
1467              wpestate_replace_plus(decodeURIComponent(control_vars.curency)) +
1468              " " +
1469              ui.values[1].format()
1470          );
1471          if (parent.hasClass("wpestate-price-popoup-wrapper")) {
1472            component_price_min.val(
1473              wpestate_replace_plus(decodeURIComponent(control_vars.curency)) +
1474                " " +
1475                temp_min
1476            );
1477            component_price_max.val(
1478              wpestate_replace_plus(decodeURIComponent(control_vars.curency)) +
1479                " " +
1480                temp_max
1481            );
1482            component_label_value =
1483              "" +
1484              wpestate_replace_plus(decodeURIComponent(control_vars.curency)) +
1485              " " +
1486              wpestate_formatNumber_short(ui.values[0]) +
1487              " - " +
1488              wpestate_replace_plus(decodeURIComponent(control_vars.curency)) +
1489              " " +
1490              wpestate_formatNumber_short(ui.values[1]);
1491
1492            dropdown_parent.text(component_label_value);
1493            dropdown_label.val(component_label_value);
1494          }
1495        } else {
1496          jQuery("#" + amount).text(
1497            ui.values[0].format() +
1498              " " +
1499              wpestate_replace_plus(decodeURIComponent(control_vars.curency)) +
1500              " " +
1501              control_vars.to +
1502              " " +
1503              ui.values[1].format() +
1504              " " +
1505              wpestate_replace_plus(decodeURIComponent(control_vars.curency))
1506          );
1507          if (parent.hasClass("wpestate-price-popoup-wrapper")) {
1508            component_price_min.val(
1509              temp_min +
1510                " " +
1511                wpestate_replace_plus(decodeURIComponent(control_vars.curency))
1512            );
1513            component_price_max.val(
1514              temp_max +
1515                " " +
1516                wpestate_replace_plus(decodeURIComponent(control_vars.curency))
1517            );
1518            component_label_value =
1519              wpestate_formatNumber_short(ui.values[0]) +
1520              " " +
1521              wpestate_replace_plus(decodeURIComponent(control_vars.curency)) +
1522              " - " +
1523              wpestate_formatNumber_short(ui.values[1]) +
1524              " " +
1525              wpestate_replace_plus(decodeURIComponent(control_vars.curency));
1526
1527            dropdown_parent.text(component_label_value);
1528            dropdown_label.val(component_label_value);
1529          }
1530        }
1531      }
1532    },
1533  });
1534}
1535
1536function wpestate_replace_plus(string) {
1537  return string.replace("+", " ");
1538}
1539
1540function wpestate_prevent_enter_submit(
1541  main_search,
1542  search_location,
1543  check_in,
1544  check_out,
1545  guest_no
1546) {
1547  jQuery("#" + main_search).on("keyup keypress", function (e) {
1548    var code = e.keyCode || e.which;
1549    if (code == 13) {
1550      e.preventDefault();
1551      if (jQuery("#" + search_location).val() !== "") {
1552        if (jQuery("#" + check_in).val() !== "") {
1553          if (jQuery("#" + check_out).val() !== "") {
1554            jQuery("#" + check_out).focusout();
1555            jQuery("#" + check_out).datepicker("hide");
1556            jQuery("#" + guest_no)
1557              .focus()
1558              .dropdown("toggle");
1559            jQuery("#" + check_out).datepicker("hide");
1560          } else {
1561            jQuery("#" + check_in).datepicker("hide");
1562            jQuery("#" + check_out).datepicker("show");
1563          }
1564        } else {
1565          jQuery("#" + check_in).datepicker("show");
1566        }
1567      }
1568
1569      return false;
1570    }
1571  });
1572}
1573
1574function wpestate_lazy_load_carousel_property_unit() {
1575  jQuery(".property_unit_carousel img").each(function (event) {
1576    var new_source = "";
1577
1578    new_source = jQuery(this).attr("data-lazy-load-src");
1579    if (typeof new_source !== "undefined" && new_source !== "") {
1580      jQuery(this).attr("src", new_source);
1581    }
1582  });
1583}
1584
1585function wpestate_open_property_card_setup() {
1586  jQuery(
1587    ".property_unit_big_grid_content_wrapper , .agent_unit, .blog_unit,.blog_unit_back,.places_wrapper,.places_wrapper_design_2_wrapper,.featured_agent,.places_slider_wrapper_type_1"
1588  ).on("click", function () {
1589    var link;
1590    link = jQuery(this).attr("data-link");
1591    window.open(link, "_self");
1592  });
1593
1594  //.property_listing .carousel a
1595  jQuery(".featured_listing_title").on("click", function (event) {
1596    if(!jQuery(this).hasClass('wprentals_forward_click')){
1597      event.preventDefault();
1598    }
1599 
1600  });
1601
1602  jQuery(".property_listing").on("click", function (event) {
1603    // event.stopPropagation();
1604    var link, classevent;
1605    var event_parent = jQuery(event.target).parent();
1606    classevent = jQuery(event.target);
1607
1608    if (
1609      classevent.hasClass("carousel-control") ||
1610      classevent.hasClass("icon-left-open-big") ||
1611      classevent.hasClass("icon-right-open-big")
1612    ) {
1613      return;
1614    }
1615
1616    if (event_parent.hasClass("category_tagline")) {
1617      return;
1618    }
1619
1620    link = jQuery(this).attr("data-link");
1621    if (typeof link !== "undefined") {
1622      window.open(link, control_vars.new_tab);
1623    }
1624  });
1625
1626  ////////////////////////////////////////////////////////////////////////////
1627  // listing map actions
1628  ////////////////////////////////////////////////////////////////////////////
1629
1630  jQuery("#google_map_prop_list_sidebar .listing_wrapper").on(
1631    "mouseenter",
1632    function (event) {
1633      event.stopPropagation();
1634      var listing_id = jQuery(this).attr("data-listid");
1635      if (typeof wpestate_hover_action_pin == "function") {
1636        wpestate_hover_action_pin(listing_id);
1637      }
1638    }
1639  );
1640
1641  jQuery("#google_map_prop_list_sidebar .listing_wrapper").on(
1642    "mouseleave",
1643    function (event) {
1644      event.stopPropagation();
1645      var listing_id = jQuery(this).attr("data-listid");
1646      if (typeof wpestate_return_hover_action_pin == "function") {
1647        wpestate_return_hover_action_pin(listing_id);
1648      }
1649    }
1650  );
1651}
1652
1653/*
1654 *
1655 *
1656 *
1657 */
1658function wpestate_formatNumber_short(num) {
1659  num = parseFloat(num);
1660
1661  if (num >= 1000000000) {
1662    return (num / 1000000000).toFixed(1).replace(/\.0$/, "") + "B";
1663  }
1664  if (num >= 1000000) {
1665    return (num / 1000000).toFixed(1).replace(/\.0$/, "") + "M";
1666  }
1667  if (num >= 1000) {
1668    return (num / 1000).toFixed(1).replace(/\.0$/, "") + "K";
1669  }
1670  return num.toString();
1671}
1672
1673jQuery(document).ready(function ($) {
1674  "use strict";
1675  var bLazy,
1676    search_label,
1677    curent,
1678    price_regular,
1679    price_featured,
1680    total,
1681    percent,
1682    parent,
1683    price_low_val,
1684    price_max_val,
1685    autoscroll_slider,
1686    all_browsers_stuff,
1687    wrap_h,
1688    map_h,
1689    mediaQuery;
1690
1691  $.datepicker.setDefaults($.datepicker.regional[control_vars.datepick_lang]);
1692  $.datepicker.setDefaults({
1693    dateFormat: control_vars.date_format,
1694  });
1695
1696  wpestate_open_property_card_setup();
1697  wpestate_slider_box();
1698  wpestate_mobile_menu_slideout();
1699  wpestate_theme_slider();
1700  wpestate_taxonomy_slider();
1701  wpestate_enable_stripe_booking_prop();
1702  wpestate_price_component_item();
1703  wpestate_beds_baths_component();
1704  wpestate_advnced_filters_bars();  
1705  wpestate_reposion_dropdowns();
1706  wprentals_three_items_slick_slider();
1707  wpestate_elementor_mobile_menu_trigger_open();
1708
1709 
1710  
1711  jQuery(".carousel").swipe({
1712    swipe: function(event, direction, distance, duration, fingerCount, fingerData) {
1713      if (direction == 'left') $(this).carousel('next');
1714      if (direction == 'right') $(this).carousel('prev');
1715    },
1716    allowPageScroll:"vertical"
1717  });
1718
1719  jQuery(".show_hide_password").on("click", function () {
1720    var pass_field = jQuery(this).parent().find(":input");
1721
1722    if (pass_field.attr("type") === "password") {
1723      pass_field.attr("type", "text");
1724      jQuery(this).removeClass("fa-eye-slash").addClass("fa-eye");
1725    } else {
1726      pass_field.attr("type", "password");
1727
1728      jQuery(this).removeClass("fa-eye").addClass("fa-eye-slash");
1729    }
1730  });
1731
1732 
1733
1734
1735
1736
1737  if ($(".full_screen_yes").length) {
1738    var new_height;
1739    if (jQuery(".transparent_header").length > 0) {
1740      new_height = jQuery(window).height();
1741    } else {
1742      new_height = jQuery(window).height() - jQuery(".master_header").height();
1743    }
1744
1745    if ($(".with_search_on_start").length > 0) {
1746      new_height =
1747        new_height - jQuery(".search_wrapper.with_search_on_start ").height();
1748    }
1749
1750    jQuery(
1751      ".wpestate_header_image,.wpestate_header_video,.theme_slider_wrapper,.theme_slider_classic,.theme_slider_wrapper .item_type2 "
1752    ).css("height", new_height);
1753  }
1754
1755  $(".search_location_autointernal_list li").on("click", function (event) {
1756    var meta_tax = $(this).attr("data-tax");
1757    var parent = $(this).parent().parent().parent();
1758    parent.find(".stype").val(meta_tax);
1759  });
1760
1761  var handler_top;
1762  $(".adv_handler").on("click", function (event) {
1763    event.preventDefault();
1764
1765    var check_row = $(this).parent().find(".adv_search_hidden_fields");
1766    var parent = $(this).parent().parent();
1767
1768    if ($("#search_wrapper").hasClass("with_search_form_float")) {
1769      if (!$("#search_wrapper").hasClass("openmore")) {
1770        check_row.css("display", "block");
1771        var height = check_row.height();
1772        handler_top = parseInt($("#search_wrapper").css("top"));
1773        var top = parseInt($("#search_wrapper").css("top")) - height;
1774
1775        check_row.css("display", "none");
1776
1777        parent
1778          .find(".adv_search_hidden_fields")
1779          .slideDown({ duration: 200, queue: false });
1780        $("#search_wrapper").addClass("openmore");
1781      } else {
1782        parent
1783          .find(".adv_search_hidden_fields")
1784          .slideUp({ duration: 200, queue: false });
1785        $("#search_wrapper").removeClass("openmore");
1786      }
1787    } else {
1788      parent.find(".adv_search_hidden_fields").slideToggle();
1789    }
1790  });
1791
1792  //////direct pay//////////////////////////////////////////////////////////////////////
1793
1794  jQuery("#direct_pay").on("click", function () {
1795    var direct_pay_modal,
1796      selected_pack,
1797      selected_prop,
1798      include_feat,
1799      attr,
1800      price_pack;
1801
1802    selected_pack = $("#pack_select").val();
1803    var price_pack = $("#pack_select option:selected").attr("data-price");
1804
1805    if (control_vars.where_curency === "after") {
1806      price_pack = price_pack + " " + control_vars.submission_curency;
1807    } else {
1808      price_pack = control_vars.submission_curency + " " + price_pack;
1809    }
1810
1811    price_pack = control_vars.direct_price + ": " + price_pack;
1812
1813    if (selected_pack !== "") {
1814      window.scrollTo(0, 0);
1815      direct_pay_modal =
1816        '<div class="modal fade" id="direct_pay_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h2 class="modal-title_big">' +
1817        control_vars.direct_title +
1818        '</h2></div><div class="modal-body listing-submit"><span class="to_be_paid">' +
1819        price_pack +
1820        "</span><span>" +
1821        control_vars.direct_pay +
1822        '</span><div id="send_direct_bill" data-pack="' +
1823        selected_pack +
1824        '">' +
1825        control_vars.send_invoice +
1826        "</div></div></div></div></div></div>";
1827      jQuery("body").append(direct_pay_modal);
1828      jQuery("#direct_pay_modal").modal();
1829      wpestate_enable_direct_pay();
1830    }
1831
1832    $("#direct_pay_modal").on("hidden.bs.modal", function (e) {
1833      $("#direct_pay_modal").remove();
1834    });
1835  });
1836
1837  $(".perpack").on("click", function () {
1838    var direct_pay_modal, selected_pack, selected_prop, include_feat, attr;
1839    selected_prop = $(this).attr("data-listing");
1840
1841    var price_pack = $(this)
1842      .parent()
1843      .parent()
1844      .find(".submit-price-total")
1845      .text();
1846
1847    attr = $(this).attr("data-isupgrade");
1848    if (typeof attr !== typeof undefined && attr !== false) {
1849      price_pack = $(this)
1850        .parent()
1851        .parent()
1852        .find(".submit-price-featured")
1853        .text();
1854    }
1855
1856    if (control_vars.where_curency === "after") {
1857      price_pack = price_pack + " " + control_vars.submission_curency;
1858    } else {
1859      price_pack = control_vars.submission_curency + " " + price_pack;
1860    }
1861
1862    price_pack = control_vars.direct_price + ": " + price_pack;
1863
1864    include_feat = ' data-include-feat="0" ';
1865    $("#send_direct_bill").attr("data-include-feat", 0);
1866    $("#send_direct_bill").attr("data-listing", selected_prop);
1867
1868    if ($(this).parent().find(".extra_featured").attr("checked")) {
1869      include_feat = ' data-include-feat="1" ';
1870      $("#send_direct_bill").attr("data-include-feat", 1);
1871    }
1872
1873    if (typeof attr !== typeof undefined && attr !== false) {
1874      include_feat = ' data-include-feat="1" ';
1875      $("#send_direct_bill").attr("data-include-feat", 1);
1876    }
1877
1878    window.scrollTo(0, 0);
1879    direct_pay_modal =
1880      '<div class="modal fade" id="direct_pay_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button><h2 class="modal-title_big">' +
1881      control_vars.direct_title +
1882      '</h2></div><div class="modal-body listing-submit"><span class="to_be_paid">' +
1883      price_pack +
1884      "</span><span>" +
1885      control_vars.direct_pay +
1886      '</span><div id="send_direct_bill" ' +
1887      include_feat +
1888      ' data-listing="' +
1889      selected_prop +
1890      '">' +
1891      control_vars.send_invoice +
1892      "</div></div></div></div></div></div>";
1893    jQuery("body").append(direct_pay_modal);
1894    jQuery("#direct_pay_modal").modal();
1895    wpestate_enable_direct_pay_perlisting();
1896
1897    $("#direct_pay_modal").on("hidden.bs.modal", function (e) {
1898      $("#direct_pay_modal").remove();
1899    });
1900  });
1901
1902  function wpestate_enable_direct_pay() {
1903    jQuery("#send_direct_bill").on("click", function () {
1904      jQuery("#send_direct_bill").unbind("click");
1905      var selected_pack, ajaxurl;
1906      selected_pack = jQuery(this).attr("data-pack");
1907      ajaxurl = ajaxcalls_vars.admin_url + "admin-ajax.php";
1908      var nonce = jQuery("#wprentals_payments_actions").val();
1909
1910      jQuery.ajax({
1911        type: "POST",
1912        url: ajaxurl,
1913        data: {
1914          action: "wpestate_direct_pay_pack",
1915          selected_pack: selected_pack,
1916          security: nonce,
1917        },
1918        success: function (data) {
1919          jQuery("#send_direct_bill").hide();
1920          jQuery("#direct_pay_modal .listing-submit span:nth-child(2)")
1921            .empty()
1922            .html(control_vars.direct_thx);
1923        },
1924        error: function (errorThrown) {},
1925      }); //end ajax
1926    });
1927  }
1928
1929  function wpestate_enable_direct_pay_perlisting() {
1930    jQuery("#send_direct_bill").unbind("click");
1931    jQuery("#send_direct_bill").on("click", function () {
1932      jQuery("#send_direct_bill").unbind("click");
1933      var selected_pack, ajaxurl, include_feat;
1934
1935      selected_pack = jQuery(this).attr("data-listing");
1936      include_feat = jQuery(this).attr("data-include-feat");
1937      ajaxurl = ajaxcalls_vars.admin_url + "admin-ajax.php";
1938
1939      var nonce = jQuery("#wprentals_payments_actions").val();
1940      jQuery.ajax({
1941        type: "POST",
1942        url: ajaxurl,
1943        data: {
1944          action: "wpestate_direct_pay_pack_per_listing",
1945          selected_pack: selected_pack,
1946          include_feat: include_feat,
1947          security: nonce,
1948        },
1949        success: function (data) {
1950          jQuery("#send_direct_bill").hide();
1951          jQuery("#direct_pay_modal .listing-submit span:nth-child(2)")
1952            .empty()
1953            .html(control_vars.direct_thx);
1954        },
1955        error: function (errorThrown) {},
1956      }); //end ajax
1957    });
1958  }
1959
1960  /////////////////////////////////////////////////////////////////////////////
1961  if (document.getElementById("imagelist")) {
1962    $("#imagelist").sortable({
1963      revert: true,
1964      update: function (event, ui) {
1965        var all_id, new_id;
1966        all_id = "";
1967        $("#imagelist .uploaded_images").each(function () {
1968          new_id = $(this).attr("data-imageid");
1969          if (typeof new_id != "undefined") {
1970            all_id = all_id + "," + new_id;
1971          }
1972        });
1973
1974        $("#attachid").val(all_id);
1975      },
1976    });
1977  }
1978
1979  $(".retina_ready").dense();
1980
1981  $("#user_tab_menu_trigger").on("click", function () {
1982    $("#user_tab_menu_container").toggle("200");
1983  });
1984
1985  $("#carousel-listing").on("slid.bs.carousel", function () {
1986    wpestate_show_capture_vertical();
1987    $("#carousel-listing div").removeClass("slideron");
1988    $("#slider_enable_slider").addClass("slideron");
1989  });
1990
1991  ////////////////////////////////////////////////////////////////////////////
1992  ///carousel show controls
1993  ////////////////////////////////////////////////////////////////////////////
1994
1995  ////////////////////////////////////////////////////////////////////////////
1996  ///prevent form submit on enter
1997  ////////////////////////////////////////////////////////////////////////////
1998  wpestate_prevent_enter_submit(
1999    "main_search",
2000    "search_location",
2001    "check_in",
2002    "check_out",
2003    "guest_no"
2004  );
2005  wpestate_prevent_enter_submit(
2006    "widget_search",
2007    "search_locationsidebar",
2008    "checkinwidget",
2009    "checkoutwidget",
2010    "guest_no_wid"
2011  );
2012  wpestate_prevent_enter_submit(
2013    "form-search-mobile",
2014    "search_location_mobile",
2015    "check_in_mobile",
2016    "check_out_mobile",
2017    "guest_no_mobile"
2018  );
2019
2020  ////////////////////////////////////////////////////////////////////////////
2021  ///unit clicks
2022  ////////////////////////////////////////////////////////////////////////////
2023  jQuery(".blog_unit_back ").on("click", function () {
2024    window.open($(this).find(".blog-title-link").attr("href"), "_self", false);
2025  });
2026
2027  jQuery(".calendar_pad").on("mouseenter", function (event) {
2028    var timeunix = $(this).attr("data-curent-date");
2029    jQuery(".calendar_pad[data-curent-date=" + timeunix + "]").addClass(
2030      "calendar-pad-hover"
2031    );
2032    jQuery(".calendar_pad_title[data-curent-date=" + timeunix + "]").addClass(
2033      "calendar-pad-hover"
2034    );
2035
2036    if (jQuery(this).hasClass("calendar-reserved")) {
2037      var reservation_data = $(this).find(".allinone_reservation");
2038      reservation_data.show();
2039      var internal_booking_id = parseFloat(
2040        $(this).find(".allinone_reservation").attr("data-internal-reservation"),
2041        10
2042      );
2043      if (!isNaN(internal_booking_id) && internal_booking_id != 0) {
2044        var ajaxurl = ajaxcalls_vars.admin_url + "admin-ajax.php";
2045
2046        var nonce = jQuery("#wprentals_allinone").val();
2047        jQuery.ajax({
2048          type: "POST",
2049          url: ajaxurl,
2050
2051          data: {
2052            action: "wpestate_get_booking_data",
2053            internal_booking_id: internal_booking_id,
2054            security: nonce,
2055          },
2056          success: function (data) {
2057            reservation_data.empty().append(data);
2058          },
2059          error: function (errorThrown) {},
2060        }); //end ajax
2061      }
2062    }
2063  });
2064
2065  jQuery(".calendar_pad").on("mouseleave", function (event) {
2066    $(this).find(".allinone_reservation").hide();
2067    var timeunix = $(this).attr("data-curent-date");
2068    $(".calendar_pad[data-curent-date=" + timeunix + "]").removeClass(
2069      "calendar-pad-hover"
2070    );
2071    $(".calendar_pad_title[data-curent-date=" + timeunix + "]").removeClass(
2072      "calendar-pad-hover"
2073    );
2074  });
2075
2076  ////////////////////////////////////////////////////////////////////////////
2077  // mobile menu
2078  ////////////////////////////////////////////////////////////////////////////
2079
2080  $(".all-elements").animate({
2081    minHeight: 100 + "%",
2082  });
2083  $(".header-tip").addClass("hide-header-tip");
2084
2085  $(".user_tab_menu_close").on("click", function () {
2086    $("#all_wrapper").removeAttr("style");
2087    $("#all_wrapper").removeClass("moved_mobile_user");
2088    $("#user_tab_menu_container").removeAttr("style");
2089  });
2090
2091  $(".mobilex-menu li").on("click", function (event) {
2092    event.stopPropagation();
2093    var selected;
2094    selected = $(this).find(".sub-menu:first");
2095    selected.slideToggle();
2096  });
2097
2098  $("#user_menu_u").on("click", function (event) {
2099    jQuery("#wpestate_header_shoping_cart").fadeOut(400);
2100    if ($("#user_menu_open").is(":visible")) {
2101      $("#user_menu_open").removeClass("iosfixed").fadeOut(400);
2102    } else {
2103      $("#user_menu_open").fadeIn(400);
2104    }
2105    event.stopPropagation();
2106  });
2107
2108  $("#shopping-cart").on("click", function (event) {
2109    $("#user_menu_open").removeClass("iosfixed").fadeOut(400);
2110    if ($("#wpestate_header_shoping_cart").is(":visible")) {
2111      jQuery("#wpestate_header_shoping_cart").fadeOut(400);
2112    } else {
2113      jQuery("#wpestate_header_shoping_cart").fadeIn(400);
2114    }
2115    event.stopPropagation();
2116  });
2117
2118  $(document).on("click", function (event) {
2119    var clicka;
2120    clicka = event.target.id;
2121    jQuery("#wpestate_header_shoping_cart").fadeOut(400);
2122    if (!$("#" + clicka).parents(".topmenux").length) {
2123      $("#user_menu_open").removeClass("iosfixed").hide(400);
2124    }
2125  });
2126
2127  ////////////////////////////////////////////////////////////////////////////
2128  // multiple cur set cookige
2129  ////////////////////////////////////////////////////////////////////////////
2130
2131  $(".list_sidebar_currency li").on("click", function () {
2132    var ajaxurl, data, pos, symbol, coef, curpos, symbol2;
2133    data = $(this).attr("data-value");
2134    pos = $(this).attr("data-pos");
2135    symbol = $(this).attr("data-symbol");
2136    coef = $(this).attr("data-coef");
2137    curpos = $(this).attr("data-curpos");
2138    symbol2 = $(this).attr("data-symbol2");
2139    var nonce = jQuery("#wprentals_change_currency").val();
2140    ajaxurl = ajaxcalls_vars.admin_url + "admin-ajax.php";
2141    jQuery.ajax({
2142      type: "POST",
2143      url: ajaxurl,
2144      data: {
2145        action: "wpestate_set_cookie_multiple_curr",
2146        curr: data,
2147        pos: pos,
2148        symbol: symbol,
2149        symbol2: symbol2,
2150        coef: coef,
2151        curpos: curpos,
2152        security: nonce,
2153      },
2154      success: function (data) {
2155        location.reload();
2156      },
2157      error: function (errorThrown) {},
2158    }); //end ajax
2159  });
2160
2161  ////////////////////////////////////////////////////////////////////////////
2162  ///prop list header
2163  ////////////////////////////////////////////////////////////////////////////
2164  // The float search form is position:absolute inside .header_media and pinned by
2165  // its BOTTOM edge (libs/customcss.php), so an in-flow amenities panel grows the
2166  // form UPWARD - behind the sticky menu whenever the hero is short (tax/category
2167  // pages). The panel is therefore taken out of the flow and dropped below the form
2168  // as an overlay, in style.css (#search_wrapper.with_search_form_float
2169  // .extended_search_check_wrapper). Out of flow means the form keeps its own
2170  // height, so the bottom pin never moves it and no JS repositioning is needed.
2171  $(".adv_extended_options_text").on("click", function () {
2172    var parent = $(this).parent();
2173    parent.find("#extended_search_check_filter").slideDown();
2174    parent.find(".extended_search_check_wrapper").slideDown();
2175    parent.find(".adv_extended_close_button").show();
2176    $(this).hide();
2177  });
2178
2179  $(".adv_extended_close_button").on("click", function () {
2180    $(this).hide();
2181    var parent = $(this).parent().parent();
2182    parent.find("#extended_search_check_filter").slideUp();
2183    parent.find(".extended_search_check_wrapper").slideUp();
2184    parent.find(".adv_extended_options_text").show();
2185  });
2186
2187  $("#adv_extended_options_show_filters").on("click", function () {
2188    $("#advanced_search_map_list").addClass("move_to_fixed");
2189    $("#extended_search_check_filter").slideDown();
2190    $("#adv_extended_close_adv").show();
2191    $("#adv_extended_options_text_adv").hide();
2192  });
2193
2194  wpestaste_check_in_out_enable("check_in", "check_out"); //advanced search
2195  wpestaste_check_in_out_enable("check_in_list", "check_out_list"); // half map search
2196  wpestaste_check_in_out_enable("booking_from_date", "booking_to_date"); // owner contact
2197  wpestaste_check_in_out_enable("check_in_mobile", "check_out_mobile"); //advanced search mobile
2198  wpestaste_check_in_out_enable("check_in_widget", "check_out_widget"); //search form widget
2199  wpestaste_check_in_out_enable("check_in_shortcode", "check_out_shortcode"); //search form shortcode search
2200
2201  // today = new Date();
2202  // jQuery("#testx").datepicker({ dateFormat: "yy-m-d" });
2203  $("#ui-datepicker-div").css("clip", "auto");
2204
2205  ////////////////////////////////////////////////////////////////////////////
2206  /// stripe
2207  ////////////////////////////////////////////////////////////////////////////
2208  $("#pack_select").change(function () {
2209    if ($(this).val() !== "") {
2210      $(".pay_disabled").removeClass("pay_disabled");
2211    } else {
2212      $(".payments_buttons_wrapper").addClass("pay_disabled");
2213    }
2214
2215    var stripe_pack_id, stripe_ammount, the_pick, labelstripe;
2216    $("#pack_select option:selected").each(function () {
2217      stripe_pack_id = $(this).val();
2218      stripe_ammount = parseFloat($(this).attr("data-price"));
2219      the_pick = $(this).attr("data-pick");
2220      labelstripe = $(this).text();
2221    });
2222
2223    $("#pack_id").val(stripe_pack_id);
2224    $("#pay_ammout").val(stripe_ammount);
2225
2226    $(".wpestate_stripe_pay_desc").html(
2227      control_vars.stripe_pay_for + " " + labelstripe
2228    );
2229    $("#wpestate_stripe_form_button_sumit").html(
2230      control_vars.stripe_pay +
2231        " " +
2232        stripe_ammount +
2233        " " +
2234        control_vars.submission_curency
2235    );
2236  });
2237
2238  $("#pack_recuring").on("click", function () {
2239    if ($(this).attr("checked")) {
2240      $("#stripe_form").append(
2241        '<input type="hidden" name="stripe_recuring" id="stripe_recuring" value="1">'
2242      );
2243    } else {
2244      $("#stripe_recuring").remove();
2245    }
2246  });
2247
2248  /////////////////////////////////////////////////////////////////////////////////////////
2249  // listing menu
2250  /////////////////////////////////////////////////////////////////////////////////////////
2251  $(".check_avalability, .property_menu_wrapper_hidden a").on(
2252    "click",
2253    function () {
2254      var target;
2255      if (
2256        location.pathname.replace(/^\//, "") ===
2257          this.pathname.replace(/^\//, "") &&
2258        location.hostname === this.hostname
2259      ) {
2260        target = $(this.hash);
2261        if (
2262          target.selector === "#carousel-control-theme-next" ||
2263          target.selector === "#carousel-control-theme-prev" ||
2264          target.selector === "#carousel-listing" ||
2265          target.selector === "#carousel-example-generic" ||
2266          target.selector === "#post_carusel_right"
2267        ) {
2268          return;
2269        }
2270        target = target.length
2271          ? target
2272          : $("[name=" + this.hash.slice(1) + "]");
2273        if (target.length) {
2274          $("html,body").animate(
2275            {
2276              scrollTop: target.offset().top - 140,
2277            },
2278            1000
2279          );
2280          return false;
2281        }
2282      }
2283    }
2284  );
2285
2286  componentForm = {
2287    establishment: "long_name",
2288    street_number: "short_name",
2289    route: "long_name",
2290    locality: "long_name",
2291    administrative_area_level_1: "long_name",
2292    administrative_area_level_2: "long_name",
2293    administrative_area_level_3: "long_name",
2294    administrative_area_level_4: "long_name",
2295    country: "long_name",
2296    postal_code: "short_name",
2297    postal_code_prefix: "short_name",
2298    neighborhood: "long_name",
2299    sublocality_level_1: "long_name",
2300    natural_feature: "long_name",
2301  };
2302
2303  wpestate_autocomplete_google("search_location");
2304  wpestate_autocomplete_google("search_locationshortcode");
2305  wpestate_autocomplete_google("search_locationmobile");
2306  wpestate_autocomplete_google("search_locationsidebar");
2307  wpestate_autocomplete_google("search_locationhalf");
2308
2309
2310
2311/**
2312 * WPEstate: Google Places Autocomplete (REST API v1)
2313 * --------------------------------------------------
2314 * Builds a fully custom, stylable autocomplete dropdown using the
2315 * Google Places REST API instead of the deprecated JS Autocomplete class.
2316 *
2317 * Behavior:
2318 * - Sends POST requests to `places.googleapis.com/v1/places:autocomplete`
2319 * - Displays results in a <ul> dropdown below the input
2320 * - On selection, fetches full place details and passes them
2321 *   to wprentals_fillInAddress_filter_google() for processing
2322 *
2323 * Requirements:
2324 * - control_vars.google_api_key  → valid API key with "Places API (New)" enabled
2325 * - wprentals_buildLegacyPlace() → function converting v1 data to legacy structure
2326 * - wprentals_fillInAddress_filter_google() → legacy address handling function
2327 */
2328let wpestatePlacesApiAlerted = false;
2329
2330async function wpestate_autocomplete_google(input_id) {
2331  
2332
2333  if ( parseInt(mapbase_vars.wprentals_places_type) == 3 ) { //open street
2334        return;
2335  }
2336
2337  // --- Safety checks ---
2338  if (typeof fetch !== "function" || !control_vars.google_api_key) {
2339    console.error("Missing Fetch or Google API key");
2340    return;
2341  }
2342
2343  const input = document.getElementById(input_id);
2344  if (!(input instanceof HTMLInputElement)) return;
2345
2346  // --- Detect which form variation we're editing (desktop, mobile, sidebar, etc.) ---
2347  let extension = "";
2348  if (input_id === "search_locationshortcode") extension = "shortcode";
2349  else if (input_id === "search_locationmobile") extension = "mobile";
2350  else if (input_id === "search_locationsidebar") extension = "sidebar";
2351  else if (input_id === "search_locationhalf") extension = "half";
2352
2353  // --- Create dropdown container below the input ---
2354  const dropdown = document.createElement("ul");
2355  dropdown.className = "wpestate-autocomplete-results"; // styled in CSS
2356  input.parentNode.style.position = "relative";
2357  input.parentNode.appendChild(dropdown);
2358
2359  let controller = null; // AbortController for cancelling in-flight requests
2360
2361  // === Handle typing in the input ===
2362  input.addEventListener("input", async function () {
2363    const query = input.value.trim();
2364
2365    // Hide dropdown for short input
2366    if (query.length < 3) {
2367      dropdown.style.display = "none";
2368      return;
2369    }
2370
2371    // Cancel any previous pending request
2372    if (controller) controller.abort();
2373    controller = new AbortController();
2374
2375    // Optional: restrict by country if configured
2376    const region =
2377      control_vars.limit_country === "yes" && control_vars.limit_country_select
2378        ? control_vars.limit_country_select
2379        : null;
2380
2381    try {
2382      // --- Autocomplete API request ---
2383      const res = await fetch("https://places.googleapis.com/v1/places:autocomplete", {
2384        method: "POST",
2385        signal: controller.signal,
2386        headers: {
2387          "Content-Type": "application/json",
2388          "X-Goog-Api-Key": control_vars.google_api_key,
2389          "X-Goog-FieldMask":
2390            "suggestions.placePrediction.text,suggestions.placePrediction.placeId"
2391        },
2392        body: JSON.stringify({
2393          input: query,
2394          // force English place names, matching the language=en the Maps JS API
2395          // was loaded with before the switch to the Places REST API
2396          languageCode: "en",
2397          ...(region ? { includedRegionCodes: region } : {})
2398        })
2399      });
2400
2401      if (!res.ok) {
2402        if (res.status === 403 && !wpestatePlacesApiAlerted) {
2403          wpestatePlacesApiAlerted = true;
2404          alert(
2405            control_vars.google_places_forbidden_message ||
2406              "Google Places Autocomplete request was rejected (HTTP 403). Please verify the API key, billing status, and Places API configuration."
2407          );
2408        }
2409        console.error(
2410          "Autocomplete fetch failed with status",
2411          res.status,
2412          res.statusText
2413        );
2414        return;
2415      }
2416
2417      const data = await res.json();
2418      const suggestions = data.suggestions || [];
2419
2420      // Clear previous results
2421      dropdown.innerHTML = "";
2422      if (!suggestions.length) {
2423        dropdown.style.display = "none";
2424        return;
2425      }
2426
2427      // --- Populate dropdown list ---
2428      suggestions.forEach((item) => {
2429        const text = item.placePrediction.text.text;
2430        const li = document.createElement("li");
2431        li.textContent = text;
2432        li.className = "wpestate-autocomplete-item"; // styled via CSS
2433        li.addEventListener("click", () =>
2434          handlePlaceSelect(item.placePrediction.placeId, text)
2435        );
2436        dropdown.appendChild(li);
2437      });
2438
2439      dropdown.style.display = "block";
2440    } catch (err) {
2441      if (err.name !== "AbortError")
2442        console.error("Autocomplete fetch failed:", err);
2443    }
2444  });
2445
2446  // --- Hide dropdown when clicking outside ---
2447  document.addEventListener("click", (e) => {
2448    if (!dropdown.contains(e.target) && e.target !== input) {
2449      dropdown.style.display = "none";
2450    }
2451  });
2452
2453  // === Handle user selecting a place ===
2454  async function handlePlaceSelect(placeId, text) {
2455    input.value = text;
2456    dropdown.style.display = "none";
2457
2458    try {
2459      // --- Fetch full Place details ---
2460      // languageCode=en keeps the selected address in English, the same as the
2461      // autocomplete list above it
2462      const res = await fetch(`https://places.googleapis.com/v1/places/${placeId}?languageCode=en`, {
2463        method: "GET",
2464        headers: {
2465          "X-Goog-Api-Key": control_vars.google_api_key,
2466          "X-Goog-FieldMask":
2467            "id,formattedAddress,displayName,location,viewport,adrFormatAddress,addressComponents"
2468        }
2469      });
2470
2471      if (!res.ok) {
2472        if (res.status === 403 && !wpestatePlacesApiAlerted) {
2473          wpestatePlacesApiAlerted = true;
2474          alert(
2475            control_vars.google_places_forbidden_message ||
2476              "Google Places Details request was rejected (HTTP 403). Please verify the API key, billing status, and Places API configuration."
2477          );
2478        }
2479        console.error(
2480          "Place details fetch failed with status",
2481          res.status,
2482          res.statusText
2483        );
2484        return;
2485      }
2486
2487      const place = await res.json();
2488
2489      // --- Convert new API format to legacy WPEstate structure ---
2490      const legacyPlace = wprentals_buildLegacyPlace(place);
2491
2492      // --- Pass to existing legacy handler ---
2493      wprentals_fillInAddress_filter_google(legacyPlace, extension);
2494    } catch (err) {
2495      console.error("Place details fetch failed:", err);
2496    }
2497  }
2498}
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509  /**
2510 * Initialize Google Places Autocomplete using the new PlaceAutocompleteElement API.
2511 * Replaces a standard input with the new AutocompleteElement and ensures backward
2512 * compatibility with legacy code by converting the new API response format to the
2513 * legacy PlaceResult format expected by wprentals_fillInAddress_filter_google().
2514 *
2515 * @param {string} input_id - The ID of the input element to convert into a Google Places Autocomplete field.
2516 */
2517function wpestate_autocomplete_google2(input_id) {
2518  // Ensure Google Maps library is loaded and the 'places' feature is enabled
2519  if (
2520    typeof google === "object" &&
2521    typeof google.maps === "object" &&
2522    parseInt(mapbase_vars.wprentals_places_type) == 1
2523  ) {
2524    var input, autocompleteElement, extension;
2525    input = document.getElementById(input_id);
2526
2527    // Proceed only if we actually have an input element
2528    if (input instanceof HTMLInputElement) {
2529      // Identify which search input variation is being initialized (for multi-instance forms)
2530      extension = "";
2531      if (input_id == "search_locationshortcode") {
2532        extension = "shortcode";
2533      } else if (input_id == "search_locationmobile") {
2534        extension = "mobile";
2535      } else if (input_id == "search_locationsidebar") {
2536        extension = "sidebar";
2537      } else if (input_id == "search_locationhalf") {
2538        extension = "half";
2539      }
2540
2541      // Define autocomplete configuration
2542      var options = {
2543        types: ["geocode"] // restrict results to real-world addresses
2544      };
2545
2546      // Apply country restriction if specified in global control_vars
2547      if (
2548        control_vars.limit_country === "yes" &&
2549        control_vars.limit_country_select != ""
2550      ) {
2551        options.includedRegionCodes = [control_vars.limit_country_select];
2552      }
2553
2554     // Create new Google Maps Places Autocomplete Element
2555      autocompleteElement = new google.maps.places.PlaceAutocompleteElement(options);
2556
2557      // Transfer class and ID for styling/logic consistency
2558      autocompleteElement.id = input_id;
2559      if (input.className) {
2560        autocompleteElement.className = input.className;
2561      }
2562
2563      // Replace the original input with the new element
2564      input.parentNode.replaceChild(autocompleteElement, input);
2565
2566      // Now that it's attached, set placeholder
2567      autocompleteElement.setAttribute("placeholder", input.placeholder || "Where do you want to go ?");
2568
2569      
2570
2571      /**
2572       * Listen for the 'gmp-select' event — triggered when the user selects a place suggestion.
2573       */
2574      autocompleteElement.addEventListener("gmp-select", async function (event) {
2575        // Convert the selected prediction to a full Place object
2576        var place = event.placePrediction.toPlace();
2577
2578        // Fetch fields from the new API – this is required before reading properties
2579        await place.fetchFields({
2580          fields: [
2581            "addressComponents",
2582            "formattedAddress",
2583            "displayName",
2584            "location",
2585            "viewport",
2586            "adrFormatAddress"
2587          ]
2588        });
2589
2590        // Convert new API response into the legacy structure expected by WPRentals
2591        const legacyPlace = wprentals_buildLegacyPlace(place);
2592
2593        // Pass the normalized object to the old function (no modification needed)
2594        wprentals_fillInAddress_filter_google(legacyPlace, extension);
2595      });
2596    }
2597  }
2598}
2599
2600/**
2601 * Converts the new Google Places API (2023+) Place object to the legacy PlaceResult structure
2602 * used by older WPRentals scripts.
2603 *
2604 * @param {object} place - The Place object returned by place.fetchFields().
2605 * @returns {object} legacyPlace - A backward-compatible PlaceResult-style object.
2606 */
2607function wprentals_buildLegacyPlace(place) {
2608  // Map new API addressComponents to legacy format (long_name, short_name, types)
2609  const legacyAddressComponents = (place.addressComponents || []).map(c => {
2610    let types = [];
2611
2612    // Preserve or reconstruct component types
2613    if (Array.isArray(c.types) && c.types.length) {
2614      types = c.types;
2615    } else if (c.type) {
2616      types = [c.type];
2617    }
2618
2619    // Convert new "administrative_area" to old-style level notation
2620    const t = c.type || (c.types && c.types[0]) || "";
2621    if (t === "administrative_area") {
2622      if (c.level) {
2623        types = [`administrative_area_level_${c.level}`];
2624      } else {
2625        types = ["administrative_area_level_1"]; // default fallback
2626      }
2627    }
2628
2629    // Return component in the same structure the old code expects
2630    return {
2631      long_name: c.longText || "",
2632      short_name: c.shortText || "",
2633      types: types
2634    };
2635  });
2636
2637  // Build final legacy-compatible place object
2638  return {
2639    address_components: legacyAddressComponents,
2640    formatted_address: place.formattedAddress || "",
2641    name: place.displayName || "",
2642    geometry: {
2643      location: place.location || null,
2644      viewport: place.viewport || null
2645    },
2646    adr_address: place.adrFormatAddress || place.formattedAddress || ""
2647  };
2648}
2649
2650/**
2651 * Fills in WPRentals form fields based on a Google Place object (legacy format).
2652 * This function remains unchanged from the old API implementation.
2653 * It reads address components and assigns them to hidden form fields
2654 * for area, city, country, and administrative areas.
2655 *
2656 * @param {object} place - The legacy PlaceResult-style object.
2657 * @param {string} extension - Optional suffix identifying which search form to populate.
2658 */
2659function wprentals_fillInAddress_filter_google(place, extension) {
2660
2661  var i, addressType, val, is_google_map, have_city, admin_area;
2662  have_city = 0;
2663  admin_area = "";
2664
2665  // Reset form fields before populating
2666  $("#advanced_area" + extension).val("");
2667  $("#advanced_city" + extension).val("");
2668  $("#advanced_country" + extension).val("");
2669  $("#search_location_area" + extension).val("");
2670  $("#search_location_city" + extension).val("");
2671  $("#search_location_country" + extension).val("");
2672  $("#property_admin_area" + extension).val("");
2673
2674  // Loop through all address components (country, locality, administrative_area_level_X, etc.)
2675  for (i = 0; i < place.address_components.length; i++) {
2676    addressType = place.address_components[i].types[0];
2677
2678    // Use componentForm map to extract long_name or short_name depending on type
2679    val = place.address_components[i][componentForm[addressType]];
2680
2681    // Normalize the value (convert to lowercase and replace spaces with dashes
2681)
2682    if (typeof val !== "undefined") {
2683      val = val.toLowerCase();
2684      val = val.split(" ").join("-");
2685    }
2686
2687    // Populate appropriate fields depending on address type
2688    if (
2689      addressType === "neighborhood" ||
2690      addressType === "sublocality_level_1"
2691    ) {
2692      $("#advanced_area" + extension).attr("data-value", val);
2693      $("#advanced_area" + extension).val(val);
2694      $("#search_location_area" + extension).val(val);
2695    } else if (addressType === "administrative_area_level_4") {
2696      admin_area = wpestate_build_admin_area(admin_area, val);
2697    } else if (addressType === "administrative_area_level_3") {
2698      admin_area = wpestate_build_admin_area(admin_area, val);
2699    } else if (addressType === "administrative_area_level_2") {
2700      admin_area = wpestate_build_admin_area(admin_area, val);
2701    } else if (addressType === "administrative_area_level_1") {
2702      admin_area = wpestate_build_admin_area(admin_area, val);
2703    } else if (addressType === "locality") {
2704      $("#advanced_city" + extension).attr("data-value", val);
2705      $("#advanced_city" + extension).val(val);
2706      $("#search_location_city" + extension).val(val);
2707      if (val !== "") {
2708        have_city = 1;
2709      }
2710    } else if (
2711      addressType === "country" ||
2712      addressType === "natural_feature"
2713    ) {
2714      $("#advanced_country" + extension).attr("data-value", val);
2715      $("#advanced_country" + extension).val(val);
2716      $("#search_location_country" + extension).val(val);
2717    }
2718  }
2719
2720  // Fallback: if no "locality" found, try extracting city from adr_address HTML
2721  if (have_city === 0) {
2722    wpestate_second_measure_city(
2723      "advanced_city" + extension,
2724      place.adr_address
2725    );
2726    wpestate_second_measure_city(
2727      "search_location_city" + extension,
2728      place.adr_address
2729    );
2730  }
2731
2732  // If the map-based search is active, trigger live search update
2733  if (jQuery("#advanced_search_map_list").length > 0) {
2734    wpestate_start_filtering_ajax_map(1);
2735  }
2736
2737  // Handle map integration if Google Map mode is enabled
2738  is_google_map = parseFloat(
2739    jQuery("#isgooglemap").attr("data-isgooglemap"),
2740    10
2741  );
2742  if (is_google_map === 1) {
2743    var guest_val = $(this).attr("data-value");
2744    // Optionally trigger live filtering on main map
2745    // start_filtering_ajax_on_main_map(guest_val);
2746  }
2747}
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758  function wpestate_autocomplete_google_old(input_id) {
2759    if (
2760      typeof google === "object" &&
2761      typeof google.maps === "object" &&
2762      parseInt(mapbase_vars.wprentals_places_type) == 1
2763    ) {
2764      var input, defaultBounds, autocomplete_normal, extension;
2765      input = document.getElementById(input_id);
2766      if (input instanceof HTMLInputElement) {
2767        extension = "";
2768        if (input_id == "search_locationshortcode") {
2769          extension = "shortcode";
2770        } else if (input_id == "search_locationmobile") {
2771          extension = "mobile";
2772        } else if (input_id == "search_locationsidebar") {
2773          extension = "sidebar";
2774        } else if (input_id == "search_locationhalf") {
2775          extension = "half";
2776        }
2777
2778        defaultBounds = new google.maps.LatLngBounds(
2779          new google.maps.LatLng(-90, -180),
2780          new google.maps.LatLng(90, 180)
2781        );
2782        var options = {
2783          bounds: defaultBounds,
2784          types: ["geocode"],
2785        };
2786
2787        autocomplete_normal = new google.maps.places.Autocomplete(
2788          input,
2789          options
2790        );
2791        if (
2792          control_vars.limit_country === "yes" &&
2793          control_vars.limit_country_select != ""
2794        ) {
2795          autocomplete_normal.setComponentRestrictions({
2796            country: [control_vars.limit_country_select],
2797          });
2798        }
2799
2800        google.maps.event.addListener(
2801          autocomplete_normal,
2802          "place_changed",
2803          function () {
2804            var place = autocomplete_normal.getPlace();
2805            wprentals_fillInAddress_filter_google(place, extension);
2806          }
2807        );
2808      }
2809    }
2810  }
2811
2812
2813
2814
2815  function wpestate_build_admin_area(admin_area, val) {
2816    if (admin_area === "") {
2817      admin_area = admin_area + val;
2818    } else {
2819      admin_area = admin_area + ", " + val;
2820    }
2821
2822    $(
2823      "#property_admin_area,#property_admin_areasidebar,#property_admin_areashortcode,#property_admin_areamobile"
2824    ).val(admin_area);
2825
2826    return admin_area;
2827  }
2828
2829  ////////
2830  function wpestate_second_measure_city(stringplace, adr_address) {
2831    var new_city;
2832    new_city = $(adr_address).filter("span.locality").html();
2833
2834    $("#" + stringplace).val(new_city);
2835  }
2836
2837  function wpestate_fillInAddress() {
2838    var place, adr, country;
2839    place = autocomplete.getPlace();
2840    adr = place["address_components"];
2841    country = adr[adr.length - 1]["long_name"];
2842    document.getElementById("property_city").value = place["name"];
2843    document.getElementById("property_country").value = country;
2844  }
2845
2846  $("#check_out").change(function () {
2847    if ($("#check_in").val() !== "") {
2848      var guest_val = $(this).attr("data-value");
2849      // start_filtering_ajax_on_main_map(guest_val);
2850    }
2851  });
2852
2853  $("#guest_no_main_list li").on("click", function () {
2854    var guest_val = $(this).attr("data-value");
2855    //  start_filtering_ajax_on_main_map(guest_val);
2856  });
2857
2858  ////////////////////////////////////////////////////////////////////////////
2859  // top bar login
2860  ////////////////////////////////////////////////////////////////////////////
2861  $("#topbarlogin,#wprentals_elementor_login").on("click", function (event) {
2862    wpestate_show_login_form(1, 0, 0);
2863  });
2864
2865  $("#topbarregister,#wprentals_elementor_register").on(
2866    "click",
2867    function (event) {
2868      wpestate_show_login_form(2, 0, 0);
2869    }
2870  );
2871
2872  ////////////////////////////////////////////////////////////////////////////
2873  /// slider price
2874  ////////////////////////////////////////////////////////////////////////////
2875
2876  price_low_val = parseFloat($("#price_low").val(), 10);
2877  price_max_val = parseFloat($("#price_max").val(), 10);
2878
2879  if (jQuery("#slider_price").length > 0) {
2880    wpestate_enable_slider(
2881      "slider_price",
2882      "price_low",
2883      "price_max",
2884      "amount",
2885      my_custom_curr_pos,
2886      my_custom_curr_symbol,
2887      my_custom_curr_cur_post,
2888      my_custom_curr_coef,
2889      my_custom_curr_label
2890    );
2891  }
2892
2893  if (jQuery("#slider_price_widget").length > 0) {
2894    wpestate_enable_slider(
2895      "slider_price_widget",
2896      "price_low_widget",
2897      "price_max_widget",
2898      "amount_wd",
2899      my_custom_curr_pos,
2900      my_custom_curr_symbol,
2901      my_custom_curr_cur_post,
2902      my_custom_curr_coef,
2903      my_custom_curr_label
2904    );
2905  }
2906  if (jQuery("#slider_price_sh").length > 0) {
2907    wpestate_enable_slider(
2908      "slider_price_sh",
2909      "price_low_sh",
2910      "price_max_sh",
2911      "amount_sh",
2912      my_custom_curr_pos,
2913      my_custom_curr_symbol,
2914      my_custom_curr_cur_post,
2915      my_custom_curr_coef,
2916      my_custom_curr_label
2917    );
2918  }
2919  if (jQuery("#slider_price_mobile").length > 0) {
2920    wpestate_enable_slider(
2921      "slider_price_mobile",
2922      "price_low_mobile",
2923      "price_max_mobile",
2924      "amount_mobile",
2925      my_custom_curr_pos,
2926      my_custom_curr_symbol,
2927      my_custom_curr_cur_post,
2928      my_custom_curr_coef,
2929      my_custom_curr_label
2930    );
2931  }
2932
2933  if (jQuery("#wpestate_slider_radius").length > 0) {
2934    wpestate_enable_slider_radius(
2935      "wpestate_slider_radius",
2936      control_vars.min_geo_radius,
2937      control_vars.max_geo_radius,
2938      control_vars.initial_radius
2939    );
2940  }
2941
2942  function wpestate_slider_control_left_function(element) {
2943    var step_size, margin_left, new_value, last_element, base_value, parent;
2944    parent = element.parent();
2945    step_size = parent.find(".shortcode_slider_list").width();
2946    margin_left = parseFloat(
2947      parent.find(".shortcode_slider_list").css("margin-left"),
2948      10
2949    );
2950    new_value = margin_left - 389;
2951    base_value = 3;
2952    parent.find(".shortcode_slider_list").css("margin-left", new_value + "px");
2953    last_element = parent.find(".shortcode_slider_list li:last-child");
2954    parent.find(".shortcode_slider_list li:last-child").remove();
2955    parent.find(".shortcode_slider_list").prepend(last_element);
2956    wpestate_restart_js_after_ajax();
2957    parent.find(".shortcode_slider_list").animate(
2958      {
2959        "margin-left": base_value,
2960      },
2961      800,
2962      function () {}
2963    );
2964  }
2965
2966  function wpestate_slider_control_right_function(elemenet) {
2967    var step_size, margin_left, new_value, first_element, parent;
2968    parent = elemenet.parent();
2969    step_size = parent.find(".shortcode_slider_list").width();
2970    margin_left = parseFloat(
2971      parent.find(".shortcode_slider_list").css("margin-left"),
2972      10
2973    );
2974    new_value = margin_left - 389;
2975    parent.find(".shortcode_slider_list").animate(
2976      {
2977        "margin-left": new_value,
2978      },
2979      800,
2980      function () {
2981        first_element = parent.find(".shortcode_slider_list li:nth-child(1)");
2982        parent.find(".shortcode_slider_list li:nth-child(1)").remove();
2983        parent.find(".shortcode_slider_list").append(first_element);
2984        parent.find(".shortcode_slider_list").css("margin-left", 3 + "px");
2985
2986        wpestate_restart_js_after_ajax();
2987      }
2988    );
2989  }
2990
2991  $(".slider_control_left").on("click", function () {
2992    wpestate_slider_control_left_function($(this));
2993    //bLazy.revalidate();
2994  });
2995
2996  $(".slider_control_right").on("click", function () {
2997    wpestate_slider_control_right_function($(this));
2998    //bLazy.revalidate();
2999  });
3000
3001  $(".slider_container ").each(function () {
3002    var element, wrapper;
3003    element = $(this).find(".slider_control_right");
3004    wrapper = $(this).find(".shortcode_slider_wrapper").attr("data-auto");
3005
3006    autoscroll_slider = parseFloat(wrapper, 10);
3007    if (autoscroll_slider !== 0) {
3008      setInterval(function () {
3009        wpestate_slider_control_right_function(element);
3010      }, autoscroll_slider);
3011    }
3012  });
3013
3014  $("#login_user_topbar,#login_pwd_topbar").on("focus", function (e) {
3015    $("#user_menu_open").addClass("iosfixed");
3016  });
3017
3018  $(
3019    "#estate-carousel .slider-content h3 a,#estate-carousel .slider-content .read_more "
3020  ).on("click", function () {
3021    var new_link;
3022    new_link = $(this).attr("href");
3023    window.open(new_link, "_self", false);
3024  });
3025
3026  ////////////////////////////////////////////////////////////////////////////////////////////
3027  ///city-area-selection
3028  ///////////////////////////////////////////////////////////////////////////////////////////
3029  $("#filter_city li").on("click", function (event) {
3030    event.preventDefault();
3031    var pick, value_city, parent, selected_city, is_city, area_value;
3032    value_city = String($(this).attr("data-value2")).toLowerCase();
3033
3034    $("#filter_area li").each(function () {
3035      is_city = String($(this).attr("data-parentcity")).toLowerCase();
3036      is_city = is_city.replace(" ", "-");
3037      area_value = String($(this).attr("data-value")).toLowerCase();
3038
3039      if (
3040        is_city === value_city ||
3041        value_city === "all" ||
3042        is_city === "undefined"
3043      ) {
3044        $(this).show();
3045      } else {
3046        $(this).hide();
3047      }
3048    });
3049  });
3050
3051  $("#sidebar_filter_city li").on("click", function (event) {
3052    event.preventDefault();
3053    var pick, value_city, parent, selected_city, is_city, area_value;
3054    value_city = String($(this).attr("data-value2")).toLowerCase();
3055    $("#sidebar_filter_area li").each(function () {
3056      is_city = String($(this).attr("data-parentcity")).toLowerCase();
3057      is_city = is_city.replace(" ", "-");
3058      area_value = String($(this).attr("data-value")).toLowerCase();
3059      if (is_city === value_city || value_city === "all") {
3060        $(this).show();
3061      } else {
3062        $(this).hide();
3063      }
3064    });
3065  });
3066
3067  $("#adv-search-city li").on("click", function (event) {
3068    event.preventDefault();
3069    var pick, value_city, parent, selected_city, is_city, area_value;
3070    value_city = String($(this).attr("data-value2")).toLowerCase();
3071
3072    $("#adv-search-area li").each(function () {
3073      is_city = String($(this).attr("data-parentcity")).toLowerCase();
3074      is_city = is_city.replace(" ", "-");
3075      area_value = String($(this).attr("data-value")).toLowerCase();
3076      if (is_city === value_city || value_city === "all") {
3077        $(this).show();
3078      } else {
3079        $(this).hide();
3080      }
3081    });
3082  });
3083
3084  $("#property_city_submit").change(function () {
3085    var city_value, area_value;
3086    city_value = $(this).val();
3087    all_browsers_stuff = $("#property_area_submit_hidden").html();
3088    $("#property_area_submit").empty().append(all_browsers_stuff);
3089    $("#property_area_submit option").each(function () {
3090      area_value = $(this).attr("data-parentcity");
3091      if (city_value === area_value || area_value === "all") {
3092        //  $(this).show();
3093      } else {
3094        //$(this).hide();
3095        $(this).remove();
3096      }
3097    });
3098  });
3099
3100  $("#adv_short_select_city li").on("click", function (event) {
3101    event.preventDefault();
3102    var pick, value_city, parent, selected_city, is_city, area_value;
3103    value_city = String($(this).attr("data-value2")).toLowerCase();
3104    $("#adv_short_select_area li").each(function () {
3105      is_city = String($(this).attr("data-parentcity")).toLowerCase();
3106      is_city = is_city.replace(" ", "-");
3107      area_value = String($(this).attr("data-value")).toLowerCase();
3108      if (is_city === value_city || value_city === "all") {
3109        $(this).show();
3110      } else {
3111        $(this).hide();
3112      }
3113    });
3114  });
3115
3116  $("#mobile-adv-city li").on("click", function (event) {
3117    event.preventDefault();
3118    var pick, value_city, parent, selected_city, is_city, area_value;
3119    value_city = String($(this).attr("data-value2")).toLowerCase();
3120    $("#mobile-adv-area li").each(function () {
3121      is_city = String($(this).attr("data-parentcity")).toLowerCase();
3122      is_city = is_city.replace(" ", "-");
3123      area_value = String($(this).attr("data-value")).toLowerCase();
3124      if (is_city === value_city || value_city === "all") {
3125        $(this).show();
3126      } else {
3127        $(this).hide();
3128      }
3129    });
3130  });
3131  ////////////////////////////////////////////////////////////////////////////////////////////
3132  ///mobile
3133  ///////////////////////////////////////////////////////////////////////////////////////////
3134  $("#adv-search-header-mobile").on("click", function () {
3135    $("#adv-search-mobile").toggle("300");
3136  });
3137
3138  ////////////////////////////////////////////////////////////////////////////////////////////
3139  ///navigational links
3140  ///////////////////////////////////////////////////////////////////////////////////////////
3141  $(".nav-prev,.nav-next ").on("click", function (event) {
3142    event.preventDefault();
3143    var link = $(this).find("a").attr("href");
3144    window.open(link, "_self", false);
3145  });
3146
3147  $(".featured_agent_details_wrapper, .agent-listing-img-wrapper").on(
3148    "click",
3149    function () {
3150      var newl = $(this).attr("data-link");
3151      window.open(newl, "_self", false);
3152    }
3153  );
3154
3155  $(".see_my_list_featured").on("click", function (event) {
3156    event.stopPropagation();
3157  });
3158
3159  $(".featured_cover").on("click", function () {
3160    var newl = $(this).attr("data-link");
3161    window.open(newl, "_self", false);
3162  });
3163
3164  jQuery(".agent_face").on("mouseenter", function (event) {
3165    $(this).find(".agent_face_details").fadeIn("500");
3166  });
3167
3168  jQuery(".agent_face").on("mouseleave", function (event) {
3169    $(this).find(".agent_face_details").fadeOut("500");
3170  });
3171
3172  jQuery("#imagelist i").on("click", function () {
3173    var curent = "";
3174    jQuery(this).parent().remove();
3175    jQuery("#imagelist .uploaded_images").each(function () {
3176      curent = curent + "," + jQuery(this).attr("data-imageid");
3177    });
3178    jQuery("#attachid").val(curent);
3179  });
3180
3181  jQuery("#imagelist img").dblclick(function () {
3182    jQuery("#imagelist .uploaded_images .thumber").each(function () {
3183      jQuery(this).remove();
3184    });
3185    jQuery(".fa-star").remove();
3186    jQuery(this).parent().append('<i class="fas thumber fa-star"></i>');
3187    jQuery("#attachthumb").val(jQuery(this).parent().attr("data-imageid"));
3188  });
3189
3190  $(".advanced_search_sidebar li").on("click", function (event) {
3191    event.preventDefault();
3192    var pick, value, parent;
3193    pick = $(this).text();
3194    value = $(this).attr("data-value");
3195    parent = $(this).parent().parent();
3196    parent
3197      .find(".filter_menu_trigger")
3198      .text(pick)
3199      .append('<span class="caret caret_sidebar"></span>')
3200      .attr("data-value", value);
3201    parent.find("input").val(value);
3202  });
3203
3204  $(".adv-search-mobile li").on("click", function (event) {
3205    event.preventDefault();
3206    var pick, value, parent;
3207    pick = $(this).text();
3208    value = $(this).attr("data-value");
3209    parent = $(this).parent().parent();
3210    parent
3211      .find(".filter_menu_trigger")
3212      .text(pick)
3213      .append('<span class="caret caret_filter"></span>')
3214      .attr("data-value", value);
3215    parent.find("input").val(value);
3216  });
3217
3218  $("#switch").on("click", function () {
3219    $(".main_wrapper").toggleClass("wide");
3220  });
3221
3222  $(
3223    "#accordion_prop_addr, #accordion_prop_details, #accordion_prop_features, #yelp_details"
3224  ).on("shown.bs.collapse", function () {
3225    $(this).find("h4").removeClass("carusel_closed");
3226  });
3227
3228  $(
3229    "#accordion_prop_addr, #accordion_prop_details, #accordion_prop_features, #yelp_details"
3230  ).on("hidden.bs.collapse", function () {
3231    $(this).find("h4").addClass("carusel_closed");
3232  });
3233
3234  $(
3235    ".search_wr_elementor li,.advanced_search_form_wrapper li,#adv-search-5 li,#adv-search-4 li,#adv-search-3 li,#adv-search-1 li,#advanced_search_shortcode li,#advanced_search_map_list li"
3236  ).on("click", function () {
3237    var pick, value, parent;
3238    pick = $(this).text();
3239    value = $(this).attr("data-value");
3240    parent = $(this).parent().parent();
3241    parent
3242      .find(".filter_menu_trigger")
3243      .text(pick)
3244      .append('<span class="caret caret_filter"></span>')
3245      .attr("data-value", value);
3246    parent.find("input").val(value);
3247  });
3248
3249  $(".advanced_search_map_list_container li").on("click", function () {
3250    wpestate_start_filtering_ajax_map(1);
3251  });
3252
3253  $('.advanced_search_map_list_container_trigger input[type="text"]').change(
3254    function () {
3255      if (
3256        $(this).attr("id") !== "search_location" &&
3257        $(this).attr("id") !== "check_in" &&
3258        $(this).attr("id") !== "search_locationhalf" &&
3259        $(this).attr("id") !== "search_locationsidebar" &&
3260        $(this).attr("id") !== "search_location" &&
3261        $(this).attr("id") !== "search_locationmobile"
3262      ) {
3263        wpestate_start_filtering_ajax_map(1);
3264      }
3265    }
3266  );
3267
3268  $("#check_out_list").change(function () {
3269    var start_date = $("#check_in_list").val();
3270    if (start_date !== "") {
3271      wpestate_start_filtering_ajax_map(1);
3272    }
3273  });
3274
3275  $("#check_out_list").change(function () {
3276    var start_date = $("#check_in_list").val();
3277    if (start_date !== "") {
3278      wpestate_start_filtering_ajax_map(1);
3279    }
3280  });
3281
3282  $('.extended_search_check_wrapper input[type="checkbox"]').on(
3283    "click",
3284    function () {
3285      wpestate_start_filtering_ajax_map(1);
3286    }
3287  );
3288
3289  $("#google_map_prop_list_sidebar #slider_price").slider({
3290    stop: function (event, ui) {
3291      wprentals_show_pins();
3292      wpestate_start_filtering_ajax_map(1);
3293    },
3294  });
3295
3296  $("#showinpage,#showinpage_mobile").on("click", function (event) {
3297    event.preventDefault();
3298    if ($("#gmap-full").hasClass("spanselected")) {
3299      $("#gmap-full").trigger("click");
3300    }
3301    wpestate_start_filtering(1);
3302  });
3303
3304  $("#openmap").on("click", function () {
3305    if ($(this).find("i").hasClass("fa-angle-down")) {
3306      $(this)
3307        .empty()
3308        .append('<i class="fas fa-angle-up"></i>' + control_vars.close_map);
3309      if (control_vars.show_adv_search_map_close === "no") {
3310        $(".search_wrapper").addClass("adv1_close");
3311        adv_search_click();
3312      }
3313    } else {
3314      $(this)
3315        .empty()
3316        .append('<i class="fas fa-angle-down"></i>' + control_vars.open_map);
3317    }
3318    wpestate_new_open_close_map(2);
3319  });
3320
3321  $("#gmap-full").on("click", function () {
3322    if ($("#gmap_wrapper").hasClass("fullmap")) {
3323      $("#gmap_wrapper")
3324        .removeClass("fullmap")
3325        .css("height", wrap_h + "px");
3326      $("#googleMap")
3327        .removeClass("fullmap")
3328        .css("height", map_h + "px");
3329      $("#search_wrapper").removeClass("fullscreen_search");
3330      $("#search_wrapper").removeClass("fullscreen_search_open");
3331      $(".master_header").removeClass("hidden");
3332      $("#gmap-controls-wrapper ").removeClass("fullscreenon");
3333      $(".content_wrapper,#colophon,#openmap").show();
3334      $("#gmap-controls-wrapper ").removeClass("fullscreenon");
3335
3336      $("body,html").animate(
3337        {
3338          scrollTop: 0,
3339        },
3340        "slow"
3341      );
3342      $("#openmap").show();
3343      $(this).removeClass("spanselected");
3344    } else {
3345      wrap_h = $("#gmap_wrapper").outerHeight();
3346      map_h = $("#googleMap").outerHeight();
3347      $("#gmap_wrapper,#googleMap").css("height", "100%").addClass("fullmap");
3348      $("#search_wrapper").addClass("fullscreen_search");
3349      $(".master_header ").addClass("hidden");
3350      $(".content_wrapper,#colophon,#openmap").hide();
3351      $("#gmap-controls-wrapper ").addClass("fullscreenon");
3352      $(this).addClass("spanselected");
3353    }
3354
3355    if ($("#google_map_prop_list_wrapper").hasClass("halfmapfull")) {
3356      $("#google_map_prop_list_wrapper").removeClass("halfmapfull");
3357      $("#google_map_prop_list_wrapper").removeClass("halfmapfullx");
3358      $(".master_header").removeClass("hidden");
3359      $("#gmap-controls-wrapper ").removeClass("fullscreenon");
3360      $(this).removeClass("spanselected");
3361    } else {
3362      $("#google_map_prop_list_wrapper").addClass("halfmapfull");
3363      $("#google_map_prop_list_wrapper").addClass("halfmapfullx");
3364    }
3365
3366    wprentals_map_resize();
3367  });
3368
3369  $("#street-view").on("click", function () {
3370    wpestate_toggleStreetView();
3371  });
3372
3373  $(".videoitem iframe").on("click", function () {
3374    $(".estate_video_control").remove();
3375  });
3376
3377  jQuery(
3378    ".icon-fav, .share_list,  .compare-action, .dashboad-tooltip, .pack-name, .normal_list_no, .mess_tooltip"
3379  ).on("mouseenter", function (event) {
3380    $(this).tooltip("show");
3381  });
3382  jQuery(
3383    ".icon-fav, .share_list,  .compare-action, .dashboad-tooltip, .pack-name, .normal_list_no, .mess_tooltip"
3384  ).on("mouseleave", function (event) {
3385    $(this).tooltip("hide");
3386  });
3387
3388  $(".share_list").on("click", function (event) {
3389    event.stopPropagation();
3390    var sharediv = $(this).parent().find(".share_unit");
3391    sharediv.toggle();
3392    $(this).toggleClass("share_on");
3393  });
3394
3395  $(".backtop").on("click", function (event) {
3396    event.preventDefault();
3397    $("body,html").animate(
3398      {
3399        scrollTop: 0,
3400      },
3401      "slow"
3402    );
3403  });
3404
3405  jQuery("#geolocation-button").on("mouseenter", function (event) {
3406    $("#tooltip-geolocation").fadeIn();
3407    $(".tooltip").fadeOut("fast");
3408  });
3409
3410  jQuery("#geolocation-button").on("mouseleave", function (event) {
3411    $("#tooltip-geolocation").fadeOut();
3412  });
3413
3414  ////////////////////////////////////////////////////////////////////////////////////////////
3415  /// adding total for featured listings
3416  ///////////////////////////////////////////////////////////////////////////////////////////
3417  $(".extra_featured").change(function () {
3418    var parent = $(this).parent();
3419    var price_regular = parseFloat(parent.find(".submit-price-no").text(), 10);
3420    var price_featured = parseFloat(
3421      parent.find(".submit-price-featured").text(),
3422      10
3423    );
3424    var total = price_regular + price_featured;
3425
3426    if ($(this).is(":checked")) {
3427      parent.find(".submit-price-total").text(total);
3428      parent.find("#stripe_form_featured").show();
3429      parent.find("#stripe_form_simple").hide();
3430    } else {
3431      //substract from total
3432      parent.find(".submit-price-total").text(price_regular);
3433      parent.find("#stripe_form_featured").hide();
3434      parent.find("#stripe_form_simple").show();
3435    }
3436    wpestate_enable_stripe_booking_prop();
3437  });
3438
3439  $(".compare_wrapper").each(function () {
3440    var cols = $(this).find(".compare_item_head").length;
3441    $(this).addClass("compar-" + cols);
3442  });
3443
3444  $("#list_view").on("click", function () {
3445    $(this).toggleClass("icon_selected");
3446    $("#listing_ajax_container").addClass("ajax12");
3447    $("#grid_view").toggleClass("icon_selected");
3448    $(".listing_wrapper")
3449      .hide()
3450      .removeClass("col-md-4")
3451      .removeClass("col-md-3")
3452      .addClass("col-md-12")
3453      .fadeIn(400);
3454    $(".the_grid_view").fadeOut(10, function () {
3455      $(".the_list_view").fadeIn(300);
3456    });
3457  });
3458
3459  $("#grid_view").on("click", function () {
3460    var class_type;
3461    class_type = $(".listing_wrapper:first-of-type").attr("data-org");
3462    $(this).toggleClass("icon_selected");
3463    $("#listing_ajax_container").removeClass("ajax12");
3464    $("#list_view").toggleClass("icon_selected");
3465    $(".listing_wrapper")
3466      .hide()
3467      .removeClass("col-md-12")
3468      .addClass("col-md-" + class_type)
3469      .fadeIn(400);
3470    $(".the_list_view").fadeOut(10, function () {
3471      $(".the_grid_view").fadeIn(300);
3472    });
3473  });
3474
3475  $("#add-new-image").on("click", function () {
3476    $(
3477      '<p><label for="file">New Image:</label><input type="file" name="upload_attachment[]" id="file_featured"></p> '
3478    ).appendTo("#files_area");
3479  });
3480
3481  $(".delete_image").on("click", function () {
3482    var image_id = $(this).attr("data-imageid");
3483    curent = $("#images_todelete").val();
3484    if (curent === "") {
3485      curent = image_id;
3486    } else {
3487      curent = curent + "," + image_id;
3488    }
3489
3490    $("#images_todelete").val(curent);
3491    $(this).parent().remove();
3492  });
3493
3494  $("#googleMap").bind("mousemove", function (e) {
3495    $(".tooltip").css({ top: e.pageY, left: e.pageX, "z-index": "1" });
3496  });
3497
3498  setTimeout(function () {
3499    $(".tooltip").fadeOut("fast");
3500  }, 10000);
3501});
3502
3503/*
3504 *
3505 *
3506 */
3507
3508function wpestate_advnced_filters_bars() {
3509  jQuery(".wpestate-selectpicker")
3510    .selectpicker({
3511      styleBase: "wpestate-multiselect-custom-style",
3512      size: 7,
3513    })
3514    .on(
3515      "changed.bs.select",
3516      function (e, clickedIndex, isSelected, previousValue) {
3517        var elememtParent = jQuery(this).closest(".tab-pane.active");
3518
3519        if (elememtParent.length == 0) {
3520          elememtParent = jQuery(this).parents().eq(2);
3521        }
3522
3523        var elementId = jQuery(this).attr("id");
3524
3525     
3526        const city_relations = {
3527          "advanced_city": "advanced_area",
3528          "sidebar-advanced_city": "sidebar-advanced_area",
3529          "shortcode-advanced_city": "shortcode-advanced_area",
3530          "mobile-advanced_city": "mobile-advanced_area",
3531        };
3532
3533        var selectedOption = jQuery(this).find("option").eq(clickedIndex);
3534        var attributeTaxonomy = selectedOption.attr("data-taxonomy"); // Replace 'your-attribute-name' with the actual attribute name
3535        var selectedOptions = jQuery(this).find("option:selected");
3536
3537        if (
3538          attributeTaxonomy === "cities" ||
3539          attributeTaxonomy === "county / state"
3540        ) {
3541          //var triggerChangeOn="advanced_city"
3542          triggerChangeOn = county_relations[elementId];
3543          if (attributeTaxonomy === "cities") {
3544            //  triggerChangeOn='advanced_area';
3545            triggerChangeOn = city_relations[elementId];
3546          }
3547
3548          var selectedValues = jQuery(this)
3549            .find("option:selected")
3550            .map(function () {
3551              return jQuery(this).val();
3552            })
3553            .get();
3554
3555          var elementCousin = elememtParent.find("#" + triggerChangeOn);
3556
3557          elementCousin.find("option").each(function () {
3558            var optionValue = jQuery(this).data("parent-value"); // Getting the data-value attribute
3559            // Check if the option's data-value matches any of the selected values or if no values are selected
3560            if (
3561              selectedValues.length === 0 ||
3562              selectedValues.indexOf(optionValue) !== -1
3563            ) {
3564              jQuery(this).show(); // Show the option if it matches or if no options are selected
3565            } else {
3566              jQuery(this).hide(); // Hide the option if it does not match any selected value
3567            }
3568          });
3569
3570          // Refresh the select picker to reflect the changes
3571          elementCousin.selectpicker("refresh");
3572        }
3573
3574        // Example action:
3575        first_time_wpestate_show_inpage_ajax_half = 1;
3576        wpestate_start_filtering_ajax_map(1);
3577      }
3578    )
3579    .on(
3580      "shown.bs.select",
3581      function (e, clickedIndex, isSelected, previousValue) {
3582        var thisButton = jQuery(this);
3583
3584        var windowWidth = jQuery(window).width();
3585        var buttonOffset = thisButton.offset();
3586        var buttonWidth = thisButton.outerWidth();
3587        var $dropdownMenu = jQuery(this).parent().find(".dropdown-menu.open");
3588
3589        // Calculate distances from the edges of the window
3590        var distanceFromLeft = buttonOffset.left;
3591        var distanceFromRight = windowWidth - (buttonOffset.left + buttonWidth);
3592
3593        // Check if the button is within 30px of either edge
3594        if (distanceFromLeft <= 150) {
3595          // Close to the left edge
3596          $dropdownMenu.css("left", 0);
3597          $dropdownMenu.css("right", "auto");
3598        } else if (distanceFromRight <= 150) {
3599          // Close to the right edge
3600
3601          $dropdownMenu.css("left", "auto");
3602          $dropdownMenu.css("right", 0);
3603        } else {
3604          // do nothing for now
3605        }
3606      }
3607    );
3608}
3609
3610
3611/*
3612*
3613* reposition dropdwons
3614*/
3615function wpestate_reposion_dropdowns(){
3616
3617
3618
3619  jQuery('.wpestate-multiselect-custom-style').each(function(){
3620
3621      jQuery(this).on('click', function() {
3622   
3623        var $popupWrapper = jQuery(this);
3624        var $searchWrapper = $popupWrapper.closest('.advanced_search_form_wrapper'); // Get the closest parent with the class '.search_wrapper'
3625
3626        if($searchWrapper.length===0){
3627            return;
3628        }
3629        var $dropdownMenu = jQuery(this).find('.dropdown-menu');   
3630        var popupOffset = $popupWrapper.offset();
3631        var searchOffset = $searchWrapper.offset();
3632
3633        // Calculate the distances
3634        var distanceToLeft = popupOffset.left - searchOffset.left;
3635        var distanceToRight = (searchOffset.left + $searchWrapper.outerWidth()) - (popupOffset.left + $popupWrapper.outerWidth());
3636
3637        if (distanceToLeft <= 150) {
3638            // Close to the left edge
3639            $dropdownMenu.css('left', 0);
3640            $dropdownMenu.css('right', 'auto');
3641
3642        } else if (distanceToRight <= 150) {
3643            // Close to the right edge
3644            $dropdownMenu.css('left', 'auto');
3645            $dropdownMenu.css('right', 0);
3646
3647        } 
3648
3649            
3650          
3651
3652      });
3653    });
3654}
3655
3656
3657
3658/*
3659 *
3660 * wp_estate_baths_component_item
3661 *
3662 */
3663
3664function wpestate_beds_baths_component() {
3665  function handleItemClick(itemClass, inputClass) {
3666    var selected_item = jQuery(this);
3667    var parent = selected_item.parent();
3668    var component = selected_item.closest(
3669      ".wpestate-beds-baths-popoup-component"
3670    );
3671
3672    parent.find(itemClass).removeClass("wp_estate_component_item_selected");
3673    selected_item.addClass("wp_estate_component_item_selected");
3674
3675    var selected_value = selected_item.attr("data-value");
3676    jQuery(inputClass).val(selected_value);
3677    update_label(component);
3678  }
3679
3680  function update_label(component) {
3681    var selected_beds =
3682      component.find(
3683        ".wp_estate_beds_component_item.wp_estate_component_item_selected"
3684      ).length > 0
3685        ? component
3686            .find(
3687              ".wp_estate_beds_component_item.wp_estate_component_item_selected"
3688            )
3689            .attr("data-value")
3690        : "0";
3691    var selected_baths =
3692      component.find(
3693        ".wp_estate_baths_component_item.wp_estate_component_item_selected"
3694      ).length > 0
3695        ? component
3696            .find(
3697              ".wp_estate_baths_component_item.wp_estate_component_item_selected"
3698            )
3699            .attr("data-value")
3700        : "0";
3701
3702    var update_label =
3703      parseFloat(selected_beds) +
3704      "+ " +
3705      control_vars.bd +
3706      "/" +
3707      parseFloat(selected_baths) +
3708      "+ " +
3709      control_vars.ba;
3710    component.find(".dropdown-toggle").text(update_label);
3711  }
3712
3713  // Attach event handlers
3714  jQuery(".wp_estate_beds_component_item").on("click", function (event) {
3715    event.stopPropagation();
3716    handleItemClick.call(
3717      this,
3718      ".wp_estate_beds_component_item",
3719      ".wpresidence-componentsbeds"
3720    );
3721  });
3722
3723  jQuery(".wp_estate_baths_component_item").on("click", function (event) {
3724    event.stopPropagation();
3725    handleItemClick.call(
3726      this,
3727      ".wp_estate_baths_component_item",
3728      ".wpresidence-componentsbaths"
3729    );
3730  });
3731
3732  jQuery(".wpestate-beds-baths-popoup-reset").on("click", function (event) {
3733    event.stopPropagation();
3734    var parent = jQuery(this).closest(".wpestate-beds-baths-popoup-wrapper");
3735    parent
3736      .find(".wp_estate_baths_component_item")
3737      .removeClass("wp_estate_component_item_selected");
3738    parent
3739      .find(".wp_estate_beds_component_item")
3740      .removeClass("wp_estate_component_item_selected");
3741
3742    parent
3743      .find(".wpresidence-componentsbeds, .wpresidence-componentsbaths")
3744      .val("");
3745    var component = jQuery(this).closest(
3746      ".wpestate-beds-baths-popoup-component"
3747    );
3748    var update_value =
3749      jQuery(this).attr("data-default-value") +
3750      '<span class="caret caret_filter "></span>';
3751    component.find(".dropdown-toggle").html(update_value);
3752  });
3753
3754  jQuery(".wpestate-beds-baths-popoup-done").on("click", function () {
3755    if (jQuery("#google_map_prop_list_sidebar").length > 0) {
3756      wpestate_start_filtering_ajax_map(1);
3757    }
3758  });
3759}
3760
3761/*
3762 *
3763 * wp estate price component_item
3764 *
3765 */
3766function wpestate_price_component_item() {
3767  jQuery(".wpestate-price-popoup-wrapper").on("click", function (event) {
3768    event.stopPropagation();
3769  });
3770  jQuery(
3771    ".component_adv_search_elementor_price_low,.component_adv_search_elementor_price_max"
3772  ).on("focus", function () {
3773    jQuery(this).val("");
3774  });
3775
3776  jQuery(
3777    ".component_adv_search_elementor_price_low,.component_adv_search_elementor_price_max"
3778  ).on("input", function () {
3779    // Replace non-digit characters with an empty string
3780    jQuery(this).val(jQuery(this).val().replace(/\D/g, ""));
3781  });
3782
3783  jQuery(
3784    ".component_adv_search_elementor_price_low,.component_adv_search_elementor_price_max"
3785  ).on("change", function (event) {
3786    var inputValue = jQuery(this).val();
3787    var parent = jQuery(this).closest(".wpestate-price-popoup-wrapper");
3788    var numericValue = parseFloat(inputValue);
3789    var slider = parent.find(".ui-slider");
3790    if (jQuery(this).hasClass("component_adv_search_elementor_price_low")) {
3791      slider.slider("values", 0, numericValue);
3792      slider
3793        .slider("option", "slide")
3794        .call(slider, null, {
3795          values: [numericValue, slider.slider("values")[1]],
3796        });
3797    } else {
3798      slider.slider("values", 1, numericValue);
3799      slider
3800        .slider("option", "slide")
3801        .call(slider, null, {
3802          values: [slider.slider("values")[0], numericValue],
3803        });
3804    }
3805  });
3806
3807  jQuery(".wpestate-price-component-popoup-reset").on(
3808    "click",
3809    function (event) {
3810      event.stopPropagation();
3811      var parent = jQuery(this).closest(".wpestate-price-popoup-wrapper");
3812      var low_value_label = parent
3813        .find(".wpestate-price-popoup-field-low")
3814        .attr("data-value");
3815      var max_value_label = parent
3816        .find(".wpestate-price-popoup-field-max")
3817        .attr("data-value");
3818
3819      if (parent.find(".adv_search_elementor_price_low").length > 0) {
3820        var low_value = parent
3821          .find(".adv_search_elementor_price_low")
3822          .attr("data-value");
3823        var max_value = parent
3824          .find(".adv_search_elementor_price_max")
3825          .attr("data-value");
3826        parent.find(".adv_search_elementor_price_low").val(low_value);
3827        parent.find(".adv_search_elementor_price_max").val(max_value);
3828      } else {
3829        if (parent.find(".adv6_price_low").length > 0) {
3830          var low_value = parent.find(".adv6_price_low").attr("data-value");
3831          var max_value = parent.find(".adv6_price_max").attr("data-value");
3832          parent.find(".adv6_price_low").val(low_value);
3833          parent.find(".adv6_price_max").val(max_value);
3834        } else {
3835          var low_value = parent.find(".single_price_low").attr("data-value");
3836          var max_value = parent.find(".single_price_max").attr("data-value");
3837          parent.find(".adv6_price_low").val(low_value);
3838          parent.find(".adv6_price_max").val(max_value);
3839        }
3840      }
3841
3842      var button_item = parent.parent().find(".dropdown-toggle");
3843      button_item.html(
3844        button_item.attr("data-default-value") +
3845          ' <span class="caret caret_filter "></span>'
3846      );
3847
3848      parent.find(".wpestate-price-popoup-field-low").val(low_value_label);
3849      parent.find(".wpestate-price-popoup-field-max").val(max_value_label);
3850
3851      var slider_label = parent
3852        .find(".wpresidence_slider_price")
3853        .attr("data-default");
3854      parent.find(".wpresidence_slider_price").text(slider_label);
3855
3856      var slider = parent.find(".ui-slider");
3857
3858      slider.slider("values", 0, parseFloat(low_value)); // sets first handle (e.g., min value)
3859      slider.slider("values", 1, parseFloat(max_value));
3860    }
3861  );
3862
3863  jQuery(".wpestate-price-component-popoup-done").on("click", function (event) {
3864    var parent_wrapper = jQuery("body");
3865    var fake_click_item = parent_wrapper.parent();
3866    fake_click_item.trigger("click");
3867  });
3868}
3869
3870/*
3871 *
3872 *  taxonomy slick slider
3873 *
3874 */
3875
3876function wpestate_taxonomy_slider() {
3877  jQuery(".estate_places_slider").each(function () {
3878    var items = jQuery(this).attr("data-items-per-row");
3879
3880    // rtl has to go in the INITIAL options. Setting it afterwards with
3881    // slickSetOption is lost as soon as a responsive breakpoint applies, which
3882    // left the track parked outside its own window on phones - a blank slider.
3883    jQuery(this).slick({
3884      infinite: true,
3885      slidesToShow: items,
3886      slidesToScroll: 1,
3887      dots: false,
3888      rtl: typeof control_vars !== "undefined" && control_vars.is_rtl === "1",
3889
3890      responsive: [
3891        {
3892          breakpoint: 1025,
3893          settings: {
3894            slidesToShow: 2,
3895            slidesToScroll: 1,
3896          },
3897        },
3898        {
3899          breakpoint: 480,
3900          settings: {
3901            slidesToShow: 1,
3902            slidesToScroll: 1,
3903          },
3904        },
3905      ],
3906    });
3907  });
3908}
3909
3910/*
3911 *
3912 * theme slider
3913 *
3914 */
3915
3916function wpestate_theme_slider() {
3917  var slick;
3918
3919  if (
3920    control_vars.wp_estate_slider_cycle != "" &&
3921    control_vars.wp_estate_slider_cycle != "0"
3922  ) {
3923    slick = jQuery("#estate-carousel_slick").slick({
3924      arrows: true,
3925      dots: true,
3926
3927      cssEase: "cubic-bezier(0.645, 0.045, 0.355, 1.000)",
3928      autoplay: true,
3929      autoplaySpeed: control_vars.wp_estate_slider_cycle,
3930    });
3931  } else {
3932    slick = jQuery("#estate-carousel_slick").slick({
3933      arrows: true,
3934      dots: true,
3935      cssEase: "cubic-bezier(0.645, 0.045, 0.355, 1.000)",
3936    });
3937  }
3938
3939  if (control_vars.is_rtl === "1") {
3940    slick.slick("slickSetOption", "rtl", true, true);
3941  }
3942
3943  if (Modernizr.mq("only all and (min-width: 1024px)")) {
3944    jQuery("#estate-carousel_slick").on(
3945      "beforeChange",
3946      function (event, slick, currentSlide, nextSlide) {
3947        jQuery(".item-version").hide(200);
3948        jQuery(".price-slider-wrapper").hide(300);
3949        jQuery(".theme-slider-view").hide(400);
3950      }
3951    );
3952
3953    jQuery("#estate-carousel_slick").on(
3954      "afterChange",
3955      function (event, slick, currentSlide, nextSlide) {
3956        jQuery(".item-version").slideDown("200", function () {
3957          jQuery(".price-slider-wrapper").slideDown(300);
3958          jQuery(".theme-slider-view").slideDown(600);
3959        });
3960      }
3961    );
3962  }
3963}
3964
3965/*
3966 *
3967 *
3968 *
3969 */
3970
3971function wpestate_show_capture() {
3972  "use strict";
3973  var position, slideno, slidedif, tomove, curentleft;
3974  jQuery("#googleMapSlider").hide();
3975  position = parseFloat(
3976    jQuery("#carousel-listing .carousel-inner .active").index(),
3977    10
3978  );
3979  jQuery("#carousel-listing  .caption-wrapper span").removeClass("active");
3980  jQuery(
3981    "#carousel-listing  .caption-wrapper span[data-slide-to='" +
3982      position +
3983      "'] "
3984  ).addClass("active");
3985  slideno = position + 1;
3986
3987  slidedif = slideno * 146;
3988  if (slidedif > 810) {
3989    tomove = 810 - slidedif;
3990    jQuery(".post-carusel .carousel-indicators").css("left", tomove + "px");
3991  } else {
3992    position = jQuery(".post-carusel .carousel-indicators")
3993      .css("left", tomove + "px")
3994      .position();
3995    curentleft = position.left;
3996
3997    if (curentleft < 0) {
3998      tomove = 0;
3999      jQuery(".post-carusel .carousel-indicators").css("left", tomove + "px");
4000    }
4001  }
4002}
4003
4004/*
4005 *
4006 *
4007 *
4008 */
4009
4010function wpestate_shortcode_google_map_load(containermap, lat, long, mapid) {
4011  "use strict";
4012  var myCenter, mapOptions, map, marker;
4013  myCenter = new google.maps.LatLng(lat, long);
4014  mapOptions = {
4015    flat: false,
4016    noClear: false,
4017    zoom: 15,
4018    scrollwheel: false,
4019    draggable: true,
4020    center: myCenter,
4021    mapTypeId: google.maps.MapTypeId.ROADMAP,
4022    streetViewControl: false,
4023    mapTypeControlOptions: {
4024      mapTypeIds: [google.maps.MapTypeId.ROADMAP],
4025    },
4026    disableDefaultUI: true,
4027    gestureHandling: "cooperative",
4028  };
4029
4030  map = new google.maps.Map(document.getElementById(mapid), mapOptions);
4031  google.maps.visualRefresh = true;
4032  marker = new google.maps.Marker({
4033    position: myCenter,
4034    map: map,
4035  });
4036
4037  marker.setMap(map);
4038}
4039
4040/*
4041 *
4042 *
4043 *
4044 */
4045
4046function wpestate_enable_stripe_booking_prop() {
4047  jQuery(".wpestate_stripe_booking_prop").unbind();
4048  jQuery(".wpestate_stripe_booking_prop").on("click", function () {
4049    var parent = jQuery(this).parent();
4050    var ajaxurl = control_vars.admin_url + "admin-ajax.php";
4051    var listingid = jQuery(this).attr("data-listingid");
4052    var isfeatured = jQuery(this).attr("data-isfeatured");
4053    var modalid = jQuery(this).attr("data-modalid");
4054    var modal = jQuery("#" + modalid);
4055    modal.appendTo("body");
4056
4057    modal.show();
4058
4059    jQuery.ajax({
4060      type: "POST",
4061      url: ajaxurl,
4062      //  dataType: 'json',
4063      data: {
4064        action: "wpestate_create_payment_intent_stripe",
4065        listingid: listingid,
4066        isfeatured: isfeatured,
4067        // HIGH-1: CSRF nonce — see wpestate_create_payment_intent_stripe()
4068        security: control_vars.wpestate_stripe_pi_nonce,
4069      },
4070      success: function (data) {
4071        jQuery("#" + modalid).show();
4072        jQuery("#" + modalid + " .wpestate_stripe_form_1").show();
4073        jQuery("#" + modalid)
4074          .find("#wpestate_stripe_form_button_sumit")
4075          .attr("data-secret", data);
4076        wpestate_start_stripe(0, modalid);
4077      },
4078      error: function (errorThrown) {},
4079    }); //end ajax
4080  });
4081
4082  jQuery(".close_stripe_form").on("click", function () {
4083    jQuery(".wpestate_stripe_form_wrapper").hide();
4084    jQuery(".wpestate_stripe_form_1").hide();
4085  });
4086}
4087
4088/*
4089 *
4090 *
4091 *
4092 */
4093
4094function wprentals_elementor_submit_form() {
4095  jQuery(".wprentals_elementor_form").on("submit", function (event) {
4096    event.preventDefault();
4097    var form_submit = jQuery(".wprentals_elementor_form").find(
4098      ".agent_submit_class_elementor"
4099    );
4100    wprentals_elementor_contact_process_form(form_submit);
4101  });
4102}
4103
4104/*
4105 *
4106 *
4107 *
4108 */
4109
4110function wprentals_elementor_contact_process_form(form_submit) {
4111  var parent,
4112    button,
4113    ajaxurl,
4114    contact_u_email,
4115    contact_u_name,
4116    subject,
4117    booking_from_date,
4118    booking_to_date,
4119    booking_guest_no,
4120    message,
4121    nonce,
4122    agent_property_id,
4123    is_elementor;
4124
4125  parent = form_submit.parent();
4126  button = jQuery(".wprentals_elementor_form").find(
4127    ".agent_submit_class_elementor"
4128  );
4129  button.val(ajaxcalls_vars.processing);
4130  button.text(ajaxcalls_vars.processing);
4131  button.prop("disabled", true);
4132  ajaxurl = control_vars.admin_url + "admin-ajax.php";
4133  booking_from_date = jQuery(
4134    "#rentals_contact_builder_booking_from_date"
4135  ).val();
4136  booking_to_date = jQuery("#rentals_contact_builder_booking_to_date").val();
4137  booking_guest_no = jQuery("#rentals_contact_builder_guests").val();
4138  message = jQuery("#form-field-message").val();
4139  contact_u_email = jQuery("#rentals_contact_builder_email").val();
4140  contact_u_name = jQuery("#rentals_contact_builder_name").val();
4141  nonce = jQuery("#agent_property_ajax_nonce").val();
4142
4143  is_elementor = parent.find("#contact_form_elementor").val();
4144  var elementor_email_send_to = jQuery("#elementor_email_send_to").val();
4145  var elementor_email_subject = jQuery("#elementor_email_subject").val();
4146  var elementor_email_sendc = jQuery("#elementor_email_sendc").val();
4147  var elementor_email_sendbcc = jQuery("#elementor_email_sendbcc").val();
4148
4149  var temp_details;
4150  temp_details = "";
4151  var elementor_form = form_submit.parents(".wprentals_elementor_form");
4152
4153  var form_items = elementor_form.find(".elementor-field");
4154
4155  form_items.each(function () {
4156    temp_details =
4157      temp_details +
4158      jQuery(this).attr("name") +
4159      ": " +
4160      jQuery(this).val() +
4161      "/n";
4162  });
4163
4164  message = temp_details;
4165
4166  if (
4167    jQuery("#wpestate_agree_gdpr").length > 0 &&
4168    !jQuery("#wpestate_agree_gdpr").is(":checked")
4169  ) {
4170    jQuery("#booking_form_request_mess_modal")
4171      .show()
4172      .empty()
4173      .append(control_vars.gdpr_terms);
4174    button.val(control_vars.send_mess);
4175    button.text(control_vars.send_mess);
4176    var aTag = jQuery(".wprentals_elementor_form");
4177    jQuery("html,body").animate({ scrollTop: aTag.offset().top - 120 }, "slow");
4178    button.prop("disabled", false);
4179    return;
4180  }
4181
4182  jQuery.ajax({
4183    type: "POST",
4184    dataType: "json",
4185    url: ajaxurl,
4186    data: {
4187      action: "wpestate_ajax_agent_contact_page",
4188      name: contact_u_name,
4189      email: contact_u_email,
4190      comment: message,
4191      booking_guest_no: booking_guest_no,
4192      booking_from_date: booking_from_date,
4193      booking_to_date: booking_to_date,
4194      //'elementor_email_send_to':elementor_email_send_to,
4195      elementor_email_subject: elementor_email_subject,
4196      //'elementor_email_sendc':elementor_email_sendc,
4197      //'elementor_email_sendbcc':elementor_email_sendbcc,
4198      is_elementor: 1,
4199
4200      nonce: nonce,
4201    },
4202    success: function (data) {
4203      var aTag = jQuery("#booking_form_request_mess_modal").parent();
4204
4205      jQuery("html,body").animate(
4206        { scrollTop: aTag.offset().top - 120 },
4207        "slow"
4208      );
4209      jQuery("#booking_form_request_mess_modal")
4210        .show()
4211        .empty()
4212        .append(data.response);
4213
4214
4215      // reset contact form
4216      button.val(control_vars.send_mess);
4217      button.text(control_vars.send_mess);
4218      button.prop("disabled", false);
4219      jQuery(".wprentals_elementor_form .elementor-field").val("");
4220      jQuery("#wpestate_agree_gdpr").prop("checked", false);
4221    },
4222    error: function (errorThrown) {},
4223  });
4224}
4225
4226/*
4227 *
4228 *
4229 *
4230 */
4231
4232function wpestate_control_guest_no() {
4233  jQuery(".wpestate_guest_no_control_info ")
4234    .off("click")
4235    .on("click", function (event) {
4236      jQuery(this).addClass('wpestate_guest_no_control_info_open');
4237      jQuery(this).parent().find(".wpestate_guest_no_buttons").toggle();
4238      event.stopPropagation();
4239    });
4240
4241  jQuery(".close_guest_control")
4242    .off("click")
4243    .on("click", function (event) {
4244      event.preventDefault();
4245      jQuery(this).parent().hide();
4246      jQuery('.wpestate_guest_no_control_info').removeClass('wpestate_guest_no_control_info_open');
4247      if (jQuery("#google_map_prop_list_sidebar").length > 0) {
4248        wpestate_start_filtering_ajax_map(1);
4249      }
4250    });
4251
4252  // when a plus or minus button is pushed
4253  jQuery(".wpestate_guest_no_button_control")
4254    .off("click")
4255    .on("click", function (event) {
4256      event.stopPropagation();
4257      event.preventDefault();
4258      var with_count_children = 1;
4259      var item_parent = jQuery(this).parent();
4260      var section_wrapper = jQuery(this).parents().eq(2);
4261      var overload_guest = parseInt(
4262        section_wrapper.attr("data-overload-guest"),
4263        10
4264      );
4265      var max_extra_guest_no = parseInt(
4266        section_wrapper.attr("data-max-extra-guest-no"),
4267        10
4268      );
4269      var max_guest = parseInt(section_wrapper.attr("data-max-guest"), 10);
4270
4271      var check_max_guest = max_guest;
4272      if (overload_guest === 1) {
4273        check_max_guest = max_guest + max_extra_guest_no;
4274      }
4275
4276      var trigger_label_creation = 1;
4277
4278      // contro item incrementioa
4279      if (!wpestate_guest_control_add_item(jQuery(this))) {
4280        return;
4281      }
4282
4283      if (jQuery(this).hasClass("on_booking_control1")) {
4284        with_count_children = 0;
4285      }
4286
4287      var guest_parent = jQuery(this).closest(
4288        ".wpestate_guest_no_control_wraper"
4289      );
4290
4291      if (!item_parent.hasClass("steper_infants")) {
4292        var guest_value_text = guest_parent.find(".guest_no_hidden").val();
4293        var guest_value_int = parseInt(guest_value_text, 10);
4294
4295        if (jQuery(this).hasClass("wpestate_guest_no_button_plus")) {
4296          if (
4297            jQuery(this).hasClass("on_booking_control1") ||
4298            jQuery(this).hasClass("on_booking_control0")
4299          ) {
4300            if (jQuery(this).parent().hasClass("steper_childs")) {
4301              if (jQuery(this).hasClass("on_booking_control0")) {
4302                guest_value_int = guest_value_int + 1;
4303              }
4304            } else {
4305              guest_value_int = guest_value_int + 1;
4306            }
4307          } else {
4308            guest_value_int = guest_value_int + 1;
4309          }
4310        } else {
4311          if (
4312            jQuery(this).hasClass("on_booking_control1") ||
4313            jQuery(this).hasClass("on_booking_control0")
4314          ) {
4315            if (jQuery(this).parent().hasClass("steper_childs")) {
4316              if (jQuery(this).hasClass("on_booking_control0")) {
4317                guest_value_int = guest_value_int - 1;
4318              }
4319            } else {
4320              guest_value_int = guest_value_int - 1;
4321            }
4322          } else {
4323            guest_value_int = guest_value_int - 1;
4324          }
4325
4326          if (guest_value_int < 0) {
4327            guest_value_int = 0;
4328          }
4329        } // end if plus or minus
4330
4331        // if we have booking control
4332        if (
4333          jQuery(this).hasClass("on_booking_control1") ||
4334          jQuery(this).hasClass("on_booking_control0")
4335        ) {
4336          if (guest_value_int === check_max_guest) {
4337            section_wrapper
4338              .find(".max_guest_notice")
4339              .show()
4340              .text(check_max_guest + " " + control_vars.guests_max);
4341            trigger_label_creation = 1;
4342            guest_parent.find(".guest_no_hidden").val(guest_value_int);
4343            wpestate_block_unblock_plus_buttons(section_wrapper, "block");
4344          } else if (guest_value_int > check_max_guest) {
4345            trigger_label_creation = 1;
4346          } else {
4347            section_wrapper.find(".max_guest_notice").hide();
4348            guest_parent.find(".guest_no_hidden").val(guest_value_int);
4349            trigger_label_creation = 1;
4350            wpestate_block_unblock_plus_buttons(section_wrapper, "unblock");
4351          }
4352        } else {
4353          // if not -it means search control
4354          guest_parent.find(".guest_no_hidden").val(guest_value_int);
4355        }
4356      } // end if is adult or guest conrols
4357
4358      // generate label for control
4359      if (trigger_label_creation == 1) {
4360        label_to_add = wpestate_guest_no_label_to_add(
4361          guest_parent,
4362          with_count_children
4363        );
4364        guest_parent.find(".wpestate_guest_no_control_info").text(label_to_add);
4365        if (jQuery(this).parents().eq(5).hasClass("booking_form_request")) {
4366          show_booking_costs();
4367        }
4368      }
4369    });
4370
4371  jQuery(document).on("click", function (event) {
4372    jQuery(".wpestate_guest_no_buttons").each(function () {
4373      var container = jQuery(this);
4374      if (
4375        !container.is(event.target) &&
4376        container.has(event.target).length === 0
4377      ) {
4378        if (container.css("display") == "block") {
4379          container.hide();
4380                jQuery('.wpestate_guest_no_control_info').removeClass('wpestate_guest_no_control_info_open');
4381          if (jQuery("#google_map_prop_list_sidebar").length > 0) {
4382            wpestate_start_filtering_ajax_map(1);
4383          }
4384        }
4385      }
4386    });
4387  });
4388}
4389
4390/*
4391 *
4392 *
4393 *
4394 */
4395
4396function wpestate_guest_no_label_to_add(wrapper, with_count_children) {
4397  var adult_guest_text = wrapper.find(".steper_value_adults").text();
4398  var children_guest_text = wrapper.find(".steper_value_childs").text();
4399  var infants_guest_text = wrapper.find(".steper_value_infants").text();
4400
4401  var adult_guest_int = parseInt(adult_guest_text, 10);
4402  var children_guest_int = parseInt(children_guest_text, 10);
4403  var infant_guest_int = parseInt(infants_guest_text, 10);
4404
4405  var label_to_return = "";
4406  var total_guests_to_bill = adult_guest_int + children_guest_int;
4407
4408  if (with_count_children == 0) {
4409    total_guests_to_bill = adult_guest_int;
4410  }
4411
4412  if (total_guests_to_bill > 0) {
4413    var guest_label = control_vars.multiple_guest;
4414    if (total_guests_to_bill == 1) {
4415      guest_label = control_vars.single_guest;
4416    }
4417    label_to_return =
4418      label_to_return + total_guests_to_bill + " " + guest_label;
4419  }
4420
4421  if (with_count_children == 0 && children_guest_int > 0) {
4422    var children_label = control_vars.multiple_child;
4423    if (children_guest_int == 1) {
4424      children_label = control_vars.single_child;
4425    }
4426
4427    if (total_guests_to_bill > 0) {
4428      label_to_return = label_to_return + ", ";
4429    }
4430    label_to_return =
4431      label_to_return + children_guest_int + " " + children_label;
4432  }
4433
4434  if (infant_guest_int > 0) {
4435    var infants_label = control_vars.multiple_infants;
4436    if (infant_guest_int == 1) {
4437      infants_label = control_vars.single_infant;
4438    }
4439
4440    if (
4441      total_guests_to_bill > 0 ||
4442      (with_count_children == 0 && children_guest_int > 0)
4443    ) {
4444      label_to_return = label_to_return + ", ";
4445    }
4446    label_to_return = label_to_return + infant_guest_int + " " + infants_label;
4447  }
4448
4449  if (
4450    (total_guests_to_bill == 0 && infant_guest_int == 0) ||
4451    (with_count_children == 0 &&
4452      total_guests_to_bill == 0 &&
4453      infant_guest_int == 0)
4454  ) {
4455    label_to_return = control_vars.multiple_guest;
4456  }
4457
4458  if (typeof wpestate_setCookie !== "undefined") {
4459    wpestate_setCookie("adult_guest_int", adult_guest_int, 1);
4460    wpestate_setCookie("children_guest_int", children_guest_int, 1);
4461    wpestate_setCookie("infant_guest_int", infant_guest_int, 1);
4462    wpestate_setCookie("label_to_return", label_to_return, 1);
4463    wpestate_setCookie("guest_no_hidden", total_guests_to_bill, 1);
4464  }
4465  return label_to_return;
4466}
4467
4468/*
4469 *
4470 *
4471 *
4472 */
4473
4474function wpestate_check_if_children_as_guests() {
4475  if (typeof property_vars !== "undefined") {
4476    if (property_vars.children_as_guests === "0") {
4477      return true;
4478    }
4479  }
4480  return false;
4481}
4482
4483/*
4484 *
4485 *
4486 *
4487 */
4488
4489function wpestate_block_unblock_plus_buttons(section_wrapper, action) {
4490
4491  if (action === "block") {
4492    section_wrapper.find(".adults_control_plus").prop("disabled", true);
4493    section_wrapper
4494      .find(".childs_control_plus.on_booking_control0")
4495      .prop("disabled", true);
4496  } else {
4497    section_wrapper
4498      .find(".wpestate_guest_no_button_plus")
4499      .prop("disabled", false);
4500  }
4501}
4502
4503/*
4504 *
4505 * Guest control add item
4506 *
4507 */
4508
4509function wpestate_guest_control_add_item(item) {
4510  var item_parent = item.parent();
4511  var item_value_text = item_parent
4512    .find(".wpestate_guest_no_button_value")
4513    .text();
4514  var item_value_int = parseInt(item_value_text, 10);
4515  var abort_flag = 0;
4516
4517  if (item.hasClass("wpestate_guest_no_button_plus")) {
4518    item_value_int = item_value_int + 1;
4519  } else {
4520    item_value_int = item_value_int - 1;
4521    if (item_value_int < 0) {
4522      item_value_int = 0;
4523      abort_flag = 1;
4524    }
4525  }
4526
4527  item.parent().find(".placeholeder_search_val").val(item_value_int);
4528  item_parent.find(".wpestate_guest_no_button_value").text(item_value_int);
4529
4530  if (abort_flag === 1) {
4531    return false;
4532  }
4533  return true;
4534}
4535
4536/**
4537 * WpEstate Sliding Box Interaction
4538 *
4539 * This function sets up the interactive behavior for the sliding box elements
4540 * in the WpResidence theme. It handles the mouseover event to activate and
4541 * deactivate sliding boxes.
4542 *
4543 * @since 1.0.0
4544 * 
4545 * @requires jQuery
4546 */
4547function wpestate_slider_box() {
4548    
4549    // Attach a mouseover event handler to all elements with class 'wpestate_sliding_box'
4550    jQuery(".wpestate_sliding_box").mouseover(function() {
4551        // 'this' refers to the current element being hovered over
4552        var selected_item = jQuery(this);
4553        
4554        // Find the parent container of the current sliding box
4555        var item_parent = selected_item.parent();
4556        
4557        // Remove 'active-element' class from all sliding boxes within the same parent
4558        item_parent.find('.wpestate_sliding_box').removeClass('active-element');
4559        
4560        // Add 'active-element' class to the currently hovered sliding box
4561        selected_item.addClass('active-element');
4562    });
4563}
4564
4565/*
4566 *
4567 * Testimonial Slider
4568 *
4569 */
4570
4571function wpestate_testimonial_slider(slider_id) {
4572  jQuery("#" + slider_id).slick({
4573    infinite: true,
4574    slidesToShow: 1,
4575    slidesToScroll: 1,
4576    dots: true,
4577    // rtl:true,
4578  });
4579}
4580
4581/*
4582 *
4583 * Mobile Menu slide out
4584 *
4585 */
4586
4587function wpestate_mobile_menu_slideout() {
4588  var vc_size;
4589  var var_parents = new Array();
4590  var var_parents_back = new Array();
4591
4592  if (jQuery(".mobile-trigger-user").length > 0) {
4593    var slideout_user_menu = new Slideout({
4594      panel: document.getElementById("all_wrapper"),
4595      menu: document.getElementById("mobilewrapperuser"),
4596      padding: -256,
4597      tolerance: 70,
4598    });
4599
4600    slideout_user_menu.disableTouch();
4601
4602    // Toggle button
4603    document
4604      .querySelector(".mobile-trigger-user")
4605      .addEventListener("click", function () {
4606        slideout_user_menu.toggle();
4607        if (jQuery("#mobilewrapperuser").is(":visible")) {
4608          jQuery("#mobilewrapperuser").hide();
4609        } else {
4610          jQuery("#mobilewrapperuser").show();
4611        }
4612      });
4613
4614    jQuery(".mobilemenu-close-user").on("click", function (event) {
4615      slideout_user_menu.toggle();
4616      setTimeout(function () {
4617        jQuery("#mobilewrapperuser").hide();
4618      }, 200);
4619    });
4620  }
4621
4622  if (jQuery(".mobile-trigger").length > 0) {
4623    var slideout_link_menu = new Slideout({
4624      panel: document.getElementById("all_wrapper"),
4625      menu: document.getElementById("mobilewrapper_links"),
4626      padding: 256,
4627      tolerance: 70,
4628      side: "left",
4629      easing: "cubic-bezier(.32,2,.55,.27)",
4630    });
4631    slideout_link_menu.disableTouch();
4632    document
4633      .querySelector(".mobile-trigger")
4634      .addEventListener("click", function () {
4635        slideout_link_menu.toggle();
4636        if (jQuery("#mobilewrapper_links").is(":visible")) {
4637          jQuery("#mobilewrapper_links").hide();
4638        } else {
4639          jQuery("#mobilewrapper_links").show();
4640        }
4641      });
4642
4643    jQuery(".mobilemenu-close").on("click", function (event) {
4644      slideout_link_menu.toggle();
4645      setTimeout(function () {
4646        jQuery("#mobilewrapper_links").hide();
4647      }, 200);
4648    });
4649  }
4650}
4651/**
4652 * Initialize Slick slider for listing image gallery
4653 * 
4654 * @param {number} slidesToShow - Number of slides to show at once (default: 3)
4655 * 
4656 * Responsive breakpoints:
4657 * - 1025px: shows 2 slides
4658 * - 480px: shows 1 slide
4659 * 
4660 * Usage:
4661 * wprentals_three_items_slick_slider();     // shows 3 slides
4662 * wprentals_three_items_slick_slider(5);    // shows 5 slides
4663 */
4664function wprentals_three_items_slick_slider(slidesToShow = 3) {
4665  jQuery("#listing_main_image_photo_slider").slick({
4666    infinite: true,
4667    slidesToShow: slidesToShow,
4668    slidesToScroll: 1,
4669    dots: true,
4670    arrows: true,
4671    responsive: [
4672      {
4673        breakpoint: 1025,
4674        settings: {
4675          slidesToShow: 2,
4676          slidesToScroll: 1,
4677        },
4678      },
4679      {
4680        breakpoint: 480,
4681        settings: {
4682          slidesToShow: 1,
4683          slidesToScroll: 1,
4684        },
4685      },
4686    ],
4687  });
4688  if (control_vars.is_rtl === "1") {
4689    jQuery("#listing_main_image_photo_slider").slick(
4690      "slickSetOption",
4691      "rtl",
4692      true,
4693      true
4694    );
4695  }
4696}
4697
4698/*
4699*
4700* 
4701*
4702*/
4703
4704function wprentalsInitializeAutocomplete(availableTags,inputID) {
4705
4706
4707    jQuery("#"+inputID).autocomplete({
4708        source: function(request, response) {
4709
4710            var results = jQuery.ui.autocomplete.filter(availableTags, request.term);
4711            response(results.slice(0, 9)); // Limiting the results to 9
4712        },
4713        select: function(event,ui) {
4714          
4715       
4716            // Add a reset button next to the input field
4717            var $input = jQuery(this);
4718
4719            var $resetBtn = jQuery('<button type="button" class="wprentals-reset-btn"><svg width="14px" height="14px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <rect width="24" height="24" ></rect> <path d="M7 17L16.8995 7.10051" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M7 7.00001L16.8995 16.8995" stroke="#000000" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg></button>');
4720            var text = ui.item.label;
4721            var $testSpan = jQuery('<span>').appendTo(document.body);
4722
4723            // Copy text styles to match the input fields text
4724            $testSpan.css({
4725                'font-size': $input.css('font-size'),
4726                'font-family': $input.css('font-family'),
4727                'visibility': 'hidden',
4728                'white-space': 'pre'  // preserve spaces and tabs
4729            }).text(text);
4730
4731            // Calculate the width and adjust the button position
4732            var textWidth = $testSpan.width();
4733            $resetBtn.css('left', textWidth + 60); // 3px after the text
4734
4735            $testSpan.remove(); // Remove the test span from the document
4736
4737
4738
4739            // Remove any existing reset button first
4740            $input.next('.wprentals-reset-btn').remove();
4741       
4742            $input.after($resetBtn);
4743
4744            jQuery(".stype").val(ui.item.category);
4745
4746            if (document.getElementById("search_location_filter_autointernal")) {
4747
4748                jQuery("#search_location_filter_autointernal").val(ui.item.label);
4749                wpestate_start_filtering_ajax_map(1);
4750            }
4751            
4752        
4753            // Event handler for the reset button
4754            $resetBtn.on('click', function() {
4755                $input.val("");
4756                jQuery(this).remove(); // Remove the reset button after use
4757                  wpestate_start_filtering_ajax_map(1);
4758            });
4759
4760           setTimeout(function(){
4761               wpestate_start_filtering_ajax_map(1);
4762            }, 1000);
4763         
4764        }, change: function() {
4765    
4766        }
4767    }).autocomplete("instance")._renderItem = function(ul, item) {
4768        if (!item.label || item.label.trim() === '') {
4769         return jQuery("<li style='display: none;'></li>").appendTo(ul);
4770        }
4771
4772        var item_class= "wprentals-geolocatiomarker-"+ item.labelcategory;
4773
4774        var $li = jQuery("<li>").append("<div class='"+item_class+"'>" + item.label + "</div>");
4775
4776     
4777        var lastCategory = jQuery(ul).find(".wprentals-dropdown-category-label:last").data("category");
4778        if(typeof lastCategory=== 'undefined'){
4779          lastCategory='';
4780        }
4781
4782        if (lastCategory.toLowerCase() !== item.labelcategory.toLowerCase() ) {
4783            var $categoryDiv = jQuery("<div>").addClass("wprentals-dropdown-category-label").attr("categoryLabel", item.labelcategory).data("category", item.category_tax).text(item.category_tax);
4784            jQuery(ul).addClass('wprentals-autocomplete').append($categoryDiv);
4785        }
4786
4787        return $li.appendTo(ul);
4788    };
4789}
4790
4791
4792/** * Check Password Strength
4793 * This function checks the strength of a password entered in two fields and updates a strength meter accordingly.
4794 * It also enables or disables a submit button based on the password strength.
4795 *
4796 * @param {jQuery} $pass1 - The first password field.
4797 * @param {jQuery} $pass2 - The second password field.
4798 * @param {jQuery} $strengthResult - The element to display the strength result.
4799 * @param {jQuery} $submitButton - The submit button to enable/disable.
4800 * @param {Array} blacklistArray - An array of blacklisted words.
4801 */
4802function checkPasswordStrength( $pass1, $pass2, $strengthResult, $submitButton, blacklistArray ) {
4803    var pass1 = $pass1.val();
4804    var pass2 = $pass2.val();
4805    // Reset the form & meter
4806    $submitButton.attr( 'disabled', 'disabled' );
4807    $strengthResult.removeClass( 'short bad good strong' );
4808    // Extend our blacklist array with those from the inputs & site data
4809    blacklistArray = blacklistArray.concat( wp.passwordStrength.userInputDisallowedList() )
4810    // Get the password strength 
4811    var strength = wp.passwordStrength.meter( pass1, blacklistArray, pass2 );
4812    // Add the strength meter results given the strength value
4813    switch ( strength ) {
4814      case 2:
4815        $strengthResult.addClass( 'bad' ).html( pwsL10n.bad );
4816        break;
4817      case 3:
4818        $strengthResult.addClass( 'good' ).html( pwsL10n.good );
4819        break;
4820      case 4:
4821        $strengthResult.addClass( 'strong' ).html( pwsL10n.strong );
4822        break;
4823      case 5:
4824        $strengthResult.addClass( 'short' ).html( pwsL10n.mismatch );
4825        break;
4826      default:
4827        $strengthResult.addClass( 'short' ).html( pwsL10n.short );
4828    }
4829  
4830    // The meter function returns a result even if pass2 is empty, 
4831    // enable only the submit button if the password is strong and 
4832    // both passwords are filled up 
4833    if ( strength >= 3 && '' !== pass2.trim() ) {
4834      $submitButton.removeAttr( 'disabled' );
4835    }
4836    
4837    return strength;
4838}
4839
4840/*
4841  * Password Strength Meter
4842  * This script checks the strength of a password entered in two fields and updates a strength meter accordingly.
4843  * It also enables or disables a submit button based on the password strength.
4844  *
4845  * @requires jQuery
4846  * @requires wp.passwordStrength
4847  * @requires wp.passwordStrength.userInputDisallowedList
4848  */
4849jQuery( document ).ready( function( $ ) {
4850  // Binding to trigger checkPasswordStrength 
4851  jQuery( 'body' ).on( 'keyup', 'input[name=user_password], input[name=user_password_retype]',
4852    function( event ) {
4853      var mainField = jQuery( this );
4854      var otherField;
4855      var passStrength = mainField.parents('.login_form').find( '.password-strength' );
4856      var submitButton = mainField.parents('.login_form').find( '.wpestate_vc_button' );
4857      // get the other field
4858      if ( mainField.attr( 'name' ) === 'user_password' ) {
4859        var otherField = mainField.parents('.login_form').find( 'input[name=user_password_retype]' );
4860      } else if ( mainField.attr( 'name' ) === 'user_password_retype' ) {
4861        var otherField = mainField.parents('.login_form').find( 'input[name=user_password]' );
4862      }
4863      checkPasswordStrength(
4864				mainField,         // First password field 
4865				otherField, // Second password field 
4866				passStrength,           // Strength meter 
4867				submitButton,           // Submit button 
4868				[]        // Blacklisted words 
4869			);
4870		}
4871	);
4872});
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885////////////////
4886
4887/**
4888 * Creates skeleton cards in container based on existing card count
4889 * @param {jQuery} container - Container element
4890 * @param {boolean} append - If true, append skeletons; if false, empty container first (default: false)
4891 * 
4892 * data-row-number="3" - blg list
4893 */
4894function wpestate_createSkeletons(container, append) {
4895    // Default parameter handling for ES5 compatibility
4896    if (typeof append === 'undefined') {
4897        append = false;
4898    }
4899    
4900     // Detect if this is a grid layout
4901    var isGrid = container.find('.shortcode_wrapper_grid_item').length > 0;
4902    
4903    // Count existing cards BEFORE they get cleared
4904    var existingCards = container.find('.listing_wrapper:not(.skeleton-placeholder)');
4905    var existingCount = existingCards.length;
4906    
4907    // Handle clearing based on append parameter
4908    if (append === false) {
4909        container.empty();
4910    }
4911   
4912    // Calculate items per row from Bootstrap grid classes based on current viewport
4913    var itemsPerRow = parseInt( container.attr('data-row-number')) ;
4914    var gridClasses = 'col-lg-4 col-12 col-sm-6 col-md-6';
4915    var cardClasses = 'property_listing property_card_default';
4916   
4917
4918
4919    if (isGrid) {
4920        // Grid layout logic
4921
4922        // For grid, we don't use Bootstrap classes
4923        gridClasses = '';
4924        
4925        // Extract card classes from existing cards
4926        if (existingCards.length > 0) {
4927            var cardElement = existingCards.first().find('.property_listing');
4928            if (cardElement.length > 0) {
4929                cardClasses = cardElement.attr('class');
4930            }
4931        }
4932        
4933        
4934        
4935    } else {
4936            
4937        if (existingCards.length > 0) {
4938            var firstCard = existingCards.first();
4939            var classList = firstCard.attr('class').split(' ');
4940        
4941            // Extract grid classes
4942            var extractedGridClasses = classList.filter(function(cls) {
4943                return cls.indexOf('col-') === 0;
4944            }).join(' ');
4945            if (extractedGridClasses) {
4946                gridClasses = extractedGridClasses;
4947            }
4948        
4949            // Calculate items per row based on current viewport
4950            var viewportWidth = window.innerWidth;
4951            var cols = 4; // default (col-lg-4 = 12/4 = 3 per row)
4952        
4953            if (viewportWidth >= 1200) {
4954                // xl breakpoint - look for col-xl-* or fallback to col-lg-*
4955                var xlClass = classList.find(function(cls) { return cls.match(/^col-xl-(\d+)$/); });
4956                if (xlClass) {
4957                    cols = parseInt(xlClass.match(/^col-xl-(\d+)$/)[1]);
4958                } else {
4959                    var lgClass = classList.find(function(cls) { return cls.match(/^col-lg-(\d+)$/); });
4960                    if (lgClass) cols = parseInt(lgClass.match(/^col-lg-(\d+)$/)[1]);
4961                }
4962            } else if (viewportWidth >= 992) {
4963                // lg breakpoint
4964                var lgClass = classList.find(function(cls) { return cls.match(/^col-lg-(\d+)$/); });
4965                if (lgClass) cols = parseInt(lgClass.match(/^col-lg-(\d+)$/)[1]);
4966            } else if (viewportWidth >= 768) {
4967                // md breakpoint
4968                var mdClass = classList.find(function(cls) { return cls.match(/^col-md-(\d+)$/); });
4969                if (mdClass) cols = parseInt(mdClass.match(/^col-md-(\d+)$/)[1]);
4970            } else if (viewportWidth >= 576) {
4971                // sm breakpoint
4972                var smClass = classList.find(function(cls) { return cls.match(/^col-sm-(\d+)$/); });
4973                if (smClass) cols = parseInt(smClass.match(/^col-sm-(\d+)$/)[1]);
4974            } else {
4975                // xs breakpoint - look for col-* (no breakpoint)
4976                var xsClass = classList.find(function(cls) { return cls.match(/^col-(\d+)$/); });
4977                if (xsClass) cols = parseInt(xsClass.match(/^col-(\d+)$/)[1]);
4978            }
4979        
4980            itemsPerRow = Math.floor(12 / cols);
4981        
4982            // Extract card classes
4983            var cardElement = firstCard.find('.property_listing');
4984            if (cardElement.length > 0) {
4985                cardClasses = cardElement.attr('class');
4986            }
4987        }
4988    }
4989
4990    var skeletonCount;
4991    
4992    // Simple: skeleton count = existing count (complete rows)
4993    if (append === false) {
4994        skeletonCount = Math.ceil(existingCount / itemsPerRow) * itemsPerRow;
4995    }else{
4996         
4997
4998        if(isGrid){
4999            skeletonCount = parseInt( container.parent().attr('data-row-number'));
5000        }else{
5001            skeletonCount = itemsPerRow;
5002          }
5003    }
5004
5005    // Create skeleton HTML
5006    var skeletonHTML = '';
5007    for (var i = 0; i < skeletonCount; i++) {
5008        skeletonHTML += wpestate_createSkeletonCard(gridClasses, cardClasses, false);
5009    }
5010   
5011    // Clear specific elements if appending (don't clear everything)
5012   
5013   
5014    // Add skeletons to container
5015    container.append(skeletonHTML);
5016}
5017
5018/**
5019 * Replaces skeleton cards with real cards
5020 * @param {jQuery} container - Container element
5021 * @param {string} htmlData - HTML data with real cards
5022 */
5023function wpestate_replaceSkeletons(container, htmlData,append) {
5024
5025
5026    // Detect if this is a grid layout
5027    var isGrid = container.find('.shortcode_wrapper_grid_item').length > 0;
5028
5029    // Default parameter handling for ES5 compatibility
5030    if (typeof append === 'undefined') {
5031        append = false;
5032    }
5033    
5034    // Find skeleton placeholders
5035    var skeletons = container.find('.skeleton-placeholder');
5036
5037    // Parse new HTML data
5038    var tempDiv = jQuery('<div>').html(htmlData);
5039    var newCards = tempDiv.find('.listing_wrapper');
5040  
5041    var pagination = tempDiv.find('.pagination_ajax_search');
5042    var pagination2 = tempDiv.find('.pagination_ajax');
5043    var pagination3 = tempDiv.find('.pagination_ajax_search_home');
5044    var scrollHere = tempDiv.find('#scrollhere');
5045    var no_results = tempDiv.find('.no_results');
5046  
5047    // If no skeletons, just append normally
5048    if (skeletons.length === 0) {
5049        container.append(htmlData);
5050        return;
5051    }
5052    
5053    // Add scrollhere at beginning if exists
5054    if (scrollHere.length > 0) {
5055        container.prepend(scrollHere);
5056    }
5057    
5058    // Replace ALL skeletons one by one - some with real cards, others removed
5059    var delay = 0;
5060    var intervalTime = 100;
5061    
5062    var maxItems = Math.max(skeletons.length, newCards.length);
5063    if (append == true) {
5064   //     console.log('maxItems with app ' + maxItems);
5065    } else {
5066     //   console.log('maxItems no app ' + maxItems);
5067    }
5068
5069
5070    for (var i = 0; i < maxItems; i++) {
5071        
5072        (function(index) {
5073            setTimeout(function() {
5074                if (index < skeletons.length && index < newCards.length) {
5075                    // Replace skeleton with real card
5076                    
5077                    if(isGrid){
5078                        var wrappedCard = jQuery('<div class="shortcode_wrapper_grid_item"></div>').append(jQuery(newCards[index]));
5079                        jQuery(skeletons[index]).replaceWith(wrappedCard);
5080                    }else{
5081                        jQuery(skeletons[index]).replaceWith(jQuery(newCards[index]));
5082                    }
5083                
5084
5085
5086                } else if (index < skeletons.length) {
5087                    // Remove empty skeleton (right to left)
5088                    var emptySkeletonIndex = skeletons.length - 1 - (index - newCards.length);
5089                    jQuery(skeletons[emptySkeletonIndex]).fadeOut(200, function() {
5090                        jQuery(this).remove();
5091                    });
5092                } else if (index < newCards.length) {
5093                    // Add extra card (more cards than skeletons)
5094                    container.append(jQuery(newCards[index]));
5095                }
5096            }, delay);
5097        })(i);
5098        
5099        delay += intervalTime;
5100
5101    } 
5102
5103    
5104    // Add pagination after all skeletons are processed
5105    if (pagination.length > 0) {
5106        setTimeout(function() {
5107            container.append(pagination);
5108        }, delay + 200);
5109    }
5110    
5111
5112    // Add pagination2 after all skeletons are processed
5113    if (pagination2.length > 0) {
5114        setTimeout(function() {
5115            container.append(pagination2);
5116        }, delay + 200);
5117    }
5118
5119
5120    // Add pagination3 after all skeletons are processed
5121    if (pagination3.length > 0) {
5122 
5123        setTimeout(function() {
5124            container.append(pagination3);
5125        }, delay + 200);
5126    }
5127    
5128
5129   
5130     // Add pagination2 after all skeletons are processed
5131    if (no_results.length > 0) {
5132        setTimeout(function() {
5133            container.append(no_results);
5134        }, delay + 200);
5135    }
5136
5137
5138     // Call restart JS after all real cards are displayed
5139    setTimeout(function() {
5140        if (typeof wpestate_restart_js_after_ajax === 'function') {
5141            wpestate_restart_js_after_ajax();
5142        }
5143    }, delay + 300);
5144
5145}
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155/**
5156 * Creates a skeleton placeholder card
5157 */
5158function wpestate_createSkeletonCard(gridClasses, cardClasses, is_grid) {
5159    var skeletonCard = `
5160    <div class="${gridClasses} listing_wrapper skeleton-placeholder">
5161        <div class="${cardClasses} skeleton-card">
5162            <div class="listing-unit-img-wrapper">
5163                <div class="skeleton-image skeleton-shimmer"></div>
5164            </div>
5165            <div class="property-unit-information-wrapper">
5166                <div class="skeleton-text title skeleton-shimmer"></div>
5167                <div class="skeleton-text category skeleton-shimmer"></div>
5168                <div class="skeleton-text details skeleton-shimmer"></div>
5169            </div>
5170        </div>
5171    </div>`;
5172    
5173    if (is_grid) {
5174        return `<div class="shortcode_wrapper_grid_item">${skeletonCard}</div>`;
5175    }
5176    
5177    return skeletonCard;
5178}
5179
5180
5181
5182
5183
5184/*
5185* Mobile Menu Elementor open/close 
5186*/
5187
5188function wpestate_elementor_mobile_menu_trigger_open(){
5189    jQuery('.wpestate_mobile_menu_trigger').on('click', function(event) {
5190            jQuery(this).hide();
5191            const parent = jQuery(this).parent();
5192            const openButton=parent.find('.wpestate_mobile_menu_trigger_close');
5193            var menu = parent.find('.mobilex-menu');
5194
5195
5196            jQuery('.wpestate_mobile_menu_trigger_close').show();
5197            // Show the menu first to measure it correctly
5198            menu.css('display', 'block');
5199
5200            var containerRect = openButton[0].getBoundingClientRect();
5201
5202            var margin = 0; // Margin from the viewport edges
5203
5204            // Calculate the left position of the child
5205            var childLeft = -containerRect.left +margin;
5206
5207            // Apply the calculated positions
5208           // menu.css('left', childLeft + 'px');
5209            menu.css('width', 'calc(100vw - ' + (margin * 2) + 'px)');
5210
5211   
5212    });
5213
5214    jQuery('.wpestate_mobile_menu_trigger_close').on('click',function(event){
5215        jQuery(this).hide();
5216        const parent=jQuery(this).parent();    
5217        var menu = parent.find('.mobilex-menu');
5218        menu.css('transform', '');
5219        jQuery('.wpestate_mobile_menu_trigger').show();
5220        parent.find('.mobilex-menu').hide();
5221    });
5222
5223}
5224
5225
5226
5227
5228function wprentals_custom_header_half_map_position(){
5229  if (jQuery('.is_half_map').length >0 ){
5230    // The map columns start where the header ENDS, not at its height: when the admin
5231    // bar is on, the theme pushes the page down 32px (body.admin-bar margin-top), so the
5232    // header's own top offset has to be added or the fixed map covers the header (#331).
5233    var site_header=jQuery('header');
5234    // The standard theme header has no <header> element - nothing to align to.
5235    if (site_header.length === 0) {
5236        return;
5237    }
5238    var header_height=site_header.offset().top + site_header.outerHeight();
5239console.log(header_height);
5240
5241        // The header offset only applies while the half map columns are position:fixed (desktop).
5242        // At 991px and below my_media.css makes them position:relative, where an inline top
5243        // pushes them down and leaves an empty gap under the header - so clear it there.
5244        var half_map_columns = jQuery('#google_map_prop_list_sidebar, #google_map_prop_list_wrapper');
5245        if ( half_map_columns.css('position') === 'fixed' ) {
5246            half_map_columns.css('top',header_height);
5247        } else {
5248            half_map_columns.css('top','');
5249        }
5250
5251  }
5252
5253}
5254
5255
5256jQuery(window).on('elementor/frontend/init', function() {
5257    wprentals_custom_header_half_map_position();
5258});

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.