<!--
// ------------------------------------------------------------------------------------------
//    TRATARDADOS UNIFICADO - INTERNET BANKING PESSOA FISICA - 25/JUL/2003
// ------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------ //
// Acrescenta algumas propriedades aos controles:
// .Indice            : indica o índice na tela para o controle
// .IndiceAnterior    : indica o índice do controle anterior
// .IndicePosterior    : indica o índice para o controle posterior
// .Tam                : tamanho máximo para digitação
// .AutoSkip        : indica se pula para o próximo campo após completar o tamanho do campo
// .Tipo            : indica o tipo de dado
//                        'D' -> só dígitos de 0(zero) a 9(nove)
//                        'N' -> dígitos de 0(zero) a 9(nove), "."(ponto) e ","(vírgula)
//                        'C' -> caracteres de 'a' até 'z' e de 'A' até 'Z'
//                        'A' -> Exclui as aspas
//                        '$' -> dígitos de 0(zero) a 9(nove) e ","(vírgula)
//                        outro -> qualquer caracter entre ascii 32 e ascii 127
// .Saltar            : (reservado) indica o momento de saltar de campo
// ------------------------------------------------------------------------------------------ //

var BrowserVersion = 5;

// Carrega índices para o próximo controle e controle anterior
function InicializarIndices()
{
    if (document.CargaInicial==null)
    {
        document.CargaInicial=false;        // Seta para só fazer uma vez por documento
        var ctrlAnterior=null;
        var IndAnt=0;
        for ( var i=0; i<document.forms[0].elements.length;i++)
        {
            var e=document.forms[0].elements[i];
            if ( e.type!="hidden" && e.type!="image" )        
            {
                if ( ctrlAnterior != null )
                    ctrlAnterior.IndicePosterior=i;
                ctrlAnterior=e;
                e.Indice=i;
                e.IndiceAnterior=IndAnt;
            }
        }
        //if ( ctrlAnterior!=null )
        //{
        //    ctrlAnterior.IndicePosterior=i-1;
        //}
    }
}

// Colocar o foco em determinado campo
function SetarFoco ( ind )
    {
    InicializarIndices();
    if ( isNaN(ind) && document.forms[0].elements[ind].type!="hidden" )
        document.forms[0].elements[ind].focus();
    else
        for (;ind<document.forms[0].elements.length;ind++)
            if ( document.forms[0].elements[ind].type!="hidden" )
                break;
        if ( ind<=document.forms[0].elements.length )
            document.forms[0].elements[ind].focus();
    }

// Limpar o conteúdo do(s) campo(s)
function LimparCampo ( ind )
    // Para -1, limpa todos os elementos
    {
    if (isNaN(ind))            // Limpa pelo nome
        document.forms[0].elements[ind].value="";
    else if (ind != -1 )    // Limpa o elemento "ind" ( só considera "text" e "password" )
        for ( var i=ind; i < document.forms[0].elements.length;i++ )
            if ( document.forms[0].elements[i].type=="text" || document.forms[0].elements[i].type=="password")        // Só limpa campo "text"
                {
                document.forms[0].elements[i].value="";
                break;
                }
    else                    // Limpa todos os elementos "text" e "password"
        for ( var i=0; i < document.forms[0].elements.length; i++ )
            if ( document.forms[0].elements[i].type=="text" || document.forms[0].elements[i].type=="password" )
                document.forms[0].elements[i].value="";
        
    }

function WhatOS() {
    var u = navigator.userAgent.toLowerCase();

    // Windows Vista
    if (u.indexOf("windows nt 6.0") != -1) {
        return "WIN_VISTA";
    }

    // Windows Server 2003; Windows XP x64 Edition
    if (u.indexOf("windows nt 5.2") != -1) {
        return "WIN_SRV_2003_OR_XP_X64";
    }

    // Windows XP
    if (u.indexOf("windows nt 5.1") != -1) {
        return "WIN_XP";
    }

    // Windows 2000, Service Pack 1 (SP1)
    if (u.indexOf("windows nt 5.01") != -1) {
        return "WIN_2000_SP1";
    }

    // Windows 2000
    if (u.indexOf("windows nt 5.0") != -1) {
        return "WIN_2000";
    }

    // Microsoft Windows NT 4.0
    if (u.indexOf("windows nt 4.0") != -1) {
        return "WIN_NT_4_0";
    }

    // Windows Millennium Edition (Windows Me)
    if (u.indexOf("win 9x 4.90") != -1) {
        return "WIN_ME";
    }

    // Windows 98
    if (u.indexOf("windows 98") != -1) {
        return "WIN_98";
    }

    // Windows 95
    if (u.indexOf("windows 95") != -1) {
        return "WIN_95";
    }

    // Windows CE
    if (u.indexOf("windows ce") != -1) {
        return "WIN_CE";
    }

    return "";
}

