WS_waitscreen = true;
var entrydata;
//Global funciones para el tutorial loadTutorial(); drawTutorial(); file:main.js
function start() {

    document.getElementById("nextStepTut").addEventListener("click", function () {
        loadTutorial(this.getAttribute("nextStep"));
    });
    document.getElementById("endTutorial").addEventListener("click", function () {
        endTutorial();
    });

    // Call Entry
    setLang();

    document.getElementById('example-element-toggle').checked = false;


    getCountries()


    document.getElementById('seeTerms').addEventListener("click", function () {
        //window.open('./img/termandconditions.pdf', '_blank');
        gotoNewPage('register', 'termsandconditions');
    });

    var selector = document.getElementsByName('bank')[0];
    var firstOopcion = document.createElement("option");
    firstOopcion.disabled = true;
    firstOopcion.text = lang == "esp" ? 'Forma de pago' : 'Way to pay'
    firstOopcion.value = ''
    firstOopcion.selected = true
    selector.add(firstOopcion);

    var selector = document.getElementsByName('currency')[0];
    var firstOopcion = document.createElement("option");
    firstOopcion.disabled = true;
    firstOopcion.text = lang == "esp" ? 'Moneda' : 'Currency';
    firstOopcion.value = ''
    firstOopcion.selected = true
    selector.add(firstOopcion);

    document.getElementById('status').value = '';
    document.getElementById('detail1').value = '';
    document.getElementById('detail2').value = '';
    document.getElementById('detail3').value = '';
    document.getElementById('detail4').value = '';

    // Add
    document.getElementById('add').addEventListener("click", function () {
        document.getElementById("modalTit").innerHTML = getLangById("addAccount")[lang];
        var el = document.getElementById('addView')
        //el.style.display = 'block';
        //el.style.display = (el.style.display == 'none') ? 'block' : 'none';
        //document.getElementById('datas').style.display = 'none';
        document.getElementById('addView').style.display = 'block';
        document.getElementById('status').value = '';
        document.getElementById('country').value = '';
        document.getElementById('detail1').value = '';
        document.getElementById('detail2').value = '';
        document.getElementById('detail3').value = '';
        document.getElementById('detail4').value = '';

        document.getElementById("addAccount").setAttribute("accid", 0);

        if (!document.getElementById('example-element-toggle').checked) {
            setTimeout(function () {
                document.getElementById('example-element-toggle').checked = !document.getElementById('example-element-toggle').checked;
            }, 15);
        }
        var camposIn = document.getElementById("example-toggled-element").getElementsByTagName("input");
        for (var i = 0; i < camposIn.length; i++) {
            camposIn[i].removeAttribute("disabled");
        }
        var camposSel = document.getElementById("example-toggled-element").getElementsByTagName("select");
        for (var i = 0; i < camposSel.length; i++) {
            camposSel[i].removeAttribute("disabled");
        }
        document.getElementById("addAccount").style.display = "";

    });

    document.getElementById('levelP').addEventListener("click", function () {

        var el = document.getElementById('addView3')
        //el.style.display = 'block';
        //el.style.display = (el.style.display == 'none') ? 'block' : 'none';
        //document.getElementById('datas').style.display = 'none';

        if (!document.getElementById('example-element-toggle3').checked) {
            document.getElementById('addView3').style.display = 'block';
        }
        //document.getElementById('example-element-toggle3').checked = !document.getElementById('example-element-toggle3').checked;

        setTimeout(function () {
            document.getElementById('example-element-toggle3').checked = !document.getElementById('example-element-toggle3').checked;
            /*if(document.getElementById('example-element-toggle3').checked){
                document.getElementById('addView3').style.display = 'block';
            }else{
                document.getElementById('addView3').style.display = 'none';
            }*/
            setTimeout(function () {
                if (!document.getElementById('example-element-toggle3').checked) {
                    document.getElementById('addView3').style.display = 'none';
                }
            }, 1020);
        }, 15);


    });


    if (screen.width < 700) {
        clonar();
    }

    // twoFAPopup
    document.getElementsByClassName('twoFAPopup')[0].style.display = "none";

    document.getElementById('Active2FA').addEventListener("click", function () {
        document.getElementsByClassName('twoFAPopup')[0].style.display = "table"
    });

    // NotwoFAPopup
    document.getElementById('goback1').addEventListener("click", function () {
        document.getElementsByClassName('twoFAPopup')[0].style.display = "none"

    });

    //twoFAPopup1
    document.getElementById('continueOne').addEventListener("click", function () {
        document.getElementsByClassName('twoFAPopup')[0].style.display = "none"
        document.getElementsByClassName('newPopup')[0].style.display = "table"
        register2FA(1);
    });
    document.getElementById('goback2').addEventListener("click", function () {
        document.getElementsByClassName('twoFAPopup')[0].style.display = "table"
        document.getElementsByClassName('newPopup')[0].style.display = "none"
    });
    //twoFAPopup2
    document.getElementById('continueTwo').addEventListener("click", function () {
        document.getElementsByClassName('newPopup')[0].style.display = "none"
        document.getElementsByClassName('newPopup1')[0].style.display = "table"
    });
    document.getElementById('goback3').addEventListener("click", function () {
        document.getElementsByClassName('newPopup')[0].style.display = "table"
        document.getElementsByClassName('newPopup1')[0].style.display = "none"
    });
    //twoFAPopup3
    document.getElementById('continueThree').addEventListener("click", function () {
        document.getElementsByClassName('newPopup1')[0].style.display = "none"
        document.getElementsByClassName('newPopup2')[0].style.display = "table"
    });
    document.getElementById('goback4').addEventListener("click", function () {
        document.getElementsByClassName('newPopup1')[0].style.display = "table"
        document.getElementsByClassName('newPopup2')[0].style.display = "none"
    });
    //Enviar Codigo de autenticacion
    document.getElementById('sendActive').addEventListener("click", function () {
        if (document.getElementById('codeAuthenticator').value == "" || document.getElementById('codeAuthenticator').value == null) {
            document.getElementById("codeAuthenticator").focus();
            document.getElementById("codeAuthenticator").style.borderColor = "red";

            document.getElementById('errorCode').innerHTML = getLangById("errinvalid2fa")[lang];
            document.getElementById('errorCode').classList.remove("vHidden")
            setTimeout(function () {
                document.getElementById('errorCode').classList.add("vHidden")
            }, 8000);
        } else {
            activate2FA(document.getElementById('codeAuthenticator').value);
        }
    });
    //Cerrar proceso de autenticacion
    document.getElementById('finalActive').addEventListener("click", function () {
        location.reload();
    });

    // DESACTIVAR 2FA
    document.getElementById('Deactive2FA').addEventListener("click", function () {
        document.getElementsByClassName('twoFAPopup3')[0].style.display = "table"
    });

    document.getElementById('goback5').addEventListener("click", function () {
        document.getElementsByClassName('newPopup3')[0].style.display = "none"

    });

    document.getElementById('sendDeactive').addEventListener("click", function () {
        if (document.getElementById('codeAuthenticatorDeactive').value == "" || document.getElementById('codeAuthenticatorDeactive').value == null) {
            document.getElementById("codeAuthenticatorDeactive").focus();
            document.getElementById("codeAuthenticatorDeactive").style.borderColor = "red";

            document.getElementById('errorCodeDeactive').innerHTML = getLangById("errinvalid2fa")[lang];
            document.getElementById('errorCodeDeactive').classList.remove("vHidden")
            setTimeout(function () {
                document.getElementById('errorCodeDeactive').classList.add("vHidden")
            }, 8000);
        } else {
            deactivate2FA(document.getElementById('codeAuthenticatorDeactive').value);
        }
    });
    document.getElementById('finalDeactive').addEventListener("click", function () {
        location.reload();
    });

    // ChangePassword
    document.getElementById('changePassword').addEventListener("click", function () {
        document.getElementsByClassName('changepassword')[0].style.display = "table"
    });

    // NoChangePassword
    document.getElementById('goback').addEventListener("click", function () {
        document.getElementsByClassName('changepassword')[0].style.display = "none"
        document.getElementById('passwordOld').value = ''
        document.getElementById('password').value = ''
        document.getElementById('passwordNew').value = ''

    });

    // ChangePassword
    document.getElementById('change').addEventListener("click", function () {
        changePassword()
    });

    // Remove red errors 
    document.getElementsByTagName('body')[0].addEventListener("click", function () {
        if (document.getElementById('status').value !== '') {
            document.getElementById('status').style.border = "1px solid #D5DCE5";
        }
        if (document.getElementById('detail1').value !== '') {
            document.getElementById('detail1').style.border = "1px solid #D5DCE5";
        }
        if (document.getElementById('currency').value !== '') {
            document.getElementById('currency').style.border = "1px solid #D5DCE5";
        }
        if (document.getElementById('country').value !== '') {
            document.getElementById('country').style.border = "1px solid #D5DCE5";
        }
        if (document.getElementById('bank').value !== '') {
            document.getElementById('bank').style.border = "1px solid #D5DCE5";
        }
        if (document.getElementById('status').value !== '' && document.getElementById('detail1').value !== '' && document.getElementById('currency').value !== '' &&
            document.getElementById('country').value !== '' && document.getElementById('bank').value !== '') {
            document.getElementById('generalerror').innerHTML = '';
        }
        for (var i = 0; i < document.getElementsByClassName('errorspecial').length; i++) {
            document.getElementsByClassName('errorspecial')[i].innerHTML = ''
        }

        if (document.getElementById('passwordOld').value !== '') {
            noError('passwordOld', 'epasswordold')
            document.getElementById('epasswordold').style.bottom = '10px';
        }

        if (document.getElementById('password').value !== '') {
            noError('password', 'epassword')
            document.getElementById('epassword').style.bottom = '10px';
        }

        if (document.getElementById('passwordNew').value !== '' && document.getElementById('epasswordnew').innerHTML != getLangById("passMatch")[lang] &&
            document.getElementById('epasswordnew').innerHTML != getLangById("passReq")[lang]) {
            noError('passwordNew', 'epasswordnew')
            document.getElementById('epasswordnew').style.bottom = '10px';

        }


    });

    // Close
    document.getElementById('close').addEventListener("click", function () {
        document.getElementById('example-element-toggle').checked = !document.getElementById('example-element-toggle').checked;
        setTimeout(function () {
            document.getElementById('datas').style.display = 'block'; document.getElementById('addView').style.display = 'none'
            document.getElementById('status').value = '';
            document.getElementById('country').value = '';
            document.getElementById('bank').value = '';
            document.getElementById('currency').value = '';
            document.getElementById('detail1').value = '';
            document.getElementById('detail2').value = '';
            document.getElementById('detail3').value = '';
            document.getElementById('detail4').value = '';
            document.getElementById('status').style.border = "1px solid #D5DCE5";
            document.getElementById('detail1').style.border = "1px solid #D5DCE5";
            document.getElementById('currency').style.border = "1px solid #D5DCE5";
            document.getElementById('country').style.border = "1px solid #D5DCE5";
            document.getElementById('bank').style.border = "1px solid #D5DCE5";
            document.getElementById('generalerror').innerHTML = '';

        }, 1000);
        var el = document.getElementById('addView')
    });

    accountsList();

    document.getElementById('country').addEventListener("change", function () {
        paymentmethodsListFunction(document.getElementById('country').value);
        removeOptions('currency')
        var selector = document.getElementsByName('currency')[0];
        var firstOopcion = document.createElement("option");
        firstOopcion.disabled = true;
        firstOopcion.text = lang == "esp" ? 'Selecciona' : 'Select'
        firstOopcion.value = ''
        firstOopcion.selected = true
        selector.add(firstOopcion);
    });

    document.getElementById('bank').addEventListener("change", function () {
        addOptionsCurrency(document.getElementById('bank').value)
    });

    document.getElementById('addAccount').addEventListener("click", function () {
        accountsUpdate(this.getAttribute("accid"));
    });

    document.addEventListener('click', function (evt) {
        if (evt.target.className === 'fas fa-trash-alt') {
            accountsDelete(evt.target);
        }
        if (evt.target.id == "checkbox") {
            if (entrydata.level.id >= 1)
                updateActiveAccount(evt.target.parentNode.parentNode.parentNode.parentNode.parentNode.name);
        }
        if (evt.target.name == 'bankP') {
        }
    });

    // Hide or show old password
    document.getElementById('changeOldPass').addEventListener("click", function () {
        show('changeOldPass', 'passwordOld')
    });
    // Hide or show password
    document.getElementById('changePass').addEventListener("click", function () {
        show('changePass', "password")
    });
    // Hide or show new password
    document.getElementById('changeNewPass').addEventListener("click", function () {
        show('changeNewPass', 'passwordNew')
    });

    // Focus
    document.getElementById('passwordOld').addEventListener('keydown', (event) => focusE(event, 'password'));
    document.getElementById('password').addEventListener('keydown', (event) => focusE(event, 'passwordNew'));
    document.getElementById('passwordNew').addEventListener('keydown', (event) => focusE(event, 'change'));



    // entryperson y entrycompany
    document.getElementById('registry').addEventListener("click", function () {
        if (entryperson) {
            goToRegisterPerson(1)
        }
        if (entrycompany) {
            goToRegisterCompany(1)
        }
    });

    // Session Update


    //Mostrar HTML cargado
    esconderHTML(false);

}

