81 lines
3.2 KiB
JavaScript
81 lines
3.2 KiB
JavaScript
// Smooth scrolling for anchor links
|
|
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
|
anchor.addEventListener('click', function (e) {
|
|
e.preventDefault();
|
|
|
|
document.querySelector(this.getAttribute('href')).scrollIntoView({
|
|
behavior: 'smooth'
|
|
});
|
|
});
|
|
});
|
|
|
|
// Address Availability Check
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const availabilityForm = document.getElementById('availability-form');
|
|
const availabilityResult = document.getElementById('availability-result');
|
|
|
|
if (availabilityForm) {
|
|
availabilityForm.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const addressInput = document.getElementById('address-input');
|
|
const address = addressInput.value;
|
|
const button = this.querySelector('button');
|
|
|
|
if (!address) {
|
|
availabilityResult.textContent = 'Please enter an address.';
|
|
availabilityResult.className = 'alert alert-warning';
|
|
availabilityResult.style.display = 'block';
|
|
return;
|
|
}
|
|
|
|
// Show loading state
|
|
button.disabled = true;
|
|
button.textContent = 'Checking...';
|
|
availabilityResult.style.display = 'none';
|
|
|
|
fetch('api/check_availability.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ address: address })
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
if (data.serviceable) {
|
|
// Address is serviceable, scroll to plans section
|
|
document.getElementById('plans').scrollIntoView({
|
|
behavior: 'smooth'
|
|
});
|
|
// Optionally, hide the success message after a delay
|
|
setTimeout(() => {
|
|
availabilityResult.style.display = 'none';
|
|
}, 3000);
|
|
availabilityResult.textContent = data.message;
|
|
availabilityResult.className = 'alert alert-success';
|
|
} else {
|
|
// Address is not serviceable
|
|
availabilityResult.textContent = data.message;
|
|
availabilityResult.className = 'alert alert-info';
|
|
}
|
|
} else {
|
|
availabilityResult.textContent = data.message || 'An unexpected error occurred.';
|
|
availabilityResult.className = 'alert alert-danger';
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
availabilityResult.textContent = 'A network error occurred. Please try again.';
|
|
availabilityResult.className = 'alert alert-danger';
|
|
})
|
|
.finally(() => {
|
|
availabilityResult.style.display = 'block';
|
|
button.disabled = false;
|
|
button.textContent = 'Check Availability';
|
|
});
|
|
});
|
|
}
|
|
});
|