function BitsProcessor() {
    var u = navigator.userAgent.toLowerCase();
    token = ["win64","ia64","x64","wow64"];
    for (var i=0; i <= this.token.length; i++) {
        if (u.indexOf(this.token[i]) != -1) {
            return "64";
        }
    }
    return "32";
}

function QualNavegador() {
    var u = navigator.userAgent.toLowerCase();
    var s = navigator.appName;    
    if (u.indexOf('safari') != -1) {
        return "SA";    
    
    } else if (u.indexOf('firefox') != -1) {    
        return "FF";
    }        
    if (s == "Microsoft Internet Explorer") {
        return "IE";        
        
    } else if ( s == "Netscape" ) {
        return "NE";        
        
    } else {
        return "";    
    }
}

function QualVersao() {
    var s = navigator.appVersion;
    if ( QualNavegador() == "IE" ) {
        var i = s.search("MSIE");
        s=s.substring(i+5);
        i=s.search(";");
        return s.substring(0,i);        
        
    } else if (QualNavegador() == 'FF') {
               var u = navigator.userAgent.toLowerCase();
               //Recuperar o numero da versao
        var firefoxVersionStr = u.substring(u.indexOf('firefox'));        
        //A string retornada tem o formato 1.n.n.n -> transforma em inteiro
        //Devolve as 2 primeiras posicoes
        return parseInt(firefoxVersionStr.replace(/\D/g, '').substring(0,2));
               
    } else if ( QualNavegador() == "NE" ){
        if(navigator.userAgent.indexOf('Netscape/7.0')!= -1)return "7.0";        
        if(navigator.userAgent.indexOf('Netscape/7.1')!= -1)return "7.1";
        return parseInt(s.substring(0,1));
        
    } else {
        return 0;
    }
}

// Verificar se é Macintosh
function SeMac()
{
    var s = navigator.appVersion;
    var v = s.search("Mac");  

    if (v!=-1)
    {
        return "MAC";
    }

    return 0;
}

// Verificar se é Linux
function SeLinux() {
    if (navigator.userAgent.indexOf('Linux') != -1) { 
        return "Linux";
    }
        return 0;
}

// Setar o evento
function SetarEvento(ctrl, Tam, Tipo, AutoSkip )
{
    // Filtra navegadores conhecidos
    var s = QualNavegador();

    if ( s.length==0 )
        return;

    if ( s=="IE" && QualVersao()>7 )
        return;
    /* As linhas abaixo, foram comentadas para a função rodar no NS 7.0    
    if ( s=="NE" && QualVersao()>4 )
        return;
    */
    if (ctrl.onkeypress==null)
    {
        if (AutoSkip==null)
            AutoSkip=true;
        if (Tipo!=null)
            Tipo.toUpperCase();
        ctrl.Tam=Tam;
        ctrl.Tipo=Tipo;
        ctrl.AutoSkip=true;
        ctrl.Saltar=false;
        InicializarIndices();
        ctrl.onkeypress=ValidarTecla;
        if (QualNavegador()=="IE" && QualVersao()>=5)
            ctrl.onkeyup=SaltarCampo;
    }
}

function SaltarCampo(ctrl)
{
    if (ctrl==null)
        ctrl=this;
    if ( ctrl.AutoSkip && ctrl.Saltar)
        if (ctrl.Saltar)
        {
            ctrl.Saltar=false;
            if ( ctrl.IndicePosterior != null )
                SetarFoco(ctrl.IndicePosterior);
        }
}

