$(".yesanswer").click(function () {
  $.ajax({
    type: "POST",
    url: "setcookie.php",
  });
});

function hideov() {
  document.body.style.overflowY = "auto";

  document.getElementById("changeover").classList.add("close-animation");

  var element = document.getElementById("changeover");

  element.addEventListener("animationend", function () {
    // This event will be triggered when the animation ends
    element.style.display = "none";

    var elementx = document.getElementById("hidemynow");
    elementx.classList.add("fadeOutx");

    // Wait for the animation to complete (1 second in this example) and then hide the element
    setTimeout(function () {
      elementx.style.display = "none";
    }, 500); // Adjust the timeout to match the animation duration
  });
}


document.addEventListener("DOMContentLoaded", function () {
    // Get the countdown elements
    let countdownElement = document.getElementById("countax");
    let countdownElementx = document.getElementById("countaxx");

    // --- COUNTAX: 35 minutes ---
    let previousCountdownDataAx = JSON.parse(localStorage.getItem("countdownDataAx")) || {};
    let previousTimestampAx = previousCountdownDataAx.timestamp || 0;
    let previousTotalTimeInSecondsAx = previousCountdownDataAx.totalTimeInSeconds || (34 * 60 + 60);
    let currentTime = new Date().getTime();
    let elapsedTimeInSecondsAx = Math.floor((currentTime - previousTimestampAx) / 1000);
    let totalTimeInSecondsAx = Math.max(previousTotalTimeInSecondsAx - elapsedTimeInSecondsAx, 0);

    if (elapsedTimeInSecondsAx > 1 * 24 * 60 * 60) {
        totalTimeInSecondsAx = 34 * 60 + 60;
    }

    setInterval(function () {
        let minutes = Math.floor(totalTimeInSecondsAx / 60);
        let seconds = totalTimeInSecondsAx % 60;

        countdownElement.textContent = `${minutes.toString().padStart(2, '0')}m ${seconds.toString().padStart(2, '0')}s`;

        if (totalTimeInSecondsAx === 0) {
            totalTimeInSecondsAx = 34 * 60 + 60;
        } else {
            totalTimeInSecondsAx--;
        }

        localStorage.setItem("countdownDataAx", JSON.stringify({
            timestamp: new Date().getTime(),
            totalTimeInSeconds: totalTimeInSecondsAx
        }));
    }, 1000);

    // --- COUNTAXX: Same functionality as COUNTAX ---
    let previousCountdownDataAxx = JSON.parse(localStorage.getItem("countdownDataAxx")) || {};
    let previousTimestampAxx = previousCountdownDataAxx.timestamp || 0;
    let previousTotalTimeInSecondsAxx = previousCountdownDataAxx.totalTimeInSeconds || (34 * 60 + 60);
    let elapsedTimeInSecondsAxx = Math.floor((currentTime - previousTimestampAxx) / 1000);
    let totalTimeInSecondsAxx = Math.max(previousTotalTimeInSecondsAxx - elapsedTimeInSecondsAxx, 0);

    if (elapsedTimeInSecondsAxx > 1 * 24 * 60 * 60) {
        totalTimeInSecondsAxx = 34 * 60 + 60;
    }

    setInterval(function () {
        let minutes = Math.floor(totalTimeInSecondsAxx / 60);
        let seconds = totalTimeInSecondsAxx % 60;

        countdownElementx.textContent = `${minutes.toString().padStart(2, '0')}m ${seconds.toString().padStart(2, '0')}s`;

        if (totalTimeInSecondsAxx === 0) {
            totalTimeInSecondsAxx = 34 * 60 + 60;
        } else {
            totalTimeInSecondsAxx--;
        }

        localStorage.setItem("countdownDataAxx", JSON.stringify({
            timestamp: new Date().getTime(),
            totalTimeInSeconds: totalTimeInSecondsAxx
        }));
    }, 1000);
});
