WS_waitscreen = true;

window.onload = function(){
    
    // Call Entry - Movído dentro del listDraw, se carga luego de que se pintan.
    //getEntry(getParameterByName('sessionid'))
    
    
    // Go to Register Profesional Information
    document.getElementById('previous-button').addEventListener("click", function(){ 
        gotoPage('register','regPersonInf',{ 'sessionid' : getParameterByName('sessionid') })
    });
    
    // Go to Register Transactional Data
    document.getElementById('next-button').addEventListener("click", function(){
        verify()
    });
     
    // Later
    document.getElementById('later-button').addEventListener("click", function(){
        document.getElementsByClassName('completeLater')[0].style.display = 'table'
    });
    
    document.getElementById('completeLaterAccept').addEventListener("click", function(){
        gotoPage('dashboard','home', { 'sessionid' : getParameterByName('sessionid') })
    });
    
    document.getElementById('completeLaterCancel').addEventListener("click", function(){
        document.getElementsByClassName('completeLater')[0].style.display = 'none'
    });
    
    // Add file
    document.addEventListener('change', function (evt) {
        if (evt.target.className === 'file') {
            var valid = validarFile(evt.target)
            
            if(valid){
                if(evt.target.files[0].name !== getLangById('select')[lang]){
                    
                    // Asignar el nombre y color
                    evt.target.offsetParent.previousElementSibling.children[0].textContent = evt.target.files[0].name
                    evt.target.offsetParent.previousElementSibling.children[0].style.color = "#262624"
                    
                    // Clases
                    evt.target.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[2].children[0].classList.remove('notReadyButton')
                    evt.target.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[2].children[0].classList.add('cancel-button')
                    evt.target.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[1].children[0].classList.remove('notReadyButton')
                    evt.target.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[1].children[0].classList.add('cancel-button')
                    evt.target.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[2].children[0].disabled = false
                    evt.target.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[1].children[0].disabled = false
                    
                    evt.target.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[0].classList.add('invisible');
                    
                    const inpFile = evt.target;
                    const previewContainer = evt.target.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[1].children[1];
                    const previewImage = previewContainer.children[0];
                    const file = evt.target.files[0];
                    if(file){
                        const reader = new FileReader();
                        reader.addEventListener("load",function(){
                            //console.log(this)
                            previewImage.setAttribute("src",this.result)
                        });
                        reader.readAsDataURL(file);
                        inpFile.setAttribute("loaded",1);
                    }
                } 
            }else{
                //evt.target.parentNode.parentNode.parentNode.children[2].innerHTML = 'Formato inválido. Permitidos: jpg y pdf.';
                //evt.target.parentNode.parentNode.parentNode.children[2].style.display = 'block';
            }
            
        }  
    });
    
    // Preview photo
    document.addEventListener("click", function(evt){
        if (evt.target.id === 'preview'){
            console.log(evt.target)
            //console.log(evt.target.nextElementSibling)
            
            // La imagen de cargado esta ok
            if (evt.target.parentNode.parentNode.children[0].style.opacity!='0' && evt.target.parentNode.parentNode.children[0].style.display!='none'){
                
                // Revisar si el input tiene valor o no
                
                // El input se acaba de cargar y tiene valor
                if (evt.target.parentNode.parentNode.parentNode.children[0].children[0].children[1].children[1].children[0].value!=''){
                    if(evt.target.parentNode.parentNode.parentNode.children[0].children[0].children[1].children[1].children[0].value.endsWith('.pdf')){
                        window.open(evt.target.nextElementSibling.children[0].src,'_blank'); 
                    }
                    else{
                        evt.target.nextElementSibling.style.display = 'block';
                    }
                // El input se cargo antes y no tiene valor  
                } else{
                    console.log(evt.target.parentNode.parentNode.parentNode.children[0].children[0].children[1].children[1].children[0])
                    if(evt.target.nextElementSibling.children[0].getAttribute('type').endsWith('.pdf')){
                        window.open(evt.target.nextElementSibling.children[0].src,'_blank'); 
                    }
                    else{
                        evt.target.nextElementSibling.style.display = 'block';
                    }
                    //evt.target.nextElementSibling.children[0].setAttribute("src",evt.target.parentNode.parentNode.parentNode.children[0].children[0].children[1].children[0].children[0].textContent)
                    console.log(evt.target.nextElementSibling)
                }
                
            // La imagen de cargado no esta ok    
            }else{
                // No se puede
            }
        }
    });
    
    // Return preview photo
    document.addEventListener("click", function(evt){
         if (evt.target.id === 'return'){
             evt.target.parentNode.parentNode.style.display = 'none'
         }
    });
    
    // Delete photo
    document.addEventListener("click", function(evt){
        if (evt.target.id === 'delete'){
            //console.log(evt.target.parentNode.parentNode.parentNode.children[0].children[0].children[1].children[1].children[0])
            evt.target.parentNode.parentNode.parentNode.children[0].children[0].children[1].children[1].children[0].value ='';
            evt.target.classList.add('notReadyButton')
            evt.target.classList.remove('cancel-button')
            evt.target.disabled = true;
            evt.target.parentNode.parentNode.children[1].children[0].classList.add('notReadyButton')
            evt.target.parentNode.parentNode.children[1].children[0].classList.add('cancel-button')
            evt.target.parentNode.parentNode.children[1].children[0].disabled = true;
            evt.target.parentNode.parentNode.parentNode.children[0].children[0].children[1].children[0].children[0].textContent = getLangById('select')[lang]
            evt.target.parentNode.parentNode.parentNode.children[0].children[0].children[1].children[0].children[0].style.color ='#7D8B9E'
            
            //Blanqueo el valor que me indica si está cargado para evniar el id o no
            evt.target.parentNode.parentNode.parentNode.children[0].children[0].children[1].children[1].children[0].setAttribute("loaded",0);
            
            evt.target.parentNode.parentNode.children[0].children[0].style.display = 'none'
            
            
         }
    });
    
    // Session Update
    document.getElementById('expSessionButton').addEventListener("click",function(){
        var req = {
            'sessionid': getParameterByName('sessionid')
        }
        sessionUpdate(req)
    })
    
    // Remove red errors 
    document.getElementsByTagName('body')[0].addEventListener("change", function(){
        for(i = 0; i < document.getElementsByClassName('file').length; i++){
            if (document.getElementsByClassName('file')[i].value!=""){
                document.getElementsByClassName('error')[i].innerHTML = '';
            }
        }
    }); 
    init();
    
    setLang()
    
    //Mostrar HTML cargado
    esconderHTML(false);
};

