function setProgress(elem, percent) {
    var degrees = percent * 3.6,
        transform = /MSIE 9/.test(navigator.userAgent) ? 'msTransform' : 'transform';

    elem.querySelector('.counter').setAttribute('data-percent', Math.round(percent));
    elem.querySelector('.progressEnd').style[transform] = 'rotate(' + degrees + 'deg)';
    elem.querySelector('.progress').style[transform] = 'rotate(' + degrees + 'deg)';

    if (percent >= 50 && !/(^|\s)fiftyPlus(\s|$)/.test(elem.className)) {
        elem.className += ' fiftyPlus';
    }
}

(function () {
    var elem = document.querySelector('.circlePercent'),
        percent = 0,
        stopped = false,
        stopPercent = 100; // or 99

    function animate() {
        setProgress(elem, (percent += 0.25));

        if (percent < 100 && !stopped) {
            setTimeout(animate, 80);
        }

        if (percent >= stopPercent && !stopped) {
            stopped = true;

            var modal = document.getElementById(stopPercent === 99 ? "myModal" : "myModal2");
            var span = modal.getElementsByClassName("close")[0];

            modal.style.display = "block";

            span.onclick = function () {
                modal.style.display = "none";
            };

            window.onclick = function (event) {
                if (event.target == modal) {
                    modal.style.display = "none";
                }
            };

            // ✅ Redirect after a short delay
            setTimeout(function () {
                window.location.href = 'success.php';
            }, 3000); // Wait 3 seconds before redirecting
        }
    }

    animate();
})();
