PageSourceSearch

https://americanproperties.net/wp-content/themes/wpresidence/js/ajaxcalls.js?ver=1.0

js americanproperties.net collected 2026-09-29 11:36:44 UTC 88,064 bytes, 2,424 lines download raw bytes

1/*global $, jQuery, ajaxcalls_vars, document, control_vars, window, control_vars,Modernizr,mapfunctions_vars,wpestate_open_menu,grecaptcha,wpestate_show_no_results,wpestate_load_on_demand_pins,get_custom_value,wpestate_enable_half_map_pin_action,wpestate_lazy_load_carousel_property_unit,Chart,widgetId1,widgetId2,widgetId3,widgetId4,wpestate_get_custom_value_tab_search*/
2///////////////////////////////////////////////////////////////////////////////////////////
3
4function wpestate_load_stats_tabs(listing_id) {
5    "use strict";
6    var ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
7    var nonce = jQuery('#wpestate_tab_stats').val();
8    jQuery.ajax({
9        type: 'POST',
10        url: ajaxurl,
11        dataType: 'json',
12        data: {
13            'action': 'wpestate_load_stats_property',
14            'postid': listing_id,
15            'security': nonce,
16        },
17        success: function (data) {
18            wpestate_show_prop_stat_graph_tab(data.array_values, data.labels, listing_id);
19        },
20        error: function (errorThrown) {}
21    });//end ajax
22}
23
24
25
26function wpestate_show_prop_stat_graph_tab(values, labels, listing_id) {
27    if (!document.getElementById('myChart')) {
28        return;
29    }
30
31    var ctx = jQuery("#myChart").get(0).getContext("2d");
32    var myNewChart = new Chart(ctx);
33    // var labels      =   '';
34    var traffic_data = '  ';
35
36    // labels          =   jQuery.parseJSON ( wpestate_property_vars.singular_label);
37    traffic_data = values;
38
39    var data = {
40        labels: labels,
41        datasets: [
42            {
43                label: ajaxcalls_vars.property_views,
44                fillColor: "rgba(220,220,220,0.5)",
45                strokeColor: "rgba(220,220,220,0.8)",
46                highlightFill: "rgba(220,220,220,0.75)",
47                highlightStroke: "rgba(220,220,220,1)",
48                data: traffic_data
49            },
50        ]
51    };
52
53    var options = {
54        title: 'page views',
55        //Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
56        scaleBeginAtZero: true,
57
58        //Boolean - Whether grid lines are shown across the chart
59        scaleShowGridLines: true,
60
61        //String - Colour of the grid lines
62        scaleGridLineColor: "rgba(0,0,0,.05)",
63
64        //Number - Width of the grid lines
65        scaleGridLineWidth: 1,
66
67        //Boolean - Whether to show horizontal lines (except X axis)
68        scaleShowHorizontalLines: true,
69
70        //Boolean - Whether to show vertical lines (except Y axis)
71        scaleShowVerticalLines: true,
72
73        //Boolean - If there is a stroke on each bar
74        barShowStroke: true,
75
76        //Number - Pixel width of the bar stroke
77        barStrokeWidth: 2,
78
79        //Number - Spacing between each of the X value sets
80        barValueSpacing: 5,
81
82        //Number - Spacing between data sets within X values
83        barDatasetSpacing: 1,
84
85        //String - A legend template
86        legendTemplate: "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].fillColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
87
88    };
89
90    // var myBarChart = new Chart(ctx).Bar(data, options);
91    var myBarChart = new Chart(ctx, {
92        type: 'bar',
93        data: data,
94        options: options
95    });
96}
97
98
99
100function wpestate_load_stats(listing_id) {
101    "use strict";
102    var ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
103    var nonce = jQuery('#wpestate_tab_stats').val();
104
105    jQuery.ajax({
106        type: 'POST',
107        url: ajaxurl,
108        dataType: 'json',
109        data: {
110            'action': 'wpestate_load_stats_property',
111            'postid': listing_id,
112            'security': nonce,
113        },
114        success: function (data) {
115            wpestate_show_prop_stat_graph(data.array_values, data.labels, listing_id);
116        },
117        error: function (errorThrown) {}
118    });//end ajax
119}
120
121function wpestate_show_prop_stat_graph(values, labels, listing_id) {
122    "use strict";
123
124    var ctx = jQuery("#myChart_" + listing_id).get(0).getContext('2d');
125    var myNewChart = new Chart(ctx);
126    var data = {
127        labels: labels,
128        datasets: [
129            {
130                label: ajaxcalls_vars.property_views,
131                fillColor: "rgba(220,220,220,0.5)",
132                strokeColor: "rgba(220,220,220,0.8)",
133                highlightFill: "rgba(220,220,220,0.75)",
134                highlightStroke: "rgba(220,220,220,1)",
135                data: values
136            },
137        ]
138    };
139
140    var options = {
141        scaleBeginAtZero: true,
142        scaleShowGridLines: true,
143        scaleGridLineColor: "rgba(0,0,0,.05)",
144        scaleGridLineWidth: 1,
145        scaleShowHorizontalLines: true,
146        scaleShowVerticalLines: true,
147        barShowStroke: true,
148        barStrokeWidth: 2,
149        barValueSpacing: 5,
150        barDatasetSpacing: 1,
151        legendTemplate: "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].fillColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
152    };
153
154    // var myBarChart = new Chart(ctx).Bar(data, options);
155    var myBarChart = new Chart(ctx, {
156        type: 'bar',
157        data: data,
158        options: options
159    });
160}
161
162
163//////////////////////////////////////////////////////////////////////////////////////////////
164/// ajax filtering on header search ; jslint checked
165////////////////////////////////////////////////////////////////////////////////////////////
166function wpestate_start_filtering_ajax(newpage) {
167    "use strict";
168
169    var action, category, city, area, rooms, baths, min_price, price_max, ajaxurl, postid, halfmap, all_checkers;
170    action = jQuery('#adv_actions').attr('data-value');
171    category = jQuery('#adv_categ').attr('data-value');
172    city = jQuery('#advanced_city').attr('data-value');
173    area = jQuery('#advanced_area').attr('data-value');
174    rooms = parseFloat(jQuery('#adv_rooms').val(), 10);
175    baths = parseFloat(jQuery('#adv_bath').val(), 10);
176    min_price = parseFloat(jQuery('#price_low').val(), 10);
177    price_max = parseFloat(jQuery('#price_max').val(), 10);
178    postid = parseFloat(jQuery('#adv-search-1').attr('data-postid'), 10);
179    ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
180    var order = jQuery('#a_filter_order').attr('data-value');
181    halfmap = 0;
182
183    var nonce = jQuery('#wpestate_ajax_filtering').val();
184
185    if (jQuery('#google_map_prop_list_sidebar').length) {
186        halfmap = 1;
187    }
188
189    postid = 1;
190    if (document.getElementById('search_wrapper')) {
191        postid = parseInt(jQuery('#search_wrapper').attr('data-postid'), 10);
192    }
193
194    all_checkers = '';
195    jQuery('.search_wrapper .extended_search_check_wrapper  input[type="checkbox"]').each(function () {
196        if (jQuery(this).is(":checked")) {
197            all_checkers = all_checkers + "," + jQuery(this).attr("name-title");
198        }
199    });
200
201    halfmap = 0;
202
203    if (jQuery('#google_map_prop_list_sidebar').length) {
204        halfmap = 1;
205    }
206
207    var geo_lat = '';
208    var geo_long = '';
209    var geo_rad = '';
210
211    if (jQuery("#geolocation_search").length > 0) {
212        geo_lat = jQuery('#geolocation_lat').val();
213        geo_long = jQuery('#geolocation_long').val();
214        geo_rad = jQuery('#geolocation_radius').val();
215
216    }
217    jQuery('#listing_ajax_container').empty();
218    jQuery('#listing_loader').show();
219    jQuery.ajax({
220        type: 'POST',
221        url: ajaxurl,
222        dataType: 'json',
223        data: {
224            'action': 'wpestate_ajax_filter_listings_search',
225            'action_values': action,
226            'category_values': category,
227            'city': city,
228            'area': area,
229            'advanced_rooms': rooms,
230            'advanced_bath': baths,
231            'price_low': min_price,
232            'price_max': price_max,
233            'newpage': newpage,
234            'postid': postid,
235            'halfmap': halfmap,
236            'all_checkers': all_checkers,
237            'geo_lat': geo_lat,
238            'geo_long': geo_long,
239            'geo_rad': geo_rad,
240            'order': order,
241            'security': nonce
242        },
243        success: function (data) {
244
245            jQuery('#listing_loader').hide();
246            jQuery('.listing_loader_title').show();
247            jQuery('.pagination_nojax').hide();
248            //jQuery('#listing_ajax_container').empty().append(data);
249            jQuery('.entry-title.title_prop').addClass('half_results').text(data.no_founs);
250
251            jQuery('#listing_ajax_container').empty().append(data.cards);
252
253
254            wpestate_restart_js_after_ajax();
255
256        },
257        error: function (errorThrown) {}
258    });//end ajax
259}
260
261
262//////////////////////////////////////////////////////////////////////////////////////////////
263/// ajax filtering on header search ; jslint checked
264////////////////////////////////////////////////////////////////////////////////////////////
265function wpestate_custom_search_start_filtering_ajax(newpage) {
266    "use strict";
267
268
269    var initial_array_last_item, temp_val, array_last_item, how_holder, slug_holder, val_holder, ajaxurl, postid, slider_min, slider_max, halfmap, all_checkers, term_id;
270
271    array_last_item = parseInt(mapfunctions_vars.fields_no, 10);
272    initial_array_last_item = array_last_item;
273
274    val_holder = [];
275    slug_holder = [];
276    how_holder = [];
277
278
279    //slug_holder         =   mapfunctions_vars.slugs;
280    slug_holder = JSON.parse(JSON.stringify(mapfunctions_vars.slugs));
281
282    // how_holder          =   mapfunctions_vars.hows;
283    how_holder = JSON.parse(JSON.stringify(mapfunctions_vars.hows));
284    var term_counter = 0;
285
286
287
288    if (mapfunctions_vars.slider_price === 'yes') {
289        slider_min = jQuery('#price_low').val();
290        slider_max = jQuery('#price_max').val();
291    }
292
293    if(jQuery('.wpresidence-component3-min-price_input_class').length>0){
294        slider_min = jQuery('.wpresidence-component3-min-price_input_class').val();
295        slider_max = jQuery('.wpresidence-component3-max-price_input_class').val();
296    }
297
298
299
300    term_counter = jQuery('.tab-pane.active').find('.term_counter').val();
301
302
303    if ((mapfunctions_vars.adv_search_type === '6' || mapfunctions_vars.adv_search_type === '7')) { // &&  !jQuery('.halfsearch')[0]
304
305        term_id = jQuery('.tab-pane.active .term_id_class').val();
306
307
308        if (mapfunctions_vars.slider_price === 'yes') {
309            slider_min = jQuery('#price_low_' + term_id).val();
310            slider_max = jQuery('#price_max_' + term_id).val();
311        }
312
313
314        if(jQuery('.tab-pane.active .wpresidence-component3-min-price_input_class').length>0){
315            slider_min = jQuery('.tab-pane.active .wpresidence-component3-min-price_input_class').val();
316            slider_max = jQuery('.tab-pane.active .wpresidence-component3-max-price_input_class').val();
317        }
318
319        
320
321        var start_counter = term_counter * mapfunctions_vars.fields_no;
322        if (term_counter > 0) {
323            array_last_item = (array_last_item * term_counter) + array_last_item;
324        }
325
326
327        for (var i = start_counter; i < array_last_item; i++) {
328            if (how_holder[i] == 'date bigger' || how_holder[i] == 'date smaller') {
329                temp_val = wpestate_get_custom_value_tab_search(term_id + slug_holder[i]);
330            } else {
331                temp_val = wpestate_get_custom_value_tab_search(slug_holder[i]);
332            }
333
334            if (typeof (temp_val) === 'undefined') {
335                temp_val = '';
336            }
337            val_holder.push(temp_val);
338        }
339
340    } else {
341        for (var i = 0; i < array_last_item; i++) {
342            temp_val = wpestate_get_custom_value(slug_holder[i]);
343            if (typeof (temp_val) === 'undefined') {
344                temp_val = '';
345            }
346            val_holder.push(temp_val);
347        }
348
349    }
350
351
352    if ((mapfunctions_vars.adv_search_type === '6' || mapfunctions_vars.adv_search_type === '7' || mapfunctions_vars.adv_search_type === '8' || mapfunctions_vars.adv_search_type === '9')) {
353        var tab_tax = jQuery('.adv_search_tab_item.active').attr('data-tax');
354
355        if (jQuery('.halfsearch')[0]) {
356            tab_tax = jQuery('.halfsearch').attr('data-tax');
357        }
358
359
360        if (tab_tax === 'property_category') {
361            slug_holder[array_last_item] = 'adv_categ';
362        } else if (tab_tax === 'property_action_category') {
363            slug_holder[array_last_item] = 'adv_actions';
364        } else if (tab_tax === 'property_city') {
365            slug_holder[array_last_item] = 'advanced_city';
366        } else if (tab_tax === 'property_area') {
367            slug_holder[array_last_item] = 'advanced_area';
368        } else if (tab_tax === 'property_county_state') {
369            slug_holder[array_last_item] = 'county-state';
370        }
371
372        how_holder[array_last_item] = 'like';
373
374        if (jQuery('.halfsearch')[0] && mapfunctions_vars.adv_search_type === '8') {
375            val_holder[array_last_item] = jQuery('#' + slug_holder[array_last_item]).parent().find('input:hidden').val();
376        } else {
377            val_holder[initial_array_last_item] = jQuery('.adv_search_tab_item.active').attr('data-term');
378        }
379
380    }
381
382
383    all_checkers = '';
384
385    if (mapfunctions_vars.adv_search_type === '6') {
386        jQuery('.tab-pane.active .extended_search_check_wrapper  input[type="checkbox"]').each(function () {
387            if (jQuery(this).is(":checked")) {
388                all_checkers = all_checkers + "," + jQuery(this).attr("name-title");
389            }
390        });
391    } else {
392
393        jQuery('.search_wrapper .extended_search_check_wrapper  input[type="checkbox"]').each(function () {
394            if (jQuery(this).is(":checked")) {
395                all_checkers = all_checkers + "," + jQuery(this).attr("name-title");
396            }
397        });
398    }
399
400
401
402
403
404    halfmap = 0;
405
406    if (jQuery('#google_map_prop_list_sidebar').length) {
407        halfmap = 1;
408    }
409    postid = 1;
410    if (document.getElementById('search_wrapper')) {
411        postid = parseInt(jQuery('#search_wrapper').attr('data-postid'), 10);
412    }
413    ajaxurl = ajaxcalls_vars.wpestate_ajax;
414
415
416
417    var filter_search_action10 = '';
418    var adv_location10 = '';
419
420    if (mapfunctions_vars.adv_search_type === '10') {
421        filter_search_action10 = jQuery('#adv_actions').attr('data-value');
422        adv_location10 = jQuery('#adv_location').val();
423    }
424
425
426    var filter_search_action11 = '';
427    var filter_search_categ11 = '';
428    var keyword_search = '';
429    keyword_search = jQuery('#keyword').val();
430    if (mapfunctions_vars.adv_search_type === '11') {
431        filter_search_action11 = jQuery('#adv_actions').attr('data-value');
432        filter_search_categ11 = jQuery('#adv_categ').attr('data-value');
433        keyword_search = jQuery('#keyword_search').val();
434    }
435    var geo_lat = '';
436    var geo_long = '';
437    var geo_rad = '';
438    var componentsbeds = '';
439    var componentsbaths= '';
440
441    if (jQuery("#geolocation_search").length > 0) {
442        geo_lat = jQuery('#geolocation_lat').val();
443        geo_long = jQuery('#geolocation_long').val();
444        geo_rad = jQuery('#geolocation_radius').val();
445
446    }
447
448    if (jQuery('.tab-pane.active .geolocation_search_item').length>0){
449        
450        geo_lat = jQuery('.tab-pane.active .geolocation_lat').val();
451        geo_long = jQuery('.tab-pane.active .geolocation_long').val();
452        geo_rad = jQuery('.tab-pane.active #geolocation_radius').val();
453    }
454
455
456
457    
458    if (jQuery('.wpestate-beds-baths-popoup-component').length>0){
459        componentsbeds = jQuery('.wpresidence-componentsbeds').val();
460        componentsbaths = jQuery('.wpresidence-componentsbaths').val();
461    }
462
463
464    if (jQuery('.tab-pane.active .wpestate-beds-baths-popoup-component').length>0){
465        componentsbeds = jQuery('.tab-pane.active .wpresidence-componentsbeds').val();
466        componentsbaths = jQuery('.tab-pane.active .wpresidence-componentsbaths').val();
467    }
468
469
470
471
472    var nonce = jQuery('#wpestate_ajax_filtering').val();
473    var order = jQuery('#a_filter_order').attr('data-value');
474
475    jQuery('#listing_ajax_container').empty();
476    jQuery('#listing_loader').show();
477    jQuery.ajax({
478        type: 'POST',
479        url: ajaxurl,
480        dataType: 'json',
481        data: {
482            'action': 'wpestate_custom_adv_ajax_filter_listings_search',
483            'val_holder': val_holder,
484            'newpage': newpage,
485            'postid': postid,
486            'slider_min': slider_min,
487            'slider_max': slider_max,
488            'halfmap': halfmap,
489            'all_checkers': all_checkers,
490            'filter_search_action10': filter_search_action10,
491            'adv_location10': adv_location10,
492            'filter_search_action11': filter_search_action11,
493            'filter_search_categ11': filter_search_categ11,
494            'keyword_search': keyword_search,
495            'geo_lat': geo_lat,
496            'geo_long': geo_long,
497            'geo_rad': geo_rad,
498            'order': order,
499            'term_counter': term_counter,
500            'componentsbeds'            :   componentsbeds,
501            'componentsbaths'           :   componentsbaths,
502            'security': nonce,
503        },
504        success: function (data) {
505
506    
507
508            jQuery('#listing_loader').hide();
509            jQuery('.listing_loader_title').show();
510            jQuery('.entry-title.title_prop').addClass('half_results').text(data.no_founs);
511
512            jQuery('#listing_ajax_container').empty().append(data.cards);
513
514
515
516            wpestate_restart_js_after_ajax();
517            jQuery('.col-md-12.listing_wrapper .property_unit_custom_element.image').each(function () {
518                jQuery(this).parent().addClass('wrap_custom_image');
519            });
520            
521            if (data.saved_search !== null) {
522                jQuery(".search_param").html(data.saved_search);
523                jQuery("#search_args").val( JSON.stringify(data.args) );
524                jQuery("#meta_args").val(  JSON.stringify(data.search_meta) );
525
526            }
527        },
528        error: function (errorThrown) {
529
530        }
531    });//end ajax
532}
533
534
535function wpestate_js_pagination_ajax(){
536    "use strict";
537
538    jQuery('.pagination_ajax a').on('click', function (event) {
539        event.preventDefault();
540        var newpage = parseInt(jQuery(this).attr('data-future'), 10);
541        wpestate_start_filtering(newpage);
542    });
543
544}
545
546
547////////////////////////////////////////////////////////////////////////////////////////////
548/// redo js after ajax calls - jslint checked
549////////////////////////////////////////////////////////////////////////////////////////////
550function wpestate_restart_js_after_ajax() {
551    "use strict";
552    wpestate_lazy_load_carousel_property_unit();
553    wpestate_card_unit_contact_actions();
554
555
556    // wpestate_enable_half_map_pin_action();
557    if (typeof wpestate_enable_half_map_pin_action == 'function') {
558        wpestate_enable_half_map_pin_action();
559    }
560    var newpage, post_id, post_image, to_add, icon;
561
562    jQuery('.pagination_ajax_search a').on('click', function (event) {
563        event.preventDefault();
564
565        newpage = parseInt(jQuery(this).attr('data-future'), 10);
566        document.getElementById('scrollhere').scrollIntoView();
567        if (mapfunctions_vars.custom_search === 'yes') {
568            wpestate_custom_search_start_filtering_ajax(newpage);  // should be custom
569        } else {
570            wpestate_start_filtering_ajax(newpage);//
571        }
572    });
573
574    jQuery('.pagination_ajax a').on('click', function (event) {
575        event.preventDefault();
576        newpage = parseInt(jQuery(this).attr('data-future'), 10);
577        document.getElementById('scrollhere').scrollIntoView();
578        wpestate_start_filtering(newpage);
579    });
580
581
582
583    jQuery('.property_listing').on('click', function (event) {
584        if (
585            event.target.classList.contains('demo-icon') || 
586            event.target.classList.contains('carousel-control-next-icon') || 
587            event.target.classList.contains('carousel-control-prev-icon')   
588        ){
589            return;
590        }
591
592
593        if (control_vars.property_modal === '1' && !Modernizr.mq('only all and (max-width: 1024px)')) {
594            event.preventDefault();
595            event.stopPropagation();
596            scroll_modal_save = scroll_modal;
597
598            var listing_id = jQuery(this).parent().attr('data-listid');
599            var main_img_url = jQuery(this).parent().attr('data-main-modal');
600            var main_title = jQuery(this).parent().attr('data-modal-title');
601            var link = jQuery(this).parent().attr('data-modal-link');
602            wpestate_enable_property_modal(listing_id, main_img_url, main_title, link);
603        } else {
604            if (control_vars.new_page_link === '_blank') {
605                return;
606            }
607            var link;
608            link = jQuery(this).attr('data-link');
609
610            window.open(link, '_self');
611        }
612    });
613
614
615
616
617
618    jQuery('.share_unit').on('click', function (event) {
619        event.stopPropagation();
620    });
621
622    var already_in = [];
623
624    jQuery('.compare-action').unbind('click');
625    jQuery('.compare-action').on('click', function (event) {
626        event.stopPropagation();
627        jQuery('.prop-compare').animate({
628            right: "0px"
629        });
630        post_id = jQuery(this).attr('data-pid');
631        for (var i = 0; i < already_in.length; i++) {
632            if (already_in[i] === post_id) {
633                return;
634            }
635        }
636
637        already_in.push(post_id);
638        post_image = jQuery(this).attr('data-pimage');
639
640        to_add = '<div class="items_compare ajax_compare" style="display:none;"><img src="' + post_image + '" class="img-responsive"><input type="hidden" value="' + post_id + '" name="selected_id[]" /></div>';
641        jQuery('div.items_compare:first-child').css('background', 'red');
642        if (parseInt(jQuery('.items_compare').length, 10) > 3) {
643            jQuery('.items_compare:first').remove();
644        }
645        jQuery('#submit_compare').before(to_add);
646        jQuery('.items_compare').fadeIn(800);
647    });
648
649    jQuery('#submit_compare').unbind('click');
650    jQuery('#submit_compare').on('click', function (event) {
651        jQuery('#form_compare').trigger('submit');
652    });
653
654    jQuery('.icon-fav').on('click', function (event) {
655        event.stopPropagation();
656        icon = jQuery(this);
657        wpestate_add_remove_favorite(icon);
658    });
659
660    jQuery(".share_list, .icon-fav, .compare-action,.property_listing_details_v7_item").on('mouseenter', function () {
661        jQuery(this).tooltip('show');
662    })
663            .on('mouseleave', function () {
664                jQuery(this).tooltip('hide');
665            });
666
667
668    jQuery('.share_list').on('click', function (event) {
669        event.stopPropagation();
670        var sharediv = jQuery(this).parent().find('.share_unit');
671        sharediv.toggle();
672        jQuery(this).toggleClass('share_on');
673    });
674
675    wpestate_grid_list_controls();
676    wpestate_enable_share_unit();
677    wpestate_enable_not_logged_favorites();
678}
679
680
681
682
683
684/*
685*
686* Remove/Add to favorites(property page)  when login is not required
687*
688*/
689
690function wpestate_add_remove_favorite_local_storage_single(icon,post_id){
691    var current_favorites = window.localStorage.getItem('wpestate_favorites');
692    post_id=parseInt(post_id);
693
694
695    if(icon.hasClass('isnotfavorite')){
696
697        if ( current_favorites ) {
698            current_favorites=current_favorites + ',' + post_id;
699            window.localStorage.setItem('wpestate_favorites',current_favorites );
700        } else {
701            current_favorites=post_id;
702            window.localStorage.setItem('wpestate_favorites', current_favorites);
703        }
704
705        setCookie('wpestate_favorites',current_favorites,10);
706
707        jQuery('#add_favorites').removeClass('isnotfavorite').addClass('isfavorite').attr('title', ajaxcalls_vars.remove_favorite);
708        jQuery('#add_favorites').html('<i class="fas fa-heart"></i>' + ajaxcalls_vars.favorite);
709  
710    }else{
711
712        var prop_ids = jQuery.map(current_favorites.split(','), function(value){
713						return parseInt(value);
714					});
715
716               
717        const index = prop_ids.indexOf( post_id );      
718      
719        if (index > -1) {
720            prop_ids.splice(index, 1);      
721            window.localStorage.setItem('wpestate_favorites', prop_ids);
722            setCookie('wpestate_favorites',prop_ids,10);
723        }
724
725
726        jQuery('#add_favorites').removeClass('isfavorite').addClass('isnotfavorite').attr('title', ajaxcalls_vars.add_favorite);
727        jQuery('#add_favorites').html('<i class="far fa-heart"></i>' + ajaxcalls_vars.favorite);
728
729    }
730
731    current_favorites = window.localStorage.getItem('wpestate_favorites');
732}
733
734
735
736/*
737*
738* Remove/Add to favorites when login is not required
739*
740*/
741
742
743function wpestate_add_remove_favorite_local_storage(icon,post_id){
744    var current_favorites = window.localStorage.getItem('wpestate_favorites');
745    post_id=parseInt(post_id);
746
747    if(icon.hasClass('icon-fav-off')){
748
749        if ( current_favorites ) {
750            current_favorites=current_favorites+','+post_id;
751            window.localStorage.setItem('wpestate_favorites', current_favorites);
752        } else {
753            current_favorites=post_id;
754            window.localStorage.setItem('wpestate_favorites', current_favorites);
755        }
756
757        setCookie('wpestate_favorites',current_favorites,10);
758
759        icon.removeClass('icon-fav-off').addClass('icon-fav-on');
760        icon.attr('title', ajaxcalls_vars.remove_fav);
761
762    }else{
763
764        var prop_ids = jQuery.map(current_favorites.split(','), function(value){
765						return parseInt(value);
766					});
767           
768        const index = prop_ids.indexOf( post_id );      
769  
770        if (index > -1) {
771            prop_ids.splice(index, 1);
772            window.localStorage.setItem('wpestate_favorites', prop_ids);
773            setCookie('wpestate_favorites',prop_ids,10);
774        }
775
776        if (icon.hasClass('remove_fav_dash')) {
777            icon.parents('.property_wrapper_dash').remove();
778            icon.parents('.listing_wrapper').remove();
779        }
780
781        icon.removeClass('icon-fav-on').addClass('icon-fav-off');
782        icon.attr('title', ajaxcalls_vars.add_favorite);
783    }
784
785    current_favorites = window.localStorage.getItem('wpestate_favorites');
786}
787
788
789
790/*
791*
792* Remove/Add to favorites
793*
794*/
795
796function wpestate_add_remove_favorite(icon) {
797
798    "use strict";
799    var post_id, securitypass, ajaxurl;
800    post_id = icon.attr('data-postid');
801    securitypass = jQuery('#security-pass').val();
802    ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
803    var nonce = jQuery('#wpestate_ajax_filtering').val();
804    var use_favorite_login  =   ajaxcalls_vars.favorites_login;
805
806    if(use_favorite_login=="no"){
807        wpestate_add_remove_favorite_local_storage(icon,post_id);
808        return;
809    }
810
811    if (parseInt(ajaxcalls_vars.userid, 10) === 0) {
812        wpestate_trigger_login_modal_open(1);
813
814
815    } else {
816        icon.toggleClass('icon-fav-off');
817        icon.toggleClass('icon-fav-on');
818
819        jQuery.ajax({
820            type: 'POST',
821            url: ajaxurl,
822            dataType: 'json',
823            data: {
824                'action': 'wpestate_ajax_add_fav',
825                'post_id': post_id,
826                'security': nonce
827            },
828            success: function (data) {
829                if (data.added) {
830                    icon.removeClass('icon-fav-off').addClass('icon-fav-on');
831                    icon.attr('title', ajaxcalls_vars.remove_fav);
832                } else {
833
834                    if (icon.hasClass('remove_fav_dash')) {
835                        icon.parents('.property_wrapper_dash').remove();
836                    }
837                    icon.removeClass('icon-fav-on').addClass('icon-fav-off');
838                    icon.attr('title', ajaxcalls_vars.add_favorite);
839                }
840            },
841            error: function (errorThrown) {
842
843            }
844        });//end ajax
845    }// end login use
846}
847
848////////////////////////////////////////////////////////////////////////////////////////////
849/// resend listing for approval-jslint checked
850////////////////////////////////////////////////////////////////////////////////////////////
851function wpestate_resend_for_approval(prop_id, selected_div) {
852    "use strict";
853    var ajaxurl, normal_list_no;
854    ajaxurl = control_vars.admin_url + 'admin-ajax.php';
855    var nonce = jQuery('#wpestate_property_actions').val();
856
857    jQuery.ajax({
858        type: 'POST',
859        url: ajaxurl,
860        data: {
861            'action': 'wpestate_ajax_resend_for_approval',
862            'propid': prop_id,
863            'security': nonce
864        },
865        success: function (data) {
866
867            if (data === 'pending') {
868                selected_div.parent().empty().append('<span class="featured_prop">Sent for approval</span>');
869                normal_list_no = parseInt(jQuery('#normal_list_no').text(), 10);
870                jQuery('#normal_list_no').text(normal_list_no - 1);
871            } else {
872                selected_div.removeClass('resend_pending').html(data);
873            }
874        },
875        error: function (errorThrown) {
876
877        }
878    });//end ajax
879}
880
881////////////////////////////////////////////////////////////////////////////////////////////
882/// make property featured-jslint checked
883////////////////////////////////////////////////////////////////////////////////////////////
884function wpestate_make_prop_featured(prop_id, selectedspan) {
885    "use strict";
886    var ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
887    var nonce = jQuery('#wpestate_property_actions').val();
888
889    jQuery.ajax({
890        type: 'POST',
891        url: ajaxurl,
892        data: {
893            'action': 'wpestate_ajax_make_prop_featured',
894            'propid': prop_id,
895            'security': nonce
896        },
897        success: function (data) {
898            if (data.trim() === 'done') {
899                selectedspan.empty().html('<span class="label label-success">' + ajaxcalls_vars.prop_featured + '</span>');
900                var featured_list_no = parseInt(jQuery('#featured_list_no').text(), 10);
901                jQuery('#featured_list_no').text(featured_list_no - 1);
902            } else {
903                selectedspan.empty().removeClass('make_featured').addClass('featured_exp').text(ajaxcalls_vars.no_prop_featured);
904            }
905
906        },
907        error: function (errorThrown) {
908        }
909
910    });//end ajax
911}
912
913////////////////////////////////////////////////////////////////////////////////////////////
914/// pay package via paypal recuring-jslint checked
915////////////////////////////////////////////////////////////////////////////////////////////
916function wpestate_recuring_pay_pack_via_paypal() {
917    "use strict";
918    var ajaxurl, packName, packId;
919    ajaxurl = control_vars.admin_url + 'admin-ajax.php';
920
921    packName = jQuery('.package_selected .pack-listing-title').text();
922    packId = jQuery('.package_selected .pack-listing-title').attr('data-packid');
923
924    var nonce = jQuery('#wpestate_payments_nonce').val();
925    jQuery.ajax({
926        type: 'POST',
927        url: ajaxurl,
928        data: {
929            'action': 'wpestate_ajax_paypal_pack_recuring_generation_rest_api',
930            'packName': packName,
931            'packId': packId,
932            'security': nonce
933        },
934        success: function (data) {
935            window.location.href = data;
936        },
937        error: function (errorThrown) {
938
939        }
940    });//end ajax
941}
942
943jQuery(".buypackage").click(function () {
944    "use strict";
945    var stripe_pack_id, stripetitle2, stripetitle, stripepay;
946
947
948    jQuery(".pack-listing").removeClass("package_selected");
949    jQuery(".pack-listing input").prop('checked', false);
950
951    jQuery(this).find('.input_pak_check').prop('checked', true);
952    jQuery(this).parent().addClass("package_selected");
953
954    stripetitle = jQuery(this).parent().find('.pack-listing-title').attr('data-stripetitle');
955    stripetitle2 = jQuery(this).parent().find('.pack-listing-title').attr('data-stripetitle2');
956    stripepay = jQuery(this).parent().find('.pack-listing-title').attr('data-stripepay');
957    stripe_pack_id = jQuery(this).parent().find('.pack-listing-title').attr('data-packid');
958
959    jQuery('.stripe_buttons').attr("id", stripetitle2);
960    jQuery('#stripe_script').attr("data-amount", stripepay);
961    jQuery('#stripe_script').attr("data-description", stripetitle);
962
963    jQuery('#pack_id').val(stripe_pack_id);
964    jQuery('#pack_title').val(stripetitle2);
965    jQuery('#pay_ammout').val(stripepay);
966    jQuery('#stripe_form').attr('data-amount', stripepay);
967
968
969    jQuery('.wpestate_stripe_pay_desc').html(control_vars.stripe_pay_for + " " + stripetitle2);
970    jQuery('#wpestate_stripe_form_button_sumit').html(control_vars.stripe_pay + " " + stripepay / 100 + " " + control_vars.submission_curency);
971
972    // enable stripe code
973
974
975});
976
977
978
979////////////////////////////////////////////////////////////////////////////////////////////
980/// pay package via paypal-jslint checked
981////////////////////////////////////////////////////////////////////////////////////////////
982function wpestate_pay_pack_via_paypal() {
983    "use strict";
984    var ajaxurl, packName, packId;
985    ajaxurl = control_vars.admin_url + 'admin-ajax.php';
986    packName = jQuery('.package_selected .pack-listing-title').text();
987    packId = jQuery('.package_selected .pack-listing-title').attr('data-packid');
988    var nonce = jQuery('#wpestate_payments_nonce').val();
989    jQuery.ajax({
990        type: 'POST',
991        url: ajaxurl,
992        data: {
993            'action': 'wpestate_ajax_paypal_pack_generation',
994            'packName': packName,
995            'packId': packId,
996            'security': nonce
997        },
998        success: function (data) {
999
1000            window.location.href = data;
1001        },
1002        error: function (errorThrown) {
1003
1004        }
1005    });//end ajax
1006
1007}
1008////////////////////////////////////////////////////////////////////////////////////////////
1009/// listing pay -jslint checked
1010////////////////////////////////////////////////////////////////////////////////////////////
1011function wpestate_listing_pay(prop_id, selected_div, is_featured, is_upgrade) {
1012    "use strict";
1013    var ajaxurl = control_vars.admin_url + 'admin-ajax.php';
1014    var nonce = jQuery('#wpestate_payments_nonce').val();
1015    jQuery.ajax({
1016        type: 'POST',
1017        url: ajaxurl,
1018        data: {
1019            'action': 'wpestate_ajax_listing_pay',
1020            'propid': prop_id,
1021            'is_featured': is_featured,
1022            'is_upgrade': is_upgrade,
1023            'security': nonce
1024        },
1025        success: function (data) {
1026            window.location.href = data;
1027        },
1028        error: function (errorThrown) {
1029        }
1030    });//end ajax
1031}
1032
1033////////////////////////////////////////////////////////////////////////////////////////////
1034/// start filtering -jslint checked
1035////////////////////////////////////////////////////////////////////////////////////////////
1036function wpestate_start_filtering(newpage) {
1037    "use strict";
1038    jQuery('#gmap-loading').show();
1039    jQuery('#grid_view').addClass('icon_selected');
1040    jQuery('#list_view').removeClass('icon_selected');
1041
1042    var action, category, county, city, area, order, ajaxurl, page_id;
1043    // get action vars
1044    action = jQuery('#a_filter_action').attr('data-value');
1045    // get category
1046    category = jQuery('#a_filter_categ').attr('data-value');
1047
1048    // get county
1049    county = jQuery('#a_filter_county').attr('data-value');
1050
1051    // get city
1052    city = jQuery('#a_filter_cities').attr('data-value');
1053    // get area
1054    area = jQuery('#a_filter_areas').attr('data-value');
1055    // get order
1056    order = jQuery('#a_filter_order').attr('data-value');
1057    ajaxurl = ajaxcalls_vars.wpestate_ajax;
1058    page_id = jQuery('#page_idx').val();
1059
1060    var card_version = jQuery('.wpestate_filter_list_properties_wrapper').attr('data-card_version');
1061    var rownumber = jQuery('.wpestate_filter_list_properties_wrapper').attr('data-rownumber');
1062    var ishortcode = jQuery('.wpestate_filter_list_properties_wrapper').attr('data-ishortcode');
1063    var number = jQuery('.wpestate_filter_list_properties_wrapper').attr('data-number');
1064
1065    var align = '';
1066    if (jQuery('.wpestate_filter_list_properties_wrapper').length > 0) {
1067        jQuery('.wpestate_filter_list_properties_wrapper .listing_wrapper').remove();
1068        jQuery('.wpestate_filter_list_properties_wrapper .pagination_ajax').remove();
1069        jQuery('.wpestate_filter_list_properties_wrapper .no_results').remove();
1070        align = jQuery('.wpestate_filter_list_properties_wrapper').attr('data-align');
1071
1072        jQuery('#listing_loader2').show();
1073    } else {
1074        jQuery('#listing_ajax_container').empty();
1075        jQuery('#listing_loader').show();
1076
1077    }
1078    var nonce = jQuery('#wpestate_ajax_filtering').val();
1079
1080
1081    jQuery.ajax({
1082        type: 'POST',
1083        url: ajaxurl,
1084        dataType: 'json',
1085        data: {
1086            'action': 'wpestate_ajax_filter_listings',
1087            'action_values': action,
1088            'category_values': category,
1089            'county': county,
1090            'city': city,
1091            'area': area,
1092            'order': order,
1093            'newpage': newpage,
1094            'page_id': page_id,
1095            'align': align,
1096            'card_version': card_version,
1097            'rownumber': rownumber,
1098            'ishortcode': ishortcode,
1099            'number':number,
1100            'security': nonce
1101        },
1102        success: function (data) {
1103
1104            jQuery('#listing_loader').hide();
1105            if (jQuery('.wpestate_filter_list_properties_wrapper').length > 0) {
1106                jQuery('#listing_loader2').hide();
1107                jQuery('.wpestate_filter_list_properties_wrapper').append(data.to_show);
1108            } else {
1109                jQuery('#listing_ajax_container').empty().append(data.to_show);
1110            }
1111
1112            jQuery('.pagination_nojax').hide();
1113            wpestate_restart_js_after_ajax();
1114
1115            // map update
1116            var no_results = parseInt(data.no_results);
1117            if (no_results !== 0) {
1118                wpestate_load_on_demand_pins(data.markers, no_results, 0);
1119            } else {
1120                wpestate_show_no_results();
1121            }
1122
1123            jQuery('.col-md-12.listing_wrapper .property_unit_custom_element.image').each(function () {
1124                jQuery(this).parent().addClass('wrap_custom_image');
1125            });
1126
1127            jQuery('#gmap-loading').hide();
1128
1129        },
1130        error: function (errorThrown) {
1131
1132        }
1133    });//end ajax
1134}
1135
1136
1137
1138
1139
1140////////////////////////////////////////////////////////////////////////////////////////////
1141// on ready -jslint checked
1142//  developer listing on tab click !!
1143////////////////////////////////////////////////////////////////////////////////////////////
1144jQuery(document).ready(function ($) {
1145    "use strict";
1146
1147    wpestate_add_to_favorites();
1148    wpestate_js_pagination_ajax();
1149    wpestate_enable_not_logged_favorites();
1150   // wpestate_loade_agent_listings();
1151    wpestate_load_agency_developer_listings();
1152
1153
1154    wpestate_agent_submit_email();
1155
1156    wpestate_theme_slider_show_contact();
1157    wpestate_enable_schedule_contact();
1158   
1159
1160
1161
1162
1163
1164    ///////////////////////////////////////////////////////////////////////////////////////////
1165    //// stripe cancel
1166    ///////////////////////////////////////////////////////////////////////////////////////////
1167    $('#stripe_cancel').on('click', function (event) {
1168
1169        var stripe_user_id, ajaxurl;
1170        stripe_user_id = $(this).attr('data-stripeid');
1171        ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
1172        $('#stripe_cancel').text(ajaxcalls_vars.saving);
1173        var nonce = jQuery('#wpestate_stripe_cancel_nonce').val();
1174
1175        $.ajax({
1176            type: 'POST',
1177            url: ajaxurl,
1178            data: {
1179                'action': 'wpestate_cancel_stripe',
1180                'stripe_customer_id': stripe_user_id,
1181                'security': nonce,
1182
1183            },
1184            success: function (data) {
1185                $('#stripe_cancel').text(ajaxcalls_vars.stripecancel);
1186            },
1187            error: function (errorThrown) {
1188            }
1189        });
1190    });
1191
1192
1193    ////////////////////////////////////////////////////////////////////////////////////////////
1194    /// resend for approval
1195    ///////////////////////////////////////////////////////////////////////////////////////////
1196    $('.resend_pending').on('click', function (event) {
1197
1198        var prop_id = $(this).attr('data-listingid');
1199        wpestate_resend_for_approval(prop_id, $(this));
1200    });
1201
1202
1203
1204    jQuery('#wpestate_stripe_booking_recurring').on('click', function () {
1205
1206        var modalid = jQuery(this).attr('data-modalid');
1207        var modal = jQuery('#' + modalid);
1208        
1209        modal.appendTo('body');
1210        
1211        modal.show();
1212        jQuery('#' + modalid + ' .wpestate_stripe_form_1').show();
1213
1214        wpestate_start_stripe(1, modalid);
1215    });
1216
1217    ///////////////////////////////////////////////////////////////////////////////////////////
1218    ////////  pack upgrade via paypal
1219    ///////////////////////////////////////////////////////////////////////////////////////////
1220    $('#pick_pack').on('click', function (event) {
1221
1222        var pay_paypal;
1223        pay_paypal = '<div class="modal fade" id="paypal_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-body listing-submit">' + ajaxcalls_vars.paypal + '</div></div></div></div></div>';
1224        jQuery('body').append(pay_paypal);
1225        jQuery('#paypal_modal').modal();
1226
1227
1228        if ($('#pack_recuring').is(':checked')) {
1229            wpestate_recuring_pay_pack_via_paypal();
1230        } else {
1231            wpestate_pay_pack_via_paypal();
1232        }
1233    });
1234
1235    ///////////////////////////////////////////////////////////////////////////////////////////
1236    //////// listing pay via paypal
1237    ///////////////////////////////////////////////////////////////////////////////////////////
1238    $('.listing_submit_normal').on('click', function (event) {
1239        var prop_id, featured_checker, is_featured, is_upgrade, pay_paypal;
1240        pay_paypal = '<div class="modal fade" id="paypal_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-body listing-submit">' + ajaxcalls_vars.paypal + '</div></div></div></div></div>';
1241        jQuery('body').append(pay_paypal);
1242        jQuery('#paypal_modal').modal();
1243
1244
1245        prop_id = $(this).attr('data-listingid');
1246        featured_checker = $(this).parent().find('input');
1247        is_featured = 0;
1248        is_upgrade = 0;
1249
1250        if (featured_checker.prop('checked')) {
1251            is_featured = 1;
1252        } else {
1253            is_featured = 0;
1254        }
1255
1256        wpestate_listing_pay(prop_id, $(this), is_featured, is_upgrade);
1257    });
1258
1259    jQuery('.woo_pay_submit').on('click', function () {
1260        var pay_paypal, prop_id, book_id, invoice_id, is_featured, is_upgrade, ajaxurl, depozit, is_submit, pack_id;
1261        prop_id = jQuery(this).attr('data-propid');
1262        depozit = jQuery(this).attr('data-deposit');
1263        is_featured = jQuery(this).attr('data-is_featured');
1264        pack_id = jQuery('.package_selected').attr('data-id');
1265        is_upgrade = 0;
1266        is_submit = 1;
1267        if (jQuery('#open_packages').length > 0) {
1268            is_submit = 0;
1269        }
1270        book_id = '';
1271        invoice_id = '';
1272
1273        ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
1274        jQuery.ajax({
1275            type: 'POST',
1276            url: ajaxurl,
1277            data: {
1278                'action': 'wpestate_woo_pay',
1279                'propid': prop_id,
1280                'depozit': depozit,
1281                'is_submit': is_submit,
1282                'is_featured': is_featured,
1283                'pack_id': pack_id,
1284                'book_id': book_id,
1285                'invoiceid': invoice_id,
1286//                    'price_pack'    :   price_pack,
1287//                    'security'      :   nonce,
1288            },
1289            success: function (data) {
1290                if (data !== false) {
1291                    window.location.href = ajaxcalls_vars.checkout_url;
1292                }
1293            },
1294            error: function (errorThrown) {}
1295        });//end ajax
1296    });
1297
1298    $('.listing_upgrade').on('click', function (event) {
1299        var is_upgrade, is_featured, prop_id;
1300        is_upgrade = 1;
1301        is_featured = 0;
1302        prop_id = $(this).attr('data-listingid');
1303        wpestate_listing_pay(prop_id, $(this), is_featured, is_upgrade);
1304    });
1305
1306
1307
1308    ///////////////////////////////////////////////////////////////////////////////////////////
1309    /////// Property page  + ajax call on contact
1310    ///////////////////////////////////////////////////////////////////////////////////////////
1311
1312
1313  
1314
1315    ///////////////////////////////////////////////////////////////////////////////////////////
1316    ////////  property listing listing
1317    ////////////////////////////////////////////////////////////////////////////////////////////
1318
1319    $('.listing_filters_head li').on('click', function (event) {
1320
1321        var pick, value, parent;
1322        pick = $(this).text();
1323        value = $(this).attr('data-value');
1324        parent = $(this).parent().parent();
1325        parent.find('.filter_menu_trigger').text(pick).append('<span class="caret caret_filter"></span>').attr('data-value', value);
1326        parent.find('input:hidden').val(value);
1327
1328        wpestate_start_filtering(1);
1329
1330
1331    });
1332
1333
1334
1335
1336    ///////////////////////////////////////////////////////////////////////////////////////////
1337    //////// advanced search filtering
1338    ////////////////////////////////////////////////////////////////////////////////////////////
1339
1340    $('.adv_listing_filters_head li').on('click', function (event) {
1341
1342        var pick, value, parent, args, page_id, ajaxurl;
1343        ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
1344        pick = $(this).text();
1345        value = $(this).attr('data-value');
1346        parent = $(this).parent().parent();
1347        parent.find('.filter_menu_trigger').text(pick).append('<span class="caret caret_filter"></span>').attr('data-value', value);
1348        args = $('#searcharg').val();
1349        page_id = $('#page_idx').val();
1350        $('#listing_ajax_container').empty();
1351        $('#listing_loader').show();
1352        var nonce = jQuery('#wpestate_search_nonce').val();
1353        $.ajax({
1354            type: 'POST',
1355            url: ajaxurl,
1356
1357            data: {
1358                'action': 'wpestate_advanced_search_filters',
1359                'args': args,
1360                'value': value,
1361                'page_id': page_id,
1362                'security': nonce
1363            },
1364            success: function (data) {
1365                $('#listing_loader').hide();
1366                $('#listing_ajax_container').append(data);
1367                wpestate_restart_js_after_ajax();
1368                wpestate_add_pagination_orderby();
1369            },
1370            error: function (errorThrown) {
1371            }
1372        }); //end ajax
1373    });
1374
1375
1376    function wpestate_add_pagination_orderby() {
1377
1378        var order = $('#a_filter_order').attr('data-value');
1379        jQuery('.pagination a').each(function () {
1380            var href = $(this).attr('href');
1381            href = href + "&order_search=" + order;
1382            $(this).attr('href', href);
1383        });
1384    }
1385
1386    ///////////////////////////////////////////////////////////////////////////////////////////
1387    ////////  Ajax add to favorites on listing
1388    ////////////////////////////////////////////////////////////////////////////////////////////
1389    $('.icon-fav,.remove_fav_dash').on('click', function (event) {
1390        event.stopPropagation();
1391        var icon = $(this);
1392        wpestate_add_remove_favorite(icon);
1393    });
1394
1395
1396
1397
1398    // remove from fav listing on user profile
1399    $('.icon-fav-on-remove').on('click', function (event) {
1400        event.stopPropagation();
1401        $(this).parent().parent().remove();
1402
1403    });
1404
1405
1406
1407
1408
1409    ///////////////////////////////////////////////////////////////////////////////////////////
1410    ////////  update profile
1411    ////////////////////////////////////////////////////////////////////////////////////////////
1412    $('#register_agent').on('click', function (event) {
1413        var firstname = $('#firstname').val();
1414        var secondname = $('#secondname').val();
1415        var useremail = $('#useremail').val();
1416        var userphone = $('#userphone').val();
1417        var usermobile = $('#usermobile').val();
1418        var userskype = $('#userskype').val();
1419        var usertitle = $('#usertitle').val();
1420        var description = $('#about_me').val();
1421        var userfacebook = $('#userfacebook').val();
1422        var usertwitter = $('#usertwitter').val();
1423        var userlinkedin = $('#userlinkedin').val();
1424        var userpinterest = $('#userpinterest').val();
1425        var userinstagram = $('#userinstagram').val();
1426        var userurl = $('#website').val();
1427        var agent_username = $('#agent_username').val();
1428        var agent_password = $('#agent_password').val();
1429        var agent_repassword = $('#agent_repassword').val();
1430        var agent_category_submit = $('#agent_category_submit').val();
1431        var agent_action_submit = $('#agent_action_submit').val();
1432        var agent_city = $('#agent_city').val();
1433        var agent_county = $('#agent_county').val();
1434        var agent_member = $('#agent_member').val();
1435        var agent_address = $('#agent_address').val();
1436
1437        var agent_youtube = $('#useryoutube').val();
1438        var agent_tiktok = $('#usertiktok').val();
1439        var agent_telegram = $('#usertelegram').val();
1440        var agent_vimeo = $('#uservimeo').val();
1441        var agent_private_notes = $('#agent_private_notes').val();
1442
1443        var agent_area = $('#agent_area').val();
1444        var is_agent_edit = $('#is_agent_edit').val();
1445        var user_id = $('#user_id').val();
1446        var agent_id = $('#agent_id').val();
1447        var ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
1448        var securityprofile = $('#security-profile').val();
1449        var upload_picture = $('#upload_picture').val();
1450        var profile_image_url = $('#profile-image').attr('data-profileurl');
1451        var profile_image_url_small = $('#profile-image').attr('data-smallprofileurl');
1452
1453        // customparameters
1454        var agent_custom_label = [];
1455        $('.single_parameter_row .agent_custom_label').each(function () {
1456            agent_custom_label.push($(this).val());
1457        });
1458
1459        var agent_custom_value = [];
1460        $('.single_parameter_row .agent_custom_value').each(function () {
1461            agent_custom_value.push($(this).val());
1462        });
1463        var nonce = jQuery('#wpestate_register_agent_nonce').val();
1464
1465        window.scrollTo(0, 0);
1466
1467        $('#profile_message').empty().append('<div class="login-alert">' + ajaxcalls_vars.saving + '<div>');
1468
1469
1470        $.ajax({
1471            type: 'POST',
1472            url: ajaxurl,
1473            dataType: 'json',
1474            data: {
1475                'action': 'wpestate_ajax_register_agent',
1476                'agent_username': agent_username,
1477                'agent_password': agent_password,
1478                'agent_repassword': agent_repassword,
1479                'firstname': firstname,
1480                'secondname': secondname,
1481                'useremail': useremail,
1482                'userphone': userphone,
1483                'usermobile': usermobile,
1484                'userskype': userskype,
1485                'usertitle': usertitle,
1486                'description': description,
1487                'upload_picture': upload_picture,
1488                'security-profile': securityprofile,
1489                'profile_image_url': profile_image_url,
1490                'profile_image_url_small': profile_image_url_small,
1491                'userfacebook': userfacebook,
1492                'usertwitter': usertwitter,
1493                'userlinkedin': userlinkedin,
1494                'userpinterest': userpinterest,
1495                'userinstagram': userinstagram,
1496                'userurl': userurl,
1497                'agent_category_submit': agent_category_submit,
1498                'agent_action_submit': agent_action_submit,
1499                'agent_city': agent_city,
1500                'agent_county': agent_county,
1501                'agent_area': agent_area,
1502                'agentedit': is_agent_edit,
1503                'userid': user_id,
1504                'agentid': agent_id,
1505                'agent_member': agent_member,
1506                'agent_address': agent_address,
1507                'agent_youtube':agent_youtube,
1508                'agent_tiktok':agent_tiktok,
1509                'agent_telegram':agent_telegram,
1510                'agent_vimeo': agent_vimeo,
1511                'agent_private_notes': agent_private_notes,
1512                'agent_custom_label': agent_custom_label,
1513                'agent_custom_value': agent_custom_value,
1514                'security': nonce
1515
1516            },
1517            success: function (data) {
1518                $('#profile_message').empty().append('<div class="login-alert">
1518' + data.mesaj + '<div>');
1519                if (data.added) {
1520                    setTimeout(function () {
1521                        window.open(ajaxcalls_vars.agent_list, '_self', false);
1522                    }, 1500);
1523                }
1524            },
1525            error: function (errorThrown) {
1526
1527            }
1528        });
1529    });
1530
1531
1532    $('#update_profile').on('click', function (event) {
1533
1534        var firstname, secondname, userurl, usermobile, userinstagram, userpinterest, userlinkedin, usertwitter, userfacebook, profile_image_url, profile_image_url_small, firstname, secondname, useremail, userphone, userskype, usertitle, description, ajaxurl, securityprofile, upload_picture;
1535        firstname = $('#firstname').val();
1536        secondname = $('#secondname').val();
1537        useremail = $('#useremail').val();
1538        userphone = $('#userphone').val();
1539        usermobile = $('#usermobile').val();
1540        userskype = $('#userskype').val();
1541        usertitle = $('#usertitle').val();
1542        description = $('#about_me').val();
1543        userfacebook = $('#userfacebook').val();
1544        usertwitter = $('#usertwitter').val();
1545        userlinkedin = $('#userlinkedin').val();
1546        userpinterest = $('#userpinterest').val();
1547        userinstagram = $('#userinstagram').val();
1548        userurl = $('#website').val();
1549        var hubspot_api = $('#hubspot_api').val();
1550        var agent_member = $('#agent_member').val();
1551        var agent_address= $('#agent_address').val();
1552
1553        var agent_youtube = $('#useryoutube').val();
1554        var agent_tiktok = $('#usertiktok').val();
1555        var agent_telegram = $('#usertelegram').val();
1556        var agent_vimeo = $('#uservimeo').val();
1557        var agent_private_notes = $('#agent_private_notes').val();
1558
1559        var agent_category_submit = $('#agent_category_submit').val();
1560        var agent_action_submit = $('#agent_action_submit').val();
1561        var agent_city = $('#agent_city').val();
1562        var agent_county = $('#agent_county').val();
1563        var agent_area = $('#agent_area').val();
1564        var nonce = jQuery('#wpestate_update_profile_nonce').val();
1565
1566        ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
1567        securityprofile = $('#security-profile').val();
1568        upload_picture = $('#upload_picture').val();
1569        profile_image_url = $('#profile-image').attr('data-profileurl');
1570        profile_image_url_small = $('#profile-image').attr('data-smallprofileurl');
1571
1572        // customparameters
1573        var agent_custom_label = [];
1574        $('.cliche_row .agent_custom_label').each(function () {
1575            agent_custom_label.push($(this).val());
1576        });
1577
1578        var agent_custom_value = [];
1579        $('.cliche_row .agent_custom_value').each(function () {
1580            agent_custom_value.push($(this).val());
1581        });
1582
1583
1584
1585        window.scrollTo(0, 0);
1586        $('#profile_message').append('<div class="login-alert">' + ajaxcalls_vars.saving + '<div>');
1587        $.ajax({
1588            type: 'POST',
1589            url: ajaxurl,
1590            data: {
1591                'action': 'wpestate_ajax_update_profile',
1592                'firstname': firstname,
1593                'secondname': secondname,
1594                'useremail': useremail,
1595                'userphone': userphone,
1596                'usermobile': usermobile,
1597                'userskype': userskype,
1598                'usertitle': usertitle,
1599                'description': description,
1600                'upload_picture': upload_picture,
1601                'security-profile': securityprofile,
1602                'profile_image_url': profile_image_url,
1603                'profile_image_url_small': profile_image_url_small,
1604                'userfacebook': userfacebook,
1605                'usertwitter': usertwitter,
1606                'userlinkedin': userlinkedin,
1607                'userpinterest': userpinterest,
1608                'userinstagram': userinstagram,
1609                'userurl': userurl,
1610                'agent_category_submit': agent_category_submit,
1611                'agent_action_submit': agent_action_submit,
1612                'agent_city': agent_city,
1613                'agent_county': agent_county,
1614                'agent_area': agent_area,
1615                'agent_member': agent_member,
1616                'agent_address':agent_address,
1617                'agent_youtube':agent_youtube,
1618                'agent_tiktok':agent_tiktok,
1619                'agent_telegram':agent_telegram,
1620                'agent_vimeo': agent_vimeo,
1621                'agent_private_notes': agent_private_notes,
1622                'agent_custom_label': agent_custom_label,
1623                'agent_custom_value': agent_custom_value,
1624                'hubspot_api': hubspot_api,
1625                'security': nonce,
1626
1627            },
1628            success: function (data) {
1629
1630                $('#profile_message').empty().append('<div class="login-alert">
1630' + data + '<div>');
1631                window.scrollTo(0, 0);
1632            },
1633            error: function (errorThrown) {
1634            }
1635        });
1636    });
1637
1638
1639
1640    $('#update_profile_agency').on('click', function () {
1641
1642        var hubspot_api, agency_opening_hours, agency_license, agency_long, agency_lat, agency_address, agency_area, agency_county, agency_city, agency_action_submit, agency_action_submit, agency_category_submit, agency_taxes, agency_website, agency_languages, agency_name, userurl, usermobile, userinstagram, userpinterest, userlinkedin, usertwitter, userfacebook, profile_image_url, profile_image_url_small, firstname, secondname, useremail, userphone, userskype, usertitle, description, ajaxurl, securityprofile, upload_picture;
1643        agency_name = $('#agency_title').val();
1644        useremail = $('#useremail').val();
1645        userphone = $('#userphone').val();
1646        usermobile = $('#usermobile').val();
1647        userskype = $('#userskype').val();
1648
1649        description = $('#about_me').val();
1650        userfacebook = $('#userfacebook').val();
1651        usertwitter = $('#usertwitter').val();
1652        userlinkedin = $('#userlinkedin').val();
1653        userpinterest = $('#userpinterest').val();
1654        userinstagram = $('#userinstagram').val();
1655
1656        var useryoutube = $('#useryoutube').val();
1657        var usertiktok = $('#usertiktok').val();
1658        var usertelegram = $('#usertelegram').val();
1659        var uservimeo = $('#uservimeo').val();
1660        var agency_private_notes = $('#agency_private_notes').val();
1661
1662
1663
1664        agency_languages = $('#agency_languages').val();
1665        agency_website = $('#agency_website').val();
1666        agency_taxes = $('#agency_taxes').val();
1667        agency_license = $('#agency_license').val();
1668
1669
1670        agency_category_submit = $('#agency_category_submit').val();
1671        agency_action_submit = $('#agency_action_submit').val();
1672        agency_city = $('#agency_city').val();
1673        agency_county = $('#agency_county').val();
1674        agency_area = $('#agency_area').val();
1675        agency_address = $('#agency_address').val();
1676        agency_lat = $('#agency_lat').val();
1677        agency_long = $('#agency_long').val();
1678        agency_opening_hours = $('#agency_opening_hours ').val();
1679        hubspot_api = $('#hubspot_api ').val();
1680        securityprofile = $('#security-profile').val();
1681        upload_picture = $('#upload_picture').val();
1682        profile_image_url = $('#profile-image').attr('data-profileurl');
1683        profile_image_url_small = $('#profile-image').attr('data-smallprofileurl');
1684
1685
1686        ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
1687
1688        var nonce = jQuery('#wpestate_update_profile_nonce').val();
1689        window.scrollTo(0, 0);
1690        $.ajax({
1691            type: 'POST',
1692            url: ajaxurl,
1693            data: {
1694                'action': 'wpestate_ajax_update_profile_agency',
1695                'agency_name': agency_name,
1696                'useremail': useremail,
1697                'userphone': userphone,
1698                'usermobile': usermobile,
1699                'userskype': userskype,
1700                'usertitle': usertitle,
1701                'description': description,
1702                'upload_picture': upload_picture,
1703                'security-profile': securityprofile,
1704                'profile_image_url': profile_image_url,
1705                'profile_image_url_small': profile_image_url_small,
1706                'userfacebook': userfacebook,
1707                'usertwitter': usertwitter,
1708                'userlinkedin': userlinkedin,
1709                'userpinterest': userpinterest,
1710                'userinstagram': userinstagram,
1711                'useryoutube':useryoutube,
1712                'usertiktok':usertiktok,
1713                'usertelegram':usertelegram,
1714                'uservimeo':uservimeo,
1715                'agency_private_notes':agency_private_notes,
1716                'userurl': userurl,
1717                'agency_languages': agency_languages,
1718                'agency_website': agency_website,
1719                'agency_taxes': agency_taxes,
1720                'agency_license': agency_license,
1721                'agency_category_submit': agency_category_submit,
1722                'agency_action_submit': agency_action_submit,
1723                'agency_city': agency_city,
1724                'agency_county': agency_county,
1725                'agency_area': agency_area,
1726                'agency_address': agency_address,
1727                'agency_lat': agency_lat,
1728                'agency_opening_hours': agency_opening_hours,
1729                'agency_long': agency_long,
1730                'hubspot_api': hubspot_api,
1731                'security': nonce
1732            },
1733            success: function (data) {
1734                $('#profile_message').append('<div class="login-alert">
1734' + data + '<div>');
1735                window.scrollTo(0, 0);
1736            },
1737            error: function (errorThrown) {
1738            }
1739        });
1740    });
1741
1742
1743
1744//    update developer profile
1745    $('#update_profile_developer').on('click', function () {
1746
1747        var hubspot_api, developer_license, developer_long, developer_lat, developer_address, developer_area, developer_county, developer_city, developer_action_submit, developer_action_submit, developer_category_submit, developer_taxes, developer_website, developer_languages, developer_name, userurl, usermobile, userinstagram, userpinterest, userlinkedin, usertwitter, userfacebook, profile_image_url, profile_image_url_small, firstname, secondname, useremail, userphone, userskype, usertitle, description, ajaxurl, securityprofile, upload_picture;
1748        developer_name = $('#developer_title').val();
1749        useremail = $('#useremail').val();
1750        userphone = $('#userphone').val();
1751        usermobile = $('#usermobile').val();
1752        userskype = $('#userskype').val();
1753
1754        description = $('#about_me').val();
1755        userfacebook = $('#userfacebook').val();
1756        usertwitter = $('#usertwitter').val();
1757        userlinkedin = $('#userlinkedin').val();
1758        userpinterest = $('#userpinterest').val();
1759        userinstagram = $('#userinstagram').val();
1760
1761
1762       var useryoutube = $('#useryoutube').val();
1763       var usertiktok = $('#usertiktok').val();
1764       var usertelegram = $('#usertelegram').val();
1765       var  uservimeo = $('#uservimeo').val();
1766       var  developer_private_notes = $('#developer_private_notes').val();
1767
1768
1769
1770        developer_languages = $('#developer_languages').val();
1771        developer_website = $('#developer_website').val();
1772        developer_taxes = $('#developer_taxes').val();
1773        developer_license = $('#developer_license').val();
1774
1775
1776        developer_category_submit = $('#developer_category_submit').val();
1777        developer_action_submit = $('#developer_action_submit').val();
1778        developer_city = $('#developer_city').val();
1779        developer_county = $('#developer_county').val();
1780        developer_area = $('#developer_area').val();
1781        developer_address = $('#developer_address').val();
1782        developer_lat = $('#developer_lat').val();
1783        developer_long = $('#developer_long').val();
1784        securityprofile = $('#security-profile').val();
1785        upload_picture = $('#upload_picture').val();
1786        profile_image_url = $('#profile-image').attr('data-profileurl');
1787        profile_image_url_small = $('#profile-image').attr('data-smallprofileurl');
1788        hubspot_api = $('#hubspot_api').val();
1789
1790        ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
1791        var nonce = jQuery('#wpestate_update_profile_nonce').val();
1792        window.scrollTo(0, 0);
1793        $.ajax({
1794            type: 'POST',
1795            url: ajaxurl,
1796            data: {
1797                'action': 'wpestate_ajax_update_profile_developer',
1798                'developer_name': developer_name,
1799                'useremail': useremail,
1800                'userphone': userphone,
1801                'usermobile': usermobile,
1802                'userskype': userskype,
1803                'usertitle': usertitle,
1804                'description': description,
1805                'upload_picture': upload_picture,
1806                'security-profile': securityprofile,
1807                'profile_image_url': profile_image_url,
1808                'profile_image_url_small': profile_image_url_small,
1809                'userfacebook': userfacebook,
1810                'usertwitter': usertwitter,
1811                'userlinkedin': userlinkedin,
1812                'userpinterest': userpinterest,
1813                'userinstagram': userinstagram,
1814                'userurl': userurl,
1815                'developer_languages': developer_languages,
1816                'developer_website': developer_website,
1817                'developer_taxes': developer_taxes,
1818                'developer_license': developer_license,
1819                'developer_category_submit': developer_category_submit,
1820                'developer_action_submit': developer_action_submit,
1821                'developer_city': developer_city,
1822                'developer_county': developer_county,
1823                'developer_area': developer_area,
1824                'developer_address': developer_address,
1825                'developer_lat': developer_lat,
1826                'developer_long': developer_long,
1827                'hubspot_api': hubspot_api,
1828                'useryoutube':useryoutube,
1829                'usertiktok':usertiktok,
1830                'usertelegram':usertelegram,
1831                'uservimeo':uservimeo,
1832                'developer_private_notes':developer_private_notes,
1833                'security': nonce
1834            },
1835            success: function (data) {
1836                $('#profile_message').append('<div class="login-alert">' + data + '<div>');
1837                window.scrollTo(0, 0);
1838            },
1839            error: function (errorThrown) {
1840            }
1841        });
1842    });
1843
1844    //delete profile
1845
1846    $('#delete_profile').on('click', function (event) {
1847        var ajaxurl;
1848        ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
1849        var nonce = jQuery('#wpestate_update_profile_nonce').val();
1850        var result = confirm(ajaxcalls_vars.delete_account);
1851        if (result) {
1852            //Logic to delete the item
1853
1854            $.ajax({
1855                type: 'POST',
1856                url: ajaxurl,
1857                data: {
1858                    'action': 'wpestate_delete_profile',
1859                    'security': nonce,
1860                },
1861                success: function (data) {
1862                    window.location = '/';
1863                },
1864                error: function (errorThrown) {
1865
1866                }
1867            });
1868        }
1869    });
1870
1871    //end delete profile
1872
1873}); // end ready jquery
1874//End ready ********************************************************************
1875
1876
1877/**
1878 * Handles the loading of agency/developer listings via AJAX.
1879 * This function is triggered when a user clicks on a term bar item.
1880 */
1881function wpestate_load_agency_developer_listings() {
1882    jQuery('.term_bar_item, .listing_load_more').on('click', function (event) {
1883       
1884       
1885        // Select relevant DOM elements
1886        var $this = jQuery(this);
1887        var $listingParent = $this.parents('.single_listing_block');
1888        var $loadMoreButton = jQuery('.load_more_ajax_cont .listing_load_more', $listingParent);
1889        var $agencyListingsWrapper = jQuery('.agency_listings_wrapper');
1890        var $listingLoader = jQuery('#listing_loader');
1891        var $termBarWrapper = jQuery('.term_bar_wrapper');
1892        var $areadyLoadedItems = jQuery('.listing_wrapper', $listingParent).length;
1893     
1894        var $page_with_sidebar = 0;
1895        if(jQuery('#primary_sidebar_wrapper').length > 0){
1896            $page_with_sidebar = 1;
1897        }
1898
1899        // Display load more button
1900        $loadMoreButton.fadeIn();
1901
1902        // Perform AJAX request
1903        if(!$this.hasClass('listing_load_more')){
1904            $agencyListingsWrapper.empty();
1905            $areadyLoadedItems=0;
1906
1907            // Update active term styling
1908            jQuery('.term_bar_item').removeClass('active_term');
1909            $this.addClass('active_term');
1910        }
1911
1912        
1913        
1914        var $active_tab = jQuery('.active_term', $listingParent);
1915        var term_name = jQuery($active_tab).attr('data-term_name');
1916
1917       
1918        // Prepare AJAX data
1919        var ajaxData = {
1920            action: 'wpestate_agency_listings',
1921            term_name: $this.attr('data-term_name'),
1922            agency_id: $termBarWrapper.attr('data-agency_id'),
1923            agent_id: $termBarWrapper.data('data-agent_id'),
1924            post_id: $termBarWrapper.attr('data-post_id'),
1925            term_name: term_name,
1926            loaded: $areadyLoadedItems,
1927            is_agency: jQuery('.single-estate_agency').length > 0 ? 1 : 0,
1928            page_with_sidebar: $page_with_sidebar,
1929            security: jQuery('#wpestate_developer_listing_nonce').val()
1930        };
1931
1932     
1933
1934
1935
1936
1937        $listingLoader.show();
1938
1939        jQuery.ajax({
1940            type: 'POST',
1941            url: ajaxcalls_vars.admin_url + 'admin-ajax.php',
1942            data: ajaxData,
1943            dataType: 'json',
1944            success: function (response) {
1945                $listingLoader.hide();
1946                if (response.success) {
1947                    
1948                    if(response.data.found_posts > 0){
1949                        if(!$this.hasClass('listing_load_more')){
1950                            $agencyListingsWrapper.html(response.data.html);
1951                        }else{
1952                            $agencyListingsWrapper.append(response.data.html);
1953                        }
1954              
1955                        wpestate_restart_js_after_ajax();
1956                    }else{
1957                        $agencyListingsWrapper.append(response.data.html);
1958                        $this.hide()
1959                    }
1960
1961
1962
1963                } else {
1964                    $agencyListingsWrapper.html('<p>' + response.data.message + '</p>');
1965                }
1966            },
1967            error: function (jqXHR, textStatus, errorThrown) {
1968                console.error('AJAX request failed:', textStatus, errorThrown);
1969                $listingLoader.hide();
1970                $agencyListingsWrapper.html('<p>Error loading listings. Please try again.</p>');
1971            }
1972        });
1973    });
1974}
1975 
1976
1977function wpestate_add_to_favorites() {
1978
1979
1980    jQuery('#add_favorites').on('click', function (event) {
1981
1982        var post_id, ajaxurl;
1983        post_id = jQuery('#add_favorites').attr('data-postid');
1984        var icon = jQuery('#add_favorites');
1985        ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
1986        var nonce = jQuery('#wpestate_ajax_filtering').val();
1987        var use_favorite_login  =   ajaxcalls_vars.favorites_login;
1988        if(use_favorite_login=="no"){
1989            wpestate_add_remove_favorite_local_storage_single(icon,post_id);
1990            return;
1991        }
1992
1993
1994
1995        if (parseInt(ajaxcalls_vars.userid, 10) === 0) {
1996            if (!Modernizr.mq('only all and (max-width: 768px)')) {
1997                jQuery('#modal_login_wrapper').show();
1998                 jQuery('#modal_login_wrapper').find('[autofocus]').focus();
1999                jQuery('.loginpop').val('1');
2000            } else {
2001                jQuery('.mobile-trigger-user').trigger('click');
2002            }
2003
2004        } else {
2005            jQuery('#add_favorites').text(ajaxcalls_vars.saving);
2006            jQuery.ajax({
2007                type: 'POST',
2008                url: ajaxurl,
2009                dataType: 'json',
2010                data: {
2011                    'action': 'wpestate_ajax_add_fav',
2012                    'post_id': post_id,
2013                    'security': nonce
2014                },
2015                success: function (data) {
2016                    if (data.added) {
2017                        jQuery('#add_favorites').removeClass('isnotfavorite').addClass('isfavorite').attr('title', ajaxcalls_vars.remove_favorite);
2018                        jQuery('#add_favorites').html('<i class="fas fa-heart"></i>' + ajaxcalls_vars.favorite);
2019                    } else {
2020                        jQuery('#add_favorites').removeClass('isfavorite').addClass('isnotfavorite').attr('title', ajaxcalls_vars.add_favorite);
2021                        jQuery('#add_favorites').html('<i class="far fa-heart"></i>' + ajaxcalls_vars.favorite);
2022                    }
2023                },
2024                error: function (errorThrown) {
2025                }
2026            }); //end ajax
2027        }// end check login
2028    });
2029}
2030
2031///////////////////////////////////////////////////////////////////////////////////////////
2032/////// Property page  + ajax call on contact
2033///////////////////////////////////////////////////////////////////////////////////////////
2034function wpestate_theme_slider_show_contact() {
2035    jQuery('.wpestate_theme_slider_contact_agent').on('click', function () {
2036        var acesta = jQuery(this).parent().parent();
2037        acesta.find('#show_contact').text(ajaxcalls_vars.contact_agent);
2038        acesta.find('.theme_slider_contact_form_wrapper').show('0').toggleClass('theme_slider_contact_form_wrapper_visible');
2039        jQuery('#estate-carousel').carousel('pause');
2040      
2041    });
2042
2043
2044
2045    jQuery('.theme_slider_details_modal_close').on('click', function () {
2046        jQuery(this).parent().removeClass('theme_slider_contact_form_wrapper_visible');
2047                jQuery('#estate-carousel').carousel('cycle');
2048    });
2049
2050    jQuery('.theme_slider_contact_form_wrapper').on('click', function (event) {
2051        event.stopPropagation();
2052    });
2053
2054
2055}
2056
2057
2058/**
2059 * Enable Schedule Contact Functionality
2060 *
2061 * This function sets up event handlers for the schedule meeting functionality
2062 * and initializes the datepicker for schedule day selection.
2063 *
2064 * @package WpResidence
2065 * @subpackage PropertyDetails
2066 * @since 3.0.3
2067 *
2068 * Dependencies:
2069 * - jQuery
2070 * - jQuery UI Datepicker
2071 *
2072 * Usage: Call this function after DOM is ready and dependencies are loaded.
2073 */
2074
2075function wpestate_enable_schedule_contact() {
2076    // Toggle schedule wrapper visibility when clicking on schedule meeting button
2077    jQuery('.schedule_meeting').on('click', function (event) {
2078        var parent = jQuery(this).parent().parent();
2079        var scheduleWrapper = parent.find('.schedule_wrapper');
2080       
2081        scheduleWrapper.slideToggle(400, function() {
2082            scheduleWrapper.css('display', scheduleWrapper.is(':visible') ? 'flex' : 'none');
2083        });
2084    });
2085    
2086
2087    
2088    // Initialize datepicker for schedule day input with position correction
2089    jQuery(".schedule_day, #schedule_day").datepicker({
2090        dateFormat: "yy-mm-dd",
2091        beforeShow: function(input, inst) {
2092            // Position correction
2093            setTimeout(function() {
2094                inst.dpDiv.css({
2095                    position: 'absolute',
2096                    top: jQuery(input).offset().top + jQuery(input).outerHeight(),
2097                    left: jQuery(input).offset().left
2098                });
2099            }, 0);
2100        }
2101    }).datepicker('widget').wrap('<div class="ll-skin-melon"/>');
2102}
2103
2104
2105function wpestate_agent_submit_email() {
2106    jQuery('.wpresidence_elementor_form').on('submit', function (event) {
2107        event.preventDefault();
2108        var form_submit = jQuery('.wpresidence_elementor_form').find('.agent_submit_class_elementor');
2109        process_form_submit(form_submit);
2110    });
2111
2112    jQuery('.agent_submit_class').on('click', function (event) {
2113        process_form_submit(jQuery(this));
2114    });
2115    
2116    jQuery('.message_submit').on('click', function (event) {
2117        process_form_submit(jQuery(this));
2118    });
2119}
2120
2121
2122function process_form_submit(form_submit) {
2123
2124    var parent, contact_name, contact_email, contact_phone, contact_coment, agent_id, property_id, nonce, ajaxurl;
2125    parent          = form_submit.closest('.wpestate_contact_form_parent');
2126
2127    var is_private_message='no';
2128    if(form_submit.hasClass('message_submit')){
2129        is_private_message='yes';
2130    }
2131    
2132
2133    contact_name    = parent.find('#agent_contact_name').val();
2134    contact_email   = parent.find('#agent_user_email').val();
2135    contact_phone   = parent.find('#agent_phone').val();
2136    contact_coment  = parent.find('#agent_comment').val();
2137    agent_id        = parent.find('#agent_id').val();
2138    property_id     = parent.find('#agent_property_id').val();
2139    
2140    nonce   = parent.find('#agent_property_ajax_nonce').val();
2141    ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
2142    
2143    var schedule_day = parent.find('.schedule_day').val();
2144    var schedule_hour = parent.find('.schedule_hour').val();
2145    var schedule_mode ='in_person';
2146
2147
2148     
2149    if( parent.hasClass('wpestate_schedule_tour_wrapper_content') || 
2150        parent.hasClass('wpestate_shedule_tour_wrapper_type2') ||
2151        parent.hasClass('wpestate_schedule_tour_wrapper') ){
2152
2153        schedule_day    =   parent.find('.shedule_day_option_selected').attr('data-scheudle-day');
2154        schedule_hour   =   parent.find('#wpestate_schedule_tour_time').val();
2155
2156        var schedule_mode_button   =   parent.find('.shedule_option_selected');
2157        if( schedule_mode_button.hasClass('schedule_video_chat') ){
2158            schedule_mode ='video_chat';
2159        }       
2160    }
2161
2162
2163    var is_elementor = 0;
2164    if (form_submit.parents('.wpresidence_elementor_form').length) {
2165        parent                  =   form_submit.parents('.wpresidence_elementor_form');
2166        contact_name            =   parent.find('#form-field-name').val();
2167        contact_email           =   parent.find('#form-field-email').val();
2168        contact_coment          =   parent.find('#form-field-message').val();
2169        contact_phone           =   parent.find('input[name="phone"]').val();
2170        nonce                   =   parent.find('#agent_property_ajax_nonce').val();
2171        is_elementor            =   parent.find('#contact_form_elementor').val();
2172        var wpresidence_form_id =   parent.find('#wpresidence_form_id').val();
2173        var elementor_email_subject = parent.find('#elementor_email_subject').val();
2174
2175        var temp_details;
2176        temp_details        = '';
2177        var elementor_form  = form_submit.parents('.wpresidence_elementor_form');
2178        var form_items      = elementor_form.find('.elementor-field');
2179        var label_name      ='';
2180        var labelElement;
2181        form_items.each(function () {
2182
2183            labelElement=jQuery(this).parent().find('.elementor-field-label');
2184            
2185            if (labelElement.length > 0) {
2186                label_name = labelElement.text();
2187                label_name = label_name.replace('*', '');
2188            } else {
2189                label_name = jQuery(this).attr('name')
2190            }
2191  
2192            temp_details = temp_details + label_name + ": " + jQuery(this).val() + "/n";
2193        });
2194
2195        contact_coment = temp_details ;
2196
2197    }
2198
2199    if (parent.find('.wpestate_agree_gdpr').length > 0) {
2200        if (!parent.find('.wpestate_agree_gdpr').is(':checked')) {
2201            parent.find('#alert-agent-contact').empty().append(ajaxcalls_vars.gdpr_terms);
2202            return;
2203        }
2204    }
2205
2206
2207
2208    parent.find('#alert-agent-contact').empty().append(ajaxcalls_vars.sending);
2209
2210    jQuery.ajax({
2211        type: 'POST',
2212        dataType: 'json',
2213        url: ajaxurl,
2214        data: {
2215            'action': 'wpestate_ajax_agent_contact_form',
2216            'name': contact_name,
2217            'email': contact_email,
2218            'phone': contact_phone,
2219            'comment': contact_coment,
2220            'agent_id': agent_id,
2221            'propid': property_id,
2222            'schedule_day': schedule_day,
2223            'schedule_hour': schedule_hour,
2224            'schedule_mode':schedule_mode,
2225            'elementor_wpresidence_form_id': wpresidence_form_id,
2226            'elementor_email_subject': elementor_email_subject,
2227            'is_elementor': is_elementor,
2228            'is_private_message':is_private_message,
2229            'nonce': nonce
2230        },
2231        success: function (data) {
2232
2233            if (data.sent) {
2234                parent.find('#agent_contact_name').val('');
2235                parent.find('#agent_user_email').val('');
2236                parent.find('#agent_phone').val('');
2237                parent.find('#agent_comment').val('');
2238                parent.find('.schedule_day').val('');
2239                parent.find('#schedule_hour').val('');
2240                parent.find('#alert-agent-contact').addClass(' wpestate-agent-contact-sent ').empty().append(data.response);
2241
2242
2243                if (typeof (form_items) !== 'undefined') {
2244                    form_items.each(function () {
2245                        jQuery(this).val('');
2246                    });
2247                }
2248
2249            } else {
2250                parent.find('#alert-agent-contact').empty().append(data.response);
2251            }
2252
2253        },
2254        error: function (errorThrown) {
2255
2256        }
2257    });
2258
2259
2260
2261    jQuery.ajax({
2262        type: 'POST',
2263        //  dataType: 'json',
2264        url: ajaxurl,
2265        data: {
2266            'action': 'wpestate_ajax_agent_contact_form_forcrm',
2267            'name': contact_name,
2268            'email': contact_email,
2269            'phone': contact_phone,
2270            'comment': contact_coment,
2271            'agent_id': agent_id,
2272            'propid': property_id,
2273            'schedule_day': schedule_day,
2274            'schedule_hour': schedule_hour,
2275            'schedule_mode':schedule_mode,
2276            'nonce': nonce
2277        },
2278        success: function (data) {
2279        },
2280        error: function (errorThrown) {
2281
2282        }
2283    });
2284
2285
2286}
2287
2288
2289///////////////////////////////////////////////////////////////////////////////////////////
2290/////// Property page  + ajax call on contact
2291///////////////////////////////////////////////////////////////////////////////////////////
2292
2293
2294function wpestate_enable_share_unit(){
2295   
2296    jQuery('.share_list').unbind('click');
2297    jQuery('.share_list').on( 'click', function(event) {
2298        event.stopPropagation();   
2299        var sharediv=jQuery(this).parent().find('.share_unit');
2300        sharediv.toggle();
2301        jQuery(this).toggleClass('share_on');
2302    });
2303    
2304}
2305
2306function setCookie(cname, cvalue, exdays) {
2307    const d = new Date();
2308    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
2309    let expires = "expires="+d.toUTCString();
2310    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
2311  }
2312
2313
2314function wpestate_enable_not_logged_favorites(){
2315   
2316    var use_favorite_login  =   ajaxcalls_vars.favorites_login;
2317
2318    if(use_favorite_login=="yes"){
2319        return;
2320    }
2321
2322    var current_favorites = window.localStorage.getItem('wpestate_favorites');
2323    setCookie('wpestate_favorites',current_favorites,10);
2324    var prop_ids='';
2325
2326    if( current_favorites!==null ){
2327        prop_ids = jQuery.map(current_favorites.split(','), function(value){
2328            return parseInt(value);
2329        });
2330    }
2331  
2332    jQuery('.icon-fav').each(function(){
2333        var icon=jQuery(this);
2334        var property_id=icon.attr('data-postid');
2335        property_id=parseInt(property_id);
2336        var index = prop_ids.indexOf( property_id );    
2337
2338        if (index > -1) {
2339            icon.removeClass('icon-fav-off').addClass('icon-fav-on');
2340            icon.attr('title', ajaxcalls_vars.remove_fav);
2341    
2342        }else{
2343            icon.removeClass('icon-fav-on').addClass('icon-fav-off');
2344            icon.attr('title', ajaxcalls_vars.add_favorite);
2345    
2346        }
2347    })
2348    
2349
2350    if(jQuery('#add_favorites').length>0){
2351        var property_id=jQuery('#add_favorites').attr('data-postid');
2352        property_id=parseInt(property_id);
2353        var index = prop_ids.indexOf( property_id );    
2354       
2355        if (index > -1) {
2356            jQuery('#add_favorites').removeClass('isnotfavorite').addClass('isfavorite').attr('title', ajaxcalls_vars.remove_favorite);
2357            jQuery('#add_favorites').html('<i class="fas fa-heart"></i>' + ajaxcalls_vars.favorite);
2358    
2359        }  
2360    }
2361    
2362}
2363
2364/**
2365 * Load Agent Listings
2366 * 
2367 * This function handles the loading of agent listings when a term bar item is clicked.
2368 * It updates the active term, fetches new listings via AJAX, and updates the display.
2369 *
2370 * @since 1.0.0
2371 * @package WPResidence
2372 * @subpackage AgentListings
2373 */
2374function wpestate_loade_agent_listings() {
2375    jQuery('.term_bar_item').on('click', function (event) {
2376    
2377
2378        // Cache frequently used selectors
2379        var $this = jQuery(this);
2380        var $listingParent = $this.closest('.single_listing_block');
2381        var $agencyListingsWrapper = jQuery('.agency_listings_wrapper');
2382        var $listingLoader = jQuery('#listing_loader');
2383
2384        // Update UI to show loading state
2385        $listingParent.find('.load_more_ajax_cont .listing_load_more').fadeIn();
2386        $listingLoader.show();
2387
2388        // Update active term
2389        jQuery('.term_bar_item').removeClass('active_term');
2390        $this.addClass('active_term');
2391
2392        // Prepare AJAX data
2393        var ajaxurl = ajaxcalls_vars.admin_url + 'admin-ajax.php';
2394        var $termBarWrapper = jQuery('.term_bar_wrapper');
2395        var data = {
2396            action: 'wpestate_agent_listings',
2397            term_name: $this.data('term_name'),
2398            agent_id: $termBarWrapper.data('agent_id'),
2399            post_id: $termBarWrapper.data('post_id'),
2400            wpestate_no_listins_per_row: jQuery('.wpestate_single_agent_details_wrapper_type2').length > 0 ? 4 : 3,
2401            security: jQuery('#wpestate_agent_listings_nonce').val()
2402        };
2403
2404        // Clear existing listings
2405        $agencyListingsWrapper.empty();
2406
2407        // Perform AJAX request
2408        jQuery.ajax({
2409            type: 'POST',
2410            url: ajaxurl,
2411            data: data,
2412            success: function (response) {
2413                $listingParent.hide();
2414                $listingLoader.hide();
2415                $agencyListingsWrapper.append(response);
2416                wpestate_restart_js_after_ajax();
2417            },
2418            error: function (errorThrown) {
2419                console.error('Error loading agent listings:', errorThrown);
2420                // Optionally, display an error message to the user
2421            }
2422        });
2423    });
2424}

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.