function start() {

    //Mostrar HTML cargado
    esconderHTML(false);

    // Go to buy 
    document.getElementById('buyCrypto').addEventListener("click", function () {
        entrydata.level.id < '0.5' ? errorLevel() : gotoPage('step', 'buyCrypto', "")
    });



    // Go to sell
    document.getElementById('sellCrypto').addEventListener("click", function () {
        entrydata.level.id < '0.5' ? errorLevel() : gotoPage('step', 'sellCryptoCur', "")
    });

    // Go to withdraw
    document.getElementById('withdrawCrypto').addEventListener("click", function () {
        entrydata.level.id < '0.5' ? errorLevel() : gotoPage('step', 'withdrawFunds', "")
    });

    // Go to deposit
    document.getElementById('depositCrypto').addEventListener("click", function () {
        entrydata.level.id < '0.5' ? errorLevel() : gotoPage('step', 'depositFunds', "")
    });

    // Go to transfer
    document.getElementById('transferCrypto').addEventListener("click", function () {
        entrydata.level.id < '0.5' ? errorLevel() : gotoPage('step', 'transferCrypto', "")
    });

    // Balance
    /*document.getElementById('floatButton').addEventListener("click",function(){
        gotoPage('dashboard','home',{ 'sessionid': sessionStorage.getItem('sessionid') });
        
    })*/

    document.getElementById('tryAgain').addEventListener("click", function () {
        document.getElementsByClassName('failure')[0].style.display = "none"
        document.getElementsByTagName('body')[0].classList.remove('hidden')
        document.getElementById('failureMsg').innerHTML = ''
        document.getElementById('failureTitle').innerHTML = ''
        document.getElementById('tryAgain').innerHTML = ''
    });

    // Step
    document.getElementById('floatButton').addEventListener("click", function () {
        var popup = document.getElementById("floatButton").children[0].children[0];
        if (popup.classList.contains('show')) {
            sessionValidUpdate(0)
            gotoPage('dashboard', 'home', "")
        } else {
            popup.classList.toggle("show");
        }
    })

    document.getElementById('floatClose').addEventListener("click", function (event) {
        var popup = document.getElementById("floatButton").children[0].children[0];
        popup.classList.remove("show")
        event.stopPropagation()
    })


    init()


}

function init() {
    setLang()
}

function getEntry(sessionid) {
    callWS("GET", "users/entry", { 'sessionid': sessionid }, response);

    function response(status, rsp) {
        switch (status) {
            case 200:
                if (JSON.parse(rsp).notifications > 0) {
                    document.getElementById('messageNotification').style.display = "table"
                    document.getElementById('messageNotification').children[0].innerHTML = JSON.parse(rsp).notifications
                } else {
                    document.getElementById('messageNotification').style.display = "none"
                    document.getElementById('messageNotification').children[0].innerHTML = ""
                }
                entrydata = (JSON.parse(rsp).entry);
                if (entrydata.level.id == 4) entrydata.level.id = 0.5; //SI ES NIVEL 0.5 LO AJUSTO MANUAL
                putName(entrydata);
                sessionValidUpdate(1)
                break;
            case 204:
                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                break;
            default:
                break;
        }
    }
}

function putName(entrydata) {
    var name;
    if (entrydata.company) {
        if (entrydata.company.name.value == "" || entrydata.company.name.value == null) {
            name = entrydata.usr
        } else {
            name = entrydata.company.name.value
        }
    }
    else if (entrydata.person) {
        if (entrydata.person.firstname.value == "" || entrydata.person.firstname.value == null) {
            name = entrydata.usr
        } else {
            name = entrydata.person.firstname.value + ' ' + entrydata.person.firstlastname.value
        }
    }
    document.getElementById('headname').innerHTML = name
    document.getElementById('name2').innerHTML = name
}

function logout() {
    var sessionid = sessionStorage.getItem('sessionid')
    var req = {
        'sessionid': sessionid,
    }
    callWS('GET', 'login/logout', req, response);

    function response(status, rsp) {


        switch (status) {
            case 200:
                sessionStorage.removeItem('sessionid')
                gotoPage('login', 'main', '')
                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                break;
            default:
                break;
        }
    }
}


function setLang() {

    addFooter()

    lang = sessionStorage.getItem('lang');

    /* inner HTML */
    setWordLanginnerHTML('home', 'home');
    setWordLanginnerHTML('balance', 'balance');
    setWordLanginnerHTML('preferences', 'preferences');
    setWordLanginnerHTML('homeR', 'home');
    setWordLanginnerHTML('balanceR', 'balance');
    setWordLanginnerHTML('preferencesR', 'preferences');
    setWordLanginnerHTML('langIcon', 'langIcon');


    setWordLanginnerHTML('titleP', 'Operations');
    setWordLanginnerHTML('step1', 'step1');
    setWordLanginnerHTML('step2', 'step2');
    setWordLanginnerHTML('step3', 'step3');
    setWordLanginnerHTML('step4', 'step4');
    setWordLanginnerHTML('step5', 'step5');
    setWordLanginnerHTML('selectLabel', 'selectLabel');
    setWordLanginnerHTML('buyCrypto', 'buyCrypto');
    setWordLanginnerHTML('sellCrypto', 'sellCrypto');
    setWordLanginnerHTML('withdrawCrypto', 'withdrawCrypto');
    setWordLanginnerHTML('depositCrypto', 'depositCrypto');
    setWordLanginnerHTML('transferCrypto', 'transferCrypto');


    setWordLanginnerHTML('buttonAdv', 'ADVANCEDMODE');
    setWordLanginnerHTML('question', 'question');
    setWordLanginnerHTML('expired1', 'expired1');
    setWordLanginnerHTML('expired2', 'expired2');
    setWordLanginnerHTML('expSessionButton', 'continue');
    setWordLanginnerHTML('ts', 'ts');


    document.getElementById('floatClose').addEventListener("click", function (event) {
        var popup = document.getElementById("floatButton").children[0].children[0];
        popup.classList.remove("show")
        event.stopPropagation()
    })

    getEntry(sessionStorage.getItem('sessionid'));

}

function errorLevel() {
    document.getElementById('failureMsg').innerHTML = getLangById('var1')[lang]
    document.getElementById('failureTitle').innerHTML = getLangById('Attention')[lang]
    document.getElementById('tryAgain').innerHTML = getLangById('var2')[lang]
    document.getElementsByClassName('failure')[0].style.display = "table"
}
