console.log('scripts loaded');
document.onreadystatechange = function(event) {
    if (document.readyState === "complete") {
        if(document.getElementById('pourcent-reveil'))
        {
            console.log('has progress bar');
            setcurrentprogress(document.getElementById('pourcent-reveil'),5);
            updateprogress(document.getElementById('pourcent-reveil'),5);
        }
        if(oLoaded = document.getElementById('loaded'))
        {
            console.log('has live content');
            oLoaded.setAttribute("class","shown");
            oLoaded.removeAttribute("aria-hidden","true");
            oLoaded.innerHTML="Document chargé!";
            oLoaded.setAttribute("aria-live","off");
            setTimeout(warning, 1500);
        }
    }
}

function warning()
{
    if(document.getElementById('warning'))
    {
        document.getElementById('warning').innerHTML="Erreur de communication avec le serveur!";
        document.getElementById('warning').setAttribute("class","shown");
        document.getElementById('warning').removeAttribute("aria-hidden");
    }
}

function setcurrentprogress(obj,value)
{
    obj.setAttribute("value",value);
    obj.setAttribute("aria-valuenow",value);
}

function updateprogress(obj, step=5)
{
    currentprogress = parseInt(obj.getAttribute("value")) + step;
    if(currentprogress >= 100)
    {
        console.log("finished");
        setcurrentprogress(obj,100);
        document.getElementById("finished").setAttribute("style","");    
        return;
    }
    console.log("updateprogress to "+currentprogress);
    setcurrentprogress(obj,currentprogress);
    setTimeout(updateprogress, 500, obj);
}