function register2FA(type) {
    var req = {
        'sessionid': sessionStorage.getItem('sessionid'),
        'type': type
    }

    callWS('GET', 'login2fa/register', req, response);

    function response(status, rsp) {
        switch (status) {
            case 200:
                var resp = JSON.parse(rsp);
                document.getElementById("qrText").innerHTML = ''
                document.getElementById("qrText").innerHTML = resp.google2fa.secret
                document.getElementById("pwdSaveAuth").value = ''
                document.getElementById("pwdSaveAuth").value = resp.google2fa.secret
                document.getElementById("qrcode").innerHTML = ''
                var qrcode = new QRCode(document.getElementById("qrcode"), {
                    text: resp.google2fa.qr,
                    width: 110,
                    height: 110,
                    colorDark: "#000000",
                    colorLight: "#ffffff",
                    correctLevel: QRCode.CorrectLevel.H
                });
                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                break;
            default:
                break;
        }
    }
}

function deactivate2FA(code) {
    var req = {
        'sessionid': sessionStorage.getItem('sessionid'),
        'secret': code
    }

    callWS('GET', 'login2fa/deactivate', req, response);

    function response(status, rsp) {
        switch (status) {
            case 200:
                var resp = JSON.parse(rsp);
                document.getElementById('boxAlert').classList.add("noShow");
                document.getElementById('titleDeactive').classList.add("noShow");
                document.getElementById('boxDeactive').classList.add("noShow");
                document.getElementById('lastButtonsDeactive').classList.add("noShow");
                document.getElementById('finalButtonsDeactive').classList.remove("noShow");

                document.getElementById('boxDeactiveCorrect').classList.remove("noShow");

                break;
            case 400:
                break;
            case 401:
                expiredSession();

                break;
            case 405:
                document.getElementById('errorCodeDeactive').innerHTML = JSON.parse(rsp).msg
                document.getElementById('errorCodeDeactive').classList.remove("vHidden")
                setTimeout(function () {
                    document.getElementById('errorCodeDeactive').classList.add("vHidden")
                }, 8000);
                break;
            case 500:
                break;
            default:
                break;
        }
    }
}

