// Mobile Menu Toggle function toggleMobileMenu() { const mobileMenu = document.getElementById('mobile-menu'); mobileMenu.classList.toggle('hidden'); } // Smooth Scroll for Anchor Links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const target = document.querySelector(this.getAttribute('href')); if (target) { target.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); }); // Form Submission Handler document.querySelectorAll('form').forEach(form => { form.addEventListener('submit', async (e) => { e.preventDefault(); const submitButton = form.querySelector('button[type="submit"]'); const originalText = submitButton.textContent; // Show loading state submitButton.innerHTML = ' Processing...'; submitButton.disabled = true; // Simulate API call await new Promise(resolve => setTimeout(resolve, 2000)); // Show success message submitButton.textContent = '✓ Success!'; submitButton.classList.add('bg-green-600'); // Reset form after delay setTimeout(() => { form.reset(); submitButton.textContent = originalText; submitButton.classList.remove('bg-green-600'); submitButton.disabled = false; }, 3000); }); }); // Intersection Observer for Animations const observerOptions = { threshold: 0.1, rootMargin: '0px 0px -50px 0px' }; const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.style.opacity = '1'; entry.target.style.transform = 'translateY(0)'; } }); }, observerOptions); // Observe elements for animation document.addEventListener('DOMContentLoaded', () => { const animatedElements = document.querySelectorAll('.service-card, .testimonial-card, .blog-card'); animatedElements.forEach(el => { el.style.opacity = '0'; el.style.transform = 'translateY(20px)'; el.style.transition = 'opacity 0.6s ease, transform 0.6s ease'; observer.observe(el); }); }); // Dynamic Year in Footer const currentYear = new Date().getFullYear(); const yearElements = document.querySelectorAll('.current-year'); yearElements.forEach(el => { el.textContent = currentYear; }); // Phone Number Formatting const phoneInputs = document.querySelectorAll('input[type="tel"]'); phoneInputs.forEach(input => { input.addEventListener('input', function(e) { let phone = e.target.value.replace(/\D/g, ''); let formatted = phone; if (phone.length >= 6) { formatted = `(${phone.slice(0, 3)}) ${phone.slice(3, 6)}-${phone.slice(6, 10)}`; } else if (phone.length >= 3) { formatted = `(${phone.slice(0, 3)}) ${phone.slice(3)}`; } e.target.value = formatted; }); }); // Insurance Checker function checkInsurance() { const insuranceChecker = document.createElement('div'); insuranceChecker.innerHTML = `

Check Your Insurance

`; document.body.appendChild(insuranceChecker); } function checkCoverage(button) { button.innerHTML = ' Checking...'; button.disabled = true; setTimeout(() => { const modal = button.closest('.fixed'); modal.innerHTML = `

Coverage Confirmed!

Your insurance covers 80% of preventive care and 50% of major procedures.

`; feather.replace(); }, 2000); } // Add click event to insurance check button document.addEventListener('DOMContentLoaded', () => { const insuranceButton = document.querySelector('button[onclick="checkInsurance()"]'); if (insuranceButton) { insuranceButton.addEventListener('click', checkInsurance); } }); // Real-time Form Validation function validateForm() { const inputs = document.querySelectorAll('.form-input'); inputs.forEach(input => { input.addEventListener('blur', function() { if (this.value.trim() === '' && this.hasAttribute('required')) { this.classList.add('border-red-500'); this.classList.remove('border-green-500'); } else if (this.value.trim() !== '') { this.classList.add('border-green-500'); this.classList.remove('border-red-500'); } }); input.addEventListener('input', function() { if (this.classList.contains('border-red-500') && this.value.trim() !== '') { this.classList.remove('border-red-500'); this.classList.add('border-green-500'); } }); }); } // Initialize validation validateForm(); // Dark mode detection and persistence if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) { document.documentElement.classList.add('dark'); } else { document.documentElement.classList.remove('dark'); } window.toggleDarkMode = function() { if (document.documentElement.classList.contains('dark')) { document.documentElement.classList.remove('dark'); localStorage.theme = 'light'; } else { document.documentElement.classList.add('dark'); localStorage.theme = 'dark'; } };