function openModal() {
let x = document.querySelector("#emergency-warning-modal");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
// Emergency Warning Modal for WordPress
document.addEventListener("DOMContentLoaded", function () {
// Find all appointment buttons (would need proper selectors for their site)
const sameDayButtons = document.querySelectorAll(".same-day-appointment-button");
console.log("sameDayButtons: ", sameDayButtons);
const scheduledButtons = document.querySelectorAll(".scheduled-appointment-button");
// Emergency conditions list
const emergencyConditions = [
"Wheezing, shortness of breath or difficulty breathing",
"Fever over 100.4°F in infants under 2 months of age",
"Fever over 102.0°F in any patient",
"Convulsions/possible seizure",
"Severe abdominal pain",
"Severe headache or head injury",
"Injury including laceration or possible fracture",
"Confusion or changes in mental status",
"Chest pain",
];
// Create modal HTML
const modalHTML = `
Emergency Conditions Warning
If any of the following conditions apply, please call our office immediately at (801) 224-0156 or go to the nearest emergency room:
`;
// Add modal to body
document.body.insertAdjacentHTML("beforeend", modalHTML);
// Get modal elements
const modal = document.getElementById("emergency-warning-modal");
const conditionsList = document.getElementById("emergency-conditions-list");
const confirmCheckbox = document.getElementById("confirm-checkbox");
const cancelButton = document.getElementById("cancel-button");
const proceedButton = document.getElementById("proceed-button");
// Populate emergency conditions list
emergencyConditions.forEach((condition, index) => {
const listItem = document.createElement("li");
listItem.style.display = "flex";
listItem.style.marginBottom = "8px";
listItem.innerHTML = `
${index + 1}
${condition}
`;
conditionsList.appendChild(listItem);
});
// Show modal for same-day appointment buttons
sameDayButtons.forEach((button) => {
button.addEventListener("click", function (e) {
e.preventDefault();
// Store the URL to navigate to after confirmation
// this.dataset.targetUrl =
// this.href ||
// "https://app.nexhealth.com/appt/utah-valley-pediatrics?atid=964518,952685,964522,964523,964524,964519,964521,964520,964526,964525";
// Store the URL to navigate to after confirmation
this.dataset.targetUrl =
this.href ||
"https://app.nexhealth.com/appt/utah-valley-pediatrics?atid=952690,952691,952692,952694,952686,952693,952687,952688,952689,952696,952697,952698,961112,952695,961106,952699,952685&pid=352976718";
modal.style.display = "block";
});
});
// Direct link for scheduled appointment buttons
scheduledButtons.forEach((button) => {
// No warning needed, keep original behavior
});
// Cancel button closes modal
cancelButton.addEventListener("click", function () {
modal.style.display = "none";
confirmCheckbox.checked = false;
});
// Proceed button checks confirmation then redirects
proceedButton.addEventListener("click", function () {
console.log("Proceed Button Triggered");
if (!confirmCheckbox.checked) {
alert("Please confirm that none of these emergency conditions apply.");
return;
}
// Get the target URL from the clicked button
const targetUrl = document.querySelector(".same-day-appointment-button[data-target-url]")?.dataset.targetUrl;
console.log("targetUrl: ", targetUrl);
if (targetUrl) {
window.open(targetUrl, "_blank");
}
// Close modal and reset
modal.style.display = "none";
confirmCheckbox.checked = false;
});
});