PageSourceSearch

https://havensuitesbnb.com/wp-content/themes/houzez/js/custom.js?ver=3.4.2

js havensuitesbnb.com collected 2026-10-05 23:33:38 UTC 198,227 bytes, 5,018 lines download raw bytes

1/*
2 Theme Name: houzez
3 Description: houzez
4 Author: Favethemes
5 Version: 1.0
6 */
7 var houzezThemeGlobal = {};
8
9(function ($) {
10    "use strict";
11
12    /* ------------------------------------------------------------------------ */
13    /*  global variables
14    /* ------------------------------------------------------------------------ */
15    var $win = $(window);
16    var popupSliderLoaded = false;
17    var houzezStickyTop = 0;
18    var adminBarHeight = 0;
19    var ajaxurl = houzez_vars.admin_url+ 'admin-ajax.php';
20    var compare_url = houzez_vars.compare_url;
21    var houzez_rtl = houzez_vars.houzez_rtl;
22    var userID = houzez_vars.user_id;
23    var wp_is_mobile = houzez_vars.wp_is_mobile;
24    var houzez_is_splash = houzez_vars.houzez_is_splash;
25    var prop_detail_nav = houzez_vars.prop_detail_nav;
26    var search_position = houzez_vars.search_position;
27    var is_singular_property = houzez_vars.is_singular_property;
28    var transparent_logo = houzez_vars.transparent_logo;
29    var is_transparent = houzez_vars.is_transparent;
30    var is_top_header = houzez_vars.is_top_header;
31    var houzez_date_language = houzez_vars.houzez_date_language;
32    var compare_add_icon = houzez_vars.compare_add_icon;
33    var add_compare_text = houzez_vars.add_compare_text;
34    var compare_remove_icon = houzez_vars.compare_remove_icon;
35    var remove_compare_text = houzez_vars.remove_compare_text;
36    var compare_limit = houzez_vars.compare_limit;
37    var compare_page_not_found = houzez_vars.compare_page_not_found;
38    var g_recaptha_version = houzez_vars.g_recaptha_version;
39    var for_rent = houzez_vars.for_rent;
40    var listings_not_found = houzez_vars.listings_not_found;
41    var for_rent_price_slider = houzez_vars.for_rent_price_slider;
42    var search_price_range_min = parseInt( houzez_vars.search_min_price_range );
43    var search_price_range_max = parseInt( houzez_vars.search_max_price_range );
44    var search_price_range_min_rent = parseInt( houzez_vars.search_min_price_range_for_rent );
45    var search_price_range_max_rent = parseInt( houzez_vars.search_max_price_range_for_rent );
46    var get_min_price = parseInt( houzez_vars.get_min_price );
47    var get_max_price = parseInt( houzez_vars.get_max_price );
48    var currency_position = houzez_vars.currency_position;
49    var decimals = houzez_vars.decimals;
50    var decimal_point_separator = houzez_vars.decimal_point_separator;
51    var thousands_separator = houzez_vars.thousands_separator;
52    var currency_symb = houzez_vars.currency_symbol;
53    var is_halfmap = parseInt(houzez_vars.is_halfmap);
54    var houzez_reCaptcha = parseInt(houzez_vars.houzez_reCaptcha);
55    var prev_text = houzez_vars.prev_text
56    var next_text = houzez_vars.next_text
57    var listing_pagination = houzez_vars.listing_pagination
58    var keyword_search_field = houzez_vars.keyword_search_field;
59    var keyword_autocomplete = houzez_vars.keyword_autocomplete;
60    var autosearch_text = houzez_vars.autosearch_text;
61    var login_redirect_type = houzez_vars.redirect_type
62    var login_redirect = houzez_vars.login_redirect
63    var login_loading = houzez_vars.login_loading
64    var paypal_connecting = houzez_vars.paypal_connecting;
65    var processing_text = houzez_vars.processing_text;
66    var is_edit_property = houzez_vars.is_edit_property;
67    var property_gallery_popup_type = houzez_vars.property_gallery_popup_type;
68
69    var simple_logo = houzez_vars.simple_logo;
70    var retina_logo = houzez_vars.retina_logo;
71    var mobile_logo = houzez_vars.mobile_logo;
72    var retina_logo_mobile = houzez_vars.retina_logo_mobile;
73    var retina_logo_mobile_splash = houzez_vars.retina_logo_mobile_splash;
74    var custom_logo_splash = houzez_vars.custom_logo_splash;
75    var retina_logo_splash = houzez_vars.retina_logo_splash;
76    var calDoughnutChart;
77    var is_listing_gallery_slider = false;
78
79    var top_banner_wrap_height = 0;
80    var top_banner_wrap  = $('.top-banner-wrap ');
81
82    var header_area = $('.header-main-wrap');
83    var advanced_search_nav = $('.advanced-search-nav');
84    var desktop_header_search_enabled = advanced_search_nav.data('sticky');
85
86    var elementor_location_header = $('.elementor-location-header');
87    var header_area_height = header_area.innerHeight();
88    var elementor_location_header_height = elementor_location_header.innerHeight();
89    var advanced_search_nav_height = advanced_search_nav.innerHeight();
90
91    var header_nav = $('#header-section');
92    var houzez_nav_sticky_height = header_nav.innerHeight();
93    var only_nav_sticky = header_nav.data('sticky');
94
95    houzezThemeGlobal.$body = $('body');
96    houzezThemeGlobal.$document = $(document);
97    houzezThemeGlobal.$window = $(window);
98
99    houzezThemeGlobal.houzezEleAddAction = function(name, callback) {
100        houzezThemeGlobal.$window.on('elementor/frontend/init', function() {
101            if ( !elementorFrontend.isEditMode() ) {
102                return;
103            }
104
105            elementorFrontend.hooks.addAction(name, callback);
106        });
107    }
108    
109    var houzez_is_mobile = /ipad|iphone|ipod|android|blackberry|webos|iemobile|windows phone/i.test(navigator.userAgent.toLowerCase());
110
111    if( prop_detail_nav == 'yes' && is_singular_property) {
112        only_nav_sticky = 0;
113    }
114
115    if(elementor_location_header_height == null) {
116        elementor_location_header_height = 0;
117    }
118
119    if(header_area_height == null) {
120        header_area_height = 0;
121    }
122
123    if(advanced_search_nav_height == null) {
124        advanced_search_nav_height = 0;
125    }
126
127    if( houzez_rtl == 'yes' ) {
128        houzez_rtl = true;
129    } else {
130        houzez_rtl = false;
131    }
132
133    if(only_nav_sticky === 1) {
134        houzezStickyTop = houzez_nav_sticky_height;
135        if( !wp_is_mobile ) {
136            desktop_header_search_enabled = 0;
137        }
138    }
139
140    var make_search_sticky_position = header_area_height + advanced_search_nav_height;
141    var searchStickyPlus = 100;
142    var search_under_navigation = true;
143    if( wp_is_mobile ) {
144        make_search_sticky_position = make_search_sticky_position + 40;
145    } 
146
147    $(document).ready(function() {
148       top_banner_wrap_height  = top_banner_wrap.innerHeight();
149
150       if(search_position == 'under_banner') {
151            make_search_sticky_position = header_area_height + top_banner_wrap_height;
152            searchStickyPlus = 0;
153            if( wp_is_mobile ) {
154                searchStickyPlus = 60;
155            }
156            if( is_transparent ) {
157                searchStickyPlus = 60;
158            }
159            search_under_navigation = false;
160        }
161
162       adminBarHeight = $('#wpadminbar').innerHeight();
163       if(adminBarHeight != null) {
164            houzezStickyTop = houzezStickyTop + adminBarHeight;
165       }
166
167    });
168
169    function HouzezDebounce(func, delay) {
170        let debounceTimer;
171        return function() {
172            const context = this;
173            const args = arguments;
174            clearTimeout(debounceTimer);
175            debounceTimer = setTimeout(() => func.apply(context, args), delay);
176        };
177    }
178
179    function parseBool(str) {
180        if( str == 'true' ) { return true; } else { return false; }
181    }
182
183    /* ------------------------------------------------------------------------ */
184    /*  force video background to play on safari 11
185    /* ------------------------------------------------------------------------ */
186    $(document).ready(function() {
187        if( $('#video-background').length > 0 ) {
188            $('#video-background').data('vide').getVideoObject().play();
189        }
190    });
191
192    function adjustMegaMenu(megaMenuSelector, containerSelector, fullwidthClass, customWidthClass, customWidthPx) {
193        jQuery(megaMenuSelector).each(function() {
194            var windowWidth = jQuery(window).width();
195            var isRTL = jQuery('html').attr('dir') === 'rtl'; // Check if the page is RTL
196
197            if (jQuery(this).closest(fullwidthClass).length > 0) {
198                // Full viewport width
199                jQuery(this).css('width', '100vw');
200                var position = jQuery(this).offset().left * -1;
201                //jQuery(this).css(isRTL ? 'right' : 'left', position + 'px');
202
203                if (isRTL) {
204                    jQuery(this).css('right', position * -1 + 'px');
205                } else {
206                    jQuery(this).css('left', position + 'px');
207                }
208
209            } else if (jQuery(this).closest(customWidthClass).length > 0) {
210                // Set custom width
211                jQuery(this).css('width', customWidthPx + 'px');
212
213                var menuItem = jQuery(this).closest('.nav-item');
214                var menuItemOffset = menuItem.offset().left;
215                var position = menuItemOffset - jQuery(this).parent().offset().left;
216
217                // Check if the dropdown goes outside the window
218                if (menuItemOffset + customWidthPx > windowWidth) {
219                    // Open towards the left (or right in RTL) side of the menu item
220                    position -= (customWidthPx - menuItem.width());
221                }
222
223                if (isRTL) {
224                    jQuery(this).css('right', position * -1 + 'px');
225                } else {
226                    jQuery(this).css('left', position + 'px');
227                }
228
229            } else {
230                // Width of the nearest container
231                var containerWidth = jQuery(this).closest(containerSelector).width();
232                jQuery(this).css('width', containerWidth);
233                // Positioning relative to container
234                var containerOffset = jQuery(this).closest(containerSelector).offset().left;
235                var megamenuOffset = jQuery(this).closest('.nav-item').offset().left;
236                var position = containerOffset - megamenuOffset;
237                //jQuery(this).css(isRTL ? 'right' : 'left', position + 'px');
238
239                if (isRTL) {
240                    jQuery(this).css('right', position * -1 + 'px');
241                } else {
242                    jQuery(this).css('left', position + 'px');
243                }
244            }
245        });
246    }
247
248    function setMenuFullWidthEle() {
249        if ($('#houzez_toggle').length > 0) {
250            var isRTL = $('html').attr('dir') === 'rtl'; // Check if the page is RTL
251
252            var leftDistance;
253            leftDistance = $('#houzez_toggle').offset().left;
254            //alert(leftDistance);
255            $('.houzez-nav-mobile-menu-fullwidth .main-mobile-nav').css('left', 'calc(50vw - ' + leftDistance + 'px)');
256
257            console.log('Distance from the left:', leftDistance);
258        }
259    }
260
261    // Call the function with specific class names
262    $(window).on('load', function () {
263        adjustMegaMenu('.houzez-elementor-menu .dropdown-menu.megamenu', '.e-con-inner', '.menu-item-design-full-width', '.menu-item-design-custom-size', 200);
264        setTimeout(setMenuFullWidthEle, 500); // Delay of 1000 milliseconds (1 second)
265
266    });
267
268    // Re-adjust the megamenu on window resize
269    $(window).resize(function() {
270        adjustMegaMenu('.houzez-elementor-menu .dropdown-menu.megamenu', '.e-con-inner', '.menu-item-design-full-width', '.menu-item-design-custom-size', 200);
271        setMenuFullWidthEle();
272    });
273
274
275    /* ------------------------------------------------------------------------ */
276    /*  Property Images Gallery
277    /* ------------------------------------------------------------------------ */
278    if( $('.hs-gallery-v3-wrap').length > 0 || $('.hs-gallery-v2-wrap .top-gallery-section').length > 0 ) {
279        function adjustTabContentHeight() {
280            var galleryHeight = $('.hs-property-gallery-wrap .top-gallery-section').height();
281            $('.tab-content').css('height', galleryHeight);
282        }
283
284        function checkAndAdjustLayout() {
285            adjustTabContentHeight();
286        }
287
288        // Recalculate the height on window load and resize
289        $(window).on('load resize', function() {
290            checkAndAdjustLayout();
291        });
292
293        // Initial calculation
294        checkAndAdjustLayout();
295    }
296
297    /* ------------------------------------------------------------------------ */
298    /*  lazy load
299    /* ------------------------------------------------------------------------ */
300    function houzez_lazyload() {
301        document.addEventListener("DOMContentLoaded", function() {
302          var lazyImages = [].slice.call(document.querySelectorAll(".houzez-lazyload"));
303
304          if ("IntersectionObserver" in window) {
305            let lazyImageObserver = new IntersectionObserver(function(entries, observer) {
306              entries.forEach(function(entry) {
307                if (entry.isIntersecting) {
308                  let lazyImage = entry.target;
309                  lazyImage.src = lazyImage.dataset.src;
310                  if(lazyImage.dataset.srcset) {
311                      lazyImage.srcset = lazyImage.dataset.srcset;
312                  }
313                  lazyImage.classList.remove("houzez-lazyload");
314                  lazyImageObserver.unobserve(lazyImage);
315                }
316              });
317            });
318
319            lazyImages.forEach(function(lazyImage) {
320              lazyImageObserver.observe(lazyImage);
321            });
322          } else {
323            // Possibly fall back to a more compatible method here
324          }
325        });
326    }
327    houzez_lazyload();
328
329    function houzez_lazyload_for_ajax() {
330        var lazyImages = [].slice.call(document.querySelectorAll(".houzez-lazyload"));
331
332      if ("IntersectionObserver" in window) {
333        let lazyImageObserver = new IntersectionObserver(function(entries, observer) {
334          entries.forEach(function(entry) {
335            if (entry.isIntersecting) {
336              let lazyImage = entry.target;
337              lazyImage.src = lazyImage.dataset.src;
338              if(lazyImage.dataset.srcset) {
339                  lazyImage.srcset = lazyImage.dataset.srcset;
340              }
341              lazyImage.classList.remove("houzez-lazyload");
342              lazyImageObserver.unobserve(lazyImage);
343            }
344          });
345        });
346
347        lazyImages.forEach(function(lazyImage) {
348          lazyImageObserver.observe(lazyImage);
349        });
350      } else {
351        // Possibly fall back to a more compatible method here
352      }
353    }
354    houzez_lazyload_for_ajax();
355
356    
357    /* ------------------------------------------------------------------------ */
358    /*  Retina logo
359    /* ------------------------------------------------------------------------ */
360    if ( retina_logo !== '' || retina_logo_splash != '' || retina_logo_mobile != '' || retina_logo_mobile_splash != '' ) { 
361        if (window.devicePixelRatio == 2) {
362
363            if( retina_logo != '' ) {
364                $(".logo-desktop img").attr("src", retina_logo);
365            }
366
367            if( retina_logo_splash != '' ) {
368                $(".logo-splash img").attr("src", retina_logo_splash);
369            } 
370
371            if( retina_logo_mobile != '' ) {
372                $(".logo-mobile img").attr("src", retina_logo_mobile);
373            } 
374        }
375    }
376
377
378    $('.all-reviews').on('click', function(e) { 
379        $('.hz-review-tab').trigger('click');
380    });
381
382    /*-----------------------------------------------------------------------------------*/
383    /*  Scroll to Top
384     /*-----------------------------------------------------------------------------------*/
385    $(function () {
386        var scroll_anchor = $('#scroll-top');
387
388        $(window).on('scroll', function () {
389            if ($(this).scrollTop() > 300) {
390                scroll_anchor.fadeIn('fast').css("display","block");
391                return;
392            }
393            // }
394            scroll_anchor.fadeOut('fast');
395        });
396
397        scroll_anchor.on('click', function (event) {
398            event.preventDefault();
399            $('html, body').animate({ scrollTop: 0 }, 'slow');
400        });
401    });
402
403    /* ------------------------------------------------------------------------ */
404    /*  Schedule tour v2
405    /* ------------------------------------------------------------------------ */
406    
407    /*$('.tour-day-form-slide-arrow.next').click(function (e) {
408        $('.property-schedule-tour-day-form-slide').addClass("end");    
409        $('.property-schedule-tour-day-form-slide').removeClass("start");    
410    });
411    $('.tour-day-form-slide-arrow.prev').click(function (e) {
412        $('.property-schedule-tour-day-form-slide').addClass("start");    
413        $('.property-schedule-tour-day-form-slide').removeClass("end");    
414    });*/
415
416    /*-------------------------------------------------------------------
417    * Properties ajax tabs
418    *-------------------------------------------------------------------*/
419    /*$.each([
420        'frontend/element_ready/houzez_properties_tabs.default',
421    ], function(index, value) {
422        houzezThemeGlobal.houzezEleAddAction(value, function() { alert('1111');
423            houzezThemeGlobal.houzezProductsTabs();
424        });
425    });*/
426
427    //houzezThemeGlobal.houzezProductsTabs();
428
429    var houzezProductsTabs = function() {
430        var alreadyProcessed = false;
431
432        $('.houzez-products-tabs-js').each(function() {
433            var $this  = $(this);
434            var $html_container = $this.find('.houzez-tab-content');
435            var $products_cache  = [];
436
437            $this.find('ul.property-nav-tabs li').on('click', function(e) {
438                e.preventDefault();
439
440                var $this = $(this);
441                var settings  = $this.data('json');
442                var data_index = $this.index();
443
444                if ( alreadyProcessed || $this.find('a').hasClass('active') ) {
445                    return;
446                }
447
448                alreadyProcessed = true;
449
450                if ($products_cache[data_index]) {
451                    setTimeout(function() {
452                        $html_container.html($products_cache[data_index].html);
453
454                        houzez_init_add_favorite(ajaxurl, userID);
455                        houzez_init_remove_favorite(ajaxurl, userID);
456                        houzez_listing_lightbox(ajaxurl, processing_text, houzez_rtl, userID);
457                        houzez_grid_image_gallery();
458                        houzez_grid_call_to_action();
459                        compare_for_ajax();
460                        $('[data-toggle="tooltip"]').tooltip();
461
462                        alreadyProcessed = false;
463                    }, 300);
464                    return;
465                }
466
467                $.ajax({
468                    url     : ajaxurl,
469                    data    : {
470                        action: 'houzez_get_properties_tab_content',
471                        settings  : settings
472                    },
473                    dataType: 'json',
474                    method  : 'POST',
475                    beforeSend: function( ) {
476                
477                        $html_container.empty().append(''
478                            +'<div id="houzez-map-loading">'
479                            +'<div class="mapPlaceholder">'
480                            +'<div class="loader-ripple spinner">'
481                            +'<div class="bounce1"></div>'
482                            +'<div class="bounce2"></div>'
483                            +'<div class="bounce3"></div>'
484                            +'</div>'
485                            +'</div>'
486                            +'</div>'
487                        );
488                    },
489                    success : function(data) {
490                        $products_cache[data_index] = data;
491                        $html_container.html(data.html);
492
493                        houzez_init_add_favorite(ajaxurl, userID);
494                        houzez_init_remove_favorite(ajaxurl, userID);
495                        houzez_listing_lightbox(ajaxurl, processing_text, houzez_rtl, userID);
496                        houzez_grid_image_gallery();
497                        houzez_grid_call_to_action();
498                        compare_for_ajax();
499                        $('[data-toggle="tooltip"]').tooltip();
500                    },
501                    error: function(xhr, status, error) {
502                        var err = eval("(" + xhr.responseText + ")");
503                        console.log(err.Message);
504                    },
505                    complete: function() { 
506                        alreadyProcessed = false;
507                    }
508                });
509
510            });
511
512        });
513    };
514    houzezProductsTabs();
515
516    /*-------------------------------------------------------------------
517    * Photo Swipe
518    *-------------------------------------------------------------------*/
519    var initPhotoSwipeFromDOM = function(gallerySelector) {
520
521        // parse slide data (url, title, size ...) from DOM elements 
522        // (children of gallerySelector)
523        var parseThumbnailElements = function(el) {
524            var thumbElements = el.childNodes,
525                numNodes = thumbElements.length,
526                items = [],
527                figureEl,
528                linkEl,
529                size,
530                item;
531
532            for(var i = 0; i < numNodes; i++) {
533                figureEl = thumbElements[i]; // <figure> element
534
535                // include only element nodes 
536                if(figureEl.nodeType !== 1) {
537                    continue;
538                }
539
540                linkEl = figureEl.children[0]; // <a> element
541
542                // Check if linkEl exists
543                if (!linkEl) {
544                    console.warn('Expected <a> element not found within figure element.');
545                    continue;
546                }
547
548                size = linkEl.getAttribute('data-size');
549                
550                // Check if size attribute exists
551                if (!size) {
552                    console.warn('Expected data-size attribute not found on <a> element.');
553                    continue;
554                }
555
556                size = size.split('x');
557
558                // create slide object
559                item = {
560                    src: linkEl.getAttribute('href'),
561                    w: parseInt(size[0], 10),
562                    h: parseInt(size[1], 10)
563                };
564
565                if(figureEl.children.length > 1) {
566                    // <figcaption> content
567                    item.title = figureEl.children[1].innerHTML; 
568                }
569
570                if(linkEl.children.length > 0) {
571                    // <img> thumbnail element, retrieving thumbnail url
572                    item.msrc = linkEl.children[0].getAttribute('src');
573                } 
574
575                item.el = figureEl; // save link to element for getThumbBoundsFn
576                items.push(item);
577            }
578
579
580            return items;
581        };
582
583        // find nearest parent element
584        var closest = function closest(el, fn) {
585            return el && ( fn(el) ? el : closest(el.parentNode, fn) );
586        };
587
588        // triggers when user clicks on thumbnail
589        var onThumbnailsClick = function(e) {
590            e = e || window.event;
591            e.preventDefault ? e.preventDefault() : e.returnValue = false;
592
593            var eTarget = e.target || e.srcElement;
594
595            // find root element of slide
596            var clickedListItem = closest(eTarget, function(el) {
597                return (el.tagName && ( el.tagName.toUpperCase() === 'FIGURE' ||  el.tagName.toUpperCase() === 'DIV' ) );
598            });
599
600            if(!clickedListItem) {
601                return;
602            }
603
604            // find index of clicked item by looping through all child nodes
605            // alternatively, you may define index via data- attribute
606            var clickedGallery = clickedListItem.parentNode,
607                childNodes = clickedListItem.parentNode.childNodes,
608                numChildNodes = childNodes.length,
609                nodeIndex = 0,
610                index;
611
612            for (var i = 0; i < numChildNodes; i++) {
613                if(childNodes[i].nodeType !== 1) { 
614                    continue; 
615                }
616
617                if(childNodes[i] === clickedListItem) {
618                    index = nodeIndex;
619                    break;
620                }
621                nodeIndex++;
622            }
623
624
625
626            if(index >= 0) {
627                // open PhotoSwipe if valid index found
628                openPhotoSwipe( index, clickedGallery );
629            }
630            return false;
631        };
632
633        // parse picture index and gallery index from URL (#&pid=1&gid=2)
634        var photoswipeParseHash = function() {
635            var hash = window.location.hash.substring(1),
636            params = {};
637
638            if(hash.length < 5) {
639                return params;
640            }
641
642            var vars = hash.split('&');
643            for (var i = 0; i < vars.length; i++) {
644                if(!vars[i]) {
645                    continue;
646                }
647                var pair = vars[i].split('=');  
648                if(pair.length < 2) {
649                    continue;
650                }           
651                params[pair[0]] = pair[1];
652            }
653
654            if(params.gid) {
655                params.gid = parseInt(params.gid, 10);
656            }
657
658            return params;
659        };
660
661        var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) {
662            var pswpElement = document.querySelectorAll('.pswp')[0];
663            if (!pswpElement) {
664                console.error('PhotoSwipe element not found.');
665                return;
666            }
667
668            var gallery, options, items;
669
670            items = parseThumbnailElements(galleryElement);
671
672            // Check if the item has an image (thumbnail) before passing it to PhotoSwipe
673            if (!items[index] || !items[index].el) {
674                console.error('Expected item or element not found at index: ', index);
675                return;
676            }
677
678            // Define options (if needed)
679            options = {
680                // Define gallery index (for URL)
681                galleryUID: galleryElement.getAttribute('data-pswp-uid'),
682
683                getThumbBoundsFn: function(index) {
684                    var thumbnail = items[index].el.getElementsByTagName('img')[0];
685                    if (!thumbnail) {
686                        console.error('Thumbnail not found for index: ', index);
687                        return {x: 0, y: 0, w: 0}; // Default value
688                    }
689
690                    var pageYScroll = window.pageYOffset || document.documentElement.scrollTop,
691                        rect = thumbnail.getBoundingClientRect();
692
693                    return {x: rect.left, y: rect.top + pageYScroll, w: rect.width};
694                }
695            };
696
697            options.closeOnScroll = false;
698            options.bgOpacity = 0.95;
699            options.showHideOpacity = false;
700            options.history = false;
701
702            // PhotoSwipe opened from URL
703            if (fromURL) {
704                if (options.galleryPIDs) {
705                    // parse real index when custom PIDs are used
706                    for (var j = 0; j < items.length; j++) {
707                        if (items[j].pid == index) {
708                            options.index = j;
709                            break;
710                        }
711                    }
712                } else {
713                    // in URL indexes start from 1
714                    options.index = parseInt(index, 10) - 1;
715                }
716            } else {
717                options.index = parseInt(index, 10);
718            }
719
720            // Exit if index not found
721            if (isNaN(options.index)) {
722                console.error('Invalid index for PhotoSwipe:', options.index);
723                return;
724            }
725
726            if (disableAnimation) {
727                options.showAnimationDuration = 0;
728            }
729
730            // Pass data to PhotoSwipe and initialize it
731            gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
732            gallery.init();
733        };
734
735
736        // loop through all gallery elements and bind events
737        var galleryElements = document.querySelectorAll( gallerySelector );
738
739        for(var i = 0, l = galleryElements.length; i < l; i++) {
740            galleryElements[i].setAttribute('data-pswp-uid', i+1);
741            galleryElements[i].onclick = onThumbnailsClick;
742        }
743
744        // Parse URL and open gallery if it contains #&pid=3&gid=1
745        var hashData = photoswipeParseHash();
746        if(hashData.pid && hashData.gid) {
747            openPhotoSwipe( hashData.pid ,  galleryElements[ hashData.gid - 1 ], true, true );
748        }
749    };
750
751    // execute above function
752    document.addEventListener('DOMContentLoaded', function() {
753        if (property_gallery_popup_type == 'photoswipe' && is_singular_property) {
754            initPhotoSwipeFromDOM('.houzez-photoswipe');
755        }
756    });
757
758
759
760    /* ------------------------------------------------------------------------ */
761    /*  STICKY HEADER
762    /* ------------------------------------------------------------------------ */
763    if (window.devicePixelRatio == 2) {
764
765        if(transparent_logo) {
766            if(retina_logo_splash != '') {
767                custom_logo_splash = retina_logo_splash;
768            }
769            if(retina_logo != '') {
770                simple_logo = retina_logo;
771            }
772        } 
773    }
774
775
776    if( only_nav_sticky && !wp_is_mobile ) {
777        houzez_sticky_nav();
778
779        if( $('.compare-table').length > 0 ) {
780            var compare_top_margin = advanced_search_nav.outerHeight();
781            $('.compare-table thead th').css('top', compare_top_margin + 25);
782        }
783    }
784
785    function houzez_sticky_nav() {
786        $(window).scroll(function() {
787            var scroll = $(window).scrollTop();
788            var admin_nav = $('#wpadminbar').height();
789            var top_banner_margin = 0;
790            var thisHeight = header_nav.outerHeight();
791            top_banner_margin = thisHeight;
792
793            if(is_top_header != 0) { 
794                var top_bar_wrap = $('.top-bar-wrap').height();
795                top_banner_margin = top_banner_margin + top_bar_wrap;
796            }
797
798            if(only_nav_sticky === 0) {
799                return;
800            }
801
802            if(transparent_logo) {
803                $('.logo-splash img').attr('src', simple_logo);
804            }
805
806            if( admin_nav == 'null' ) { admin_nav = 0; }
807
808            if (scroll > header_area_height ) { 
809                header_nav.addClass('sticky-nav-area');
810                header_nav.css('top', admin_nav);
811                if(transparent_logo){ 
812                    header_area.removeClass('header-transparent-wrap');
813                    $('.top-banner-wrap').css('margin-top', "-"+top_banner_margin+"px");
814                    $('body.houzez-header-elementor .content-wrap').css('margin-top', "-"+top_banner_margin+"px");
815                    $('#main-wrap > div.elementor').css('margin-top', "-"+top_banner_margin+"px");
816                }
817
818                if (scroll >= header_area_height + 20 ) { 
819                    header_nav.addClass('houzez-in-view');
820                    $('#main-wrap').css('margin-top', thisHeight);
821                }
822
823            } else { 
824                header_nav.removeClass('sticky-nav-area');
825                header_nav.removeAttr("style");
826                if(transparent_logo){
827                    header_area.addClass('header-transparent-wrap');
828                    $('.top-banner-wrap').css('margin-top', 0);
829                    $('body.houzez-header-elementor .content-wrap').css('margin-top', 0);
830                    $('#main-wrap > div.elementor').css('margin-top', 0);
831                    $('.logo-splash img').attr('src', custom_logo_splash);
832                }
833
834                if (scroll <= header_area_height + 20 ) { 
835                    header_nav.removeClass('houzez-in-view');
836                }
837                $('#main-wrap').css('margin-top', 0);
838            }
839        });
840    }
841
842    /* ------------------------------------------------------------------------ */
843    /*  STICKY Header Search
844    /* ------------------------------------------------------------------------ */
845    if( desktop_header_search_enabled ) {
846        houzez_sticky_search();
847    }
848
849    function houzez_sticky_search() {
850        $(window).scroll(function() {
851            var scroll = $(window).scrollTop();
852            var admin_nav = $('#wpadminbar').height();
853            var thisHeight = advanced_search_nav.outerHeight();
854            var hidden_data = advanced_search_nav.data('hidden');
855
856            if( admin_nav == 'null' ) { admin_nav = 0; }
857
858            if (scroll  >= make_search_sticky_position ) { 
859
860                advanced_search_nav.addClass('sticky-search-area');
861                if(hidden_data) {
862                    advanced_search_nav.removeClass('search-hidden');
863                }
864
865                if( !wp_is_mobile ) {
866                    advanced_search_nav.css('top', admin_nav);
867                }
868
869                if (scroll >= make_search_sticky_position + searchStickyPlus ) { 
870                    advanced_search_nav.addClass('houzez-in-view');
871                    
872                    if( !hidden_data ) {
873                        $('#main-wrap').css('padding-top',thisHeight);
874                    }
875    
876                }
877            } else { 
878                advanced_search_nav.removeClass('sticky-search-area');
879                advanced_search_nav.removeAttr("style");
880                if (scroll <= make_search_sticky_position + 20 ) { 
881                    advanced_search_nav.removeClass('houzez-in-view');
882                }
883                if(hidden_data) {
884                    advanced_search_nav.addClass('search-hidden');
885                }
886                if( !hidden_data ) {
887                    $('#main-wrap').css('padding-top', 0);
888                }
889    
890            }
891        });
892    }
893
894    /*var header_mobile = $('#header-mobile');
895    var mobile_sticky_nav = header_mobile.data('sticky');
896    if( mobile_sticky_nav && wp_is_mobile ) {
897        houzez_mobile_sticky_nav();
898    }*/
899    function houzez_mobile_sticky_nav() {
900        $(window).scroll(function() {
901            var scroll = $(window).scrollTop();
902            var admin_nav = 0;//$('#wpadminbar').height();
903            var top_banner_margin = 0;
904            var thisHeight = header_mobile.outerHeight();
905            top_banner_margin = thisHeight;
906
907            if(is_top_header) {
908                var top_bar_wrap = $('.top-bar-wrap').height();
909                top_banner_margin = top_banner_margin + top_bar_wrap;
910            }
911
912            if(mobile_sticky_nav === 0) {
913                return;
914            }
915
916
917            if( admin_nav == 'null' ) { admin_nav = 0; }
918
919            if (scroll > header_area_height ) { 
920                header_mobile.addClass('sticky-nav-area');
921                //header_mobile.css('top', admin_nav);
922                
923                if (scroll >= header_area_height + 20 ) { 
924                    header_mobile.addClass('houzez-in-view');
925                    $('#main-wrap').css('margin-top', thisHeight);
926                }
927
928            } else { 
929                header_mobile.removeClass('sticky-nav-area');
930                header_mobile.removeAttr("style");
931
932                if (scroll <= header_area_height + 20 ) { 
933                    header_mobile.removeClass('houzez-in-view');
934                }
935                $('#main-wrap').css('margin-top', 0);
936            }
937        });
938    }
939
940    /* ------------------------------------------------------------------------ */
941    /*  Add Comma to value
942    /* ------------------------------------------------------------------------ */
943    var addCommas = function (nStr) {
944        nStr += '';
945        var x = nStr.split('.');
946        var x1 = x[0];
947        var x2 = x.length > 1 ? '.' + x[1] : '';
948        var rgx = /(\d+)(\d{3})/;
949        while (rgx.test(x1)) {
950            x1 = x1.replace(rgx, '$1' + ',' + '$2');
951        }
952        return x1 + x2;
953    }
954
955    var thousandSeparator = (n) => {
956        if (typeof n === 'number') {
957            n += '';
958            var x = n.split('.');
959            var x1 = x[0];
960            var x2 = x.length > 1 ? '.' + x[1] : '';
961            var rgx = /(\d+)(\d{3})/;
962            while (rgx.test(x1)) {
963                x1 = x1.replace(rgx, '$1' + thousands_separator + '$2');
964            }
965            return x1 + x2;
966        } else {
967            return n;
968        }
969    }
970
971    /* ------------------------------------------------------------------------ */
972    /*  Number format
973     /* ------------------------------------------------------------------------ */
974    function number_format( number ) {
975
976        var decimals, dec_point, thousands_sep;
977
978        dec_point = decimal_point_separator;
979        thousands_sep = thousands_separator;
980
981        var i, j, kw, kd, km;
982
983        // input sanitation & defaults
984        if( isNaN( decimals = Math.abs( decimals ) ) ) {
985            decimals = 2;
986        }
987
988        dec_point = dec_point || ",";
989        thousands_sep = thousands_sep || ".";
990
991        i = parseInt(number = (+number || 0).toFixed(decimals)) + "";
992        j = ( j = i.length ) > 3 ? j % 3 : 0;
993
994        km = (j ? i.substr(0, j) + thousands_sep : "");
995        kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
996        
997        kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");
998
999        return km + kw + kd;
1000    }
1001
1002    if( $('#houzez-calculator-form').length > 0 ) {
1003
1004        $('#houzez-calculator-form input').on('input', () => {
1005            mortgage_calucaltion_section();
1006        });
1007
1008        mortgage_calucaltion_section();
1009    }
1010
1011    function calculateMonthlyPayment(principal, annualInterestRate, loanTermInYears) {
1012        const monthlyInterestRate = annualInterestRate / 12 / 100;
1013        const numberOfMonths = loanTermInYears * 12;
1014
1015        if (monthlyInterestRate === 0) {
1016            return principal / numberOfMonths;
1017        }
1018
1019        return principal * (monthlyInterestRate * Math.pow((1 + monthlyInterestRate), numberOfMonths)) / (Math.pow((1 + monthlyInterestRate), numberOfMonths) - 1);
1020    }
1021
1022    // Define a helper function to parse and validate our inputs
1023    function parseInput(selector) {
1024        const rawValue = $(selector).val();
1025
1026        if (!rawValue) return 0;  // if value is empty or undefined, return 0
1027
1028        // Remove any non-digit character except the decimal point
1029        const cleanedValue = rawValue.replace(/[^0-9.]/g, '');
1030
1031        // Parsing to number
1032        const parsedValue = parseFloat(cleanedValue);
1033
1034        // if parsedValue is NaN, return 0, otherwise return the parsed number
1035        return isNaN(parsedValue) ? 0 : parsedValue; 
1036    }
1037
1038
1039    function mortgage_calucaltion_section() {
1040        const homePrice = parseInput('#homePrice');
1041        const downPaymentPercentage = parseInput('#downPaymentPercentage');
1042        const annualInterestRate = parseInput('#annualInterestRate');
1043        const loanTermInYears = parseInput('#loanTermInYears');
1044        const annualPropertyTaxRate = parseInput('#annualPropertyTaxRate');
1045        const annualHomeInsurance = parseInput('#annualHomeInsurance');
1046        const monthlyHOAFees = parseInput('#monthlyHOAFees');
1047        const pmi = parseInput('#pmi');
1048
1049        const downPayment = homePrice * (downPaymentPercentage / 100);
1050        const principal = homePrice - downPayment;
1051        const monthlyPayment = calculateMonthlyPayment(principal, annualInterestRate, loanTermInYears);
1052        const monthlyPropertyTax = (homePrice * (annualPropertyTaxRate / 100)) / 12;
1053        const monthlyHomeInsurance = annualHomeInsurance / 12;
1054
1055        const pmiRequired = (downPayment / homePrice) < 0.2;
1056
1057        const monthlyPMI = pmiRequired ? (principal * (pmi / 100)) / 12 : 0;
1058
1059        const totalMonthlyPayment = monthlyPayment + monthlyPropertyTax + monthlyHomeInsurance + monthlyHOAFees + monthlyPMI;
1060
1061        const loanAmount = homePrice - downPayment;
1062
1063        const formattedDownPayment = number_format(downPayment);
1064        const formattedLoanAmount = number_format(loanAmount);
1065        const formattedMonthlyPayment = number_format(monthlyPayment);
1066        const formattedPropertyTax = number_format(monthlyPropertyTax);
1067        const formattedHomeInsurance = number_format(monthlyHomeInsurance);
1068        const formattedPMI = pmiRequired ? number_format(monthlyPMI) : '';
1069        const formattedHOAFees = number_format(monthlyHOAFees);
1070        const formattedTotalMonthlyPayment = number_format(totalMonthlyPayment);
1071
1072        $('#downPaymentResult').html( currencyFormate(formattedDownPayment) );
1073        $('#loadAmountResult').html( currencyFormate(formattedLoanAmount) );
1074        $('#monthlyMortgagePaymentResult').html( currencyFormate(formattedMonthlyPayment) );
1075        $('#monthlyPropertyTaxResult').html( currencyFormate(formattedPropertyTax) );
1076        $('#monthlyHomeInsuranceResult').html( currencyFormate(formattedHomeInsurance) );
1077
1078        if (pmiRequired) {
1079            $('.rslt-pmi').show();
1080            $('#monthlyPMIResult').html( currencyFormate(formattedPMI) );
1081        } else {
1082            $('.rslt-pmi').hide();
1083        }
1084
1085        $('#monthlyHOAResult').html( currencyFormate(formattedHOAFees) );
1086        $('#m_monthly_val').html( currencyFormate(formattedTotalMonthlyPayment) );
1087
1088        const chartData = [
1089            { label: 'Monthly Mortgage Payment', value: monthlyPayment, color: '#ff6384' },
1090            { label: 'Property Tax', value: monthlyPropertyTax, color: '#36a2eb' },
1091            { label: 'Home Insurance', value: monthlyHomeInsurance, color: '#ffce56' },
1092            { label: 'HOA', value: monthlyHOAFees, color: '#c2d500' },
1093        ];
1094
1095        if (pmiRequired) {
1096            chartData.push({ label: 'PMI', value: monthlyPMI, color: '#4bc0c0' });
1097        }
1098
1099        updateChart(chartData);
1100    }
1101
1102    const inputElements = document.querySelectorAll('#calculator-form input');
1103    inputElements.forEach(input => {
1104        input.addEventListener('input', () => {
1105            formatInputValue(input);
1106            updateResults();
1107        });
1108    });
1109
1110    function updateChart(chartData) {
1111        const ctx = $('#mortgage-calculator-chart')[0].getContext('2d');
1112
1113        if (window.myChart) {
1114            window.myChart.destroy();
1115        }
1116
1117        window.myChart = new Chart(ctx, {
1118            type: 'doughnut',
1119            data: {
1120                //labels: chartData.map(item => item.label),
1121                datasets: [{
1122                    data: chartData.map(item => item.value),
1123                    backgroundColor: chartData.map(item => item.color),
1124                }],
1125            },
1126            options: {
1127                cutoutPercentage: 85,
1128                responsive: false,
1129                tooltips: false,
1130            },
1131        });
1132    }
1133
1134    function currencyFormate(price_value) {
1135        var value;
1136
1137        if( currency_position == '' || currency_symb == '' ) {
1138            return price_value;
1139        }
1140
1141        value = 'after' === currency_position ? price_value + '' + currency_symb : currency_symb + '' + price_value;
1142        return value;
1143        
1144    }
1145
1146    /* ------------------------------------------------------------------------ */
1147    /*  Listing Preview
1148     /* ------------------------------------------------------------------------ */ 
1149    houzez_listing_lightbox(ajaxurl, processing_text, houzez_rtl, userID);
1150
1151    /* ------------------------------------------------------------------------ */
1152    /*  Listing Gallery
1153    /* ------------------------------------------------------------------------ */ 
1154    $(window).on('load', function() {
1155        houzez_grid_image_gallery();
1156        houzez_grid_call_to_action();
1157    });
1158
1159    /* ------------------------------------------------------------------------ */
1160    /*  Cities chart for agent and agency
1161     /* ------------------------------------------------------------------------ */
1162    if( $('#stats-property-cities').length > 0 ) { 
1163        var chartData = $('#stats-property-cities').data('chart');
1164        var ctx = document.getElementById('stats-property-cities').getContext('2d');
1165        var myDoughnutChart = new Chart(ctx, {
1166            type: 'doughnut',
1167            data: {
1168                datasets: [{
1169                    data: chartData,
1170                    backgroundColor: [
1171                    'rgba(255, 99, 132, 0.5)',
1172                    'rgba(54, 162, 235, 0.5)',
1173                    'rgba(255, 206, 86, 0.5)',
1174                    'rgba(75, 192, 192, 0.5)'
1175                    ],
1176                    borderColor: [
1177                    'rgba(255 ,99, 132, 1)',
1178                    'rgba(54, 162, 235, 1)',
1179                    'rgba(255, 206, 86, 1)',
1180                    'rgba(75, 192, 192, 1)'
1181                    ],
1182                    borderWidth: 1
1183                }]
1184            },
1185            options: {
1186                cutoutPercentage: 60,
1187                responsive: false,
1188                tooltips: false,
1189            }
1190        });
1191    }
1192
1193    /* ------------------------------------------------------------------------ */
1194    /*  Status chart for agent and agency
1195     /* ------------------------------------------------------------------------ */
1196    if( $('#stats-property-status').length > 0 ) { 
1197        var chartData = $('#stats-property-status').data('chart');
1198        var ctx = document.getElementById('stats-property-status').getContext('2d');
1199        var myDoughnutChart = new Chart(ctx, {
1200            type: 'doughnut',
1201            data: {
1202                datasets: [{
1203                    data: chartData,
1204                    backgroundColor: [
1205                    'rgba(255, 99, 132, 0.5)',
1206                    'rgba(54, 162, 235, 0.5)',
1207                    'rgba(255, 206, 86, 0.5)',
1208                    'rgba(75, 192, 192, 0.5)'
1209                    ],
1210                    borderColor: [
1211                    'rgba(255 ,99, 132, 1)',
1212                    'rgba(54, 162, 235, 1)',
1213                    'rgba(255, 206, 86, 1)',
1214                    'rgba(75, 192, 192, 1)'
1215                    ],
1216                    borderWidth: 1
1217                }]
1218            },
1219            options: {
1220                cutoutPercentage: 60,
1221                responsive: false,
1222                tooltips: false,
1223            }
1224        });
1225    }
1226
1227    /* ------------------------------------------------------------------------ */
1228    /*  Types chart for agent and agency
1229     /* ------------------------------------------------------------------------ */
1230    $('.houzez-realtor-stats-js[id^="stats-property-"]').each(function() {
1231        var $div = $(this);
1232        var token = $div.data('token');
1233
1234        var statsID = 'stats-property-' + token;
1235        if ($('#' + statsID).length > 0) {
1236            var chartData = $('#' + statsID).data('chart');
1237            var ctx = document.getElementById(statsID).getContext('2d');
1238            var myDoughnutChart = new Chart(ctx, {
1239                type: 'doughnut',
1240                data: {
1241                    datasets: [{
1242                        data: chartData,
1243                        backgroundColor: [
1244                            'rgba(255, 99, 132, 0.5)',
1245                            'rgba(54, 162, 235, 0.5)',
1246                            'rgba(255, 206, 86, 0.5)',
1247                            'rgba(75, 192, 192, 0.5)'
1248                        ],
1249                        borderColor: [
1250                            'rgba(255, 99, 132, 1)',
1251                            'rgba(54, 162, 235, 1)',
1252                            'rgba(255, 206, 86, 1)',
1253                            'rgba(75, 192, 192, 1)'
1254                        ],
1255                        borderWidth: 1
1256                    }]
1257                },
1258                options: {
1259                    cutoutPercentage: 60,
1260                    responsive: false,
1261                    tooltips: false
1262                }
1263            });
1264        }
1265    });
1266
1267    if( $('#stats-property-types').length > 0 ) { 
1268        var chartData = $('#stats-property-types').data('chart');
1269        var ctx = document.getElementById('stats-property-types').getContext('2d');
1270        var myDoughnutChart = new Chart(ctx, {
1271            type: 'doughnut',
1272            data: {
1273                datasets: [{
1274                    data: chartData,
1275                    backgroundColor: [
1276                    'rgba(255, 99, 132, 0.5)',
1277                    'rgba(54, 162, 235, 0.5)',
1278                    'rgba(255, 206, 86, 0.5)',
1279                    'rgba(75, 192, 192, 0.5)'
1280                    ],
1281                    borderColor: [
1282                    'rgba(255 ,99, 132, 1)',
1283                    'rgba(54, 162, 235, 1)',
1284                    'rgba(255, 206, 86, 1)',
1285                    'rgba(75, 192, 192, 1)'
1286                    ],
1287                    borderWidth: 1
1288                }]
1289            },
1290            options: {
1291                cutoutPercentage: 60,
1292                responsive: false,
1293                tooltips: false,
1294            }
1295        });
1296    }
1297
1298    /* ------------------------------------------------------------------------ */
1299    /*  Types chart for agent and agency
1300     /* ------------------------------------------------------------------------ */
1301    if( $('#stats-property-types').length > 0 ) { 
1302        var chartData = $('#stats-property-types').data('chart');
1303        var ctx = document.getElementById('stats-property-types').getContext('2d');
1304        var myDoughnutChart = new Chart(ctx, {
1305            type: 'doughnut',
1306            data: {
1307                datasets: [{
1308                    data: chartData,
1309                    backgroundColor: [
1310                    'rgba(255, 99, 132, 0.5)',
1311                    'rgba(54, 162, 235, 0.5)',
1312                    'rgba(255, 206, 86, 0.5)',
1313                    'rgba(75, 192, 192, 0.5)'
1314                    ],
1315                    borderColor: [
1316                    'rgba(255 ,99, 132, 1)',
1317                    'rgba(54, 162, 235, 1)',
1318                    'rgba(255, 206, 86, 1)',
1319                    'rgba(75, 192, 192, 1)'
1320                    ],
1321                    borderWidth: 1
1322                }]
1323            },
1324            options: {
1325                cutoutPercentage: 60,
1326                responsive: false,
1327                tooltips: false,
1328            }
1329        });
1330    }
1331
1332
1333    /* ------------------------------------------------------------------------ */
1334    /*  Fave login and regsiter
1335     /* ------------------------------------------------------------------------ */
1336    var houzez_login_modal = function() {
1337        jQuery('#login-register-form').modal('show');
1338        jQuery('.login-form-tab').addClass('active show');
1339        jQuery('.modal-toggle-1.nav-link').addClass('active');
1340    }
1341
1342    $('#houzez-login-btn').on('click', function(e){
1343        e.preventDefault();
1344        var currnt = $(this);
1345        houzez_login( currnt );
1346    });
1347
1348    $('#houzez-register-btn').on('click', function(e){
1349        e.preventDefault();
1350        var currnt = $(this);
1351        houzez_register( currnt );
1352    });
1353
1354    $('#houzez-create-account-btn').on('click', function(e){
1355        e.preventDefault();
1356        var currnt = $(this);
1357        houzez_social_create_account( currnt );
1358    });
1359
1360    var houzez_login = function( currnt ) {
1361        var $form = currnt.parents('form');
1362        var $messages = $('#hz-login-messages');
1363
1364        $.ajax({
1365            type: 'post',
1366            url: ajaxurl,
1367            dataType: 'json',
1368            data: $form.serialize(),
1369            beforeSend: function( ) {
1370                currnt.find('.houzez-loader-js').addClass('loader-show');
1371            },
1372            complete: function(){
1373                currnt.find('.houzez-loader-js').removeClass('loader-show');
1374            },
1375            success: function( response ) {
1376                if( response.success ) {
1377                    $messages.empty().append('<div class="alert alert-success" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ response.msg +'</div>');
1378                    
1379                    window.location.replace( response.redirect_to );
1380
1381                } else {
1382                    $messages.empty().append('<div class="alert alert-danger" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ response.msg +'</div>');
1383                }
1384
1385                currnt.find('.houzez-loader-js').removeClass('loader-show');
1386
1387                if(houzez_reCaptcha == 1) {
1388                    $form.find('.g-recaptcha-response').remove();
1389                    if( g_recaptha_version == 'v3' ) {
1390                        houzezReCaptchaLoad();
1391                    } else {
1392                        houzezReCaptchaReset();
1393                    }
1394                }
1395            },
1396            error: function(xhr, status, error) {
1397                console.log("Error Status: " + status);
1398                console.log("Error Thrown: " + error);
1399                console.log("Response Text: " + xhr.responseText);
1400            }
1401        })
1402
1403    } // end houzez_login
1404
1405    var houzez_register = function ( currnt ) {
1406
1407        var $form = currnt.parents('form');
1408        var $messages = $('#hz-register-messages');
1409
1410        $.ajax({
1411            type: 'post',
1412            url: ajaxurl,
1413            dataType: 'json',
1414            data: $form.serialize(),
1415            beforeSend: function( ) {
1416                currnt.find('.houzez-loader-js').addClass('loader-show');
1417            },
1418            complete: function(){
1419                currnt.find('.houzez-loader-js').removeClass('loader-show');
1420            },
1421            success: function( response ) {
1422                if( response.success ) {
1423                    $messages.empty().append('<div class="alert alert-success" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ response.msg +'</div>');
1424                    
1425                    setTimeout(function() {
1426                        $('a[href="#login-form-tab"]').tab('show');
1427                    }, 2000);
1428
1429                } else {
1430                    $messages.empty().append('<div class="alert alert-danger" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ response.msg +'</div>');
1431                }
1432
1433                currnt.find('.houzez-loader-js').removeClass('loader-show');
1434                if(houzez_reCaptcha == 1) {
1435                    $form.find('.g-recaptcha-response').remove();
1436                    if( g_recaptha_version == 'v3' ) {
1437                        houzezReCaptchaLoad();
1438                    } else {
1439                        houzezReCaptchaReset();
1440                    }
1441                }
1442            },
1443            error: function(xhr, status, error) {
1444                console.log("Error Status: " + status);
1445                console.log("Error Thrown: " + error);
1446                console.log("Response Text: " + xhr.responseText);
1447            }
1448        });
1449    }
1450
1451    var houzez_social_create_account = function ( currnt ) {
1452
1453        var $form = currnt.parents('form');
1454        var $messages = $('#hz-create-messages');
1455
1456        $.ajax({
1457            type: 'post',
1458            url: ajaxurl,
1459            dataType: 'json',
1460            data: $form.serialize(),
1461            beforeSend: function( ) {
1462                currnt.find('.houzez-loader-js').addClass('loader-show');
1463            },
1464            complete: function(){
1465                currnt.find('.houzez-loader-js').removeClass('loader-show');
1466            },
1467            success: function( response ) {
1468                if( response.success ) {
1469                    $messages.empty().append('<div class="alert alert-success" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ response.msg +'</div>');
1470                    
1471                    window.location.replace( response.redirect_to );
1472
1473                } else {
1474                    $messages.empty().append('<div class="alert alert-danger" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ response.msg +'</div>');
1475                }
1476
1477                currnt.find('.houzez-loader-js').removeClass('loader-show');
1478            
1479            },
1480            error: function(xhr, status, error) {
1481                var err = eval("(" + xhr.responseText + ")");
1482                console.log(err.Message);
1483            }
1484        });
1485    }
1486
1487    $('#houzez-link-account').on('click', function(e){
1488        e.preventDefault();
1489        var currnt = $(this);
1490        houzez_link_account( currnt );
1491    });
1492
1493    var houzez_link_account = function ( currnt ) {
1494
1495        var $form = currnt.parents('form');
1496        var $messages = $('#hz-link-messages');
1497
1498        $.ajax({
1499            type: 'post',
1500            url: ajaxurl,
1501            dataType: 'json',
1502            data: $form.serialize(),
1503            beforeSend: function( ) {
1504                currnt.find('.houzez-loader-js').addClass('loader-show');
1505            },
1506            complete: function(){
1507                currnt.find('.houzez-loader-js').removeClass('loader-show');
1508            },
1509            success: function( response ) {
1510                if( response.success ) {
1511                    $messages.empty().append('<div class="alert alert-success" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ response.msg +'</div>');
1512                    
1513                    window.location.replace( response.redirect_to );
1514
1515                } else {
1516                    $messages.empty().append('<div class="alert alert-danger" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ response.msg +'</div>');
1517                }
1518
1519                currnt.find('.houzez-loader-js').removeClass('loader-show');
1520                if(houzez_reCaptcha == 1) {
1521                    $form.find('.g-recaptcha-response').remove();
1522                    if( g_recaptha_version == 'v3' ) {
1523                        houzezReCaptchaLoad();
1524                    } else {
1525                        houzezReCaptchaReset();
1526                    }
1527                }
1528            },
1529            error: function(xhr, status, error) {
1530                var err = eval("(" + xhr.responseText + ")");
1531                console.log(err.Message);
1532            }
1533        });
1534    }
1535
1536    function houzez_social_login_panel() {
1537        var $mainStepWrap = $('.main-step-wrap');
1538        var $newAccountWrap = $('.new-account-wrap');
1539        var $linkAccountWrap = $('.link-account-wrap');
1540
1541        function toggleVisibility(hide1, hide2, show) {
1542            hide1.hide();
1543            hide2.hide();
1544            show.show();
1545        }
1546
1547        $(document).on('click', '.btn-link-account', function(event) {
1548            event.preventDefault();
1549            toggleVisibility($mainStepWrap, $newAccountWrap, $linkAccountWrap);
1550        });
1551
1552        $(document).on('click', '.btn-create-account', function(event) {
1553            event.preventDefault();
1554            toggleVisibility($mainStepWrap, $linkAccountWrap, $newAccountWrap);
1555        });
1556
1557        $(document).on('click', '.hz-fb-cancel', function(event) {
1558            event.preventDefault();
1559            toggleVisibility($linkAccountWrap, $newAccountWrap, $mainStepWrap);
1560        });
1561    }
1562
1563    houzez_social_login_panel();
1564
1565    $( '#houzez_forgetpass').on('click', function(){
1566        var user_login = $('#user_login_forgot').val(),
1567            security    = $('#fave_resetpassword_security').val();
1568
1569        var $this = $(this);
1570        var $messages = $('#reset_pass_msg');
1571
1572        $.ajax({
1573            type: 'post',
1574            url: ajaxurl,
1575            dataType: 'json',
1576            data: {
1577                'action': 'houzez_reset_password',
1578                'user_login': user_login,
1579                'security': security
1580            },
1581            beforeSend: function( ) {
1582                $this.find('.houzez-loader-js').addClass('loader-show');
1583            },
1584            complete: function(){
1585                $this.find('.houzez-loader-js').removeClass('loader-show');
1586            },
1587            success: function( response ) {
1588                if( response.success ) {
1589                    $messages.empty().append('<div class="alert alert-success" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ response.msg +'</div>');
1590                } else {
1591                    $messages.empty().append('<div class="alert alert-danger" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ response.msg +'</div>');
1592                }
1593            },
1594            error: function(xhr, status, error) {
1595                var err = eval("(" + xhr.responseText + ")");
1596                console.log(err.Message);
1597            }
1598        });
1599
1600    });
1601
1602
1603    if( $('#houzez_reset_password').length > 0 ) {
1604        $('#houzez_reset_password').click( function(e) {
1605            e.preventDefault();
1606
1607            var $this = $(this);
1608            var rg_login = $('input[name="rp_login"]').val();
1609            var rp_key = $('input[name="rp_key"]').val();
1610            var pass1 = $('input[name="pass1"]').val();
1611            var pass2 = $('input[name="pass2"]').val();
1612            var security = $('input[name="fave_resetpassword_security"]').val();
1613            var $messages = $('#reset_pass_msg_2');
1614
1615            $.ajax({
1616                type: 'post',
1617                url: ajaxurl,
1618                dataType: 'json',
1619                data: {
1620                    'action': 'houzez_reset_password_2',
1621                    'rq_login': rg_login,
1622                    'password': pass1,
1623                    'confirm_pass': pass2,
1624                    'rp_key': rp_key,
1625                    'security': security
1626                },
1627                beforeSend: function( ) {
1628                    $this.find('.houzez-loader-js').addClass('loader-show');
1629                },
1630                complete: function(){
1631                    $this.find('.houzez-loader-js').removeClass('loader-show');
1632                },
1633                success: function(response) {
1634                    if( response.success ) {
1635                        $messages.empty().append('<div class="alert alert-success" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ response.msg +'</div>');
1636                        jQuery('#oldpass, #newpass, #confirmpass').val('');
1637                    } else {
1638                        $messages.empty().append('<div class="alert alert-danger" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ response.msg +'</div>');
1639                    }
1640                },
1641                error: function(errorThrown) {
1642
1643                }
1644
1645            });
1646
1647        } );
1648    }
1649
1650
1651    $('.hz-facebook-login').on('click', function () {
1652        var current = $(this);
1653        houzez_login_via_facebook( current );
1654    });
1655
1656    var houzez_login_via_facebook = function ( current ) {
1657        var $messages = $('.hz-social-messages');
1658
1659        $.ajax({
1660            type: 'POST',
1661            url: ajaxurl,
1662            dataType: 'json',
1663            data: {
1664                'action' : 'houzez_facebook_login_oauth'
1665            },
1666            beforeSend: function( ) {
1667                $messages.empty().append('<div class="alert alert-success" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ login_loading +'</div>');
1668                current.find('.houzez-loader-js').addClass('loader-show');
1669            },
1670            complete: function(){
1671                current.find('.houzez-loader-js').removeClass('loader-show');
1672            },
1673            success: function (response) { 
1674                if(response.success) {
1675                    window.location.replace( response.url );
1676                } else {
1677                    $messages.empty().append('<div class="alert alert-danger" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ response.message +'</div>');
1678                }
1679                
1680            },
1681            error: function(xhr, status, error) {
1682                var err = eval("(" + xhr.responseText + ")");
1683                console.log(err.Message);
1684            }
1685        });
1686    }
1687
1688    $('.hz-google-login').on('click', function () {
1689        var current = $(this);
1690        houzez_login_via_google( current );
1691    });
1692
1693    var houzez_login_via_google = function ( current ) {
1694        var $form = current.parents('form');
1695        var $messages = $('#hz-login-messages');
1696
1697        $.ajax({
1698            type: 'POST',
1699            url: ajaxurl,
1700            data: {
1701                'action' : 'houzez_google_login_oauth'
1702            },
1703            beforeSend: function( ) {
1704                $messages.empty().append('<div class="alert alert-success" role="alert"><i class="houzez-icon icon-check-circle-1 mr-1"></i>'+ login_loading +'</div>');
1705                current.find('.houzez-loader-js').addClass('loader-show');
1706            },
1707            complete: function(){
1708                current.find('.houzez-loader-js').removeClass('loader-show');
1709            },
1710            success: function (data) { 
1711                window.location.replace( data );
1712            },
1713            error: function(xhr, status, error) {
1714                var err = eval("(" + xhr.responseText + ")");
1715                console.log(err.Message);
1716            }
1717        });
1718    }
1719
1720
1721
1722    /*--------------------------------------------------------------------------
1723     *  Property Module Ajax Pagination with Load More and Infinite Scroll
1724     * -------------------------------------------------------------------------*/
1725    var properties_module_section = $('#properties_module_section');
1726    if (properties_module_section.length > 0) {
1727        var loading = false;
1728        var $loadMoreButton = $('.fave-load-more a');
1729        var paginationType = $loadMoreButton.data('pagination-type') || 'loadmore';
1730        var observer;
1731
1732        function loadMoreProperties(e) {
1733            if (e) e.preventDefault();
1734            if (loading) return;
1735
1736            var $this = $(this);
1737            var $wrap = $this.closest('#properties_module_section').find('#module_properties');
1738            var prop_limit = $this.data('prop-limit');
1739            var paged = $this.data('paged');
1740            var card_version = $this.data('card');
1741            var type = $this.data('type');
1742            var status = $this.data('status');
1743            var state = $this.data('state');
1744            var city = $this.data('city');
1745            var country = $this.data('country');
1746            var area = $this.data('area');
1747            var label = $this.data('label');
1748            var user_role = $this.data('user-role');
1749            var featured_prop = $this.data('featured-prop');
1750            var offset = $this.data('offset');
1751            var sortby = $this.data('sortby');
1752
1753            var property_ids = $this.data('property_ids');
1754            var min_price = $this.data('min_price');
1755            var max_price = $this.data('max_price');
1756            var min_beds = $this.data('min_beds');
1757            var max_beds = $this.data('max_beds');
1758            var min_baths = $this.data('min_baths');
1759            var max_baths = $this.data('max_baths');
1760            var agents = $this.data('agents');
1761            var agencies = $this.data('agencies');
1762            var post_status = $this.data('post_status');
1763
1764            loading = true;
1765            $.ajax({
1766                type: 'POST',
1767                url: ajaxurl,
1768                dataType: 'json',
1769                data: {
1770                    'action': 'houzez_loadmore_properties',
1771                    'prop_limit': prop_limit,
1772                    'paged': paged,
1773                    'card_version': card_version,
1774                    'type': type,
1775                    'status': status,
1776                    'state': state,
1777                    'city': city,
1778                    'country': country,
1779                    'area': area,
1780                    'label': label,
1781                    'property_ids': property_ids,
1782                    'min_price': min_price,
1783                    'max_price': max_price,
1784                    'min_beds': min_beds,
1785                    'max_beds': max_beds,
1786                    'min_baths': min_baths,
1787                    'max_baths': max_baths,
1788                    'user_role': user_role,
1789                    'agents': agents,
1790                    'agencies': agencies,
1791                    'featured_prop': featured_prop,
1792                    'sort_by': sortby,
1793                    'offset': offset,
1794                    'post_status': post_status
1795                },
1796                beforeSend: function() {
1797                    $this.find('.houzez-loader-js').addClass('loader-show');
1798                },
1799                complete: function() {
1800                    $this.find('.houzez-loader-js').removeClass('loader-show');
1801                    loading = false;
1802                },
1803                success: function(data) {
1804                    if (data.html == 'no_result') {
1805                        $this.closest('#properties_module_section').find('.fave-load-more').fadeOut('fast').remove();
1806                        return;
1807                    }
1808                    $wrap.append(data.html);
1809                    $this.data("paged", paged + 1);
1810                    $this.find('i').remove();
1811
1812                    if (!data.has_more_posts) {
1813                        $this.closest('#properties_module_section').find('.fave-load-more').fadeOut('fast').remove();
1814                    } else if (paginationType === 'infinite_scroll') {
1815                        // Re-observe the button after new content is loaded
1816                        observeLoadMoreButton();
1817                    }
1818
1819                    // Reinitialize necessary functions
1820                    houzez_init_add_favorite(ajaxurl, userID);
1821                    houzez_init_remove_favorite(ajaxurl, userID);
1822                    houzez_listing_lightbox(ajaxurl, processing_text, houzez_rtl, userID);
1823                    houzez_grid_image_gallery();
1824                    houzez_grid_call_to_action();
1825                    houzez_lazyload_for_ajax();
1826                    compare_for_ajax();
1827                    $('[data-toggle="tooltip"]').tooltip();
1828                },
1829                error: function(jqXHR, textStatus, errorThrown) {
1830                    console.error("AJAX error: " + textStatus + ' : ' + errorThrown);
1831                    loading = false;
1832                }
1833            });
1834        }
1835
1836        function observeLoadMoreButton() {
1837            if (observer) {
1838                observer.disconnect();
1839            }
1840
1841            observer = new IntersectionObserver((entries) => {
1842                entries.forEach(entry => {
1843                    if (entry.isIntersecting && !loading) {
1844                        loadMoreProperties.call($('.fave-load-more a')[0]);
1845                    }
1846                });
1847            }, {
1848                root: null,
1849                rootMargin: '0px',
1850                threshold: 0.1
1851            });
1852
1853            var loadMoreButton = document.querySelector('.fave-load-more a');
1854            if (loadMoreButton) {
1855                observer.observe(loadMoreButton);
1856            }
1857        }
1858
1859        // Load More button click event
1860        $("body").on('click', '.fave-load-more a', loadMoreProperties);
1861
1862        // Initialize Infinite Scroll if that's the pagination type
1863        if (paginationType === 'infinite_scroll') {
1864            observeLoadMoreButton();
1865        }
1866    }
1867
1868    /*--------------------------------------------------------------------------
1869     *  Property Infinite load
1870     * -------------------------------------------------------------------------*/
1871    jQuery(document).ready(function($) {
1872        const $listingView = $('.listing-view');
1873        const $loadMoreBtn = $('.houzez-infinite-load');
1874        const $paginationContainer = $('#fave-pagination-loadmore');
1875        let loading = false;
1876        let currentPage = 1;
1877        let noMoreListings = false;
1878        let totalListings = parseInt($loadMoreBtn.data('total'), 10) || 0;  // Get total listings count
1879        let perPage = parseInt($loadMoreBtn.data('per-page'), 10) || 10;    // Get per page count
1880        let pagi_type = $loadMoreBtn.data('pagi-type') || '_number';    // Get per page count
1881
1882        function loadMoreListings() {
1883            if (loading || noMoreListings) return;
1884            loading = true;
1885            const nextPageUrl = $loadMoreBtn.attr('href');
1886            $.ajax({
1887                url: nextPageUrl,
1888                type: 'GET',
1889                dataType: 'html',
1890                beforeSend: function() {
1891                    $loadMoreBtn.find('.houzez-loader-js').addClass('loader-show');
1892                },
1893                complete: function(){
1894                    $loadMoreBtn.find('.houzez-loader-js').removeClass('loader-show');
1895                },
1896                success: function(response) {
1897                    const $html = $(response);
1898                    const $newListings = $html.find('.listing-view .item-listing-wrap');
1899                    
1900                    if ($newListings.length > 0) {
1901                        $listingView.append($newListings);
1902                        currentPage++;
1903                        
1904                        const nextPageLink = $html.find('.houzez-infinite-load').attr('href');
1905
1906                        if (nextPageLink && (currentPage * perPage < totalListings)) {
1907                            $loadMoreBtn.attr('href', nextPageLink);
1908                            $loadMoreBtn.attr('data-page', currentPage + 1);
1909                            updateBrowserUrl(nextPageUrl);
1910                            $loadMoreBtn.show();  // Ensure button is visible
1911                        } else {
1912                            noMoreListings = true;
1913                            showEndMessage();
1914                            $loadMoreBtn.hide();  // Hide button when no more listings
1915                        }
1916
1917                        // Reinitialize necessary functions
1918                        houzez_init_add_favorite(ajaxurl, userID);
1919                        houzez_init_remove_favorite(ajaxurl, userID);
1920                        houzez_listing_lightbox(ajaxurl, processing_text, houzez_rtl, userID);
1921                        houzez_grid_image_gallery();
1922                        houzez_grid_call_to_action();
1923                        houzez_lazyload_for_ajax();
1924                        compare_for_ajax();
1925                        houzez_parallax_listings();
1926                        $('[data-toggle="tooltip"]').tooltip();
1927                    } else {
1928                        noMoreListings = true;
1929                        showEndMessage();
1930                        $loadMoreBtn.hide();  // Hide button when no more listings
1931                    }
1932                    
1933                    loading = false;
1934                },
1935                error: function(xhr, status, error) {
1936                    console.error('Error loading more listings:', error);
1937                    loading = false;
1938                }
1939            });
1940        }
1941
1942        function updateBrowserUrl(url) {
1943            if (history.pushState) {
1944                const newUrl = new URL(url);
1945                window.history.pushState({ path: newUrl.href }, '', newUrl.href);
1946            }
1947        }
1948
1949        function showEndMessage() {
1950            $paginationContainer.html('<p class="no-more-listings">'+listings_not_found+'</p>');
1951        }
1952
1953        // Check if we need to show the Load More button initially
1954        if (totalListings <= perPage) {
1955            $loadMoreBtn.hide();
1956        }
1957
1958        // Intersection Observer setup
1959        if (pagi_type == '_infinite' && $('#houzez-infinite-load').length > 0) {
1960            const options = {
1961                root: null,
1962                rootMargin: '0px',
1963                threshold: 0.1
1964            };
1965
1966            const observer = new IntersectionObserver((entries) => {
1967                entries.forEach(entry => {
1968                    if (entry.isIntersecting && !loading && !noMoreListings) {
1969                        loadMoreListings();
1970                    }
1971                });
1972            }, options);
1973
1974            // Start observing the load more button
1975            observer.observe($loadMoreBtn[0]);
1976        }
1977
1978        // Keep the click event for browsers that don't support IntersectionObserver
1979        $loadMoreBtn.on('click', function(e) {
1980            e.preventDefault();
1981            if (!loading && !noMoreListings) {
1982                loadMoreListings();
1983            }
1984        });
1985
1986        // Handle browser back/forward buttons
1987        $(window).on('popstate', function(e) {
1988            if (e.originalEvent.state !== null) {
1989                window.location.reload();
1990            }
1991        });
1992    });
1993    
1994    /*--------------------------------------------------------------------------
1995     *  Change search price on status change
1996     * -------------------------------------------------------------------------*/
1997    var property_status_changed = function(prop_status, $form) { 
1998        
1999        if( prop_status == for_rent ) { 
2000            $form.find('.prices-for-all').addClass('hide');
2001            $form.find('.prices-for-all select').attr('disabled','disabled');
2002            $form.find('.prices-only-for-rent').removeClass('hide');
2003            $form.find('.prices-only-for-rent select').removeAttr('disabled','disabled');
2004            $form.find('.prices-only-for-rent select').selectpicker('refresh');
2005        } else {  
2006            $form.find('.prices-only-for-rent').addClass('hide');
2007            $form.find('.prices-only-for-rent select').attr('disabled','disabled');
2008            $form.find('.prices-for-all').removeClass('hide');
2009            $form.find('.prices-for-all select').removeAttr('disabled','disabled');
2010            $form.find('.prices-for-all select').selectpicker('refresh');
2011        }
2012    }
2013    $('.status-js').on('change', function(e) { 
2014        var selected_status = $(this).val();
2015        var $form = $(this).parents('form');
2016        property_status_changed(selected_status, $form);
2017    });
2018
2019    $('.status-tab-js').on('click', function() {
2020        var tab_selected_status = $(this).data('val');
2021        var $form = $(this).parents('form');
2022        property_status_changed(tab_selected_status, $form);
2023    });
2024
2025
2026
2027    /* On page load*/
2028    var selected_status = $('.status-js').val();
2029    if( selected_status == for_rent ) {
2030        var $form = $('.houzez-search-form-js');
2031        property_status_changed(selected_status, $form);
2032    } else {
2033        var $form = $('.houzez-search-form-js');
2034        property_status_changed('dummy', $form);
2035    }
2036
2037    /* On page load status tab */
2038    var selected_status_tab = $('.status-tab-js').val();
2039    if( selected_status_tab == for_rent ) {
2040        var $tab_form = $('.houzez-search-builder-form-js'); 
2041        property_status_changed(selected_status_tab, $tab_form);
2042    } else {
2043        var $tab_form = $('.houzez-search-builder-form-js');
2044        property_status_changed( selected_status_tab, $tab_form );
2045    }
2046
2047    /* ------------------------------------------------------------------------ */
2048    /*  Price Range Slider
2049     /* ------------------------------------------------------------------------ */
2050    var price_range_search = function( min_price, max_price ) {
2051        $(".price-range").slider({
2052            range: true,
2053            min: min_price,
2054            max: max_price,
2055            values: [min_price, max_price],
2056            slide: function (event, ui) {
2057                if( currency_position == 'after' ) {
2058                    var min_price_range = thousandSeparator(ui.values[0]) + currency_symb;
2059                    var max_price_range = thousandSeparator(ui.values[1]) + currency_symb;
2060                } else {
2061                    var min_price_range = currency_symb + thousandSeparator(ui.values[0]);
2062                    var max_price_range = currency_symb + thousandSeparator(ui.values[1]);
2063                }
2064                $(".min-price-range-hidden").val( ui.values[0] );
2065                $(".max-price-range-hidden").val( ui.values[1] );
2066
2067                $(".min-price-range").text( min_price_range );
2068                $(".max-price-range").text( max_price_range );
2069            },
2070            stop: function( event, ui ) {
2071                
2072            },
2073            change: function( event, ui ) {  }
2074        });
2075
2076        if( currency_position == 'after' ) {
2077            var min_price_range = thousandSeparator($(".price-range").slider("values", 0)) + currency_symb;
2078            var max_price_range = thousandSeparator($(".price-range").slider("values", 1)) + currency_symb;
2079        } else {
2080            var min_price_range = currency_symb + thousandSeparator($(".price-range").slider("values", 0));
2081            var max_price_range = currency_symb + thousandSeparator($(".price-range").slider("values", 1));
2082        }
2083
2084        $(".min-price-range").text(min_price_range);
2085        $(".max-price-range").text(max_price_range);
2086        $(".min-price-range-hidden").val($(".price-range").slider("values", 0));
2087        $(".max-price-range-hidden").val($(".price-range").slider("values", 1));
2088        
2089    }
2090
2091    if($( ".price-range").length > 0 && is_halfmap != 1) {
2092        var selected_status_adv_search = $('.status-js').val();
2093        if( selected_status_adv_search == for_rent_price_slider ){
2094            price_range_search(search_price_range_min_rent, search_price_range_max_rent);
2095        } else {
2096            price_range_search( search_price_range_min, search_price_range_max );
2097        }
2098
2099        $('.status-js').on('change', function(){
2100            var search_status = $(this).val();
2101            if( search_status == for_rent_price_slider ) {
2102                price_range_search(search_price_range_min_rent, search_price_range_max_rent);
2103            } else { 
2104                price_range_search( search_price_range_min, search_price_range_max );
2105            }
2106        });
2107
2108        $('.status-tab-js').on('click', function() {
2109            var tab_status = $(this).data('val');
2110            if( tab_status == for_rent_price_slider ) {
2111                price_range_search(search_price_range_min_rent, search_price_range_max_rent);
2112            } else { 
2113                price_range_search( search_price_range_min, search_price_range_max );
2114            }
2115        });
2116    }
2117
2118    /*-----------------------------------------------------------------------------------*/
2119    /* Search Status tabs
2120    /*-----------------------------------------------------------------------------------*/
2121    $('.houzez-status-tabs li a').on('click', function(e) {
2122        e.preventDefault();
2123        var $this = $(this);
2124        var status = $this.data('val');
2125
2126        $('#search-tabs').val(status);
2127
2128        var $form = $('.houzez-search-form-js');
2129        property_status_changed(status, $form);
2130
2131    });
2132
2133
2134    /*-----------------------------------------------------------------------------------*/
2135    /* PROPERTIES SORTING
2136    /*-----------------------------------------------------------------------------------*/
2137    function insertParam(key, value) {
2138        key = encodeURI(key);
2139        value = encodeURI(value);
2140
2141        // get querystring , remove (?) and covernt into array
2142        var qrp = document.location.search.substr(1).split('&');
2143
2144        // get qrp array length
2145        var i = qrp.length;
2146        var j;
2147        while (i--) {
2148            //covert query strings into array for check key and value
2149            j = qrp[i].split('=');
2150
2151            // if find key and value then join
2152            if (j[0] == key) {
2153                j[1] = value;
2154                qrp[i] = j.join('=');
2155                break;
2156            }
2157        }
2158
2159        if (i < 0) {
2160            qrp[qrp.length] = [key, value].join('=');
2161        }
2162        // reload the page
2163        document.location.search = qrp.join('&');
2164
2165    }
2166
2167    $('#sort_properties').on('change', function() {
2168        var key = 'sortby';
2169        var value = $(this).val();
2170        insertParam( key, value );
2171    });
2172
2173    $('#insights_filter').on('change', function() {
2174        var key = 'listing_id';
2175        var value = $(this).val();
2176        insertParam( key, value );
2177    });
2178
2179    $('#houzez-gmap-full').on('click', function() {
2180        var $this = $(this);
2181        if($this.hasClass('active')) {
2182            $this.removeClass('active');
2183            $this.parents('.map-wrap').removeClass('houzez-fullscreen-map');
2184        } else {
2185            $this.parents('.map-wrap').addClass('houzez-fullscreen-map');
2186            $this.addClass('active');
2187        }
2188        
2189    });
2190
2191    /*--------------------------------------------------------------------------
2192     *  Property Agent Contact Form
2193     * -------------------------------------------------------------------------*/
2194    $( '.houzez_agent_property_form').on('click', function(e) {
2195        e.preventDefault();
2196
2197        var $result;
2198        var $this = $(this);
2199        var $form = $this.parents( 'form' );
2200        var $form_wrap = $this.parents( '.property-form-wrap' );
2201        $result = $form_wrap.find('.form_messages');
2202        var $is_bottom = $('.is_bottom').val();
2203        if($is_bottom == 'bottom') {
2204            $result = $form.find('.form_messages');
2205        }
2206        $result.empty();
2207
2208        $.ajax({
2209            url: ajaxurl,
2210            data: $form.serialize(),
2211            method: $form.attr('method'),
2212            dataType: "JSON",
2213
2214            beforeSend: function( ) {
2215                $this.find('.houzez-loader-js').addClass('loader-show');
2216            },
2217            success: function(response) {
2218                if( response.success ) {
2219                    
2220                    $form.find('input[name="name"], input[name="mobile"], input[name="email"]').val('');
2221                    $form.find('textarea').val('');
2222                    if($is_bottom == 'bottom') {
2223                        $result.empty().append('<div class="alert alert-success alert-dismissible fade show" role="alert">'+response.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
2224                    } else {
2225                        $result.empty().append('<p class="success text-success"><i class="fa fa-check"></i> '+ response.msg +'</p>');
2226                    }
2227                } else {
2228                    if($is_bottom == 'bottom') {
2229                        $result.empty().append('<div class="alert alert-danger alert-dismissible fade show" role="alert">'+response.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
2230                    } else {
2231                        $result.empty().append('<p class="error text-danger"><i class="fas fa-times"></i> '+ response.msg +'</p>');
2232                    }
2233                }
2234
2235                $this.find('.houzez-loader-js').removeClass('loader-show');
2236                
2237                if(houzez_reCaptcha == 1) {
2238                    $form.find('.g-recaptcha-response').remove();
2239                    if( g_recaptha_version == 'v3' ) {
2240                        houzezReCaptchaLoad();
2241                    } else {
2242                        houzezReCaptchaReset();
2243                    }
2244                }
2245                
2246                if( houzez_vars.agent_redirection != '' && response.success ) {
2247                    setTimeout(function(){
2248                        window.location.replace(houzez_vars.agent_redirection);
2249                    }, 500);
2250                }
2251
2252            },
2253            error: function(xhr, status, error) {
2254                var err = eval("(" + xhr.responseText + ")");
2255                console.log(err.Message);
2256            },
2257            complete: function(){
2258                $this.find('.houzez-loader-js').removeClass('loader-show');
2259            }
2260        });
2261    });
2262
2263    /*--------------------------------------------------------------------------
2264     *  Direct message
2265     * -------------------------------------------------------------------------*/
2266    $('.msg-login-required').on('click', function() {
2267        $('.modal-toggle-1').addClass("active");
2268        jQuery('.login-form-tab').addClass('active show');
2269    });
2270
2271    $( '.houzez-send-message').on('click', function(e) {
2272        e.preventDefault();
2273
2274        var $result;
2275        var $this = $(this);
2276        var $form = $this.parents( 'form' );
2277        var $form_wrap = $this.parents( '.property-form-wrap' );
2278        $result = $form_wrap.find('.form_messages');
2279        var $is_bottom = $('.is_bottom').val();
2280        if($is_bottom == 'bottom') {
2281            $result = $form.find('.form_messages');
2282        }
2283        $result.empty();
2284
2285        var property_id = $('input[name="listing_id"]').val();
2286        var message = $form.find('.hz-form-message').val();
2287        var security = $('input[name="property_agent_contact_security"]').val();
2288
2289        $.ajax({
2290            url: ajaxurl,
2291            data: {
2292                'action' : 'houzez_start_thread',
2293                'property_id' : property_id,
2294                'message' : message,
2295                'start_thread_form_ajax' : security,
2296            },
2297            method: $form.attr('method'),
2298            dataType: "JSON",
2299
2300            beforeSend: function( ) {
2301                $this.find('.houzez-loader-js').addClass('loader-show');
2302            },
2303            success: function(response) {
2304                if( response.success ) {
2305                    
2306                    $form.find('input[name="name"], input[name="mobile"], input[name="email"]').val('');
2307                    $form.find('textarea').val('');
2308                    if($is_bottom == 'bottom') {
2309                        $result.empty().append('<div class="alert alert-success alert-dismissible fade show" role="alert">'+response.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
2310                    } else {
2311                        $result.empty().append('<p class="success text-success"><i class="fa fa-check"></i> '+ response.msg +'</p>');
2312                    }
2313                } else {
2314                    if($is_bottom == 'bottom') {
2315                        $result.empty().append('<div class="alert alert-danger alert-dismissible fade show" role="alert">'+response.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
2316                    } else {
2317                        $result.empty().append('<p class="error text-danger"><i class="fas fa-times"></i> '+ response.msg +'</p>');
2318                    }
2319                }
2320
2321                $this.find('.houzez-loader-js').removeClass('loader-show');
2322                
2323                if(houzez_reCaptcha == 1) {
2324                    $form.find('.g-recaptcha-response').remove();
2325                    if( g_recaptha_version == 'v3' ) {
2326                        houzezReCaptchaLoad();
2327                    } else {
2328                        houzezReCaptchaReset();
2329                    }
2330                }
2331                
2332                if( houzez_vars.agent_redirection != '' ) {
2333                    setTimeout(function(){
2334                        window.location.replace(houzez_vars.agent_redirection);
2335                    }, 500);
2336                }
2337
2338            },
2339            error: function(xhr, status, error) {
2340                var err = eval("(" + xhr.responseText + ")");
2341                console.log(err.Message);
2342            },
2343            complete: function(){
2344                $this.find('.houzez-loader-js').removeClass('loader-show');
2345            }
2346        });
2347    });
2348
2349
2350    /*
2351     * Property Thread Message Form
2352     * -----------------------------*/
2353    $( '.start_thread_message_form').on('click', function(e) {
2354
2355        e.preventDefault();
2356
2357        var $this = $(this);
2358        var $form = $this.parents( 'form' );
2359        var $result = $form.find('.form_messages');
2360
2361        $.ajax({
2362            url: ajaxurl,
2363            data: $form.serialize(),
2364            method: $form.attr('method'),
2365            dataType: "JSON",
2366
2367            beforeSend: function( ) {
2368                $this.find('.houzez-loader-js').addClass('loader-show');
2369            },
2370            success: function( response ) {
2371                $this.find('.houzez-loader-js').removeClass('loader-show');
2372                window.location.replace( response.url );
2373            },
2374            complete: function(){
2375                $this.find('.houzez-loader-js').removeClass('loader-show');
2376            }
2377        });
2378
2379    });
2380
2381    /*--------------------------------------------------------------------------
2382     *   Contact agent form on agent detail page
2383     * -------------------------------------------------------------------------*/
2384    $('#contact_realtor_btn').on('click', function(e) {
2385        e.preventDefault();
2386        var current_element = $(this);
2387        var $this = $(this);
2388        var $form = $this.parents( 'form' );
2389
2390        jQuery.ajax({
2391            type: 'post',
2392            url: ajaxurl,
2393            data: $form.serialize(),
2394            method: $form.attr('method'),
2395            dataType: "JSON",
2396
2397            beforeSend: function( ) {
2398                $this.find('.houzez-loader-js').addClass('loader-show');
2399            },
2400            success: function( res ) {
2401                if( res.success ) {
2402                    $('.form_messages').empty().append('<div class="alert alert-success alert-dismissible fade show" role="alert">'+res.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
2403                } else {
2404                    $('.form_messages').empty().append('<div class="alert alert-danger alert-dismissible fade show" role="alert">'+res.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
2405                }
2406
2407                $this.find('.houzez-loader-js').removeClass('loader-show');
2408                if(houzez_reCaptcha == 1) {
2409                    $form.find('.g-recaptcha-response').remove();
2410                    if( g_recaptha_version == 'v3' ) {
2411                        houzezReCaptchaLoad();
2412                    } else {
2413                        houzezReCaptchaReset();
2414                    }
2415                }
2416            },
2417            error: function(xhr, status, error) {
2418                var err = eval("(" + xhr.responseText + ")");
2419                console.log(err.Message);
2420            },
2421            complete: function(){
2422                $this.find('.houzez-loader-js').removeClass('loader-show');
2423            }
2424
2425        });
2426    });
2427
2428    /*--------------------------------------------------------------------------
2429     *  AutoComplete Search
2430     * -------------------------------------------------------------------------*/
2431    if( keyword_autocomplete != 0 ) {
2432        var houzezAutoComplete = function () {
2433
2434            var ajaxCount = 0;
2435            var auto_complete_container = $('.auto-complete');
2436            var lastLenght = 0;
2437
2438            $( 'body' ).on('keyup', '.houzez-keyword-autocomplete', HouzezDebounce(function() {
2439
2440                var $this = $( this );
2441                var $dataType = $this.data('type');
2442                var $form = $this.parents( 'form');
2443                
2444                if( $dataType == 'banner' ) {
2445                    var auto_complete_container = $( '#houzez-auto-complete-banner' );
2446                } else {
2447                    var auto_complete_container = $form.find( '.auto-complete' );
2448                }
2449
2450                var keyword = $( this ).val();
2451                
2452                keyword = $.trim( keyword );
2453                var currentLenght = keyword.length;
2454
2455                if ( currentLenght >= 2 && currentLenght != lastLenght ) {
2456
2457                    lastLenght = currentLenght;
2458                    auto_complete_container.fadeIn();
2459
2460                    $.ajax({
2461                        type: 'POST',
2462                        url: ajaxurl,
2463                        data: {
2464                            'action': 'houzez_get_auto_complete_search',
2465                            'key': keyword,
2466                        },
2467                        beforeSend: function( ) {
2468                            ajaxCount++;
2469                            if ( ajaxCount == 1 ) {
2470                                auto_complete_container.html('<ul class="list-group"><li class="list-group-item"><i class="fa fa-spinner fa-spin fa-fw"></i> '+autosearch_text+ '</li></ul>');
2471                            }
2472                        },
2473                        success: function(data) {
2474                            ajaxCount--;
2475                            if ( ajaxCount == 0 ) {
2476                                auto_complete_container.show();
2477                                if( data != '' ) {
2478                                    auto_complete_container.empty().html(data).bind();
2479                                }
2480                            }
2481                        },
2482                        error: function(errorThrown) {
2483                            ajaxCount--;
2484                            if ( ajaxCount == 0 ) {
2485                                auto_complete_container.html('<ul class="list-group"><li class="list-group-item"><i class="fa fa-spinner fa-spin fa-fw"></i> '+autosearch_text+ '</li></ul>');
2486                            }
2487                        }
2488                    });
2489
2490                } else {
2491                    if ( currentLenght != lastLenght ) {
2492                        auto_complete_container.fadeOut();
2493                    }
2494                }
2495
2496            }, 400)); // 500 milliseconds as the delay
2497            auto_complete_container.on( 'click', 'li', function (){
2498                $('.houzez-keyword-autocomplete').val( $( this ).data( 'text' ) );
2499                auto_complete_container.fadeOut();
2500            }).bind();
2501        }
2502        houzezAutoComplete();
2503    }
2504
2505    /*--------------------------------------------------------------------------
2506     *  Save Search
2507     * -------------------------------------------------------------------------*/
2508    $(".save_search_click").on('click', function(e) {
2509        e.preventDefault();
2510
2511        var $this = $(this);
2512
2513        var search_args = $('input[name="search_args"]').val();
2514        var security = $('input[name="houzez_save_search_ajax"]').val();
2515        var search_URI = $('input[name="search_URI"]').val();
2516
2517        if( parseInt( userID, 10 ) === 0 ) {
2518                houzez_login_modal();
2519        } else {
2520            $.ajax({
2521                url: ajaxurl,
2522                data: {
2523                    'action': 'houzez_save_search',
2524                    'search_args': search_args,
2525                    'search_URI': search_URI,
2526                    'houzez_save_search_ajax': security,
2527                },
2528                method: 'POST',
2529                dataType: 'JSON',
2530
2531                beforeSend: function () {
2532                    $this.find('.houzez-loader-js').addClass('loader-show');
2533                },
2534                success: function (response) {
2535                    if (response.success) {
2536                        $('.save_search_click').attr('disabled', true);
2537                    }
2538                },
2539                error: function (xhr, status, error) {
2540                    var err = eval("(" + xhr.responseText + ")");
2541                    console.log(err.Message);
2542                },
2543                complete: function () {
2544                    $this.find('.houzez-loader-js').removeClass('loader-show');
2545                }
2546            });
2547        }
2548
2549    });
2550
2551
2552    /*--------------------------------------------------------------------------
2553     *  Property Schedule Contact Form
2554     * -------------------------------------------------------------------------*/
2555    $( '.schedule_contact_form').on('click', function(e) {
2556        e.preventDefault();
2557
2558        var $this = $(this);
2559        var $form = $this.parents( 'form' );
2560        var $result = $form.find('.form_messages');
2561
2562        $.ajax({
2563            url: ajaxurl,
2564            data: $form.serialize(),
2565            method: $form.attr('method'),
2566            dataType: "JSON",
2567
2568            beforeSend: function( ) {
2569                $this.find('.houzez-loader-js').addClass('loader-show');
2570            },
2571            success: function(response) {
2572                if( response.success ) {
2573                    $form.find('input[name="name"], input[name="phone"], input[name="email"]').val('');
2574                    $form.find('textarea').val('');
2575                    $result.empty().append('<div class="alert alert-success alert-dismissible fade show" role="alert">'+response.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
2576
2577                    if( typeof response.redirect_to !=='undefined' && response.redirect_to != '' ) {
2578                        setTimeout(function(){
2579                            window.location.replace(response.redirect_to);
2580                        }, 500);
2581                    }
2582
2583                } else {
2584                    $result.empty().append('<div class="alert alert-danger alert-dismissible fade show" role="alert">'+response.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
2585                }
2586            },
2587            error: function(xhr, status, error) {
2588                var err = eval("(" + xhr.responseText + ")");
2589                console.log(err.Message);
2590            },
2591            complete: function(){
2592                $this.find('.houzez-loader-js').removeClass('loader-show');
2593            }
2594        });
2595
2596    });
2597
2598    /* ------------------------------------------------------------------------ */
2599    /*  autocomplete result position
2600    /* ------------------------------------------------------------------------ */
2601    function setAutoCompleteResultPosition() {
2602        var parallax_banner_inner_height = $('.top-banner-wrap').innerHeight();
2603        var banner_caption_inner_height = $('.banner-caption').innerHeight();
2604        var autocomplete_search_position = (parallax_banner_inner_height - (parallax_banner_inner_height - banner_caption_inner_height) / 2);
2605
2606        $('#houzez-auto-complete-banner').css('top', autocomplete_search_position);
2607    }
2608
2609    /* ------------------------------------------------------------------------ */
2610    /*  Elementor Mobile menu trigger
2611    /* ------------------------------------------------------------------------ */
2612
2613    $('.houzez-nav-menu-main-mobile-wrap .houzez-menu-toggle').click(function (e) {
2614        $('.houzez-nav-menu-main-mobile-wrap .navbar-nav, .houzez-nav-menu-main-mobile-wrap .houzez-menu-toggle').toggleClass('houzez-nav-menu-active');
2615    });
2616
2617
2618    $(window).on('load', function(){
2619        setAutoCompleteResultPosition();
2620    });
2621    
2622    $win.on('resize', function () {
2623        setAutoCompleteResultPosition();
2624    });
2625
2626    /*-----------------------------------------------------------------------------------*/
2627    /* Print Property
2628    /*-----------------------------------------------------------------------------------*/
2629    if( $('.houzez-print').length > 0 ) {
2630        $('.houzez-print').on('click', function (e) {
2631            e.preventDefault();
2632            var propID, printWindow;
2633
2634            propID = $(this).attr('data-propid');
2635
2636            printWindow = window.open('', 'Print Me', 'width=800 ,height=842');
2637            $.ajax({
2638                type: 'POST',
2639                url: ajaxurl,
2640                data: {
2641                    'action': 'houzez_create_print',
2642                    'propid': propID,
2643                },
2644                success: function (data) {
2645                    printWindow.document.write(data);
2646                    printWindow.document.close();
2647                    printWindow.focus();
2648                },
2649                error: function (xhr, status, error) {
2650                    var err = eval("(" + xhr.responseText + ")");
2651                    console.log(err.Message);
2652                }
2653
2654            });
2655        });
2656    }
2657
2658    /*-----------------------------------------------------------------------------------*/
2659    /* Reviews like dislike 
2660    /*-----------------------------------------------------------------------------------*/
2661    var review_likes = function() {
2662        $('.hz-like-dislike-js').on('click', function(e) {
2663            e.preventDefault();
2664            var $this = jQuery(this);
2665            var $parent = $this.parents('.likes-container-js');
2666
2667            if($this.hasClass('already-voted')){
2668                $parent.find( '.vote-msg' ).text($this.data('msg')).show();
2669                var hideMessage = function(){
2670                    $parent.find( '.vote-msg' ).hide();
2671                };
2672                setTimeout(hideMessage, 3000);
2673            
2674            } else {
2675
2676                var review_id = $this.data('id');
2677                var type = $this.data('type');
2678
2679                $.ajax({
2680                    type: 'post',
2681                    url: ajaxurl,
2682                    dataType: "JSON",
2683                    data: {
2684                        'action': 'reviews_likes_dislikes',
2685                        'type': type,
2686                        'review_id': review_id,
2687                    },
2688                    beforeSend: function( ) {
2689                        $parent.find('.vote-msg').empty();
2690                        $parent.find('.houzez-loader-js').addClass('loader-show');
2691
2692                        if(type == 'likes') {
2693                            $('.review-dislike-button a').removeClass('already-voted');
2694                        } else if(type == 'dislikes') {
2695                            $('.review-like-button a').removeClass('already-voted');
2696                        }
2697                    },
2698                    success: function(res) {
2699                        if(res.success) {
2700                            $parent.find('.likes-count').text(res.likes);
2701                            $parent.find('.dislikes-count').text(res.dislikes);
2702                            $parent.find('.vote-msg').text(res.msg).show();
2703                        } else {
2704                            $parent.find('.vote-msg').text(res.msg).show();
2705                        }
2706
2707                        var hideMessage = function(){
2708                            $parent.find( '.vote-msg' ).hide();
2709                        };
2710                        setTimeout(hideMessage, 3000);
2711                        $this.addClass('already-voted');
2712                    },
2713                    error: function(xhr, status, error) {
2714                        var err = eval("(" + xhr.responseText + ")");
2715                        console.log(err.Message);
2716                    },
2717                    complete: function(){
2718                        $parent.find('.houzez-loader-js').removeClass('loader-show');
2719                    }
2720
2721                });
2722            }
2723
2724        });
2725    }
2726    review_likes();
2727    
2728
2729    /*-----------------------------------------------------------------------------------*/
2730    /* Reviews 
2731    /*-----------------------------------------------------------------------------------*/
2732    $('#submit-review').on('click', function(e) {
2733        e.preventDefault();
2734
2735        var $this = $(this);
2736        var $form = $this.parents( 'form' );
2737        var $result = $form.find('.form_messages');
2738
2739        $.ajax({
2740            url: ajaxurl,
2741            data: $form.serialize(),
2742            method: $form.attr('method'),
2743            dataType: "JSON",
2744
2745            beforeSend: function( ) {
2746                $this.find('.houzez-loader-js').addClass('loader-show');
2747            },
2748            success: function(response) {
2749                if( response.success ) {
2750                    $result.empty().append('<div class="alert alert-success alert-dismissible fade show" role="alert">'+response.msg+'<button type="button" class="close" data-dismiss="alert" aria-label=
2750"Close"><span aria-hidden="true">&times;</span></button></div>');
2751                    window.location.replace( response.review_link );
2752                } else {
2753                    $result.empty().append('<div class="alert alert-danger alert-dismissible fade show" role="alert">'+response.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
2754                }
2755            },
2756            error: function(xhr, status, error) {
2757                var err = eval("(" + xhr.responseText + ")");
2758                console.log(err.Message);
2759            },
2760            complete: function() {
2761                $this.find('.houzez-loader-js').removeClass('loader-show');
2762            }
2763        });
2764    });
2765
2766    var listing_review_ajax = function(sortby, listing_id, paged) {
2767        var review_container = $('#houzez_reviews_container');
2768        var review_post_type = $('input[name="review_post_type"]').val();
2769        
2770        $.ajax({
2771            type: 'post',
2772            url: ajaxurl,
2773            data: {
2774                'action': 'houzez_ajax_review',
2775                'sortby': sortby,
2776                'listing_id': listing_id,
2777                'review_post_type': review_post_type,
2778                'paged': paged
2779            },
2780            beforeSend: function( ) {
2781                
2782                review_container.empty().append(''
2783                    +'<div id="houzez-map-loading">'
2784                    +'<div class="mapPlaceholder">'
2785                    +'<div class="loader-ripple spinner">'
2786                    +'<div class="bounce1"></div>'
2787                    +'<div class="bounce2"></div>'
2788                    +'<div class="bounce3"></div>'
2789                    +'</div>'
2790                    +'</div>'
2791                    +'</div>'
2792                );
2793
2794                $('html, body').animate({
2795                    scrollTop: $("#property-review-wrap").offset().top-50
2796                }, 'slow');
2797            },
2798            success: function(data) {
2799                review_container.empty();
2800                review_container.html(data);
2801                review_likes();
2802                
2803            },
2804            error: function(xhr, status, error) {
2805                var err = eval("(" + xhr.responseText + ")");
2806                console.log(err.Message);
2807            },
2808            complete: function(){
2809                
2810            }
2811
2812        });
2813    }
2814
2815    if($('#sort_review').length > 0) {
2816        $('#sort_review').on('change', function() {
2817            var sortby = $(this).val();
2818            var listing_id = $('input[name="listing_id"]').val();
2819            var paged = 1;
2820            $('#review_paged').val(paged);
2821            $('#review_prev').attr('disabled', true);
2822            $('#review_next').attr('disabled', false);
2823            listing_review_ajax(sortby, listing_id, paged);
2824            return;
2825        }); 
2826    }
2827
2828    if($('#review_next').length > 0) {
2829        $('#review_next').on('click', function(e) {
2830            e.preventDefault();
2831            $('#review_prev').removeAttr('disabled');
2832            var sortby = $('#sort_review').val();
2833            var total_pages = $('#total_pages').val();
2834            var listing_id = $('input[name="listing_id"]').val();
2835            var paged = $('#review_paged').val();
2836            paged = Number(paged)+1;
2837            $('#review_paged').val(paged);
2838
2839            if(paged == total_pages) {
2840                $(this).attr('disabled', true);
2841            }
2842            listing_review_ajax(sortby, listing_id, paged);
2843            return;
2844        }); 
2845    }
2846
2847    if($('#review_prev').length > 0) {
2848        $('#review_prev').on('click', function(e) {
2849            e.preventDefault();
2850            $('#review_next').removeAttr('disabled');
2851            var sortby = $('#sort_review').val();
2852            var listing_id = $('input[name="listing_id"]').val();
2853            var paged = $('#review_paged').val();
2854            paged = Number(paged)-1;
2855            $('#review_paged').val(paged);
2856            if(paged <= 1) {
2857                $(this).attr('disabled', true);
2858            }
2859            listing_review_ajax(sortby, listing_id, paged);
2860            return;
2861        }); 
2862    }
2863
2864    /* ------------------------------------------------------------------------ */
2865    /*  Houzez Select Filter
2866    /* ------------------------------------------------------------------------ */
2867    function houzezSelectFilter($this, $dataRef, $list_num = '', is_on_load = '') {
2868        var e = $this.data("target"),
2869            i = $this.find(":selected").data("ref");
2870
2871        if( is_on_load == 'yes' ) {
2872            e = $list_num;
2873            i = $dataRef;
2874        }
2875
2876        $("select." + e).val(""),
2877            null == i
2878                ? $("select." + e)
2879                      .find("option")
2880                      .each(function () {
2881                          console.log("inside undefined"), $(this).removeAttr("disabled hidden");
2882                      })
2883                : $("select." + e)
2884                      .find("option")
2885                      .each(function () {
2886                          var e = $(this).data("belong"),
2887                              t = $(this).val();
2888
2889                            i != e && t != '' ? ($(this).prop("disabled", !0), $(this).prop("hidden", !0)) : ($(this).prop("disabled", !1), $(this).prop("hidden", !1));
2890                            //i != e && -1 != t ? ($(this).prop("disabled", !0), $(this).prop("hidden", !0)) : ($(this).prop("disabled", !1), $(this).prop("hidden", !1));
2891                      });
2892                      $("select." + e).selectpicker('refresh');
2893    }
2894
2895    $(".houzezSelectFilter").on("change", function () {
2896        var $this = $(this);
2897        houzezSelectFilter($this);
2898    });
2899
2900    if( $('.houzez-search-form-js').length > 0 || $('#location').length > 0 ) {
2901
2902        var countryRef, stateRef, cityRef, areasRef;
2903        if( is_edit_property ) {
2904            countryRef = $('#country').data("country");
2905            stateRef = $('#countyState').data("state");
2906            cityRef = $('#city').data("city");
2907            areasRef = $('#neighborhood').data("area");
2908        } else {
2909            countryRef = houzez_vars.s_country;
2910            stateRef = houzez_vars.s_state;
2911            cityRef = houzez_vars.s_city;
2912            areasRef = houzez_vars.s_areas;
2913        }
2914
2915        if( ( $('.houzez-country-js').length > 0 || $('#country').length > 0 ) && countryRef != "" ) {
2916            var countryFilter = $('.houzezCountryFilter');
2917            houzezSelectFilter(countryFilter, countryRef, 'houzezSecondList', 'yes');
2918
2919            $( window ).load(function() {
2920                $('.houzezSecondList').val(stateRef);
2921                $("select.houzezSecondList").selectpicker('refresh');
2922            });
2923        }
2924
2925        if( ( $('.houzez-state-js').length > 0 || $('#countyState').length > 0 ) && stateRef != "" ) {
2926            var stateFilter = $('.houzezStateFilter');
2927            houzezSelectFilter(stateFilter, stateRef, 'houzezThirdList', 'yes');
2928
2929            $( window ).load(function() {
2930                $('.houzezThirdList').val(cityRef);
2931                $("select.houzezThirdList").selectpicker('refresh');
2932            });
2933        }
2934
2935        if( ( $('.houzez-city-js').length > 0 || $('#city').length > 0 ) && cityRef != "" ) {
2936            var cityFilter = $('.houzezCityFilter');
2937            houzezSelectFilter(cityFilter, cityRef, 'houzezFourthList', 'yes');
2938
2939            $( window ).load(function() {
2940                $('.houzezFourthList').val(areasRef);
2941                $("select.houzezFourthList").selectpicker('refresh');
2942            });
2943        }
2944    }
2945
2946    
2947
2948    /*-----------------------------------------------------------------------------------*/
2949    /* mortgage calculate by waqas
2950    /*-----------------------------------------------------------------------------------*/
2951    if( $('#houzez_mortgage_calculate').length > 0 ) {
2952        $('#houzez_mortgage_calculate').click(function(e) {
2953            e.preventDefault();
2954
2955            var monthly_payment = houzez_vars.monthly_payment;
2956            var weekly_payment = houzez_vars.weekly_payment;
2957            var bi_weekly_payment = houzez_vars.bi_weekly_payment;
2958            var currency_symb = houzez_vars.currency_symbol;
2959
2960            var totalPrice  = 0;
2961            var down_payment = 0;
2962            var term_years  = 0;
2963            var interest_rate = 0;
2964            var amount_financed  = 0;
2965            var monthInterest = 0;
2966            var intVal = 0;
2967            var mortgage_pay = 0;
2968            var annualCost = 0;
2969            var payment_period;
2970            var mortgage_pay_text;
2971
2972
2973            var total_years = $('#mc_term_years').val();
2974            payment_period = $('#mc_payment_period').val();
2975
2976            totalPrice = $('#mc_total_amount').val().replace(/,/g, '');
2977            down_payment = $('#mc_down_payment').val().replace(/,/g, '');
2978            amount_financed = totalPrice - down_payment;
2979            term_years =  parseInt ($('#mc_term_years').val(),10) * payment_period;
2980            interest_rate = parseFloat ($('#mc_interest_rate').val(),10);
2981            monthInterest = interest_rate / (payment_period * 100);
2982            intVal = Math.pow( 1 + monthInterest, -term_years );
2983            mortgage_pay = amount_financed * (monthInterest / (1 - intVal));
2984            annualCost = mortgage_pay * payment_period;
2985            
2986            if( $('#mc_term_years').val() == '' || $('#mc_total_amount') == '' || $('#mc_down_payment') == '' || $('#mc_interest_rate') == '' ) {
2987                return;
2988            }
2989
2990            var total_mortgage_with_interest = mortgage_pay * total_years * payment_period;
2991
2992            var total_with_down_payment = total_mortgage_with_interest + parseInt(down_payment);
2993
2994            if( payment_period == '12' ) {
2995                mortgage_pay_text = monthly_payment;
2996
2997            } else if ( payment_period == '26' ) {
2998                mortgage_pay_text = bi_weekly_payment;
2999
3000            } else if ( payment_period == '52' ) {
3001                mortgage_pay_text = weekly_payment;
3002
3003            }
3004
3005
3006            if(currency_position == 'after') {
3007                $('#mortgage_mwbi').html("<strong>"+mortgage_pay_text+ "</strong>: <span>"+(Math.round(mortgage_pay * 100)) / 100 + currency_symb + "</span>");
3008                $('#amount_financed').html(((Math.round(amount_financed * 100)) / 100)+currency_symb);
3009                $('#mortgage_pay').html(((Math.round(mortgage_pay * 100)) / 100)+currency_symb);
3010                $('#annual_cost').html(( (Math.round(annualCost * 100)) / 100)+currency_symb);
3011                $('#balance_payable_with_interest').html(( (Math.round(total_mortgage_with_interest * 100)) / 100)+currency_symb);
3012                $('#total_with_down_payment').html(( (Math.round(total_with_down_payment * 100)) / 100)+currency_symb);
3013            } else {
3014                $('#mortgage_mwbi').html("<strong>"+mortgage_pay_text+ "</strong>: <span>" +currency_symb+ (Math.round(mortgage_pay * 100)) / 100 + "</span>");
3015                $('#amount_financed').html(currency_symb+(Math.round(amount_financed * 100)) / 100);
3016                $('#mortgage_pay').html(currency_symb+(Math.round(mortgage_pay * 100)) / 100);
3017                $('#annual_cost').html(currency_symb+(Math.round(annualCost * 100)) / 100);
3018                $('#balance_payable_with_interest').html(currency_symb+(Math.round(total_mortgage_with_interest * 100)) / 100);
3019                $('#total_with_down_payment').html(currency_symb+(Math.round(total_with_down_payment * 100)) / 100);
3020            }
3021
3022            $('#cal_years').html(total_years);
3023            $('.mortgage-details').show();
3024        });
3025    }
3026
3027    /* ------------------------------------------------------------------------ */
3028    /* Beds and baths
3029    /* ------------------------------------------------------------------------ */
3030    var beds_baths = function(btn_action, btn_count, btn_val) {
3031        $('.'+btn_action).on('click', function(e) {
3032            e.preventDefault();
3033            var current_val = parseInt($('.'+btn_val).val()) || 0;
3034
3035            if(btn_action == 'btn_count_plus' || btn_action == 'btn_beds_plus') {
3036                current_val++;
3037
3038            } else { 
3039                if(current_val == 0)
3040                return;
3041                current_val--;
3042            }
3043            
3044            $('.'+btn_count).text(current_val);
3045            $('.'+btn_val).val(current_val);
3046        });
3047
3048    }
3049    beds_baths('btn_count_plus', 'baths_count', 'bathrooms');
3050    beds_baths('btn_count_minus', 'baths_count', 'bathrooms');
3051
3052    beds_baths('btn_beds_plus', 'beds_count', 'bedrooms');
3053    beds_baths('btn_beds_minus', 'beds_count', 'bedrooms');
3054
3055    $('.btn-apply').on('click', function(e) {
3056        e.preventDefault();
3057        $('.advanced-search-v3 .btn-group .dropdown-menu').removeClass('show');
3058    });
3059
3060    $('.clear-baths').on('click', function(e) {
3061        e.preventDefault();
3062        $('.baths_count').text('0');
3063        $('.bathrooms').val('');
3064    });
3065
3066    $('.clear-beds').on('click', function(e) {
3067        e.preventDefault();
3068        $('.beds_count').text('0');
3069        $('.bedrooms').val('');
3070    });
3071
3072    $('.clear-checkboxes').on('click', function(e) {
3073        e.preventDefault();
3074        $(this).parents('.btn-group').find('input[type="checkbox"]').prop("checked", false).attr('checked', false);
3075    });
3076
3077    /* ------------------------------------------------------------------------ */
3078    /*  PAYPAL & Stripe OPTIONS
3079     /* ------------------------------------------------------------------------ */
3080    $('.method-select input').on('change',function () {
3081        if($(this).is(':checked')) {
3082            $('.recurring-payment-wrap').slideUp();
3083            $(this).parents('.payment-method-block').next('.recurring-payment-wrap').slideDown();
3084        }else{
3085            $('.recurring-payment-wrap').slideUp();
3086        }
3087    });
3088    function paypal_option(ele){
3089        if($(ele).attr('checked')) {
3090            $(ele).parents('.payment-method-block').next('.recurring-payment-wrap').slideDown();
3091        }else{
3092            $(ele).parents('.payment-method-block').next('.recurring-payment-wrap').slideUp();
3093        }
3094    }
3095
3096    paypal_option('.paypal-method');
3097    paypal_option('.stripe-method');
3098
3099    $('button.stripe-button-el span').prepend('<i class="fa fa-credit-card"></i>');
3100    $('#stripe_package_recurring').click(function () {
3101        if( $(this).attr('checked') ) {
3102            $('.houzez_payment_form').append('<input type="hidden" name="houzez_stripe_recurring" id="houzez_stripe_recurring" value="1">');
3103        }else{
3104            $('#houzez_stripe_recurring').remove();
3105        }
3106    });
3107
3108    /* ------------------------------------------------------------------------ */
3109    /*  Change listing fee for featured
3110     /* ------------------------------------------------------------------------ */
3111    $('.prop_featured').on('change', function() {
3112
3113        var currency_symbol = houzez_vars.currency_symbol;
3114        var currency_position = houzez_vars.currency_position;
3115        var total_price, total_price_with_currency, price_regular_with_currency;
3116        var price_regular  = parseFloat( $('#submission_price').text() );
3117        var price_featured = parseFloat( $('#submission_featured_price').text() );
3118
3119        total_price = price_regular+price_featured;
3120
3121        if ( currency_position === 'after'){
3122            price_regular_with_currency = price_regular +''+currency_symbol;
3123            total_price_with_currency = total_price +''+currency_symbol;
3124        }else{
3125            price_regular_with_currency = currency_symbol +''+price_regular;
3126            total_price_with_currency = currency_symbol+''+total_price;
3127        }
3128
3129        if( $(this).is(':checked') ) {
3130            $('#submission_total_price').text(total_price_with_currency);
3131            $('#featured_pay').val(1);
3132            $('input[name="pay_ammout"]').val(total_price * 100);
3133            $('#houzez_listing_price').val(total_price);
3134        } else {
3135            $('#submission_total_price').text(price_regular_with_currency);
3136            $('#featured_pay').val(0);
3137            $('input[name="pay_ammout"]').val(price_regular * 100);
3138            $('#houzez_listing_price').val(price_regular);
3139        }
3140        return false;
3141    });
3142
3143    /* ------------------------------------------------------------------------ */
3144    /*  Paypal single listing payment
3145     /* ------------------------------------------------------------------------ */
3146    $('#houzez_complete_order').on('click', function(e) {
3147        e.preventDefault();
3148        var hform, relist_mode, payment_gateway, houzez_listing_price, property_id, is_prop_featured, is_prop_upgrade;
3149
3150        payment_gateway = $("input[name='houzez_payment_type']:checked").val();
3151        is_prop_featured = $("input[name='featured_pay']").val();
3152        is_prop_upgrade = $("input[name='is_upgrade']").val();
3153        relist_mode = $("input[name='relist_mode']").val();
3154
3155        property_id = $('#houzez_property_id').val();
3156        houzez_listing_price = $('#houzez_listing_price').val();
3157
3158        if( payment_gateway == 'paypal' ) {
3159            fave_processing_modal( paypal_connecting );
3160            paypal_per_listing_payment( property_id, is_prop_featured, is_prop_upgrade, relist_mode);
3161
3162        } else if ( payment_gateway == 'stripe' ) {
3163            
3164            fave_processing_modal( processing_text );
3165            stripe_per_listing_payment( property_id, is_prop_featured, is_prop_upgrade, relist_mode);
3166
3167        } else if ( payment_gateway == 'direct_pay' ) {
3168            fave_processing_modal( processing_text );
3169            bank_transfer_per_listing(property_id, houzez_listing_price);
3170        }
3171        return;
3172
3173    });
3174
3175    /* ------------------------------------------------------------------------ */
3176    /*  Paypal payment for per listing
3177     /* ------------------------------------------------------------------------ */
3178    var paypal_per_listing_payment = function( property_id, is_prop_featured, is_prop_upgrade, relist_mode ) {
3179
3180        $.ajax({
3181            type: 'post',
3182            url: ajaxurl,
3183            data: {
3184                'action': 'houzez_property_paypal_payment',
3185                'prop_id': property_id,
3186                'is_prop_featured': is_prop_featured,
3187                'is_prop_upgrade': is_prop_upgrade,
3188                'relist_mode': relist_mode,
3189            },
3190            success: function( response ) {
3191                window.location.href = response;
3192            },
3193            error: function(xhr, status, error) {
3194                var err = eval("(" + xhr.responseText + ")");
3195                console.log(err.Message);
3196            }
3197        });
3198    }
3199
3200    /* ------------------------------------------------------------------------ */
3201    /*  Stripe payment for per listing
3202     /* ------------------------------------------------------------------------ */
3203    var stripe_per_listing_payment = function( property_id, is_prop_featured, is_prop_upgrade, relist_mode ) {
3204
3205        $.ajax({
3206            type: 'post',
3207            url: ajaxurl,
3208            dataType: 'JSON',
3209            data: {
3210                'action': 'houzez_property_stripe_payment',
3211                'prop_id': property_id,
3212                'is_prop_featured': is_prop_featured,
3213                'is_prop_upgrade': is_prop_upgrade,
3214                'relist_mode': relist_mode,
3215            },
3216            success: function( response ) {
3217                if( response.status ) {
3218                    window.location.href = response.paymeny_link;
3219                } else {
3220                    alert(response.message);
3221                }
3222            },
3223            error: function(xhr, status, error) {
3224                var err = eval("(" + xhr.responseText + ")");
3225                console.log(err.Message);
3226            }
3227        });
3228    }
3229
3230    /* ------------------------------------------------------------------------ */
3231    /*  Wire Transfer per listing payment
3232     /* ------------------------------------------------------------------------ */
3233    var bank_transfer_per_listing = function( prop_id, listing_price ) {
3234        var is_featured = $('input[name="featured_pay"]').val();
3235        var is_upgrade = $('input[name="is_upgrade"]').val();
3236
3237        jQuery.ajax({
3238            type: 'POST',
3239            url: ajaxurl,
3240            data: {
3241                'action'        : 'houzez_direct_pay_per_listing',
3242                'prop_id'       : prop_id,
3243                'is_featured'   : is_featured,
3244                'is_upgrade'    : is_upgrade
3245            },
3246            success: function (data) {
3247                window.location.href = data;
3248            },
3249            error: function (errorThrown) {}
3250        });
3251
3252    }
3253
3254    /* ------------------------------------------------------------------------ */
3255    /*  Select Membership payment
3256     /* ------------------------------------------------------------------------ */
3257     var houzez_stripe_package_payment = function( houzez_package_id, is_stripe_recurring ) { 
3258
3259        $.ajax({
3260            type: 'POST',
3261            url: ajaxurl,
3262            dataType: 'JSON',
3263            data: {
3264                'action'    : 'houzez_stripe_package_payment',
3265                'package_id'  : houzez_package_id,
3266                'is_stripe_recurring' : is_stripe_recurring
3267            },
3268            success: function (response) {
3269                if( response.status ) {
3270                    window.location.href = response.paymeny_link;
3271                } else {
3272                    alert(response.message);
3273                }
3274            },
3275            error: function(xhr, status, error) {
3276                var err = eval("(" + xhr.responseText + ")");
3277                console.log(err.Message);
3278            }
3279        });
3280    }
3281
3282    var houzez_paypal_package_payment = function( houzez_package_price, houzez_package_name, houzez_package_id ) {
3283
3284        $.ajax({
3285            type: 'POST',
3286            url: ajaxurl,
3287            data: {
3288                'action'    : 'houzez_paypal_package_payment',
3289                'houzez_package_price' : houzez_package_price,
3290                'houzez_package_name'  : houzez_package_name,
3291                'houzez_package_id'  : houzez_package_id
3292            },
3293            success: function (data) {
3294                window.location.href = data;
3295            },
3296            error: function(xhr, status, error) {
3297                var err = eval("(" + xhr.responseText + ")");
3298                console.log(err.Message);
3299            }
3300        });
3301    }
3302
3303    var houzez_recuring_paypal_package_payment = function(  houzez_package_price, houzez_package_name, houzez_package_id  ) {
3304
3305        jQuery.ajax({
3306            type: 'POST',
3307            url: ajaxurl,
3308            data: {
3309                'action'               : 'houzez_recuring_paypal_package_payment',
3310                'houzez_package_name'  : houzez_package_name,
3311                'houzez_package_id'    : houzez_package_id,
3312                'houzez_package_price' : houzez_package_price
3313            },
3314            success: function (data) { //alert(data); return false;
3315                window.location.href = data;
3316            },
3317            error: function(xhr, status, error) {
3318                var err = eval("(" + xhr.responseText + ")");
3319                console.log(err.Message);
3320            }
3321        });
3322    }
3323
3324    var direct_bank_transfer_package = function( houzez_package_id, houzez_package_price, houzez_package_name ) {
3325
3326        jQuery.ajax({
3327            type: 'POST',
3328            url: ajaxurl,
3329            data: {
3330                'action'           : 'houzez_direct_pay_package',
3331                'selected_package' : houzez_package_id,
3332            },
3333            success: function (data) {
3334                window.location.href = data;
3335
3336            },
3337            error: function (errorThrown) {}
3338        });
3339    }
3340
3341    var houzez_free_membership_package = function ( houzez_package_id ) {
3342        jQuery.ajax({
3343            type: 'POST',
3344            url: ajaxurl,
3345            data: {
3346                'action'           : 'houzez_free_membership_package',
3347                'selected_package' : houzez_package_id,
3348            },
3349            success: function (data) {
3350                window.location.href = data;
3351
3352            },
3353            error: function (errorThrown) {}
3354        });
3355    }
3356
3357    var houzez_membership_data = function(currnt) {
3358        var payment_gateway = $("input[name='houzez_payment_type']:checked").val();
3359        var houzez_package_price = $("input[name='houzez_package_price']").val();
3360        var houzez_package_id    = $("input[name='houzez_package_id']").val();
3361        var houzez_package_name  = $("#houzez_package_name").text();
3362
3363        if( payment_gateway == 'paypal' ) {
3364            fave_processing_modal( paypal_connecting );
3365            if ($('#paypal_package_recurring').is(':checked')) {
3366                houzez_recuring_paypal_package_payment( houzez_package_price, houzez_package_name, houzez_package_id );
3367            } else {
3368                houzez_paypal_package_payment( houzez_package_price, houzez_package_name, houzez_package_id );
3369            }
3370
3371        } else if ( payment_gateway == 'stripe' ) {
3372            fave_processing_modal( processing_text );
3373            var is_stripe_recurring = $('#houzez_stripe_recurring').is(':checked');
3374            houzez_stripe_package_payment( houzez_package_id, is_stripe_recurring );
3375
3376        } else if ( payment_gateway == 'direct_pay' ) {
3377            fave_processing_modal( processing_text );
3378            direct_bank_transfer_package( houzez_package_id, houzez_package_price, houzez_package_name );
3379
3380        } else {
3381            fave_processing_modal( processing_text );
3382            houzez_free_membership_package(  houzez_package_id );
3383        }
3384
3385        return false;
3386    }
3387
3388    var houzez_register_user_with_membership = function ( currnt ) {
3389
3390        var $form = currnt.parents('form');
3391        var $messages = $('#packmem-msgs');
3392
3393        $.ajax({
3394            type: 'post',
3395            url: ajaxurl,
3396            dataType: 'json',
3397            data: $form.serialize(),
3398            beforeSend: function( ) {
3399                currnt.find('.houzez-loader-js').addClass('loader-show');
3400            },
3401            complete: function(){
3402                currnt.find('.houzez-loader-js').removeClass('loader-show');
3403            },
3404            success: function( response ) {
3405                if( response.success ) {
3406                    houzez_membership_data(currnt);
3407                } else {
3408                    $('html, body').animate({
3409                        scrollTop: $(".frontend-submission-page").offset().top
3410                    }, 'slow');
3411                    $messages.empty().append('<div class="alert alert-danger alert-dismissible fade show" role="alert">'+response.msg+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
3412                }
3413            },
3414            error: function(xhr, status, error) {
3415                var err = eval("(" + xhr.responseText + ")");
3416                console.log(err.Message);
3417            }
3418        });
3419    }
3420
3421    $('#houzez_complete_membership').on('click', function(e) {
3422        e.preventDefault();
3423        var currnt = $(this);
3424        if( parseInt( userID, 10 ) === 0 || userID == undefined) {
3425            houzez_register_user_with_membership( currnt );
3426            return;
3427        }
3428        houzez_membership_data(currnt);
3429    } );
3430
3431
3432    /*--------------------------------------------------------------------------
3433     *  Area Switcher
3434     * -------------------------------------------------------------------------*/
3435    var areaSwitcherList = $('#area-switcher-list-js');
3436    if( areaSwitcherList.length > 0 ) {
3437
3438        $('#area-switcher-list-js > li').on('click', function(e) {
3439            //e.stopPropagation();
3440            
3441            var selectedAreaCode = $(this).data( 'area-code' );
3442            if ( selectedAreaCode ) {
3443
3444                $('#houzez-switch-to-area').val( selectedAreaCode );
3445                var houzez_switch_to_area = $('#houzez-switch-to-area').val();
3446                fave_processing_modal(processing_text);
3447
3448                $.ajax({
3449                    url: ajaxurl,
3450                    dataType: 'JSON',
3451                    method: 'POST',
3452                    data: {
3453                        'action' : 'houzez_switch_area',
3454                        'switch_to_area' : houzez_switch_to_area,
3455                    },
3456                    success: function (res) {
3457                        if( res.success ) {
3458                            window.location.reload( true );
3459                        } else {
3460                            console.log( res );
3461                        }
3462                    },
3463                    error: function (xhr, status, error) {
3464                        var err = eval("(" + xhr.responseText + ")");
3465                        console.log(err.Message);
3466                    }
3467                });
3468
3469            }
3470
3471        });
3472    }
3473
3474    /*--------------------------------------------------------------------------
3475     *  Currency Switcher
3476     * -------------------------------------------------------------------------*/
3477    var currencySwitcherList = $('#hz-currency-switcher-list');
3478    if( currencySwitcherList.length > 0 ) {
3479
3480        $('#hz-currency-switcher-list > li').on('click', function(e) {
3481        
3482            var selectedCurrencyCode = $(this).data( 'currency-code' );
3483
3484            if ( selectedCurrencyCode ) {
3485
3486                $('#houzez-switch-to-currency').val( selectedCurrencyCode );
3487                var houzez_switch_to_currency = $('#houzez-switch-to-currency').val();
3488                fave_processing_modal(processing_text);
3489
3490                $.ajax({
3491                    url: ajaxurl,
3492                    dataType: 'JSON',
3493                    method: 'POST',
3494                    data: {
3495                        'action' : 'houzez_currency_converter',
3496                        'currency_converter' : selectedCurrencyCode
3497                    },
3498                    success: function (res) {
3499                        if( res.success ) {
3500                            window.location.reload( true );
3501                        } else {
3502                            console.log( res );
3503                        }
3504                    },
3505                    error: function (xhr, status, error) {
3506                        var err = eval("(" + xhr.responseText + ")");
3507                        console.log(err.Message);
3508                    }
3509                });
3510
3511            }
3512
3513        });
3514    }
3515
3516    /* ------------------------------------------------------------------------ */
3517    /* tooltip
3518    /* ------------------------------------------------------------------------ */
3519    $('[data-toggle="tooltip"]').tooltip()
3520
3521    /* ------------------------------------------------------------------------ */
3522    /* prevent advanced search dropdowns from closing on clicks
3523    /* ------------------------------------------------------------------------ */
3524    $('.advanced-search-dropdown').on('click', function (e) {
3525        e.stopPropagation();
3526    });
3527
3528    /* ------------------------------------------------------------------------ */
3529    /* agent phone number
3530    /* ------------------------------------------------------------------------ */
3531    $('.agent-show-onClick').on('click', function (e) {
3532        $(this).toggleClass('agent-phone-hidden');
3533    });
3534
3535    /* ------------------------------------------------------------------------ */
3536    /*  drop down menus
3537    /* ------------------------------------------------------------------------ */
3538    $('.dropdown-menu span.dropdown-toggle').on('click', function(e) {
3539      if (!$(this).next().hasClass('show')) {
3540            $(this).parents('.dropdown-menu').first().find('.show').removeClass('show');
3541        }
3542        var $subMenu = $(this).next('.dropdown-menu');
3543        $subMenu.toggleClass('show');
3544
3545
3546        $(this).parents('li.nav-item.dropdown.show').on('hidden.bs.dropdown', function(e) {
3547            $('.dropdown-submenu .show').removeClass('show');
3548        });
3549
3550
3551        return false;
3552    });
3553
3554    /* ------------------------------------------------------------------------ */
3555    /*  avoid zoom when double click on mobile devices
3556    /* ------------------------------------------------------------------------ */
3557    $.fn.nodoubletapzoom = function () {
3558        $(this).bind('touchstart', function preventZoom(e) {
3559            var t2 = e.timeStamp,
3560                t1 = $(this).data('lastTouch') || t2,
3561                dt = t2 - t1,
3562                fingers = e.originalEvent.touches.length;
3563            $(this).data('lastTouch', t2);
3564            if (!dt || dt > 500 || fingers > 1) return;
3565
3566            e.preventDefault();
3567            $(this).trigger('click').trigger('click');
3568        });
3569    };
3570
3571
3572    /* ------------------------------------------------------------------------ */
3573    /*  mobile menu
3574    /* ------------------------------------------------------------------------ */
3575    // disable touch
3576    if($('.nav-mobile-js').length > 0 ) {
3577
3578        var smm_transform = 256;
3579        if ( houzez_rtl ) {
3580            smm_transform = -256;
3581        }
3582        var slideout_left = new Slideout({
3583            'panel': document.getElementById('main-wrap'),
3584            'menu': document.getElementById('nav-mobile'),
3585            'padding': smm_transform,
3586            'tolerance': 70,
3587            'side': 'left',
3588            'easing': 'cubic-bezier(.32,2,.55,.27)'
3589        });
3590        slideout_left.disableTouch();
3591    }
3592
3593    if($('.main-wrap-js').length > 0 ) {
3594        var smd_transform = 256;
3595        if ( houzez_rtl ) {
3596            smd_transform = -256;
3597        }
3598        var slideout_right = new Slideout({
3599            'panel': document.getElementById('main-wrap'),
3600            'menu': document.getElementById('navi-user'),
3601            'padding': smd_transform,
3602            'tolerance': 70,
3603            'side': 'right',
3604            'easing': 'cubic-bezier(.32,2,.55,.27)'
3605        });
3606        slideout_right.disableTouch();
3607    }
3608
3609    // Toggle button
3610    $('.toggle-button-left, #nav-mobile .nav-link:not(.dropdown-toggle)').on('click', function () {
3611        slideout_left.toggle();
3612        $('.slideout-menu-left').toggleClass('open');
3613    });
3614    $('.toggle-button-right').on('click', function () {
3615        slideout_right.toggle();
3616        $('.slideout-menu-right').toggleClass('open');
3617    });
3618
3619
3620     /* ---------------------------------------------------- */
3621    /*  Close Menu when click outside
3622     /* ---------------------------------------------------- */
3623    $(document).on('mouseup', function (e) { 
3624        var mobileNavcontainer = $(".nav-mobile");
3625        var toggleBtnCloseW = $(".toggle-button-left");
3626        var mobileMenuDiv = $('#nav-mobile');
3627        
3628
3629        var toggleBtnCloseL = $(".toggle-button-right");
3630        var mobileMenuDivL = $('#navi-user');
3631
3632        if (!mobileNavcontainer.is(e.target) && mobileNavcontainer.has(e.target).length === 0 && mobileMenuDiv.hasClass('open') && !toggleBtnCloseW.is(e.target) && toggleBtnCloseW.has(e.target).length === 0 ) {
3633            slideout_left.toggle();
3634            $('.slideout-menu-left').toggleClass('open');
3635        }
3636
3637        if (!mobileNavcontainer.is(e.target) && mobileNavcontainer.has(e.target).length === 0 && mobileMenuDivL.hasClass('open') && !toggleBtnCloseL.is(e.target) && toggleBtnCloseL.has(e.target).length === 0 ) {
3638            slideout_right.toggle();
3639            $('.slideout-menu-right').toggleClass('open');
3640        }
3641    });
3642
3643    /* ------------------------------------------------------------------------ */
3644    /*  search distance slider
3645    /* ------------------------------------------------------------------------ */
3646    $(function () {
3647        if($('.distance-range').length > 0) {
3648            $(".distance-range").slider();
3649        }
3650    });
3651    /* ------------------------------------------------------------------------ */
3652    /*  parallax
3653    /* ------------------------------------------------------------------------ */
3654    function houzez_parallax_listings() {
3655        var header_parallax = $('.parallax');
3656        if( header_parallax.length > 0 ) {
3657            header_parallax.parallaxBackground({
3658                parallaxBgPosition: "center center",
3659                parallaxBgRepeat: "no-repeat",
3660                parallaxBgSize: "cover",
3661                parallaxSpeed: "0.25",
3662            });
3663        }
3664    }
3665    houzez_parallax_listings();
3666
3667    /* ------------------------------------------------------------------------ */
3668    /* mobile search form overlay
3669    /* ------------------------------------------------------------------------ */
3670    $(document).ready(function () {
3671        $(".mobile-search-nav").click(function () {
3672            $("#overlay-search-advanced-module").toggleClass("open");
3673        });
3674    });
3675    $(document).ready(function () {
3676        $(".overlay-search-module-close, .overly_is_halfmap .half-map-search-js-btn").click(function () {
3677            $("#overlay-search-advanced-module").toggleClass("open");
3678        });
3679    });
3680
3681    /* ------------------------------------------------------------------------ */
3682    /*  half map elements size
3683    /* ------------------------------------------------------------------------ */
3684    function setSectionHeight() {
3685        var window_height = $(window).innerHeight();
3686        var sections_height = window_height - header_area_height;
3687        sections_height = sections_height - advanced_search_nav_height;
3688        sections_height = sections_height - elementor_location_header_height;
3689
3690        if ($(window).width() >= 767) { 
3691            $('.half-map-left-wrap, .half-map-right-wrap').css('height', sections_height);
3692        } else { 
3693            $('.map-on-right .half-map-right-wrap').css('height', sections_height);
3694            $('.map-on-right .half-map-left-wrap').css('height', '100vh');
3695            $('.map-on-left .half-map-right-wrap').css('height', sections_height);
3696            $('.map-on-left .half-map-left-wrap').css('height', '100vh');
3697        }
3698    }
3699    setSectionHeight();
3700    $win.on('resize', function () {
3701        setSectionHeight();
3702    });
3703
3704    /* ------------------------------------------------------------------------ */
3705    /*  listing switch view
3706    /* ------------------------------------------------------------------------ */
3707    $('.switch-btn').on("click", function () {
3708        $('.switch-btn').removeClass('active');
3709        $(this).addClass('active');
3710        if ($(this).hasClass('btn-list')) {
3711            $('.listing-view').removeClass('grid-view').addClass('list-view');
3712        } else if ($(this).hasClass('btn-grid')) {
3713            $('.listing-view').removeClass('list-view').addClass('grid-view');
3714        }
3715
3716    });
3717    /* ------------------------------------------------------------------------ */
3718    /* compare properties
3719    /* ------------------------------------------------------------------------ */
3720    $(document).ready(function () {
3721        $('.show-compare-panel').click(function () {
3722            $(this).toggleClass('active');
3723            $('.compare-property-active').addClass('compare-property-active-push-toleft');
3724            $('#compare-property-panel').addClass('compare-property-panel-open');
3725            //disableOther( 'show-compare-panel' );
3726        });
3727        $('.close-compare-panel').click(function () {
3728            $(this).toggleClass('active');
3729            $('.compare-property-active').removeClass('compare-property-active-push-toleft');
3730            $('#compare-property-panel').removeClass('compare-property-panel-open');
3731            //disableOther( 'show-compare-panel' );
3732        });
3733    });
3734    /* ------------------------------------------------------------------------ */
3735    /*  property slider
3736    /* ------------------------------------------------------------------------ */
3737    var property_banner_slider = $('.property-slider');
3738    if( property_banner_slider.length > 0 ) {
3739        
3740        var autoplay = property_banner_slider.data('autoplay');
3741        var slider_loop = property_banner_slider.data('loop');
3742        var slider_speed = property_banner_slider.data('speed');
3743
3744        var s_loop = false;
3745        if(slider_loop == 1) {
3746            s_loop = true;
3747        }
3748
3749        property_banner_slider.slick({
3750            rtl: houzez_rtl,
3751            autoplay: autoplay,
3752            autoplaySpeed: slider_speed,
3753            lazyLoad: 'ondemand',
3754            infinite: s_loop,
3755            speed: 300,
3756            slidesToShow: 1,
3757            arrows: true,
3758            adaptiveHeight: true
3759        });
3760    }
3761
3762    var property_detail_gallery = $('#property-gallery-js');
3763    if( property_detail_gallery.length > 0 ) { 
3764        property_detail_gallery.lightSlider({
3765            rtl: houzez_rtl,
3766            gallery:true,
3767            item:1,
3768            thumbItem:8,
3769            slideMargin: 0,
3770            speed:500,
3771            adaptiveHeight: true,
3772            auto:false,
3773            loop:false,
3774            prevHtml: '<button type="button" class="slick-prev slick-arrow"></button>',
3775            nextHtml: '<button type="button" class="slick-next slick-arrow"></button>',
3776            onSliderLoad: function() {
3777                property_detail_gallery.removeClass('cS-hidden');
3778            }  
3779        });
3780    }
3781
3782
3783    var lightbox_slider_js = $('#lightbox-slider-js');
3784    if( lightbox_slider_js.length > 0 ) {
3785        
3786        lightbox_slider_js.slick({
3787            rtl: houzez_rtl,
3788            lazyLoad: 'ondemand',
3789            infinite: true,
3790            speed: 300,
3791            slidesToShow: 1,
3792            arrows: true,
3793            adaptiveHeight: true,
3794        });
3795
3796        $('.houzez-trigger-popup-slider-js').on('click', function (e) {
3797            e.preventDefault();
3798                
3799            var slider_num = parseInt( $(this).data('slider-no') );
3800            setTimeout(function(){ 
3801                lightbox_slider_js.slick('slickGoTo', slider_num - 1);
3802            }, 200);
3803        });
3804
3805    }
3806
3807    
3808    var listing_slider_variable_width = $('.listing-slider-variable-width');
3809    if( listing_slider_variable_width.length > 0 ) {
3810        listing_slider_variable_width.slick({
3811            rtl: houzez_rtl,
3812            lazyLoad: 'ondemand',
3813            infinite: true,
3814            speed: 300,
3815            slidesToShow: 1,
3816            centerMode: true,
3817            variableWidth: true,
3818            arrows: true,
3819            adaptiveHeight: true
3820        });  
3821
3822        $('.property-detail-v5 #pills-gallery-tab').on('click', function() {
3823            if (!listing_slider_variable_width.hasClass('hz-slick-refreshed')) {
3824                setTimeout(function() {
3825                    listing_slider_variable_width.slick('setPosition');
3826                    listing_slider_variable_width.slick('refresh');
3827                    listing_slider_variable_width.addClass('hz-slick-refreshed');
3828                }, 0);
3829            }
3830        });
3831    }
3832
3833
3834    /* ------------------------------------------------------------------------ */
3835    /*  testimonial slider
3836    /* ------------------------------------------------------------------------ */
3837    var testimonials_slider_v1 = $('.testimonials-slider-wrap-v1');
3838    if( testimonials_slider_v1.length > 0 ) {
3839        
3840        testimonials_slider_v1.slick({
3841            rtl: houzez_rtl,
3842            lazyLoad: 'ondemand',
3843            infinite: true,
3844            autoplay: true,
3845            speed: 300,
3846            slidesToShow: 1,
3847            arrows: true,
3848            adaptiveHeight: true,
3849            dots: true,
3850            appendArrows: '.testimonials-module-slider-v1',
3851            prevArrow: '<button type="button" class="slick-prev btn-primary-outlined">'+prev_text+'</button>',
3852            nextArrow: '<button type="button" class="slick-next btn-primary-outlined">'+next_text+'</button>',
3853        });
3854    }
3855
3856    var testimonials_slider_v2 = $('.testimonials-slider-wrap-v2');
3857    if( testimonials_slider_v2.length > 0 ) {
3858        testimonials_slider_v2.slick({
3859            rtl: houzez_rtl,
3860            lazyLoad: 'ondemand',
3861            infinite: true,
3862            autoplay: true,
3863            speed: 300,
3864            slidesToShow: 3,
3865            arrows: true,
3866            adaptiveHeight: true,
3867            dots: true,
3868            appendArrows: '.testimonials-module-slider-v2',
3869            prevArrow: '<button type="button" class="slick-prev btn-primary-outlined">'+prev_text+'</button>',
3870            nextArrow: '<button type="button" class="slick-next btn-primary-outlined">'+next_text+'</button>',
3871            responsive: [{
3872                    breakpoint: 992,
3873                    settings: {
3874                        slidesToShow: 2,
3875                        slidesToScroll: 2
3876                    }
3877                },
3878                {
3879                    breakpoint: 769,
3880                    settings: {
3881                        slidesToShow: 1,
3882                        slidesToScroll: 1
3883                    }
3884                }
3885            ]
3886        });
3887    }
3888
3889    var testimonials_slider_v3 = $('.testimonials-slider-wrap-v3');
3890    if( testimonials_slider_v3.length > 0 ) {
3891        
3892        testimonials_slider_v3.slick({
3893            rtl: houzez_rtl,
3894            lazyLoad: 'ondemand',
3895            infinite: true,
3896            fade: true,
3897            autoplay: true,
3898            speed: 300,
3899            slidesToShow: 1,
3900            arrows: true,
3901            adaptiveHeight: true,
3902            dots: false,
3903            appendArrows: '.testimonials-module-slider-v3',
3904            prevArrow: $('.slick-prev'),
3905            nextArrow: $('.slick-next'),
3906        });
3907    }
3908
3909    /* ------------------------------------------------------------------------ */
3910    /*  Custom slider
3911    /* ------------------------------------------------------------------------ */
3912    var houzez_custom_carousel = $('.custom-carousel');
3913    if( houzez_custom_carousel.length > 0 ) {
3914        
3915        $('.custom-carousel').each(function() {
3916            var token = $(this).data('token');
3917            var carouselSettings = $(this).data('carousel');
3918            
3919            // No need to parse, as jQuery has already done it for us
3920
3921            $('.custom-carousel-js-' + token).slick({
3922                rtl: houzez_rtl,
3923                lazyLoad: 'ondemand',
3924                autoplay: carouselSettings.slide_auto === 'true',
3925                autoplaySpeed: parseInt(carouselSettings.auto_speed) || 3000,
3926                infinite: carouselSettings.slide_infinite === 'true',
3927                speed: 500,
3928                slidesToShow: parseInt(carouselSettings.slides_to_show) || 3,
3929                slidesToScroll: parseInt(carouselSettings.slides_to_scroll) || 1,
3930                arrows: carouselSettings.navigation === 'true',
3931                adaptiveHeight: true,
3932                dots: carouselSettings.slide_dots === 'true',
3933                appendArrows: '.custom-carousel-js-wrap-' + token,
3934                prevArrow: $('.slick-prev-js-' + token),
3935                nextArrow: $('.slick-next-js-' + token),
3936                responsive: [{
3937                    breakpoint: 992,
3938                    settings: {
3939                        slidesToShow: 2,
3940                        slidesToScroll: 1
3941                    }
3942                }, {
3943                    breakpoint: 769,
3944                    settings: {
3945                        slidesToShow: 1,
3946                        slidesToScroll: 1
3947                    }
3948                }]
3949            });
3950        });
3951    }
3952    
3953    /* ------------------------------------------------------------------------ */
3954    /*  partners slider
3955    /* ------------------------------------------------------------------------ */
3956    var partners_carousel = $('.partners-slider-wrap');
3957    if( partners_carousel.length > 0 ) {
3958        partners_carousel.slick({
3959            rtl: houzez_rtl,
3960            lazyLoad: 'ondemand',
3961            infinite: true,
3962            speed: 300,
3963            slidesToShow: 4,
3964            arrows: true,
3965            adaptiveHeight: true,
3966            dots: true,
3967            appendArrows: '.partners-module-slider',
3968            prevArrow: $('.partner-prev-js'),
3969            nextArrow: $('.partner-next-js'),
3970            responsive: [{
3971                    breakpoint: 992,
3972                    settings: {
3973                        slidesToShow: 2,
3974                        slidesToScroll: 2
3975                    }
3976                },
3977                {
3978                    breakpoint: 769,
3979                    settings: {
3980                        slidesToShow: 1,
3981                        slidesToScroll: 1
3982                    }
3983                }
3984            ]
3985        });
3986    }
3987
3988    /* ------------------------------------------------------------------------ */
3989    /*  Schedule your dates
3990    /* ------------------------------------------------------------------------ */
3991    var schedule_tour_day = $('.property-schedule-tour-day-form-slide-v2');
3992    if( schedule_tour_day.length > 0 ) {
3993        schedule_tour_day.slick({
3994            rtl: houzez_rtl,
3995            lazyLoad: 'ondemand',
3996            infinite: false,
3997            speed: 300,
3998            slidesToShow: 3,
3999            slidesToScroll: 3,
4000            arrows: true,
4001            adaptiveHeight: false,
4002            dots: false,
4003            prevArrow: $('.tour-day-form-slide-arrow.sche-tabs-prev-js'),
4004            nextArrow: $('.tour-day-form-slide-arrow.sche-tabs-next-js'),
4005            responsive: [{
4006                    breakpoint: 992,
4007                    settings: {
4008                        slidesToShow: 3,
4009                        slidesToScroll: 3
4010                    }
4011                },
4012                {
4013                    breakpoint: 769,
4014                    settings: {
4015                        slidesToShow: 3,
4016                        slidesToScroll: 3
4017                    }
4018                }
4019            ]
4020        });
4021    }
4022
4023    var schedule_tour_day2 = $('.property-schedule-tour-day-form-slide-v2-bottom');
4024    if( schedule_tour_day2.length > 0 ) {
4025        schedule_tour_day2.slick({
4026            rtl: houzez_rtl,
4027            lazyLoad: 'ondemand',
4028            infinite: false,
4029            speed: 300,
4030            slidesToShow: 4,
4031            slidesToScroll: 4,
4032            arrows: true,
4033            adaptiveHeight: false,
4034            dots: false,
4035            prevArrow: $('.tour-day-form-slide-arrow.sche-prev-js'),
4036            nextArrow: $('.tour-day-form-slide-arrow.sche-next-js'),
4037            responsive: [{
4038                    breakpoint: 992,
4039                    settings: {
4040                        slidesToShow: 4,
4041                        slidesToScroll: 4
4042                    }
4043                },
4044                {
4045                    breakpoint: 769,
4046                    settings: {
4047                        slidesToShow: 3,
4048                        slidesToScroll: 3
4049                    }
4050                }
4051            ]
4052        });
4053    }
4054    
4055    
4056    /* ------------------------------------------------------------------------ */
4057    /*  featured property widget
4058    /* ------------------------------------------------------------------------ */
4059    var widget_featured_carousel = $('.widget-featured-property-slider');
4060    if( widget_featured_carousel.length > 0 ) {
4061        widget_featured_carousel.slick({
4062            rtl: houzez_rtl,
4063            speed: 300,
4064            slidesToShow: 1,
4065            arrows: true,
4066            adaptiveHeight: true,
4067            dots: true,
4068            responsive: [{
4069                    breakpoint: 992,
4070                    settings: {
4071                        slidesToShow: 1,
4072                        slidesToScroll: 1
4073                    }
4074                },
4075                {
4076                    breakpoint: 769,
4077                    settings: {
4078                        slidesToShow: 1,
4079                        slidesToScroll: 1
4080                    }
4081                }
4082            ]
4083        });
4084    }
4085
4086
4087    /* ------------------------------------------------------------------------ */
4088    /*  half maps listing layout 
4089    /* ------------------------------------------------------------------------ */
4090    // function homy_half_map_switch_listing_layout() {
4091    //     if ($(window).width() < 1200) {
4092    //         $('.half-map-wrap .listing-view').removeClass('list-view').addClass('grid-view');
4093    //     } else if ($(window).width() > 1200) {
4094    //         $('.half-map-wrap .listing-view').removeClass('grid-view').addClass('list-view');
4095    //     }
4096    // }
4097    // if(houzez_vars.halfmap_layout == 'list-view') {
4098    //     homy_half_map_switch_listing_layout();
4099    //     $win.on('resize', function () {
4100    //         homy_half_map_switch_listing_layout();
4101    //     });
4102    //     $win.bind('load', function () {
4103    //         homy_half_map_switch_listing_layout();
4104    //     });
4105    // }
4106
4107    /* ------------------------------------------------------------------------ */
4108    /*  property lightbox
4109    /* ------------------------------------------------------------------------ */
4110    $(document).ready(function () {
4111        $('.btn-expand').click(function () {
4112            $('.lightbox-gallery-wrap').toggleClass("lightbox-gallery-full-wrap");
4113            $('#lightbox-slider-js').slick('refresh');
4114        });
4115        $('.btn-email').click(function () {
4116            $('.lightbox-form-wrap').toggleClass("lightbox-form-wrap-show");
4117        });
4118    });
4119
4120    /* ------------------------------------------------------------------------ */
4121    /*  property navigation
4122    /* ------------------------------------------------------------------------ */
4123    var houzez_listing_nav = $('.property-navigation-wrap');
4124    
4125    if( houzez_listing_nav.length > 0 ) {
4126        $(document).scroll(function() {
4127            var y = $(this).scrollTop();
4128
4129            houzez_listing_nav.css('top', houzezStickyTop);
4130            if (y > 300) {
4131                houzez_listing_nav.fadeIn(250);
4132            } else {
4133                houzez_listing_nav.fadeOut(0);
4134            }
4135        });
4136
4137        $(".property-navigation-item a.target").click(function (event) {
4138            event.preventDefault();
4139            $("html, body").animate({
4140                scrollTop: $($(this).attr("href")).offset().top - 84
4141            }, 500);
4142        });
4143
4144        $(window).on('scroll', function () {
4145            $('.property-section-wrap').each(function () {
4146                if ($(window).scrollTop() >= $(this).offset().top - 86) {
4147                    var id = $(this).attr('id');
4148                    $('.target').removeClass('active');
4149                    $('.target[href="#' + id + '"]').addClass('active');
4150                } else if ($(window).scrollTop() <= 0) {
4151                    $('.target').removeClass('active');
4152                }
4153            });
4154        });
4155    }
4156
4157    /* ------------------------------------------------------------------------ */
4158    /*  availability calendar cells height
4159    /* ------------------------------------------------------------------------ */
4160    function setCalendarCellHeight() {
4161        var calendarCellWidth = $('.block-availability-calendars .search-calendar li').innerWidth();
4162        $('.block-availability-calendars .search-calendar li').css('height', calendarCellWidth);
4163        $('.block-availability-calendars .search-calendar li').css('line-height', calendarCellWidth + 'px');
4164    }
4165    setCalendarCellHeight();
4166    $win.on('resize', function () {
4167        setCalendarCellHeight();
4168    });
4169
4170    /* ------------------------------------------------------------------------ */
4171    /* login and register links
4172    /* ------------------------------------------------------------------------ */
4173    $('.login-link a').on('click', function () {
4174        $('.modal-toggle-1').addClass("active");
4175        $('.modal-toggle-2').removeClass("active");
4176        $('.register-form-tab').removeClass("active").removeClass("show");
4177        $('.login-form-tab').addClass("active").addClass("show");
4178    });
4179    $('.register-link a').click(function () {
4180        $('.modal-toggle-2').addClass("active");
4181        $('.modal-toggle-1').removeClass("active");
4182        $('.register-form-tab').addClass("active").addClass("show");
4183        $('.login-form-tab').removeClass("active").removeClass("show");
4184    });
4185    
4186    /* ------------------------------------------------------------------------ */
4187    /* datepicker
4188    /* ------------------------------------------------------------------------ */
4189    if($('.db_input_date').length > 0) { 
4190        $('.db_input_date').datepicker({
4191            format : "yyyy-mm-dd",
4192            clearBtn: true,
4193            autoclose: true,
4194            language:
4194 houzez_date_language
4195        });
4196    }
4197
4198    
4199    /* ------------------------------------------------------------------------ */
4200    /* custom scroll bars
4201    /* ------------------------------------------------------------------------ */
4202    if (houzez_is_mobile) {
4203        //console.log('You are using a mobile device!');
4204    } else {
4205
4206        if( $('.deals-table-wrap').length > 0 ) {
4207            $('.deals-table-wrap').overlayScrollbars({
4208                overflowBehavior: {
4209                    x: "scroll",
4210                    y: "scroll"
4211                },
4212            });
4213        }
4214
4215    }
4216
4217    /* ------------------------------------------------------------------------ */
4218    /*  sticky search bar
4219    /* ------------------------------------------------------------------------ */
4220    var listing_nav_area_height = $('.property-navigation-wrap').innerHeight();
4221    if( listing_nav_area_height == null ) {
4222        listing_nav_area_height = 0;
4223    }
4224    if( $('.houzez_sticky').length > 0 ) {
4225        $('.houzez_sticky').theiaStickySidebar({
4226            additionalMarginTop: houzezStickyTop + advanced_search_nav_height + listing_nav_area_height,
4227            minWidth: 768,
4228            updateSidebarHeight: false
4229        });
4230    }
4231    
4232
4233    /* ------------------------------------------------------------------------ */
4234    /* masonry blog
4235    /* ------------------------------------------------------------------------ */
4236    
4237    /**
4238     * Set appropriate spanning to any masonry item
4239     *
4240     * Get different properties we already set for the masonry, calculate 
4241     * height or spanning for any cell of the masonry grid based on its 
4242     * content-wrapper's height, the (row) gap of the grid, and the size 
4243     * of the implicit row tracks.
4244     *
4245     * @param item Object A brick/tile/cell inside the masonry
4246     */
4247    function resizeMasonryItem(item) {
4248        /* Get the grid object, its row-gap, and the size of its implicit rows */
4249        var grid = document.getElementsByClassName('masonry')[0],
4250            rowGap = parseInt(window.getComputedStyle(grid).getPropertyValue('grid-row-gap')),
4251            rowHeight = parseInt(window.getComputedStyle(grid).getPropertyValue('grid-auto-rows'));
4252
4253        /*
4254         * Spanning for any brick = S
4255         * Grid's row-gap = G
4256         * Size of grid's implicitly create row-track = R
4257         * Height of item content = H
4258         * Net height of the item = H1 = H + G
4259         * Net height of the implicit row-track = T = G + R
4260         * S = H1 / T
4261         */
4262        var rowSpan = Math.ceil((item.querySelector('.masonry-content').getBoundingClientRect().height + rowGap) / (rowHeight + rowGap));
4263
4264        /* Set the spanning as calculated above (S) */
4265        item.style.gridRowEnd = 'span ' + rowSpan;
4266    }
4267
4268    /**
4269     * Apply spanning to all the masonry items
4270     *
4271     * Loop through all the items and apply the spanning to them using 
4272     * `resizeMasonryItem()` function.
4273     *
4274     * @uses resizeMasonryItem
4275     */
4276    function resizeAllMasonryItems() {
4277        // Get all item class objects in one list
4278        var allItems = document.getElementsByClassName('masonry-brick');
4279
4280        /*
4281         * Loop through the above list and execute the spanning function to
4282         * each list-item (i.e. each masonry item)
4283         */
4284        for (var i = 0; i > allItems.length; i++) {
4285            resizeMasonryItem(allItems[i]);
4286        }
4287    }
4288
4289    /**
4290     * Resize the items when all the images inside the masonry grid 
4291     * finish loading. This will ensure that all the content inside our
4292     * masonry items is visible.
4293     *
4294     * @uses ImagesLoaded
4295     * @uses resizeMasonryItem
4296     */
4297
4298    if( $('.page-template-blog-masonry').length > 0 ) { 
4299        var waitForImages = function() {
4300            var allItems = document.getElementsByClassName('masonry-brick');
4301            for (var i = 0; i < allItems.length; i++) {
4302                imagesLoaded(allItems[i], function (instance) {
4303                    var item = instance.elements[0];
4304                    resizeMasonryItem(item);
4305                });
4306            }
4307        }
4308
4309        /* Resize all the grid items on the load and resize events */
4310        var masonryEvents = ['load', 'resize'];
4311        masonryEvents.forEach(function (event) {
4312            window.addEventListener(event, resizeAllMasonryItems);
4313        });
4314
4315        /* Do a resize once more when all the images finish loading */
4316        waitForImages();
4317    }
4318
4319    /* ------------------------------------------------------------------------ */
4320    /*  splash page slider 
4321    /* ------------------------------------------------------------------------ */
4322    var splash_slider_wrap = $('.splash-slider-wrap');
4323    if(splash_slider_wrap.length > 0) {
4324        splash_slider_wrap.slick({
4325            rtl: houzez_rtl,
4326            lazyLoad: 'ondemand',
4327            adaptiveHeight: true,
4328            autoplay: true,
4329            infinite: true,
4330            speed: 300,
4331            fade: true,
4332            slidesToShow: 1,
4333            arrows: false,
4334        });
4335    }
4336
4337    /*--------------------------------------------------------------------------
4338     *   Add or remove favorites
4339     * -------------------------------------------------------------------------*/
4340    houzez_init_add_favorite(ajaxurl, userID);
4341    houzez_init_remove_favorite(ajaxurl, userID);
4342    houzez_check_favourites(userID);
4343
4344    /* ------------------------------------------------------------------------ */
4345    /*  GET WINDOWS WIDTH HEIGHT
4346     /* ------------------------------------------------------------------------ */
4347    function getWindowWidth() {
4348        return Math.max( $(window).width(), window.innerWidth);
4349    }
4350
4351    function getWindowHeight() {
4352        return Math.max( $(window).height(), window.innerHeight);
4353    }
4354
4355    /* ------------------------------------------------------------------------ */
4356    /* WooCommerce Pay
4357    /* ------------------------------------------------------------------------ */
4358    $('.houzez-woocommerce-pay').on('click', function(e) {
4359        e.preventDefault();
4360
4361        let listID = $(this).data('listid');
4362        let is_featured = $(this).data('featured');
4363
4364        fave_processing_modal( processing_text );
4365
4366        $.ajax({
4367            type: 'POST',
4368            url: ajaxurl,
4369            data: {
4370                'action': 'houzez_perlist_woo_pay',
4371                'listing_id': listID,
4372                'is_featured': is_featured,
4373            },
4374            success: function(data) { 
4375                if ( data.success != false ) {
4376                    window.location.href= houzez_vars.woo_checkout_url;
4377                } else {
4378                    jQuery('#fave_modal').modal('hide');
4379                }
4380            },
4381            error: function(errorThrown) {
4382
4383            }
4384        }); // $.ajax
4385
4386    });
4387
4388    /* ------------------------------------------------------------------------ */
4389    /* WooCommerce Pay Package
4390    /* ------------------------------------------------------------------------ */
4391    $('.houzez-woocommerce-package').on('click', function(e) {
4392        e.preventDefault();
4393
4394        if( parseInt( userID, 10 ) === 0 || userID == undefined) {
4395            
4396            jQuery('#login-register-form').modal('show');
4397            jQuery('.login-form-tab').addClass('active show');
4398            jQuery('.modal-toggle-1.nav-link').addClass('active');
4399
4400        } else {
4401            let packid = $(this).data('packid');
4402
4403            fave_processing_modal( processing_text );
4404
4405            $.ajax({
4406                type: 'POST',
4407                url: ajaxurl,
4408                data: {
4409                    'action': 'houzez_woo_pay_package',
4410                    'package_id': packid
4411                },
4412                success: function(data) { 
4413                    if ( data.success != false ) {
4414                        window.location.href= houzez_vars.woo_checkout_url;
4415                    } else {
4416                        jQuery('#fave_modal').modal('hide');
4417                    }
4418                },
4419                error: function(errorThrown) {
4420
4421                }
4422            }); // $.ajax
4423
4424        } // login
4425
4426    });
4427
4428    /* ------------------------------------------------------------------------ */
4429    /* Top Banner Full Screen
4430    /* ------------------------------------------------------------------------ */
4431    var setTopBannerFullScreen = function() {
4432        var totalTopBarsHeight = 0;
4433        var searchH = 0;
4434        var topBarH = 0;
4435        var totalBannerHeight = 0;
4436        var window_height = $(window).innerHeight();
4437        var admin_bar = $('#wpadminbar');
4438        var topBarB = $('.top-bar-wrap');
4439        var admin_bar_height = admin_bar.outerHeight();
4440        searchH = (window_height-header_area_height);  
4441
4442        if( header_area.hasClass('header-transparent-wrap') ) {
4443            if( topBarB.length ) {
4444                topBarH = topBarB.outerHeight();
4445            }
4446            totalBannerHeight =  getWindowHeight() - (topBarH + admin_bar_height);
4447
4448        } else {
4449
4450            if( header_area.length && advanced_search_nav.length && !advanced_search_nav.hasClass('search-hidden')) {
4451                totalTopBarsHeight = parseInt(header_area_height) + parseInt(advanced_search_nav_height);
4452
4453            } else if(header_area.length) {
4454                totalTopBarsHeight = parseInt(header_area_height);
4455
4456            }
4457            totalBannerHeight =  getWindowHeight() - (totalTopBarsHeight + admin_bar_height);
4458        }
4459
4460        $('.top-banner-wrap-fullscreen').css( 'height', totalBannerHeight );
4461    }
4462
4463    if( !houzez_is_splash && $('.top-banner-wrap-fullscreen').length > 0 ) {
4464        $(document).ready(function() {
4465            setTopBannerFullScreen();
4466        });
4467
4468        $(window).on('resize', function () {
4469            setTopBannerFullScreen();
4470        });
4471    }
4472
4473
4474    /* ------------------------------------------------------------------------ */
4475    /* compare Listings
4476    /* ------------------------------------------------------------------------ */
4477    $(document).ready(function() {    
4478        $('.compare-property-label').on('click', function() {
4479            $(this).toggleClass('active');
4480            $('.compare-property-active').addClass('compare-property-active-push-toleft' );
4481            $('#compare-property-panel').addClass('compare-property-panel-open');
4482        });
4483        $('.close-compare-panel').on('click', function() {
4484            $(this).toggleClass('active');
4485            $('.compare-property-active').removeClass('compare-property-active-push-toleft' );
4486            $('#compare-property-panel').removeClass('compare-property-panel-open');
4487        });
4488        var listings_compare = houzezGetCookie('houzez_compare_listings');
4489
4490        var limit_item_compare = 4;
4491        add_to_compare(compare_url, compare_add_icon, compare_remove_icon, add_compare_text, remove_compare_text, compare_limit, listings_compare, limit_item_compare );
4492        remove_from_compare(listings_compare, compare_add_icon, compare_remove_icon, add_compare_text, remove_compare_text);
4493
4494    });
4495
4496    /*--------------------------------------------------------------------------
4497     *   Compare for ajax
4498     * -------------------------------------------------------------------------*/
4499    function compare_for_ajax() {
4500        var listings_compare = houzezGetCookie('houzez_compare_listings');
4501        var limit_item_compare = 4;
4502        add_to_compare(compare_url, compare_add_icon, compare_remove_icon, add_compare_text, remove_compare_text, compare_limit, listings_compare, limit_item_compare );
4503        remove_from_compare(listings_compare, compare_add_icon, compare_remove_icon, add_compare_text, remove_compare_text);
4504    }
4505
4506    /*---------------------------------------------------------------------------
4507    * One Page push state
4508    * -------------------------------------------------------------------------*/
4509    $('.houzez-onepage-mode .header-main-wrap .main-nav li.nav-item a.nav-link').on( 'click', function(e) {
4510        
4511        var currentUrl = $(this).attr('href');
4512        window.history.pushState({houzezTheme: true}, '', currentUrl);
4513
4514    } );
4515
4516    /*---------------------------------------------------------------------------
4517    * Render compare data on page load
4518    * -------------------------------------------------------------------------*/
4519    houzez_render_compare_properties_data();
4520    function houzez_render_compare_properties_data() {
4521        let compare_listings = JSON.parse(localStorage.getItem('houzez_compare_listings'));
4522
4523        // Check if 'compare_listings' is not null and not empty before processing
4524        if (compare_listings && compare_listings.length > 0) {
4525            let properties_array = '';
4526            compare_listings.forEach(function(item) {
4527                let img = item.image; // Image URL from the local storage array
4528                let listingId = item.id; // Listing ID from the local storage array
4529                
4530                properties_array += '<div class="compare-item remove-' + listingId + '">' +
4531                    '<a href="#" class="remove-compare remove-icon" data-listing_id="' + listingId + '">' +
4532                    '<i class="houzez-icon icon-remove-circle"></i></a>' +
4533                    '<img class="img-fluid" src="' + img + '" width="200" height="150" alt="Thumb">' +
4534                    '</div>';
4535            });
4536
4537            jQuery('.compare-wrap').html(properties_array);
4538        }
4539    }
4540
4541
4542
4543})(jQuery);
4544
4545/* ------------------------------------------------------------------------ */
4546/*  houzez Cookie
4547/* ------------------------------------------------------------------------ */
4548function houzezSetCookie(cname, cvalue, exdays) {
4549    var d = new Date();
4550    d.setTime(d.getTime() + (exdays*24*60*60*1000));
4551    var expires = "expires="+ d.toUTCString();
4552    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
4553};
4554
4555function houzezGetCookie(cname) {
4556    var name = cname + "=";
4557    var decodedCookie = decodeURIComponent(document.cookie);
4558    var ca = decodedCookie.split(';');
4559    for(var i = 0; i <ca.length; i++) {
4560        var c = ca[i];
4561        while (c.charAt(0) == ' ') {
4562            c = c.substring(1);
4563        }
4564        if (c.indexOf(name) == 0) {
4565            return c.substring(name.length, c.length);
4566        }
4567    }
4568    return "";
4569};
4570
4571function fave_processing_modal( msg ) {
4572    var process_modal ='<div class="modal fade" id="fave_modal" tabindex="-1" role="dialog" aria-labelledby="faveModalLabel" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-body houzez_messages_modal">'+msg+'</div></div></div></div></div>';
4573    jQuery('body').append(process_modal);
4574    jQuery('#fave_modal').modal();
4575}
4576
4577function fave_processing_modal_close( ) {
4578    jQuery('#fave_modal').modal('hide');
4579}
4580
4581/*--------------------------------------------------------------------------
4582*   Listing Gallery 
4583* -------------------------------------------------------------------------*/
4584function houzez_grid_image_gallery() {
4585    if (houzez_vars.disable_property_gallery == 1) {
4586
4587        var gallery_behaviour = houzez_vars.grid_gallery_behaviour;
4588        var houzez_rtl = houzez_vars.houzez_rtl === 'yes';
4589
4590        jQuery('.hz-item-gallery-js').each(function () {
4591            var $this = jQuery(this);
4592            
4593            if (!$this.hasClass('houzez-gallery-loaded') && $this.data('images')) {
4594                var href = $this.find('a.listing-featured-thumb').attr('href');
4595                var link_target = $this.find('a.listing-featured-thumb').attr('target');
4596                var images = $this.data('images');
4597
4598                // Create document fragment for better performance
4599                var fragment = document.createDocumentFragment();
4600                var galleryWrap = document.createElement('div');
4601                galleryWrap.className = 'listing-gallery-wrap ' + gallery_behaviour;
4602                
4603                var carouselDiv = document.createElement('div');
4604                carouselDiv.className = 'houzez-listing-carousel';
4605                
4606                images.forEach(function (image) {
4607                    var itemDiv = document.createElement('div');
4608                    itemDiv.className = 'item';
4609                    
4610                    var anchor = document.createElement('a');
4611                    anchor.className = 'hover-effect';
4612                    anchor.href = href;
4613                    anchor.target = link_target;
4614                    
4615                    var img = document.createElement('img');
4616                    img.src = image.image;
4617                    img.alt = image.alt;
4618                    img.width = image.width;
4619                    img.height = image.height;
4620                    img.className = 'img-fluid';
4621                    
4622                    anchor.appendChild(img);
4623                    itemDiv.appendChild(anchor);
4624                    carouselDiv.appendChild(itemDiv);
4625                });
4626                
4627                galleryWrap.appendChild(carouselDiv);
4628                fragment.appendChild(galleryWrap);
4629                
4630                $this.find('.listing-image-wrap').html(fragment);
4631
4632                jQuery('.item-wrap-v6 .listing-gallery-wrap .item a').removeClass('hover-effect');
4633
4634                var listing_slider = $this.find('.houzez-listing-carousel');
4635                listing_slider.slick({
4636                    rtl: houzez_rtl,
4637                    autoplay: false,
4638                    lazyLoad: 'ondemand',
4639                    infinite: false,
4640                    speed: 300,
4641                    slidesToShow: 1,
4642                    arrows: true,
4643                    prevArrow: '<button type="button" class="slick-prev slick-arrow"></button>',
4644                    nextArrow: '<button type="button" class="slick-next slick-arrow"></button>',
4645                    adaptiveHeight: true
4646                });
4647
4648                is_listing_gallery_slider = true;
4649
4650                $this.addClass('houzez-gallery-loaded');
4651            }
4652        });
4653    }
4654
4655    // Use event delegation for dynamically added elements
4656    jQuery(document).on("click", '.switch-btn', function () {
4657        jQuery('.hz-item-gallery-js .houzez-listing-carousel').slick('refresh');
4658    });
4659}
4660
4661
4662/*--------------------------------------------------------------------------
4663*   Listing Preview
4664* -------------------------------------------------------------------------*/
4665function houzez_listing_lightbox(ajaxurl, processing_text, houzez_rtl, userID) {
4666        
4667    jQuery('.hz-show-lightbox-js').on('click', function() {
4668
4669        var listing_id = jQuery(this).data('listid');
4670        var $parents = jQuery(this).parents('.item-wrap');
4671        var preview_loader = $parents.find('.preview_loader');
4672
4673        jQuery.ajax({
4674            type: 'post',
4675            url: ajaxurl,
4676            data: {
4677                'action': 'load_lightbox_content',
4678                'listing_id': listing_id
4679            },
4680            beforeSend: function( ) {
4681                preview_loader.empty().append(''
4682                    +'<div class="houzez-overlay-loading">'
4683                    +'<div class="overlay-placeholder">'
4684                    +'<div class="loader-ripple spinner">'
4685                    +'<div class="bounce1"></div>'
4686                    +'<div class="bounce2"></div>'
4687                    +'<div class="bounce3"></div>'
4688                    +'</div>'
4689                    +'</div>'
4690                    +'</div>'
4691                );
4692            },
4693            complete: function(){
4694                preview_loader.empty();
4695            },
4696            success: function( response ) {
4697                
4698                jQuery('#hz-listing-model-content').html(response);
4699
4700                jQuery('#houzez-listing-lightbox').modal('show'); 
4701
4702                jQuery('.lightbox-slider').not('.slick-initialized').slick({
4703                    rtl: houzez_rtl,
4704                    lazyLoad: 'ondemand',
4705                    infinite: true,
4706                    speed: 300,
4707                    slidesToShow: 1,
4708                    arrows: true,
4709                    adaptiveHeight: true,
4710                });
4711
4712                jQuery('#houzez-listing-lightbox').on('shown.bs.modal', function (e) {
4713                    jQuery('.lightbox-slider').slick('setPosition');
4714                    jQuery('.lightbox-slider').slick('refresh');
4715                });
4716                
4717
4718                jQuery('.btn-expand').on('click', function () {
4719                    jQuery('.lightbox-gallery-wrap').toggleClass("lightbox-gallery-full-wrap");
4720                    jQuery('.lightbox-slider').slick('setPosition');
4721                    
4722                });
4723
4724                jQuery('.btn-email').on('click', function () {
4725                    jQuery('.lightbox-form-wrap').toggleClass("lightbox-form-wrap-show");
4726                });
4727
4728                houzez_init_add_favorite(ajaxurl, userID);
4729                houzez_init_remove_favorite(ajaxurl, userID);
4730
4731            },
4732            error: function(xhr, status, error) {
4733                var err = eval("(" + xhr.responseText + ")");
4734                console.log(err.Message);
4735            }
4736        })
4737
4738    });
4739}
4740
4741/*--------------------------------------------------------------------------
4742*   Add or remove favorites
4743* -------------------------------------------------------------------------*/
4744function houzez_init_add_favorite(ajaxurl, userID) {
4745    jQuery(".add-favorite-js").on('click', function (e) {
4746        e.preventDefault();
4747        var curnt = jQuery(this);
4748        var listID = jQuery(this).attr('data-listid');
4749        add_to_favorite( ajaxurl, listID, curnt, userID );
4750        return false;
4751    });
4752}
4753
4754function houzez_init_remove_favorite(ajaxurl, userID) {
4755    jQuery(".remove_fav").on('click', function () {
4756        var curnt = jQuery(this);
4757        var listID = jQuery(this).attr('data-listid');
4758        add_to_favorite( ajaxurl, listID, curnt, userID );
4759        var itemWrap = curnt.parents('tr').remove();
4760    });
4761}
4762
4763function add_to_favorite( ajaxurl, listID, curnt, userID ) {
4764    if( parseInt( userID, 10 ) === 0 || userID == undefined) {
4765        
4766        var add_to_favorite_login_required = houzez_vars.add_to_favorite_login_required;
4767        
4768        if ( add_to_favorite_login_required != 0 ) {
4769            jQuery('.register-form-tab').removeClass('active show');
4770            jQuery('.modal-toggle-2.nav-link').removeClass('active');
4771            jQuery('#login-register-form').modal('show');
4772            jQuery('.login-form-tab').addClass('active show');
4773            jQuery('.modal-toggle-1.nav-link').addClass('active');
4774        } else {
4775            add_to_favorite_without_login(curnt);
4776        }
4777        
4778    } else {
4779        var $parents = curnt.parents('.item-wrap');
4780        var preview_loader = $parents.find('.preview_loader');
4781
4782        jQuery.ajax({
4783            type: 'post',
4784            url: ajaxurl,
4785            dataType: 'json',
4786            data: {
4787                'action': 'houzez_add_to_favorite',
4788                'listing_id': listID
4789            },
4790            beforeSend: function( ) {
4791                preview_loader.empty().append(''
4792                    +'<div class="houzez-overlay-loading">'
4793                    +'<div class="overlay-placeholder">'
4794                    +'<div class="loader-ripple spinner">'
4795                    +'<div class="bounce1"></div>'
4796                    +'<div class="bounce2"></div>'
4797                    +'<div class="bounce3"></div>'
4798                    +'</div>'
4799                    +'</div>'
4800                    +'</div>'
4801                );
4802            },
4803            complete: function(){
4804                preview_loader.empty();
4805            },
4806            success: function( data ) {
4807                if( data.added ) {
4808                    curnt.children('i').addClass('text-danger');
4809                } else {
4810                    curnt.children('i').removeClass('text-danger');
4811                }
4812                preview_loader.empty();
4813            },
4814            complete: function(){
4815
4816            },
4817            error: function(xhr, status, error) {
4818                var err = eval("(" + xhr.responseText + ")");
4819                console.log(err.Message);
4820            }
4821        });
4822    } // End else
4823}
4824
4825// Add to Favourite without login
4826function add_to_favorite_without_login(curnt) {
4827    
4828    var listings_favorite = houzezGetCookie('houzez_favorite_listings');
4829
4830    if ( listings_favorite && listings_favorite.length ) {
4831        listings_favorite = listings_favorite.split(',');
4832    } else {
4833        listings_favorite = [];
4834    }
4835
4836    var listing_id  = curnt.data('listid');
4837    var index       = listings_favorite.indexOf( listing_id.toString() );
4838
4839    if ( index == -1 ) {  
4840        listings_favorite.push(listing_id.toString());
4841        houzezSetCookie('houzez_favorite_listings', listings_favorite.join(','), 30);
4842        
4843        jQuery("span.frvt-count").html("");
4844        jQuery("span.frvt-count").html(listings_favorite.length);
4845
4846        for (var i = 0 ; i < listings_favorite.length; i++) {
4847            jQuery('.add-favorite-js[data-listid="' + listings_favorite[i] + '"] i').addClass("text-danger");
4848            jQuery('.add-favorite-js[data-listid="' + listings_favorite[i] + '"]').addClass('remove-favorite');
4849        }
4850        
4851    } else {
4852        listings_favorite.splice(index, 1);
4853        houzezSetCookie('houzez_favorite_listings', listings_favorite.join(','), 30);
4854        jQuery("span.frvt-count").html("")
4855        jQuery("span.frvt-count").html(listings_favorite.length);
4856        jQuery('.add-favorite-js[data-listid="' + listing_id.toString() + '"] i').removeClass("text-danger");
4857        jQuery('.add-favorite-js[data-listid="' + listing_id.toString() + '"]').removeClass("remove-favorite");
4858    }
4859
4860    jQuery('a.favorite-btn').attr('href', houzez_vars.favorite_url + '?ids=' + listings_favorite);
4861
4862    return false;  
4863
4864}
4865
4866function houzez_check_favourites( userID ) {
4867    
4868    if( parseInt( userID, 10 ) === 0 || userID == undefined) {
4869        var listings_favorite = houzezGetCookie('houzez_favorite_listings');
4870
4871        jQuery('a.favorite-btn').attr('href', houzez_vars.favorite_url + '?ids=' + listings_favorite);
4872
4873        if ( listings_favorite && listings_favorite.length ) {
4874            listings_favorite = listings_favorite.split(',');
4875            
4876            if ( listings_favorite.length ) {
4877                for (var i = 0 ; i < listings_favorite.length; i++) {
4878                    jQuery('.add-favorite-js[data-listid="' + listings_favorite[i] + '"] i').addClass("text-danger");
4879                    jQuery('.add-favorite-js[data-listid="' + listings_favorite[i] + '"]').addClass('remove-favorite');
4880                }
4881
4882                jQuery("span.frvt-count").html("");
4883                jQuery("span.frvt-count").html(listings_favorite.length);
4884            }
4885        } else {
4886            listings_favorite = [];
4887        }
4888    }
4889}
4890
4891function add_to_compare(compare_url, compare_add_icon, compare_remove_icon, add_compare_text, remove_compare_text, compare_limit, listings_compare, limit_item_compare) {
4892    var storedData = localStorage.getItem('houzez_compare_listings');
4893    var listings_compare = storedData ? JSON.parse(storedData) : [];
4894
4895    jQuery('a.compare-btn').attr('href', compare_url + '?ids=' + listings_compare.map(item => item.id).join(','));
4896
4897    if (listings_compare.length > 0) {
4898        jQuery('.compare-property-label').fadeIn(1000);
4899    }
4900
4901    if(listings_compare.length){
4902        for(var i = 0 ; i < listings_compare.length; i++) {
4903            jQuery( '.houzez_compare[data-listing_id="'+listings_compare[i].id+'"] i').removeClass('icon-add-circle').addClass('icon-subtract-circle');
4904            jQuery( '.houzez_compare[data-listing_id="'+listings_compare[i].id+'"]').attr('title', remove_compare_text);
4905            jQuery( '.houzez_compare[data-listing_id="'+listings_compare[i].id+'"]').tooltip('hide').attr('data-original-title', remove_compare_text);
4906        }
4907        jQuery('.compare-property-label').find('.compare-count').html(listings_compare.length);
4908    }
4909    
4910    jQuery('.houzez_compare').on('click', function(e) {
4911        e.preventDefault();
4912
4913        var storedData = localStorage.getItem('houzez_compare_listings');
4914        var listings_compare = storedData ? JSON.parse(storedData) : [];
4915
4916        var listing_id = jQuery(this).data('listing_id');
4917        var index = listings_compare.findIndex(item => item.id === listing_id.toString());
4918        var image_div = jQuery(this).parents('.item-wrap');
4919        var thumb_url = image_div.find('img').attr('src');
4920
4921        if(index == -1){
4922            if(listings_compare.length >= limit_item_compare){
4923                alert(compare_limit);
4924            }else{
4925                jQuery('.compare-wrap').append('<div class="compare-item remove-'+listing_id+'"><a href="" class="remove-compare remove-icon" data-listing_id="'+listing_id+'"><i class="houzez-icon icon-remove-circle"></i></a><img class="img-fluid" src="'+thumb_url+'" width="200" height="150" alt="Thumb"></div>');
4926
4927                listings_compare.push({id: listing_id.toString(), image: thumb_url});
4928                localStorage.setItem('houzez_compare_listings', JSON.stringify(listings_compare));
4929                jQuery(this).attr('title', remove_compare_text);
4930                jQuery(this).find('i').removeClass('icon-add-circle').addClass('icon-subtract-circle');
4931                jQuery('.compare-property-label').find('.compare-count').html(listings_compare.length);
4932                jQuery('a.compare-btn').attr('href', compare_url + '?ids=' + listings_compare.map(item => item.id).join(','));
4933                jQuery('.compare-property-label').fadeIn(1000);
4934                jQuery(this).toggleClass('active');
4935                jQuery('.compare-property-active').addClass('compare-property-active-push-toleft');
4936                jQuery('#compare-property-panel').addClass('compare-property-panel-open');
4937                jQuery(this).tooltip('dispose').tooltip('show');
4938                remove_from_compare(listings_compare, compare_add_icon, compare_remove_icon, add_compare_text, remove_compare_text);
4939            }
4940        } else {
4941            jQuery('div.remove-'+listing_id).remove();
4942            jQuery(this).attr('title', add_compare_text);
4943            jQuery(this).find('i').removeClass('icon-subtract-circle').addClass('icon-add-circle');
4944            listings_compare.splice(index, 1);
4945            localStorage.setItem('houzez_compare_listings', JSON.stringify(listings_compare));
4946            jQuery('.compare-property-label').find('.compare-count').html(listings_compare.length);
4947            jQuery('a.compare-btn').attr('href', compare_url + '?ids=' + listings_compare.map(item => item.id).join(','));
4948            jQuery(this).tooltip('dispose').tooltip('show');
4949
4950            if (listings_compare.length > 0) {
4951                jQuery('.compare-property-label').fadeIn(1000);
4952                jQuery(this).toggleClass('active');
4953                jQuery('.compare-property-active').addClass('compare-property-active-push-toleft');
4954                jQuery('#compare-property-panel').addClass('compare-property-panel-open');
4955            } else {
4956                jQuery('.compare-property-label').fadeOut(1000);
4957            }
4958        }
4959        return false;
4960    });
4961}
4962
4963function remove_from_compare(listings_compare, compare_add_icon, compare_remove_icon, add_compare_text, remove_compare_text) {
4964    // Moved the event binding outside of this function to prevent multiple bindings
4965    // This should be called once, outside and independently from this function
4966    jQuery('.remove-compare').off('click').on('click', function(e) {
4967        e.preventDefault();
4968        var compare_url = houzez_vars.compare_url; // Ensure houzez_vars is globally available
4969        var storedData = localStorage.getItem('houzez_compare_listings');
4970        listings_compare = storedData ? JSON.parse(storedData) : [];
4971
4972        var listing_id = jQuery(this).data('listing_id');
4973        var index = listings_compare.findIndex(item => item.id === listing_id.toString());
4974        
4975        if (index !== -1) { // Only proceed if the item was found
4976            listings_compare.splice(index, 1);
4977            localStorage.setItem('houzez_compare_listings', JSON.stringify(listings_compare));
4978            
4979            jQuery('.compare-property-label').find('.compare-count').html(listings_compare.length);
4980
4981            // Update UI elements if they exist
4982            var compareElement = jQuery('.compare-' + listing_id);
4983            if (compareElement.length) {
4984                compareElement.attr('title', add_compare_text);
4985                compareElement.tooltip('hide').attr('data-original-title', add_compare_text);
4986                compareElement.find('i').removeClass('icon-subtract-circle').addClass('icon-add-circle');
4987            }
4988            
4989            jQuery(this).parents('.compare-item').remove();
4990
4991            // Update the compare URL
4992            jQuery('a.compare-btn').attr('href', compare_url + '?ids=' + listings_compare.map(item => item.id).join(','));
4993        }
4994    });
4995}
4996
4997
4998
4999/* ------------------------------------------------------------------------ */
5000/*  mobile popup js
5001/* ------------------------------------------------------------------------ */
5002
5003function houzez_grid_call_to_action() {
5004    jQuery('.hz-call-popup-js').on('click', function() {
5005        var call_model_id = jQuery(this).data('model-id');
5006        jQuery('#'+call_model_id).appendTo("body");
5007        jQuery('#'+call_model_id).modal("show");
5008
5009    });
5010
5011    jQuery('.hz-email-popup-js').on('click', function() {
5012        var email_model_id = jQuery(this).data('model-id');
5013        jQuery('#'+email_model_id).appendTo("body");
5014        jQuery('#'+email_model_id).modal("show");
5015
5016    });
5017}
5018

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.