document.addEventListener('DOMContentLoaded', function () { const contactForm = document.getElementById('contactForm'); if (contactForm) { contactForm.addEventListener('submit', function (e) { e.preventDefault(); const form = e.target; const formData = new FormData(form); const status = document.getElementById('form-status'); // Basic client-side validation const name = formData.get('name'); const email = formData.get('email'); const message = formData.get('message'); if (!name || !email || !message) { status.innerHTML = '
Please fill out all fields.
'; return; } fetch('contact.php', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { if (data.success) { status.innerHTML = `
${data.message}
`; form.reset(); } else { status.innerHTML = `
${data.message}
`; } }) .catch(error => { status.innerHTML = '
An error occurred. Please try again.
'; console.error('Error:', error); }); }); } // Fetch and display cyclone data const cycloneDataContainer = document.getElementById('cyclone-data'); if (cycloneDataContainer) { fetch('api/cyclone.php') .then(response => response.json()) .then(data => { if (data && data.length > 0) { let html = ''; data.forEach(alert => { html += `
${alert.headline}

${alert.description.substring(0, 150)}...

Read More
`; }); cycloneDataContainer.innerHTML = html; } else { cycloneDataContainer.innerHTML = '

No active severe weather alerts from the SPC at the moment.

'; } }) .catch(error => { cycloneDataContainer.innerHTML = '

Could not load cyclone data. Please try again later.

'; console.error('Error fetching cyclone data:', error); }); } // Fetch and display wildfire data const wildfireDataContainer = document.getElementById('wildfire-data'); if (wildfireDataContainer) { fetch('api/wildfires.php') .then(response => response.json()) .then(data => { if (data && data.length > 0) { let html = ''; data.forEach(fire => { html += `
${fire.name}

${fire.acres ? Math.round(fire.acres) + ' acres' : 'Size not available'}

${fire.percent_contained !== null ? fire.percent_contained + '% contained' : 'Containment not available'}

`; }); wildfireDataContainer.innerHTML = html; } else { wildfireDataContainer.innerHTML = '

No active wildfires reported at the moment.

'; } }) .catch(error => { wildfireDataContainer.innerHTML = '

Could not load wildfire data. Please try again later.

'; console.error('Error fetching wildfire data:', error); }); } });