function activate2FA(code) {
    var req = {
        'sessionid': sessionStorage.getItem('sessionid'),
        'secret': code
    }
    callWS('GET', 'login2fa/activate', req, response);
    function response(status, rsp) {
        switch (status) {
            case 200:
                var resp = JSON.parse(rsp);
                document.getElementById('titleActive').classList.add("noShow");
                document.getElementById('boxActive').classList.add("noShow");
                document.getElementById('lastIconActive').classList.remove("check");
                document.getElementById('lastIconActive').classList.add("check-done");
                document.getElementById('twoFA4Active').classList.remove("poppins-bold");
                document.getElementById('twoFA4Active').classList.add("poppins-medium");
                document.getElementById('lastButtonsActive').classList.add("noShow");
                document.getElementById('finalButtonsActive').classList.remove("noShow");

                document.getElementById('boxActiveCorrect').classList.remove("noShow");
                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 405:
                document.getElementById('errorCode').innerHTML = JSON.parse(rsp).msg
                document.getElementById('errorCode').classList.remove("vHidden")
                setTimeout(function () {
                    document.getElementById('errorCode').classList.add("vHidden")
                }, 8000);
                break;
            case 500:
                break;
            default:
                break;
        }
    }
}
function clonar() {
    var c = document.getElementById("informationUser");
    var clon0 = c.children[0].children[0].cloneNode("informationUser");
    var clon1 = c.children[0].children[1].cloneNode("informationUser");
    var clon2 = c.children[0].children[2].cloneNode("informationUser");
    c.removeChild(c.children[0])
    c.appendChild(clon1)
    c.appendChild(clon0)
    c.appendChild(clon2)

    for (var i = 0; i < 3; i++) {
        document.getElementsByClassName('levelDivs')[0].children[i].style.display = 'none'
    }
    for (var i = 0; i < document.getElementById('informationUser').children.length; i++) {
        document.getElementById('informationUser').children[i].classList.remove("cellForm20");
        document.getElementById('informationUser').children[i].classList.remove("cellForm60");
        document.getElementById('informationUser').children[i].classList.remove("cellForm");
        document.getElementById('informationUser').children[i].classList.add("table100");
    }

    for (var i = 0; i < document.getElementsByClassName('tableButton')[0].children.length; i++) {
        document.getElementsByClassName('tableButton')[0].children[i].style.display = 'table'
        document.getElementsByClassName('tableButton')[0].children[i].style.width = '100%'

    }
}

function goToRegisterPerson(numberStep) {
    switch (numberStep) {
        /*
        case 1:
            gotoPage('register','regPerson',"");
            break;
        case 2:
            gotoPage('register','regPersonRes',"");
            break;
        case 3:
            gotoPage('register','regPersonInf',"");
            break;
        case 4:
            gotoPage('register','regPersonImg',"");
            break;
        case 5:
            gotoPage('register','regPersonTr',"");
            break;
        case 6:
            gotoPage('register','regPersonStatement',"");
        break;
        case 7:
            gotoPage('register','regPersonStatement',"");
        break;
        */
        case 0:
            gotoPage('kyc', 'regC', "");
            break;
        case 1:
            gotoPage('kyc', 'natInitialLvl', "");
            break;
        case 2:
            gotoPage('kyc', 'natBasicLvl', "");
            break;
        case 3:
            gotoPage('kyc', 'natMiddleLvl', "");
            break;
        case 4:
            gotoPage('kyc', 'natAdvancedLvl', "");
            break;
        case 5:
            if (rsp.entry.view == 0) {
                gotoPage('dashboard', 'home', "");
            } else {
                gotoPage('step', 'main', "");
            }
            break;
    }
}

function goToRegisterCompany(numberStep) {
    switch (numberStep) {
        case 0:
            gotoPage('kyc', 'regC', "");
            break;
        case 1:
            gotoPage('kyc', 'jurInitBasic', "");
            break;
        case 2:
            gotoPage('kyc', 'jurInitReg', "");
            break;
        case 3:
            gotoPage('kyc', 'jurInitPrtnrs', "");
            break;
        case 4:
            gotoPage('kyc', 'jurInitEconom', "");
            break;
        case 5:
            gotoPage('kyc', 'jurInitImgs', "");
            break;
        case 6:
            gotoPage('kyc', 'jurMiddleLvl', "");
            break;
        case 7:
            gotoPage('kyc', 'jurAdvancedLvl', "");
            break;
        case 8:
            if (rsp.entry.view == 0) {
                gotoPage('dashboard', 'home', "");
            } else {
                gotoPage('step', 'main', "");
            }
            break;
    }
}



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

    function response(status, rsp) {
        switch (status) {
            case 200:
                var twofa = JSON.parse(rsp).login2fa;
                if (twofa.email == true || twofa.google == true || twofa.phone == true) {
                    document.getElementById('Active2FA').classList.add("noShow");
                    document.getElementById('Deactive2FA').classList.remove("noShow");
                } else {
                    document.getElementById('Active2FA').classList.remove("noShow");
                    document.getElementById('Deactive2FA').classList.add("noShow");
                }

                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 = ""
                }

                if (JSON.parse(rsp).entry.person) {
                    entryperson = JSON.parse(rsp).entry.person
                    if (JSON.parse(rsp).entry.person.firstname.value != null) {
                        document.getElementById('dataName').innerHTML = JSON.parse(rsp).entry.person.firstname.value + ' ' + JSON.parse(rsp).entry.person.firstlastname.value
                    }
                    document.getElementById('modalName').innerHTML = JSON.parse(rsp).entry.person.firstname.value + ' ' + JSON.parse(rsp).entry.person.firstlastname.value
                    document.getElementById('dataEmail').innerHTML = JSON.parse(rsp).entry.usr
                    document.getElementById('dataIdent').innerHTML = JSON.parse(rsp).entry.person.document.dsc.value
                    document.getElementById('modalid').innerHTML = JSON.parse(rsp).entry.person.document.dsc.value
                    document.getElementById('dataCountryE').innerHTML = JSON.parse(rsp).entry.person.document.country.dsc
                    document.getElementById('dataPhone').innerHTML = JSON.parse(rsp).entry.person.phone.value
                    document.getElementById('dataAddress').innerHTML = ''
                    if (JSON.parse(rsp).entry.person.street.value) {
                        document.getElementById('dataAddress').innerHTML = JSON.parse(rsp).entry.person.street.value
                        if (JSON.parse(rsp).entry.person.home.value) {
                            document.getElementById('dataAddress').innerHTML = document.getElementById('dataAddress').innerHTML + ', ' + JSON.parse(rsp).entry.person.home.value
                            if (JSON.parse(rsp).entry.person.city.dsc) {
                                document.getElementById('dataAddress').innerHTML = document.getElementById('dataAddress').innerHTML + ', ' + JSON.parse(rsp).entry.person.city.dsc
                                if (JSON.parse(rsp).entry.person.region.dsc) {
                                    document.getElementById('dataAddress').innerHTML = document.getElementById('dataAddress').innerHTML + ', ' + JSON.parse(rsp).entry.person.region.dsc
                                    if (JSON.parse(rsp).entry.person.postalcode.value) {
                                        document.getElementById('dataAddress').innerHTML = document.getElementById('dataAddress').innerHTML + ', ' + JSON.parse(rsp).entry.person.postalcode.value
                                        if (JSON.parse(rsp).entry.person.country.dsc) {
                                            document.getElementById('dataAddress').innerHTML = document.getElementById('dataAddress').innerHTML + ', ' + JSON.parse(rsp).entry.person.country.dsc
                                        }
                                    }
                                }
                            }
                        }

                    }
                    //if(JSON.parse(rsp).entry.person.step<7){
                    if (!JSON.parse(rsp).entry.declaration) {
                        document.getElementById('registry').innerHTML = getLangById("completeReg")[lang]
                        document.getElementById('seeTerms').style.opacity = '0.5'
                        document.getElementById('seeTerms').style.cursor = 'initial'
                        document.getElementById('seeTerms').disabled = true
                    }
                } else if (JSON.parse(rsp).entry.company) {
                    entrycompany = JSON.parse(rsp).entry.company
                    if (JSON.parse(rsp).entry.company.name.value != null) {
                        document.getElementById('dataName').innerHTML = JSON.parse(rsp).entry.company.name.value
                    }
                    document.getElementById('modalName').innerHTML = JSON.parse(rsp).entry.company.name.value
                    document.getElementById('dataEmail').innerHTML = JSON.parse(rsp).entry.usr
                    document.getElementById('dataIdent').innerHTML = JSON.parse(rsp).entry.company.document.dsc.value
                    document.getElementById('modalid').innerHTML = JSON.parse(rsp).entry.company.document.dsc.value
                    document.getElementById('dataCountryE').innerHTML = JSON.parse(rsp).entry.company.document.country.dsc
                    document.getElementById('dataPhone').innerHTML = JSON.parse(rsp).entry.company.phone.value
                    document.getElementById('dataAddress').innerHTML = ''
                    if (JSON.parse(rsp).entry.company.street.value) {
                        document.getElementById('dataAddress').innerHTML = JSON.parse(rsp).entry.company.street.value
                        if (JSON.parse(rsp).entry.company.home.value) {
                            document.getElementById('dataAddress').innerHTML = document.getElementById('dataAddress').innerHTML + ', ' + JSON.parse(rsp).entry.company.home.value
                            if (JSON.parse(rsp).entry.company.city.dsc) {
                                document.getElementById('dataAddress').innerHTML = document.getElementById('dataAddress').innerHTML + ', ' + JSON.parse(rsp).entry.company.city.dsc
                                if (JSON.parse(rsp).entry.company.region.dsc) {
                                    document.getElementById('dataAddress').innerHTML = document.getElementById('dataAddress').innerHTML + ', ' + JSON.parse(rsp).entry.company.region.dsc
                                    if (JSON.parse(rsp).entry.company.document.postalcode.value) {
                                        document.getElementById('dataAddress').innerHTML = document.getElementById('dataAddress').innerHTML + ', ' + JSON.parse(rsp).entry.company.document.postalcode.value
                                        if (JSON.parse(rsp).entry.company.country.dsc) {
                                            document.getElementById('dataAddress').innerHTML = document.getElementById('dataAddress').innerHTML + ', ' + JSON.parse(rsp).entry.company.country.dsc
                                        }
                                    }
                                }
                            }
                        }

                    }
                    //if(JSON.parse(rsp).entry.company.step<8){
                    if (!JSON.parse(rsp).entry.declaration) {
                        document.getElementById('registry').innerHTML = getLangById("completeReg")[lang]
                        document.getElementById('seeTerms').style.opacity = '0.5'
                        document.getElementById('seeTerms').style.cursor = 'initial'
                        document.getElementById('seeTerms').disabled = true
                    }
                }
                var lvlid = JSON.parse(rsp).entry.level.id;
                if (lvlid > 3) lvlid = 0;
                for (var i = 0; i < lvlid; i++) {
                    document.getElementsByClassName('levelbar')[i].classList.remove("grayLevel");
                    document.getElementsByClassName('levelbar')[i].classList.add("blueLevel");
                }
                if (JSON.parse(rsp).entry.level.id == 4) {
                    document.getElementsByClassName('levelbar')[0].style.backgroundImage = 'linear-gradient(to right, #478ACF 0%, #478ACF 50%, #D5DCE5 50%, #D5DCE5 100%)';
                }
                document.getElementById('levelP').innerHTML = JSON.parse(rsp).entry.level.name
                arrayLevel = JSON.parse(rsp).entry.level.dsc.split('\n')

                document.getElementById('levelP1').innerHTML = arrayLevel.length > 0 ? arrayLevel[0] : ''
                document.getElementById('levelP2').innerHTML = arrayLevel.length > 1 ? arrayLevel[1] : ''
                entrydata = (JSON.parse(rsp).entry)
                view = JSON.parse(rsp).entry.view
                putName(entrydata);
                //Bloquear cuentasda
                if (entrydata.level.id <= 0) {
                    var ckecks = document.getElementById("datas").querySelectorAll('[type="checkbox"]');
                    for (var x = 0; x < ckecks.length; x++) {
                        ckecks[x].setAttribute("disabled", "");
                    }
                }

                levelsList()
                setTimeout(function () {
                    if (getCookie('withtut') == 'with2')
                        loadTutorial('with3');
                }, 2000);
                break;
            case 204:
                break;
            case 400:
                // Parametros incorrectos
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                // Error
                break;
            default:
                break;
        }
    }
}

