curInf = '';
feesInf = '';
var details = ''
selectType = '';
function start() {

    // Go back
    document.getElementById('previous-button').addEventListener("click", function () {
        gotoPage('step', 'withdrawFunds', "")
    });

    // Go step 4
    document.getElementById('next-button').addEventListener("click", function () {
        verifyNextButton()
    });



    // Go back R
    document.getElementById('previous-buttonR').addEventListener("click", function () {
        gotoPage('step', 'withdrawFunds', "")
    });

    // Go step 4 R
    document.getElementById('next-buttonR').addEventListener("click", function () {
        verifyNextButton()
    });

    // Session Update


    // Step
    document.getElementById('floatButton').addEventListener("click", function () {
        var popup = document.getElementById("floatButton").children[0].children[0];
        if (popup.classList.contains('show')) {
            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()
    })

    // withdraw
    document.getElementById('withdrawAmount').addEventListener("keyup", function (e) {
        decimCoin = this.getAttribute("icDecim");
        var noVal = formatCurrency(decimCoin, this.value);
        if (noVal !== "") this.value = noVal;
        document.getElementById('withdrawAmount').setAttribute("dataNumber", parseFloat(document.getElementById('withdrawAmount').value).noExponents());
        document.getElementById('error').style.display = 'none'
    })

    //BOTÓN QUE CARGA EL FORMULARIO CON EL SALDO TOTAL MOVIDO A SET LANG
    /*
    document.getElementById('all').addEventListener("click",function(){
        
        //SE IDENTIFICA EL TIPO DE INTERFAZ SI ES btc/ptr SE MUESTRA UN MODELO SI ES DISTINTO SE MUESTRA FIAT
        if(document.getElementById('next-button').getAttribute('interface') == 4 || document.getElementById('next-button').getAttribute('interface') == 5){
            document.getElementById('withdrawAmount').setAttribute('dataNumber',document.getElementById('avail').getAttribute('number'))
            document.getElementById('withdrawAmount').value = number_format((document.getElementById('avail').getAttribute('number')),decimCoin);
            
            document.getElementById('withdrawChainFee').innerHTML = curInf.currency.symbol + ' ' + (feesInf.entry.blockchainfee.number).toFixed(decimCoin).replace('.', ',');
            //Se muestra el bloque
            document.getElementById("comisionChain").style.display = "";
            
            //Calculo según tipo de comisión
            if(feesInf.entry.withdrawals.nmalfee){
                document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + (feesInf.entry.withdrawals.nmalfee.number).toFixed(decimCoin).replace('.', ',');
                document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + ((feesInf.entry.withdrawals.nmalfee.number).toFixed(decimCoin).replace('.', ','));
                
                var noVal = formatCurrency(decimCoin,this.value);
                if(noVal!=="")this.value = noVal;
                if(document.getElementById('withdrawAmount').value == ""){
                    document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0,decimCoin);
                    document.getElementById('withdrawTotalFinal').style.color="#262624";
                }else{
                    document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('avail').getAttribute('number')),decimCoin);
                    document.getElementById('withdrawTotalFinal').setAttribute('dataNumber',parseFloat(document.getElementById('avail').getAttribute('number')));
                    document.getElementById('withdrawAmount').value = number_format(parseFloat(document.getElementById('avail').getAttribute('number')),decimCoin);
                    document.getElementById('withdrawAmount').setAttribute('dataNumber',parseFloat(document.getElementById('avail').getAttribute('number')));
                     
                    if(((((parseFloat((document.getElementById('withdrawAmount').value).replaceAll(',','.').replaceAll(',','.')) - parseFloat(feesInf.entry.withdrawals.nmalfee.number)).toFixed(decimCoin)).replaceAll('.', ','))).startsWith('-')){
                        document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0,decimCoin);
                        document.getElementById('withdrawTotalFinal').style.color="#D0021B";
                    }else{
                        document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('avail').getAttribute('number'))-parseFloat(feesInf.entry.withdrawals.nmalfee.number),decimCoin);
                        document.getElementById('withdrawTotalFinal').style.color="#262624";
                    }
                    
                }
            }else if(feesInf.entry.withdrawals.pctfee){
                document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + number_format(0,decimCoin);
                document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0,decimCoin);
                
                var noVal = formatCurrency(decimCoin,this.value);
                if(noVal!=="")this.value = noVal;
                document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')) *feesInf.entry.withdrawals.pctfee.number / 100 ,decimCoin);
                document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('avail').getAttribute('number')),decimCoin);
                document.getElementById('withdrawTotalFinal').setAttribute('dataNumber',parseFloat(document.getElementById('avail').getAttribute('number')));
                document.getElementById('withdrawAmount').setAttribute('dataNumber',parseFloat(document.getElementById('avail').getAttribute('number'))*100 / (parseFloat(feesInf.entry.withdrawals.pctfee.number) + 100) );
                document.getElementById('withdrawAmount').value = number_format(parseFloat(document.getElementById('avail').getAttribute('number'))*100 / (parseFloat(feesInf.entry.withdrawals.pctfee.number) + 100),decimCoin);
            }else{
                console.log('N/A');
            }   
        }else{
            //Si NO es interfaz btc y ptr se llena la comisión blockchain
            document.getElementById('withdrawChainFee').innerHTML = "";
            //Se OCULTA el bloque
            document.getElementById("comisionChain").style.display = "none";
            
            
            if(feesInf.entry.withdrawals.nmalfee){
                document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + (feesInf.entry.withdrawals.nmalfee.number).toFixed(decimCoin).replace('.', ',');
                document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + ((feesInf.entry.withdrawals.nmalfee.number).toFixed(decimCoin).replace('.', ','));
                var noVal = formatCurrency(decimCoin,this.value);
                if(noVal!=="")this.value = noVal;
                if(document.getElementById('withdrawAmount').value == ""){
                    document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0,decimCoin);
                    document.getElementById('withdrawTotalFinal').setAttribute('dataNumber',0);
                    document.getElementById('withdrawTotalFinal').style.color="#262624"
                }else{
                    document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('avail').getAttribute('number')),decimCoin)
                    document.getElementById('withdrawTotalFinal').setAttribute('dataNumber',parseFloat(document.getElementById('avail').getAttribute('number')))
                    document.getElementById('withdrawAmount').value = number_format(parseFloat(document.getElementById('avail').getAttribute('number'))-parseFloat(feesInf.entry.withdrawals.nmalfee.number),decimCoin);
                    document.getElementById('withdrawAmount').setAttribute('dataNumber',parseFloat(document.getElementById('avail').getAttribute('number'))-parseFloat(feesInf.entry.withdrawals.nmalfee.number))
                     
                    if(((((parseFloat((document.getElementById('withdrawAmount').value).replace(',','.')) - feesInf.entry.withdrawals.nmalfee.number).toFixed(decimCoin)).replace('.', ','))).startsWith('-')){
                        document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0,decimCoin);
                        document.getElementById('withdrawTotalFinal').style.color="#D0021B"
                    }else{
                        //document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('avail').getAttribute('number')),decimCoin)
                        document.getElementById('withdrawTotalFinal').style.color="#262624"
                    }
                    
                }
            }else if(feesInf.entry.withdrawals.pctfee){
                document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + number_format(0,decimCoin);
                document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0,decimCoin);
                var noVal = formatCurrency(decimCoin,this.value);
                if(noVal!=="")this.value = noVal;
                //document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')) *feesInf.entry.withdrawals.pctfee.number / 100 ,decimCoin)
                document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('avail').getAttribute('number')),decimCoin)
                document.getElementById('withdrawTotalFinal').setAttribute('dataNumber',parseFloat(document.getElementById('avail').getAttribute('number')))
                document.getElementById('withdrawAmount').setAttribute('dataNumber',parseFloat(document.getElementById('avail').getAttribute('number'))*100 / (parseFloat(feesInf.entry.withdrawals.pctfee.number) + 100) )
                document.getElementById('withdrawAmount').value = number_format(parseFloat(document.getElementById('avail').getAttribute('number'))*100 / (parseFloat(feesInf.entry.withdrawals.pctfee.number) + 100),decimCoin);
                document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + number_format(document.getElementById('withdrawTotalFinal').getAttribute('dataNumber') - document.getElementById('withdrawAmount').getAttribute('dataNumber'),decimCoin)
            }else{
                console.log('N/A')
            }   
        }
        document.getElementById('withdrawAmount').disabled = true
        
    });
    document.getElementById('notAll').addEventListener("click",function(){
        document.getElementById('withdrawAmount').disabled = false
    })
    */


    var fieldAmo = ["withdrawAmount"];
    formatAmount(fieldAmo);

    init()

    //Mostrar HTML cargado
    esconderHTML(false);




}

// AAAAAAAAA

function verifyNextButton() {

    // BBBBBBB
    if (parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber'))) {

        if (parseFloat(document.getElementById('withdrawTotalFinal').getAttribute('datanumber')) > parseFloat(document.getElementById('avail').getAttribute('number'))) {
            document.getElementById('error').innerHTML = getLangById('var1')[lang]
            document.getElementById('error').style.display = 'block'
        }
        else if ((document.getElementById('withdrawAmount').value == number_format(0, document.getElementById('withdrawAmount').getAttribute("icDecim")).replace(".", ",")) || document.getElementById('withdrawAmount').value == "") {
            document.getElementById('error').innerHTML = getLangById('var2')[lang]
            document.getElementById('error').style.display = 'block'
        }
        else if (document.getElementById('withdrawTotalFinal').style.color == '#D0021B' || document.getElementById('withdrawTotalFinal').style.color == 'rgb(208, 2, 27)') {
            document.getElementById('error').innerHTML = getLangById('var2')[lang]
            document.getElementById('error').style.display = 'block'
        }
        else if (document.getElementById('withdrawAmount').getAttribute('datanumber') > feesInf.entry.withdrawals.max.number) {
            document.getElementById('error').innerHTML = getLangById('var3')[lang] + feesInf.entry.withdrawals.max.formatted + ' ' + curInf.currency.symbol
            document.getElementById('error').style.display = 'block'
        }
        else if (document.getElementById('withdrawAmount').getAttribute('datanumber') < feesInf.entry.withdrawals.min.number) {
            document.getElementById('error').innerHTML = getLangById('var4')[lang] + feesInf.entry.withdrawals.min.formatted + ' ' + curInf.currency.symbol
            document.getElementById('error').style.display = 'block'
        }
        else {
            document.getElementById('error').style.display = 'none';
            if (document.getElementById('next-button').getAttribute('interface') == 4 || document.getElementById('next-button').getAttribute('interface') == 5
                || document.getElementById('next-button').getAttribute('interface') == 6 || document.getElementById('next-button').getAttribute('interface') == 7) {
                gotoPage('step', 'withdrawFundsAcC', {
                    'cid': getParameterByName('cid'), 'i': document.getElementById('next-button').getAttribute('interface'),
                    'q': number_format(parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')).noExponents(), document.getElementById('withdrawAmount').getAttribute('icdecim')).replaceAll(".", "").replaceAll(",", ".")
                })
            } else {
                if (selectType == 1) {
                    gotoPage('step', 'withdrawFundsAcP', {
                        'cid': getParameterByName('cid'),
                        'q': number_format(parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')).noExponents(), document.getElementById('withdrawAmount').getAttribute('icdecim')).replaceAll(".", "").replaceAll(",", ".")
                    })
                } else {
                    gotoPage('step', 'withdrawFundsAc', {
                        'cid': getParameterByName('cid'),
                        'q': number_format(parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')).noExponents(), document.getElementById('withdrawAmount').getAttribute('icdecim')).replaceAll(".", "").replaceAll(",", "."), 'cin': curInf.currency.interface
                    })
                }

            }

        }
    } else {
        document.getElementById('error').innerHTML = getLangById('var2')[lang]
        document.getElementById('error').style.display = 'block'
    }
}



function sessionUpdate(req) {
    callWS('GET', 'session/update', req, response);
    function response(status, rsp) {

        switch (status) {
            case 200:
                document.getElementsByClassName('expired')[0].style.display = "none";
                init()
                break;
            case 400:
                break;
            case 401:
                gotoPage('login', 'main', '');
                break;
            case 402:
                break;
            case 403:
                break;
            case 500:
                break;
            default:
                break;
        }
    }
}

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)
                putName(entrydata);
                var req = {
                    'sessionid': sessionStorage.getItem('sessionid'),
                    'action': 3, /*1 INtercambio, 2 Deposito, 3 Retiro, 4 Transferencia
                    'currencyid': getParameterByName('cid)*/
                }
                accountsPortfolio(req)
                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 accountsPortfolio(req) {
    callWS('GET', 'accounts/portfolio', req, response);
    function response(status, rsp) {

        switch (status) {
            case 200:
                curInf = null;
                JSON.parse(rsp).records.forEach(currency => {
                    if (currency.currency.id == getParameterByName('cid')) {
                        curInf = currency;
                    }
                });
                req = {
                    'sessionid': sessionStorage.getItem('sessionid'),
                    'currencyid': getParameterByName('cid')
                }
                feesEntry(req, curInf)
                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 402:
                break;
            case 403:
                break;
            case 500:
                break;
            default:
                break;
        }
    }
}

// fees/entry
function feesEntry(req, accPor) {
    callWS('GET', 'fees/entry', req, response);
    function response(status, rsp) {

        switch (status) {
            case 200:
                loadData(accPor, JSON.parse(rsp))
                break;
            case 400:
                break;
            case 401:
                expiredSession();
                break;
            case 402:
                break;
            case 403:
                break;
            case 502:
                document.getElementById('error').innerHTML = getLangById('errconmsg')[lang]
                document.getElementById('error').style.display = 'block'
                break;
            case 500:
                break;
            default:
                break;
        }
        if (status != 200) {
            document.getElementById("next-button").parentElement.parentElement.removeChild(document.getElementById("next-button").parentElement);
        }
    }
}

function loadData(currency, fees) {
    feesInf = fees
    /*
    if(feesInf.entry.blockchainfee!==undefined)
        feesInf.entry.blockchainfee.number = 0.0000546;
    */
    currency = currency
    document.getElementById('withdrawAmount').setAttribute("icDecim", currency.currency.decimals);
    document.getElementById('avail').innerHTML = currency.currency.symbol + ' ' + currency.avaliable.formatted
    document.getElementById('avail').setAttribute("number", parseFloat(currency.avaliable.number));
    document.getElementById('titleTextP').children[0].innerHTML = currency.currency.dsc
    decimCoin = document.getElementById('withdrawAmount').getAttribute("icDecim")
    document.getElementById('next-button').setAttribute('interface', currency.currency.interface)
    if (currency.currency.interface == 4 || currency.currency.interface == 5 || currency.currency.interface == 6 || currency.currency.interface == 7) {
        document.getElementById("feeComents").style.display = "";
        if (fees.entry.withdrawals.nmalfee) {
            //document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + (fees.entry.withdrawals.nmalfee.number).toFixed(decimCoin).replace('.', ',');

            document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + ((fees.entry.withdrawals.nmalfee.number + fees.entry.blockchainfee.number).toFixed(decimCoin).replace('.', ','));
            document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + ((fees.entry.withdrawals.nmalfee.number).toFixed(decimCoin).replace('.', ','));
            document.getElementById('withdrawAmount').addEventListener("keyup", function () {
                var noVal = formatCurrency(decimCoin, this.value);
                if (noVal !== "") this.value = noVal;
                if (document.getElementById('withdrawAmount').value == "") {
                    document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
                    document.getElementById('withdrawTotalFinal').setAttribute("datanumber", 0);
                    document.getElementById('withdrawTotalFinal').style.color = "#262624"
                } else {
                    if (((((parseFloat((document.getElementById('withdrawAmount').value).replace(',', '.')) - fees.entry.withdrawals.nmalfee.number).toFixed(decimCoin)).replace('.', ','))).startsWith('-')) {
                        document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
                        document.getElementById('withdrawTotalFinal').setAttribute("datanumber", 0);
                        document.getElementById('withdrawTotalFinal').style.color = "#D0021B";
                    } else {
                        //Si todo es valido calculo el total 
                        var tot = (parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')) - (fees.entry.withdrawals.nmalfee.number + fees.entry.blockchainfee.number)).toFixed(decimCoin);//Agregada comisión blockchain

                        document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(tot, decimCoin);
                        document.getElementById('withdrawTotalFinal').setAttribute("datanumber", tot);
                        document.getElementById('withdrawTotalFinal').style.color = "#262624";
                    }

                }
            });
        } else if (fees.entry.withdrawals.pctfee) {
            document.getElementById("feepctNo").innerHTML = "(" + number_format(fees.entry.withdrawals.pctfee.number, 2) + "%)";
            document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
            document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
            document.getElementById('withdrawAmount').addEventListener("keyup", function () {
                var noVal = formatCurrency(decimCoin, this.value);
                if (noVal !== "") this.value = noVal;
                document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + ((parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')) * fees.entry.withdrawals.pctfee.number / 100) + fees.entry.blockchainfee.number).toFixed(decimCoin).replace('.', ',')

                var tot = (parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')) * (1 - (fees.entry.withdrawals.pctfee.number / 100)) - (fees.entry.blockchainfee.number)).toFixed(decimCoin);//Agregada comisión blockcahin
                var totFormatted = number_format(tot, decimCoin);

                document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + totFormatted;
                document.getElementById('withdrawTotalFinal').setAttribute('dataNumber', tot);

            });

        } else {
            console.log('N/A');
        }
    } else {
        document.getElementById("feeComents").style.display = "none";

        if (fees.entry.withdrawals.nmalfee) {
            document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + (fees.entry.withdrawals.nmalfee.number).toFixed(decimCoin).replace('.', ',');

            document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + ((fees.entry.withdrawals.nmalfee.number).toFixed(decimCoin).replace('.', ','));
            document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + ((fees.entry.withdrawals.nmalfee.number).toFixed(decimCoin).replace('.', ','));
            document.getElementById('withdrawAmount').addEventListener("keyup", function () {
                var noVal = formatCurrency(decimCoin, this.value);
                if (noVal !== "") this.value = noVal;
                if (document.getElementById('withdrawAmount').value == "") {
                    document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
                    document.getElementById('withdrawTotalFinal').style.color = "#262624"
                } else {
                    if (((((parseFloat(document.getElementById('avail').getAttribute('number')) - fees.entry.withdrawals.nmalfee.number).toFixed(decimCoin)).replaceAll('.', ','))).startsWith('-')) {
                        document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
                        document.getElementById('withdrawTotalFinal').style.color = "#D0021B";
                        document.getElementById('withdrawTotalFinal').setAttribute("datanumber", 0);
                    } else {
                        document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')) + parseFloat(fees.entry.withdrawals.nmalfee.number), decimCoin)
                        //((((parseFloat((document.getElementById('withdrawAmount').value).replace(',','.')) - fees.entry.withdrawals.nmalfee.number).toFixed(decimCoin)).replace('.', ',')));
                        document.getElementById('withdrawTotalFinal').setAttribute("datanumber", parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')) + parseFloat(fees.entry.withdrawals.nmalfee.number));
                        document.getElementById('withdrawTotalFinal').style.color = "#262624";
                    }

                }
            });
        } else if (fees.entry.withdrawals.pctfee) {
            document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
            document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
            document.getElementById('withdrawAmount').addEventListener("keyup", function () {
                var noVal = formatCurrency(decimCoin, this.value);
                if (noVal !== "") this.value = noVal;
                document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')) * fees.entry.withdrawals.pctfee.number / 100, decimCoin)
                document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')) * (1 + fees.entry.withdrawals.pctfee.number / 100), decimCoin)
                document.getElementById('withdrawTotalFinal').setAttribute('dataNumber', parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')) * (1 + fees.entry.withdrawals.pctfee.number / 100))

            });

        } else {
            console.log('N/A')
        }
    }
}

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('titlePage', 'titlePage');
    setWordLanginnerHTML('step1', 'step1');
    setWordLanginnerHTML('step2', 'step2');
    setWordLanginnerHTML('step3', 'step3');
    setWordLanginnerHTML('step4', 'step4');
    setWordLanginnerHTML('step5', 'step5');
    setWordLanginnerHTML('titleTextP', 't1');

    setWordLanginnerHTML('t2', 't2');
    setWordLanginnerHTML('avaLabel', 'AVAILABLE');
    setWordLanginnerHTML('QuantityToW', 'QuantityToW');
    setWordLanginnerHTML('allAm', 'allAm');
    setWordLanginnerHTML('notAllLabel', 'notAll');
    setWordLanginnerHTML('feesLabel', 'FEES');
    setWordLanginnerHTML('feeComents', 'feeComents');

    setWordLanginnerHTML('previous-button', 'RETURN');
    setWordLanginnerHTML('next-button', 'continue');
    setWordLanginnerHTML('previous-buttonR', 'RETURN');
    setWordLanginnerHTML('next-buttonR', 'continue');


    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()
    })

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

        //SE IDENTIFICA EL TIPO DE INTERFAZ SI ES BTC, PTR SE ENTRA EN UN MODELO SI NO ENTRA EN FIAT
        if (document.getElementById('next-button').getAttribute('interface') == 4 || document.getElementById('next-button').getAttribute('interface') == 5 || document.getElementById('next-button').getAttribute('interface') == 6
            || document.getElementById('next-button').getAttribute('interface') == 7) {
            document.getElementById('withdrawAmount').setAttribute('dataNumber', document.getElementById('avail').getAttribute('number'));
            document.getElementById('withdrawAmount').value = number_format((document.getElementById('avail').getAttribute('number')), decimCoin);

            if (feesInf.entry.withdrawals.nmalfee) {
                document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + (feesInf.entry.withdrawals.nmalfee.number + feesInf.entry.blockchainfee.number).toFixed(decimCoin).replace('.', ',');
                document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + ((feesInf.entry.withdrawals.nmalfee.number).toFixed(decimCoin).replace('.', ','));

                var noVal = formatCurrency(decimCoin, this.value);
                if (noVal !== "") this.value = noVal;

                if (document.getElementById('withdrawAmount').value == "") {
                    document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
                    document.getElementById('withdrawTotalFinal').style.color = "#262624";
                } else {
                    document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('avail').getAttribute('number')), decimCoin)
                    document.getElementById('withdrawTotalFinal').setAttribute('dataNumber', parseFloat(document.getElementById('avail').getAttribute('number')))
                    document.getElementById('withdrawAmount').value = number_format(parseFloat(document.getElementById('avail').getAttribute('number')), decimCoin);
                    document.getElementById('withdrawAmount').setAttribute('dataNumber', parseFloat(document.getElementById('avail').getAttribute('number')));

                    if (((((parseFloat((document.getElementById('withdrawAmount').value).replace(',', '.')) - (feesInf.entry.withdrawals.nmalfee.number + feesInf.entry.blockchainfee.number)).toFixed(decimCoin)).replace('.', ','))).startsWith('-')) {
                        document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
                        document.getElementById('withdrawTotalFinal').style.color = "#D0021B";
                    } else {
                        document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('avail').getAttribute('number')) - parseFloat(feesInf.entry.withdrawals.nmalfee.number + feesInf.entry.blockchainfee.number), decimCoin)
                        document.getElementById('withdrawTotalFinal').style.color = "#262624";
                    }

                }
            } else if (feesInf.entry.withdrawals.pctfee) {
                document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
                document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);

                var noVal = formatCurrency(decimCoin, this.value);
                if (noVal !== "") this.value = noVal;
                var feeFinalNumber = parseFloat((parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')) * feesInf.entry.withdrawals.pctfee.number / 100) + feesInf.entry.blockchainfee.number).toFixed(decimCoin);

                document.getElementById('withdrawAmount').setAttribute('dataNumber', parseFloat(document.getElementById('avail').getAttribute('number')) * 1 / 1);
                document.getElementById('withdrawAmount').value = number_format(parseFloat(document.getElementById('avail').getAttribute('number')) * 1 / 1, decimCoin);

                document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + number_format(feeFinalNumber, decimCoin)

                var tot = parseFloat(document.getElementById('avail').getAttribute('number')) - (((parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')) * feesInf.entry.withdrawals.pctfee.number) / 100) + feesInf.entry.blockchainfee.number);
                document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(tot, decimCoin);

                document.getElementById('withdrawTotalFinal').setAttribute('dataNumber', tot);
            } else {
                console.log('N/A');
            }
        } else {
            document.getElementById('withdrawAmount').setAttribute('dataNumber', document.getElementById('avail').getAttribute('number'))
            document.getElementById('withdrawAmount').value = number_format((document.getElementById('avail').getAttribute('number')), decimCoin);

            if (feesInf.entry.withdrawals.nmalfee) {
                document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + (feesInf.entry.withdrawals.nmalfee.number).toFixed(decimCoin).replace('.', ',');
                document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + ((feesInf.entry.withdrawals.nmalfee.number).toFixed(decimCoin).replace('.', ','));
                var noVal = formatCurrency(decimCoin, this.value);
                if (noVal !== "") this.value = noVal;
                if (document.getElementById('withdrawAmount').value == "") {
                    document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
                    document.getElementById('withdrawTotalFinal').setAttribute('dataNumber', 0);
                    document.getElementById('withdrawTotalFinal').style.color = "#262624"
                } else {
                    document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('avail').getAttribute('number')), decimCoin)
                    document.getElementById('withdrawTotalFinal').setAttribute('dataNumber', parseFloat(document.getElementById('avail').getAttribute('number')))
                    document.getElementById('withdrawAmount').value = number_format(parseFloat(document.getElementById('avail').getAttribute('number')) - parseFloat(feesInf.entry.withdrawals.nmalfee.number), decimCoin);
                    document.getElementById('withdrawAmount').setAttribute('dataNumber', parseFloat(document.getElementById('avail').getAttribute('number')) - parseFloat(feesInf.entry.withdrawals.nmalfee.number))

                    if (((((parseFloat((document.getElementById('withdrawAmount').value).replaceAll('.', '').replaceAll(',', '.')) - feesInf.entry.withdrawals.nmalfee.number).toFixed(decimCoin)).replaceAll('.', ','))).startsWith('-')) {
                        document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
                        document.getElementById('withdrawTotalFinal').style.color = "#D0021B"
                    } else {
                        //document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('avail').getAttribute('number')),decimCoin)
                        document.getElementById('withdrawTotalFinal').style.color = "#262624"
                    }

                }
            } else if (feesInf.entry.withdrawals.pctfee) {
                document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
                document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(0, decimCoin);
                var noVal = formatCurrency(decimCoin, this.value);
                if (noVal !== "") this.value = noVal;
                //document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('withdrawAmount').getAttribute('datanumber')) *feesInf.entry.withdrawals.pctfee.number / 100 ,decimCoin)
                document.getElementById('withdrawTotalFinal').innerHTML = curInf.currency.symbol + ' ' + number_format(parseFloat(document.getElementById('avail').getAttribute('number')), decimCoin)
                document.getElementById('withdrawTotalFinal').setAttribute('dataNumber', parseFloat(document.getElementById('avail').getAttribute('number')))
                document.getElementById('withdrawAmount').setAttribute('dataNumber', parseFloat(document.getElementById('avail').getAttribute('number')) * 100 / (parseFloat(feesInf.entry.withdrawals.pctfee.number) + 100))
                document.getElementById('withdrawAmount').value = number_format(parseFloat(document.getElementById('avail').getAttribute('number')) * 100 / (parseFloat(feesInf.entry.withdrawals.pctfee.number) + 100), decimCoin);
                document.getElementById('withdrawBTCFee').innerHTML = curInf.currency.symbol + ' ' + number_format(document.getElementById('withdrawTotalFinal').getAttribute('dataNumber') - document.getElementById('withdrawAmount').getAttribute('dataNumber'), decimCoin)
            } else {
                console.log('N/A')
            }
        }
        document.getElementById('withdrawAmount').disabled = true


    })
    document.getElementById('notAll').addEventListener("click", function () {
        document.getElementById('withdrawAmount').disabled = false
    })

    document.getElementById('tabDepFiat').style.display = "none"

    /**if(getParameterByName('cid')!=1){
        document.getElementById('tabDepFiat').style.display = "none"
    }else{
        document.getElementById('p2c').style.display = "block"
        // Tab 1 Retiro Fiat
        document.getElementById('reportDTFiat').addEventListener("click", function(){
            selectType = 0
            openTabFiat('reportDTFiat','depTr')
        });
        
        // Tab 2 Retiro Fiat
        document.getElementById('p2cfiat').addEventListener("click", function(e){
            //e.preventDefault();
            //return false;
            selectType = 1
            openTabFiat('p2cfiat','p2c');
        });
        
        document.getElementById('reportDTFiat').dispatchEvent(new Event("click"));
        
        /*setWordLanginnerHTML('reportDTFiat','ReportDeposit');
        setWordLanginnerHTML('p2cfiat','UsingP2C');
        setWordLanginnerHTML('bankDest2Fiat','DestinationBank');
        setWordLanginnerHTML('Am2Fiat','portfolio2');
        setWordLanginnerHTML('id2Fiat','IdentificationCard');
        setWordLanginnerHTML('phone2Fiat','CellPhone');
        setWordLanginnerHTML('depFiatDep','depLabel');
        setWordLanginnerHTML('fiatFees1DepPM','FEES');
        setWordLanginnerHTML('netTotalDepFiat1PM','NETTOTAL');
        setWordLanginnerHTML('PMTextInp','var49'); //
        
    }**/


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

}



function openTabFiat(name, nametab) {
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabDepFiatContent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }

    tablinks = document.getElementsByClassName("tablinksDepFiat");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }

    document.getElementById(nametab).style.display = "block";
    document.getElementById(name).className += " active";

} 
