var tempo
function popup(url) {
	window.open(url);
}

function lyrVisual(id, estado) {
    try {
        //if (navigator.appName == "Netscape") {
        //    opcao = (estado) ? "show" : "hide";
        //    controle(id, '', opcao);
        //}
        //else {
            opcao = (estado) ? "visible" : "hidden";
            document.getElementById('Layer1').style.visibility = "hidden";
            //document.getElementById(id).style.pixelTop = document.body.scrollTop;
            document.getElementById(id).style.visibility = opcao;
            //oldId = id.toString()
        //}
    }
    catch (e)
	{ }
}

function Verificar() {
	
	if(window.event){
	    var ctrl = window.event.ctrlKey;
	    var tecla = window.event.keyCode;
	    if (ctrl && tecla == 67) { event.keyCode = 0; event.returnValue = false; }
	    if (ctrl && tecla == 86) { event.keyCode = 0; event.returnValue = false; }
	}
}

function checa_agencia(campo) {
    switch (campo) {
        case "AGN": 
            {
                if (document.FormIB2001.AGN.value.length == 4)
                { document.FormIB2001.CTA.focus(); }
                break;
            }
        case "CTA": 
            {
                if (document.FormIB2001.CTA.value.length == 7)
                { document.FormIB2001.DIGCTA.focus(); }
                break;
            }
    }
}

function Apenas_Numeros(e, campo) {
    var msg = "Favor digitar somente caracteres numéricos";
    var monta = "";
    var NS = (navigator.appName == "Netscape")
    var Digit = parseInt(eval(((NS) ? "e.which" : "e.keyCode")))

    if (!(Digit > 47 && Digit < 58 || Digit == 8 || Digit == 0 || Digit == 13)) {
        alert(msg);
        monta = "document.FormIB2001." + campo + ".focus();";
        eval(monta);
        e.keyCode.returnValue = false;
        return false;
    }
    else {
        if (parseInt(Digit) == 13) {
            if (VerificaLogin() == true)
            { IB2000Open(window.document.FormIB2001); e.keyCode.returnValue = false; return false; }
            else
            { ValidaLogin(campo); e.keyCode.returnValue = false; return false; }
        }
    }
}

function VerificaLogin() {
    var valor = true;
    var Agencia = parseInt(document.FormIB2001.AGN.value);
    var Conta = parseInt(document.FormIB2001.CTA.value);
    var Digito = parseInt(document.FormIB2001.DIGCTA.value);

    if ((isNaN(Agencia) == true) || (isNaN(Conta) == true) || (isNaN(Digito) == true))
    { valor = false; }
    else {
        if (ValidaDigito() == true)
        { valor = true; }
        else
        { valor = false; }
    }
    return valor;
}

function ValidaDigito() {
    var lsoma = 0;
    var ipeso = 2;
    var dv_informado = document.FormIB2001.DIGCTA.value;
    var dv_conta = document.FormIB2001.CTA.value;
    var tam = document.FormIB2001.CTA.value.length;
    var conta = new Array(tam);
    for (i = 0; i <= tam; i++)
    { conta[i] = dv_conta.substr(i, 1); }
    while (tam > 0) {
        digito = conta[--tam];
        if ((digito >= 0) && (digito <= 9)) {
            lsoma = lsoma + (digito - 0) * ipeso;
            ipeso = ipeso + 1;
            if (ipeso > 7)
            { ipeso = 2; }
        }
    }
    lsoma %= 11;
    lsoma = 11 - lsoma;
    if ((lsoma == 11) || (lsoma == 10))
    { lsoma = 0; }
    if (parseInt(dv_informado) == parseInt(lsoma))
    { RetDig = true; }
    else
    { RetDig = false; }
    return RetDig;
}

function ValidaLogin(campo) {
    //Habilitando  o código abaixo o acesso a area transacional fica indisponível
    //window.open("/msg/index.html","pop_indisponibilidade","width=750, height=528, top=0; left=0");

    //Para habilitar o acesso ao transacional basta retiara o comentário do if abaixo
    if (VerificaLogin() == true)
    { IB2000Open(window.document.FormIB2001); }
    else {
        var Agencia = parseInt(document.FormIB2001.AGN.value);
        var Conta = parseInt(document.FormIB2001.CTA.value);
        var Digito = parseInt(document.FormIB2001.DIGCTA.value);
        if (isNaN(Agencia) == true) {
            alert("Favor preencher o campo agência");
            document.FormIB2001.AGN.focus();
        }
        else {
            if (isNaN(Conta) == true) {
                if ((campo == "CTA") && (document.FormIB2001.CTA.value == ""))
                { alert("Favor preencher o campo conta"); }
                document.FormIB2001.CTA.focus();
            }
            else {
                if (isNaN(Digito) == true) {
                    if ((campo == "DIGCTA") && (document.FormIB2001.DIGCTA.value == ""))
                    { alert("Favor preencher o dígito de sua conta"); }
                    document.FormIB2001.DIGCTA.focus();
                }
                else {
                    alert("Informações inválidas. Por favor, verifique agência, conta e dígito");
                    document.FormIB2001.CTA.focus();
                }
            }
        }
    }
    //Fim do if que habilita o acesso a area transacional
}

function IB2000Open(IB2000Form) {
    window.document.IB2000.action = IB2000Form.action
    window.document.IB2000.AGN.value = IB2000Form.AGN.value
    window.document.IB2000.CTA.value = IB2000Form.CTA.value
    window.document.IB2000.DIGCTA.value = IB2000Form.DIGCTA.value    

    if (IB2000Form.AGN.value != '' && IB2000Form.CTA.value != '' && IB2000Form.DIGCTA.value != '') {
  
      //  InternetBanking = window.open("", "InternetBanking", "toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,screenX=0,screenY=0,left=0,top=0,width=765,height=528");
        window.document.IB2000.target='_blank';
        window.document.IB2000.submit()
        IB2000Form.reset()
    }
    return false;
}

function mOut(src,clrIn)
{
	if (!src.contains(event.toElement)) {
	  src.style.cursor = 'default';
	  src.bgColor = clrIn;
	}
}