function init(){
    var req = {
        "sessionid" : getParameterByName('sessionid'),
        "type" : 1
    };
    /* level : */
    getList(req);
}

function verify(){
    var complete = true;
    console.log(document.getElementsByClassName('file'))
    for(i = 0; i < document.getElementsByClassName('file').length; i++){
        if ((document.getElementsByClassName('file')[i].value=="" || document.getElementsByClassName('file')[i].value==null || document.getElementsByClassName('file')[i].value==" ")
            && document.getElementsByClassName('file')[i].getAttribute('level') <= entrydata.entry.level.id + 1 ){
            if (document.getElementsByClassName('file')[i].parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[0].style.opacity=='0' ||
                document.getElementsByClassName('file')[i].parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[0].classList.contains('invisible') ||
                document.getElementsByClassName('file')[i].parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[0].children[0].style.opacity=='0' ||
                document.getElementsByClassName('file')[i].parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[0].children[0].style.display=='none'){
                    complete = false;
                    document.getElementsByClassName('error')[i].innerHTML = getLangById('usersUpdateperson1')[lang];
                }
            // evt.target.parentNode.parentNode.style.display = 'none'
        }
    }
    if(!complete){
        return;
    }else{
        uploadFile();
    }
}

function getList(req){
    callWS("GET", "uploads/list", req, response);
    function response(status, rsp){
        switch(status){
            case 200:
                var rp = JSON.parse(rsp);
                var numofrecords = rp.numofrecords
                listDraw(rp.records);
                // Ok
                //gotoPage('register','regPersonTr',{ 'sessionid' : getParameterByName('sessionid') })
                break;
            case 204:
                break;
            case 400:
                // Parametros incorrectos
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                // Error
                break;
            default:
                break;
        }
    }  
}