// Fazer o salto de campo
function ValidarTecla (evnt)
{
    var tk;
    var c;
    var tkce;
    var ce;
    // Recebe a tecla pressionada
    tk = ( (QualNavegador()=="IE") ? event.keyCode : evnt.which);
    c=String.fromCharCode(tk);
    c=c.toUpperCase();

    tkce = ( (QualNavegador()=="IE") ? event.keyCode : evnt.which);
    ce=String.fromCharCode(tkce);
    ce=ce.toUpperCase();
    
    // -- Este trecho faz com que o <Enter> tenha a função de <Tab>, mas acho inviável, pois não é possível
    //       colocar o foco em campos do Tipo "image", e, neste caso, nunca seria possível fazer a submissão
    //       do formulário
    // if ( tk == 13 )
    // {
    //    this.Saltar=true;
    //    SaltarCampo(this);
    //    return false;
    // }
    
    // Só aceita teclas alfanuméricas. Não aceita teclas de controle
    if ( tk < 32 )
        return true;
    if ( tk > 127 )
        return false;

    switch ( this.Tipo )
    {
    case "D":
        if ( c<"0" || c>"9" )
            return false;
        break;
    case "N":
        if ( (c<"0" || c>"9") && (c!="." && c!=",") )
            return false;
        if ( (c==",") && ((this.value.search(",")>-1) || (this.value.length==0)) )
            return false;
        if ( (c==".") && (this.value.length==0) )
            return false;
        break;
    case "C":
        if ( c<"A" || c>"Z" )
            return false;
        break;
    case "A":
        if ( c=='"' )
            return false;
        break;
    case "$":
        if ((c<"0" || c>"9") && (c!=",") && (c!="-"))
            return false;
        if ((c==",") && ((this.value.search(",")>-1) || (this.value.length==0)))
            return false;
        break;
    case "V":
        if ((c<"0" || c>"9") && (c!=","))
            return false;
        if ((c==",") && ((this.value.search(",")>-1) || (this.value.length==0)))
            return false;
        break;
    default:
        break;
    }

    //verifica se o tamanho do campo, coincide com o solicitado para saltar    
    // se for NS7.0, Safari não decrementa        
    if ((QualNavegador()=="NE" && QualVersao()=="7.0") || QualNavegador()=="SA")    
        this.Saltar=(this.value.length==this.Tam);    
    else
        this.Saltar=(this.value.length==this.Tam-1);    
        
        
    if ( ((QualNavegador()=="IE") && QualVersao()<5) || (QualNavegador()!="IE") )
        SaltarCampo(this);

    return true;
}
//-->
// ------------------------------------------------------------------------------------------ //
// Função   : Formata
// ------------------------------------------------------------------------------------------ //
function Formata(campo,tammax,teclapres,decimal) { 
  var tecla = teclapres.keyCode; 
  vr         = Limpar(campo.value,"0123456789"); 
  tam        = vr.length; 
  dec        = decimal 


if(tam < tammax && tecla != 8){ 
  tam = vr.length + 1; 
} 

if(tecla == 8 ) { 
  tam = tam - 1 ; 
} 

if( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) { 
 if ( tam <= dec ){
   campo.value = vr;
 } 

 if( (tam > dec) && (tam <= 5) ){ 
   campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam );
 } 

 if( (tam >= 6) && (tam <= 8) ){  
   campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ); 
 } 

 if( (tam >= 9) && (tam <= 11) ){ 
   campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
 }
 
 if( (tam >= 12) && (tam <= 14) ){ 
    campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam );
 }
 
  if ( (tam >= 15) && (tam <= 17) ){  
    campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam );
  } 
 } 
} 

// ------------------------------------------------------------------------------------------ //
// Função   : trataBlocoValor
// ------------------------------------------------------------------------------------------ //

function saltaUltimoBloco(objeto, evento, proximo) {
    
    var tecla = window.event ? evento.keyCode : evento.which;

    if (objeto.value.length >= objeto.maxLength && ((tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105))) {
        proximo.focus();
        proximo.select();
    }

    if (tecla == 86) {
        proximo.focus();
        proximo.select();
    }

    if (tecla == 9) {
        proximo.focus();
        proximo.select();
    }
}


//retira espaços da string
function lTrim(str){
    var resul;
    resul = "";
    //while (str.substr(0,1)==' ') 
    for (var i=0; i < str.length; i++) { 
        if (str.substr(i,1)!=' ')
            resul = resul + str.substr(i,1);
    }
    return resul;
}

