PageSourceSearch

https://neworleanscondos.net/wp-content/themes/houzez/js/custom.js?ver=2.8.4.1

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

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.