function listDraw(rsp){
    var tbl = document.getElementById("regForm");
    var node = tbl.firstElementChild.cloneNode(true);
    var tmp = null; tmp = node.cloneNode(true);
    tbl.innerHTML = "";
    if(!(rsp.length>0)){
        console.log('if')
        var ele = null;
        ele = tmp.cloneNode(true);
        ele.style.display = "none";
        tbl.appendChild(ele);
    }else{
        for(var i=0; i<rsp.length; i++){
            //console.log(i) // 0, 1, 2, 3
            console.log(rsp)
            var ele = null;
            ele = tmp.cloneNode(true);
            ele.style.display = "";
            //Bg del reglon
            ele.classList.add("tableForm");
            ele.children[0].children[0].children[1].children[1].children[0].setAttribute('level',rsp[i].level.id)
            console.log(ele)
            if(rsp[i].dsc !== ""){
                ele.id = (i+1)
                ele.children[0].children[0].children[0].textContent = rsp[i].dsc // Nombrelabel
                ele.children[0].children[0].children[1].children[1].children[0].id = "file"+rsp[i].id; // Asignar id a cada input
                ele.children[0].children[0].children[1].children[1].children[0].setAttribute("loaded", 0);
                ele.children[0].children[0].children[1].children[1].children[0].setAttribute("label",rsp[i].id);
            }
            
            setLevel(ele.children[0].children[0].children[1].children[1].children[0])
            
            var col1, col2;
            var col1, name;
            //tbl.
            //tbl.appendChild(ele);
            //console.log(ele)
        
            
            tbl.appendChild(ele);
            
        }
    }
}
function uploadFile(){
    var wait = document.createElement("div");
    wait.classList.add("waitScreenUp")
    wait.setAttribute("id", "waitScreen");
    var spin = document.createElement("div");
    spin.classList.add("spinChar");
    spin.innerHTML = '<i class="fas fa-circle-notch fa-spin"></i>';
    //wait.appendChild(spin);
    document.body.appendChild(wait);
    
    var recaudos = document.getElementsByClassName("file");
    
    var formdata = new FormData();
    var docids = "";
    formdata.append('sessionid', getParameterByName('sessionid'));
    for(var i=0; i<recaudos.length; i++){
        if(recaudos[i].getAttribute("loaded") == 1){
            docids  += recaudos[i].getAttribute("label")+"-"; 
        }
        if(recaudos[i].value !== ""){    
            formdata.append(recaudos[i].getAttribute("label"), recaudos[i].files[0]);
        }
    }
    docids = docids.slice(0,-1); // Controla si estoy editando, guardando o eliminando algun archivo
    formdata.append("uploadids", docids);
    formdata.append("step", 4);
    
    var xhttp = new XMLHttpRequest();
    var url = globalurl + "/api/users/updateperson.php";
    
    xhttp.upload.addEventListener("loadstart", progressHandler, false);
    xhttp.open("POST", url);
    xhttp.addEventListener("load", completeHandler, false);
    xhttp.send(formdata);
    
}

var filestmp; 
function progressHandler(event){
    var progressList = document.getElementsByClassName("progress");
    var recaudos = document.getElementsByClassName("file");
    console.log(recaudos)
    var cnt = 0;
    var positions = [];
    for(var i=0; i<recaudos.length; i++){
        if(recaudos[i].value !== ""){
            cnt = cnt+1;
            positions.push(i);
        }
    }
    
    var maxTime = (10000)//*cnt); //15s por cada elemento
    var time = 0;
    var tot = 0;
    var w = 0;
    filestmp = setInterval(function(){
        if(tot<cnt){
            if(time > maxTime){
                var progBox = document.getElementsByClassName("progress")[positions[tot]];
                progBox.classList.remove("invisible");
                var dsc = progBox.children[1];
                
                tot = tot + 1; // Aumenta el completado
                time = 0; // Reinicia el contador porcentual
                
                if(document.getElementById("waitScreen") !== null && tot==cnt){  
                    //SI es el ultimo y el wait sigue activo registra hasta 99% para mostrarse pendiente aún
                    dsc.innerHTML = lang ==  getLangById('usersUpdateperson2')[lang];
                    progBox.lastElementChild.style.width = "99%";
                }else{
                    dsc.innerHTML = getLangById('successfulUploadLabel')[lang];
                    progBox.lastElementChild.style.width = "100%";
                }
                    //clearInterval(filestmp);
            }else{
                var width = Math.round((time*100)/(maxTime));
                var progBox = document.getElementsByClassName("progress")[positions[tot]];
                progBox.parentElement.classList.remove("invisible");
                var dsc = progBox.children[1];
                dsc.innerHTML = getLangById('usersUpdateperson3')[lang] + width+"%"
                progBox.lastElementChild.style.width = width+"%";
                time = time + 1000;
            }
        }else{
            clearInterval(filestmp);
        }
    },1000);
}

