PageSourceSearch

https://www.carsed.pl/templates/carsed_2022/js/scripts.js?6ac8410b978fc

js carsed.pl collected 2026-10-09 01:19:27 UTC 34,258 bytes, 1,145 lines download raw bytes

1
2$(document).ready(function(){
3
4
5	/* UKRYWANIE PRZYCISKU NA STARCIE
6	UKRYWANIE PRZYCISKU KIEDY JEST NA GÓRZE STRONY
7	ANIMACJA PRZEWIJANIA DO GÓRY */
8	
9	$('#gototop').hide();
10	$(window).scroll(function(){
11		if ($(this).scrollTop() > 100) {
12			$('#gototop').fadeIn(500);
13		} 
14		else {
15			$('#gototop').fadeOut(500);
16		}
17	});
18	$('#gototop').click(function(){
19		$('html, body').animate({ scrollTop: 0 }, 500);
20		return false;
21	});
22	
23	
24	/* PRZYCISK WSTECZ */
25	
26	$('div#button_back').click(function(){
27		parent.history.back();
28		return false;
29	});
30
31	
32	
33	
34	/* ----- FORMULARZ CZYTAJ WIĘCEJ ----- */
35	
36	$('.new_form div.pweb-field-czytaj_wiecej input.pweb-checkbox').change(function(){
37		if($(this).is(":checked")){
38			$('.new_form div.pweb-field-container:nth-child(12), .new_form div.pweb-field-container:nth-child(13), .new_form div.pweb-field-container:nth-child(14), .new_form div.pweb-field-container:nth-child(15), .new_form div.pweb-field-container:nth-child(16), .new_form div.pweb-field-container:nth-child(17), .new_form div.pweb-field-container:nth-child(18), .new_form div.pweb-field-container:nth-child(19)').addClass("form_pokaz_wiecej");
39		}else{
40			$('.new_form div.pweb-field-container:nth-child(12), .new_form div.pweb-field-container:nth-child(13), .new_form div.pweb-field-container:nth-child(14), .new_form div.pweb-field-container:nth-child(15), .new_form div.pweb-field-container:nth-child(16), .new_form div.pweb-field-container:nth-child(17), .new_form div.pweb-field-container:nth-child(18), .new_form div.pweb-field-container:nth-child(19)').removeClass("form_pokaz_wiecej");
41		}
42	});
43
44
45/* ---------------------------------------------------------------------
46	AKORDEON
47--------------------------------------------------------------------- */
48
49	// Dodaj grot tylko jeśli JS działa
50  $('.crd-accordion .crd-accordion-header').each(function() {
51    $(this).append('<span class="crd-arrow"><</span>');
52  });
53
54  // Ukryj treści na start (JS-only)
55  $('.crd-accordion .crd-accordion-content').hide();
56
57  // Obsługa kliknięcia
58  $('.crd-accordion .crd-accordion-header').on('click', function() {
59    const $this = $(this);
60
61    if ($this.hasClass('active')) {
62      $this.removeClass('active');
63      $this.next('.crd-accordion-content').slideUp();
64    } else {
65      $('.crd-accordion .crd-accordion-header').removeClass('active');
66      $('.crd-accordion .crd-accordion-content').slideUp();
67
68      $this.addClass('active');
69      $this.next('.crd-accordion-content').slideDown();
70    }
71  });
72
73
74/* ---------------------------------------------------------------------
75
76 2022_ACCORDION
77	
78--------------------------------------------------------------------- */
79
80	$.fn.accordion_2025 = function (duration) {
81		if (duration == null)
82			duration = 200;
83			this.find("[data-type='accordion-section']").each(function () {
84			//$(this).attr("draggable", "true");
85			var content = $(this).find("[data-type='accordion-section-body']");
86			var title = $(this).find("[data-type='accordion-section-title']");
87			title.addClass("header_default");
88			content.addClass("content_default");
89			title.append("<div class='fa_plus_circle'></div>")
90			title.click(function () {
91				if (content.css("display") == "none") {
92					$("[data-type='accordion-section-title']").each(function () {
93						$(this).removeClass("header_active");
94						$(this).find("div").removeClass("fa_minus_circle");
95						$(this).find("div").addClass("fa_plus_circle");
96					});
97					$(this).addClass("header_active");
98					$("[data-type='accordion-section-body']").each(function () {
99						$(this).slideUp(0);
100					});
101						content.slideDown(0);
102						title.find("div").addClass("fa_minus_circle");
103						title.find("div").removeClass("fa_plus_circle");
104					$('html, body').animate({scrollTop: $(this).offset().top -200 }, 0);
105				} else {
106					content.slideUp(0);
107					title.removeClass("header_active");
108					title.find("div").removeClass("fa_minus_circle");
109					title.find("div").addClass("fa_plus_circle");
110				}
111			});
112		});
113		return this;
114	};
115	
116	$(".d_accordion, .accordion, .art_accordion, .n_accordion").accordion_2025();
117
118	
119
120/* ---------------------------------------------------------------------
121
122 PROMOCJE SEZONOWE ACCORDION
123 
124--------------------------------------------------------------------- */
125
126	$( "#promocje_sezonowe_accordion" ).accordion({
127		heightStyle: "content"
128	});
129	
130
131
132/* ---------------------------------------------------------------------
133
134 PRZEWIJANIE DO KOTWICY
135	
136--------------------------------------------------------------------- */
137	
138	$('a[href^="#"]').on('click', function(event) {
139	
140		var target = $( $(this).attr('href') );
141	
142		if( target.length ) {
143			event.preventDefault();
144			$('html, body').animate({
145				scrollTop: target.offset().top
146			}, 500);
147		}
148	});
149
150
151
152/* ---------------------------------------------------------------------
153
154 SLIDETOOGLE
155	
156--------------------------------------------------------------------- */
157
158	$('.department-employees-choice').click(function(){
159    $('.department-employees-links').slideToggle(200);
160  });
161
162	$(document).on("click", function (event) {
163    if ($(event.target).closest('.department-employees-choice').length === 0) {
164    	$('.department-employees-links').slideUp(200);
165    }
166  });
167
168
169
170/* ---------------------------------------------------------------------
171
172 WHATSAPP
173 
174--------------------------------------------------------------------- */
175
176	if(window.matchMedia("(max-width: 767px)").matches){
177    $('a[href^="https://web.whatsapp.com"]').each(function(){ 
178		var oldUrl = $(this).attr("href"); // pobranie obecnego url
179		var newUrl = oldUrl.replace("https://web.whatsapp.com", "https://api.whatsapp.com"); // utworzenie nowego url
180		$(this).attr("href", newUrl); // przypisanie wartości atrybutowi href
181		});
182  }
183	
184	
185
186/* ---------------------------------------------------------------------
187
188 NAVBAR
189 
190--------------------------------------------------------------------- */
191
192	if($('#sticky_wrapper').length>0){ 
193	
194		// When the user scrolls the page, execute myFunction
195		window.onscroll = function() {myFunction()};
196	
197		// Get the navbar
198		var navbar = document.getElementById("navbar");
199	
200		// Get the offset position of the navbar
201		var sticky = navbar.offsetTop;
202	
203		// Add the sticky class to the navbar when you reach its scroll position. Remove "sticky" when you leave the scroll position
204		function myFunction() {
205			if (window.pageYOffset >= sticky) {
206				navbar.classList.add("sticky");
207				sticky_wrapper.classList.add("sticky_move");
208			} else {
209				navbar.classList.remove("sticky");
210				sticky_wrapper.classList.remove("sticky_move");
211			}
212		}
213	}
214
215	var sections = $('div[id^="sekcja"]'); // Wszystkie sekcje, które mają id zaczynające się od "section"
216	var menuItems = $('#navbar a');  // Wszystkie elementy w menu
217
218	$(window).scroll(function() {
219		var scrollPosition = $(this).scrollTop(); // Aktualna pozycja scrolla
220		var windowHeight = $(this).height(); // Wysokość okna przeglądarki
221
222		// Sprawdzamy każdą sekcję
223		sections.each(function() {
224			var section = $(this);
225			var sectionTop = section.offset().top; // Górna krawędź sekcji
226			var sectionBottom = sectionTop + section.outerHeight(); // Dolna krawędź sekcji
227
228			// Sprawdzamy, czy sekcja jest widoczna w oknie przeglądarki
229			if (scrollPosition + windowHeight / 10 >= sectionTop && scrollPosition + windowHeight / 10 < sectionBottom) {
230				var sectionId = section.attr('id');
231				
232				// Zaznacz element w menu odpowiadający sekcji
233				menuItems.removeClass('after');
234				$('a[href="#' + sectionId + '"]').parent().addClass('after');
235			} else {
236				var sectionId = section.attr('id');
237				$('a[href="#' + sectionId + '"]').parent().removeClass('after');
238			}
239		});
240	});
241
242
243
244/* ---------------------------------------------------------------------
245
246 ACCORDION ZAKŁADKI
247	
248--------------------------------------------------------------------- */
249
250	$.fn.accordion_tabs = function (duration) {
251		if (duration == null)
252			duration = 200;
253			this.find("[data-type='accordion-section']").each(function () {
254			//$(this).attr("draggable", "true");
255			var content = $(this).find("[data-type='accordion-section-body']");
256			var title = $(this).find("[data-type='accordion-section-title']");
257			title.addClass("header_default");
258			content.addClass("content_default");
259			title.append("<div class='fa_plus_circle'></div>")
260			title.click(function () {
261				if (content.css("display") == "none") {
262					$("[data-type='accordion-section-title']").each(function () {
263						$(this).removeClass("header_active");
264						$(this).find("div").removeClass("fa_minus_circle");
265						$(this).find("div").addClass("fa_plus_circle");
266					});
267					$(this).addClass("header_active");
268					$("[data-type='accordion-section-body']").each(function () {
269						$(this).slideUp("fast");
270					});
271						content.slideDown("fast");
272						title.find("div").addClass("fa_minus_circle");
273						title.find("div").removeClass("fa_plus_circle");
274				} else {
275					content.slideUp("fast");
276					title.removeClass("header_active");
277					title.find("div").removeClass("fa_minus_circle");
278					title.find("div").addClass("fa_plus_circle");
279				}
280			});
281		});
282		return this;
283	};
284	
285	$(".accordion_tabs").accordion_tabs();
286	
287
288
289/* ---------------------------------------------------------------------
290
291 LINK KONTAKT UŻYWANE
292	
293--------------------------------------------------------------------- */
294
295	$('p.cu_kontakt_button a').click(function() {
296		$('.accordion_section_sam_nowe').find("[data-type='accordion-section-title']").removeClass("header_active");
297		$('.accordion_section_sam_nowe h3').find("div").removeClass("fa_minus_cir
297cle");
298		$('.accordion_section_sam_nowe h3').find("div").addClass("fa_plus_circle");
299		$('.accordion_section_sam_nowe').find("[data-type='accordion-section-body']").css("display","none");
300		$('.accordion_section_sam_uzywane').find("[data-type='accordion-section-title']").addClass("header_active");
301		$('.accordion_section_sam_uzywane h3').find("div").addClass("fa_minus_circle");
302		$('.accordion_section_sam_uzywane h3').find("div").removeClass("fa_plus_circle");
303		$('.accordion_section_sam_uzywane').find("[data-type='accordion-section-body']").css("display","block");
304	});
305
306
307	
308/* ---------------------------------------------------------------------
309
310 TABS - ZAKŁADKI
311	
312--------------------------------------------------------------------- */	
313	
314	$('.tab_contents').hide();
315
316	$('.tab').click(function() {
317		var target = $(this.rel);
318		$('.tab_contents').not(target).hide();
319		target.toggle();
320		$('#tabs_container > .tabs > li.active')
321			.removeClass('active');
322
323		$(this).parent().addClass('active');
324
325		$('#tabs_container > .tab_contents_container > div.tab_contents_active')
326			.removeClass('tab_contents_active');
327
328		$(this.rel).addClass('tab_contents_active');
329	});
330	
331	
332/* ---------------------------------------------------------------------
333 PODMIANA HTML
334--------------------------------------------------------------------- */
335
336$('.n-form-zmiany-leasingowe .pweb-field-mailto label').html('Wybierz markę <span class="pweb-asterisk">*</span>');
337
338	
339/* ---------------------------------------------------------------------
340 FORM WŁASNY CHECKBOX I UKRYWANIE ELEMENTÓW
341--------------------------------------------------------------------- */
342
343// --- 1. Ukrywanie 4 bloków po głównym checkboxie na starcie ---
344$('.pweb-field-zgoda').each(function() {
345  const $targets = $(this).nextAll().filter(function() {
346    return $(this).is('.pweb-field-container.pweb-separator-text, .pweb-field-zgoda_email, .pweb-field-zgoda_smsmms, .pweb-field-zgoda_telefon');
347  }).slice(0,4);
348  $targets.hide();
349});
350
351// --- 2. Handler dla wszystkich checkboxów ---
352$('input.pweb-checkbox').change(function() {
353  const $input = $(this);
354  const $label = $input.closest('.pweb-field-checkbox').find('label[for="' + this.id + '"]');
355
356  // --- A. Dodawanie/Usuwanie klasy na labelu ---
357  $label.toggleClass('etykieta_wybrana', this.checked);
358
359  // --- B. Pokazywanie/Ukrywanie 4 bloków po głównym checkboxie ---
360  if ($input.closest('.pweb-field-zgoda').length) {
361    const $targets = $input.closest('.pweb-field-zgoda').nextAll().filter(function() {
362      return $(this).is('.pweb-field-container.pweb-separator-text, .pweb-field-zgoda_email, .pweb-field-zgoda_smsmms, .pweb-field-zgoda_telefon');
363    }).slice(0,4);
364
365    $targets.toggle(this.checked);
366  }
367});
368	
369
370
371/* ---------------------------------------------------------------------
372	WALIDACJA
373--------------------------------------------------------------------- */
374
375/* --	CONFIG -- */
376
377const customMessages = {
378  'fields[seat_lokalnie_model]': 'Wybierz model auta',
379  'fields[seat_lokalnie_finansowanie]': 'Wybierz rodzaj finansowania',
380  'fields[seat_lokalnie_lokalizacja]': 'Wybierz lokalizację',
381	
382	'fields[nazwa_druzyny]': 'Wpisz nazwę drużyny',
383	
384  'fields[imie]': 'Wpisz imię i nazwisko',
385	'fields[imie_kontaktowa]': 'Wpisz imię i nazwisko',
386  'fields[telefon]': 'Wpisz 9-cyfrowy numer telefonu',
387	'fields[telefon_kontaktowa]': 'Wpisz 9-cyfrowy numer telefonu',
388	'fields[email]': 'Wpisz adres e-mail',
389	'fields[model]': 'Wybór modelu wymagany',
390	'fields[marka]': 'Wybór marki wymagany',
391  'mailto': 'Wybierz lokalizację'
392};
393
394function nameToId(name) {
395  return 'error-' + (name || '').replace(/[\[\]]/g, '_');
396}
397
398/* --	ERROR RENDER -- */
399
400function updateErrorMessage($field, name) {
401  if (!name) return;
402
403  const errorId = nameToId(name);
404  const $existingError = $('#' + errorId);
405
406  const isInvalid = $field.hasClass('invalid');
407  const isValid = $field.hasClass('valid');
408
409  if (isInvalid) {
410    if ($existingError.length === 0) {
411      const message = customMessages[name] || 'To pole jest wymagane';
412
413      const $error = $('<div></div>')
414        .addClass('n-error-message')
415        .attr('id', errorId)
416        .text(message);
417
418      $field.after($error);
419    }
420  } else if (isValid) {
421    $existingError.remove();
422  }
423}
424
425/* --	OBSERVER -- */
426
427function observeFields() {
428
429  $('input.required[name]').each(function () {
430    const $input = $(this);
431    const name = $input.attr('name');
432
433    new MutationObserver(() => {
434      updateErrorMessage($input, name);
435    }).observe(this, {
436      attributes: true,
437      attributeFilter: ['class']
438    });
439  });
440
441  $('.custom-select[data-name]').each(function () {
442    const $el = $(this);
443    const name = $el.data('name');
444
445    new MutationObserver(() => {
446      updateErrorMessage($el, name);
447    }).observe(this, {
448      attributes: true,
449      attributeFilter: ['class']
450    });
451  });
452}
453
454/* --	CUSTOM SELECT -- */
455
456$(document).on('click', '.custom-option', function () {
457
458  const $custom = $(this).closest('.custom-select');
459  const value = $(this).data('value');
460
461  $custom.attr('data-value', value);
462
463  const $select = $custom.closest('.custom-select-wrapper').find('select');
464
465  if ($select.length) {
466    $select.val(value).trigger('change');
467  }
468
469  $custom.find('.custom-option').removeClass('selection');
470  $(this).addClass('selection');
471
472  $custom.find('.custom-select-trigger').text($(this).text().trim());
473	
474	if (value) {
475    $custom.removeClass('invalid').addClass('valid');
476  } else {
477    $custom.removeClass('valid').addClass('invalid');
478  }
479});
480
481/* --	RADIO -- */
482
483$(document).on('change', 'input[type="radio"][name]', function () {
484
485	const name = $(this).attr('name');
486	const $group = $(`input[type="radio"][name="${name}"]`);
487
488	if ($group.is(':checked')) {
489		$group.removeClass('invalid').addClass('valid');
490	} else {
491		$group.removeClass('valid').addClass('invalid');
492	}
493
494	updateErrorMessage($group.first(), name);
495
496});
497
498/* --	VALIDATION -- */
499
500function validateForm($form) {
501
502  /* INPUTS */
503  $form.find('input.required').each(function () {
504
505    const $input = $(this);
506    const name = $input.attr('name');
507    const value = ($input.val() || '').trim();
508
509    let isValid = !!value;
510
511    if (name === 'fields[telefon]') {
512      const cleaned = value.replace(/\s/g, '');
513      isValid = /^(?:\+48)?\d{9}$/.test(cleaned);
514    }
515
516    if (!isValid) {
517      $input.removeClass('valid').addClass('invalid');
518    } else {
519      $input.removeClass('invalid').addClass('valid');
520    }
521
522    updateErrorMessage($input, name);
523  });
524
525  /* RADIO */
526  const radioGroups = {};
527
528  $form.find('input[type="radio"][name]').each(function () {
529    const name = $(this).attr('name');
530    if (!radioGroups[name]) {
531      radioGroups[name] = $form.find(`input[name="${name}"]`);
532    }
533  });
534
535  $.each(radioGroups, function (name, $group) {
536
537    const isChecked = $group.is(':checked');
538
539    if (!isChecked) {
540      $group.addClass('invalid').removeClass('valid');
541    } else {
542      $group.removeClass('invalid').addClass('valid');
543    }
544
545    updateErrorMessage($group.first(), name);
546  });
547
548  /* CUSTOM SELECT */
549  $form.find('.custom-select[data-name]').each(function () {
550
551    const $custom = $(this);
552    const name = $custom.data('name');
553
554    const $select = $custom.closest('.custom-select-wrapper').find('select');
555
556    const value =
557      (($select.length ? $select.val() : '') ||
558      $custom.attr('data-value') || '').trim();
559
560    if (!value) {
561      $custom.addClass('invalid').removeClass('valid');
562    } else {
563      $custom.addClass('valid').removeClass('invalid');
564    }
565
566    updateErrorMessage($custom, name);
567  });
568}
569
570/* --	SUBMIT TRIGGER -- */
571
572$(document).on('click', 'form button[type="button"], form button[type="submit"]', function (e) {
573
574  const $form = $(this).closest('form');
575
576  validateForm($form);
577
578  if ($form.find('.invalid').length > 0) {
579    e.preventDefault();
580    return false;
581  }
582});
583
584/* --	INIT -- */
585
586setTimeout(() => {
587  observeFields();
588}, 100);
589
590
591
592
593/* ---------------------------------------------------------------------
594  WŁASNY SELECT
595--------------------------------------------------------------------- */
596
597(function () {
598
599  if (!$('.pwebcontact').length) return;
600
601  // -------------------------
602  // BUILD SELECTS
603  // -------------------------
604  $('.pwebcontact .pweb-field-select select').each(function () {
605
606    const $select = $(this);
607
608    const name = $select.attr('name');
609    const id = $select.attr('id');
610
611    const $wrapper = $('<div class="custom-select-wrapper"></div>');
612    const $custom = $(`
613      <div class="custom-select" data-name="${name}" data-select-id="${id}">
614        <span class="custom-select-trigger">&nbsp;</span>
615        <div class="custom-options"></div>
616      </div>
617    `);
618
619    const $optionsBox = $custom.find('.custom-options');
620
621    $select.find('option').each(function (optionIndex) {
622
623      const value = $(this).attr('value') || '';
624      const text = $(this).text();
625
626      const $opt = $(`
627        <span class="custom-option"
628          data-value="${value}"
629          data-index="${optionIndex}"
630          data-select="${name}">
631          ${text}
632        </span>
633      `);
634
635      $optionsBox.append($opt);
636    });
637
638    $select.wrap($wrapper);
639    $select.hide();
640    $select.after($custom);
641
642  });
643
644  // <<< informacja dla innych modułów >>>
645  $(document).trigger('customSelectReady');
646
647  // -------------------------
648  // OPEN / CLOSE
649  // -------------------------
650  $(document).on('click', '.custom-select-trigger', function (e) {
651
652    const $current = $(this).closest('.custom-select');
653
654    $('.custom-select')
655      .not($current)
656      .removeClass('opened');
657
658    $current.toggleClass('opened');
659
660    e.stopPropagation();
661
662  });
663
664  $(document).on('click', function () {
665    $('.custom-select').removeClass('opened');
666  });
667
668  // -------------------------
669  // OPTION SELECT
670  // -------------------------
671  $(document).on('click', '.custom-option', function () {
672
673    const $opt = $(this);
674
675    const value = $opt.data('value');
676
677    const $custom = $opt.closest('.custom-select');
678    const $select = $custom.closest('.custom-select-wrapper').find('select');
679
680    // sync native select
681    $select.val(value).trigger('change');
682
683    // visual state
684    $custom.find('.custom-option').removeClass('selection');
685    $opt.addClass('selection');
686
687    // trigger
688    $custom.find('.custom-select-trigger').text($opt.text());
689
690    $custom.removeClass('opened');
691
692  });
693
694})();
695	
696	
697	
698/* ---------------------------------------------------------------------
699	AKTYWNY MODEL
700--------------------------------------------------------------------- */
701	
702	$('.pweb-field-model_oj .pweb-fields-group input[type="radio"]').on('click', function () {
703    if ($(this).is(':checked')) {
704			const $group = $(this).closest('.pweb-fields-group');
705
706        // Najpierw dodajemy `model-transparent` do wszystkich "div" wewnątrz grupy
707      $group.children('div').addClass('model-transparent');
708
709        // Potem usuwamy `model-transparent` tylko z tego jednego klikniętego
710      $(this).parent().removeClass('model-transparent');
711    }
712	});
713
714	
715
716});
717
718
719
720
721
722/* MODELE - FORMULARZ NOWY SALON OJ */
723document.querySelectorAll(".n-form-salon-oj .pweb-field-model_oj .pweb-fields-group label").forEach(label => {
724  const text = label.textContent.trim();
725  label.textContent = "";
726
727  // tutaj możesz dynamicznie dobrać obrazek na podstawie tekstu
728  const img = document.createElement("img");
729  img.alt = text;
730
731  // przykład mapowania nazw modeli na pliki
732  const images = {
733    "Omoda 5": "https://carsed.pl/images/lp_carsed_e-motion/form-omoda5.webp",
734    "Omoda 9 SH": "https://carsed.pl/images/lp_carsed_e-motion/form-omoda9sh.webp",
735    "Jaecoo 7": "https://carsed.pl/images/lp_carsed_e-motion/form-jaecoo7.webp",
736    "Jaecoo 7 SH": "https://carsed.pl/images/lp_carsed_e-motion/form-jaecoo7sh.webp"
737  };
738
739  img.src = images[text] || "default.jpg";
740
741  const span = document.createElement("span");
742  span.textContent = text;
743
744  label.appendChild(img);
745  label.appendChild(span);
746});
747
748
749
750/* MODELE - LIMITY AMORTYZACJI - POKAZ/UKRYJ */
751document.addEventListener("DOMContentLoaded", function () {
752  const boxes = document.querySelectorAll(".box-expand-body");
753
754  boxes.forEach(function (box) {
755    const button = box.querySelector(".box-expand-button");
756    const container = box.querySelector(".box-expand-container");
757    const label = button.querySelector("span");
758
759    if (!button || !container || !label) return;
760
761    const staticText = "modele";
762
763    container.style.maxHeight = "0";
764    label.textContent = "pokaż " + staticText;
765
766    button.addEventListener("click", function () {
767      const isClosed = container.style.maxHeight === "0px" || !container.style.maxHeight;
768
769      if (isClosed) {
770        container.style.maxHeight = container.scrollHeight + "px";
771        button.classList.add("active");
772        label.textContent = "ukryj " + staticText;
773      } else {
774        container.style.maxHeight = "0";
775        button.classList.remove("active");
776        label.textContent = "pokaż " + staticText;
777      }
778    });
779  });
780});
781
782
783// ==============================================
784// Funkcja do ładowania zajętych godzin z backendu
785// ==============================================
786function loadDisabledHours(model) {
787  $.getJSON('https://www.carsed.pl/1_rezerwacje_oj_jazda_testowa/rezerwacje.php?model=' + encodeURIComponent(model), function(disabledHours) {
788    // Usuń stare oznaczenia
789    $('.pweb-field-godziny_modele_oj .custom-options .custom-option').removeClass('disabled');
790
791    // Oznacz zajęte godziny
792    disabledHours.forEach(hour => {
793      $('.pweb-field-godziny_modele_oj .custom-options .custom-option[data-value="' + hour + '"]')
794        .addClass('disabled');
795    });
796  });
797}
798
799// ==============================================
800// Inicjalizacja custom select jako zablokowany
801// ==============================================
802var waitForSelect = setInterval(function() {
803  var $select = $('.pweb-field-godziny_modele_oj .custom-select');
804  if($select.length){
805    $select.addClass('disabled'); // dodanie klasy
806    clearInterval(waitForSelect);
807  }
808}, 100);
809
810// ==============================================
811// Nasłuchiwanie zmiany w radio buttonach (modele aut)
812// ==============================================
813$('input[name="fields[model_oj]"]').on('change', function() {
814  const model = $(this).val();
815
816  // Odblokuj custom select
817  $('.pweb-field-godziny_modele_oj .custom-select').removeClass('disabled');
818
819  // Załaduj zajęte godziny dla wybranego modelu
820  loadDisabledHours(model);
821
822  // Reset wyboru w custom select
823  const $trigger = $('.pweb-field-godziny_modele_oj .custom-select-trigger');
824  const $firstOption = $('.pweb-field-godziny_modele_oj .custom-options .custom-option').first();
825  $trigger.text($firstOption.text());
826  $('.pweb-field-godziny_modele_oj .custom-options .custom-option').removeClass('selection');
827});
828
829// ==============================================
830// Kliknięcie w opcję custom select
831// ==============================================
832$('.pweb-field-godziny_modele_oj .custom-options').on('click', '.custom-option', function() {
833  if($(this).hasClass('disabled')) return; // blokada dla zajętej godziny
834
835  const $select = $(this).closest('.custom-select-wrapper').find('select');
836  const $customSelect = $(this).closest('.custom-select');
837
838  // Zaznacz wybór
839  $select.val($(this).data('value')).trigger('change');
840  $customSelect.find('.custom-option').removeClass('selection');
841  $(this).addClass('selection');
842  $customSelect.removeClass('opened');
843  $customSelect.find('.custom-select-trigger').text($(this).text());
844});
845
846// ==============================================
847// Obsługa przycisku wysyłki formularza
848// ==============================================
849$('#pwebcontact749_send').on('click', function(e) {
850  const $form = $(this).closest('form');
851
852  // -----------------------
853  // 1. Sprawdzenie pól radio i custom select
854  // -----------------------
855  const model = $('input[name="fields[model_oj]"]:checked').val();
856  const godzina = $('.pweb-field-godziny_modele_oj .custom-option.selection').data('value');
857
858  if (!model || !godzina) return; // brak wyboru › przerwij
859
860  // -----------------------
861  // 2. Sprawdzenie pól tekstowych: imię i telefon
862  // -----------------------
863  const imie = $form.find('input[name="fields[imie]"]').val().trim();
864  const telefon = $form.find('input[name="fields[telefon]"]').val().trim();
865
866  // Wyrażenia regularne
867  const imieRegex = /^.{5,}$/; // min 5 znaków
868  const telefonRegex = /^\+?(?=(?:\D*\d){9,})[\d ]+$/; // min 9 cyfr
869
870  // Walidacja
871  if (!imieRegex.test(imie)) return;        // imię niepoprawne › przerwij
872  if (!telefonRegex.test(telefon)) return;  // telefon niepoprawny › przerwij
873
874  // -----------------------
875  // 3. Wysyłka do JSON
876  // -----------------------
877  $.post(
878    'https://www.carsed.pl/1_rezerwacje_oj_jazda_testowa/rezerwacje.php',
879    { model: model, godzina: godzina },
880    function() {
881      loadDisabledHours(model); // odświeżenie widoku zajętych godzin
882    }
883  );
884});
885
886
887// =====================================================================
888// KLIKALNY JR-CONTACT-PHONE
889// =====================================================================
890
891(() => {
892  document.addEventListener('DOMContentLoaded', () => {
893    const landlinePrefixes = [
894      '12','13','14','15','16','17','18','22','23','24','25','29',
895      '32','33','34','41','42','43','44','46','48','49','52','54',
896      '55','56','58','59','61','62','63','65','67','68','71','74',
897      '75','76','77','81','82','83','84','85','86','87','89','91',
898      '94','95'
899    ];
900
901    document.querySelectorAll('.jr-contact-phone').forEach(el => {
902      let raw = el.textContent.trim().replace(/\s+/g, '');
903
904      // normalizacja prefiksu
905      if (raw.startsWith('0048')) {
906        raw = '+' + raw.slice(2); // 0048 -> +48
907      } else if (!raw.startsWith('+48')) {
908        raw = '+48' + raw; // dopisz +48 jeśli brak
909      }
910
911      const num = raw.slice(3); // 9 cyfr po +48
912      const prefix2 = num.slice(0, 2);
913
914      let formatted = '';
915
916      if (landlinePrefixes.includes(prefix2)) {
917        // stacjonarny: 2-3-2-2
918        formatted = '+48 ' + num.replace(/(\d{2})(\d{3})(\d{2})(\d{2})/, '$1 $2 $3 $4');
919      } else {
920        // komórkowy: 3-3-3
921        formatted = '+48 ' + num.replace(/(\d{3})(\d{3})(\d{3})/, '$1 $2 $3');
922      }
923
924      const link = document.createElement('a');
925      link.href = 'tel:+48' + num;
926      link.textContent = formatted;
927
928      el.textContent = '';
929      el.appendChild(link);
930    });
931  });
932})();
933
934
935
936/* ---------------------------------------------------------------------
937	FORM CUPRA
938--------------------------------------------------------------------- */
939
940(function($){
941  // Sprawdzenie czy formularz istnieje
942  if(!$('#pwebcontact810_form').length) return;
943
944  // ==============================================
945  // Funkcja do ładowania zajętych godzin
946  // ==============================================
947  function loadDisabledHours() {
948    $.getJSON('https://www.carsed.pl/2_rezerwacje_cupra_jazda_testowa/rezerwacje.php', function(disabledHours) {
949      $('.pweb-field-godziny_cupra_vibe .custom-options .custom-option')
950        .removeClass('disabled');
951
952      disabledHours.forEach(hour => {
953        $('.pweb-field-godziny_cupra_vibe .custom-options .custom-option[data-value="' + hour + '"]')
954          .addClass('disabled');
955      });
956    });
957  }
958
959  // ==============================================
960  // Kliknięcie w opcję custom select
961  // ==============================================
962  $('.pweb-field-godziny_cupra_vibe .custom-options').on('click', '.custom-option', function() {
963    if($(this).hasClass('disabled')) return;
964
965    const $select = $(this).closest('.custom-select-wrapper').find('select');
966    const $customSelect = $(this).closest('.custom-select');
967
968    $select.val($(this).data('value')).trigger('change');
969    $customSelect.find('.custom-option').removeClass('selection');
970    $(this).addClass('selection');
971    $customSelect.removeClass('opened');
972    $customSelect.find('.custom-select-trigger').text($(this).text());
973  });
974
975  // ==============================================
976  // Zapis danych do sessionStorage zamiast wysyłki
977  // ==============================================
978  $('#pwebcontact810_send').on('click', function() {
979    const $form = $(this).closest('form');
980
981    const godzina = $('.pweb-field-godziny_cupra_vibe .custom-option.selection').data('value');
982    if (!godzina) return;
983
984    const imie = $form.find('input[name="fields[imie]"]').val().trim();
985    const telefon = $form.find('input[name="fields[telefon]"]').val().trim();
986
987    const imieRegex = /^.{5,}$/;
988    const telefonRegex = /^\+?(?=(?:\D*\d){9,})[\d ]+$/;
989
990    if (!imieRegex.test(imie)) return;
991    if (!telefonRegex.test(telefon)) return;
992
993    // Zapis do sessionStorage
994    sessionStorage.setItem('cupra_godzina', godzina);
995    sessionStorage.setItem('cupra_imie', imie);
996    sessionStorage.setItem('cupra_telefon', telefon);
997
998    // Pozostawiamy standardowe zachowanie formularza (przekierowanie na thankyoupage)
999  });
1000
1001  // ==============================================
1002  // Inicjalizacja przy ładowaniu strony
1003  // ==============================================
1004  $(document).ready(function() {
1005    loadDisabledHours();
1006  });
1007
1008})(jQuery);
1009
1010
1011/* ---------------------------------------------------------------------
1012	FORM FINANSOWANIE - ZAMIANA FIELDSET NA DIV
1013--------------------------------------------------------------------- */
1014
1015(() => {
1016    const fieldset = document.getElementById('pwebcontact846_field-marka');
1017    if (!fieldset || fieldset.tagName !== 'FIELDSET') return;
1018
1019    const div = document.createElement('div');
1020
1021    // przepisanie wszystkich atrybutów
1022    for (const attr of fieldset.attributes) {
1023        div.setAttribute(attr.name, attr.value);
1024    }
1025
1026    // przeniesienie wszystkich dzieci (bez utraty eventów)
1027    while (fieldset.firstChild) {
1028        div.appendChild(fieldset.firstChild);
1029    }
1030
1031    fieldset.replaceWith(div);
1032})();
1033
1034/* ---------------------------------------------------------------------
1035	FORM FINANSOWANIE - MAPOWANIE MARKA -> SALON
1036--------------------------------------------------------------------- */
1037
1038(() => {
1039
1040	$(document).one('customSelectReady', function () {
1041
1042		const container = document.getElementById('pwebcontact846_field-marka');
1043		if (!container) return;
1044
1045		const radios = container.querySelectorAll('input[name="fields[marka]"]');
1046
1047		const customSelect = document.querySelector(
1048			'.custom-select[data-name="mailto"]'
1049		);
1050
1051		if (!customSelect) return;
1052
1053		const options = customSelect.querySelectorAll('.custom-option');
1054
1055		const nativeSelect = customSelect
1056			.closest('.custom-select-wrapper')
1057			.querySelector('select');
1058
1059		const markaMap = {
1060			'Volkswagen': ['2'],
1061			'SEAT': ['1'],
1062			'Skoda': ['2', '3'],
1063			'Volkswagen Dostawcze': ['2'],
1064			'CUPRA': ['1']
1065		};
1066
1067		function updateSalons(marka) {
1068
1069			const visible = markaMap[marka] || [];
1070
1071			options.forEach(option => {
1072
1073				const value = option.dataset.value;
1074
1075				// "-" zawsze widoczna
1076				if (value === '') {
1077					option.style.display = '';
1078					return;
1079				}
1080
1081				option.style.display = visible.includes(value)
1082					? ''
1083					: 'none';
1084
1085			});
1086
1087			// reset wyboru salonu
1088			nativeSelect.selectedIndex = 0;
1089			nativeSelect.dispatchEvent(new Event('change', { bubbles: true }));
1090
1091			customSelect.querySelector('.custom-select-trigger').innerHTML = '&nbsp;';
1092
1093			options.forEach(option => {
1094				option.classList.remove('selection');
1095			});
1096
1097		}
1098
1099		radios.forEach(radio => {
1100
1101			radio.addEventListener('change', function () {
1102
1103				if (this.checked) {
1104					updateSalons(this.value);
1105				}
1106
1107			});
1108
1109		});
1110
1111	});
1112
1113})();
1114
1115
1116/* ---------------------------------------------------------------------
1117	JS - JR-FAQ
1118--------------------------------------------------------------------- */
1119
1120(() => {
1121  const jrfaq = document.querySelector('.jr-faq');
1122
1123  if (!jrfaq) return;
1124
1125  const buttons = jrfaq.querySelectorAll('.jr-faq-question');
1126
1127  buttons.forEach(button => {
1128    button.addEventListener('click', () => {
1129
1130      const item = button.closest('.jr-faq-item');
1131      const answer = item.querySelector('.jr-faq-answer');
1132
1133      const isOpen = item.classList.contains('active');
1134      item.classList.toggle('active');
1135
1136      if (isOpen) {
1137        answer.style.maxHeight = '0px';
1138      } else {
1139        answer.style.maxHeight = answer.scrollHeight + 'px';
1140      }
1141
1142    });
1143  });
1144})();
1145

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.