function levelsList() {
    callWS("GET", "levels/list", { 'sessionid': sessionStorage.getItem('sessionid') }, response);
    function response(status, rsp) {
        switch (status) {
            case 200:
                loadLevelsList(JSON.parse(rsp))
                notificationsList()
                break;
            case 401:
                expiredSession();
                break;
            default:
                break;
        }
    }
}


function show(a, password) {
    var icon = document.getElementById(a);
    var passwordInput = document.getElementById(password);
    if (passwordInput.getAttribute('type') == "password") {
        icon.removeAttribute("class");
        icon.setAttribute("class", "fas fa-eye");
        passwordInput.removeAttribute("type");
        passwordInput.setAttribute("type", "text");
    } else {
        passwordInput.removeAttribute("type");
        passwordInput.setAttribute('type', "password");
        icon.removeAttribute("class");
        icon.setAttribute("class", "fas fa-eye-slash");
    }
}

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 listDraw(rsp, changeName) {
    var tbl;
    var node;
    if (changeName === 'data') {
        tbl = document.getElementsByClassName("card2")[0];
        var node = tbl.children[3].children[0].cloneNode(true);
        tbl.children[3].innerHTML = "";
    }
    var tmp = null; tmp = node.cloneNode(true);
    //tbl.children[2].innerHTML = "";
    if (changeName === 'data') {
        //tbl.removeChild(document.getElementById('tableMarks'))   
    }
    if (!(rsp.length > 0)) {
        var ele = null;
        ele = tmp.cloneNode(true);
        ele.style.display = "none";
        tbl.children[3].appendChild(ele);
    } else {
        for (var i = 0; i < rsp.length; i++) {
            var ele = null;
            ele = tmp.cloneNode(true);
            ele.style.display = "table";
            if (rsp[i].name !== "") {
                if (changeName === 'data') {
                    ele.name = i
                    ele.setAttribute("id", "iddata" + i);
                    ele.classList.add("datas");
                    if (rsp[i].status == 'green') {
                        ele.children[0].children[0].innerHTML = '<i class="fas fa-check-circle" style="font-size: 55%; top: -4px; position: relative; color: #85BB4F"></i>'
                    }
                    else if (rsp[i].status == 'red') {
                        ele.children[0].children[0].innerHTML = '<i class="fas fa-times-circle" style="font-size: 55%; top: -4px; position: relative; color: #C04F5D"></i>'
                    }
                    else if (rsp[i].status == 'yellow') {
                        ele.children[0].children[0].innerHTML = '<i class="fas fa-pause-circle" style="font-size: 55%; top: -4px; position: relative; color: #f2c542"></i>'
                    }

                    ele.children[0].children[1].innerHTML = '<i class="fas fa-qrcode" style="font-size: 55%; top: -4px; position: relative;"></i>'

                    ele.children[0].children[2].children[0].textContent = rsp[i].currency;
                    ele.children[0].children[3].children[0].textContent = rsp[i].bank;
                    ele.children[0].children[6].children[0].setAttribute("accid", rsp[i].id);
                    ele.children[0].children[6].children[0].setAttribute("valid", rsp[i].valid);
                    ele.children[0].children[6].children[0].setAttribute("countryid", rsp[i].countryid);
                    ele.children[0].children[6].children[0].addEventListener("click", function () {
                        document.getElementById('add').dispatchEvent(new Event("click"));
                        document.getElementById("modalTit").innerHTML = "Editar Cuenta";
                        entryInf(this.getAttribute("accid"), this.getAttribute("countryid"));

                    });
                    ele.children[0].children[4].children[0].textContent = rsp[i].number;
                    if (rsp[i].toggle == "true") {
                        ele.children[0].children[5].children[0].children[0].children[0].checked = true;
                    } else {
                        ele.children[0].children[5].children[0].children[0].children[0].checked = false;
                    }

                    if (i % 2 != 0) {
                        ele.children[0].style.backgroundColor = 'rgba(245, 246, 248, 0.800000011920929)'
                    }
                    tbl.children[3].appendChild(ele);
                }

            }

        }
    }
    document.getElementsByClassName('pageCnt')[0].style.display = "table";

}