function trataBlocoValor(objeto, destinoDia, destinoMes, destinoAno, destinoValor) { 
    var a, b, c, d;
        var day, month, year;
        var data, valor;
    var notData, notValor;
    var naoPreenche;
    var aux;

    // Inicializa variaveis
    naoPreenche = 0;
    notData = 0;
    notValor = 0;
    destinoDia.value = "";
    destinoMes.value = "";
    destinoAno.value = "";
    destinoValor.value = "";
    
    // Verifica se o bloco foi preenchido completamente
    aux = objeto;
    aux = lTrim(aux.value);    // Retira os espaços
        if (aux.length != 14) {
        naoPreenche = 1;
    } 
    // Verifica se o bloco é diferente de zeros
    aux = aux * 1;
        if (aux == 0) {
        naoPreenche = 1;
    } 
    
    // Verifica se a data é diferente de zero
    aux = objeto.value.substr( 0, 4 );
    aux = lTrim(aux);    // Retira os espaços
        if ((aux  * 1) == 0) {
        notData = 1;
    } 
    
    // Verifica se o valor é diferente de zero
    aux = objeto.value.substr( 4, 10 );
    aux = lTrim(aux);    // Retira os espaços
        if ((aux  * 1) == 0) {
        notValor = 1;
    } 

    // Preenche a data e o valor apenas se todo o bloco tiver sido preenchido    
    if (naoPreenche != 1) {        

        if (notData != 1){
            data = objeto.value.substr(0, 4) * 1;
            a = data + 35710 + 68569 + 2415019;
            b = toInteger(( 4 * a ) / 146097);
            a = a - toInteger(( 146097 * b + 3 ) / 4);
            c = toInteger(( 4000 * ( a + 1 ) ) / 1461001);
            a = a - toInteger(( 1461 * c ) / 4) + 31;
            d = toInteger(( 80 * a) / 2447);
            day = (a - toInteger(( 2447 * d ) / 80));
            a = toInteger(d / 11);
            month = (d + 2 - ( 12 * a ));
            year = (100 * ( b - 49 ) + c + a);
    
            destinoDia.value = padLeft(day, 2);                   
            destinoMes.value = padLeft(month, 2);
            destinoAno.value = year;
        }

        if (notValor != 1){    
            valor = (objeto.value.substring(4) * 1) + "";

            if (valor.length == 1) {
                valor = "00" + valor;
            }

            if (valor.length == 2) {
                valor = "0" + valor;
            }

            destinoValor.value = valor.substr(0, valor.length - 2) + "," + valor.substring(valor.length - 2);
        }

    }
}

//-------------------------------------------------

         function toInteger(value) {
            return Math.floor(value);
         }

         function padLeft(value, size) {
            return value < 10 ? "0" + value : value;
         }
// ------------------------------------------------------------------------------------------ //
// Função   : Recebe
// ------------------------------------------------------------------------------------------ //

function Recebe(campoTela){
     
     eval("document.forms[0]."+campoTela+".checked = true");
 }

// ------------------------------------------------------------------------------------------ //
 // Função   : RadioLimpa
// ------------------------------------------------------------------------------------------ //

function RadioLimpa(campoLimpaDia, campoLimpaMes, campoLimpaAno){
     


        eval("document.forms[0]."+campoLimpaDia+".value = '' ");
        eval("document.forms[0]."+campoLimpaMes+".value = '' ");
        eval("document.forms[0]."+campoLimpaAno+".value = '' ");

    
 }


// ------------------------------------------------------------------------------------------ //
// Função   : Limpar
// ------------------------------------------------------------------------------------------ //
function Limpar(valor, validos) { 
  // retira caracteres invalidos da string 
  var result = ""; 
  var aux; 
  for (var i=0; i < valor.length; i++) { 
   aux = validos.indexOf(valor.substring(i, i+1)); 
   if (aux>=0) { 
     result += aux; 
   } 
 } 
  return result; 
} 
// ------------------------------------------------------------------------------------------ //
// Função   : Retira
// ------------------------------------------------------------------------------------------ //

function Retira(campoDia, campoMes, campoAno,campoFoco){



    if(campoDia == ""){
    if(campoMes == ""){
    if(campoAno == ""){

          eval("document.forms[0]."+campoFoco+".checked = true");
        }
      }
    }
  }
// -------------------------------------------------------
// ´processaAcoesDataPagamento
// -------------------------------------------------------

function processaAcoesDataPagamento(objetoThis, radioHoje, radioAgendado, editDia, editMes, editAno, proximoElemento, evento) {
    var tecla = window.event ? evento.keyCode : evento.which;

  if(editDia != "" && editMes != ""){
    if (objetoThis == radioHoje) {
        editDia.value = "";
        editMes.value = "";
        editAno.value = "";
    } else {
        radioAgendado.checked = true;
        if (objetoThis == editDia && editDia.value.length >= editDia.maxLength && tecla >= 32) {
            editMes.focus();
            editMes.select();
        } else if (objetoThis == editMes && editMes.value.length >= editMes.maxLength && tecla >= 32) {
            editAno.focus();
            editAno.select();
        } else if (objetoThis == editAno && editAno.value.length >= editAno.maxLength && tecla >= 32) {
            proximoElemento.focus();
        }else if(tecla == 9){
            objetoThis.checked = true;
        }else if (objetoThis != radioAgendado && editDia.value.length + editMes.value.length + editAno.value.length == 0) {
            radioHoje.checked = true;
            radioHoje.focus();
        }
    }
  }
}
// ------------------------------------------------------------------------------------------ //
// Função   : FormataTotal
// ------------------------------------------------------------------------------------------ //
function FormataTotal(campo,tammax,decimal) { 
  vr         = Limpar(campo,"0123456789"); 
  tam        = vr.length; 
  dec        = decimal;
  

 if ( tam <= dec ){
   campo = vr;
 } 

 if( (tam > dec) && (tam <= 5) ){ 
   campo = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam );
 } 

 if( (tam >= 6) && (tam <= 8) ){  
   campo = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ); 
 } 

 if( (tam >= 9) && (tam <= 11) ){ 
   campo = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
 }
 
 if( (tam >= 12) && (tam <= 14) ){ 
    campo = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam );
 }
 
  if ( (tam >= 15) && (tam <= 17) ){  
    campo = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam );
  } 

  return campo;
} 