function completeHandler(event){
    var recaudos = document.getElementsByClassName("file");
    var progressList = document.getElementsByClassName("progress");
    for(var i=0;i<recaudos.length;i++){
        if(recaudos[i].value !== ""){
            var progBox = progressList[i];
            progBox.parentElement.classList.remove("invisible");
            var dsc = progBox.children[1];
            dsc.innerHTML =  getLangById('successfulUploadLabel')[lang];
            progBox.lastElementChild.style.width = "100%";
        }
    }
    clearInterval(filestmp);
    var waitScreen = document.getElementById("waitScreen");
    document.body.removeChild(waitScreen);
    
    //Redireccion de pagina
    console.log('fel')
    gotoPage('register','regPersonTr',{ 'sessionid' : getParameterByName('sessionid') })
}
var entrydata;
function getEntry(sessionid){
    console.log('entry')
    callWS("GET", "users/entry", { 'sessionid' : sessionid}, response);
        
    function response(status, rsp){
        switch(status){
            case 200:
                entrydata = JSON.parse(rsp);
                levels = JSON.parse(rsp).entry.levels
                
                // Add file
                var uploads = JSON.parse(rsp).entry.person.uploads;
                if(uploads !== null){
                    setTimeout(function(){ 
                        for(i = 0; i<uploads.length ; i++ ){
                            var evt = document.getElementById('file'+uploads[i].id);
                            evt.setAttribute('level',JSON.parse(rsp).entry.person.uploads[i].level.id)
                            evt.parentNode.parentNode.setAttribute('level',JSON.parse(rsp).entry.person.uploads[i].level.id)
                            evt.parentNode.parentNode.children[0].children[0].textContent = uploads[i].url;
                            evt.parentNode.parentNode.children[0].children[0].style.color = "#262624";
                            
                            // Clases
                            evt.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[2].children[0].classList.remove('notReadyButton')
                            evt.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[2].children[0].classList.add('cancel-button')
                            evt.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[1].children[0].classList.remove('notReadyButton')
                            evt.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[1].children[0].classList.add('cancel-button')
                            evt.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[2].children[0].disabled = false
                            evt.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[1].children[0].disabled = false
                            evt.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[0].classList.remove('invisible')
                            
                            // Validado o no
                            if (JSON.parse(rsp).entry.person.uploads[i].validated == -1){
                                evt.parentNode.parentNode.children[2].children[0].classList.add("iconRed")
                                evt.parentNode.parentNode.children[2].children[0].classList.add("fas")
                                evt.parentNode.parentNode.children[2].children[0].classList.add("fa-times-circle")
                            }
                            else if (JSON.parse(rsp).entry.person.uploads[i].validated == 0){
                                evt.parentNode.parentNode.children[2].children[0].classList.add("iconYellow")
                                evt.parentNode.parentNode.children[2].children[0].classList.add("fas")
                                evt.parentNode.parentNode.children[2].children[0].classList.add("fa-pause-circle")
                            }
                            else if (JSON.parse(rsp).entry.person.uploads[i].validated == 1){
                                evt.parentNode.parentNode.children[2].children[0].classList.add("iconGreen")
                                evt.parentNode.parentNode.children[2].children[0].classList.add("fas")
                                evt.parentNode.parentNode.children[2].children[0].classList.add("fa-check-circle")
                                evt.disabled = true;
                                evt.style.cursor = 'default'
                                
                                evt.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[2].children[0].classList.add('notReadyButton')
                                evt.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[2].children[0].disabled = true;
                                evt.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[2].children[0].classList.remove('cancel-button')
                            }
                            
                            const inpFile = evt;
                            const previewContainer = evt.parentNode.parentNode.parentNode.parentNode.parentNode.children[1].children[1].children[1];
                            const previewImage = previewContainer.children[0];
                            if(uploads[i].url !== ""){
                                inpFile.setAttribute("loaded", 1);
                                //Se asigna la url
                                previewImage.setAttribute("src",uploads[i].url);
                                previewImage.setAttribute("type",uploads[i].type);
                            }
                        
                        }        
                    }, 500);
                }
                setDynamicLang()
                //setLevels(levels)
                document.getElementsByClassName('pageCnt')[0].style.visibility="visible"
                // Window Load
                var waitScreen = document.getElementById("waitScreen");
                document.body.removeChild(waitScreen);
                WS_waitscreen = false;
                
                break;
            case 204:
                break;
            case 400:
                // Parametros incorrectos
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                // Error
                break;
            default:
                break;
        }
        //console.log(status)
        //console.log(rsp)
    }    
}

