document.addEventListener("DOMContentLoaded", function() { var ageModal = document.getElementById("ageModal"); var submitBtn = document.getElementById("submitBtn"); var birthMonth = document.getElementById("birthMonth"); var birthYear = document.getElementById("birthYear"); var errorMsg = document.getElementById("errorMsg"); if (ageModal && !localStorage.getItem("ageVerified")) { ageModal.classList.add("show"); document.body.classList.add("modal-open"); } if (submitBtn) { submitBtn.addEventListener("click", function() { var month = parseInt(birthMonth.value, 10); var year = parseInt(birthYear.value, 10); var today = new Date(); if (!month || !year || month < 1 || month > 12 || year < 1900) { errorMsg.style.display = "block"; return; } var age = today.getFullYear() - year; if ((today.getMonth() + 1) < month) age--; if (age < 18) { errorMsg.style.display = "block"; return; } localStorage.setItem("ageVerified", "true"); ageModal.classList.remove("show"); document.body.classList.remove("modal-open"); }); } if (birthYear) { birthYear.addEventListener("keypress", function(e) { if (e.keyCode === 13 && submitBtn) submitBtn.click(); }); } });