PageSourceSearch

https://www.ukboardingschools.com/wp-content/themes/ukbs-child/js/custom.js?ver=2.3.8

js ukboardingschools.com collected 2026-09-24 23:50:12 UTC 158,174 bytes, 3,946 lines download raw bytes

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

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.