function validarFile(all){
    //EXTENSIONES Y TAMANO PERMITIDO.
    //var extensiones_permitidas = [".png", ".bmp", ".jpg", ".jpeg", ".pdf", ".doc", ".docx", ".gif"];
    var extensiones_permitidas = [".jpg",".pdf",".png",".jpeg"];
    var tamano = 2; // EXPRESADO EN MB.
    var rutayarchivo = all.value;
    var ultimo_punto = all.value.lastIndexOf(".");
    var extension = rutayarchivo.slice(ultimo_punto, rutayarchivo.length);
    if(extensiones_permitidas.indexOf(extension.toLowerCase()) == -1){
        //alert("Extensión de archivo no valida");
        document.getElementById(all.id).value = "";
        all.parentNode.parentNode.parentNode.children[2].innerHTML = getLangById('usersUpdateperson4')[lang];
        all.parentNode.parentNode.parentNode.children[2].style.display = 'block';
        return false; // Si la extension es no válida ya no chequeo lo de abajo.
    }else{
        if((all.files[0].size / 1048576) > tamano){
            document.getElementById(all.id).value = "";
            all.parentNode.parentNode.parentNode.children[2].innerHTML = getLangById('usersUpdateperson5')[lang] +tamano+"MB.";
            all.parentNode.parentNode.parentNode.children[2].style.display = 'block';
            return false;
        }else{
            return true;
        }
    }
    /*if((all.files[0].size / 1048576) > tamano)
    {
        alert("El archivo no puede superar los "+tamano+"MB");
        document.getElementById(all.id).value = "";
        return;
    }*/
}

function expiredSession(){
    document.getElementsByClassName('expired')[0].style.display = "table"
    WS_waitscreen = false;
    var seconds = 30;
    var countdown = setInterval(countDown, 1000);
    
    function countDown(){
        seconds--;
        if(seconds == 0){
            if(document.getElementsByClassName('expired')[0].style.display == "table"){
                gotoPage('login','main','');
                clearInterval(countdown);
            }
        }
        if(document.getElementsByClassName('expired')[0].style.display == "none"){
            clearInterval(countdown)
        }
    }
}

function sessionUpdate(req){
    callWS('GET', 'session/update', req, response);
    function response(status, rsp){
        console.log('session/update')
        console.log(JSON.parse(rsp));
        console.log(status) 
        switch(status){
            case 200:
                document.getElementsByClassName('expired')[0].style.display = "none"
                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 402:
                break;
            case 403:
                break;
            case 500:
                break;
            default:
                break;
        }
    }   
}

function setLevels(levels){
    console.log(levels)
    levels1 = levels[1].basicRequired.split(',')
    levels2 = levels[2].basicRequired.split(',')
    levels3 = levels[3].basicRequired.split(',')
    console.log(document.getElementsByClassName('inputElement'))
    console.log(document.getElementsByClassName('inputElement').length)
    for(var i = 0; i < document.getElementsByClassName('inputElement').length ; i++){
        if(levels1.includes(document.getElementsByClassName('inputElement')[i].getAttribute('dataname'))){
            if(!document.getElementsByClassName('inputElement')[i].previousElementSibling.children[0]){
                document.getElementsByClassName('inputElement')[i].previousElementSibling.innerHTML += '<span style="font-size: 90%; color: #7D8B9E;" class="roboto-bold"> (1) </span>'   
            }
        }
        else if(levels2.includes(document.getElementsByClassName('inputElement')[i].getAttribute('dataname'))){
            if(!document.getElementsByClassName('inputElement')[i].previousElementSibling.children[0]){
                document.getElementsByClassName('inputElement')[i].previousElementSibling.innerHTML += '<span style="font-size: 90%; color: #4287CE;" class="roboto-bold"> (2) </span>'   
            }
        }
        else if(levels3.includes(document.getElementsByClassName('inputElement')[i].getAttribute('dataname'))){
            if(!document.getElementsByClassName('inputElement')[i].previousElementSibling.children[0]){
                document.getElementsByClassName('inputElement')[i].previousElementSibling.innerHTML += '<span style="font-size: 90%; color: rgb(1, 42, 63);" class="roboto-bold"> (3) </span>'
            }
        }
    }
}

