function autoTestSession() {
    if (!($("autoTestSessionDiabled") && $("autoTestSessionDiabled").active == "true") && $("frmTestSession")) {
        new Ajax.Request("rpc.php", {
            method: "post",
            parameters: $("frmTestSession").serialize(true),
            onSuccess : function (transmission) {
                if(transmission.responseText == "0") {
                    Event.stopObserving(window, "unload", unload);
                    window.location.href = "index.php";
                }
            }
        });
        window.setTimeout("autoTestSession()", 10000);
    }
}

// prendre en compte la premiere fonction
var timer = 90;
function sessionTimer() {
    if (timer > 0) {
        $("sessionTimerDisplay").innerHTML = " dans : " + timer + "s";
        if ($("autoTestSessionDiabled").active == "true") {
            timer--
            window.setTimeout("sessionTimer()", 1000);
        }
        else {
            timer = 90;
            $("sessionTimerDisplay").innerHTML = "";
            autoTestSession();
        }
    }
    else {
        Event.stopObserving(window, "unload", unload);
        window.location.href="index.php";
    }
}

Event.observe (window, "load", autoTestSession);

Event.observe (window, "load", function () {
    if ($("autoTestSessionDiabled"))  {
        Event.observe($("autoTestSessionDiabled"), "click", function (event) {
            $("autoTestSessionDiabled").active = "true";
            if ($("autoTestSessionDiabled").active == "true") {
                sessionTimer();
            }
        });
    }
    if ($("autoTestSessionEnabled"))  {
        Event.observe($("autoTestSessionEnabled"), "click", function (event) {
            $("autoTestSessionDiabled").active = "false";
        });
    }

});