// next prev function
$(document).ready(function() {
    var divs = $('.show-section>.steps-inner');
    var now = 0; // currently shown div
    divs.hide().first().show(); // hide all divs except first
    $(".next").click(function() {
        divs.eq(now).hide();
        now = (now + 1 < divs.length) ? now + 1 : 0;
        divs.eq(now).show(); // show next
    });
    $(".prev").click(function() {
        divs.eq(now).hide();
        now = (now > 0) ? now - 1 : divs.length - 1;
        divs.eq(now).show(); // show previous
    });
});
// label active on input check
$(document).ready(function() {
    $('.form-input input').on("change", function() {

        $(".form-input").removeClass("active-input");
        $(this).parent().addClass("active-input");
    })
})
var timeoutHandle;

function countdown(minutes, seconds) {
    function tick() {
        var counter = document.getElementById("countdown-timer");
        counter.innerHTML =
            minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);
        seconds--;
        if (seconds >= 0) {
            timeoutHandle = setTimeout(tick, 1000);
        } else {
            if (minutes >= 1) {
                // countdown(mins-1);   never reach “00″ issue solved:Contributed by Victor Streithorst
                setTimeout(function() {
                    countdown(minutes - 1, 59);
                }, 1000);
            }
        }
    }
    tick();
}
countdown(document.getElementById("min").value, document.getElementById("sec").value);
$("#finish-exam").click(function() {
    var UNQ = $('#exam-uniqid').val();
    var USN = $('#exam-username').val();
    var IDS = $('#exam-number').val();
    const asnwer_json = [];
    $("input[name='EXAM[]']").each(function(i, v) {
        asnwer_json.push(`{
    "Answer": {
      "ID": "` + this.id + `",
      "REPLAY": "` + this.value + `"
    }
  }`);
    });
    $.post(
        "https://app2.drsiamakheydari.ir/ChatCreateAnswer.php", {
            username: USN,
            uid: UNQ,
            number: IDS,
            body: JSON.stringify(asnwer_json),
        },
        function(data, status) {

        }
    );
});

function square() {
    if (document.getElementById("countdown-timer").innerHTML == '00:00' || document.getElementById("countdown-timer").innerHTML == '0:00') {
        var UNQ = $('#exam-uniqid').val();
        var USN = $('#exam-username').val();
        const asnwer_json = [];
        $("input[name='EXAM[]']").each(function(i, v) {
            asnwer_json.push(`{
    "Answer": {
      "ID": "` + this.id + `",
      "REPLAY": "` + this.value + `"
    }
  }`);
        });
        $.post(
            "https://app2.drsiamakheydari.ir/ChatCreateAnswer.php", {
                username: USN,
                uid: UNQ,
                body: JSON.stringify(asnwer_json),
            },
            function(data, status) {
                location.reload();
            }
        );
    }
}
setInterval(square, 1000);