PageSourceSearch

https://cityofdavid.org.il/wp-content/themes/cod/assets/js/custom.js?ver=1790245595

js cityofdavid.org.il collected 2026-09-24 17:34:16 UTC 215,077 bytes, 5,527 lines download raw bytes

1;(function($) {
2
3	$(document).ready(function() {
4
5		var _this = {
6			
7			// Init all data
8			__construct: function() {
9
10				_this.product_slider = $('.product-slider');
11				_this.accordion_item = $('.accordion .title');
12				_this.accordion_item_close = $('.accordion .panel .close-panel');
13				_this.product_review_slider = $('.product-reviews-slider');
14				_this.product_review_slider_open = $('.product-reviews-slider-shadow');
15				_this.play_video_icon = $('.play_video_icon');
16				_this.product_video = $('.product-slider .slider-item video');
17				_this.event_main_gallery = $('.event-gallery .slider-single .item');
18
19				_this.date_picker_section = $('.product-add-to-cart .inner .step-1');
20				_this.product_map_open_btn = $('.product-map');
21				_this.product_map_modal = $('.google-map-modal');
22				_this.add_to_cart_modal_close_btn = $('.cod_modal .close_modal');
23				_this.cart_cross_sales_item = $('.cart-cross-sales ul li');
24				_this.add_to_cart_qty = $('form.variations_form .quantity .qty');
25				_this.children_adults_qty = $('.accommodation-audience.wrap_product_tents .quantity .qty');
26
27				_this.qty_in_cart = $('.quantity.update-product-in-cart .qty');
28				_this.club_select = $('.variations_form select[name=pa_club]');
29				_this.time_select = $('.add_to_cart_time');
30
31				_this.add_to_cart_btn = $('.product-add-to-cart button.add-to-cart');
32				_this.add_go_to_cart_btn = $('.product-add-to-cart button.add-go-to-cart');
33				// club
34				_this.for_club_members_btn = $('.product-add-to-cart button.for-club-members');
35				_this.step_return_btn = $('.product-add-to-cart .step-return');
36				// club -
37				_this.add_to_cart_form_simple_product = $('#product_select_date.simple_product');
38				_this.ajax_url = '/wp-admin/admin-ajax.php';
39
40				_this.load_more_btn = $('.load-more-btn');
41				_this.load_more_btn_search = $('.load-more-btn-search');
42				_this.load_more_btn_search_ml_articles = $('.load-more-btn-search-ml-articles');
43				_this.load_more_btn_search_megalim = $('.load-more-btn-search-megalim');
44				_this.load_more_btn_search_megalim_2 = $('.load-more-btn-search-megalim_2');
45				_this.load_more_btn_search_megalim_institute = $('.load-more-btn-search-megalim-institute');
46				_this.load_more_btn_megalim_media = $('.load-more-btn-search-megalim-media');
47				_this.load_more_btn_search_megalim_academy = $('.load-more-btn-search-megalim-academy');
48				_this.load_more_btn_static = $('.load-more-btn-static');
49
50				_this.search_orderby_select = $('.sort-filter select[name=orderby]');
51				_this.search_type_select = $('.regular-search-form select[name=type]');
52
53				_this.show_event_gallery_btn = $('.past-events');
54				_this.event_gallery_box = $('.event-gallery');
55
56				_this.no_events_btn = $('.no-events-form input[type=email]');
57				_this.footer_subscription_btn = $('.footer-subscription input[type=email]');
58				_this.footer_subscription_label = $('.footer-subscription .animated-placeholder label');
59
60				// _this.schools_lobby_main_filter_btn = $('.schools-lobby .main-tabs a');
61				// _this.schools_lobby_main_filter_btn_new = $('.schools-lobby .main-tabs .filter-button');
62				// _this.schools_sub_filter_btn = $('.schools-lobby .sub-tabs a');
63				_this.schools_sub_filter_btn = $('.schools-lobby .sub-tabs [role="tab"]');
64				_this.product_search_filter_btn = $('.search-products-content .filter-tags a');
65				_this.product_search_form_btn = $('.banner-form .form-btn');
66				_this.product_search_duration_select = $('.banner-form select[name=duration]');
67
68				_this.schools_form_field = $('.schools-contact-form .wpcf7-form-control-wrap input, .ml-form-section .wpcf7-form-control-wrap input');
69
70				_this.select_field = $('.styled-select select');
71				_this.select_autocomplete = $('.autocomplete_select');
72
73				_this.product_select_date_popup = $('#product_select_date select[name=date]');
74
75				_this.open_mobile_menu_btn = $('.col-mobile-menu .pie');
76				_this.mobile_nav = $('.mobile-menu');
77				_this.mobile_open_sub_menu_btn = $('img.mobile-open-sub-menu');
78
79				_this.select_product_time = $('.wrap_product_time input');
80				_this.select_product_time_span = $('.popup_time_list');
81
82				_this.counterAreaVal =  $('.countervalue');
83				_this.careers_lobby_slider = $('.careers-lobby-carousel-slider');
84
85				_this.donationStep1Form = $('#donation-step-1');
86				_this.donationStep2Back = $('.donation-details .back');
87				_this.donationSelect = $('#donation-step-1 .purposes .custom-dropdown');
88				_this.donationRepeaterAdd = $('.donation-details .repeater-container button.add_extra_name');
89				_this.donationRepeater = $('.donation-details .repeater-container');
90
91				_this.bubblesContainer = $('.bubbles-container');
92				_this.bubblesSlider = $('.bubbles-slider');
93				_this.visitedUsVideoBtn = $('.bubbles-slider .item button');
94				_this.mediaVideoBtn = $('.media-lobby-content,.media-latest-clips,.megalim-period-items');
95				_this.visitedUsVideoClose = $('.visited-us-video .close-bubbles');
96
97				_this.media_lobby_slider = $('.latest-clips-slider');
98
99				_this.checkoutForm = $('form.woocommerce-checkout');
100				_this.socialShare = $('.social_button');
101
102				_this.func_term_slider = $('.term-header-slider');
103				_this.renew_time_btn = $('.eoi_renew_time');
104
105				_this.jobApplicationFormFile = $('.job_application_form form input[type=file]');
106				_this.jobApplicationFormTel = $('.job_application_form form input[type=tel]');
107
108				_this.accommodationAudience = $('.accommodation-audience');
109
110				_this.sites_slider = $('.sites-item-gallery');
111				_this.aal_ao_cube_bg_slider = $('.aal-ao-cube-bg-slider');
112				_this.gallery_slider = $('.gallery-slider');
113				_this.select_subscribed_list_btn = $('.subscribe-to-newsletters .choose-list');
114				_this.input_your_list = $('.subscribe-fixed-bottom-bar form input[name=your-lists]');
115
116				_this.home_jewelry = $('.jewelry-slider');
117
118			},
119
120			// Call functions
121			init: function() {
122				_this.__construct();
123				_this.slowScroll();
124				_this.sliders();
125				_this.accordion();
126				_this.product();
127				_this.video();
128				_this.datepicker();
129				_this.quantity();
130				_this.add_to_cart();
131				_this.countdownTimer();
132				_this.loadMore();
133				// _this.schools();
134				_this.filterBoxes();
135				_this.select_2();
136				_this.mobile();
137				_this.counterArea();
138				_this.donation();
139				_this.visited_us();
140				_this.checkoutValidation();
141				_this.social();
142				_this.renewTime();
143				_this.stickyHeader();
144				_this.subscribe();
145
146				_this.price_table_type_2();
147				_this.price_table_type_3();
148				_this.dubbing_languages();
149
150				_this.simpleProduct();
151
152				_this.clubs_flow();
153				_this.guides();
154
155				_this.validationTicketsForProducts();
156
157				_this.cartPopupClubs();
158
159				_this.mountOfOlives();
160				_this.mountOfOlivesForms();
161			},
162
163			mobile: function() {
164
165				_this.open_mobile_menu_btn.on('click', function() {
166					_this.mobile_nav.animate({'right':'0vw'}, 200); 
167					_this.open_mobile_menu_btn.attr('aria-expanded', true);
168					_this.mobile_nav.find('.close_mobile_menu button').focus();
169				});
170
171				_this.mobile_nav.on('click', '.close_mobile_menu button', function() {
172					_this.mobile_nav.animate({'right':'-100vw'}, 200);
173					_this.open_mobile_menu_btn.attr('aria-expanded', false);
174					_this.open_mobile_menu_btn.focus();
175				});
176
177				$(document).on('focusin', function(event) {
178					if (_this.mobile_nav.css('right') === '0px') {
179						$('.home-banner').attr('inert', '');
180						const $menuButton = $('.col-mobile-menu button[aria-expanded]');
181						const $target = $(event.target);
182		                const isInMenu = $target.closest('.mobile-menu').length > 0;
183		                const isMenuButton = $target.is($menuButton) || $target.closest($menuButton).length > 0;
184		                
185		                if (!isInMenu && !isMenuButton) {
186		                	$('.home-banner').removeAttr('inert');
187		                	_this.mobile_nav.animate({'right':'-100vw'}, 200);
188							_this.open_mobile_menu_btn.attr('aria-expanded', false);
189							_this.open_mobile_menu_btn.focus();
190		                }
191					}
192				});
193
194				document.addEventListener('keyup', function(e) {
195				  if (e.keyCode == 27 && _this.open_mobile_menu_btn.attr('aria-expanded') == 'true') {
196				    _this.mobile_nav.animate({'right':'-100vw'}, 200);
197					_this.open_mobile_menu_btn.attr('aria-expanded', false);
198					_this.open_mobile_menu_btn.focus();
199				  }
200				});
201
202				_this.mobile_open_sub_menu_btn.on('click', function() {
203					$(this).parent().toggleClass('open-sub-menu');
204					$(this).next().next().slideToggle();
205
206					var a = $(this).parent().find('> a');
207					if(a.attr('aria-expanded') == 'true'){
208						a.attr('aria-expanded', false);
209					}else{
210						a.attr('aria-expanded', true);
211					}
212				});
213
214				$('.camp_extra_order_btn').on('click', function() {
215					$('#product_select_date .wrap_product_date .single-select').click();
216				});
217
218				$('.mod-training-courses-benefits-content .column-whatsapp').on('click', function() {
219					$(this).find('.mod-training-courses-benefits-wl')[0].click();
220				});
221
222			},
223
224			mountOfOlives: function() {
225
226				jQuery('.mo-grave-card-slider').slick({
227					rtl: jQuery('body').hasClass('rtl'),
228				  	slidesToShow: 1,
229				  	slidesToScroll: 1,
230				  	arrows: true,
231				  	dots: false,
232				  	fade: true,
233				  	prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="40" height="34.667" viewBox="0 0 40 34.667"><defs><filter id="arrow-left" x="0" y="0" width="40" height="34.667" filterUnits="userSpaceOnUse"><feOffset dy="3" input="SourceAlpha"/><feGaussianBlur stdDeviation="4" result="blur"/><feFlood flood-opacity="0.522"/><feComposite operator="in" in2="blur"/><feComposite in="SourceGraphic"/></filter></defs><g id="gallery_arrow_left" data-name="gallery arrow left" transform="translate(12 9)">
233<g transform="matrix(1, 0, 0, 1, -12, -9)" filter="url(#arrow-left)"><path id="arrow-left-2" data-name="arrow-left" d="M17.324,13.233H4.157L8.6,9.43l-1.047-.9L1.324,13.867,7.551,19.2,8.6,18.3l-4.44-3.8H17.323V13.233Z" transform="translate(10.68 0.47)" fill="#fff"/></g></g></svg></button>',
234					nextArrow: '<button type="button" class="slick-next" aria-label="' + customTexts.next + '"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="40" height="34.853" viewBox="0 0 40 34.853"><defs><filter id="arrow-right" x="0" y="0" width="40" height="34.853" filterUnits="userSpaceOnUse"><feOffset dy="3" input="SourceAlpha"/><feGaussianBlur stdDeviation="4" result="blur"/><feFlood flood-opacity="0.522"/><feComposite operator="in" in2="blur"/><feComposite in="SourceGraphic"/></filter></defs><g id="gallery_arrow_right" data-name="gallery arrow right" transform="translate(12 9)"><g transform="matrix(1, 0, 0, 1, -12, -9)" filter="url(#arrow-right)"><path id="arrow-right-2" data-name="arrow-right" d="M20.459,8.534,19.4,9.446l4.5,3.869H10.769v1.29H23.9l-4.5,3.869,1.061.912,6.311-5.426Z" transform="translate(1.23 0.47)" fill="#fff"/></g></g></svg></button>',
235
236				});
237
238				function addDateAriaDescription() {
239			        let $dateInput = $('#styled-select-calendar-input');
240
241			        if ($dateInput.length) {
242			            $dateInput.attr('aria-describedby', 'date-calendar-format');
243
244			            console.log('aria-describedby added:', $dateInput.attr('aria-describedby'));
245			        }
246			    }
247
248			    // Initial
249			    //addDateAriaDescription();
250
251			    // After CF7 / calendar scripts have initialized
252			    setTimeout(addDateAriaDescription, 3000);
253			    setTimeout(addDateAriaDescription, 6000);
254
255				$('.home-mount-of-olives-inner').on('click', function() {
256					const $anchor = $(this).find('a');
257    				if ($anchor.length) $anchor[0].click();
258				});
259
260				$(".text-tombstone .read-more").click(function () {
261			        var textBlock = $(this).siblings(".text-content");
262
263			        if (textBlock.css("-webkit-line-clamp") === "2") {
264			            textBlock.css({
265			                "-webkit-line-clamp": "unset",
266			                "overflow": "visible"
267			            });
268			            $(this).text("קרא פחות"); // Read Less in Hebrew
269			        } else {
270			            textBlock.css({
271			                "-webkit-line-clamp": "2",
272			                "overflow": "hidden"
273			            });
274			            $(this).text("קרא עוד");
275			        }
276			    });
277
278			    $(".mo-search .input input").on("focus blur input", function () {
279			        if ($(this).val().trim() !== "" || $(this).is(":focus")) {
280			            $(this).closest('.input').addClass("active");
281			        } else {
282			            $(this).closest('.input').removeClass("active");
283			        }
284			    });
285
286			    $('.select-year .radio-label input').on('change', function() {
287
288			        var selectedValue = $(this).val();
289
290			        $('.select-year-fields').removeClass('active');
291			        $('.select-year-fields.' + selectedValue).addClass('active');
292			    });
293
294			    $('.select-yob .radio-label input').on('change', function() {
295
296			    	var el_this = $(this);
297			        var selectedValue = el_this.val();
298
299			        el_this.closest('.select-yob').find('.yob-yoi1').removeClass('active');
300			        el_this.closest('.select-yob').find('.yob-yoi1.' + selectedValue).addClass('active');
301			    });
302
303			    $('.select-yoi .radio-label input').on('change', function() {
304
305			        var selectedValue = $(this).val();
306
307			        $('.yob-yoi2').removeClass('active');
308			        $('.yob-yoi2.' + selectedValue).addClass('active');
309			    });
310
311			    // $('.mo-search .advanced-search .show-more').on('click', function() {
312			    // 	$(this).parent().toggleClass('open').find('.advanced-search-inner').slideToggle();
313			    // });
314			    // $('.mo-search .advanced-search > h3').on('click', function() {
315			    // 	$(this).parent().toggleClass('open').find('.advanced-search-inner').slideToggle();
316			    // });
317
318			    $('.mo-search .advanced-search .show-more, .mo-search .advanced-search > h3').on('click keydown', function(e) {
319				    const isClick = e.type === 'click';
320				    const isKey = e.type === 'keydown' && (e.key === 'Enter' || e.key === ' ');
321				    if (!isClick && !isKey) return;
322
323				    e.preventDefault();
324
325				    const $advanced = $(this).closest('.advanced-search');
326				    const $inner = $advanced.find('.advanced-search-inner');
327
328				    $advanced.toggleClass('open');
329
330				    $inner.stop(true, true).slideToggle();
331
332				    const $button = $advanced.find('.show-more');
333				    const expanded = $button.attr('aria-expanded') === 'true';
334				    $button.attr('aria-expanded', !expanded);
335				});
336
337
338			    $('.mo-multiple-select > button').on('click', function() {
339			    	$(this).parent().toggleClass('open');
340			    });
341
342			    $('.mo-multiple-select-options .ss').on('input', function () {
343			        let $input = $(this); // The specific input being typed in
344			        let searchValue = $input.val().toLowerCase(); // Get the input value in lowercase
345			        let $container = $input.closest('.mo-multiple-select-options'); // Get the closest parent container
346
347			        // Filter <p> elements within the same container
348			        $container.find('div').each(function () {
349			            let text = $(this).find('label').text().toLowerCase(); // Get the <p> text in lowercase
350
351			            // Show or hide based on match
352			            if (text.includes(searchValue)) {
353			                $(this).show(); // Show if it matches
354			            } else {
355			                $(this).hide(); // Hide if it doesn't match
356			            }
357			        });
358			    });
359			    $('.mo-multiple-select-options #checkbox-all').on('change', function () {
360					// Get the checked state of the "Select All" checkbox
361				    const isChecked = $(this).prop('checked');
362				    
363				    // Set all other checkboxes in the container to the same state
364				    $('.mo-multiple-select-options .custom-checkbox').not(this).prop('checked', isChecked);
365				    
366				    // Optional: Trigger any other events that might be bound to these checkboxes
367				    $('.mo-multiple-select-options .custom-checkbox').not(this).trigger('change');
368			    });
369
370			    // Add tooltip to specified field
371			    setTimeout(function() {
372					$('.mo-with-tooltip').each(function() {
373				    var $input = $(this);
374				    var tooltipId = 'tooltip-' + Math.random().toString(36).substr(2, 9);
375				    
376				    var tooltipIcon = $('<button type="button" class="cf7-tooltip-icon" aria-describedby="' + tooltipId + '" aria-label="' + customTexts.graveTooltip + '"><span class="mo-tooltip-text" id="' + tooltipId + '" role="tooltip">' + customTexts.graveTooltip + '</span><svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 192 512"><path d="M48 80a48 48 0 1 1 96 0A48 48 0 1 1 48 80zM0 224c0-17.7 14.3-32 32-32l64 0c17.7 0 32 14.3 32 32l0 224 32 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 512c-17.7 0-32-14.3-32-32s14.3-32 32-32l32 0 0-192-32 0c-17.7 0-32-14.3-32-32z"/></svg></button>');
377
378				    $(this).parent().find('.placeholder').addClass('mo-tooltip-placeholder').prepend(tooltipIcon);
379
380				    // Link input to tooltip
381				    $input.attr('aria-describedby', tooltipId);
382
383				    // Show/hide on focus/blur of button
384				    tooltipIcon.on('focus mouseenter', function() {
385				        $(this).find('.mo-tooltip-text').addClass('visible');
386				    }).on('blur mouseleave', function() {
387				        $(this).find('.mo-tooltip-text').removeClass('visible');
388				    });
389
390				    // Also show on input focus
391				    $input.on('focus', function() {
392				        tooltipIcon.find('.mo-tooltip-text').addClass('visible');
393				    }).on('blur', function() {
394				        tooltipIcon.find('.mo-tooltip-text').removeClass('visible');
395				    });
396				});
397									
398				}, 1000);
399
400			    // Define the validation function
401				function validateForm($form) {
402				    var isValid = true;
403				    var dateOptionValid = true;
404
405				    const $submitButton = $form.find('input[type=submit]');
406				    const disabledLabel = $submitButton.data('aria-disabled-label');
407    				const enabledLabel = $submitButton.val();
408				    
409				    $form.find('input.required-field, textarea.required-field, select.required-field').each(function() {
410				        var $field = $(this);
411				        if (!$field.val().trim()) {
412				            isValid = false;
413				        }
414				    });
415
416				    $form.find('input').each(function() {
417				        var $field = $(this);
418				        if ($field.val().trim()) $field.parent().addClass('active');
419				    });
420
421				    if ($form.find('.required-one-select').length) {
422			            
423				    	var $dateSection = $form.find('.required-one-select');
424				        dateOptionValid = false; // Start false when validation is required
425				        
426				        // Check exact date input
427				        if ($dateSection.find('input[name=select-1-exact-date]').val()) {
428				            dateOptionValid = true;
429				        }
430				        // OR check month/day/year selects
431				        else if ($dateSection.find('select[name=select-2-month]').val() && $dateSection.find('select[name=select-2-day]').val()) {
432				            dateOptionValid = true;
433				        }
434				        // OR check Hebrew year select
435				        else if ($dateSection.find('select[name=hebrew-basic-sr-hb-year-born]').val()) {
436				            dateOptionValid = true;
437				        }
438				        // OR check English year select
439				        else if ($dateSection.find('select[name=hebrew-basic-sr-en-year-born]').val()) {
440				            dateOptionValid = true;
441				        }
442
443				    }
444				    
445					const formIsValid = isValid && dateOptionValid;
446
447				    // === ACCESSIBILITY HANDLING ===
448				    if (formIsValid) {
449				        $submitButton
450				            .attr('aria-disabled', 'false')
451				            .attr('aria-label', enabledLabel)
452				            .removeClass('is-disabled');
453				    } else {
454				        $submitButton
455				            .attr('aria-disabled', 'true')
456				            .attr('aria-label', disabledLabel)
457				            .addClass('is-disabled');
458				    }
459
460				    // $submitButton.prop('disabled', !(isValid && dateOptionValid));
461				}
462
463			    $('.mo-search input.required-field, .mo-form-step textarea.required-field, .mo-form-step select.required-field, .mo-search input[name=select-1-exact-date], .mo-search .required-one-select select').on('input change', function() {
464			    
465			    	validateForm($(this).closest('form'));
466
467			    });
468
469			    if ($('form.mo-search').length) {
470			    	setTimeout(function() {
471					    $('form.mo-search').each(function() {
472					        validateForm($(this));
473					    });
474					}, 500);
475				}
476
477				$('form.mo-search').on('submit', function (e) {
478				    const $submitButton = $(this).find('input[type=submit]');
479				    if ($submitButton.attr('aria-disabled') === 'true') {
480				        e.preventDefault();
481				    }
482				});
483
484				// Function to update the existing images display
485				function updateExistingImages(images) {
486				    var $container = jQuery('.mo-existing-images');
487				    var $hiddenField = jQuery('.wpcf7-form input[name=existing_images]');
488				    
489				    // Clear current content
490				    $container.empty();
491				    
492				    // If no images, clear the hidden field and return
493				    if (!images || images.trim() === '') {
494				        $hiddenField.val('');
495				        return;
496				    }
497				    
498				    // Split the images string into an array
499				    var imageArray = images.split(',');
500				    
501				    // Create HTML for each image
502				    imageArray.forEach(function(imageUrl, index) {
503				        if (imageUrl.trim() === '') return;
504				        
505				        // Extract filename from URL
506				        var filename = imageUrl.split('/').pop();
507				        
508				        // Create the HTML element
509				        var $imageElement = jQuery(`
510				            <p class="wpcf7-form-control-wrap documents" style="">
511				                <span class="mfcf7-zl-multifile-name">${filename}&nbsp;</span>
512				                <a href="javascript:void(0);" class="mfcf7_zl_delete_file" style="">
513				                    <span class="delete-file" aria-hidden="true">
514				                        <img draggable="false" role="img" class="emoji" alt="❌" src="https://s.w.org/images/core/emoji/15.1.0/svg/274c.svg">
515				                    </span>
516				                </a>
517				            </p>
518				        `);
519				        
520				        // Add click handler for delete button
521				        $imageElement.find('.mfcf7_zl_delete_file').on('click', function() {
522				            // Remove this image from the array
523				            imageArray.splice(index, 1);
524				            
525				            // Update the hidden field with remaining images
526				            var updatedImages = imageArray.join(',');
527				            $hiddenField.val(updatedImages);
528				            
529				            // Update the display
530				            updateExistingImages(updatedImages);
531				        });
532				        
533				        // Add to container
534				        $container.append($imageElement);
535				    });
536				    
537				    // Update the hidden field with all images
538				    $hiddenField.val(images);
539				}
540
541				$('.product-link[data-grave-id]').each(function() {
542			        var graveId = $(this).data('grave-id');
543			        var cookieName = 'candle_light_' + graveId;
544			        var existingCookie = document.cookie.split(';')
545			            .find(item => item.trim().startsWith(cookieName + '='));
546			        
547			        if (existingCookie) {
548			            $(this).addClass('light').find('span').text("הדלקתי נר");
549			        }
550			    });
551
552				$('.mo-grave-card .location .product-link').on('click', function(e) {
553			        e.preventDefault();
554
555			        if ($(this).hasClass('light')) return;
556
557			        var garveId = $(this).data('grave-id');
558			        var _thisbtn = $(this);
559			        var cookieName = 'candle_light_' + garveId;
560			        
561			        $.ajax({
562			            url: _this.ajax_url,
563			            type: 'POST',
564			            data: {
565			                action: 'save_candle_lighting',
566			                garve_id: garveId
567			            },
568			            success: function(response) {
569			                if(response.success) {
570
571			                	// Set cookie for 24 hours
572				                var expiryDate = new Date();
573				                expiryDate.setTime(expiryDate.getTime() + (24 * 60 * 60 * 1000));
574				                document.cookie = cookieName + '=1; expires=' + expiryDate.toUTCString() + '; path=/';
575
576			                	if (response.data.count < 1000) jQuery('.light_candle_popup .total').hide();
577
578			                    jQuery('.light_candle_popup .total span').text(response.data.formatted_count);
579			                    jQuery('.light_candle_popup').show();
580			                    _thisbtn.addClass('light').find('span').text("הדלקתי נר");
581			                    
582			                    // Sending an event to the Data Layer
583													dataLayer.push({
584													  event: "candle_light",
585													  grave_id: garveId,
586													  page_type: "grave-card",
587													  page_path: location.pathname,
588													  method: "candle",
589													  language: document.documentElement.lang || "he"
590													});
591			                } else {
592			                    alert('Error: ' + response.data);
593			                }
594			            },
595			            error: function(xhr, status, error) {
596			                alert('An error occurred: ' + error);
597			            }
598			        });
599			    });
600
601			    // Function to normalize strings for comparison
602			    function normalizeString(str) {
603			        if (!str) return '';
604			        return str.replace(/&quot;/g, '"')
605			                 .replace(/&#39;/g, "'")
606			                 .replace(/&amp;/g, "&")
607			                 .trim();
608			    }
609			    
610			    // Function to check if two company strings match
611			    function companiesMatch(company1, company2) {
612			        if (!company1 || !company2) return false;
613			        
614			        const norm1 = normalizeString(company1);
615			        const norm2 = normalizeString(company2);
616			        
617			        // Simple exact match comparison
618			        return norm1 === norm2;
619			    }
620
621			    // Function to check if a block matches any in the list
622			    function blockMatches(optionValue, blocksList) {
623			        const normalizedOption = normalizeString(optionValue);
624			        
625			        for (let block of blocksList) {
626			            if (normalizedOption === normalizeString(block)) {
627			                return true;
628			            }
629			        }
630			        return false;
631			    }
632
633			    // Function to update Select2 with filtered options
634			    function updateSelect2Options(allowedBlocks) {
635			        const $select = $('select[name="block-plot2"]');
636			        const currentValue = $select.val();
637			        
638			        // Store all original options if not already stored
639			        if (!$select.data('allOptions')) {
640			            const allOptions = [];
641			            $select.find('option').each(function() {
642			                allOptions.push({
643			                    value: $(this).val(),
644			                    text: $(this).text(),
645			                    company: $(this).data('company')
646			                });
647			            });
648			            $select.data('allOptions', allOptions);
649			        }
650			        
651			        const allOptions = $select.data('allOptions');
652			        
653			        // Clear current options
654			        $select.empty();
655			        
656			        // Add back filtered options
657			        let currentValueStillValid = false;
658			        
659			        allOptions.forEach(function(option) {
660			            // Always add the empty option
661			            if (!option.value) {
662			                $select.append(new Option(option.text, option.value));
663			                return;
664			            }
665			            
666			            // Check if this option should be included
667			            if (allowedBlocks.length === 0 || blockMatches(option.value, allowedBlocks)) {
668			                const newOption = new Option(option.text, option.value);
669			                $(newOption).data('company', option.company);
670			                $select.append(newOption);
671			                
672			                if (option.value === currentValue) {
673			                    currentValueStillValid = true;
674			                }
675			            }
676			        });
677			        
678			        // Restore value if still valid
679			        if (currentValueStillValid) {
680			            $select.val(currentValue);
681			        } else {
682			            $select.val('');
683			        }
684			        
685			        // Refresh Select2
686			        $select.trigger('change');
687			    }
688			    
689			    // When a block is selected
690			    $('select[name="block-plot2"]').on('change', function() {
691			        const selectedOption = $(this).find('option:selected');
692			        const selectedValue = $(this).val();
693			        const selectedCompany = selectedOption.data('company');
694			        
695			        if (!selectedValue) {
696			            // Show all companies if no block is selected
697			            $('.mo-multiple-select-options .company-item').show();
698			            return;
699			        }
700			        
701			        // Hide all company items first
702			        $('.mo-multiple-select-options .company-item').hide().addClass('hidden');
703			        
704			        // Show only the matching company
705			        $('.mo-multiple-select-options .company-item').each(function() {
706			            // Skip the "Select All" item
707			            // if ($(this).find('#checkbox-all').length > 0) {
708			            //     $(this).show(); // Always show Select All
709			            //     return;
710			            // }
711			            
712			            const checkbox = $(this).find('input[type="checkbox"]');
713			            const companyValue = checkbox.val();
714			            
715			            if (companiesMatch(companyValue, selectedCompany)) {
716			                $(this).show().removeClass('hidden');
717			            }
718			        });
719			    });
720
721			    // When companies are selected/deselected
722			    $('.mo-multiple-select-options').on('change', 'input[type="checkbox"]', function() {
723			        // Skip if this is the "Select All" checkbox
724			        if (this.id === 'checkbox-all') return;
725			        
726			        const checkedCompanies = $('.mo-multiple-select-options input[type="checkbox"]:checked').not('#checkbox-all');
727			        
728			        console.log('Checked companies count:', checkedCompanies.length);
729			        
730			        if (checkedCompanies.length === 0) {
731			            // Show all options if no company is selected
732			            updateSelect2Options([]);
733			            return;
734			        }
735			        
736			        // Collect all blocks from checked companies
737			        let allowedBlocks = [];
738			        
739			        checkedCompanies.each(function() {
740			            const companyDiv = $(this).closest('.company-item');
741			            const blocksData = companyDiv.data('blocks');
742			            
743			            console.log('Company blocks data:', blocksData);
744			            
745			            if (blocksData) {
746			                // Split by | to get individual blocks
747			                const blocks = String(blocksData).split('|');
748			                allowedBlocks = allowedBlocks.concat(blocks);
749			            }
750			        });
751			        
752			        console.log('All allowed blocks:', allowedBlocks);
753			        
754			        // Update Select2 with filtered options
755			        updateSelect2Options(allowedBlocks);
756			    });
757
758			},
759
760			mountOfOlivesForms: function() {
761
762			    // Initialize variables
763			    var currentStep = 1;
764			    var totalSteps = $('.mo-form-step').length;
765
766			    // Map of radio button labels to their corresponding values
767			    var dateOptionValues = {
768			        "תאריך מדויק": "1",
769			        "חודש ויום": "2",
770			        "שנה / טווח שנים": "3",
771			        "Exact date": "1",
772			        "Month and Day": "2",
773			        "Year / Year range": "3"
774			    };
775
776			    // Initialize form
777			    function initForm() {
778			        $('.mo-form-step').removeClass('active');
779			        $('.mo-form-step[data-step="1"]').addClass('active');
780			        updateProgressBar();
781			        updateStepAnnouncer(currentStep);
782			        checkStepValidity(currentStep);
783			    }
784
785			    // Update progress bar
786			    function updateProgressBar() {
787			        $('.mo-form-progress-bar-item').removeClass('active completed');
788			        $('.mo-form-progress-bar-item').each(function(index) {
789			            if (index < currentStep - 1) {
790			                $(this).addClass('completed');
791			            }
792			        });
793			        $('.mo-form-progress-bar-item').eq(currentStep - 1).addClass('active');
794			    }
795
796			    // Get numeric value for the selected date option
797			    function getSelectedDateOptionValue() {
798			        if ($('.mo-form-step[data-step="2"] input[name="date-of-death-hebrew"]').length) {
799			            var selectedLabel = $('.mo-form-step[data-step="2"] input[name="date-of-death-hebrew"]:checked').val().trim();
800			            return dateOptionValues[selectedLabel] || "2";
801			        }
802			        else return "2";
803			    }
804
805			    // Validate email format
806			    function isValidEmail(email) {
807			        var regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
808			        return regex.test(email);
809			    }
810
811			    // Validate phone format
812			    function isValidPhone(phone) {
813			        var regex = /^0\d([\d]{0,1})([-]{0,1})\d{8}$/;
814			        return regex.test(phone);
815			    }
816
817			    // Check if current step is valid
818			    function checkStepValidity(step) {
819			        var isValid = true;
820			        var $step = $('.mo-form-step[data-step="' + step + '"]');
821			        var $nextButton = $step.find('.next');
822			        var $submitButton = $step.find('input[type=submit]');
823
824			        switch(step) {
825			            case 1:
826			                $step.find('.wpcf7-validates-as-required').each(function() {
827			                    var $field = $(this);
828			                    if (!$field.val().trim()) {
829			                        isValid = false;
830			                    } else {
831			                        if ($field.attr('type') === 'email' && !isValidEmail($field.val())) {
832			                            isValid = false;
833			                        }
834			                        if ($field.attr('type') === 'tel' && !isValidPhone($field.val())) {
835			                            isValid = false;
836			                        }
837			                    }
838			                });
839			                break;
840
841			            case 2:
842			                $step.find('.wpcf7-validates-as-required').each(function() {
843			                    if (!$(this).val().trim()) {
844			                        isValid = false;
845			                    }
846			                });
847
848			                if ($step.find('.one-option-required input[type="text"]').length) {
849			                    var oneOptionValid = false;
850			                    $step.find('.one-option-required input[type="text"]').each(function() {
851			                        if ($(this).val().trim()) {
852			                            oneOptionValid = true;
853			                        }
854			                    });
855			                } else var oneOptionValid = true;
856
857			                var selectedDateOption = getSelectedDateOptionValue();
858			                var dateOptionValid = false;
859
860			                if (selectedDateOption) {
861			                    switch(selectedDateOption) {
862			                        case "1":
863			                            dateOptionValid = $step.find('select[name="exact-date"]').val() !== "";
864			                            break;
865			                        case "2":
866			                            dateOptionValid = $step.find('select[name="select-2-month"]').val() !== "" &&
867			                                          $step.find('select[name="select-2-day"]').val() !== "";
868			                            break;
869			                        case "3":
870			                            dateOptionValid = $step.find('select[name="select-3-month"]').val() !== "" &&
871			                                          $step.find('select[name="select-3-day"]').val() !== "";
872			                            break;
873			                    }
874			                } else {
875			                    dateOptionValid = false;
876			                }
877
878			                isValid = isValid && dateOptionValid && oneOptionValid;
879			                break;
880
881			            case 3:
882			                break;
883			        }
884
885			        if (isValid) {
886			            $nextButton.prop('disabled', false).removeAttr('aria-disabled').removeAttr('aria-describedby');
887			            $submitButton.prop('disabled', false).removeAttr('aria-disabled').removeAttr('aria-describedby');
888			        } else {
889			            $nextButton.prop('disabled', false).attr('aria-disabled', 'true').attr('aria-describedby', 'mo-form-error-desc');
890			            $submitButton.prop('disabled', false).attr('aria-disabled', 'true').attr('aria-describedby', 'mo-form-error-desc');
891			        }
892
893			        return isValid;
894			    }
895
896			    // Real-time validation for fields
897			    function setupRealTimeValidation() {
898			        $('.mo-form-step input, .mo-form-step textarea, .mo-form-step select').on('input change', function() {
899			            var $field = $(this);
900			            var $step = $field.closest('.mo-form-step');
901			            var step = $step.data('step');
902
903			            $field.removeClass('error');
904
905			            if ($field.prop('required') && !$field.val().trim()) {
906			                $field.addClass('error');
907			            } else if ($field.attr('type') === 'email' && $field.val().trim() && !isValidEmail($field.val())) {
908			                $field.addClass('error');
909			            } else if ($field.attr('type') === 'tel' && $field.val().trim() && !isValidPhone($field.val())) {
910			                $field.addClass('error');
911			            }
912
913			            checkStepValidity(step);
914			        });
915
916			        $('.mo-form-step input[type="radio"]').on('change', function() {
917			            var selectedDateOption = getSelectedDateOptionValue();
918			            jQuery('.mo-radio-options > div').removeClass('active');
919			            jQuery('.mo-radio-options > div.option-' + selectedDateOption).addClass('active');
920			            var $step = $(this).closest('.mo-form-step');
921			            checkStepValidity($step.data('step'));
922			        });
923			    }
924
925
926					function updateStepAnnouncer(step) {
927					    var $form = $('.mo-form-main');
928					    var $step = $form.find('.mo-form-step[data-step="' + step + '"]');
929					    var $announcer = $form.find('.mo-form-step-announcer');
930					    if (!$step.length || !$announcer.length) {
931					        return;
932					    }
933					    var totalSteps = $form.find('.mo-form-step').filter(function() {
934					        return !$(this).hasClass('mo-form-success-step');
935					    }).length;
936					    var stepTitle = $step
937					        .find('.mo-step-title, .mo-step-3-title')
938					        .first()
939					        .text()
940					        .trim();
941					    if (!stepTitle) {
942					        stepTitle = 'שלב ' + step;
943					    }
944					    // Clear first to ensure screen readers detect new message
945					    $announcer.text('');
946							setTimeout(function() {
947							    $announcer.text(
948							        'הגעת לשלב ' + step +
949							        ' מתוך ' + totalSteps +
950							        ': ' + stepTitle
951							    );
952							}, 300);
953					}
954
955			    // Add aria-labels to form selects
956					function setupSelectAriaLabels() {
957					    var selectLabels = {
958					        'select-2-month': 'חודש פטירה',
959					        'select-2-day': 'יום פטירה',
960					        'year-death-he': 'שנת פטירה עברית',
961					        'year-death-en': 'שנת פטירה לועזית',
962					        'year-immigration-he': 'שנת עלייה עברית',
963					        'year-immigration-en': 'שנת עלייה לועזית',
964					        'blok-plot': 'גוש / חלקה',
965					        'hevrat-kadisha': 'חברת קדישא',
966					        'gender': 'מגדר',
967					        'group-affiliation': 'מעמד הנפטר'
968					    };
969
970					    // Set aria-label on native select
971					    $.each(selectLabels, function(name, label) {
972					        var $select = $('.mo-form-step select[name="' + name + '"]');
973					        if ($select.length) {
974					            $select.attr('aria-label', label);
975					        }
976					    });
977
978					    // Set aria-label on Select2 rendered element after full initialization
979					    setTimeout(function() {
980					        $.each(selectLabels, function(name, label) {
981					            var $select = $('.mo-form-step select[name="' + name + '"]');
982					            if ($select.length) {
983					                $select.closest('.styled-select')
984					                    .find('.select2-selection')
985					                    .attr('aria-label', label);
986					            }
987					        });
988					    }, 2000);
989					}
990
991			    // Setup aria-describedby for error messages
992			    function setupAriaDescribedBy() {
993			        $('.mo-form-step .wpcf7-form-control-wrap').each(function() {
994			            var $wrap = $(this);
995			            var fieldName = $wrap.attr('data-name');
996			            var $field = $wrap.find('input, select, textarea').first();
997			            var $error = $wrap.find('.wpcf7-not-valid-tip');
998
999			            if ($field.length && $error.length) {
1000			                var errorId = 'error-' + fieldName;
1001			                $error.attr('id', errorId);
1002			                $field.attr('aria-describedby', errorId);
1003			            }
1004			        });
1005			    }
1006
1007				// Go to next step
1008				$('.mo-form-main').on('click', '.next', function() {
1009				    if ($(this).attr('aria-disabled') === 'true') return;
1010				    if (checkStepValidity(currentStep)) {
1011				        // Hide error messages from current step
1012				        $('.mo-form-step[data-step="' + currentStep + '"] .wpcf7-not-valid-tip').attr('aria-hidden', 'true').hide();
1013				        
1014				        $('.mo-form-step[data-step="' + currentStep + '"]').removeClass('active');
1015				        currentStep++;
1016				        $('.mo-form-step[data-step="' + currentStep + '"]').addClass('active');
1017				        updateProgressBar();
1018				        updateStepAnnouncer(currentStep);
1019				        checkStepValidity(currentStep);
1020				        $('html, body').animate({
1021				            scrollTop: $('.mo-form-step[data-step="' + currentStep + '"]').offset().top - 100
1022				        }, 300);
1023				    }
1024				});
1025
1026				// Go to previous step
1027				$('.mo-form-main').on('click', '.back', function() {
1028				    // Hide error messages from current step
1029				    $('.mo-form-step[data-step="' + currentStep + '"] .wpcf7-not-valid-tip').attr('aria-hidden', 'true').hide();
1030				    
1031				    $('.mo-form-step[data-step="' + currentStep + '"]').removeClass('active');
1032				    currentStep--;
1033				    $('.mo-form-step[data-step="' + currentStep + '"]').addClass('active');
1034				    updateProgressBar();
1035				    updateStepAnnouncer(currentStep);
1036				    $('html, body').animate({
1037				        scrollTop: $('.mo-form-step[data-step="' + currentStep + '"]').offset().top - 100
1038				    }, 300);
1039				});
1040
1041			    $('.mo-form-progress-bar-item').on('click', function(e) {
1042			        e.preventDefault();
1043			        var stepNumber = $(this).find('.number').text();
1044			        if (!$(this).hasClass('completed')) {
1045			            return;
1046			        }
1047			        if ($('.mo-form-step.active').attr('data-step') == $('.mo-form-step').length) {
1048			            return;
1049			        }
1050			        $('.mo-form-step').removeClass('active');
1051			        $('.mo-form-step[data-step="' + stepNumber + '"]').addClass('active');
1052			        currentStep = stepNumber;
1053			        updateProgressBar();
1054			        updateStepAnnouncer(currentStep);
1055			        $('html, body').animate({
1056			            scrollTop: $('.mo-form-step[data-step="' + currentStep + '"]').offset().top - 100
1057			        }, 300);
1058			    });
1059
1060			    // Upload button click
1061			    $('.mo-form-main').on('click', '.styled-upload-button', function() {
1062			        $('.mo-multiple-upload > p input').click();
1063			    });
1064
1065			    $(document).on('wpcf7mailsent', function(event) {
1066			        $('.mo-form-step').removeClass('active');
1067			        $('.mo-form-step[data-step="4"]').addClass('active');
1068			        $('.mo-form-progress-bar-item').removeClass('active').addClass('completed');
1069			        $('.mo-form-progress-bar-item:last-child').addClass('active');
1070			        $('.mo-contact.banner-form').show();
1071			        $('.mo-form-main.contact-us').addClass('sent');
1072			        updateStepAnnouncer(4);
1073			        $('html, body').animate({
1074			            scrollTop: $('.mo-form-step[data-step="4"]').offset().top - 100
1075			        }, 300);
1076			    });
1077
1078			    // Fix focus after Select2 close in form
1079			    $(document).on('select2:close', '.mo-form-step select', function() {
1080			        var $select = $(this);
1081			        setTimeout(function() {
1082			            $select.data('select2').$selection.focus();
1083			        }, 100);
1084			    });
1085
1086			    // Update aria-label on select2-selection after selection
1087			    $(document).on('select2:select select2:unselect', '.mo-form-step select[aria-label]', function(e) {
1088			        var baseLabel = $(this).attr('aria-label');
1089			        var selectedText = e.type === 'select2:select' ? e.params.data.text : '';
1090			        var newLabel = selectedText ? baseLabel + ': ' + selectedText : baseLabel;
1091			        $(this).closest('.styled-select')
1092			            .find('.select2-selection')
1093			            .attr('aria-label', newLabel);
1094			    });
1095
1096			    $(document).on('wpcf7invalid', function() {
1097			        setupAriaDescribedBy();
1098			    });
1099
1100			    $('.mo-form-step input, .mo-form-step select, .mo-form-step textarea').on('blur', function() {
1101			        var $wrap = $(this).closest('.wpcf7-form-control-wrap');
1102			        var fieldName = $wrap.attr('data-name');
1103			        var $error = $wrap.find('.wpcf7-not-valid-tip');
1104			        if ($error.length) {
1105			            var errorId = 'error-' + fieldName;
1106			            $error.attr('id', errorId);
1107			            $(this).attr('aria-describedby', errorId);
1108			        }
1109			    });
1110
1111			    // Initialize
1112			    initForm();
1113			    setupRealTimeValidation();
1114			    setupSelectAriaLabels();
1115
1116			},
1117
1118			cartPopupClubs: function() {
1119
1120				$('.popup-overlay-clubs').on('click', function (event) {
1121	                if (!$(event.target).closest('.popup-box-clubs').length) {
1122	                    $('.popup-overlay-clubs').hide();
1123	                    $('.popup-overlay-clubs .buttons a').attr('href', '#');
1124	                }
1125            	});
1126
1127            	$('.popup-overlay-clubs .close-btn').on('click', function() {
1128            		$('.popup-overlay-clubs').hide();
1129            		$('.popup-overlay-clubs .buttons a').attr('href', '#');
1130            	});
1131
1132            	$('.popup-overlay-clubs .buttons button').on('click', function() {
1133            		$('.popup-overlay-clubs').hide();
1134            		$('.popup-overlay-clubs .buttons a').attr('href', '#');
1135            	});
1136
1137            	$('.product-edit.with-popup a').on('click', function(e) {
1138            		e.preventDefault();
1139            		let href = $(this).attr('href');
1140            		$('.popup-overlay-clubs .buttons a').attr('href', href);
1141            		$('.popup-overlay-clubs').css({'display' : 'flex'});
1142            	});
1143
1144			},
1145
1146			validationTicketsForProducts: function() {
1147			    // Check if 'available_tickets' variable exists
1148			    if (typeof available_tickets !== "undefined") {
1149			        // Check if the container with class 'notice-container-alert' exists
1150			        const $noticeContainer = $(".notice-container-alert");
1151			        if ($noticeContainer.length) {
1152			            // Retrieve the query parameters from the URL
1153			            const urlParams = new URLSearchParams(window.location.search);
1154			            const date = urlParams.get("date");
1155			            const time = urlParams.get("time");
1156
1157			            if (date) {
1158			                let ticketsAvailable = null;
1159			                
1160			                if (time) {
1161			                    // Case 1: Both date and time are provided
1162			                    const dateTimeKey = `${date}-${time}`;
1163			                    
1164			                    // Check if the exact date-time key exists in the available_tickets object
1165			                    if (available_tickets.hasOwnProperty(dateTimeKey)) {
1166			                        ticketsAvailable = available_tickets[dateTimeKey];
1167			                    }
1168			                } else {
1169			                    // Case 2: Only date is provided, find any time slot for that date
1170			                    // Look for keys that start with the date followed by a dash
1171			                    const datePrefix = date + '-';
1172			                    
1173			                    for (const key in available_tickets) {
1174			                        if (key.startsWith(datePrefix)) {
1175			                            ticketsAvailable = available_tickets[key];
1176			                            break; // Use the first found time slot for this date
1177			                        }
1178			                    }
1179			                }
1180
1181			                // If tickets are found and 5 or less, show the notice
1182			                if (ticketsAvailable !== null && ticketsAvailable <= 5) {
1183			                    $noticeContainer.find('.less-5tickets span.left-tickets').text(ticketsAvailable);
1184			                    $noticeContainer.removeClass("hide");
1185			                }
1186			            }
1187			        }
1188			    }
1189			},
1190
1191			validateTotalQuantity: function() {
1192
1193				// Ensure available_tickets variable exists
1194		        if (typeof available_tickets === "undefined") return;
1195
1196		        // Ensure .price_table__body container exists
1197		        const $priceTableBody = $(".price_table__body");
1198		        if (!$priceTableBody.length) return;
1199
1200		        // Ensure .notice-container-alert container exists
1201		        const $alertContainer = $(".notice-container-alert");
1202		        if (!$alertContainer.length) return;
1203
1204		        // Retrieve the selected date and time from the URL
1205		        const urlParams = new URLSearchParams(window.location.search);
1206		        const date = urlParams.get("date");
1207		        const time = urlParams.get("time");
1208
1209		        if (!date) return;
1210
1211			    let availableTicketsForDate = null;
1212			    let dateTimeKey = null;
1213
1214			    if (time) {
1215			        // Case 1: Both date and time are provided
1216			        dateTimeKey = `${date}-${time}`;
1217			        if (available_tickets.hasOwnProperty(dateTimeKey)) {
1218			            availableTicketsForDate = available_tickets[dateTimeKey];
1219			        }
1220			    } else {
1221			        // Case 2: Only date is provided, find any time slot for that date
1222			        const datePrefix = date + '-';
1223			        for (const key in available_tickets) {
1224			            if (key.startsWith(datePrefix)) {
1225			                dateTimeKey = key;
1226			                availableTicketsForDate = available_tickets[key];
1227			                break; // Use the first found time slot for this date
1228			            }
1229			        }
1230			    }
1231
1232			    // If no available tickets found for the date, return
1233			    if (availableTicketsForDate === null) return;
1234
1235		        // Calculate the total quantity from inputs
1236		        let totalQuantity = 0; 
1237		        $priceTableBody.find(".input-text.qty.text").each(function () {
1238		            const value = parseInt($(this).val(), 10) || 0; // Default to 0 if input is empty or invalid
1239		            totalQuantity += value;
1240		        });
1241
1242		        let left_tickets = availableTicketsForDate - totalQuantity;
1243
1244		        $alertContainer.find('.less-5tickets span.left-tickets').text(left_tickets);
1245
1246		        if (left_tickets <= 5) {
1247		        	$alertContainer.removeClass("hide");
1248		        }
1249		        else $alertContainer.addClass("hide");
1250
1251		        // If totalQuantity equals available tickets, show an error message
1252		        if (totalQuantity >= availableTicketsForDate) {
1253		            $alertContainer.find('.less-5tickets').addClass('hide');
1254		            $alertContainer.find('.notice-amount-of-tickets').addClass('error');
1255		            $alertContainer.find('.no-more-tickets').removeClass('hide');
1256
1257		            $priceTableBody.find("button.qty_button.plus").each(function () {
1258			            $(this).attr('disabled', 'disabled');
1259			        });
1260		        }
1261		        else {
1262		        	$alertContainer.find('.less-5tickets').removeClass('hide');
1263		        	$alertContainer.find('.notice-amount-of-tickets').removeClass('error');
1264		            $alertContainer.find('.no-more-tickets').addClass('hide');
1265
1266		            $priceTableBody.find("button.qty_button.plus").each(function () {
1267			            $(this).removeAttr('disabled');
1268			        });
1269		        }
1270    		},
1271
1272			guides: function() {
1273			    function trapFocus(modal) {
1274			        modal.on('keydown.trapFocus', function(e) {
1275			            if (e.key === 'Tab') {
1276			                var focusable = modal.find('button, a, input, select, textarea, [tabindex]:not
1276([tabindex="-1"])').filter(':visible');
1277			                var first = focusable.first()[0];
1278			                var last = focusable.last()[0];
1279			                if (e.shiftKey && document.activeElement === first) {
1280			                    e.preventDefault();
1281			                    last.focus();
1282			                } else if (!e.shiftKey && document.activeElement === last) {
1283			                    e.preventDefault();
1284			                    first.focus();
1285			                }
1286			            }
1287			        });
1288			    }
1289
1290			    function closePopup($popup) {
1291			        const $btn = $popup.prev('.guid-item');
1292			        $popup.addClass('hide').attr('aria-hidden', 'true');
1293			        $popup.off('keydown.trapFocus');
1294			        $btn.attr('aria-expanded', 'false').focus();
1295			    }
1296
1297			    $('.guid-item').on('click', function() {
1298			        const $popup = $(this).parent().find('.guid-more-details');
1299			        $popup.removeClass('hide').attr('aria-hidden', 'false');
1300			        $(this).attr('aria-expanded', 'true');
1301			        $popup.find('.close-popup').focus();
1302			        trapFocus($popup);
1303			    });
1304
1305			    $('.guid-item2').on('click', function() {
1306			        const item = $(this).data('item');
1307			        const $popup = $('.guid-more-details.item-' + item);
1308			        $popup.removeClass('hide').attr('aria-hidden', 'false');
1309			        $(this).attr('aria-expanded', 'true');
1310			        $popup.find('.close-popup').focus();
1311			        trapFocus($popup);
1312			    });
1313
1314			    $('.guid-more-details').on('click', '.close-popup, .close-popup-yellow', function() {
1315			        closePopup($(this).closest('.guid-more-details'));
1316			    });
1317
1318			    $(document).on('keydown', function(e) {
1319			        if (e.key === 'Escape') {
1320			            $('.guid-more-details:not(.hide)').each(function() {
1321			                closePopup($(this));
1322			            });
1323			        }
1324			    });
1325			},
1326
1327			simpleProduct: function() {
1328
1329				jQuery('.open-share-frame').on('click', function() {
1330					jQuery('.simple-product-share-popup').show();
1331				});
1332				jQuery('.simple-product-share-popup .close-popup').on('click', function() {
1333					jQuery('.simple-product-share-popup').hide();
1334				});
1335				jQuery(document).on('click', function(event) {
1336					if ( ! (jQuery(event.target).closest('.simple-product-share-buttons').length !== 0 || jQuery(event.target).closest('.open-share-frame').length !== 0) ) {
1337						jQuery('.simple-product-share-popup').hide();
1338					}
1339				});
1340				jQuery('.simple-product-main-image').slick({
1341					rtl: jQuery('body').hasClass('rtl'),
1342				  	slidesToShow: 1,
1343				  	slidesToScroll: 1,
1344				  	arrows: false,
1345				  	fade: true,
1346				  	asNavFor: '.simple-product-slider'
1347				});
1348				if (jQuery('.simple-product-slider').length) {
1349					jQuery('.simple-product-slider').slick({
1350						rtl: jQuery('body').hasClass('rtl'),
1351					  	slidesToShow: 6,
1352					  	slidesToScroll: 1,
1353					  	asNavFor: '.simple-product-main-image',
1354					  	prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '"><svg xmlns="http://www.w3.org/2000/svg" width="17" height="30" viewBox="0 0 17 30" fill="none"><path d="M2 2L15 15.2503L2 28" stroke="#707070" stroke-width="3.25" stroke-linecap="round" stroke-linejoin="round"/></svg></button>',
1355					  	nextArrow: '<button type="button" class="slick-next" aria-label="' + customTexts.next + '"><svg xmlns="http://www.w3.org/2000/svg" width="17" height="30" viewBox="0 0 17 30" fill="none"><path d="M15 2L2 15.2503L15 28" stroke="#707070" stroke-width="3.25" stroke-linecap="round" stroke-linejoin="round"/></svg></button>',
1356					  	focusOnSelect: true,
1357					  	responsive: [
1358						    {
1359						      breakpoint: 1200,
1360						      settings: {
1361						        slidesToShow: 5,
1362						      }
1363						    },
1364						    {
1365						      breakpoint: 992,
1366						      settings: {
1367						        slidesToShow: 6,
1368						      }
1369						    },
1370						    {
1371						      breakpoint: 768,
1372						      settings: {
1373						        slidesToShow: 5,
1374						      }
1375						    },
1376						    {
1377						      breakpoint: 480,
1378						      settings: {
1379						        slidesToShow: 4,
1380						      }
1381						    }
1382					  	]
1383					});
1384				}
1385				
1386			},
1387
1388			subscribe: function() {
1389
1390				_this.select_subscribed_list_btn.on('click', function() {
1391					$(this).toggleClass('selected');
1392
1393					if ($(this).hasClass('selected')) $(this).find('span.btn-text').text($(this).attr('data-selected'));
1394					else $(this).find('span.btn-text').text($(this).attr('data-original'));
1395
1396					if ($('.subscribe-to-newsletters .choose-list.selected').length == 1 && $(this).hasClass('selected') && $(this).closest('.main-item').length) {
1397						$('html, body').animate({
1398						    scrollTop: $(window).scrollTop() + 300
1399						    //scrollTop: $('.rest-items').offset().top - 100
1400						}, 500);
1401					}
1402
1403					update_subscribe_list($('.subscribe-to-newsletters .choose-list.selected'));
1404				});
1405
1406				function update_subscribe_list(items) {
1407					if (items.length) {
1408						var ids = '';
1409						$.each(items, function(k,v) {
1410							if ($(v).attr('data-list-id')) ids += $(v).attr('data-list-id') + ',';
1411						});
1412						if (ids) ids = ids.slice(0,-1);
1413						_this.input_your_list.val(ids);
1414						_this.input_your_list.closest('.subscribe-fixed-bottom-bar').find('.textual span').text(items.length);
1415						_this.input_your_list.closest('.subscribe-fixed-bottom-bar').show();
1416					} else {
1417						_this.input_your_list.val('');
1418						_this.input_your_list.closest('.subscribe-fixed-bottom-bar').hide();
1419					}
1420				}
1421
1422			},
1423
1424			stickyHeader: function() {
1425
1426				if (jQuery('body').find('.sticky-header').length) {
1427					stickyElem = document.querySelector(".sticky-header");
1428	     
1429				    currStickyPos = stickyElem.getBoundingClientRect().top + window.pageYOffset;
1430				    window.onscroll = function() {
1431				        if(window.pageYOffset > currStickyPos) {
1432				            $(".sticky-header").addClass('sticky');
1433				        } else {
1434				            $(".sticky-header").removeClass('sticky');
1435				        }
1436				    }
1437				}
1438			},
1439
1440			social: function() {
1441				_this.socialShare.on('click', function(a) {
1442					if (a.preventDefault(), "mobile" == jQuery(this).data("facebook")) FB.ui({
1443					    method: "share",
1444					    mobile_iframe: !0,
1445					    href: jQuery(this).data("href")
1446					}, function(a) {});
1447
1448					else if ("email" == jQuery(this).data("site") || "print" == jQuery(this).data("site") || "pinterest" == jQuery(this).data("site")) window.location.href = jQuery(this).attr("href");
1449
1450					else {
1451
1452					    var b = 575,
1453					      	c = 520,
1454					      	d = (jQuery(window).width() - b) / 2,
1455					      	e = (jQuery(window).height() - c) / 2,
1456					      	f = "status=1,width=" + b + ",height=" + c + ",top=" + e + ",left=" + d;
1457
1458					    window.open(jQuery(this).attr("href"), "share", f)
1459
1460					}
1461
1462				});
1463
1464			},
1465
1466			checkoutValidation: function() {
1467
1468				_this.checkoutForm.on('blur', '#billing_first_name, #billing_last_name, #billing_phone, #billing_email, #custom_role', function() {
1469					if ($(this).val() == '') {
1470						$(this).closest('p.validate-required').addClass('woocommerce-invalid');
1471						$(this).closest('p.validate-required').find('.error').show();
1472					}
1473					else {
1474						$(this).closest('p.validate-required').removeClass('woocommerce-invalid');
1475						$(this).closest('p.validate-required').find('.error').hide();
1476					}
1477
1478					if ($(this).attr('type') == 'email') {
1479						var EmailRegex = /^[^\\.]([a-zA-Z0-9_+-.])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
1480
1481  						if (!EmailRegex.test($(this).val()) && $(this).val() != '') {
1482  							$(this).closest('p.validate-required').addClass('woocommerce-invalid');
1483  							$(this).closest('p.validate-required').find('.error-email').show();
1484  						}
1485  						else {
1486  							$(this).closest('p.validate-required').removeClass('woocommerce-invalid');
1487  							$(this).closest('p.validate-required').find('.error-email').hide();
1488  						}
1489					}
1490
1491					if ($(this).attr('type') == 'tel') {
1492						var EmailRegex = /^(([0-9+-]){7,15})$/;
1493
1494  						if (!EmailRegex.test($(this).val()) && $(this).val() != '') {
1495  							$(this).closest('p.validate-required').addClass('woocommerce-invalid');
1496  							$(this).closest('p.validate-required').find('.error-tel').show();
1497  						}
1498  						else {
1499  							$(this).closest('p.validate-required').removeClass('woocommerce-invalid');
1500  							$(this).closest('p.validate-required').find('.error-tel').hide();
1501  						}
1502					}
1503				});
1504
1505			},
1506
1507			visited_us: function() {
1508
1509				var $zone = _this.bubblesContainer;
1510				var canvasWidth = $zone.outerWidth();
1511				var canvasHeight = $zone.outerHeight();
1512				var protection = 1000000;
1513				var counter = 0;
1514
1515				var circleCoordinate = [];
1516
1517				function getAllCoordinates(circles, circleCoordinate) {
1518
1519				  	jQuery.each(circles, function(k,v) {
1520
1521				  		var protection = 0;
1522				  		var diametr_from = (v.size == 'big') ? 190 : ((v.size == 'middle') ? 120 : 70);
1523						var diametr_to = (v.size == 'big') ? 210 : ((v.size == 'middle') ? 140 : 90);
1524
1525				  		while (circleCoordinate.length <= circles.length) {
1526
1527					  		var diametr = generateRandom(diametr_from, diametr_to);
1528					  		var min_w = diametr / 2;
1529						    var min_h = diametr / 2;
1530						    var max_w = canvasWidth - diametr / 2;
1531						    var max_h = canvasHeight - diametr / 2;
1532
1533					  		var circle = {
1534					  			x: generateRandom(min_w, max_w),
1535					  			y: generateRandom(min_h, max_h),
1536					  			diametr: diametr
1537					  		};
1538
1539					  		var overlaping = false;
1540
1541					  		if (circleCoordinate.length) {
1542						  		for (var kk = 0; kk < circleCoordinate.length; kk++) {
1543
1544						  			if (!circleCoordinate[kk]) continue;
1545
1546						  			var x2 = circleCoordinate[kk].x;
1547							 		var y2 = circleCoordinate[kk].y;
1548
1549							 		var r1 = circle.diametr / 2;
1550							 		var r2 = circleCoordinate[kk].diametr / 2
1551
1552						  			var d = getDistance(circle.x, circle.y, x2, y2);
1553						  			var sum = circle.diametr * 0.5 + circleCoordinate[kk].diametr * 0.5;
1554
1555						  			if (d < sum) {
1556						  				overlaping = true;
1557						  				break;
1558						  			}
1559						  		}
1560						  	}
1561
1562					  		if (!overlaping) {
1563					  			circleCoordinate[k] = circle;
1564					  		}
1565
1566					  		protection++;
1567
1568					  		if (protection > 500) break; 
1569
1570					  	}
1571
1572				  	});
1573
1574				  	return circleCoordinate;
1575
1576				}
1577
1578
1579				function getDistance(x1, y1, x2, y2){
1580				    let y = x2 - x1;
1581				    let x = y2 - y1;
1582				    
1583				    return Math.sqrt(x * x + y * y);
1584				}
1585				function getDistance2(x1, y1, x2, y2, r1, r2){
1586				    let x = x2 - x1;
1587				    let y = y2 - y1;
1588				    let diag = Math.sqrt(x * x + y * y);
1589				    let d_r = r1 - r2;
1590				    
1591				    return Math.sqrt(diag * diag - d_r * d_r);
1592				}
1593				function generateRandom(min = 0, max = 100) {
1594
1595				    // find diff
1596				    let difference = max - min;
1597
1598				    // generate random number 
1599				    let rand = Math.random();
1600
1601				    // multiply with difference 
1602				    rand = Math.floor( rand * difference);
1603
1604				    // add with min value 
1605				    rand = rand + min;
1606
1607				    return rand;
1608				}
1609
1610				if (typeof circles !== 'undefined') {
1611
1612					if ($(window).width() > 1100) {
1613						var yyy = getAllCoordinates(circles, circleCoordinate);
1614
1615						$.each(yyy, function(k,v) {
1616							var top = v.y - v.diametr / 2;
1617							var left = v.x - v.diametr / 2;
1618						 	_this.bubblesContainer.append('<li tabindex="0" class="circle '+ circles[k].size +'" data-item="'+k+'" style="left:'+left+'px; top:'+top+'px; width:'+v.diametr+'px; height:'+v.diametr+'px;"><div class="image"><img src="'+circles[k].image.sizes.medium+'" alt="'+circles[k].image.alt+'"></div><p class="name"><span>'+circles[k].name+'</span></p></li>');
1619						});
1620					} 
1621					else {
1622						$('.bubbles-container-main').hide();
1623						$('.bubbles-slider-main').show();
1624					}
1625
1626					_this.bubblesSlider.slick({
1627					  	centerMode: true,
1628					  	//centerPadding: '100px',
1629					  	slidesToShow: 7,
1630					  	dots: false,
1631				 		infinite: true,
1632				 		variableWidth: true,
1633				 		rtl: $('body').hasClass('rtl'),
1634				 		// cssEase: 'ease',
1635				 		prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '"></button>',
1636			  			nextArrow: '<button type="button" class="slick-next" aria-label="' + customTexts.next + '"></button>',
1637					  	responsive: [
1638						    {
1639						      breakpoint: 1024,
1640						      settings: {
1641						        centerMode: true,
1642						        centerPadding: '0px',
1643						        slidesToShow: 5
1644						      }
1645						    },
1646						    {
1647						      breakpoint: 767,
1648						      settings: {
1649						        centerMode: true,
1650						        centerPadding: '0px',
1651						        slidesToShow: 3
1652						      }
1653						    },
1654						    {
1655						      breakpoint: 480,
1656						      settings: {
1657						        centerMode: true,
1658						        centerPadding: '0px',
1659						        slidesToShow: 1
1660						      }
1661						    }
1662					  	]
1663					});
1664
1665					$('.bubbles-arrows button').on('click', function() {
1666						$('.bubbles-container-main').hide();
1667						$('.bubbles-slider').slick('setPosition');
1668						$('.bubbles-slider').slick('slickGoTo', 0);
1669						$('.bubbles-slider-main').show();
1670					});	
1671					$('.bubbles-container .circle').on('click', function() {
1672						var index = $(this).attr('data-item');
1673
1674						$('.bubbles-container-main').hide();
1675						$('.bubbles-slider').slick('setPosition');
1676						$('.bubbles-slider').slick('slickGoTo', index);
1677						$('.bubbles-slider-main').show();
1678					});
1679				}
1680
1681				_this.visitedUsVideoBtn.on('click', function() {
1682					var src = $(this).attr('data-src');
1683
1684					if (src) {
1685						$('.visited-us-video iframe').attr('src', src);
1686						$('.visited-us-video').fadeIn();
1687						$("html, body").animate({ scrollTop: 0 }, 300);
1688					}
1689				});
1690
1691				var last_in_focus;
1692
1693				_this.mediaVideoBtn.on('click', '.play-media', function() {
1694					console.log('mediatttttttest');
1695					var src = $(this).attr('data-src');
1696					var title = $(this).attr('data-title');
1697
1698					if (src) {
1699						$('.visited-us-video iframe').attr('src', src);
1700						$('.visited-us-video .media-title').text(title);
1701						$('.visited-us-video').fadeIn();
1702						//$("html, body").animate({ scrollTop: 0 }, 300);
1703						_this.visitedUsVideoClose.focus();
1704						last_in_focus = $(this);
1705					}
1706				});
1707
1708				_this.visitedUsVideoClose.on('click', function() {
1709					$(this).closest('.visited-us-video').fadeOut().find('iframe').attr('src', '');
1710					if(last_in_focus.length){ last_in_focus.focus(); }
1711				});
1712
1713				document.addEventListener('keydown', function(e) {
1714					//console.log(e);
1715
1716					if (e.key === 'Enter' && (e.target.className == "form-row terms-marketing" || e.target.className == "form-row terms validate-required") ) {
1717				  		$(e.target).find('input').click();
1718				  	}
1719
1720				  	if (e.key === 'Enter' && e.target.className == "form-row application-terms") {
1721				  		$(e.target).find('input').click();
1722				  	}
1723
1724					var isEscapePressed = e.key === 'Escape' || e.keyCode === 27;
1725
1726					if (!isEscapePressed) {
1727				    return;
1728				  }
1729
1730					var modal = $('.visited-us-video');
1731
1732					if (modal.css('display') == 'block') {
1733				  	modal.fadeOut().find('iframe').attr('src', '');
1734				  	if(last_in_focus.length){ last_in_focus.focus(); }
1735				  }
1736				});
1737
1738
1739				const modal = document.querySelector('.visited-us-video'); 
1740				if (modal) {
1741					const focusableElements = 'button, [href], input, select, textarea';
1742					const firstFocusableElement = modal.querySelectorAll(focusableElements)[0];
1743					const focusableContent = modal.querySelectorAll(focusableElements);
1744					const lastFocusableElement = focusableContent[focusableContent.length - 1];
1745
1746
1747					document.addEventListener('keydown', function(e) {
1748					  let isTabPressed = e.key === 'Tab' || e.keyCode === 9;
1749
1750					  if (!isTabPressed) {
1751					    return;
1752					  }
1753
1754					  if (modal.style.display != 'block') {
1755					  	return;
1756					  }
1757
1758					  if (e.shiftKey) {
1759					    if (document.activeElement === firstFocusableElement) {
1760					      lastFocusableElement.focus();
1761					      e.preventDefault();
1762					    }
1763					  } else {
1764					    if (document.activeElement === lastFocusableElement) {
1765					      firstFocusableElement.focus();
1766					      e.preventDefault();
1767					    }
1768					  }
1769					});
1770
1771				}
1772
1773
1774
1775
1776			},
1777
1778			donation: function() {
1779
1780				_this.donationSelect.on('click', '.title-input', function() {
1781					$(this).parent().toggleClass('open'); 
1782				});
1783
1784				_this.donationSelect.on('focus', function() {
1785					$(this).addClass('open'); 
1786				});
1787
1788				_this.donationSelect.on('focusout', function(e) {
1789					if(!$(e.relatedTarget).closest('.open').length){
1790						$(this).removeClass('open'); 
1791					}
1792				});
1793
1794				$(document).mouseup(function(e) {
1795					var container = _this.donationSelect;
1796
1797					if (!container.is(e.target) && container.has(e.target).length === 0) _this.donationSelect.removeClass('open');
1798				});
1799
1800				_this.donationSelect.on('click', '.dropdown-menu-2 .checkbox-container', function() {
1801					var checkboxes = $(this).closest('.dropdown-menu-2').find('input');
1802					var text = '';
1803
1804					$.each(checkboxes, function(k,v) {
1805						if( $(v).is(':checked') ){
1806						    text += $(v).val() + ', ';
1807						}
1808					});
1809
1810					if (text) text = text.slice(0,-2);
1811					else text = _this.donationSelect.find('.default-title').attr('data-default');
1812
1813					_this.donationSelect.find('.default-title').text(text);
1814				});
1815
1816				_this.donationStep1Form.on('input', 'input[name=amount]', function() {
1817					if ($(this).val() < 1) {
1818						$(this).closest('.amount').addClass('error').find('.error').show();
1819					}
1820					else $(this).closest('.amount').removeClass('error').find('.error').hide();
1821				});
1822
1823				_this.donationStep1Form.on('submit', function() {
1824
1825					if ($(this).find('input[name=amount]').val() < 1) {
1826						$(this).find('.amount').addClass('error').find('.error').show();
1827						return false;
1828					} 
1829					else $(this).find('.amount').removeClass('error').find('.error').hide();
1830					
1831					$(this).closest('.donation-start').hide();
1832					$('.donation-details').show();
1833
1834					var amount = $(this).closest('form').find('input[name=amount]').val();
1835					var type = $(this).closest('form').find('input[name=donation-type]').is(':checked');
1836					var months = $(this).closest('form').find('select[name=months] option:checked').val();
1837					var purpose = '';
1838
1839					$(this).closest('form').find('input.purposes:checked').each(function(){
1840    					purpose += $(this).val() + ', ';
1841					});
1842
1843					if (purpose) purpose = purpose.slice(0,-2);
1844
1845					if (type) {
1846						$('.donation-payment .one-time').hide();
1847						$('.donation-payment .monthly').show();
1848						$('.donation-payment .monthly span.total .amount').text(amount);
1849						$('.donation-payment .monthly span.months').text(months);
1850						$('.donation-payment .monthly span.purposes').text(purpose);
1851					}
1852					else {
1853						$('.donation-payment .one-time').show();
1854						$('.donation-payment .monthly').hide();
1855						$('.donation-payment .one-time span.total .amount').text(amount);
1856						$('.donation-payment .one-time span.purposes').text(purpose);
1857					}
1858
1859					$('.donation-payment div.total .amount').text(amount);
1860
1861					if ($('.donation-details form').find('input[name=radio_amount]').length) {
1862						console.log(amount);
1863						$('.donation-details form').find('input[name=radio_amount]').val(amount);
1864						$('.donation-details form').find('input[name=fundName]').val(purpose);
1865
1866						if (type) {
1867							$('.donation-details form').find('input[name=rgsFrequency]').val(months);
1868							$('.donation-details form').find('input[name=rgsCreate]').val("true");
1869						}
1870						else {
1871							$('.donation-details form').find('input[name=rgsFrequency]').val('1');
1872							$('.donation-details form').find('input[name=rgsCreate]').val("false");
1873						}
1874					}
1875
1876					$("html, body").animate({ scrollTop: 0 }, 300);
1877
1878					return false;
1879				});
1880
1881				_this.donationStep2Back.on('click', function() {
1882					$(this).closest('.donation-details').hide();
1883					$('.donation-start').show();
1884					$("html, body").animate({ scrollTop: 0 }, 300);
1885				});
1886
1887				_this.donationRepeaterAdd.on('click', function() {
1888					var label = $(this).closest('.repeater-container').find('.repeater-field label');
1889
1890					if (label.length) {
1891						var last = label.last().clone();
1892						$(this).closest('.repeater-container').find('.repeater-field').append(last);
1893
1894						update_individual_names();
1895					}
1896				});
1897
1898				$('.repeater-field').on('input', 'input', function() {
1899					update_individual_names();
1900				});
1901
1902				function update_individual_names() {
1903					var inputs = _this.donationRepeater.find('.repeater-field input');
1904					var full_name = '';
1905					$.each(inputs, function(k,v) {
1906						if ($.trim($(v).val()) != '') full_name += $(v).val() + '; ';
1907					});
1908					if (full_name) full_name = full_name.slice(0,-2);
1909
1910					_this.donationRepeater.find('input[name=individual_name]').val(full_name);
1911				}
1912
1913				// document.addEventListener( 'wpcf7mailsent', function( event ) {
1914				//   	if ( '1211' == event.detail.contactFormId ) {
1915			 //      		$('.donation-details').hide();
1916			 //      		$('.donation-payment').show();
1917			 //      		$("html, body").animate({ scrollTop: 0 }, 300);
1918				//     }
1919				// }, false );
1920
1921				// document.addEventListener( 'wpcf7mailsent', function( event ) {
1922				//   	if ( '1440' == event.detail.contactFormId ) {
1923			 //      		$('.donation-details').hide();
1924			 //      		$('.donation-payment').show();
1925			 //      		$("html, body").animate({ scrollTop: 0 }, 300);
1926				//     }
1927				// }, false );
1928
1929
1930
1931			},
1932
1933			select_2: function() {
1934
1935				$('.styled-select.with-autocomplete select').each(function() {
1936
1937					var $select = $(this);
1938			        var $container = $select.closest('.styled-select.with-autocomplete');
1939			        var isFirstAsLabel = $container.hasClass('first-as-label');
1940
1941			        var placeholderText = isFirstAsLabel 
1942		            ? $select.find('option:first').text().trim() || 'יישוב *'
1943		            : customTexts.select;
1944
1945					$select.select2({
1946					    dir: $('body').hasClass('rtl') ? 'rtl' : 'ltr',
1947					    minimumResultsForSearch: 5,
1948					    width: '100%',
1949					    theme: 'default styled-select-container',
1950					    placeholder: placeholderText,
1951					    allowClear: !isFirstAsLabel,
1952					    tags: false,
1953					    matcher: function(params, data) {
1954					        // If no search term, return all results
1955					        if (!params.term || params.term.trim() === '') {
1956					            return data;
1957					        }
1958
1959					        // Safely get text (handle undefined cases)
1960					        var text = (data.text || '').toString();
1961					        var searchTerm = (params.term || '').toString();
1962
1963					        // Remove quotes and normalize Hebrew text
1964					        var normalizedText = text.replace(/["×´]/g, '').toLowerCase();
1965					        var normalizedSearchTerm = searchTerm.replace(/["×´]/g, '').toLowerCase();
1966
1967					        // Check if text contains search term
1968					        if (normalizedText.includes(normalizedSearchTerm)) {
1969					            return data;
1970					        }
1971
1972					        // For optgroups or other special cases
1973					        if (data.children) {
1974					            return null;
1975					        }
1976
1977					        // Return null if no match
1978					        return null;
1979					    },
1980					    language: {
1981					        "noResults": function() {
1982					            return customTexts.noResults;
1983					        }
1984					    }
1985					});
1986				});
1987				    
1988			    $('.styled-select:not(.with-autocomplete) select').select2({
1989			        dir: $('body').hasClass('rtl') ? 'rtl' : 'ltr',
1990			        minimumResultsForSearch: Infinity,
1991			        width: '100%',
1992			        theme: 'default styled-select-container',
1993			        selectionCssClass: 'select2-focusable',
1994			    });
1995			    
1996				_this.select_autocomplete.select2({
1997			 		dir: $('body').hasClass('rtl') ? 'rtl' : 'ltr',
1998			 		width : '100%',
1999			 		placeholder: customTexts.city,
2000			 		theme: 'default styled-select-autocomplete styled-select-container',
2001			 		language: {
2002						"noResults": function(){
2003					        return customTexts.noResults;
2004					    }
2005					},
2006				});
2007
2008				if (_this.select_field.length) {
2009					setTimeout(function() {
2010						$.each(_this.select_field, function(k,v) {
2011							var aria_label = $(v).attr('aria-label');
2012
2013							if (aria_label) {
2014								$(v).closest('.styled-select').find('span.select2-selection__rendered').attr('title', aria_label);
2015								$(v).closest('.styled-select').find('span.select2-selection__rendered').attr('aria-label', aria_label);
2016							} 
2017							else {
2018
2019								var selected = $(v).find('option:selected');
2020								banner_form_select2($(selected));
2021							}
2022						});
2023					}, 1000);
2024				}
2025				_this.select_field.on("change", function (e) { 
2026					//setTimeout(function() {
2027						var selected = $(this).find('option:selected');
2028						banner_form_select2($(selected));
2029					//}, 1000);
2030				});
2031
2032				function banner_form_select2($this) {
2033					var text = $this.text();
2034					$this.closest('.styled-select').find('span.select2-selection__rendered').attr('aria-label', text);
2035				}
2036
2037			},
2038
2039			schools: function() {
2040        // "setSelectedTab" - now doing all job
2041
2042			},
2043
2044			getQueryParam: function(param) {
2045		    	$result = '';
2046		    	var search_items = location.search.substr(1).split("&");
2047		    	jQuery.each(search_items, function(k,v) {
2048		    		if (v.split("=")[0] == param) $result = v.split("=")[1];
2049		    	});
2050		    	return $result;
2051			},
2052
2053			filterBoxes: function() {
2054
2055				// _this.schools_sub_filter_btn.on('click', function(e) {
2056			  	// 	e.preventDefault();
2057
2058			  	// 	if ($(this).hasClass('selected')) return;
2059
2060			  	// 	var $filters = $('.main-content-item.active .sub-tabs a'),
2061			    // 		$boxes = $('.main-content-item.active .tab-schools .item');
2062
2063			  	// 	_this.filter_common($(this), $filters, $boxes);
2064
2065			  	// 	console.log('3');
2066			  	// });
2067			  	_this.schools_sub_filter_btn.on('click', function(e) {
2068					    e.preventDefault();
2069
2070					    var $currentTab = $(this);
2071
2072					    if ($currentTab.hasClass('selected')) return;
2073
2074					    var $filters = $('.main-content-item.active .sub-tabs [role="tab"]'),
2075					        $boxes = $('.main-content-item.active .tab-schools .item');
2076
2077					    // визуальное состояние
2078					    $filters
2079					        .removeClass('selected')
2080					        .attr('aria-selected', 'false')
2081					        .attr('tabindex', '-1');
2082
2083					    $currentTab
2084					        .addClass('selected')
2085					        .attr('aria-selected', 'true')
2086					        .attr('tabindex', '0')
2087					        .focus();
2088
2089					    _this.filter_common($currentTab, $filters, $boxes);
2090					});
2091
2092					if (_this.getQueryParam('sub') != '') {
2093					    var filters_1 = $('.schools-lobby .sub-tabs [role="tab"][data-filter="filter-' + _this.getQueryParam('sub') + '"]');
2094					    var $filters = $('.main-content-item.active .sub-tabs [role="tab"]'),
2095					        $boxes = $('.main-content-item.active .tab-schools .item');
2096
2097					    if (filters_1.length) {
2098					        $filters
2099					            .removeClass('selected')
2100					            .attr('aria-selected', 'false')
2101					            .attr('tabindex', '-1');
2102
2103					        filters_1
2104					            .addClass('selected')
2105					            .attr('aria-selected', 'true')
2106					            .attr('tabindex', '0');
2107
2108					        _this.filter_common(filters_1, $filters, $boxes);
2109					    }
2110
2111					    // if (filters_1.length) _this.filter_common(filters_1, $filters, $boxes);
2112
2113					    console.log('4');
2114					}
2115
2116					if (_this.getQueryParam('tab') != '' && jQuery('body').find('#tab-' + _this.getQueryParam('tab')).length) {
2117
2118					    var button = jQuery('#tab-' + _this.getQueryParam('tab'));
2119					    if (button.hasClass('selected')) return;
2120
2121					    var $tabs = button.parent().find('button');
2122
2123					    $tabs
2124					        .removeClass('selected')
2125					        .attr('aria-selected', 'false')
2126					        .attr('tabindex', '-1');
2127
2128					    button
2129					        .addClass('selected')
2130					        .attr('aria-selected', 'true')
2131					        .attr('tabindex', '0')
2132					        .focus();
2133
2134					    console.log('5');
2135
2136					}
2137
2138			  	_this.product_search_filter_btn.on('click', function(e) {
2139			  		e.preventDefault();
2140
2141			  		if ($(this).hasClass('selected')) return;
2142
2143			  		var $filters = $('.search-products-content .filter-tags a'),
2144			    		$boxes = $('.search-products-content .search-list-inner .product-item');
2145
2146			  		_this.filter_common($(this), $filters, $boxes);
2147
2148			  		console.log('6');
2149
2150			  	});
2151
2152			  	$('.schools-lobby').on('keydown', '.sub-tabs [role="tab"]', function(e) {
2153				  var $tabs = $('.main-content-item.active .sub-tabs [role="tab"]');
2154				  var index = $tabs.index(this);
2155
2156				  switch (e.key) {
2157				    case 'ArrowLeft':
2158				    case 'ArrowDown':
2159				      e.preventDefault();
2160				      $tabs.eq((index + 1) % $tabs.length).trigger('click');
2161				      break;
2162
2163				    case 'ArrowRight':
2164				    case 'ArrowUp':
2165				      e.preventDefault();
2166				      $tabs.eq((index - 1 + $tabs.length) % $tabs.length).trigger('click');
2167				      break;
2168
2169				    case 'Home':
2170				      e.preventDefault();
2171				      $tabs.eq(0).trigger('click');
2172				      break;
2173
2174				    case 'End':
2175				      e.preventDefault();
2176				      $tabs.eq($tabs.length - 1).trigger('click');
2177				      break;
2178
2179				    case 'Enter':
2180				    case ' ':
2181				      e.preventDefault();
2182				      $(this).trigger('click');
2183				      break;
2184				  }
2185				});
2186
2187			  	$('.schools-lobby').on('keydown', '.sub-tabs [role="tab"]', function(e) {
2188				  if (e.key === 'Enter' || e.key === ' ') {
2189				    e.preventDefault();
2190				    $(this).trigger('click');
2191				  }
2192				});
2193				
2194			},
2195
2196			filter_common: function($this, $filters, $boxes) {
2197				var $this = $this;
2198			    
2199			    $filters.removeClass('selected');
2200			    $this.addClass('selected');
2201
2202			    var $filterColor = $this.attr('data-filter');
2203
2204			    console.log($filterColor);
2205
2206			    if ($filterColor == 'all') {
2207			      	$boxes.removeClass('is-animated')
2208			        .fadeOut().promise().done(function() {
2209			        	$boxes.addClass('is-animated').fadeIn();
2210			        });
2211			    } else {
2212			    	$boxes.removeClass('is-animated')
2213			        .fadeOut().promise().done(function() {
2214			        	$boxes.filter("." + $filterColor).addClass('is-animated').fadeIn();
2215			        });
2216			    }
2217			    console.log('7');
2218			},
2219
2220			loadMore: function() {
2221
2222				_this.load_more_btn.on('click', function() {
2223
2224					var _btn = $(this);
2225					var per_page = _btn.attr('data-per-page');
2226					var page = parseInt(_btn.attr('data-page')) + 1;
2227					var site = _btn.attr('data-site');
2228					var filter = _btn.attr('data-filter');
2229					var term = _btn.attr('data-term');
2230					var action = _btn.attr('data-action');
2231					var total = per_page * page;
2232
2233					if( ! _btn.hasClass('loading') ) {
2234
2235						_btn.addClass('loading');
2236
2237						$.ajax({
2238							type: "POST",
2239						   	beforeSend:function(){
2240
2241						   	},
2242						   	url: '/wp-admin/admin-ajax.php',
2243						   	data: {
2244						   		'paged': page,
2245						   		'per_page': per_page,
2246						   		'site' : site,
2247						   		'filter' : filter,
2248						   		'term' : term,
2249						   		'action' : action
2250						   	},
2251						   	dataType: 'html',
2252						   	success: function (html, textstatus, xhrReq){
2253								    if (html != '') {
2254								        var $row = _btn.parent().parent().find('.row');
2255								        var countBefore = $row.find('.col-md-4').length;
2256								        $row.append(html);
2257								        _btn.attr('data-page', page);
2258								        if ($row.find('.col-md-4').length < total) _btn.hide();
2259
2260								        // Move focus to first newly added item
2261								        var $newItems = $row.find('.col-md-4').slice(countBefore);
2262								        var $firstLink = $newItems.first().find('a, button').first();
2263								        if ($firstLink.length) {
2264								            $firstLink.focus();
2265								        }
2266								    } else {
2267								        _btn.hide();
2268								    }
2269								    _btn.removeClass('loading');
2270								},
2271						   	error: function() {
2272						   		_btn.removeClass('loading');
2273						   	}
2274						});
2275
2276					}
2277				});
2278				_this.load_more_btn_search_megalim.on('click', function() {
2279					var _btn = $(this);
2280					var per_page = _btn.attr('data-per-page');
2281					var page = parseInt(_btn.attr('data-page')) + 1;
2282					var post_type = _btn.attr('data-post-type');
2283					var search = _btn.attr('data-search');
2284					var tax1_slug = _btn.attr('data-tax1-slug');
2285					var tax2_slug = _btn.attr('data-tax2-slug');
2286					var tax1_id = _btn.attr('data-tax1-id');
2287					var tax2_id = _btn.attr('data-tax2-id');
2288					var orderby = _btn.attr('data-sort');
2289					var action = _btn.attr('data-action');
2290					var total = per_page * page;
2291
2292					if( ! _btn.hasClass('loading') ) {
2293						_btn.addClass('loading');
2294
2295						$.ajax({
2296							type: "POST",
2297						   	beforeSend:function(){},
2298						   	url: '/wp-admin/admin-ajax.php',
2299						   	data: {
2300						   		'paged': page,
2301						   		'per_page': per_page,
2302						   		'post_type': post_type,
2303						   		'search' : search,
2304						   		'tax1_slug': tax1_slug,
2305						   		'tax2_slug': tax2_slug,
2306						   		'tax1_id': tax1_id,
2307						   		'tax2_id': tax2_id,
2308						   		'orderby' : orderby,
2309						   		'action' : action
2310						   	},
2311						   	dataType: 'html',
2312						   	success: function (html, textstatus, xhrReq){
2313						   		if (html != '') {
2314						   			_btn.parent().parent().find('.row').append(html);
2315						   			_btn.attr('data-page', page);
2316						   			var focus_element = parseInt(per_page) * (page - 1) + 1;
2317						   			var the_first_new_div = _btn.parent().parent().find('.row > div:nth-child('+focus_element+')');
2318						   			if (the_first_new_div.length) {
2319						   				the_first_new_div.find('a:last-child').focus();
2320						   			}
2321						   			if (_btn.parent().parent().find('.row .col-md-12').length && _btn.parent().parent().find('.row .col-md-12').length < total) _btn.hide();
2322						   			if (_btn.parent().parent().find('.row .col-md-4').length && _btn.parent().parent().find('.row .col-md-4').length < total) _btn.hide();
2323
2324						   		} else {
2325						   			_btn.parent().parent().find('.row>div:last-child a:last-child').focus();
2326						   			_btn.hide();
2327						   		}
2328						   		_btn.removeClass('loading');
2329						   	},
2330						   	error: function() {
2331						   		_btn.removeClass('loading');
2332						   	}
2333						});
2334					}
2335				});
2336
2337				_this.lo
2337ad_more_btn_search_megalim_2.on('click', function() {
2338				    var _btn = $(this);
2339				    var per_page = parseInt(_btn.attr('data-per-page'));
2340				    var page = parseInt(_btn.attr('data-page')) + 1;
2341				    var post_type = _btn.attr('data-post-type');
2342				    var search = _btn.attr('data-search');
2343				    var tax1_slug = _btn.attr('data-tax1-slug');
2344				    var tax2_slug = _btn.attr('data-tax2-slug');
2345				    var tax3_slug = _btn.attr('data-tax3-slug');
2346				    var tax1_id = _btn.attr('data-tax1-id');
2347				    var tax2_id = _btn.attr('data-tax2-id');
2348				    var tax3_id = _btn.attr('data-tax3-id');
2349				    var orderby = _btn.attr('data-sort');
2350				    var action = _btn.attr('data-action');
2351				    var total = per_page * page;
2352
2353				    if (!_btn.hasClass('loading')) {
2354				        _btn.addClass('loading');
2355
2356				        $.ajax({
2357				            type: "POST",
2358				            url: '/wp-admin/admin-ajax.php',
2359				            data: {
2360				                'paged': page,
2361				                'per_page': per_page,
2362				                'post_type': post_type,
2363				                'search': search,
2364				                'tax1_slug': tax1_slug,
2365				                'tax2_slug': tax2_slug,
2366				                'tax3_slug': tax3_slug,
2367				                'tax1_id': tax1_id,
2368				                'tax2_id': tax2_id,
2369				                'tax3_id': tax3_id,
2370				                'orderby': orderby,
2371				                'action': action
2372				            },
2373				            dataType: 'html',
2374				            success: function(html) {
2375				                if (html !== '') {
2376				                    var $container = _btn.closest('.load-more-archive').prev('.ml-art');
2377				                    $container.append(html);
2378				                    _btn.attr('data-page', page);
2379				                    if ($container.find('.ml-art2-item').length < total) {
2380				                        _btn.hide();
2381				                    }
2382				                } else {
2383				                    _btn.hide();
2384				                }
2385				                _btn.removeClass('loading');
2386				            },
2387				            error: function() {
2388				                _btn.removeClass('loading');
2389				            }
2390				        });
2391				    }
2392				});
2393
2394				_this.load_more_btn_search.on('click', function() {
2395
2396					var _btn = $(this);
2397					var per_page = _btn.attr('data-per-page');
2398					var page = parseInt(_btn.attr('data-page')) + 1;
2399					var pageid =  _btn.attr('data-page-id');
2400					var search = _btn.attr('data-search');
2401					var type = _btn.attr('data-type');
2402					var orderby = _btn.attr('data-sort');
2403					var action = _btn.attr('data-action');
2404					var total = per_page * page;
2405
2406					if( ! _btn.hasClass('loading') ) {
2407
2408						_btn.addClass('loading');
2409
2410						$.ajax({
2411							type: "POST",
2412						   	beforeSend:function(){
2413
2414						   	},
2415						   	url: '/wp-admin/admin-ajax.php',
2416						   	data: {
2417						   		'paged': page,
2418						   		'pageid': pageid,
2419						   		'per_page': per_page,
2420						   		'search' : search,
2421						   		'type' : type,
2422						   		'orderby' : orderby,
2423						   		'action' : action
2424						   	},
2425						   	dataType: 'html',
2426						   	success: function (html, textstatus, xhrReq){
2427
2428						   		if (html != '') {
2429						   			_btn.parent().parent().find('.row').append(html);
2430						   			_btn.attr('data-page', page);
2431
2432						   			var focus_element = parseInt(per_page) * (page - 1) + 1;
2433						   			var the_first_new_div = _btn.parent().parent().find('.row > div:nth-child('+focus_element+')');
2434						   			if (the_first_new_div.length) {
2435						   				the_first_new_div.find('a:last-child').focus();
2436						   			}
2437
2438						   			if (!$('body').hasClass('page-template-template-news')) {
2439							   			if (_btn.parent().parent().find('.row .col-md-12').length && _btn.parent().parent().find('.row .col-md-12').length < total) _btn.hide();
2440							   			if (_btn.parent().parent().find('.row .col-md-4').length && _btn.parent().parent().find('.row .col-md-4').length < total) _btn.hide();
2441							   		}
2442							   		else {
2443							   			if (_btn.parent().parent().find('.row .col-xs-12').length && _btn.parent().parent().find('.row .col-xs-12').length < total) _btn.hide();
2444							   		}
2445						   		} else {
2446						   			_btn.parent().parent().find('.row>div:last-child a:last-child').focus();
2447						   			_btn.hide();
2448						   		}
2449						   		_btn.removeClass('loading');
2450						   	},
2451						   	error: function() {
2452						   		_btn.removeClass('loading');
2453						   	}
2454						});
2455
2456					}
2457				});
2458				_this.load_more_btn_search_ml_articles.on('click', function() {
2459			    var _btn = $(this);
2460			    var per_page = _btn.attr('data-per-page');
2461			    var page = parseInt(_btn.attr('data-page')) + 1;
2462			    var search = _btn.attr('data-search');
2463			    var orderby = _btn.attr('data-sort');
2464			    var action = _btn.attr('data-action');
2465
2466			    if( ! _btn.hasClass('loading') ) {
2467			        _btn.addClass('loading');
2468
2469			        $.ajax({
2470			            type: "POST",
2471			            url: '/wp-admin/admin-ajax.php',
2472			            data: {
2473			                'paged': page,
2474			                'per_page': per_page,
2475			                'search' : search,
2476			                'orderby' : orderby,
2477			                'action' : action,
2478			                // Passing taxonomy filters to AJAX
2479			                'tax1_slug' : _btn.attr('data-tax1-slug'),
2480			                'tax1_id'   : _btn.attr('data-tax1-id'),
2481			                'tax2_slug' : _btn.attr('data-tax2-slug'),
2482			                'tax2_id'   : _btn.attr('data-tax2-id'),
2483			                'tax3_slug' : _btn.attr('data-tax3-slug'),
2484			                'tax3_id'   : _btn.attr('data-tax3-id')
2485			            },
2486			            dataType: 'html',
2487			            success: function (html){
2488			                if (html.trim() != '') {
2489			                    _btn.closest('.media-lobby-content').find('.row').append(html);
2490			                    _btn.attr('data-page', page);
2491			                    
2492			                    // Logic to hide button if no more posts
2493			                    var total_loaded = _btn.closest('.media-lobby-content').find('.row > div').length;
2494			                    // Note: You might want to pass 'data-found-posts' to compare properly
2495			                } else {
2496			                    _btn.hide();
2497			                }
2498			                _btn.removeClass('loading');
2499			            }
2500			        });
2501			    }
2502			});
2503				_this.load_more_btn_search_megalim_institute.on('click', function() {
2504				    var _btn = $(this);
2505				    var per_page = parseInt(_btn.attr('data-per-page'));
2506				    var page = parseInt(_btn.attr('data-page')) + 1;
2507				    var search = _btn.attr('data-search');
2508				    var type = _btn.attr('data-type');
2509				    var period = _btn.attr('data-period');
2510				    var orderby = _btn.attr('data-sort');
2511				    var action = _btn.attr('data-action');
2512				    var total = per_page * page;
2513
2514				    if (!_btn.hasClass('loading')) {
2515				        _btn.addClass('loading');
2516
2517				        $.ajax({
2518				            type: "POST",
2519				            url: '/wp-admin/admin-ajax.php',
2520				            data: {
2521				                'paged': page,
2522				                'per_page': per_page,
2523				                'search': search,
2524				                'type': type,
2525				                'period': period,
2526				                'orderby': orderby,
2527				                'action': action
2528				            },
2529				            dataType: 'html',
2530				            success: function (html) {
2531				                if (html !== '') {
2532				                    var $row = _btn.closest('.load-more-archive').prev('.megalim-period-items').find('.row');
2533				                    $row.append(html);
2534				                    _btn.attr('data-page', page);
2535				                    var focus_element = per_page * (page - 1) + 1;
2536				                    var $first_new = $row.find('> div:nth-child(' + focus_element + ')');
2537				                    if ($first_new.length) {
2538				                        $first_new.find('a:last-child').focus();
2539				                    }
2540
2541				                    if ($row.children().length < total) {
2542				                        _btn.hide();
2543				                    }
2544				                } else {
2545				                    _btn.hide();
2546				                }
2547
2548				                _btn.removeClass('loading');
2549				            },
2550				            error: function() {
2551				                _btn.removeClass('loading');
2552				            }
2553				        });
2554				    }
2555				});
2556				_this.load_more_btn_megalim_media.on('click', function() {
2557			    var _btn = $(this);
2558			    var per_page = parseInt(_btn.attr('data-per-page'));
2559			    var page = parseInt(_btn.attr('data-page')) + 1;
2560			    var search = _btn.attr('data-search');
2561			    var topic = _btn.attr('data-type');
2562			    var action = _btn.attr('data-action');
2563			    var total = per_page * page;
2564
2565			    if (!_btn.hasClass('loading')) {
2566			        _btn.addClass('loading');
2567
2568			        $.ajax({
2569			            type: "POST",
2570			            url: '/wp-admin/admin-ajax.php',
2571			            data: {
2572			                'paged': page,
2573			                'per_page': per_page,
2574			                'search': search,
2575			                'topic': topic,
2576			                'action': action
2577			            },
2578			            dataType: 'html',
2579			            success: function (html) {
2580			                if (html.trim() !== '') {
2581			                    var $row = _btn.closest('.load-more-archive').prev().find('.row');
2582			                    $row.append(html);
2583			                    
2584			                    _btn.attr('data-page', page);
2585			                    if (html.length < 12) {
2586			                        _btn.hide();
2587			                    }
2588			                } else {
2589			                    _btn.hide();
2590			                }
2591			                _btn.removeClass('loading');
2592			            }
2593			        });
2594			    }
2595			});
2596				_this.load_more_btn_search_megalim_academy.on('click', function() {
2597				    var _btn = $(this);
2598				    var per_page = parseInt(_btn.attr('data-per-page'));
2599				    var page = parseInt(_btn.attr('data-page')) + 1;
2600				    var search = _btn.attr('data-search');
2601				    var type = _btn.attr('data-type');
2602				    var period = _btn.attr('data-period');
2603				    var orderby = _btn.attr('data-sort');
2604				    var action = _btn.attr('data-action');
2605				    var found_posts = parseInt(_btn.attr('data-found-posts'));
2606
2607				    if (!_btn.hasClass('loading')) {
2608				        _btn.addClass('loading');
2609
2610				        $.ajax({
2611				            type: "POST",
2612				            url: '/wp-admin/admin-ajax.php',
2613				            data: {
2614				                'paged': page,
2615				                'per_page': per_page,
2616				                'search': search,
2617				                'type': type,
2618				                'period': period,
2619				                'orderby': orderby,
2620				                'action': action
2621				            },
2622				            dataType: 'html',
2623				            success: function (html) {
2624				                if (html !== '') {
2625				                    var $row = _btn.closest('.load-more-archive').prev('.megalim-period-items').find('.row');
2626				                    $row.append(html);
2627				                    _btn.attr('data-page', page); 
2628				                    
2629				                    var focus_element = per_page * (page - 1) + 1;
2630				                    var $first_new = $row.find('> div:nth-child(' + focus_element + ')');
2631				                    if ($first_new.length) {
2632				                        $first_new.find('a:last-child').focus();
2633				                    }
2634				                    if ($row.children().length >
2634= found_posts) { 
2635				                        _btn.hide();
2636				                    }
2637				                } else {
2638				                    _btn.hide();
2639				                }
2640
2641				                _btn.removeClass('loading');
2642				            },
2643				            error: function() {
2644				                _btn.removeClass('loading');
2645				            }
2646				        });
2647				    }
2648				});
2649				_this.load_more_btn_static.on('click', function() {
2650			    var _btn = jQuery(this);
2651			    var container = jQuery('.megalim-period-items .row');
2652			    var hiddenPosts = container.find('.megalim-post-item.hidden-post').slice(0, 6);
2653			    if (hiddenPosts.length > 0) {
2654			        hiddenPosts.fadeIn().removeClass('hidden-post');
2655			    }
2656			    if (container.find('.megalim-post-item.hidden-post').length === 0) {
2657			        _btn.fadeOut();
2658			    }
2659				});
2660
2661				_this.search_orderby_select.on('change', function() {
2662
2663					var sort = $(this).val();
2664
2665					if ($('.regular-search-form').length) {
2666						$('.regular-search-form input[name=orderby]').val(sort);
2667						$('.regular-search-form').submit();
2668					}
2669					else {
2670						var currentUrl = window.location.href;
2671						var url = new URL(currentUrl);
2672						url.searchParams.set("orderby", sort); // setting your param
2673						window.location.href = url.href;
2674					}
2675
2676					if ($('.search-page-products .banner-form').length) {
2677						$('.search-page-products .banner-form .tabs-item.active form input[name=orderby]').val(sort);
2678						$('.search-page-products .banner-form .tabs-item.active form').submit();
2679					}
2680				});
2681
2682				_this.search_type_select.on('change', function() {
2683					$(this).closest('form').submit();
2684				});
2685
2686				// _this.product_search_form_btn.on('click', function() {
2687				// 	$(this).closest('.form-content').find('.tabs-item.active form').submit();
2688				// });
2689				_this.product_search_form_btn.on('click', function(e) {
2690					e.preventDefault();
2691					$(this).closest('.form-content').find('.tabs-item:not(.is-hidden) form').submit();
2692				});
2693
2694				_this.product_search_duration_select.on('change', function() {
2695					var selected_val = $(this).find(":selected").val();
2696
2697					if (selected_val > 0 && selected_val <= 240 && $(this).closest('form').find('select[name=start-time]').length) {
2698						$(this).closest('form').find('select[name=start-time]').parent().show();
2699					} 
2700					else if (selected_val == '' || selected_val > 240 && $(this).closest('form').find('select[name=start-time]').length) {
2701						$(this).closest('form').find('select[name=start-time]').parent().hide();
2702						$(this).closest('form').find('select[name=start-time] option:selected').prop("selected", false);
2703						$(this).closest('form').find('select[name=start-time] option:first').prop("selected", "selected");
2704					}
2705				});
2706
2707			},
2708
2709			renewTime: function() {
2710
2711				_this.renew_time_btn.on('click', function() {
2712
2713					jQuery.ajax({
2714			            type: "POST",
2715			            url: '/wp-admin/admin-ajax.php',
2716			            data: {
2717			                'action' : 'renew_left_time'
2718			            },
2719			            success: function (data){
2720			            	$('.popup_remove_products_from_cart').fadeOut();
2721			            	$('.popup_remove_products_from_cart .countdown-timer').text('03:00');
2722
2723			            	if (previouslyFocusedElement) {
2724					            previouslyFocusedElement.focus();
2725					        }
2726
2727			            	var check_time = setInterval(function() {
2728						        jQuery.ajax({
2729						            type: "POST",
2730						            url: '/wp-admin/admin-ajax.php',
2731						            data: {
2732						                'action' : 'check_left_time'
2733						            },
2734						            success: function (data){
2735						                var result = jQuery.parseJSON(data);
2736						                if (result && result.status == '200') {
2737						                    if (result.left_sec <= 180) {
2738
2739						                    	previouslyFocusedElement = document.activeElement;
2740
2741						                        jQuery('.popup_remove_products_from_cart').show();
2742
2743						                        clearInterval(check_time);
2744
2745						                        var x = setInterval(function() {
2746
2747						                            var time = jQuery('.popup_remove_products_from_cart .countdown-timer').text();
2748						                            var time_array = time.split(":");
2749
2750						                            var total_seconds = parseFloat(time_array[1]) + parseFloat(time_array[0]) * 60;
2751
2752						                            total_seconds = total_seconds - 1;
2753
2754						                            var minutes = Math.floor(total_seconds / 60);
2755						                            var seconds = Math.floor(total_seconds - minutes * 60);
2756						                            seconds = (seconds < 10) ? '0'+seconds : seconds;
2757
2758						                            jQuery('.popup_remove_products_from_cart .countdown-timer').text(minutes + ':' + seconds);
2759
2760						                            // If the count down is finished, write some text
2761						                            if (total_seconds < 0) {
2762						                                clearInterval(x);
2763						                            }
2764						                        }, 1000);
2765						                    }
2766						                }
2767						            },
2768						            error: function() {
2769						                
2770						            }
2771						        });
2772						    }, 30000);
2773			            },
2774			            error: function() {
2775			                
2776			            }
2777			        });
2778
2779				});
2780				$(document).off('click.codIdleClose').on('click.codIdleClose', '.popup_remove_products_from_cart .close_modal', function() {
2781				    _this.renew_time_btn.trigger('click');
2782				});
2783
2784			},
2785
2786			slowScroll: function() {
2787				$('a[href*="#"]')
2788			  	.not('[href="#"]')
2789			  	.not('[href="#0"]')
2790			  	.click(function(event) {
2791			    	if (
2792			      		location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') 
2793			      			&& 
2794			      		location.hostname == this.hostname
2795			    	) {
2796				      	var target = $(this.hash);
2797				      	target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
2798				      	if (target.length) {
2799				      		if (!$(this).hasClass('slider-link')) {
2800					        	event.preventDefault();
2801					        	var mobile_header = ($(window).width() > 992) ? 10 : 70;
2802					        	$('html, body').animate({
2803					          		scrollTop: target.offset().top - mobile_header
2804					        	}, 1000, function() {
2805					          		// Do anything after scroll
2806					        		// var f = target.find('a:visible, button:visible').eq(0);
2807					        		// if(f.length){ f.focus(); }
2808					        	});
2809					        }
2810				      	}
2811				    }
2812
2813			  	});
2814			},
2815
2816			countdownTimer: function() {
2817
2818				if ($('body').find('.notice-countdown').length) {
2819					var max = $('body').find('.notice-countdown').attr('data-max');
2820					var diff = $('body').find('.notice-countdown').attr('data-diff');
2821
2822					if (max != '0' && diff != '0' && max >= diff) {
2823						_this.startCountdownTimer(max, diff);
2824					}
2825					else {
2826
2827						console.log('hide countdown - 1');
2828
2829						$('.notice-countdown').removeClass('open').parent().hide();
2830
2831					}
2832				}
2833
2834			},
2835
2836			startCountdownTimer: function(max, diff) {
2837
2838				var distance = max - diff;
2839
2840				var minutes = Math.floor(distance / 60);
2841				var seconds = Math.floor(distance - minutes * 60);
2842
2843				seconds = (seconds < 10) ? '0'+seconds : seconds;
2844
2845				$('.notice-countdown span').text(minutes + ':' + seconds);
2846				$('.notice-countdown').addClass('open').parent().show();
2847
2848				var x = setInterval(function() {
2849
2850					var time = $('.notice-countdown span').text();
2851					var time_array = time.split(":");
2852
2853					var total_seconds = parseFloat(time_array[1]) + parseFloat(time_array[0]) * 60;
2854
2855					total_seconds = total_seconds - 1;
2856
2857					var minutes = Math.floor(total_seconds / 60);
2858					var seconds = Math.floor(total_seconds - minutes * 60);
2859					seconds = (seconds < 10) ? '0'+seconds : seconds;
2860
2861					$('.notice-countdown span').text(minutes + ':' + seconds);
2862
2863				  	// If the count down is finished, write some text
2864				  	if (total_seconds < 0) {
2865				    	clearInterval(x);
2866				    	$('.notice-countdown').removeClass('opne').parent().hide();
2867
2868				    	console.log('hide countdown');
2869
2870				    	if ($('body').find('.form-pay-page').length) {
2871
2872				    		console.log('start redirect');
2873
2874							if (jQuery('html').attr('lang') == "en-US") window.location.href = window.location.origin + "/en/";
2875							else window.location.href = window.location.origin;
2876						}
2877				  	}
2878				}, 1000);
2879
2880			},
2881
2882			accordion: function() {
2883
2884				_this.accordion_item.on('click', function() {
2885					$(this).closest('.item').toggleClass('open');
2886					$(this).next().slideToggle();
2887
2888					if($(this).attr('aria-expanded') == 'true'){
2889					  $(this).attr('aria-expanded', false);
2890					}else{
2891					  $(this).attr('aria-expanded', true);
2892					}
2893				});
2894
2895				_this.accordion_item_close.on('click', function() {
2896					$(this).closest('.item').toggleClass('open');
2897					$(this).closest('.panel').slideToggle();
2898
2899					if($(this).closest('.item').find('.title').attr('aria-expanded') == 'true'){
2900					  $(this).closest('.item').find('.title').attr('aria-expanded', false);
2901					}else{
2902					  $(this).closest('.item').find('.title').attr('aria-expanded', true);
2903					}
2904				});
2905
2906			},
2907
2908			add_to_cart: function() {
2909
2910				_this.add_to_cart_btn.on('click', function() { 
2911
2912					$('.error-not-availbale-tickets').text("").hide();
2913
2914					//if (parseFloat($(this).parent().find('.total_price span').text()) <= 0) {
2915					if (validate_selected_tickets() === false) {
2916						//alert("נא לבחור כרטיסים");
2917						$(this).parent().find('.error-empty-tickets').show();
2918						$('form.variations_form .price_table').addClass('empty-tickets');
2919						return;
2920					} 
2921					else {
2922						$(this).parent().find('.error-empty-tickets').hide();
2923						$('form.variations_form .price_table').removeClass('empty-tickets');
2924					}
2925
2926					if ($('.select_club_form.active').length) {
2927						var club_error_text = ($('body').hasClass('rtl')) ? "יש להזין קוד מועדון" : "Please enter a discount code";
2928						$('.error-not-availbale-tickets').text(club_error_text).show();
2929						return;
2930					}
2931
2932					var _this_btn = $(this);
2933
2934					_this_btn.attr('disabled', 'disabled').addClass('loading').removeClass('added');
2935					$('.product-add-to-cart .notice-container').hide().find('.notice').removeClass('open');
2936
2937					$('.error-not-availbale-tickets').text("").hide();
2938
2939					var form_data = _this_btn.closest('.product-add-to-cart').find('form.variations_form').serialize();
2940
2941					$.ajax({
2942						type: "POST",
2943					   	beforeSend:function(){
2944					   		
2945					   	},
2946					   	url: _this.ajax_url,
2947					   	data: form_data,
2948					   	success: function (html, textstatus, xhrReq){
2949					   		var result = $.parseJSON(html);
2950					   		if (result && result.error) {
2951					   			_this_btn.removeAttr('disabled').removeClass('loading').removeClass('added');
2952					   			alert(result.error[0]);
2953					   		} 
2954					   		else if (result && result.notify) {
2955					   			_this_btn.removeAttr('disabled').removeClass('loading').removeClass('added');
2956					   			$('.product-add-to-cart .notice-container').show().find('.group-tour-notice').addClass('open');
2957
2958					   			if(window.matchMedia("(max-width: 767px)").matches){ $('html, body').animate({scrollTop:0}, 500);}
2959					   		}
2960					   		else if (result && result.notify2) {
2961					   			_this_btn.removeAttr('disabled').removeClass('loading').removeClass('added');
2962					   			$('.error-not-availbale-tickets').text(result.notify2[0]).show();
2963					   		}
2964					   		else if (result && result.success == 200) {
2965
2966					   			var product_main_title = result.data['title'];
2967					   			var fixed_main_title = product_main_title.replace('&quot;','"');
2968
2969					   			_this_btn.removeAttr('disabled').removeClass('loading').addClass('added');
2970					   			$('.variations_form input[name=edit]').val('true');
2971
2972					   			var product_main_prod_title = result.data?.prod_title || '';
2973                                var fixed_main_prod_title = product_main_prod_title.replace('&quot;', '"');
2974					   			$('.shopping_cart_modal .prod-name').text(fixed_main_prod_title);
2975					   			// $('.shopping_cart_modal .main_product_title').text(fixed_main_title);
2976					   			$('.shopping_cart_modal .date').text(result.data['date'] + ' ' + result.data['time']);
2977					   			$('.shopping_cart_modal .ticket_info').text(result.data['label']);
2978					   			$('.shopping_cart_modal .main_product_price span').text(result.data['total_price']);
2979					   			$('.shopping_cart_modal .main_product_image img').attr('src', result.data['image_url']);
2980
2981					   			if (result.data['site'] != '') $('.shopping_cart_modal .location').text(result.data['site']);
2982					   			else $('.shopping_cart_modal .location').hide();
2983
2984					   			if (result.data['crosssales']) {
2985					   				if (result.data['crosssales'][1]) {
2986					   					var product_title = result.data['crosssales'][1]['title'];
2987					   					var fixed_title = product_title.replace('&quot;','"');
2988					   					$('.shopping_cart_modal .cross_sales_products .item1').show();
2989					   					$('.shopping_cart_modal .cross_sales_products .item1 img').attr('src', result.data['crosssales'][1]['image']);
2990					   					$('.shopping_cart_modal .cross_sales_products .item1 .title-c').attr('href', result.data['crosssales'][1]['url']);
2991					   					$('.shopping_cart_modal .cross_sales_products .item1 .title-c').text(fixed_title);
2992					   					$('.shopping_cart_modal .cross_sales_products .item1 .subtitle').text(result.data['crosssales'][1]['site']);
2993					   					$('.shopping_cart_modal .cross_sales_products .item1 .link').attr('href', result.data['crosssales'][1]['url']);
2994					   				} 
2995					   				else $('.shopping_cart_modal .cross_sales_products .item1').hide();
2996					   				
2997					   				if (result.data['crosssales'][2]) {
2998					   					var product_title = result.data['crosssales'][2]['title'];
2999					   					var fixed_title = product_title.replace('&quot;','"');
3000					   					$('.shopping_cart_modal .cross_sales_products .item2').show();
3001					   					$('.shopping_cart_modal .cross_sales_products .item2 img').attr('src', result.data['crosssales'][2]['image']);
3002					   					$('.shopping_cart_modal .cross_sales_products .item2 .title-c').attr('href', result.data['crosssales'][2]['url']);
3003					   					$('.shopping_cart_modal .cross_sales_products .item2 .title-c').text(fixed_title);
3004					   					$('.shopping_cart_modal .cross_sales_products .item2 .subtitle').text(result.data['crosssales'][2]['site']);
3005					   					$('.shopping_cart_modal .cross_sales_products .item2 .link').attr('href', result.data['crosssales'][2]['url']);
3006					   				}
3007					   				else $('.shopping_cart_modal .cross_sales_products .item2').hide();
3008
3009					   			} else $('.shopping_cart_modal .cross_sales_products').hide();
3010
3011					   			$( document.body ).trigger( 'wc_fragment_refresh' );
3012
3013					   			_this.focusable_elements_popup();
3014
3015					   			$('.shopping_cart_modal').fadeIn();
3016					   			$('.shopping_cart_modal .close_modal').focus();
3017
3018					   			_this.startCountdownTimer($('body').find('.notice-countdown').attr('data-max'), 0);
3019								
3020					   		} 
3021					   		else {
3022					   			_this_btn.removeAttr('disabled').removeClass('loading').removeClass('added');
3023					   		}
3024
3025					   	},
3026					   	error: function() {
3027					   		_this_btn.removeAttr('disabled').removeClass('loading').removeClass('added');
3028					   	}
3029					});
3030				});
3031
3032				// club
3033				_this.for_club_members_btn.on('click', function() {
3034					$(this).closest('.product-add-to-cart').addClass('club-view');
3035					$('.select_club_container').each(function(){
3036						$(this).closest('.price_row').addClass('row-club-view');
3037					});
3038					return;
3039				});
3040				_this.step_return_btn.on('click', function() {
3041					$(this).closest('.product-add-to-cart').removeClass('club-view');
3042					$('.select_club_container').each(function(){
3043						$(this).closest('.price_row').removeClass('row-club-view');
3044					});
3045					return false;
3046				});
3047				// club-
3048
3049				_this.add_go_to_cart_btn.on('click', function() {
3050
3051					$('.error-not-availbale-tickets').text("").hide();
3052
3053					//if (parseFloat($(this).parent().find('.total_price span').text()) <= 0) {
3054
3055					if (validate_selected_tickets() === false) {
3056						//alert("נא לבחור כרטיסים");
3057						$(this).parent().find('.error-empty-tickets').show();
3058						$('form.variations_form .price_table').addClass('empty-tickets');
3059						return;
3060					} 
3061					else {
3062						$(this).parent().find('.error-empty-tickets').hide();
3063						$('form.variations_form .price_table').removeClass('empty-tickets');
3064					}
3065
3066					if ($('.select_club_form.active').length) {
3067						var club_error_text = ($('body').hasClass('rtl')) ? "יש להזין קוד מועדון" : "Please enter a discount code";
3068						$('.error-not-availbale-tickets').text(club_error_text).show();
3069						return;
3070					}
3071
3072					var _this_btn = $(this);
3073
3074					_this_btn.attr('disabled', 'disabled').addClass('loading').removeClass('added');
3075					$('.product-add-to-cart .notice-container').hide().find('.notice').removeClass('open');
3076					$('.error-not-availbale-tickets').text("").hide();
3077					var form_data = _this_btn.closest('.product-add-to-cart').find('form.variations_form').serialize();
3078
3079					$.ajax({
3080						type: "POST",
3081					   	beforeSend:function(){
3082
3083					   	},
3084					   	url: _this.ajax_url,
3085					   	data: form_data,
3086
3087					   	success: function (html, textstatus, xhrReq){
3088					   		var result = $.parseJSON(html);
3089					   		if (result && result.error) {
3090					   			_this_btn.removeAttr('disabled').removeClass('loading').removeClass('added');
3091					   			alert(result.error[0]);
3092					   			console.log(result.error);
3093					   		} 
3094					   		else if (result && result.notify) {
3095					   			_this_btn.removeAttr('disabled').removeClass('loading').removeClass('added');
3096					   			$('.product-add-to-cart .notice-container').show().find('.group-tour-notice').addClass('open');
3097					   			if(window.matchMedia("(max-width: 767px)").matches){ $('html, body').animate({scrollTop:0}, 500);}
3098					   		}
3099					   		else if (result && result.notify2) {
3100                  				_this_btn.removeAttr('disabled').removeClass('loading').removeClass('added');
3101                  				$('.error-not-availbale-tickets').text(result.notify2[0]).show();
3102               				}
3103					   		else if (result && result.success == 200) {
3104					   			if (jQuery('html').attr('lang') == "en-US") {
3105					   				window.location.href = window.location.origin + "/en/" + "/checkout/";
3106					   			} else { 
3107					   				window.location.href = window.location.origin + "/checkout/";
3108					   			}
3109					   		} 
3110					   		else {
3111					   			_this_btn.removeAttr('disabled').removeClass('loading').removeClass('added');
3112					   		}
3113					   	},
3114
3115					   	error: function() {
3116					   		_this_btn.removeAttr('disabled').removeClass('loading').removeClass('added');
3117					   	}
3118					});
3119				});
3120
3121				_this.add_to_cart_form_simple_product.on('submit', function() {
3122
3123					var _this_btn = $(this).find('button[type=submit]');
3124
3125					_this_btn.attr('disabled', 'disabled').addClass('loading').removeClass('added');
3126					$('.product-add-to-cart .notice-container').hide().find('.notice').removeClass('open');
3127
3128					var form_data = $(this).serialize();
3129
3130					$.ajax({
3131						type: "POST",
3132					   	beforeSend:function(){
3133					   		
3134					   	},
3135					   	url: _this.ajax_url,
3136					   	data: form_data,
3137					   	success: function (response, textstatus, xhrReq){
3138					   		window.location.href = response;
3139					   		_this_btn.removeAttr('disabled').removeClass('loading').removeClass('added');
3140					   	},
3141					   	error: function() {
3142					   		_this_btn.removeAttr('disabled').removeClass('loading').removeClass('added');
3143					   	}
3144					});
3145
3146					return false;
3147
3148				});
3149
3150				function validate_selected_tickets() {
3151
3152					var inputs = $('.price_table__body input.qty');
3153					var selected_tickets = false;
3154
3155					if (inputs.length) {
3156						$.each(inputs, function(k,v) {
3157							if ($(v).val() > 0) selected_tickets = true;
3158						});
3159					}
3160
3161					return selected_tickets;
3162
3163				}
3164
3165				_this.select_product_time.on('click', function() {
3166					if ( ! $(this).closest('.wrap_product_time').hasClass('open') ) {
3167						$(this).next().show();
3168						$(this).closest('.wrap_product_time').addClass('open');
3169					}
3170					else {
3171						$(this).next().hide();
3172						$(this).closest('.wrap_product_time').removeClass('open');
3173					}
3174				});
3175				_this.select_product_time_span.on('click', 'span', function() {
3176					if (!$(this).hasClass('selected')) {
3177						$(this).parent().find('span.selected').removeClass('selected');
3178						$(this).addClass('selected');
3179						var time = $(this).text();
3180						$(this).closest('.wrap_product_time').find('input[name=time]').val(time);
3181					}
3182					$(this).closest('.wrap_product_time').removeClass('open').find('.popup_t
3182ime_list').hide();
3183				});
3184
3185				_this.product_select_date_popup.on('change', function() {
3186
3187					var available_dates = $(this).find(':selected').attr('data-time');
3188
3189					if (available_dates) {
3190
3191						var splitted = available_dates.split(',');
3192						var html = '';
3193
3194						$.each(splitted, function(k,v) {
3195							var selected = (k == 0) ? ' selected' : '';
3196							html += '<option value="' + v + '"' + selected + '>' + v + '</option>';
3197						});	
3198
3199						$(this).closest('form').find('select[name=time]').html(html);
3200					}
3201					else if ($(this).closest('form').find('select[name=time]').length) {
3202						$(this).closest('form').find('select[name=time]').html('');
3203					}
3204				});
3205
3206			},
3207
3208			product: function() {
3209
3210				_this.product_review_slider_open.on('click', '.open-t, .close-t', function() {
3211					$(this).parent().toggleClass('open');
3212					$(this).closest('.product-reviews').toggleClass('open');
3213				});
3214
3215				_this.date_picker_section.on('click', '.head button', function() {
3216					$(this).closest('.step-1').toggleClass('open').find('.body').slideToggle();
3217					$(this).attr('aria-expanded', true);
3218				});
3219				_this.date_picker_section.on('click', '.body .close_datepicker', function() {
3220					$(this).closest('.step-1').find('.body').slideToggle().promise().done(function() {
3221						$(this).closest('.step-1').toggleClass('open');
3222						$(this).closest('.step-1').find('.head button').attr('aria-expanded', false);
3223					});
3224				});
3225
3226				_this.time_select.on('change', function() {
3227					$('form.variations_form input[name=selected_time]').val($(this).val());
3228				    $('.add-to-cart-sidebar .selected_time').text($(this).val());
3229
3230				    update_max_tickets_for_single_new($('form.variations_form input[name=selected_date]').val(), $('form.variations_form input[name=selected_time]').val());
3231				});	
3232
3233				function update_max_tickets_for_single_new(new_date, time = '') {
3234
3235					if(typeof available_tickets !== 'undefined'){
3236
3237						var max_tickets = 999;
3238						var new_date_and_time = (time) ? new_date + "-" + time : new_date;
3239
3240						if (typeof available_tickets[new_date_and_time] != "undefined") {
3241
3242							var new_max_tickets = available_tickets[new_date_and_time];
3243							if (new_max_tickets < max_tickets) max_tickets = new_max_tickets;
3244
3245						}
3246
3247						$.each($('.price_table__body input.qty'), function(k,v) {
3248							$(v).attr('max', max_tickets);
3249						});
3250
3251					}
3252
3253				}
3254
3255				var previouslyFocusedElement = null;
3256				_this.product_map_open_btn.on('click', function() {
3257				    previouslyFocusedElement = document.activeElement;
3258				    _this.product_map_modal.show();
3259				    _this.product_map_modal.find('.close_modal').focus();
3260				});
3261
3262				_this.product_map_modal.on('click', 'button.close_modal', function() {
3263				    $(this).closest('.google-map-modal').hide();
3264				    if (previouslyFocusedElement) {
3265				        previouslyFocusedElement.focus();
3266				    }
3267				});
3268
3269				_this.product_map_modal.on('keydown', function(e) {
3270				    if (e.key === 'Escape') {
3271				        $(this).hide();
3272				        if (previouslyFocusedElement) {
3273				            previouslyFocusedElement.focus();
3274				        }
3275				    }
3276				    if (e.key === 'Tab') {
3277				        var focusable = $(this).find('button, iframe, [tabindex]:not([tabindex="-1"])').filter(':visible');
3278				        var first = focusable.first()[0];
3279				        var last = focusable.last()[0];
3280				        if (e.shiftKey && document.activeElement === first) {
3281				            e.preventDefault();
3282				            last.focus();
3283				        } else if (!e.shiftKey && document.activeElement === last) {
3284				            e.preventDefault();
3285				            first.focus();
3286				        }
3287				    }
3288				});
3289				
3290				_this.add_to_cart_modal_close_btn.on('keypress', function(event) {
3291			        if (event.keyCode === 13) {
3292			            $(this).click();
3293			        }
3294			    });
3295
3296				document.addEventListener('keydown', function(e) {
3297					var isEscapePressed = e.key === 'Escape' || e.keyCode === 27;
3298
3299					if (!isEscapePressed) {
3300				    return;
3301				  }
3302
3303				  _this.add_to_cart_modal_close_btn.closest('.cod_modal').fadeOut();
3304				  _this.add_to_cart_btn.focus();
3305				});
3306
3307				_this.club_select.on('change', function() {
3308
3309					var form = $(this).closest('form');
3310					var selected_option = $(this).find('option:selected').val();
3311					var selected_option_text = $(this).find('option:selected').text();
3312					var rows = form.find('.price_table__body .price_row');
3313
3314					form.find('.price_table').removeClass('empty-tickets');
3315					$('.error-empty-tickets').hide();
3316
3317					// if (selected_option == "non-customer-club-en" || selected_option == "non-customer-club") $(this).closest('form').find('p.notice').hide();
3318					// else $(this).closest('form').find('p.notice').show();
3319
3320					if (rows.length) {
3321
3322						$.each(rows, function(k,v) {
3323							// $(v).find('input.qty').val(0);
3324							// $(v).find('input.qty').change();
3325							if ($(v).hasClass('club_' + selected_option)) $(v).show();
3326							else $(v).hide();
3327						});
3328
3329					}
3330
3331					$(this).closest('form').find('p.notice').hide();
3332
3333					if ($(this).closest('form').find('p.notice[data-club="'+ selected_option_text +'"]').length) {
3334						$(this).closest('form').find('p.notice[data-club="'+ selected_option_text +'"]').show();
3335					}
3336
3337					// var form = $(this).closest('form');
3338					// var selected_club = $(this).val();
3339					// var data = $.parseJSON($(this).closest('form').attr('data-product_variations'));
3340
3341					// $.each(data, function(k,v) {
3342					// 	if (selected_club == v['attributes']['attribute_pa_club']) {
3343
3344					// 		var ticket_type = v['attributes_ids']['attribute_pa_ticket-type'];
3345					// 		var ticket_row = form.find('.variation_' + ticket_type);
3346
3347					// 		if (ticket_row.length) {
3348					// 			$(ticket_row).find('.price').html(v['price_html']);
3349					// 			$(ticket_row).find('.pr_var_id').val(v['variation_id']);
3350					// 			$(ticket_row).find('.quantity').attr('data-price', v['display_price']);
3351
3352					// 			_this.calculate_total_price_row(ticket_row);
3353					// 		}
3354					// 	}
3355					// });	
3356
3357					// _this.calculate_total_price();
3358				});
3359
3360			},
3361
3362			calculate_rows_prices: function(){
3363			    let totalDiscountedUnits = 0;
3364			    let applied_discount_xx = 0;
3365
3366			    // Get all products and their quantity
3367			    let products = $('.price_table .price_row').map(function() {
3368
3369			    	let price = parseFloat($(this).find('.quantity').attr('data-display-regular-price'));
3370			    	let init_price = parseFloat($(this).find('.quantity').attr('data-display-init-price'));
3371			    	let sf_discount_price = parseFloat($(this).find('.quantity').attr('data-price'));
3372			    	let var_id = ($(this).find('.pr_var_id').length) ? parseInt($(this).find('.pr_var_id').val()) : 0;
3373			    	let var_sku = $(this).attr('data-sku');
3374			    	let quantity = parseInt($(this).find('.qty').val(), 10);
3375			    	let quantity_var = 0;
3376			    	var variations = [];
3377
3378			    	if ($(this).find('.select_club_container .single-applied-code.applied').length) {
3379			    		$.each($(this).find('.select_club_container .single-applied-code.applied'), function(k,v) {
3380			    			quantity_var += parseInt($(v).find('.var_qty').val());
3381			    			quantity -= parseInt($(v).find('.var_qty').val());
3382
3383			    			var obj = {};
3384			    			obj.price = $(v).find('.var_price').val();
3385			    			obj.init_price = $(v).find('.var_sales_price').val();
3386			    			obj.quantity = $(v).find('.var_qty').val(); 
3387			    			obj.quantity_var = 0; 
3388			    			obj.discountedPrice = 0;
3389
3390			    			variations.push(obj);
3391			    		});
3392			    	}
3393
3394			    	if($(this).css('display') != 'none'){
3395			    		return {
3396			    			element: $(this),
3397					        price: price,
3398					        init_price: init_price,
3399					        sf_discount_price: sf_discount_price,
3400					        var_id: var_id,
3401					        var_sku: var_sku,
3402					        quantity: quantity,
3403					        quantity_var: quantity_var,
3404					        variations: variations,
3405					        discountedPrice: 0
3406				      	};
3407			    	}
3408			    }).get();
3409
3410			    //console.log(products);
3411
3412			    // Calculate the total number of products
3413			    const totalUnits = products.reduce((sum, product) => sum + product.quantity, 0);
3414
3415			    // Sort products by price from lowest to highest
3416			    products.sort((a, b) => a.price - b.price);
3417
3418			    // Apply discounts
3419			    products.forEach((product, index) => {
3420			    	let simple_discounts = 1;
3421		    		let bogo_discounts = 1;
3422		    		let bogo_quantity = 0;
3423		    		var total_var_price = 0;
3424
3425			    	if(typeof applied_pricing_rules !== 'undefined'){
3426			    		$.each(applied_pricing_rules, function(k, v){
3427			    			let discount = 0;
3428
3429			    			if(v.pricing_method == 'discount__amount'){
3430									discount = v.pricing_value / product.price;
3431								}else if(v.pricing_method == 'discount__percentage'){
3432									discount = v.pricing_value / 100;
3433								} 
3434
3435			    			if(v.method == 'simple'){
3436			    				simple_discounts -= discount;
3437			    			}else if((v.method == 'bogo_repeat' || v.method == 'bogo') && v.receive_quantity){
3438			    				bogo_discounts -= discount;
3439			    				bogo_quantity += v.receive_quantity;
3440							}
3441						});
3442			    	}
3443
3444			    	// console.log('disc:', simple_discounts, bogo_discounts, bogo_quantity);
3445
3446			    	if(typeof applied_pricing_rules !== 'undefined' && applied_pricing_rules.length > 0 && applied_pricing_rules[0].method == 'bogo_xx_repeat') {
3447				        product.discountedPrice = product.price * simple_discounts;
3448				        product.init_price = product.sf_discount_price = product.discountedPrice;
3449		      		}
3450
3451			      	if(product.quantity > 0){
3452				      	if (totalDiscountedUnits < bogo_quantity) {
3453					        const availableDiscountUnits = bogo_quantity - totalDiscountedUnits;
3454					        const discountUnits = Math.min(product.quantity, availableDiscountUnits);
3455					        totalDiscountedUnits += discountUnits;
3456
3457					      	// Calculate the discount for the product taking into account the number of units that receive additional discount
3458					        const discountedPriceForSome = product.price * simple_discounts * bogo_discounts * discountUnits;
3459					        const fullPriceForOthers = product.price * simple_discounts * (product.quantity - discountUnits);
3460
3461					        product.discountedPrice = (discountedPriceForSome + fullPriceForOthers) / product.quantity;
3462
3463					        if (bogo_quantity) {
3464					        	product.init_price = product.sf_discount_price = product.discountedPrice;
3465					        }
3466
3467					    } else {
3468					        product.discountedPrice = product.price * simple_discounts;
3469					        if (bogo_quantity) {
3470					        	product.init_price = product.sf_discount_price = product.discountedPrice;
3471					        }
3472					    }
3473			      	}
3474
3475			      	if (product.quantity_var > 0) {
3476
3477			      		// Remove discount for club prices 
3478			      		simple_discounts = 1;
3479
3480			      		product.variations.forEach((product1, index) => {
3481			      			var yyy = update_discounted_price_for_variations(product1, totalDiscountedUnits, 0, simple_discounts, bogo_discounts, bogo_quantity);
3482			      			totalDiscountedUnits += yyy.totalDiscountedUnits;
3483			      			product1 = yyy.product;
3484
3485			      			total_var_price += parseFloat(yyy.total_var_price);
3486			      		});
3487			      	}
3488
3489			      	// console.log(product);
3490			      	// console.log('total_var_price - ' + total_var_price);
3491
3492			      	// // For Omega product
3493			      	// if (product.var_id == 96544 || product.var_id == 97441) {
3494			      	// 	if (product.quantity >= 3) {
3495			      	// 		var selected_date_1 = $('.variations_form').find('input[name=selected_date]').val();
3496			      	// 		if (selected_date_1 && _this.isDateInRange(selected_date_1, '16.09.2025', '17.10.2025')) {
3497			      	// 			product.init_price = 80;
3498			      	// 		}
3499			      	// 	}
3500			      	// }
3501
3502			      	const urlParams = new URLSearchParams(window.location.search);
3503					const dateFromUrl = urlParams.get('date');
3504
3505					if (date_discounts && date_discounts[product.var_sku]) {
3506				        const discountData = date_discounts[product.var_sku];
3507				        
3508				        // Check if the date exists for this SKU
3509				        if (discountData[dateFromUrl]) {
3510				            familyDiscount = discountData[dateFromUrl].FamilyDiscount__c;
3511
3512				            if (product.quantity >= familyDiscount) {
3513				            	product.init_price = discountData[dateFromUrl].price;
3514				            	$('.price_row[data-sku="'+ product.var_sku +'"]').find('.column.name').text(discountData[dateFromUrl].name);
3515				            }
3516				            else $('.price_row[data-sku="'+ product.var_sku +'"]').find('.column.name').text($('.price_row[data-sku="'+ product.var_sku +'"]').find('.column.name').attr('data-name'));
3517				        }
3518				    }
3519
3520				    // End For Omega product
3521
3522			      	// Update product price
3523
3524			      	update_single_price_html(product);
3525
3526			      	// let currency = ($('body').hasClass('rtl')) ? 'ש"ח' : 'NIS';
3527
3528			      	// // Update product price
3529			      	// if(product.price > product.sf_discount_price && product.discountedPrice > product.sf_discount_price){
3530			      	// 	product.element.find('.price').html('&rlm;<span><span class="stritethrough">'+product.price+'</span> '+product.sf_discount_price.toFixed(0)+'</span> ' + currency);
3531			      	// }
3532			      	// else if(product.discountedPrice && product.price > product.discountedPrice){
3533			      	// 	product.element.find('.price').html('&rlm;<span><span class="stritethrough">'+product.price+'</span> '+product.discountedPrice.toFixed(0)+'</span> ' + currency);
3534			      	// }
3535			      	// else if(product.price > product.init_price){
3536			      	// 	product.element.find('.price').html('&rlm;<span><span class="stritethrough">'+product.price+'</span> '+product.init_price.toFixed(0)+'</span> ' + currency);
3537			      	// }
3538			      	// else{
3539			      	// 	product.element.find('.price').html('&rlm;<span>'+product.price+'</span> ' + currency);
3540			      	// }
3541
3542			      	// Update product total_price
3543			      	// const totalDiscountedPrice = (product.sf_discount_price < product.init_price && product.sf_discount_price < product.init_price) ? product.sf_discount_price * product.quantity : ((product.init_price < product.discountedPrice) ? product.init_price * product.quantity : product.discountedPrice * product.quantity + total_var_price);
3544			      	var totalDiscountedPrice = (product.sf_discount_price < product.init_price) ? product.sf_discount_price * product.quantity + total_var_price : ((product.init_price < product.discountedPrice) ? product.init_price * product.quantity + total_var_price : product.discountedPrice * product.quantity + total_var_price);
3545			      	// console.log('totalDiscountedPrice - ' + totalDiscountedPrice);
3546
3547			      	if(typeof applied_pricing_rules !== 'undefined' && applied_pricing_rules.length > 0 && applied_pricing_rules[0].method == 'bogo_xx_repeat' && !applied_discount_xx) {
3548				        if (applied_pricing_rules[0].pricing_method == "discount__amount") {
3549
3550				        	var discount_1 = applied_pricing_rules[0].pricing_value;
3551				        	var groups = Math.floor(totalUnits / (applied_pricing_rules[0].purchase_quantity_repeat + applied_pricing_rules[0].receive_quantity_repeat));
3552				        	var total_discount_1 = groups * discount_1;
3553
3554				        	if (totalDiscountedPrice >= total_discount_1) {
3555				        		totalDiscountedPrice = totalDiscountedPrice - total_discount_1;
3556				        		applied_discount_xx = 1;
3557				        	}
3558
3559				        	if (total_discount_1 > 0 && $('.add-to-cart-sidebar .total_price_discount-2').length) {
3560				        		$('.add-to-cart-sidebar .total_price_discount-2 span').text(total_discount_1).parent().show();
3561				        	}
3562				        	else 
3563				        		$('.add-to-cart-sidebar .total_price_discount-2 span').text(0).parent().hide();
3564				        }
3565		      		}
3566
3567			      	product.element.find('.total_price span').text(totalDiscountedPrice.toFixed(0));
3568			    });
3569
3570				
3571				function update_single_price_html(product) {
3572
3573			    	let applied_clubs = $(product.element).find('.select_club_container .single-applied-code.applied');
3574			    	let price = (applied_clubs.length == 1 && !product.quantity) ? product.variations[0].price : product.price;
3575			    	let price_discounted = (applied_clubs.length == 1 && !product.quantity) ? product.variations[0].discountedPrice : product.discountedPrice;
3576			    	let price_init = (applied_clubs.length == 1 && !product.quantity) ? product.variations[0].init_price : product.init_price;
3577			    	let price_sf = (applied_clubs.length == 1 && !product.quantity) ? product.variations[0].init_price : product.sf_discount_price;
3578			    	let currency = ($('body').hasClass('rtl')) ? 'ש"ח' : 'NIS';
3579
3580			    	if(price > price_sf && price_discounted > price_sf){
3581			      		product.element.find('.price').html('&rlm;<span><span class="stritethrough">'+price+'</span> '+price_sf.toFixed(0)+'</span> ' + currency);
3582			      	}
3583			    	else if(price_discounted && price > price_discounted){
3584			      		product.element.find('.price').html('&rlm;<span><span class="stritethrough">'+price+'</span> '+price_discounted.toFixed(0)+'</span> ' + currency);
3585			      	}
3586			      	else if(price > price_init){
3587			      		product.element.find('.price').html('&rlm;<span><span class="stritethrough">'+price+'</span> '+price_init.toFixed(0)+'</span> ' + currency);
3588			      	}
3589			      	else{
3590			      		product.element.find('.price').html('&rlm;<span>'+price+'</span> ' + currency);
3591			      	}
3592
3593			    }
3594
3595			    function update_discounted_price_for_variations(product, totalDiscountedUnits, total_var_price, simple_discounts, bogo_discounts, bogo_quantity) {
3596
3597			    	if (totalDiscountedUnits < bogo_quantity) {
3598				        const availableDiscountUnits = bogo_quantity - totalDiscountedUnits;
3599				        const discountUnits = Math.min(product.quantity, availableDiscountUnits);
3600				        totalDiscountedUnits += discountUnits;
3601
3602				      	// Calculate the discount for the product taking into account the number of units that receive additional discount
3603				        const discountedPriceForSome = product.price * simple_discounts * bogo_discounts * discountUnits;
3604				        const fullPriceForOthers = product.price * simple_discounts * (product.quantity - discountUnits);
3605
3606				        product.discountedPrice = (discountedPriceForSome + fullPriceForOthers) / product.quantity;
3607
3608				    } else {
3609				        product.discountedPrice = product.price * simple_discounts;
3610				    }
3611
3612				    total_var_price += product.discountedPrice * product.quantity;
3613
3614			    	return {product: product, totalDiscountedUnits: totalDiscountedUnits, total_var_price: total_var_price};
3615
3616			    }
3617		  	},
3618
3619			// calculate_total_price_row: function(row) {
3620			// 	var price = parseFloat($(row).find('.quantity').attr('data-price'));
3621			// 	var currentVal = parseFloat($(row).find('.qty').val());
3622			// 	var total_price = price * currentVal;
3623			// 	$(row).find('.total_price span').text(total_price.toFixed(0));
3624			// },
3625
3626			isDateInRange: function(selectedDate, startDate, endDate) {
3627			    // Parse DD.MM.YYYY dates
3628			    function parseDate(dateStr) {
3629			        const parts = dateStr.split('.');
3630			        if (parts.length !== 3) return null;
3631			        
3632			        return {
3633			            day: parseInt(parts[0], 10),
3634			            month: parseInt(parts[1], 10),
3635			            year: parseInt(parts[2], 10)
3636			        };
3637			    }
3638			    
3639			    const selDate = parseDate(selectedDate);
3640			    const start = parseDate(startDate);
3641			    const end = parseDate(endDate);
3642			    
3643			    if (!selDate || !start || !end) return false;
3644			    
3645			    // Create comparable numeric value (YYYYMMDD)
3646			    const selValue = selDate.year * 10000 + selDate.month * 100 + selDate.day;
3647			    const startValue = start.year * 10000 + start.month * 100 + start.day;
3648			    const endValue = end.year * 10000 + end.month * 100 + end.day;
3649			    
3650			    return selValue >= startValue && selValue <= endValue;
3651			},
3652
3653			calculate_total_price: function() {
3654				var rows = $('.price_table .price_row');
3655				var total_price = 0;
3656				var full_price = 0;
3657				var total_quantity = 0;
3658				var label = '';
3659				var hasRecords = false;
3660
3661				var buttons = $('.add-go-to-cart, .add-to-cart');
3662
3663				var ticket_list_row = $('.add-to-cart-sidebar-modern div.ticket_list_row');
3664				var currency = $('html').attr('lang') === "en-US" ? "NIS" : "ש\"ח";
3665    			ticket_list_row.empty();
3666
3667				// $.each(rows, function(k,v) {
3668				// 	var price_row = parseFloat($(v).find('.total_price span').text());
3669				// 	total_price = total_price + price_row;
3670
3671				// 	if (price_row > 0) {
3672				// 		var qty = $(v).find('.qty').val();
3673				// 		var ticket_name = $(v).find('.name').text();
3674				// 		label += qty + ' ' + ticket_name + ', ';
3675				// 		total_quantity += parseFloat(qty);
3676
3677				// 		full_price += qty * parseFloat($(v).find('.quantity').data('display-regular-price'));
3678				// 	}
3679				// });
3680
3681				$.each(rows, function(k,v) {
3682					var price_row = parseFloat($(v).find('.total_price span').text());
3683					total_price = total_price + price_row;
3684					var qty = $(v).find('.qty').val();
3685
3686					if (qty > 0 || $(v).find('.select_club_container .single-applied-code.applied').length) {
3687						hasRecords = true;
3688						var ticket_name = $(v).find('.name').text();
3689
3690						if ($(v).find('.select_club_container .single-applied-code.applied').length) {
3691				    		$.each($(this).find('.select_club_container .single-applied-code.applied'), function(k1,v1) {
3692
3693				    			var club_qty = parseInt($(v1).find('.var_qty').val());
3694				    			var club_name = $(v1).find('.club_name').text();
3695				    			qty -= club_qty;
3696
3697				    			var club_price = parseFloat($(v1).find('.var_price').val());
3698			                    var club_p = `
3699			                        <div>
3700			                        	<p>
3701			                            <span class="tckt-quantity">${club_qty}</span>
3702			                            <i>x</i>
3703			                            <span class="tckt-name">${ticket_name} (${club_name})</span>
3704			                    		</p>
3705			                            <span class="tckt-price">${club_price.toFixed(0)} ${currency}</span>
3706			                        </div>`;
3707			                    ticket_list_row.append(club_p);
3708
3709				    			label += club_qty + ' ' + ticket_name + '('+ club_name +'), ';
3710				    			full_price += club_qty * parseInt($(v1).find('.var_price').val());
3711				    		});
3712				    	}
3713
3714						if (qty > 0) { 
3715							label += qty + ' ' + ticket_name + ', ';
3716			                var regular_price = parseFloat($(v).find('.quantity').data('display-regular-price'));
3717
3718			                // // For omega product
3719			                // if (qty >= 3 && $(v).find('.pr_var_id').length) {
3720		                 //    	if ($(v).find('.pr_var_id').val() == '96544' || $(v).find('.pr_var_id').val() == '97441') {
3721		                 //    		var selected_date = $('.variations_form').find('input[name=selected_date]').val();
3722		                 //    		if (selected_date && _this.isDateInRange(selected_date, '16.09.2025', '17.10.2025')) {
3723		                 //    			regular_price = 80; // 80 for omega
3724		                 //    		}
3725		                 //    	}
3726		                 //    }
3727
3728		                 	const urlParams = new URLSearchParams(window.location.search);
3729							const dateFromUrl = urlParams.get('date');
3730							const var_sku = $(v).attr('data-sku');
3731
3732							if (date_discounts && date_discounts[var_sku]) {
3733						        const discountData = date_discounts[var_sku];
3734						        
3735						        // Check if the date exists for this SKU
3736						        if (discountData[dateFromUrl]) {
3737						            familyDiscount = discountData[dateFromUrl].FamilyDiscount__c;
3738
3739						            if (qty >= familyDiscount) {
3740						            	regular_price = discountData[dateFromUrl].price;
3741						            }
3742						        }
3743						    }
3744		                    // End for omega product
3745
3746			                var regular_p = `
3747			                    <div>
3748		                        	<p>
3749			                        <span class="tckt-quantity">${qty}</span>
3750			                        <i>x</i>
3751			                        <span class="tckt-name">${ticket_name}</span>
3752			                		</p>
3753			                        <span class="tckt-price">${regular_price.toFixed(0)} ${currency}</span>
3754			                    </div>`;
3755			                ticket_list_row.append(regular_p);
3756						}
3757
3758						total_quantity += parseFloat(qty);
3759						full_price += qty * parseFloat($(v).find('.quantity').data('display-regular-price'));
3760					}
3761				});
3762
3763				if (label) label = label.slice(0,-2);
3764
3765				if (!hasRecords) {
3766			        buttons.addClass('no-chosen').attr('disabled', 'disabled');
3767			    } else {
3768			        buttons.removeClass('no-chosen').removeAttr('disabled');
3769			    }
3770
3771				if (total_quantity >= 30) {
3772					$('.group-modal').fadeIn();
3773				}
3774
3775				var total_discount = $('body').find('.add-to-cart-sidebar .total_discount');
3776				if (total_discount.length) {
3777					if(full_price > total_price){ total_discount.show(); }
3778					else{ total_discount.hide(); }
3779
3780					total_discount.find('strong span').text(full_price.toFixed(0));
3781					total_discount.find('b span').text((full_price - total_price).toFixed(0));
3782				}
3783				
3784	      		if ($('body').find('.add-to-cart-sidebar .total_price').length) {
3785					$('body').find('.add-to-cart-sidebar .total_price span').text(total_price.toFixed(0));
3786					$('body').find('.add-to-cart-sidebar .ticket_list span').text(label);
3787					$(document).trigger('sidebar_total_price_changed', total_price);
3788				}
3789			},
3790
3791			quantity: function() {
3792
3793				if ( ! String.prototype.getDecimals ) {
3794		            String.prototype.getDecimals = function() {
3795		                var num = this,
3796		                    match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
3797		                if ( ! match ) {
3798		                    return 0;
3799		                }
3800		                return Math.max( 0, ( match[1] ? match[1].length : 0 ) - ( match[2] ? +match[2] : 0 ) );
3801		            }
3802		        }
3803
3804				$( 'body' ).on( 'click', '.plus, .minus', function() {
3805		            var $qty        = $( this ).closest( '.quantity' ).find( '.qty'),
3806		                currentVal  = parseFloat( $qty.val() ),
3807		                max         = parseFloat( $qty.attr( 'max' ) ),
3808		                min         = parseFloat( $qty.attr( 'min' ) ),
3809		                step        = $qty.attr( 'step' ),
3810		                new_value   = 1;
3811
3812		            // Format values
3813		            if ( ! currentVal || currentVal === '' || currentVal === 'NaN' ) currentVal = 0;
3814		            if ( max === '' || max === 'NaN' ) max = '';
3815		            if ( min === '' || min === 'NaN' ) min = 0;
3816		            if ( step === 'any' || step === '' || step === undefined || parseFloat( step ) 
3816=== 'NaN' ) step = 1;
3817
3818		            //console.log(step);
3819
3820		            // Change the value
3821		            if ( $( this ).is( '.plus' ) ) {
3822		                if ( max && ( currentVal >= max ) ) {
3823		                    $qty.val( max );
3824		                    new_value = max;
3825		                } else {
3826		                    $qty.val( ( currentVal + parseFloat( step )).toFixed( 0 ) );
3827		                    new_value = ( currentVal + parseFloat( step )).toFixed( 0 );
3828		                }
3829		            } else {
3830		                if ( min && ( currentVal <= min ) ) {
3831		                    $qty.val( min );
3832		                    new_value = min;
3833		                } else if ( currentVal > 0 ) {
3834		                    $qty.val( ( currentVal - parseFloat( step )).toFixed( 0 ) );
3835		                    new_value = ( currentVal - parseFloat( step )).toFixed( 0 );
3836		                }
3837		            }
3838
3839		            if ($(this).closest('.cart-cross-sales').length) {
3840		            	$(this).closest('li').find('.add_to_cart_button').attr('data-quantity', new_value);
3841
3842		            	var new_price = new_value * parseFloat($(this).closest('li').find('.quantity').attr('data-price'));
3843		            	$(this).closest('li').find('.cross-sales-product-total bdi').html(parseFloat(new_price).toFixed(0) + ' <span class="woocommerce-Price-currencySymbol">' + $(this).closest('li').find('.cross-sales-product-total .woocommerce-Price-currencySymbol').text() + '</span>' ); 	
3844		            }
3845
3846		            // Trigger change event
3847		            $qty.trigger( 'change' );
3848		        });
3849
3850		        _this.cart_cross_sales_item.on('change', '.quantity .qty', function() {
3851		        	var $qty        = $( this ),
3852		                currentVal  = parseFloat( $qty.val() );
3853
3854		            if ( ! currentVal || currentVal === '' || currentVal === 'NaN' ) currentVal = 1;
3855
3856		            var new_price = currentVal * parseFloat($(this).closest('li').find('.quantity').attr('data-price'));
3857
3858		            $(this).closest('li').find('.add_to_cart_button').attr('data-quantity', currentVal);
3859		            $(this).closest('li').find('.cross-sales-product-total bdi').html(parseFloat(new_price).toFixed(0) + ' <span class="woocommerce-Price-currencySymbol">' + $(this).closest('li').find('.cross-sales-product-total .woocommerce-Price-currencySymbol').text() + '</span>' ); 	
3860	
3861		        });
3862
3863		        _this.add_to_cart_qty.on('change', function() {
3864
3865		        	var $qty        = $( this ),
3866		                currentVal  = parseFloat( $qty.val() ),
3867		                new_value = currentVal;
3868
3869		            if ( ! currentVal || currentVal === '' || currentVal === 'NaN' || currentVal < 0 ) {
3870		            	$( this ).val('0');
3871		            	new_value = 0;
3872		            	// if ($(this).closest('.price_row').find('.clubs-list-btn').length) {
3873		            	// 	$(this).closest('.price_row').find('.clubs-list-btn').removeClass('active');
3874		            	// }
3875		            }
3876
3877		            // Clubs flow
3878		            if ($(this).closest('.price_row').find('.select_club_container').length) {
3879
3880		            	let select_club_container = $(this).closest('.price_row').find('.select_club_container');
3881		            	let applied_clubs = $(this).closest('.price_row').find('.single-applied-code.applied');
3882		            	let container = applied_clubs.first();
3883		            	let applied_tickets = 0;
3884
3885		            	$.each(applied_clubs, function(k,v) { applied_tickets += parseFloat($(v).find('.var_qty').val()); });
3886
3887		            	if (applied_tickets > new_value) {
3888		            		let last_club_qty = parseFloat(applied_clubs.last().find('.var_qty').val());
3889		            		let all_exlude_last = applied_tickets - last_club_qty;
3890
3891		            		if ( all_exlude_last < new_value ) {
3892		            			let difference = new_value - all_exlude_last;
3893
3894								applied_clubs.last().find('.var_qty').val(difference);
3895
3896								var hiddenFieldValue = applied_clubs.last().find('.var_club_code').val();
3897								var records = hiddenFieldValue.split('#');
3898
3899								// Calculate current total quantity
3900						        var totalQuantity = 0;
3901						        for (var i = 0; i < records.length; i++) {
3902						            var recordData = records[i].split('|');
3903						            totalQuantity += parseInt(recordData[3]); // The last element is the quantity
3904						        }
3905
3906						        // Calculate how much we need to reduce
3907						        var quantityToReduce = totalQuantity - difference;
3908
3909						        // Start reducing quantity from the last record
3910						        for (var i = records.length - 1; i >= 0; i--) {
3911						            var recordData = records[i].split('|');
3912						            var currentQuantity = parseInt(recordData[3], 10); // The last element is the quantity
3913
3914						            if (quantityToReduce <= currentQuantity) {
3915						                // Reduce the current record's quantity
3916						                currentQuantity -= quantityToReduce;
3917						                recordData[3] = currentQuantity;
3918
3919						                if (currentQuantity === 0) {
3920						                    // If quantity is 0, remove the record
3921						                    records.splice(i, 1);
3922						                } else {
3923						                    // Update the record with the reduced quantity
3924						                    records[i] = recordData.join('|');
3925						                }
3926						                break; // Stop reducing once quantity is adjusted
3927						            } else {
3928						                // Reduce the entire quantity of the current record and move to the previous one
3929						                quantityToReduce -= currentQuantity;
3930						                records.splice(i, 1); // Remove the current record since quantity becomes 0
3931						            }
3932						        }
3933
3934						        // Join the updated records back into a string with "#" separator
3935						        var updatedHiddenFieldValue = records.join('#');
3936
3937						        applied_clubs.last().find('.var_club_code').val(updatedHiddenFieldValue);
3938
3939		            		}
3940		            		else if (applied_clubs.length > 1 && all_exlude_last == new_value) {
3941		            			applied_clubs.last().remove();
3942		            		}
3943		            		else if (applied_clubs.length == 1 && all_exlude_last == new_value) {
3944		            			container.removeClass('applied').closest('.success-applied-code-container').removeClass('active');
3945								container.find('input.var_id').val('');
3946								container.find('input.var_club_code').val('');
3947								container.find('input.var_qty').val('0');
3948								container.find('input.var_price').val('0');
3949								container.find('input.var_sales_price').val('0');
3950								container.find('.club_name').text('');
3951								container.closest('.select_club_container').find('.select_club_inner').show();
3952
3953								if (container.closest('.price_row').find('.input-text.qty').val() > 0) 
3954									container.closest('.select_club_container').find('.clubs-list-btn').addClass('active');
3955
3956		            		}
3957
3958		            	}
3959
3960		            	if (new_value > 0) select_club_container.find('.clubs-list-btn').addClass('active');
3961		            	else {
3962		            		select_club_container.find('.clubs-list-btn').removeClass('active').find('span').text(select_club_container.find('.clubs-list-btn span').attr('data-default'));
3963		            		select_club_container.find('.select_club_inner').removeClass('open').find('.clubs-list-popup p').siblings().removeClass('selected');
3964		            		select_club_container.find('.select_club_form').removeClass('active').find('input').val('');
3965		            		select_club_container.find('.select_club_form button').attr('disabled', 'disabled');
3966		            	}
3967
3968		            	if (applied_tickets > 0 && new_value > 0 && new_value > applied_tickets) {
3969										// club +
3970										// select_club_container.find('.another_code').removeClass('hide');
3971										// club -
3972										select_club_container.find('.clubs-list-btn').addClass('active');
3973										// club +
3974										console.log('show the form!!!');
3975										select_club_container.find('.select_club_inner').show();
3976										// club -
3977		            	}
3978		            	else {
3979		            		select_club_container.find('.another_code').addClass('hide');
3980		            		select_club_container.find('.clubs-list-btn').removeClass('active');
3981
3982		            		if (new_value > 0 && applied_tickets == 0) select_club_container.find('.clubs-list-btn').addClass('active');
3983		            	}
3984
3985		            	if (select_club_container.find('.clubs-list-btn').hasClass('active') || select_club_container.find('.success-applied-code-container.active').length) {
3986									  select_club_container.addClass('open');
3987									  $('.for-club-members').removeClass('hide');
3988									} else {
3989									  select_club_container.removeClass('open');
3990									  $('.for-club-members').addClass('hide');
3991									}
3992
3993		            }
3994
3995		        	if ( $(this).attr('max') && ( parseFloat($(this).val()) > parseFloat($(this).attr('max')) ) ) $(this).val($(this).attr('max'));
3996		        	
3997		        	_this.validateTotalQuantity();
3998
3999		        	// _this.calculate_total_price_row($(this).closest('.price_row'));
4000		        	_this.calculate_rows_prices();
4001		        	_this.calculate_total_price();
4002		        });
4003
4004		        _this.children_adults_qty.on('change', function() {
4005		        	var type = $(this).attr('name');
4006		        	var other_type = (type == 'adults') ? 'children' : 'adults';
4007		        	var max_number = parseFloat($(this).attr('data-max'));
4008		        	var max_total = parseFloat($(this).attr('data-total-max'));
4009
4010		        	var number = parseFloat($(this).val());
4011		        	var number_other = $(this).closest('.accommodation-audience').find('input[name='+other_type+']').val();
4012		        	var total_selected_guests = parseFloat(number) + parseFloat(number_other);
4013
4014		        	var error = '';
4015
4016		        	if (max_number && max_total) {
4017
4018		        		console.log('max_number - ' + max_number);
4019		        		console.log('number - ' + number);
4020
4021			        	if (number > max_number && type == 'adults') {
4022			        		error = $(this).closest('.accommodation-audience').find('.select-number-error').attr('data-max-adults');
4023			        		//console.log('error adults');
4024			        	}
4025			        	else if (number > max_number && type == 'children') {
4026			        		error = $(this).closest('.accommodation-audience').find('.select-number-error').attr('data-max-children');
4027			        		//console.log('error children');
4028			        	}
4029			        	else if (total_selected_guests > max_total) {
4030			        		error = $(this).closest('.accommodation-audience').find('.select-number-error').attr('data-max-total');
4031			        		//console.log('error total');
4032			        	}
4033
4034			        	if (error) $(this).closest('.accommodation-audience').find('.select-number-error').text(error).removeClass('hide');
4035			        	else $(this).closest('.accommodation-audience').find('.select-number-error').text('').addClass('hide');
4036
4037			        }
4038
4039		        });
4040
4041		        $('#product_select_date').on('submit', function() {
4042		        	if ($(this).find('.accommodation-audience').length) {
4043			        	var max_adults = parseFloat($(this).find('.accommodation-audience input[name=adults]').attr('data-max'));
4044			        	var max_children = parseFloat($(this).find('.accommodation-audience input[name=children]').attr('data-max'));
4045			        	var max_total = parseFloat($(this).find('.accommodation-audience input[name=adults]').attr('data-total-max'));
4046
4047			        	var number_adults = parseFloat($(this).find('.accommodation-audience input[name=adults]').val());
4048			        	var number_children = parseFloat($(this).find('.accommodation-audience input[name=children]').val());
4049			        	var total_selected_guests = parseFloat(number_adults) + parseFloat(number_children);
4050
4051			        	var error = '';
4052
4053			        	if (max_adults && max_children && max_total) {
4054
4055				        	if (number_adults > max_adults) 
4056				        		error = $(this).find('.accommodation-audience .select-number-error').attr('data-max-adults');
4057				        	else if (number_children > max_children)
4058				        		error = $(this).find('.accommodation-audience .select-number-error').attr('data-max-children');
4059				        	else if (total_selected_guests > max_total)
4060				        		error = $(this).find('.accommodation-audience .select-number-error').attr('data-max-total');
4061
4062				        	if (error) {
4063				        		$(this).find('.accommodation-audience .select-number-error').text(error).removeClass('hide');
4064				        		return false;
4065				        	}
4066				        	else $(this).find('.accommodation-audience .select-number-error').text('').addClass('hide');
4067
4068				        }
4069		        	}
4070		        });
4071
4072		        let timeout;
4073		        $('body').on('change', '.quantity.update-product-in-cart .qty', function() {
4074		        	if ( timeout !== undefined ) {
4075						clearTimeout( timeout );
4076					}
4077					timeout = setTimeout(function() {
4078						$("[name='update_cart']").removeAttr('disabled').trigger("click"); // trigger cart update
4079					}, 1000 ); // 1 second delay, half a second (500) seems comfortable too
4080		        });
4081
4082		        jQuery(document.body).on('added_to_cart', function(){
4083				    var items = $('.product_type_simple.add_to_cart_button.ajax_add_to_cart.added');
4084
4085				    if (items.length) {
4086					    $.each(items, function(k,v) {
4087					    	$(v).closest('li.product').hide();
4088					    });
4089					}
4090
4091					if (items.length == $('.cart-cross-sales.price_table li').length) $('.cart-cross-sales.price_table').hide();
4092				});
4093
4094			},
4095
4096			datepicker: function() {
4097
4098				var date = new Date();
4099				$('#datepicker').datepicker({
4100				    format: "dd.mm.yyyy",
4101				    startDate: "today",
4102				    language: "he",
4103				});
4104
4105				$('#datepicker').on('changeDate', function() {
4106					var new_date = $('#datepicker').datepicker('getFormattedDate');
4107				    $('form.variations_form input[name=selected_date]').val(new_date);
4108				    $('.add-to-cart-sidebar .selected_date').text(new_date);
4109				});
4110
4111			},
4112
4113			video: function() {
4114
4115				_this.play_video_icon.on('click', function() {
4116					$(this).parent().addClass('playing');
4117					$(this).prev()[0].play();
4118				});
4119
4120				_this.product_video.on('click', function() {
4121					$(this).parent().removeClass('playing');
4122					$(this)[0].pause();
4123				});
4124
4125				_this.product_slider.on('click', '.slick-arrow', function() {
4126					var videos = $(this).parent().find('.slick-slide:not(.slick-current) iframe');
4127
4128					if (videos.length) {
4129						$.each(videos, function(k,v) {
4130							var src = ($(this).attr('data-src') == 'about:blank') ? $(this).attr('data-lazy-src') : $(this).attr('data-src');
4131							$(v).attr('src', src);
4132						})
4133					}
4134				});
4135
4136				_this.product_slider.on('beforeChange', function(event, slick, currentSlide, nextSlide){
4137					var iframes = jQuery(this).find('.slick-slide:not(.slick-slide[data-slick-index='+nextSlide+']) iframe');
4138
4139					if (iframes.length) {
4140						$.each(iframes, function(k,v) {
4141							var src = ($(this).attr('data-src') == 'about:blank') ? $(this).attr('data-lazy-src') : $(this).attr('data-src');
4142							$(v).attr('src', src);
4143						})
4144					}
4145				});
4146
4147			},
4148
4149			counterArea: function() {
4150
4151				_this.counterAreaVal.each(function() {
4152
4153                    var $this = $(this);
4154        
4155                    $this.waypoint( function(  ) {
4156                
4157                        var valFrom = $this.data("from");
4158                        var valTo = $this.data("to");
4159
4160                        if("string" == typeof valTo) valTo = valTo.replace(',', '.');
4161
4162                        var valSpeed = $this.data("speed");
4163                        var numDecimals = $this.data("decimals");
4164                        var selectedFormat = $this.data("format");
4165                
4166                        $this.countTo({
4167                            from: valFrom,
4168                            to: valTo,
4169                            speed: valSpeed,
4170                            refreshInterval: 50,
4171                            decimals: numDecimals,
4172                            formatter: function(value, options) {
4173
4174                                if(selectedFormat == 'default') {
4175                                    value = value.toFixed(0);
4176                                } 
4177                                else if(selectedFormat == 'thousand') {
4178                                    value = value.toFixed(0).replace(/./g, function(c, i, a) {
4179                                        return i && c !== "." && ((a.length - i) % 3 === 0) ? '.' + c : c;
4180                                    });
4181                               	} 
4182                               	else if(selectedFormat == 'thous
4182and-comma') {
4183
4184									value = value.toFixed(0).replace(/./g, function(c, i, a) {
4185
4186                                        return i && c !== "," && ((a.length - i) % 3 === 0) ? ',' + c : c;
4187
4188                                    });
4189
4190                               	} 
4191                               	else {
4192                                    value = value.toFixed(1);
4193                                    value = value.replace('.', ',');
4194                               	}
4195								return value;
4196                            }
4197                        });
4198
4199                    }, { offset: '100%' } );
4200               	});
4201			},
4202
4203			sliders: function() {
4204
4205				var next_slide_text = $('body').hasClass('rtl') ? "השקף הבא" : "Next slide";
4206				var prev_slide_text = $('body').hasClass('rtl') ? "שקופית קודמת" : "Next slide";
4207
4208				$('.aal-bp-slider').slick({
4209				  	dots: false,
4210				  	arrows: true,
4211				  	rtl: $('body').hasClass('rtl'),
4212				  	infinite: true,
4213				  	slidesToShow: 2,
4214				  	slidesToScroll: 1,
4215				  	prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '"></button>',
4216			  		nextArrow: '<button type="button" class="slick-next" aria-label="' + customTexts.next + '"></button>',
4217				  	responsive: [{
4218			 			breakpoint: 767,
4219			 			settings: {
4220			 				slidesToShow: 1,
4221			 			}
4222			 		}]
4223				});
4224
4225				if ($('.aal-aa-slider').length) {
4226				    function updateAalSliderFocus() {
4227				        $('.aal-aa-slider .slick-slide').each(function() {
4228				            var isHidden = $(this).attr('aria-hidden') === 'true';
4229				            $(this).find('a, button').attr('tabindex', isHidden ? '-1' : '0');
4230				        });
4231				    }
4232
4233				    $('.aal-aa-slider').slick({
4234				        dots: false,
4235				        arrows: true,
4236				        rtl: $('body').hasClass('rtl'),
4237				        infinite: true,
4238				        slidesToShow: 3,
4239				        slidesToScroll: 1,
4240				        prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '"></button>',
4241				        nextArrow: '<button type="button" class="slick-next" aria-label="' + customTexts.next + '"></button>',
4242				        responsive: [{
4243				            breakpoint: 992,
4244				            settings: {
4245				                slidesToShow: 2,
4246				            }
4247				        }, {
4248				            breakpoint: 767,
4249				            settings: {
4250				                slidesToShow: 1,
4251				            }
4252				        }]
4253				    });
4254
4255				    $('.aal-aa-slider').on('init reInit afterChange', function() {
4256				        updateAalSliderFocus();
4257				    });
4258
4259				    updateAalSliderFocus();
4260				}
4261
4262				_this.product_slider.slick({
4263				  	dots: false,
4264				  	arrows: true,
4265				  	rtl: $('body').hasClass('rtl'),
4266				  	fade: true,
4267				  	autoplay: false,
4268  					autoplaySpeed: 3000,
4269				  	slidesToShow: 1,
4270				  	speed: 600,
4271				  	lazyLoad: 'progressive',
4272				  	prevArrow: '<div class="slick-prev"><button aria-label="'+ prev_slide_text +'"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="42.932" viewBox="0 0 48 42.932"><defs><filter id="arrow-right" x="0" y="0" width="48" height="42.932" filterUnits="userSpaceOnUse"><feOffset dy="3" input="SourceAlpha"/><feGaussianBlur stdDeviation="4" result="blur"/><feFlood flood-opacity="0.522"/><feComposite operator="in" in2="blur"/><feComposite in="SourceGraphic"/></filter></defs><g id="gallery_arrow_right" data-name="gallery arrow right" transform="translate(12 9)"><g transform="matrix(1, 0, 0, 1, -12, -9)" filter="url(#arrow-right)"><path id="arrow-right-2" data-name="arrow-right" d="M25.3,8.534l-1.591,1.591,6.75,6.75H10.769v2.25H30.462l-6.75,6.75L25.3,27.466,34.769,18Z" transform="translate(1.23 0.47)" fill="#fff"/></g></g></svg></button></div>',
4273    				nextArrow: '<div class="slick-next"><button aria-label="'+ next_slide_text +'"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="42.932" viewBox="0 0 48 42.932"><defs><filter id="arrow-left" x="0" y="0" width="48" height="42.932" filterUnits="userSpaceOnUse"><feOffset dy="3" input="SourceAlpha"/><feGaussianBlur stdDeviation="4" result="blur"/><feFlood flood-opacity="0.522"/><feComposite operator="in" in2="blur"/><feComposite in="SourceGraphic"/></filter></defs><g id="gallery_arrow_left" data-name="gallery arrow left" transform="translate(12 9)">
4273<g transform="matrix(1, 0, 0, 1, -12, -9)" filter="url(#arrow-left)"><path id="arrow-left-2" data-name="arrow-left" d="M25.324,16.875H5.574l6.66-6.75-1.57-1.591L1.324,18l9.34,9.466,1.57-1.591-6.66-6.75H25.323v-2.25Z" transform="translate(10.68 0.47)" fill="#fff"/></g></g></svg></button></div>'
4274				});
4275
4276				_this.sites_slider.slick({
4277				    dots: false,
4278				    arrows: true,
4279				    rtl: $('body').hasClass('rtl'),
4280				    slidesToShow: 1,
4281				    speed: 600,
4282				    lazyLoad: 'progressive',
4283				    prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="42.932" viewBox="0 0 48 42.932"><defs><filter id="arrow-right" x="0" y="0" width="48" height="42.932" filterUnits="userSpaceOnUse"><feOffset dy="3" input="SourceAlpha"/><feGaussianBlur stdDeviation="4" result="blur"/><feFlood flood-opacity="0.522"/><feComposite operator="in" in2="blur"/><feComposite in="SourceGraphic"/></filter></defs><g id="gallery_arrow_right" data-name="gallery arrow right" transform="translate(12 9)"><g transform="matrix(1, 0, 0, 1, -12, -9)" filter="url(#arrow-right)"><path id="arrow-right-2" data-name="arrow-right" d="M25.3,8.534l-1.591,1.591,6.75,6.75H10.769v2.25H30.462l-6.75,6.75L25.3,27.466,34.769,18Z" transform="translate(1.23 0.47)" fill="#fff"/></g></g></svg></button>',
4284				    nextArrow: '<button type="button" class="slick-next" aria-label="' + customTexts.next + '"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="42.932" viewBox="0 0 48 42.932"><defs><filter id="arrow-left" x="0" y="0" width="48" height="42.932" filterUnits="userSpaceOnUse"><feOffset dy="3" input="SourceAlpha"/><feGaussianBlur stdDeviation="4" result="blur"/><feFlood flood-opacity="0.522"/><feComposite operator="in" in2="blur"/><feComposite in="SourceGraphic"/></filter></defs><g id="gallery_arrow_left" data-name="gallery arrow left" transform="translate(12 9)"><g transform="matrix(1, 0, 0, 1, -12, -9)" filter="url(#arrow-left)"><path id="arrow-left-2" data-name="arrow-left" d="M25.324,16.875H5.574l6.66-6.75-1.57-1.591L1.324,18l9.34,9.466,1.57-1.591-6.66-6.75H25.323v-2.25Z" transform="translate(10.68 0.47)" fill="#fff"/></g></g></svg></button>'
4285				});
4286
4287				// Add aria-live region for screen reader announcements
4288				_this.sites_slider.each(function() {
4289				    $(this).append('<div class="sr-only" aria-live="polite" aria-atomic="true"></div>');
4290				});
4291
4292				// Announce slide change to screen reader
4293				_this.sites_slider.on('afterChange', function(event, slick, currentSlide) {
4294				    var $currentSlide = $(slick.$slides[currentSlide]);
4295				    var altText = $currentSlide.find('img').attr('alt') || '';
4296				    var total = slick.slideCount;
4297				    $(this).find('[aria-live]').text(
4298				        (currentSlide + 1) + ' / ' + total + (altText ? ': ' + altText : '')
4299				    );
4300				});
4301
4302				// Keep keyboard navigation
4303				_this.sites_slider.on('keydown', function(e) {
4304				    if (e.key === 'ArrowLeft') {
4305				        e.preventDefault();
4306				        $(this).slick('slickNext');
4307				    }
4308				    if (e.key === 'ArrowRight') {
4309				        e.preventDefault();
4310				        $(this).slick('slickPrev');
4311				    }
4312				});
4313
4314				_this.aal_ao_cube_bg_slider.slick({
4315				  	dots: false,
4316			      arrows: true,
4317			      rtl: $('body').hasClass('rtl'),
4318			      slidesToShow: 1,
4319			      speed: 600,
4320			      lazyLoad: 'progressive',
4321			      prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="42.932" viewBox="0 0 48 42.932"><defs><filter id="arrow-right" x="0" y="0" width="48" height="42.932" filterUnits="userSpaceOnUse"><feOffset dy="3" input="SourceAlpha"/><feGaussianBlur stdDeviation="4" result="blur"/><feFlood flood-opacity="0.522"/><feComposite operator="in" in2="blur"/><feComposite in="SourceGraphic"/></filter></defs><g id="gallery_arrow_right" data-name="gallery arrow right" transform="translate(12 9)">
4321<g transform="matrix(1, 0, 0, 1, -12, -9)" filter="url(#arrow-right)"><path id="arrow-right-2" data-name="arrow-right" d="M25.3,8.534l-1.591,1.591,6.75,6.75H10.769v2.25H30.462l-6.75,6.75L25.3,27.466,34.769,18Z" transform="translate(1.23 0.47)" fill="#fff"/></g></g></svg></button>',
4322			      nextArrow: '<button type="button" class="slick-next" aria-label="' + customTexts.next + '"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="42.932" viewBox="0 0 48 42.932"><defs><filter id="arrow-left" x="0" y="0" width="48" height="42.932" filterUnits="userSpaceOnUse"><feOffset dy="3" input="SourceAlpha"/><feGaussianBlur stdDeviation="4" result="blur"/><feFlood flood-opacity="0.522"/><feComposite operator="in" in2="blur"/><feComposite in="SourceGraphic"/></filter></defs><g id="gallery_arrow_left" data-name="gallery arrow left" transform="translate(12 9)"><g transform="matrix(1, 0, 0, 1, -12, -9)" filter="url(#arrow-left)"><path id="arrow-left-2" data-name="arrow-left" d="M25.324,16.875H5.574l6.66-6.75-1.57-1.591L1.324,18l9.34,9.466,1.57-1.591-6.66-6.75H25.323v-2.25Z" transform="translate(10.68 0.47)" fill="#fff"/></g></g></svg></button>'
4323				});
4324				_this.gallery_slider.slick({
4325				  	dots: false,
4326			        arrows: false,
4327			        rtl: $('body').hasClass('rtl'),
4328			        fade: true,
4329			        slidesToShow: 1,
4330			        speed: 600,
4331			        lazyLoad: 'progressive',
4332			        prevArrow: '<div class="slick-prev"></div>',
4333			        nextArrow: '<div class="slick-next"></div>'
4334				});
4335				_this.gallery_slider.on('init', function (event, slick) {
4336				    updateGalleryAccessibility($(this));
4337				});
4338
4339				_this.gallery_slider.on('afterChange', function (event, slick) {
4340				    updateGalleryAccessibility($(this));
4341				});
4342
4343				_this.func_term_slider.slick({
4344				    dots: false,
4345				    arrows: true,
4346				    rtl: $('body').hasClass('rtl'),
4347				    fade: true,
4348				    slidesToShow: 1,
4349				    speed: 600,
4350				    lazyLoad: 'progressive',
4351				    prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '"></button>',
4352				    nextArrow: '<button type="button" class="slick-next" aria-label="' + customTexts.next + '"></button>',
4353				});
4354
4355				_this.product_review_slider.slick({
4356				    dots: true,
4357				    arrows: true,
4358				    rtl: $('body').hasClass('rtl'),
4359				    slidesToShow: 3,
4360				    slidesToScroll: 1,
4361				    prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '"></button>',
4362				    nextArrow: '<button type="button" class="slick-next" aria-label="' + customTexts.next + '"></button>',
4363				    responsive: [{
4364				        breakpoint: 992,
4365				        settings: { slidesToShow: 2 }
4366				    }, {
4367				        breakpoint: 480,
4368				        settings: { slidesToShow: 1 }
4369				    }]
4370				});
4371
4372				// Accessibility for reviews slider
4373				function updateReviewsSliderAria() {
4374				    $('.product-reviews-slider .slick-slide').each(function() {
4375				        var $slide = $(this);
4376				        var isActive = $slide.hasClass('slick-active') && !$slide.hasClass('slick-cloned');
4377
4378				        if (isActive) {
4379				            $slide.removeAttr('aria-hidden');
4380				            $slide.find('h3').attr('tabindex', '0');
4381				            $slide.find('p').removeAttr('tabindex');
4382				            $slide.find('a, button').attr('tabindex', '0');
4383				        } else {
4384				            $slide.attr('aria-hidden', 'true');
4385				            $slide.find('a, button, p, h3').attr('tabindex', '-1');
4386				        }
4387				    });
4388				}
4389
4390				if (_this.product_review_slider.length) {
4391				    _this.product_review_slider.on('init reInit afterChange', function() {
4392				        setTimeout(updateReviewsSliderAria, 100);
4393				    });
4394				    updateReviewsSliderAria();
4395				    
4396				    $('.product-reviews-slider .item-inner').on('focus', function() {
4397				        const $slickSlide = $(this).closest('.slick-slide');
4398				        const $slider = $slickSlide.closest('.product-reviews-slider');
4399				        
4400				        if (!$slickSlide.hasClass('slick-center')) {
4401				            $slider.find('.slick-next').trigger('click');
4402				        }
4403				    });
4404				}
4405				$('.product-reviews-slider .item-inner').on('focus', function() {
4406				    const $slickSlide = $(this).closest('.slick-slide');
4407				    const $slider = $slickSlide.closest('.product-reviews-slider');
4408				    const slideIndex = $slickSlide.data().slickIndex;
4409				    
4410				    if (!$slickSlide.hasClass('slick-center')) {
4411				        $slider.find('.slick-next').trigger('click');
4412				    }
4413				});
4414
4415
4416
4417				_this.home_jewelry.slick({
4418				  	dots: false,
4419				  	arrows: true,
4420				  	rtl: $('body').hasClass('rtl'),
4421				  	infinite: true,
4422				  	slidesToShow: 3,
4423				  	slidesToScroll: 1,
4424				  	prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '"></button>',
4425			  		nextArrow: '<button type="button" class="slick-next" aria-label="' + customTexts.next + '"></button>',
4426				  	responsive: [{
4427			 			breakpoint: 992,
4428			 			settings: {
4429			 				slidesToShow: 2,
4430			 			}
4431			 		}, {
4432			 			breakpoint: 520,
4433			 			settings: {
4434			 				slidesToShow: 1,
4435					}
4436			 		}]
4437				});
4438
4439				_this.careers_lobby_slider.slick({
4440				    dots: false,
4441				    arrows: true,
4442				    rtl: $('body').hasClass('rtl'),
4443				    prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '">‹</button>',
4444				    nextArrow: '<button type="button" class="slick-next" aria-label="' + customTexts.next + '">›</button>',
4445				    infinite: false,
4446				    slidesToShow: 4,
4447				    slidesToScroll: 1,
4448				    responsive: [{
4449				        breakpoint: 992,
4450				        settings: {
4451				            slidesToShow: 3,
4452				        }
4453				    }, {
4454				        breakpoint: 480,
4455				        settings: {
4456				            slidesToShow: 1,
4457				        }
4458				    }]
4459				});
4460				_this.careers_lobby_slider.find('a[aria-hidden="true"]').attr('tabindex', '-1');
4461
4462				function updateGalleryAccessibility(slider) {
4463				    slider.find('.slick-slide .lightbox-icon')
4464				        .attr('tabindex', '-1');
4465				    slider.find('.slick-current .lightbox-icon')
4466				        .removeAttr('tabindex');
4467				}
4468
4469				// Megalim Academy slider
4470				if (_this.media_lobby_slider.length) {
4471					var customSlides = _this.media_lobby_slider.data('slides-to-show') || 4;
4472
4473			    _this.media_lobby_slider.slick({
4474			        dots: false,
4475			        arrows: true,
4476			        rtl: $('body').hasClass('rtl'),
4477			        prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '">‹</button>',
4478			        nextArrow: '<button type="button" class="slick-next" aria-label="' + customTexts.next + '">›</button>',
4479			        infinite: false,
4480			        slidesToShow: parseInt(customSlides),
4481			        slidesToScroll: 1,
4482			        responsive: [{
4483			            breakpoint: 992,
4484			            settings: {
4485			                slidesToShow: 2,
4486			            }
4487			        }, {
4488			            breakpoint: 480,
4489			            settings: {
4490			                slidesToShow: 1,
4491			            }
4492			        }]
4493			    });
4494				}
4495
4496				// Megalim Institute slider
4497				if ($('.ml-media-slider').length) {
4498				  $('.ml-media-slider').slick({
4499				    slidesToShow: 3,
4500				    slidesToScroll: 1,
4501				    autoplay: false,
4502				    autoplaySpeed: 4000,
4503				    arrows: true,
4504				    dots: false,
4505				    infinite: false,
4506				    rtl: true,
4507				    prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '"></button>',
4508				    nextArrow: '<button type="button" class="slick-next" aria-label="' + customTexts.next + '"></button>',
4509				    responsive: [
4510				      {
4511				          breakpoint: 992,
4512				          settings: { slidesToShow: 2 }
4513				      },
4514				      {
4515				          breakpoint: 600,
4516				          settings: { slidesToShow: 1 }
4517				      }
4518				    ]
4519				  });
4520			  }
4521				// Megalim Period slider
4522				function initPeriodSlider() {
4523				    var $slider = $('.period-slider');
4524
4525				    if ($(window).width() <= 768) {
4526				        if (!$slider.hasClass('slick-initialized')) {
4527				            $slider.slick({
4528				                slidesToShow: 3,
4529				                slidesToScroll: 1,
4530				                arrows: true,
4531				                dots: false,
4532				                infinite: false,
4533				                vertical: true,
4534				                verticalSwiping: true,
4535				                rtl: false,
4536				                prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '">
4536<svg width="18" height="10" viewBox="0 0 18 10" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.79883 8.73145L9.13743 1.53145L16.1988 8.73145" stroke="white" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>',
4537				                nextArrow: '<button type="button" class="slick-next" aria-label="הבא"><svg width="18" height="10" viewBox="0 0 18 10" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.79883 1.26855L9.13743 8.46856L16.1988 1.26855" stroke="white" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>',
4538				            });
4539				        }
4540				    } else {
4541				        if ($slider.hasClass('slick-initialized')) {
4542				            $slider.slick('unslick');
4543				        }
4544				        $slider.slick({
4545				            slidesToShow: 4,
4546				            slidesToScroll: 1,
4547				            arrows: true,
4548				            dots: false,
4549				            infinite: false,
4550				            rtl: true,
4551				            prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '"><svg width="18" height="10" viewBox="0 0 18 10" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.79883 8.73145L9.13743 1.53145L16.1988 8.73145" stroke="white" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>',
4552				            nextArrow: '<button type="button" class="slick-next" aria-label="הבא"><svg width="18" height="10" viewBox="0 0 18 10" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.79883 1.26855L9.13743 8.46856L16.1988 1.26855" stroke="white" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>',
4553				            responsive: [
4554				                {
4555				                    breakpoint: 1024,
4556				                    settings: {
4557				                        slidesToShow: 3
4558				                    }
4559				                },
4560				                {
4561				                    breakpoint: 992,
4562				                    settings: {
4563				                        slidesToShow: 3
4564				                    }
4565				                },
4566				                {
4567				                    breakpoint: 480,
4568				                    settings: {
4569				                        slidesToShow: 1,
4570				                        centerMode: true
4571				                    }
4572				                }
4573				            ]
4574				        });
4575				    }
4576				}
4577				if (jQuery('.period-slider').length) {
4578				  initPeriodSlider();
4579				  $(window).on('resize', function(){
4580				    initPeriodSlider();
4581				  });
4582				};
4583
4584				$('.slider-nav')
4585				 	.on('init', function(event, slick) {
4586				 		$('.slider-nav .slick-slide.slick-current').addClass('is-active');
4587				 	})
4588				 	.slick({
4589				 		slidesToShow: 6,
4590				 		slidesToScroll: 1,
4591				 		dots: false,
4592				 		focusOnSelect: false,
4593				 		infinite: true,
4594				 		rtl: $('body').hasClass('rtl'),
4595				 		prevArrow: '<button type="button" class="slick-prev" aria-label="' + customTexts.prev + '">‹</button>',
4596			  			nextArrow: '<button type="button" class="slick-next" aria-label="' + customTexts.next + '">›</button>',
4597				 		responsive: [
4598					 		{
4599					 			breakpoint: 992,
4600					 			settings: {
4601					 				slidesToShow: 5,
4602					 				slidesToScroll: 1,
4603					 			}
4604					 		}, {
4605					 			breakpoint: 767,
4606					 			settings: {
4607					 				slidesToShow: 4,
4608					 				slidesToScroll: 1,
4609								}
4610					 		}, {
4611					 			breakpoint: 520,
4612					 			settings: {
4613					 				slidesToShow: 3,
4614					 				slidesToScroll: 1,
4615								}
4616					 		}, {
4617					 			breakpoint: 420,
4618					 			settings: {
4619					 				slidesToShow: 2,
4620					 				slidesToScroll: 1,
4621								}
4622					 		}
4623				 		]
4624				});
4625
4626				$('.slider-nav').on('click', '.slick-slide', function(event) {
4627				 	event.preventDefault();
4628				 	var slideIndex = $(this).data('slick-index');
4629				 	var html = $(this).find('.item').html();
4630
4631				 	$(this).closest('.slider-nav').slick('slickGoTo', slideIndex);
4632
4633				 	$(this).closest('.event-gallery').find('.slider-single .item').removeClass('playing').html(html);
4634				});
4635
4636				$('.slider-nav').on('click', '.slick-arrow', function(event) {
4637
4638				 	var html = $(this).parent().find('.slick-current .item').html();
4639
4640				 	$(this).closest('.event-gallery').find('.slider-single .item').removeClass('playing').html(html);
4641				});
4642				$('.slider-nav').on('swipe', function(event) {
4643
4644				 	var html = $(this).parent().find('.slick-current .item').html();
4645
4646				 	$(this).closest('.event-gallery').find('.slider-single .item').removeClass('playing').html(html);
4647				});
4648
4649				_this.show_event_gallery_btn.on('click', '.show-gallery', function(e) {
4650					console.log('adwwdwadw');
4651				 	e.preventDefault();
4652				 	var event = $(this).attr('data-event');
4653
4654				 	$('.event-gallery-' + event).fadeIn();
4655
4656				 	if (!$('.event-gallery-' + event).hasClass('already-init')) {
4657				 		$('.event-gallery-' + event + ' .slider-nav').slick('setPosition');
4658				 		$('.event-gallery-' + event).addClass('already-init');
4659				 	} 
4660				});
4661
4662				_this.event_gallery_box.on('click', '.close-event-gallery', function() {
4663
4664					$(this).closest('.event-gallery').fadeOut();
4665
4666					var current_item = $(this).parent().find('.slider-single .item iframe');
4667					if (current_item.length) {
4668						current_item.attr('src', current_item.attr('data-src'));
4669					}
4670				});
4671
4672				_this.event_main_gallery.on('click', '.play_video_icon2', function() {
4673					$(this).parent().addClass('playing');
4674					$(this).prev()[0].play();
4675				});
4676				_this.event_main_gallery.on('click', 'video', function() {
4677					$(this).parent().removeClass('playing');
4678					$(this)[0].pause();
4679				});
4680
4681				_this.no_events_btn.on('focus', function() {
4682					$(this).closest('p').addClass('focused');
4683				});
4684				_this.no_events_btn.on('blur', function() {
4685					if ($(this).val() == '') $(this).closest('p').removeClass('focused');
4686				});
4687
4688				_this.footer_subscription_btn.on('focus', function() {
4689					$(this).closest('.animated-placeholder').addClass('focused');
4690				});
4691				_this.footer_subscription_btn.on('blur', function() {
4692					if ($(this).val() == '') $(this).closest('.animated-placeholder').removeClass('focused');
4693				});
4694				_this.footer_subscription_label.on('click', function() {
4695					if (!$(this).closest('.animated-placeholder').hasClass('focused')) {
4696						$(this).closest('.animated-placeholder').addClass('focused');
4697						$(this).closest('.animated-placeholder').find('input').focus();
4698					}
4699				});
4700
4701				_this.schools_form_field.on('focus', function() {
4702					$(this).closest('.col-xs-12').addClass('focused');
4703				});
4704				_this.schools_form_field.on('blur', function() {
4705					if ($(this).val() == '') $(this).closest('.col-xs-12').removeClass('focused');
4706				});
4707
4708				document.addEventListener( 'wpcf7mailsent', function( event ) {
4709				    if ($('form.wpcf7-form').find('.focused').length) {
4710				    	$.each($('form.wpcf7-form').find('.focused'), function(k,v) { $(v).removeClass('focused'); });
4711				    }
4712				}, true );
4713
4714				_this.jobApplicationFormFile.on('change', function(e) {
4715					var name = e.target.files[0].name;
4716					
4717					if ($(this).parent().find('span').length) $(this).parent().find('span').text(name);
4718					else $(this).parent().append('<span>'+ name +'</span>');
4719				});
4720
4721				_this.jobApplicationFormTel.on('input', function(event) {
4722					// // Allow only backspace and delete
4723					// if ( event.keyCode == 46 || event.keyCode == 8 ) {
4724					//     // let it happen, don't do anything
4725					// }
4726					// else {
4727					//     // Ensure that it is a number and stop the keypress
4728					//     if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) )) {
4729					//         event.preventDefault(); 
4730					//     }   
4731					// }
4732					$(this).val($(this).val().replace(/[^0-9]/g, ''));
4733				});
4734
4735				_this.accommodationAudience.on('click', '.head', function() {
4736					$(this).closest('.accommodation-audience').toggleClass('open');
4737				});
4738				_this.accommodationAudience.on('click', '.accommodation-audience-close', function() {
4739					$(this).closest('.accommodation-audience').toggleClass('open');
4740				});
4741				_this.accommodationAudience.on('change', '.input-text.qty', function() {
4742					var adults = $(this).closest('.dropdown').find('.adults input[type=number]').val();
4743					var children = $(this).closest('.dropdown').find('.children input[type=number]').val();
4744
4745					$(this).closest('.accommodation-audience').find('.head .adults').text(adults);
4746					$(this).closest('.accommodation-audience').find('.head .children').text(children);
4747				});
4748
4749			},
4750
4751			price_table_type_2: function(){
4752				if(!$('.price_table_type_2').length){ return; }
4753
4754				/* Start */
4755				var url_params = new URLSearchParams(window.location.search);
4756        if(!url_params.get('quantity')){
4757        	setTimeout(function(){
4758        		_this.add_to_cart_qty.each(function(){
4759	        		if(parseFloat($(this).val()) > 0){
4760	        			$(this).trigger('change');
4761	        		}
4762	        	});
4763					}, 100);
4764        }
4765				/* End */
4766
4767        /* Start */
4768        var quantity_audience = '.quantity-audience',
4769			audience_qty = $(quantity_audience).find('.qty'),
4770			audience_error = $('#audience-error');
4771
4772		audience_qty.off().on('change', function(){
4773        	var type = $(this).attr('name');
4774        	var aria_label_composition_sidebar = $('.add-to-cart-sidebar .ticket_list img').attr('aria-label');
4775        	var other_type = (type == 'adults') ? 'children' : 'adults';
4776        	var max_number = parseFloat($(this).attr('data-max'));
4777        	var max_total = parseFloat($(this).attr('data-total-max'));
4778
4779        	var number = parseFloat($(this).val());
4780        	var number_other = $(this).closest('.column').find('input[name='+other_type+']').val();
4781        	var total_selected_guests = parseFloat(number) + parseFloat(number_other);
4782
4783        	if (type == 'adults') {
4784				var aria_label_composition_sidebar_updated = aria_label_composition_sidebar.replace(/(\d+)/, number);
4785        	}
4786        	else {
4787        		var aria_label_composition_sidebar_updated = aria_label_composition_sidebar.replace(/(\d+)(.*?)(\d+)/, function(match, p1, p2, p3) {
4788                    return p1 + p2 + number;
4789                });
4790        	}
4791
4792        	$('.add-to-cart-sidebar .ticket_list img').attr('aria-label', aria_label_composition_sidebar_updated);
4793
4794        	var error = false;
4795
4796        	if (max_number && max_total) {
4797        		var ticket_list = $('body').find('.add-to-cart-sidebar .ticket_list');
4798        		if(other_type == 'adults'){
4799        			ticket_list.find('b.max-adults').text(number_other);
4800        			ticket_list.find('b.max-children').text(number);
4801        		}else if(other_type == 'children'){
4802        			ticket_list.find('b.max-adults').text(number);
4803        			ticket_list.find('b.max-children').text(number_other);
4804        		}
4805
4806	        	if (
4807	        		number > max_number && type == 'adults'
4808	        		|| number > max_number && type == 'children'
4809	        		|| total_selected_guests > max_total
4810	        	) {
4811	        		error = true;
4812	        	}
4813
4814	        	if(audience_error.length){
4815	        		if(error){
4816	        			var aria_label = $(this).attr('data-error');
4817			        	$(this).attr('aria-label', aria_label);
4818
4819		        		audience_error.removeClass('hide');
4820		        	}else{
4821		        		var aria_label = $(this).attr('data-label');
4822						$(this).attr('aria-label', aria_label.replace(/\d+/, number));
4823
4824		        		audience_error.addClass('hide');
4825		        	}
4826	        	}
4827	        }
4828        });
4829        /* End */
4830
4831				$(document).on('sidebar_total_price_changed', function(e, total_price){
4832        	$('body').find('.price_table__foot .total_price span').text(total_price.toFixed(0));
4833        });
4834				
4835			},
4836
4837			price_table_type_3: function(){
4838				var price_table = $('.price_table_type_3');
4839				if(!price_table.length){ return; }
4840
4841				var rent_tent = $('#rent-tent'),
4842						rent_tent_btn = rent_tent.find('button'),
4843						rent_tent_row = $('#rent-tent-row'),
4844						rent_tent_row_input = rent_tent_row.find('> input'),
4845						rent_tent_row_delete = rent_tent_row.find('.delete'),
4846						audience_qty = price_table.find('.quantity-audience .qty');
4847
4848
4849				var calculate = function(){
4850					var withouttent = price_table.find('.price_row.withouttent'),
4851						withtent = price_table.find('.price_row.withtent'),
4852
4853						withouttent_pr_var_id = withouttent.find('.pr_var_id'),
4854						withtent_pr_var_id = withtent.find('.pr_var_id'),
4855
4856						nights = parseFloat(withtent.attr('data-nights')),
4857
4858						adults_qty =	parseFloat(withtent.find('.qty[name="adults"]').val()),
4859						children_qty =	parseFloat(withtent.find('.qty[name="children"]').val()),
4860						total_selected = adults_qty + children_qty,
4861
4862						adult_price_with = withtent.data('adult-price'),
4863						child_price_with = withtent.data('child-price'),
4864
4865						adult_price_without = withouttent.data('adult-price'),
4866						child_price_without = withouttent.data('child-price'),
4867
4868						price_with = (adults_qty * adult_price_with + children_qty * child_price_with) * nights,
4869						price_without = (adults_qty * adult_price_without + children_qty * child_price_without) * nights,
4870
4871						tent_volume = rent_tent.data('tent-volume'),
4872						number_of_tents = Math.ceil(total_selected / tent_volume),
4873						total_for_tents = price_with - price_without,
4874
4875						col_qty_selector = '.column.quantity .qty',
4876						col_name_selector = '.column.name';
4877
4878					rent_tent.find('.tent-qty').text(number_of_tents);
4879    				rent_tent.find('.tent-price').text(total_for_tents);
4880    				rent_tent_row.find('.total > span').text(total_for_tents);
4881
4882					if(rent_tent_row_input.is(':checked')){
4883						var total_price = price_with,
4884							row_name = withtent.find(col_name_selector).text();
4885								
4886						withtent.removeClass('hide').find(col_qty_selector).val('1');
4887						withouttent.addClass('hide').find(col_qty_selector).val('0');
4888      				}else{
4889      					var total_price = price_without,
4890      					row_name = withouttent.find(col_name_selector).text();
4891								
4892						withouttent.removeClass('hide').find(col_qty_selector).val('1');
4893						withtent.addClass('hide').find(col_qty_selector).val('0');
4894      				}
4895
4896		      		price_table.find('.price_row').find('.total_price span').text(price_without.toFixed(0));
4897		      		price_table.find('.price_table__foot .total_price span').text(total_price.toFixed(0));
4898		      		$('.add-to-cart-sidebar .total_price span').text(total_price.toFixed(0));
4899
4900		      		var ticket_list = $('.add-to-cart-sidebar .ticket_list');
4901		      		ticket_list.find('b.max-adults').text(adults_qty);
4902	    			ticket_list.find('b.max-children').text(children_qty);
4903	    			ticket_list.find('> span').hide();
4904
4905	    			if(ticket_list.find('> div').length){
4906	    				ticket_list.find('> div').text(row_name);
4907	    			}else{
4908	    				ticket_list.find('> span').after('<div>
4908'+row_name+'</div>');
4909	    			}
4910
4911	    			if (children_qty == 0) {
4912	    				withouttent_pr_var_id.val(withouttent_pr_var_id.attr('data-adults'));
4913	    				withtent_pr_var_id.val(withtent_pr_var_id.attr('data-adults'));
4914	    			}
4915	    			else {
4916	    				withouttent_pr_var_id.val(withouttent_pr_var_id.attr('data-all'));
4917	    				withtent_pr_var_id.val(withtent_pr_var_id.attr('data-all'));	
4918	    			}
4919				}
4920
4921				calculate();
4922
4923				rent_tent_btn.on('click', function(){
4924					rent_tent_row_input.prop('checked', true);
4925					rent_tent.hide();
4926					calculate();
4927        });
4928
4929        rent_tent_row_delete.on('click', function(){
4930        	rent_tent_row_input.prop('checked', false);
4931        	rent_tent.show();
4932        	calculate();
4933				});
4934
4935				audience_qty.off().on('change', function(){
4936					var name = $(this).attr('name'),
4937							val = $(this).val();
4938					$('.qty[name="'+name+'"]').not(this).val(val);
4939					calculate();
4940				});
4941			},
4942
4943			dubbing_languages: function(){
4944				// var dubbing_languages = $('.dubbing-languages');
4945				// if(!dubbing_languages.length){ return; }
4946
4947				// var inputs = dubbing_languages.find('input.qty'),
4948				// 		price_row = $('.price_table .price_row')
4949
4950				// inputs.on('change', function(){
4951				// 	var val = parseFloat($(this).val());
4952
4953				// 	var count_lang = 0;
4954				// 	inputs.each(function(){
4955				// 		count_lang+= parseFloat($(this).val());
4956				// 	});
4957
4958				// 	var count_guests = 0;
4959				// 	price_row.each(function(){
4960				// 		if($(this).css('display') !== 'none'){
4961				// 			count_guests+= parseFloat($(this).find('.quantity > .qty').val());
4962				// 		}
4963				// 	});
4964
4965				// 	if(count_guests < count_lang && val != 0){
4966				// 		$(this).val(val-1);
4967				// 	}
4968				// });
4969
4970				var dubbing_languages = $('.dubbing-languages');
4971				if(!dubbing_languages.length){ return; }
4972
4973				_this.add_to_cart_qty.on('change', function(){
4974					if(!dubbing_languages.hasClass('scrolled')){
4975						dubbing_languages.addClass('scrolled');
4976						$('html, body').animate({scrollTop: dubbing_languages.closest('.variations_form').find('.price_table').offset().top}, 500);
4977					}
4978				});
4979
4980				var inputs = dubbing_languages.find('input.qty');
4981				inputs.off().on('change', function(){
4982					var ticket_list = $('.add-to-cart-sidebar .ticket_list'),
4983							div = ticket_list.find('> div'),
4984							span = ticket_list.find('> span'),
4985							label = '';
4986
4987					inputs.each(function(){
4988						var val = parseFloat($(this).val()),
4989								col_item = $(this).closest('.col-item'),
4990								name = col_item.find('.item-label').text().replace(':', '');
4991
4992						if(val){
4993							label+= !label ? val+' '+name : ', '+val+' '+name;
4994						}
4995					});
4996
4997					if(div.length){
4998						div.text(label);
4999					}else{
5000						span.after('<div>'+label+'</div>');
5001					}
5002				});
5003
5004			},
5005
5006			clubs_flow: function() {
5007
5008				// Attach the event handler only to the specific input and its parent container
5009			    $('.select_club_container .search_club_name').on('input', function () {
5010			        let $input = $(this); // The specific input being typed in
5011			        let searchValue = $input.val().toLowerCase(); // Get the input value in lowercase
5012			        let $container = $input.closest('.clubs-list-popup'); // Get the closest parent container
5013
5014			        // Filter <p> elements within the same container
5015			        $container.find('p').each(function () {
5016			            let text = $(this).text().toLowerCase(); // Get the <p> text in lowercase
5017
5018			            // Show or hide based on match
5019			            if (text.includes(searchValue)) {
5020			                $(this).show(); // Show if it matches
5021			            } else {
5022			                $(this).hide(); // Hide if it doesn't match
5023			            }
5024			        });
5025			    });
5026
5027				// Function to sort <p> elements alphabetically by text content
5028			    function sortClubsListAlphabetically(element) {
5029
5030			        var $clubsList = $(element).find('.clubs-list-popup');
5031
5032			        // Remove 'moved' class from all <p> elements
5033    				$clubsList.find('p').removeClass('moved');
5034
5035			        var $items = $clubsList.find('p').get();
5036
5037			        $items.sort(function(a, b) {
5038			            return $(a).text().localeCompare($(b).text());
5039			        });
5040
5041			        $.each($items, function(i, p) {
5042			            $clubsList.append(p); // Reappend sorted items back into the container
5043			        });
5044			    }
5045
5046				$('.select_club_container').on('click', '.clubs-list-btn.active', function() {
5047
5048					// Find the parent with the class 'select_club_inner'
5049				    var currentInner = $(this).parent('.select_club_inner');
5050				    var parent_container = $(this).closest('.select_club_container');
5051				    
5052				    // Remove the 'open' class from all 'select_club_inner' elements except the current one
5053				    $('.select_club_inner').not(currentInner).removeClass('open');
5054
5055				    if (parent_container.find('.single-applied-code.applied').length === 0) {
5056				        // If none are found, sort all <p> elements alphabetically by text content
5057				        sortClubsListAlphabetically(parent_container);
5058				    }
5059				    else {
5060				    	parent_container.find('.single-applied-code.applied .club_name').each(function() {
5061			                var clubNameInApplied = $(this).text().trim(); // Get the club name inside the applied div
5062
5063			                // Ensure that we're targeting the .clubs-list-popup within the correct parent_container
5064				            var relatedClubsListPopup = parent_container.find('.clubs-list-popup');
5065
5066				            relatedClubsListPopup.find('p:contains("' + clubNameInApplied + '")').not('.moved').insertAfter(relatedClubsListPopup.find('.search_club_name')).addClass('moved');
5067			            });
5068				    }
5069				    
5070				    // Toggle the 'open' class on the current 'select_club_inner'
5071				    currentInner.toggleClass('open');
5072
5073				});
5074
5075				$('.select_club_container').on('click', '.clubs-list-popup button', function() {
5076					$(this).closest('.select_club_inner').removeClass('open');
5077					$(this).closest('.clubs-list-popup').scrollTop(0);
5078				});
5079
5080				$('.select_club_container').on('click', '.clubs-list-popup p', function() {
5081
5082					let _this_p = $(this);
5083					let input_form = _this_p.closest('.select_club_inner').find('.select_club_form input');
5084
5085					fix_plural_code_in_hebrew();
5086
5087					if ('מטמון' == _this_p.text()) input_form.attr('placeholder', input_form.attr('data-cache-placeholder'));
5088					else input_form.attr('placeholder', input_form.attr('data-placeholder').replace('%s', _this_p.text()));
5089
5090					_this_p.addClass('selected').siblings().removeClass('selected');
5091					_this_p.closest('.clubs-list-popup').scrollTop(0);
5092					_this_p.closest('.select_club_inner').toggleClass('open').find('.clubs-list-btn span').text(_this_p.text());
5093					_this_p.closest('.select_club_inner').find('.select_club_form').addClass('active');
5094					_this_p.closest('.select_club_inner').find('.select_club_form .error').html('').hide();
5095
5096				});
5097
5098				$(".select_club_container").on('keypress', '.clubs-list-popup p', function(event) {
5099
5100			        if (event.keyCode === 13) {
5101
5102			            let _this_p = $(this);
5103
5104			            fix_plural_code_in_hebrew();
5105
5106			            _this_p.closest('.clubs-list-popup').scrollTop(0);
5107						_this_p.addClass('selected').siblings().removeClass('selected');
5108						_this_p.closest('.select_club_inner').toggleClass('open').find('.clubs-list-btn span').text(_this_p.text());
5109						_this_p.closest('.select_club_inner').find('.select_club_form').addClass('active');
5110
5111			        }
5112
5113			    });
5114
5115				$('.select_club_container').on('input', '.select_club_form input', function() {
5116
5117					this.value = this.value.replace(/[^0-9\-]/g, '');
5118
5119					let _this_p = $(this);
5120
5121					if (_this_p.val() == '') _this_p.parent().find('button').attr('disabled', 'disabled');
5122					else _this_p.parent().find('button').removeAttr('disabled');
5123
5124				});
5125
5126				$('.select_club_container').on('click', '.another_code', function() {
5127					var qty = $(this).closest('.price_row').find('.input-text.qty').val();
5128					var applied_qty = get_applied_code_qty($(this).closest('.price_row'));
5129
5130					if (applied_qty < qty) $(this).closest('.price_row').find('.select_club_inner').show();
5131
5132				});
5133
5134				$(".select_club_container").on('keypress', '.another_code', function(event) {
5135			        if (event.keyCode === 13) {
5136			        	var qty = $(this).closest('.price_row').find('.input-text.qty').val();
5137						var applied_qty = get_applied_code_qty($(this).closest('.price_row'));
5138
5139						if (applied_qty < qty) $(this).closest('.price_row').find('.select_club_inner').show();
5140			        }
5141
5142			    });
5143
5144				$('.select_club_container').on('click', '.single-applied-code.applied .remove', function() {
5145					remove_applied_club($(this));
5146					fix_plural_code_in_hebrew();
5147				});
5148
5149				$(".select_club_container").on('keypress', '.single-applied-code.applied .remove', function(event) {
5150
5151			        if (event.keyCode === 13) {
5152			        	remove_applied_club($(this));
5153			        	fix_plural_code_in_hebrew();
5154			        }
5155
5156			    });
5157
5158				$('.select_club_container').on('click', '.select_club_form button', function() {
5159
5160					let _this_btn = $(this),
5161						form = _this_btn.closest('.select_club_inner'),
5162						code = form.find('.select_club_form input').val(),
5163						club = form.find('.clubs-list-popup p.selected').attr('data-id'),
5164						club_name = form.find('.clubs-list-popup p.selected').text(),
5165						ticket_type = form.closest('.price_row').attr('data-ticket-type'),
5166						product = form.closest('form.variations_form').find('input[name=product_id]').val(),
5167						qty = form.closest('.price_row').find('.input-text.qty').val() - get_applied_code_qty(form.closest('.price_row')),
5168						row_element = _this_btn.closest('.price_row');
5169
5170					$.ajax({
5171							type: "POST",
5172						   	beforeSend:function(){
5173						   		_this_btn.addClass('loading').attr('disabled', 'disabled');
5174						   		_this_btn.parent().find('.error').hide().text('');
5175						   	},
5176						   	url: '/wp-admin/admin-ajax.php',
5177						   	data: {
5178						   		'action': 'validate_club_code',
5179						   		'code': code,
5180						   		'club': club,
5181						   		'ticket_type' : ticket_type,
5182						   		'product' : product,
5183						   		'qty' : qty,
5184						   		'date' : _this_btn.closest('form').find('input[name=selected_date]').val(),
5185						   		'time' : _this_btn.closest('form').find('input[name=selected_time]').val()
5186						   	},
5187						   	success: function (html, textstatus, xhrReq){
5188
5189						   		_this_btn.removeClass('loading').removeAttr('disabled');
5190
5191						   		var result = $.parseJSON(html);
5192
5193						   		if (result && result.error) {
5194						   			_this_btn.parent().find('.error').html(result.error).show();
5195						   		} 
5196						   		else if (result && result.success) {
5197						   			render_clubs_row_success(result.success, club_name, code, row_element);
5198						   			form.find('.clubs-list-popup p.selected').removeClass('selected');
5199						   			$(row_element).find('.success-applied-code-container').addClass('active');
5200						   			form.find('.select_club_form').removeClass('active').find('input').val('').parent().find('button').attr('disabled', 'disabled');
5201						   			form.find('.clubs-list-btn').removeClass('active').find('span').text(form.find('.clubs-list-btn span').attr('data-default'));
5202						   			form.hide();
5203
5204						   			_this.calculate_rows_prices();
5205		        					_this.calculate_total_price();
5206
5207						   		}
5208
5209						   	},
5210						   	error: function() {
5211						   		_this_btn.removeClass('loading').removeAttr('disabled');
5212						   	}
5213						});
5214				});
5215
5216				function remove_applied_club(element) {
5217
5218					let number_clubs = element.closest('.success-applied-code-inner').find('.single-applied-code.applied');
5219					let container = element.closest('.single-applied-code');
5220
5221					if (number_clubs.length >= 2) {
5222
5223						if (container.closest('.price_row').find('.input-text.qty').val() > 0) 
5224							container.closest('.select_club_container').find('.clubs-list-btn').addClass('active');
5225
5226						container.remove();
5227					}
5228					else {
5229
5230						container.removeClass('applied').closest('.success-applied-code-container').removeClass('active');
5231						container.find('input.var_id').val('');
5232						container.find('input.var_club_code').val('');
5233						container.find('input.var_qty').val('0');
5234						container.find('input.var_price').val('0');
5235						container.find('input.var_sales_price').val('0');
5236						container.find('.club_name').text('');
5237						container.closest('.select_club_container').find('.select_club_inner').show();
5238
5239						if (container.closest('.price_row').find('.input-text.qty').val() > 0) 
5240							container.closest('.select_club_container').find('.clubs-list-btn').addClass('active');
5241					}
5242
5243					_this.calculate_rows_prices();
5244		        	_this.calculate_total_price();
5245
5246				}
5247
5248				function fix_plural_code_in_hebrew() {
5249
5250					var applied = $('.single-applied-code.applied').length >= 1;
5251
5252					$('.select_club_form').each(function() {
5253					    $(this).find('.notify').text(function(_, text) {
5254					        // Check if the replacement word is already present
5255					        if (applied && text.indexOf('קודי') === -1) {
5256					        	console.log('codes');
5257					            return text.replace('קוד', 'קודי');
5258					        } else if (!applied && text.indexOf('קודי') !== -1) {
5259					        	console.log('code');
5260					            return text.replace('קודי', 'קוד');
5261					        }
5262					        return text;
5263					    });
5264					});
5265
5266				}
5267
5268				function get_applied_code_qty(container) {
5269
5270					var total = 0;
5271
5272					var applied = container.find('.success-applied-code-container .single-applied-code.applied');
5273
5274					$.each(applied, function(k,v) {
5275						total += parseInt($(v).find('input.var_qty').val());
5276					});
5277
5278					return total;
5279
5280				}
5281
5282				function render_clubs_row_success(data, club_name, club_code, row_element) {
5283
5284					var container = $(row_element).find('.success-applied-code-container .single-applied-code').first();
5285					var add_row = true;
5286
5287					if ( $(row_element).find('.success-applied-code-container .single-applied-code.applied').length ) {
5288
5289						// check clubs duplication
5290
5291						if ($(row_element).find('.success-applied-code-container .single-applied-code.applied .var_id[value="'+ data.var_id +'"]').length ) {
5292
5293							var p_item = $(row_element).find('.success-applied-code-container .single-applied-code.applied .var_id[value="'+ data.var_id +'"]').parent();
5294
5295							var hiddenClubCode = p_item.find('input.var_club_code').val();
5296
5297							if ( hiddenClubCode.indexOf(club_code) !== -1 ) {
5298
5299								var records = hiddenClubCode.split('#');
5300
5301								for (var i = 0; i < records.length; i++) {
5302	        						
5303	        						var recordData = records[i].split('|'); // Split record by "|"
5304	        						
5305	        						if (recordData[0] == club_code) {
5306
5307	        							var newQuantity = parseInt(recordData[3]) + parseInt(data.max_tickets); // Increment it
5308	        							recordData[3] = newQuantity;
5309
5310	        							records[i] = recordData.join('|');
5311
5312	            						break; // Exit the loop once the club code is found and updated
5313	        						}
5314	        					}
5315
5316	        					var updatedHiddenFieldValue = records.join('#');
5317
5318							    // Set the updated value back into the hidden field
5319							    p_item.find('input.var_club_code').val(updatedHiddenFieldValue);
5320
5321							} else {
5322
5323    							var new_line = club_code + '|' + data.var_id + '|' + row_element.find('.pr_var_id').val() + '|' + data.max_tickets;
5324    							p_item.find('input.var_club_code').val(hiddenClubCode + '#' + new_line);
5325
5326    						}
5327
5328							var new_qty = parseInt(data.max_tickets) + parseInt(p_item.find('input.var_qty').val());
5329
5330							p_item.find('input.var_qty').val(new_qty);
5331
5332							add_row = false;
5333						}
5334						else {
5335							// let new_index = $('.success-applied-code-container .single-applied-code.applied').length + 1;
5336							let container_prev = container.html();
5337							$(row_element).find('.success-applied-code-container .success-applied-code-inner').append('<div class="single-applied-code">' + container_prev + '</div>');
5338
5339							container = $(row_element).find('.success-applied-code-container .single-applied-code').last();
5340						}
5341					}
5342
5343					if (add_row) {
5344						container.addClass('applied');
5345						container.find('input.var_id').val(data.var_id);
5346						container.find('input.var_club_code').val(club_code + '|' + data.var_id + '|' + row_element.find('.pr_var_id').val() + '|' + data.max_tickets );
5347						container.find('input.var_qty').val(data.max_tickets);
5348						container.find('input.var_price').val(data.var_price);
5349						container.find('input.var_sales_price').val(data.var_sale_price);
5350						container.find('.club_name').text(club_name);
5351					}
5352				}
5353
5354			},
5355
5356			focusable_elements_popup: function() {
5357				const modal = document.querySelector('.shopping_cart_modal'); 
5358				if (modal) {
5359					const focusableElements = 'button, [href]';
5360					const firstFocusableElement = modal.querySelectorAll(focusableElements)[0];
5361					const focusableContent = modal.querySelectorAll(focusableElements);
5362					const lastFocusableElement = focusableContent[focusableContent.length - 1];
5363
5364					document.addEventListener('keydown', function(e) {
5365					  let isTabPressed = e.key === 'Tab' || e.keyCode === 9;
5366
5367					  if (!isTabPressed) {
5368					    return;
5369					  }
5370
5371					  //console.log(document.activeElement, firstFocusableElement, lastFocusableElement );
5372
5373					  if (e.shiftKey) {
5374					    if (document.activeElement === firstFocusableElement) {
5375					      lastFocusableElement.focus();
5376					      e.preventDefault();
5377					    }
5378					  } else {
5379					    if (document.activeElement === lastFocusableElement) {
5380					      firstFocusableElement.focus();
5381					      e.preventDefault();
5382					    }
5383					  }
5384					});
5385
5386				}
5387			},
5388
5389		}
5390
5391		_this.init();
5392
5393	});
5394
5395	class TabsManual {
5396	  constructor(groupNode) {
5397	    this.tablistNode = groupNode;
5398
5399	    this.tabs = [];
5400
5401	    this.firstTab = null;
5402	    this.lastTab = null;
5403	    this.openTab = null;
5404
5405	    this.tabs = Array.from(this.tablistNode.querySelectorAll('[role=tab]'));
5406	    this.tabpanels = [];
5407
5408	    for (var i = 0; i < this.tabs.length; i += 1) {
5409	      var tab = this.tabs[i];
5410	      var tabpanel = document.getElementById(tab.getAttribute('aria-controls'));
5411
5412	      tab.tabIndex = -1;
5413	      tab.setAttribute('aria-selected', 'false');
5414	      this.tabpanels.push(tabpanel);
5415
5416	      tab.addEventListener('keydown', this.onKeydown.bind(this));
5417	      tab.addEventListener('click', this.onClick.bind(this));
5418
5419	      if (!this.firstTab) {
5420	        this.firstTab = tab;
5421	        this.openTab = tab;
5422	      }
5423	      if (tab.classList.contains('selected')) {
5424	      	this.openTab = tab;
5425	      }
5426	      this.lastTab = tab;
5427	      
5428	    }
5429
5430	    this.setSelectedTab(this.openTab);
5431	  }
5432
5433	  setSelectedTab(currentTab) {
5434	    for (var i = 0; i < this.tabs.length; i += 1) {
5435	      var tab = this.tabs[i];
5436	      if (currentTab === tab) {
5437	        tab.setAttribute('aria-selected', 'true');
5438	        tab.removeAttribute('tabindex');
5439	        this.tabpanels[i].classList.add('active');
5440	      } else {
5441	        tab.setAttribute('aria-selected', 'false');
5442	        tab.tabIndex = -1;
5443	        this.tabpanels[i].classList.remove('active');
5444	      }
5445	    }
5446	  }
5447
5448	  moveFocusToTab(currentTab) {
5449	    currentTab.focus();
5450	  }
5451
5452	  moveFocusToPreviousTab(currentTab) {
5453	    var index;
5454
5455	    if (currentTab === this.firstTab) {
5456	      this.moveFocusToTab(this.lastTab);
5457	    } else {
5458	      index = this.tabs.indexOf(currentTab);
5459	      this.moveFocusToTab(this.tabs[index - 1]);
5460	    }
5461	  }
5462
5463	  moveFocusToNextTab(currentTab) {
5464	    var index;
5465
5466	    if (currentTab === this.lastTab) {
5467	      this.moveFocusToTab(this.firstTab);
5468	    } else {
5469	      index = this.tabs.indexOf(currentTab);
5470	      this.moveFocusToTab(this.tabs[index + 1]);
5471	    }
5472	  }
5473
5474	  /* EVENT HANDLERS */
5475
5476	  onKeydown(event) {
5477	    var tgt = event.currentTarget,
5478	      flag = false;
5479
5480	    switch (event.key) {
5481	      case 'ArrowLeft':
5482	        this.moveFocusToNextTab(tgt);
5483	        flag = true;
5484	        break;
5485
5486	      case 'ArrowRight':
5487	        this.moveFocusToPreviousTab(tgt);
5488	        flag = true;
5489	        break;
5490
5491	      case 'Home':
5492	        this.moveFocusToTab(this.firstTab);
5493	        flag = true;
5494	        break;
5495
5496	      case 'End':
5497	        this.moveFocusToTab(this.lastTab);
5498	        flag = true;
5499	        break;
5500
5501	      default:
5502	        break;
5503	    }
5504
5505	    if (flag) {
5506	      event.stopPropagation();
5507	      event.preventDefault();
5508	    }
5509	  }
5510
5511	  // Since this example uses buttons for the tabs, the click onr also is activated
5512	  // with the space and enter keys
5513	  onClick(event) {
5514	    this.setSelectedTab(event.currentTarget);
5515	  }
5516	}
5517
5518	// Initialize tablist
5519
5520	window.addEventListener('load', function () {
5521	  var tablists = document.querySelectorAll('[role=tablist].manual');
5522	  for (var i = 0; i < tablists.length; i++) {
5523	    new TabsManual(tablists[i]);
5524	  }
5525	});
5526	
5527})(jQuery);

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.