function drawNotifications(rsp) {
    var tbl;
    var node;
    tbl = document.getElementsByClassName("card2")[1];
    node = tbl.children[2].children[0].children[0].cloneNode(true);
    tbl.children[2].children[0].innerHTML = "";
    var tmp = null; tmp = node.cloneNode(true);
    if (!(rsp.length > 0)) {
        var ele = null;
        ele = tmp.cloneNode(true);
        ele.style.display = "none";
        tbl.appendChild(ele);
    } else {
        for (var i = 0; i < rsp.length; i++) {
            var ele = null;
            ele = tmp.cloneNode(true);
            ele.style.display = "table"
            ele.name = i
            ele.setAttribute("id", "iddataNot" + i);
            ele.setAttribute("idNotification", rsp[i].id);
            ele.setAttribute("smsStatus", rsp[i].sms);
            ele.setAttribute("emailStatus", rsp[i].email);
            ele.classList.add("datasNot");
            ele.children[0].children[0].innerHTML = rsp[i].dsc
            if (rsp[i].email == "1") {
                ele.children[1].children[0].children[0].children[0].checked = true;
            } else {
                ele.children[1].children[0].children[0].children[0].checked = false;
            }
            if (rsp[i].sms == "1") {
                ele.children[2].children[0].children[0].children[0].checked = true;
            } else {
                ele.children[2].children[0].children[0].children[0].checked = false;
            }
            if (i % 2 != 0) {
                ele.style.backgroundColor = 'rgba(245, 246, 248, 0.800000011920929)'
            }

            ele.children[1].children[0].children[0].children[0].addEventListener("click", function () {
                changeNotif('email', this.parentNode.parentNode.parentNode.parentNode.getAttribute('idnotification'),
                    this.parentNode.parentNode.parentNode.parentNode.getAttribute('smsStatus'),
                    this.parentNode.parentNode.parentNode.parentNode.getAttribute('emailStatus'));
            });
            ele.children[2].children[0].children[0].children[0].addEventListener("click", function () {
                changeNotif('sms', this.parentNode.parentNode.parentNode.parentNode.getAttribute('idnotification'),
                    this.parentNode.parentNode.parentNode.parentNode.getAttribute('smsStatus'),
                    this.parentNode.parentNode.parentNode.parentNode.getAttribute('emailStatus'));
            });
            tbl.children[2].children[0].appendChild(ele);


        }
    }
}

function changeNotif(type, id, statusSms, statusEmail) {
    var req = {
        "sessionid": sessionStorage.getItem('sessionid'),
        "categoryid": id,
        "email": statusEmail,
        "sms": statusSms
    }

    switch (type) {
        case 'sms':
            req.sms = statusSms == 0 ? 1 : 0
            break;
        case 'email':
            req.email = statusEmail == 0 ? 1 : 0
            break;
        default:
            break;
    }
    notificationsUpdate(req)
}

function updateNotificationsConfig(req) {

}

var accountSel = "";
function entryInf(id, countryid) {
    var req = {
        'sessionid': sessionStorage.getItem('sessionid'),
        'id': id
    }

    callWS('GET', 'accounts/entry', req, response);

    function response(status, rsp) {
        switch (status) {
            case 200:
                accountSel = "";
                document.getElementById("country").value = countryid;
                var resp = JSON.parse(rsp);
                document.getElementById("status").value = resp.entry.status;
                accountSel = resp.entry;
                paymentmethodsListFunction(countryid, resp.entry.paymentmethod.id);
                document.getElementById("addAccount").setAttribute("accid", resp.entry.id);
                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                break;
            default:
                break;
        }
    }
}

var varAccountsList;
// accounts/list
function accountsList() {

    var sessionid = sessionStorage.getItem('sessionid');
    var offset = 0;
    var numofrec;

    var req = {
        'sessionid': sessionid,
        'offset': offset,
        'paym': 0,
    }

    callWS('GET', 'accounts/list', req, response);

    function response(status, rsp) {
        switch (status) {
            case 200:
                varAccountsList = JSON.parse(rsp);
                chargeData2(JSON.parse(rsp))
                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                break;
            default:
                break;
        }
    }
}

// accounts/update
function accountsUpdate(id) {
    var sessionid = sessionStorage.getItem('sessionid');
    var id = id;
    var paymentmethodid = document.getElementById('bank').value;
    var currencyid = document.getElementById('currency').value;
    var details1 = document.getElementById('detail1');
    var details2 = document.getElementById('detail2');
    var details3 = document.getElementById('detail3');
    var details4 = document.getElementById('detail4');
    var status = document.getElementById('status').value
    var country = document.getElementById('country').value

    var req = {
        'sessionid': sessionid,
        'id': id,
        'paymentmethodid': parseInt(paymentmethodid),
        'currencyid': parseInt(currencyid),
        'details1': capitalize(details1.value),
        'details2': capitalize(details2.value),
        'details3': capitalize(details3.value),
        'details4': capitalize(details4.value),
        'status': parseInt(status)
    }
    var detailsfield = [];
    for (var i = 0; i < 4; i++) {
        document.getElementById('detail' + (i + 1)).style.border = "";
        if (document.getElementById('detail' + (i + 1)).getAttribute("disabled") == null && req['details' + (i + 1)] == "") {
            detailsfield.push(('detail' + (i + 1)));
        }
    }
    document.getElementById('bank').style.border = "";
    document.getElementById('currency').style.border = "";
    document.getElementById('status').style.border = "";
    document.getElementById('country').style.border = "";
    if (paymentmethodid == '' || currencyid == '' || status == '' || country == '' || detailsfield.length > 0) {

        if (paymentmethodid == '') {
            document.getElementById('bank').style.border = "2px solid #D0021B";
            document.getElementById('generalerror').innerHTML = getLangById("selectOblg")[lang];
        }
        if (currencyid == '') {
            document.getElementById('currency').style.border = "2px solid #D0021B";
            document.getElementById('generalerror').innerHTML = getLangById("selectOblg")[lang];
        }
        if (status == '') {
            document.getElementById('status').style.border = "2px solid #D0021B";
            document.getElementById('generalerror').innerHTML = getLangById("selectOblg")[lang];
        }
        if (country == '') {
            document.getElementById('country').style.border = "2px solid #D0021B";
            document.getElementById('generalerror').innerHTML = getLangById("selectOblg")[lang];
        }
        if (detailsfield.length > 0) {
            for (var i = 0; i < detailsfield.length; i++) {
                document.getElementById(detailsfield[i]).style.border = "2px solid #D0021B";
                document.getElementById('generalerror').innerHTML = getLangById("selectOblg")[lang];
            }
        }

    } else {

        callWS('POST', 'accounts/update', req, response);

        function response(status, rsp) {
            switch (status) {
                case 200:
                    //window.location.reload()
                    accountsList();
                    document.getElementById('example-element-toggle').checked = !document.getElementById('example-element-toggle').checked;
                    setTimeout(function () {
                        document.getElementById('datas').style.display = 'block'; document.getElementById('addView').style.display = 'none'
                    }, 1000);
                    break;
                case 304:
                    accountsList();
                    document.getElementById('example-element-toggle').checked = !document.getElementById('example-element-toggle').checked;
                    setTimeout(function () {
                        document.getElementById('datas').style.display = 'block'; document.getElementById('addView').style.display = 'none'
                    }, 1000);
                    break;
                case 400:
                    break;
                case 401:
                    expiredSession();
                    break;
                case 403:
                    document.getElementById('generalerror').innerHTML = getLangById("conditionLevel1")[lang];
                    break;
                case 500:
                    document.getElementById('generalerror').innerHTML = getLangById("existAcc")[lang];
                    break;
                default:
                    break;
            }
        }

    }
}

var paymentmethodsList;
// paymentmethods/list
function paymentmethodsListFunction(countryid, sel = "") {

    var sessionid = sessionStorage.getItem('sessionid');
    var countryid = countryid;

    var req = {
        'sessionid': sessionid,
        'countryid': countryid // Cambiar
    }
    callWS('GET', 'paymentmethods/list', req, response);

    function response(status, rsp) {
        switch (status) {
            case 200:
                this.paymentmethodsList = JSON.parse(rsp)
                removeOptions('bank')
                addOptionsBanks('bank', JSON.parse(rsp), sel);
                if (sel !== "") {
                    for (var i = 0; i < paymentmethodsList.records.length; i++) {
                        if (sel == paymentmethodsList.records[i].id) {
                            var defcurr = accountSel.currency.id;
                            addEntryCurrency(paymentmethodsList.records[i], defcurr);
                        }
                    }
                }
                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                break;
            default:
                break;
        }
    }
}

