// Theme toggle functionality document.addEventListener('DOMContentLoaded', function() { // Theme toggle removed; dark mode may be toggled by server-side or manual class if needed. // Check for saved theme preference or respect OS preference // Theme toggle functionality removed per UX requirement. // Form validation for prediction forms const predictionForms = document.querySelectorAll('.prediction-form'); predictionForms.forEach(form => { form.addEventListener('submit', function(e) { const inputs = this.querySelectorAll('input[type="text"]'); let isValid = true; inputs.forEach(input => { if (!input.value.trim()) { input.classList.add('is-invalid'); isValid = false; } else { // Check if input is a valid number if (isNaN(input.value)) { input.classList.add('is-invalid'); isValid = false; } else { input.classList.remove('is-invalid'); } } }); if (!isValid) { e.preventDefault(); // Show a more user-friendly alert const alertDiv = document.createElement('div'); alertDiv.className = 'alert alert-danger alert-dismissible fade show mt-3'; alertDiv.innerHTML = ` Error! Please fill in all fields with valid numbers. `; form.insertBefore(alertDiv, form.firstChild); // Remove alert after 5 seconds setTimeout(() => { if (alertDiv.parentNode) { alertDiv.remove(); } }, 5000); } }); }); // Real-time validation for number inputs const numberInputs = document.querySelectorAll('input[type="text"]'); numberInputs.forEach(input => { input.addEventListener('input', function() { if (this.value && isNaN(this.value)) { this.classList.add('is-invalid'); } else { this.classList.remove('is-invalid'); } }); }); // Confirmation for delete actions const deleteButtons = document.querySelectorAll('.delete-btn'); deleteButtons.forEach(button => { button.addEventListener('click', function(e) { if (!confirm('Are you sure you want to delete this record? This action cannot be undone.')) { e.preventDefault(); } }); }); // Auto-hide alerts after 5 seconds const alerts = document.querySelectorAll('.alert'); alerts.forEach(alert => { setTimeout(() => { alert.classList.remove('show'); alert.classList.add('hide'); }, 5000); }); // Mobile menu toggle const navbarToggler = document.querySelector('.navbar-toggler'); const navbarCollapse = document.querySelector('.navbar-collapse'); if (navbarToggler && navbarCollapse) { navbarToggler.addEventListener('click', function() { navbarCollapse.classList.toggle('show'); }); } // Add animation to cards when they come into view const cards = document.querySelectorAll('.card'); const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.style.opacity = 1; entry.target.style.transform = 'translateY(0)'; } }); }, { threshold: 0.1 }); cards.forEach(card => { card.style.opacity = 0; card.style.transform = 'translateY(20px)'; card.style.transition = 'opacity 0.5s ease, transform 0.5s ease'; observer.observe(card); }); // Add floating animation to new messages const messages = document.querySelectorAll('.message'); messages.forEach(message => { message.classList.add('float-animation'); }); }); // Function to print report function printReport() { window.print(); } // Function to download report as PDF function downloadPDF() { // In a real implementation, this would generate a PDF alert('PDF download functionality would be implemented here'); } // Function to show loading spinner during form submission function showLoadingSpinner(form) { const submitButton = form.querySelector('button[type="submit"]'); if (submitButton) { submitButton.innerHTML = ' Processing...'; submitButton.disabled = true; } } // Add loading spinner to all forms document.addEventListener('DOMContentLoaded', function() { const forms = document.querySelectorAll('form'); forms.forEach(form => { form.addEventListener('submit', function() { showLoadingSpinner(this); }); }); });