(function () { const STORAGE_KEY = "csa_cookie_preferences_v3"; const CONSENT_VERSION = "2026-03-26"; function gtag() { window.dataLayer = window.dataLayer || []; window.dataLayer.push(arguments); } function defaultConsent() { return { version: CONSENT_VERSION, updated_at: null, categories: { necessary: true, measurement: false, preferences: false } }; } function loadSavedConsent() { try { const raw = localStorage.getItem(STORAGE_KEY); if (!raw) { return defaultConsent(); } const parsed = JSON.parse(raw); return { version: parsed.version || CONSENT_VERSION, updated_at: parsed.updated_at || null, categories: { necessary: true, measurement: !!(parsed.categories && parsed.categories.measurement), preferences: !!(parsed.categories && parsed.categories.preferences) } }; } catch (err) { return defaultConsent(); } } function saveConsent(consent) { const payload = { version: CONSENT_VERSION, updated_at: new Date().toISOString(), categories: { necessary: true, measurement: !!consent.categories.measurement, preferences: !!consent.categories.preferences } }; localStorage.setItem(STORAGE_KEY, JSON.stringify(payload)); return payload; } function applyConsent(consent) { gtag("consent", "update", { ad_storage: "denied", ad_user_data: "denied", ad_personalization: "denied", analytics_storage: consent.categories.measurement ? "granted" : "denied", functionality_storage: consent.categories.preferences ? "granted" : "denied", security_storage: "granted" }); maybeLoadGtm(consent); } function maybeLoadGtm(consent) { const cfg = window.CSA_SITE_CONFIG || {}; if (!consent.categories.measurement) { return; } if (!cfg.gtmId || cfg.gtmId === "GTM-PLACEHOLDER") { return; } if (document.getElementById("csa-gtm-script")) { return; } const script = document.createElement("script"); script.id = "csa-gtm-script"; script.async = true; script.src = "https://www.googletagmanager.com/gtm.js?id=" + encodeURIComponent(cfg.gtmId); document.head.appendChild(script); } function bannerHtml() { return ( '
' + '
' + '
' + '
Privacy and cookie controls
' + '

' + 'Necessary cookies stay enabled for security and session integrity. Measurement and preference cookies stay off until you choose otherwise. You can review this choice at any time from the footer or the legal page.' + '

' + '
' + '
' + '' + '' + '' + '
' + '
' + '
' ); } function modalHtml(consent) { const measurementChecked = consent.categories.measurement ? "checked" : ""; const preferencesChecked = consent.categories.preferences ? "checked" : ""; return ( '' ); } function ensureBanner() { if (document.getElementById("csa-cookie-banner")) { return; } const banner = document.createElement("div"); banner.id = "csa-cookie-banner"; banner.className = "fixed-bottom bg-white border-top shadow-lg p-4"; banner.style.zIndex = "99999"; banner.innerHTML = bannerHtml(); document.body.appendChild(banner); banner.addEventListener("click", function (event) { const target = event.target; if (!(target instanceof HTMLElement)) { return; } const action = target.getAttribute("data-cookie-action"); if (action === "reject") { CookieManager.rejectAll(); } else if (action === "manage") { CookieManager.openPreferences(); } else if (action === "accept") { CookieManager.acceptSelectedDefaults(); } }); } function removeBanner() { const banner = document.getElementById("csa-cookie-banner"); if (banner) { banner.remove(); } } function ensureModal() { const consent = loadSavedConsent(); let modalEl = document.getElementById("csaCookieModal"); if (modalEl) { modalEl.remove(); } const wrapper = document.createElement("div"); wrapper.innerHTML = modalHtml(consent); document.body.appendChild(wrapper.firstChild); modalEl = document.getElementById("csaCookieModal"); modalEl.addEventListener("click", function (event) { const target = event.target; if (!(target instanceof HTMLElement)) { return; } const mode = target.getAttribute("data-cookie-save"); if (!mode) { return; } if (mode === "reject") { CookieManager.rejectAll(); const modal = bootstrap.Modal.getInstance(modalEl); if (modal) { modal.hide(); } return; } const nextConsent = { categories: { necessary: true, measurement: !!document.getElementById("cookieMeasurement").checked, preferences: !!document.getElementById("cookiePreferences").checked } }; CookieManager.save(nextConsent); const modal = bootstrap.Modal.getInstance(modalEl); if (modal) { modal.hide(); } }); return modalEl; } window.CookieManager = { init: function () { const consent = loadSavedConsent(); applyConsent(consent); if (!consent.updated_at) { ensureBanner(); } }, acceptSelectedDefaults: function () { this.save({ categories: { necessary: true, measurement: true, preferences: false } }); }, rejectAll: function () { this.save({ categories: { necessary: true, measurement: false, preferences: false } }); }, save: function (consent) { const saved = saveConsent(consent); applyConsent(saved); removeBanner(); }, openPreferences: function () { const modalEl = ensureModal(); const modal = new bootstrap.Modal(modalEl); modal.show(); } }; document.addEventListener("DOMContentLoaded", function () { window.CookieManager.init(); }); })();