document.addEventListener('DOMContentLoaded', () => {
// Inquiry Form Handling
const inquiryForm = document.getElementById('inquiryForm');
if (inquiryForm) {
inquiryForm.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(inquiryForm);
const submitBtn = inquiryForm.querySelector('button[type="submit"]');
submitBtn.disabled = true;
submitBtn.innerHTML = ' Sending...';
try {
const response = await fetch('/api/inquiry.php', {
method: 'POST',
body: formData
});
const result = await response.json();
if (result.success) {
inquiryForm.innerHTML = `
Thank you, ${formData.get('name')}!
We have received your inquiry and will contact you shortly.
`;
} else {
alert('Something went wrong. Please try again.');
submitBtn.disabled = false;
submitBtn.innerHTML = 'Send Inquiry';
}
} catch (error) {
console.error('Error:', error);
alert('Connection error. Please try again later.');
submitBtn.disabled = false;
submitBtn.innerHTML = 'Send Inquiry';
}
});
}
// Initialize cart count
updateCartCount();
});
function addToCart(id, name, price, image) {
const formData = new FormData();
formData.append('id', id);
formData.append('name', name);
formData.append('price', price);
formData.append('image', image);
fetch('/api/cart.php?action=add', {
method: 'POST',
body: formData
})
.then(response => {
if (!response.ok) throw new Error('Network response was not ok');
return response.json();
})
.then(data => {
if (data.success) {
updateCartCount(data.cart_count);
showToast(`