function notificationsList() {

    req = {
        'sessionid': sessionStorage.getItem('sessionid')
    }

    callWS('GET', 'notifications/list', req, response);

    function response(status, rsp) {
        switch (status) {
            case 200:
                drawNotifications(JSON.parse(rsp).records)
                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                break;
            default:
                break;
        }
    }
}

function notificationsUpdate(req) {

    callWS('GET', 'notifications/update', req, response);

    function response(status, rsp) {
        switch (status) {
            case 200:
                notificationsList()
                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                break;
            default:
                break;
        }
    }
}


var dataaccountsEntry;
// accounts/entry
function accountsEntry(id) {

    var req = {
        'sessionid': sessionStorage.getItem('sessionid'),
        'id': id
    }

    callWS('GET', 'accounts/entry', req, response);

    function response(status, rsp) {
        switch (status) {
            case 200:
                var paymentmethodid = JSON.parse(rsp).entry.paymentmethod.id;
                var currencyid = JSON.parse(rsp).entry.currency.id;
                var details1 = JSON.parse(rsp).entry.details1;
                var details2 = JSON.parse(rsp).entry.details2;
                var details3 = JSON.parse(rsp).entry.details3;
                var details4 = JSON.parse(rsp).entry.details4;
                var status;
                if (JSON.parse(rsp).entry.status === 1) status = 0;
                if (JSON.parse(rsp).entry.status === 0) status = 1;

                var req = {
                    'sessionid': sessionStorage.getItem('sessionid'),
                    'id': id,
                    'paymentmethodid': parseInt(paymentmethodid),
                    'currencyid': parseInt(currencyid),
                    'details1': nullTxt(details1.value),
                    'details2': nullTxt(details2.value),
                    'details3': nullTxt(details3.value),
                    'details4': nullTxt(details4.value),
                    'status': parseInt(status)
                }

                callWS('POST', 'accounts/update', req, response);

                function response(status, rsp) {
                    switch (status) {
                        case 200:
                            //window.location.reload()
                            accountsList();
                            break;
                        case 400:
                            break;
                        case 403:
                            document.getElementById('generalerror').innerHTML = getLangById("conditionLevel1")[lang];
                            accountsList();
                            break;
                        case 401:
                            expiredSession();
                            break;
                        case 500:
                            break;
                        default:
                            break;
                    }
                }
                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                break;
            default:
                break;
        }
    }
}

function nullTxt(val) {
    if (val == null || val == "null") return "";
    else return val;
}

// accounts/portfolio

// accounts/delete
function accountsDelete(element) {
    var id = varAccountsList.records[element.parentNode.parentNode.parentNode.name].id

    var req = {
        'sessionid': sessionStorage.getItem('sessionid'),
        'id': id
    }

    callWS('GET', 'accounts/entry', req, response);

    function response(status, rsp) {
        switch (status) {
            case 200:
                if (JSON.parse(rsp).entry.deleteable == true) {
                    callWS('GET', 'accounts/delete', req, response);

                    function response(status, rsp) {
                        switch (status) {
                            case 200:
                                accountsList();
                                document.getElementById('example-element-toggle').checked = !document.getElementById('example-element-toggle').checked;
                                setTimeout(function () {
                                    document.getElementById('datas').style.display = 'block'; document.getElementById('addView').style.display = 'none'
                                }, 1000);
                                break;
                            case 304:
                                element.parentNode.parentNode.parentNode.children[1].innerHTML = getLangById("noDelAcc")[lang];
                                break;
                            case 400:
                                break;
                            case 401:
                                expiredSession();
                                break;
                            case 500:
                                break;
                            default:
                                break;
                        }
                    }
                } else {
                    element.parentNode.parentNode.parentNode.children[1].innerHTML = getLangById("noDelActAcc")[lang];
                }



                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                break;
            default:
                break;
        }
    }
}

function chargeData2(chargeData) {

    var data = []

    var status = new Array(chargeData.numofrecords);
    var qr = new Array(chargeData.numofrecords);
    var currency = new Array(chargeData.numofrecords);
    var bank = new Array(chargeData.numofrecords);
    var number = new Array(chargeData.numofrecords);
    var toggle = new Array(chargeData.numofrecords);
    var trash = new Array(chargeData.numofrecords);
    var id = new Array(chargeData.numofrecords);
    var countryid = new Array(chargeData.numofrecords);
    for (var i = 0; i < chargeData.numofrecords; i++) {

        if (chargeData.records[i].valid.id == 1) {
            status[i] = 'green'
        }
        else if (chargeData.records[i].valid.id == -1) {
            status[i] = 'red'
        }
        else if (chargeData.records[i].valid.id == 0) {
            status[i] = 'yellow'
        }

        qr[i] = 'qr'
        currency[i] = chargeData.records[i].currency.symbol;
        bank[i] = chargeData.records[i].paymentmethod.dsc;
        number[i] = chargeData.records[i].details1;
        id[i] = chargeData.records[i].id;
        countryid[i] = chargeData.records[i].country.id;
        if (chargeData.records[i].status === 1) {
            toggle[i] = 'true'
        } else {
            toggle[i] = 'false'
        }

        trash[i] = 'trash'

        data.push({
            'status': status[i],
            'valid': chargeData.records[i].valid.id,
            'qr': 'qr',
            'currency': currency[i],
            'bank': bank[i],
            'number': number[i],
            'toggle': toggle[i],
            'trash': 'trash',
            'id': id[i],
            'countryid': countryid[i]
        })
    }
    listDraw(data, 'data')
}

function getCountries() {
    var req = {
        "sessionid": sessionStorage.getItem('sessionid'),
        "paymentmethods": 1
    }

    callWS("GET", "demographics/countries", req, response);

    function response(status, rsp) {
        switch (status) {
            case 200:
                countries = JSON.parse(rsp);
                addOptions("country", countries)
                break;
            case 204:
                break;
            case 400:
                // Parametros incorrectos
                break;
            case 401:
                expiredSession();
                break;
            case 500:
                // Error
                break;
            default:
                break;
        }
    }
}

function addOptions(domElement, array) {
    var selector = document.getElementsByName(domElement)[0];
    var firstOopcion = document.createElement("option");
    firstOopcion.disabled = true;
    firstOopcion.text = lang == "esp" ? 'País' : 'Country'
    firstOopcion.value = ''
    firstOopcion.selected = true
    selector.add(firstOopcion);
    for (var x = 0; x < array.records.length; x++) {
        var opcion = document.createElement("option");
        opcion.text = array.records[x].dsc;
        opcion.value = array.records[x].id
        selector.add(opcion);
    }
}

function addOptionsBanks(domElement, array, sel) {
    var selector = document.getElementById(domElement);
    var firstOopcion = document.createElement("option");
    firstOopcion.disabled = true;
    firstOopcion.text = lang == "esp" ? 'Forma de pago' : 'Way to pay'
    firstOopcion.value = ''
    if (sel === "" || sel === undefined || sel === null)
        firstOopcion.selected = true
    selector.add(firstOopcion);
    for (var bank = 0; bank < array.records.length; bank++) {
        var opcion = document.createElement("option");
        if (sel !== "" && sel !== undefined && sel !== null)
            if (array.records[bank].id == sel) opcion.selected = true
        opcion.text = array.records[bank].dsc;
        opcion.value = array.records[bank].id
        selector.add(opcion);
    }

}

function removeOptions(selectElement) {
    x = document.getElementById(selectElement)
    var i, L = x.options.length - 1;
    for (i = L; i >= 0; i--) {
        x.remove(i);
    }
}