function setLevel(input){
    console.log(input.parentNode.parentNode.parentNode.children[0])
    console.log(input.getAttribute('level'))
    if(input.getAttribute('level') == 1){
        if(!input.parentNode.parentNode.parentNode.children[0].children[0]){
            console.log(input.parentNode.parentNode.parentNode.children[0].innerHTML)
            input.parentNode.parentNode.parentNode.children[0].innerHTML += '<span style="font-size: 90%; color: #7D8B9E;" class="roboto-bold"> (1) </span>'   
        }
    }
    else if(input.getAttribute('level') == 2){
        if(!input.parentNode.parentNode.parentNode.children[0].children[0]){
            input.parentNode.parentNode.parentNode.children[0].innerHTML += '<span style="font-size: 90%; color: #4287CE;" class="roboto-bold"> (2) </span>'   
        }
    }
    else if(input.getAttribute('level') == 3){
        if(!input.parentNode.parentNode.parentNode.children[0].children[0]){
            input.parentNode.parentNode.parentNode.children[0].innerHTML += '<span style="font-size: 90%; color:rgb(1, 42, 63);" class="roboto-bold"> (3) </span>'   
        }
    }
}

function setLang(){
    
    lang = localStorage.getItem('lang');
    
    /* inner HTML */
    setWordLanginnerHTML('regperson1','regperson1');
    setWordLanginnerHTML('regperson2','regperson2');
    setWordLanginnerHTML('regperson3','regperson3');
    setWordLanginnerHTML('regperson4','regperson4');
    setWordLanginnerHTML('regperson5','regperson5');
    setWordLanginnerHTML('regperson6','regperson6');
    setWordLanginnerHTML('regTitle','regperson4');
    setWordLanginnerHTML('requiredLevel1','requiredLevel1');
    setWordLanginnerHTML('requiredLevel2','requiredLevel2');
    setWordLanginnerHTML('requiredLevel3','requiredLevel3');
    setWordLanginnerHTML('previous-button','goBack');
    setWordLanginnerHTML('later-button','completeThen');
    setWordLanginnerHTML('next-button','continue');
    setWordLanginnerHTML('ts','ts');
    setWordLanginnerHTML('completeLater','completeLater');
    setWordLanginnerHTML('completeLaterAccept','completeThen');
    setWordLanginnerHTML('completeLaterCancel','cancel');
    setWordLanginnerHTML('expired1','expired1');
    setWordLanginnerHTML('expired2','expired2');
    setWordLanginnerHTML('expSessionButton','continue');
    
    getEntry(getParameterByName('sessionid'));

}

function setDynamicLang(){
    Array.from(document.getElementsByClassName('selectLabel')).forEach(select => {
        select.innerHTML = getLangById('select')[lang]
    })
    Array.from(document.getElementsByClassName('search')).forEach(select => {
        select.innerHTML = getLangById('search')[lang]
    })
    Array.from(document.getElementsByClassName('successfulUploadLabel')).forEach(select => {
        select.innerHTML = getLangById('successfulUploadLabel')[lang]
    })
    Array.from(document.getElementsByClassName('previewLabel')).forEach(select => {
        select.innerHTML = getLangById('previewLabel')[lang]
    })
    Array.from(document.getElementsByClassName('goBackLabel')).forEach(select => {
        select.innerHTML = getLangById('goBackLabel')[lang]
    })
    Array.from(document.getElementsByClassName('deleteLabel')).forEach(select => {
        select.innerHTML = getLangById('deleteLabel')[lang]
    })
}