summaryrefslogtreecommitdiff
path: root/js/timer.js
blob: 318230a17a4b5ace9db5e767f16f3352ba133bbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function getseconds() {
    // take mins remaining (as seconds) away from total seconds remaining
    return secs-Math.round(mins *60);
}
function getminutes() {
    // minutes is seconds divided by 60, rounded down
    mins = Math.floor(secs / 60);
    return mins;
}
function Decrement() {
    if (document.getElementById) {
        minutes = document.getElementById("minutes");
        seconds = document.getElementById("seconds");
        // if less than a minute remaining
        if (seconds < 59) {
            seconds.value = secs;
        } else {
            minutes.innerHTML= getminutes();
            seconds.innerHTML = getseconds();
        }
        secs--;
        
        if(mins == 0 && secs == 0) {
            window.location = modPath + "eligibility_test/end";
        }
        setTimeout('Decrement()',1000);
    }
}
function countdown() {
    setTimeout('Decrement()',1000);
}
$(document).ready(function() {
    basePath = Drupal.settings.basePath;
    modPath = basePath + "tbc_external_review/";
    mins = parseInt($("#minutes_remaining").val());
    tmp = parseInt($("#seconds_remaining").val());  
    secs = mins * 60 + tmp;
    countdown();
});