document.addEventListener('DOMContentLoaded', function () { initializeCalendarFunctionality(); }, { once: true }); window.addEventListener('pageshow', function () { if (!document.getElementById('calendarDays')) return; if (!window.__fbCalendarInit) { initializeCalendarFunctionality(); return; } if (typeof window.__fbCalendarRehydrate === 'function') window.__fbCalendarRehydrate(); }); window.initializeCalendarFunctionality = function() { if (window.__fbCalendarInit) return; window.__fbCalendarInit = true; const baseDate = new Date(); baseDate.setHours(0, 0, 0, 0); let isBootstrapping = false; let geslotenDagen = []; let currentView = 'calendar'; let latestTimeSlotsRequestId = 0; let rehydrateScheduled = false; async function loadGeslotenDagen() { try { const response = await fetch('https://frameblinds.nl/agendas/geslotendagen_showroom.json', { cache: 'no-store' }); if (response.ok) { const data = await response.json(); if (Array.isArray(data)) { geslotenDagen = data; } } } catch (e) {} } function formatLocalYMD(date) { const y = date.getFullYear(); const m = String(date.getMonth() + 1).padStart(2, '0'); const d = String(date.getDate()).padStart(2, '0'); return `${y}-${m}-${d}`; } function parseLocalYMD(ymd) { const [y, m, d] = ymd.split('-').map(Number); const dt = new Date(y, m - 1, d); dt.setHours(0, 0, 0, 0); return dt; } function isDatumGesloten(date) { return geslotenDagen.includes(formatLocalYMD(date)); } function showFridayModal() { // Controleer of de modal al bestaat, anders maak hem aan let modal = document.getElementById('fridayShowroomModal'); if (!modal) { modal = document.createElement('div'); modal.id = 'fridayShowroomModal'; modal.className = 'modal fade'; modal.setAttribute('tabindex', '-1'); modal.setAttribute('aria-labelledby', 'fridayShowroomModalLabel'); modal.setAttribute('aria-hidden', 'true'); modal.innerHTML = `