//************************************************************************
//
//Função para desabilitar campo, dependendo da escolha no radio button
//
//************************************************************************

function desabilitaNasc(campo1){

 if("document.forms[0]."+ campo1 +".ckecked == true"){
     document.forms[0].NUMPASSAPORTE.value  = "";
    document.forms[0].PAISORIGEM.value = "";
    document.forms[0].NUMPASSAPORTE.disabled  = true;
    document.forms[0].PAISORIGEM.disabled  = true;

  }
}

function habilataNasc(campo1){

 if("document.forms[0]."+ campo1 +".ckecked == true"){
    document.forms[0].NUMPASSAPORTE.disabled  = false;
    document.forms[0].PAISORIGEM.disabled  = false;
  }
}
 
function desabilitaEnd(campo1){

 if("document.forms[0]."+ campo1 +".ckecked == true"){
    document.forms[0].OUTROENDERECO.value  = "";
    document.forms[0].ENDNUMERO.value  = "";
    document.forms[0].COMPLEMENTO.value  = "";
    document.forms[0].BAIRRO.value  = "";
    document.forms[0].CEP.value  = "";
    document.forms[0].CEPCOMPL.value  = "";
    document.forms[0].CIDADE.value  = "";
    document.forms[0].UFPORT.value  = "";

    document.forms[0].OUTROENDERECO.disabled  = true;
    document.forms[0].ENDNUMERO.disabled  = true;
    document.forms[0].COMPLEMENTO.disabled  = true;
    document.forms[0].BAIRRO.disabled  = true;
    document.forms[0].CEP.disabled  = true;
    document.forms[0].CEPCOMPL.disabled  = true;
    document.forms[0].CIDADE.disabled  = true;
    document.forms[0].UFPORT.disabled  = true;

  }
}

function habilitaEnd(campo1){

 if("document.forms[0]."+ campo1 +".ckecked == true"){
    document.forms[0].OUTROENDERECO.disabled  = false;
    document.forms[0].ENDNUMERO.disabled  = false;
    document.forms[0].COMPLEMENTO.disabled  = false;
    document.forms[0].BAIRRO.disabled  = false;
    document.forms[0].CEP.disabled  = false;
    document.forms[0].CEPCOMPL.disabled  = false;
    document.forms[0].CIDADE.disabled  = false;
    document.forms[0].UFPORT.disabled  = false;
  }
}

//*********************************************************
//
//Função para completar o tamanho de um string, à esquerda.
//
//*********************************************************

function fillLeft(field, size, value) {
    var result = field==null?"":field;
    if (size != 0 && value != "") {
        for (var i = size; result.length < i;) {
            result = value + result;
        }
    }
    return result;
}

//*********************************************************
//
//Função para completar o tamanho de um string, à direita.
//
//*********************************************************

function fillRight(field, size, value) {
    var result = field==null?"":field;
    if (size != 0 && value != "") {
        for (var i = size; result.length < i;) {
            result = result + value;
        }
    }
    return result;
}

//*********************************************************
//
//Função para obter determinado parametro da URL.
//param callingURL - possibilita passagem de URL de frames 
//              além do self.document.URL 
//
//*********************************************************

function getParametroURL(paramName, callingURL) {
    var search = paramName + "=";
    var callingURL;            
    var URLPar;
    
    // Verifica URL
    if (callingURL ==null || callingURL == "") {
        callingURL = self.document.URL;            
    } else {
        URLParam = callingURL.substring(callingURL.indexOf('?')+1,callingURL.length);
    }
    
    // Verifica se existe algum parametro    
    if (URLParam) {         
        offset = URLParam.indexOf(search); // O nome solicitado existe                                           
        if (offset != -1) {                             
            offset += search.length; // início do valor
            end = URLParam.indexOf("&", offset); // fim do valor
            if (end == -1) {                                         
                end = URLParam.length;                              
            }                        
            return unescape(URLParam.substring(offset, end));
        }           
    }
}

// -------------------------------------------------------