function addOptionsCurrency(id) {
    removeOptions('currency');
    var selector = document.getElementById('currency');
    var firstOopcion = document.createElement("option");
    firstOopcion.disabled = true;
    firstOopcion.text = lang == "esp" ? 'Moneda' : 'Currency';
    firstOopcion.value = '';
    firstOopcion.selected = true;

    selector.add(firstOopcion);
    var currencies = this.paymentmethodsList.records[(document.getElementById('bank').selectedIndex) - 1].currencies;
    for (var paymentmethod = 0; paymentmethod < currencies.length; paymentmethod++) {
        var opcion = document.createElement("option");
        opcion.text = this.paymentmethodsList.records[(document.getElementById('bank').selectedIndex) - 1].currencies[paymentmethod].dsc
        opcion.value = this.paymentmethodsList.records[(document.getElementById('bank').selectedIndex) - 1].currencies[paymentmethod].id
        selector.add(opcion);
    }

    document.getElementById('detail1').placeholder = this.paymentmethodsList.records[(document.getElementById('bank').selectedIndex) - 1].details1
    document.getElementById('detail2').placeholder = this.paymentmethodsList.records[(document.getElementById('bank').selectedIndex) - 1].details2
    document.getElementById('detail3').placeholder = this.paymentmethodsList.records[(document.getElementById('bank').selectedIndex) - 1].details3
    document.getElementById('detail4').placeholder = this.paymentmethodsList.records[(document.getElementById('bank').selectedIndex) - 1].details4

    if (document.getElementById('detail1').placeholder == '' || document.getElementById('detail1').placeholder == null) {
        document.getElementById('detail1').disabled = true;
    } else {
        document.getElementById('detail1').disabled = false;
        document.getElementById('detail1').placeholder == 'Email' ? document.getElementById('detail1').classList.add('no-cap') : document.getElementById('detail1').classList.remove('no-cap')
    }
    if (document.getElementById('detail2').placeholder == '' || document.getElementById('detail2').placeholder == null) {
        document.getElementById('detail2').disabled = true;
    } else {
        document.getElementById('detail2').disabled = false;
        document.getElementById('detail2').placeholder == 'Email' ? document.getElementById('detail2').classList.add('no-cap') : document.getElementById('detail2').classList.remove('no-cap')
    }
    if (document.getElementById('detail3').placeholder == '' || document.getElementById('detail3').placeholder == null) {
        document.getElementById('detail3').disabled = true;
    } else {
        document.getElementById('detail3').disabled = false;
        document.getElementById('detail3').placeholder == 'Email' ? document.getElementById('detail3').classList.add('no-cap') : document.getElementById('detail3').classList.remove('no-cap')
    }
    if (document.getElementById('detail4').placeholder == '' || document.getElementById('detail4').placeholder == null) {
        document.getElementById('detail4').disabled = true;
    } else {
        document.getElementById('detail4').disabled = false;
        document.getElementById('detail4').placeholder == 'Email' ? document.getElementById('detail4').classList.add('no-cap') : document.getElementById('detail4').classList.remove('no-cap')
    }
}
function addEntryCurrency(rsp, sel) {
    removeOptions('currency');

    var selector = document.getElementById('currency');
    var firstOopcion = document.createElement("option");
    firstOopcion.disabled = true;
    firstOopcion.text = lang == "esp" ? 'Moneda' : "Currency";
    firstOopcion.value = '';
    if (sel === "" || sel === undefined || sel === null)
        firstOopcion.selected = true;

    selector.add(firstOopcion);

    for (var i = 0; i < rsp.currencies.length; i++) {
        var opcion = document.createElement("option");
        opcion.text = rsp.currencies[i].dsc;
        opcion.value = rsp.currencies[i].id;

        if (sel === "" || sel === undefined || sel === null)
            if (sel === rsp.currencies[i].id) {
                opcion.selected = true
            }

        selector.add(opcion);
    }

    var campos = document.getElementById("example-toggled-element").getElementsByTagName("input");
    for (var i = 0; i < campos.length; i++) {
        campos[i].removeAttribute("disabled");
    }
    var camposSel = document.getElementById("example-toggled-element").getElementsByTagName("select");
    for (var i = 0; i < camposSel.length; i++) {
        camposSel[i].removeAttribute("disabled");
    }
    document.getElementById("addAccount").style.display = "";
    document.getElementById('detail1').placeholder = rsp.details1;
    if (rsp.details2 == "") document.getElementById('detail2').disabled = true;
    document.getElementById('detail2').placeholder = rsp.details2;
    if (rsp.details3 == "") document.getElementById('detail3').disabled = true;
    document.getElementById('detail3').placeholder = rsp.details3;
    if (rsp.details4 == "") document.getElementById('detail4').disabled = true;
    document.getElementById('detail4').placeholder = rsp.details4;
    if (accountSel.details1.valid == 1) document.getElementById('detail1').disabled = true;
    document.getElementById('detail1').value = accountSel.details1.value;
    if (accountSel.details2.valid == 1) document.getElementById('detail2').disabled = true;
    document.getElementById('detail2').value = accountSel.details2.value;
    if (accountSel.details3.valid == 1) document.getElementById('detail3').disabled = true;
    document.getElementById('detail3').value = accountSel.details3.value;
    if (accountSel.details4.valid == 1) document.getElementById('detail4').disabled = true;
    document.getElementById('detail4').value = accountSel.details4.value;
    if (accountSel.valid.id == 1) {
        var camposSel = document.getElementById("example-toggled-element").getElementsByTagName("select");
        for (var i = 0; i < camposSel.length; i++) {
            camposSel[i].disabled = true;
        }
        document.getElementById("addAccount").style.display = "none";
    }


}

function updateActiveAccount(id) {
    var sessionid = sessionStorage.getItem('sessionid');
    var id = id;
    accountsEntry(varAccountsList.records[id].id)
}

function changePassword() {
    var oldpass = document.getElementById('passwordOld')
    var pass = document.getElementById('password')
    var newpass = document.getElementById('passwordNew')

    if (oldpass.value == '' || pass.value == '' || newpass.value == '') {
        if (oldpass.value == '') {
            error('passwordOld', 'epasswordold', getLangById("pass1")[lang])
        }
        if (pass.value == '') {
            error('password', 'epassword', getLangById("pass2")[lang])
        }
        if (newpass.value == '') {
            error('passwordNew', 'epasswordnew', getLangById("pass3")[lang])
        }
        return;
    }

    if (pass.value != newpass.value) {
        document.getElementById('epasswordnew').innerHTML = getLangById("passMatch")[lang]
        return;
    }

    if (!isOkPass(pass.value).result) {
        document.getElementById('epasswordnew').innerHTML = getLangById("passReq")[lang]
        return;
    }

    var req = {
        'sessionid': sessionStorage.getItem('sessionid'),
        'pwd': MD5(oldpass.value),
        'newpwd': MD5(pass.value),
    }

    callWS('GET', 'users/update', req, response);

    function response(status, rsp) {
        switch (status) {
            case 200:
                document.getElementById('epasswordnew').innerHTML = getLangById("pass4")[lang];
                setTimeout(function () {
                    document.getElementsByClassName('changepassword')[0].style.display = "none"
                    document.getElementById('passwordOld').value = ''
                    document.getElementById('password').value = ''
                    document.getElementById('passwordNew').value = ''
                }, 3000);
                break;
            case 400:
                document.getElementById('epasswordnew').innerHTML = getLangById("pass5")[lang];
                break;
            case 401:
                expiredSession();
                break;
            case 409:
                document.getElementById('epasswordnew').innerHTML = getLangById("pass6")[lang];
                break;
            case 500:
                document.getElementById('epasswordnew').innerHTML = 'Error.'
                break;
            default:
                document.getElementById('epasswordnew').innerHTML = 'Error.'
                break;
        }
    }

}




function isOkPass(p) {
    var anUpperCase = /[A-Z]/;
    var aLowerCase = /[a-z]/;
    var aNumber = /[0-9]/;
    var aSpecial = /[!|@|#|$|%|^|&|*|(|)|-|_|.|=|+|\/]/;
    var obj = {};
    obj.result = true;

    if (p.length < 8) {
        obj.result = false;
        obj.error = "Not long enough!"
        return obj;
    }

    var numUpper = 0;
    var numLower = 0;
    var numNums = 0;
    var numSpecials = 0;
    for (var i = 0; i < p.length; i++) {
        if (anUpperCase.test(p[i]))
            numUpper++;
        else if (aLowerCase.test(p[i]))
            numLower++;
        else if (aNumber.test(p[i]))
            numNums++;
        else if (aSpecial.test(p[i]))
            numSpecials++;
    }

    if (numUpper < 1 || numLower < 1 || numNums < 1 || numSpecials < 1) {
        obj.result = false;
        obj.error = "Wrong Format!";
        return obj;
    }
    return obj;
}

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 loadLevelsList(list) {
    for (var i = 0; i < list.records.length; i++) {
        level = "textLevel" + i
        arrayLevelName = list.records[i].name
        arrayLeveldsc = list.records[i].dsc.split('\n')
        document.getElementById(level).children[0] = arrayLeveldsc[0] ? arrayLeveldsc[0] : ''
        for (var j = 0; j < arrayLeveldsc.length; j++) {
            itm = document.getElementById(level).children[1];
            cln = itm.cloneNode(true);
            cln.children[0].innerHTML = arrayLeveldsc[j]
            if (arrayLeveldsc[j]) document.getElementById(level).appendChild(cln);
        }
    }

    var idLevel = entrydata.level.id
    document.getElementById('levelP').innerHTML = getLangById("level" + idLevel)[lang]
    /*
    var arrayLeveldsc2 = list.records[idLevel].dsc.split('\n')
    document.getElementById('levelP1').innerHTML = (arrayLeveldsc2.length > 0) ? arrayLeveldsc2[0] : ''
    document.getElementById('levelP2').innerHTML = (arrayLeveldsc2.length > 1) ? arrayLeveldsc2[1] : ''*/
}

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('prefTitle', 'basicData');
    setWordLanginnerHTML('level0CardLabel', 'level0');
    setWordLanginnerHTML('level1CardLabel', 'level1');
    setWordLanginnerHTML('level2CardLabel', 'level2');
    setWordLanginnerHTML('level3CardLabel', 'level3');
    setWordLanginnerHTML('idLabel', 'iden');
    setWordLanginnerHTML('countryLabel', 'countryE');
    setWordLanginnerHTML('adLabel', 'address');
    setWordLanginnerHTML('changePassword', 'changePassword');
    setWordLanginnerHTML('registry', 'registry');
    setWordLanginnerHTML('seeTerms', 'seeTerms');
    setWordLanginnerHTML('dataAcR', 'dataAcR');
    setWordLanginnerHTML('dataAcR2', 'dataAcR2');
    setWordLanginnerHTML('statusLabel21', 'statusLabel21');
    setWordLanginnerHTML('infP', 'infP');
    setWordLanginnerHTML('statusLabel', 'status');
    setWordLanginnerHTML('addLabel', 'add');
    setWordLanginnerHTML('formStatusSel', 'status');
    setWordLanginnerHTML('formStatusSel1', 'active');
    setWordLanginnerHTML('formStatusSel2', 'inactive');
    setWordLanginnerHTML('addAccount', 'ADD');
    setWordLanginnerHTML('ts', 'ts');
    setWordLanginnerHTML('completeLater', 'completeLater');
    setWordLanginnerHTML('completeLaterAccept', 'completeThen');
    setWordLanginnerHTML('completeLaterCancel', 'cancel');
    setWordLanginnerHTML('expired1', 'expired1');
    setWordLanginnerHTML('expired2', 'expired2');
    setWordLanginnerHTML('expSessionButton', 'continue')
    setWordLanginnerHTML('actPassLabel', 'currentPassword');
    setWordLanginnerHTML('newPassLabel', 'newPassword');
    setWordLanginnerHTML('confirmNewPass', 'confirmNewPassword');
    setWordLanginnerHTML('change', 'CHANGE');
    setWordLanginnerHTML('button', 'CANCEL');

    /*PREFERENCIAS 2FA*/
    setWordLanginnerHTML('Active2FA', 'Active2FA');
    setWordLanginnerHTML('Deactive2FA', 'Deactive2FA');
    /*paso a paso activación desactivación titulos*/
    setWordLanginnerHTML('title2fa1', 'title2fa1');
    setWordLanginnerHTML('title2fa2', 'title2fa1');
    setWordLanginnerHTML('title2fa3', 'title2fa1');
    setWordLanginnerHTML('title2fa4', 'title2fa1');

    /*paso a paso activación desactivación subtitulos - se repiten*/
    setWordLanginnerHTML('down2fa1', 'down2fa1');
    setWordLanginnerHTML('down2fa2', 'down2fa1');
    setWordLanginnerHTML('down2fa3', 'down2fa1');
    setWordLanginnerHTML('down2fa4', 'down2fa1');

    setWordLanginnerHTML('qrscan2fa1', 'qrscan2fa1');
    setWordLanginnerHTML('qrscan2fa2', 'qrscan2fa1');
    setWordLanginnerHTML('qrscan2fa3', 'qrscan2fa1');
    setWordLanginnerHTML('qrscan2fa4', 'qrscan2fa1');

    setWordLanginnerHTML('safekey2fa1', 'safekey2fa1');
    setWordLanginnerHTML('safekey2fa2', 'safekey2fa1');
    setWordLanginnerHTML('safekey2fa3', 'safekey2fa1');
    setWordLanginnerHTML('safekey2fa4', 'safekey2fa1');

    setWordLanginnerHTML('safekey2fa1', 'safekey2fa1');
    setWordLanginnerHTML('safekey2fa2', 'safekey2fa1');
    setWordLanginnerHTML('safekey2fa3', 'safekey2fa1');
    setWordLanginnerHTML('safekey2fa4', 'safekey2fa1');

    setWordLanginnerHTML('cfrm2fa1', 'cfrm2fa1');
    setWordLanginnerHTML('cfrm2fa2', 'cfrm2fa1');
    setWordLanginnerHTML('cfrm2fa3', 'cfrm2fa1');
    setWordLanginnerHTML('twoFA4Active', 'cfrm2fa1');
    /*Botones*/
    setWordLanginnerHTML('continueOne', 'continueOne');
    setWordLanginnerHTML('continueTwo', 'continueOne');
    setWordLanginnerHTML('continueThree', 'continueOne');
    setWordLanginnerHTML('sendActive', 'continueOne');
    setWordLanginnerHTML('sendDeactive', 'continueOne');

    setWordLanginnerHTML('goback1', 'goback1');
    setWordLanginnerHTML('goback2', 'goback2');
    setWordLanginnerHTML('goback3', 'goback2');
    setWordLanginnerHTML('goback4', 'goback2');

    setWordLanginnerHTML('goback5', 'goback1');

    setWordLanginnerHTML('finalActive', 'finalActive');
    setWordLanginnerHTML('finalDeactive', 'finalDeactive');

    /*textos largos*/
    setWordLanginnerHTML('text2fa1', 'text2fa1');
    setWordLanginnerHTML('textScan2fa2', 'textScan2fa2');
    setWordLanginnerHTML('textKey2fa3', 'textKey2fa3');
    setWordLanginnerHTML('titleActive', 'titleActive');

    setWordLanginnerHTML('2faVerifyTit', '2faVerifyTit');
    setWordLanginnerHTML('2faVerifyDisTit', '2faVerifyTit');

    setWordLanginnerHTML('2faVerifyInst', '2faVerifyInst');
    setWordLanginnerHTML('2faVerifyDisInst', '2faVerifyInst');

    setWordLanginnerHTML('congr2faTit', 'congr2faTit');
    setWordLanginnerHTML('congr2faSubt', 'congr2faSubt');
    setWordLanginnerHTML('congr2faMsg', 'congr2faMsg');

    setWordLanginnerHTML('deact2faTit', 'congr2faTit');
    setWordLanginnerHTML('deact2faSubt', 'congr2faSubt');
    setWordLanginnerHTML('deact2faMsg', 'deact2faMsg');

    setWordLanginnerHTML('titleDeactive', 'titleDeactive');
    setWordLanginnerHTML('title2faDis', 'title2faDis');
    setWordLanginnerHTML('deact2faMsg', 'deact2faMsg');

    setWordLanginnerHTML('boxMsgDis2fa', 'boxMsgDis2fa');




    setWordLangPlaceHolder('passwordOld', 'currentPassword');
    setWordLangPlaceHolder('password', 'newPassword');
    setWordLangPlaceHolder('passwordNew', 'confirmNewPassword');

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

}










