<!--
// Programa    : funcao_geral.js
// Programador : Emerson Dutra dos Reis
// Finalidade  : Funções gerais de sistemas em java script

// ----------------------------------------------------
//   Funções Gerais do sistema
// ----------------------------------------------------


var isNN   = (navigator.appName.indexOf("Netscape")!=-1);
var IsMSIE = (navigator.userAgent.indexOf("MSIE") != -1);


// Funções para Saltar de campo
// Salta de campo tipo input
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    

    if(input.value.length >= len && !containsElement(filter,keyCode)) {
       // input.value = input.value.slice(0, len);
       input.value.toUpperCase();
       input.form[(getIndex(input)+1) % input.form.length].focus();
    }
    //  Se for back space volta campos
    // else
    //{
    // if (e.keyCode == 8) {       
    //   input.value = input.value.slice(0, len);
    //   input.value.toUpperCase();
    //   // alert(input.value);
    //   if (input.value == "") {
    //   input.form[(getIndex(input)-1) % input.form.length].focus();
    //   }
    // }
    // }

    function containsElement(arr, ele) {
    var found = false, index = 0;
       while(!found && index < arr.length)
          if(arr[index] == ele)
             found = true;
          else
             index++;
          return found;
    }

    function getIndex(input) {
    var index = -1, i = 0, found = false;
       while (i < input.form.length && index == -1)
          if (input.form[i] == input)index = i;
          else i++;
             return index;
    }

    return true;
}

// Salta de campo tipo select
function autoTabsele(input, e) {

    // alert(input.form[(getIndex2(input)+1) % input.form.length].readOnly);
    if (input.form[(getIndex2(input)+1) % input.form.length].readOnly == true){
       input.form[(getIndex2(input)+2) % input.form.length].focus();
    }
    else {
       input.form[(getIndex2(input)+1) % input.form.length].focus();
    }

    // input.form[(getIndex2(input)+1) % input.form.length].focus();

    return true;
}

function getIndex2(input) {
var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
      if (input.form[i] == input)index = i;
      else i++;
      return index;
}

// Funcao para contar numero de caracter em campo memo 
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
// alert(countfield.value);
}


//Bloco de código para esconder e mostra frmFormulario
var Ver4 = parseInt(navigator.appVersion) >= 4
var IE4 = ((navigator.userAgent.indexOf("MSIE") != -1) && Ver4)
var block = "frmFormularioulario";
function esconde() {	document.frmFormulario.style.visibility = "hidden" }
function mostra() { document.frmFormulario.style.visibility = "visible" }
//Bloco de código para esconder e mostra frmFormulario


// Código para o teclado 
function tecladown (digito){
	if (digito == ''){
		document.frmFormulario.senha.value = '';
		return;	
	}
	var pass = document.frmFormulario.senha.value;
	if (pass.length >= 8){
		return;
	}
	document.frmFormulario.senha.value = document.frmFormulario.senha.value + digito;
}
function teclaclick(tecla){
	return false;
}
function teclaup(tecla){
	tecladown(tecla);
}
// --


// -- Contador para objeto TextArea.
function limita(campo){
	var tamanho = document.frmFormulario[campo].value.length;
	var tex=document.frmFormulario[campo].value;
	if (tamanho>=1539) {
		document.frmFormulario[campo].value=tex.substring(0,1539); 
	}
	return true;
}

function contacampo(campo, tamtxt) {
document.frmFormulario[tamtxt].value =  1540-document.frmFormulario[campo].value.length;
}
// --



function SetHelp(txt) { help.innerText = txt ; }

function main(campofoco) { 
	if ( campofoco == '' || document.frmFormulario.elements.length == 0 ) 
		return false;
			
	var num = parseInt(campofoco);

	if ( num || num == 0 )
	{
		if ( document.frmFormulario[num] )
			document.frmFormulario[num].focus();
	}
	else 
	{
		if ( (campofoco == "senhaConta" || campofoco == "senhaAtual") && document.applets["tclJava"] ) 
			document.applets["tclJava"].setFocus();
		else if ( document.frmFormulario[campofoco] )
			document.frmFormulario[campofoco].focus();
	}
}

function Apaga(){
	if (document.frmFormulario.elements.length != 0)
		for (i = 0; i < document.frmFormulario.elements.length; i++)
		{
			if( document.frmFormulario[i].type != "hidden" )
				document.frmFormulario[i].value="";
		}
}


var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage()
{
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // other browsers
    alert("Desculpe seu browser não suporta esta função. Por favor utilize a barra de trabalho para imprimir a página.");
  return false;
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}

function FormataDado(campo,tammax,pos,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.frmFormulario[campo].value;
	vr = vr.replace( "-", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length ;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){ tam = tam - 1 ; }
			
	if ( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
	 		document.frmFormulario[campo].value = vr ;}
		if ( tam > pos && tam <= tammax ){
			document.frmFormulario[campo].value = vr.substr( 0, tam - pos ) + '-' + vr.substr( tam - pos, tam );}
	}
	//alert("campo: " + document.frmFormulario[campo+1].name);
	if ( !teclapres.shiftKey && tecla == 9 && document.frmFormulario[campo+1].name == "senhaConta" && document.applets['tclJava'] ){
		//alert("aki 1");
			document.applets['tclJava'].setFocus();
	}
}

function FormataValor(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.frmFormulario[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	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 <= 2 ){ 
	 		document.frmFormulario[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		document.frmFormulario[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 - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.frmFormulario[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 ) ;}
	}
}

function FormataValor2(campo) {
var	vr = document.frmFormulario[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
var	tam = vr.length;
	
		if ( tam <= 2 ){ 
	 		document.frmFormulario[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		document.frmFormulario[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 - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.frmFormulario[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 ) ;}

}

function SaltaCampo (campo,prox,tammax,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.frmFormulario[campo].value;	
	 	
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		document.frmFormulario[campo].value = vr.substr( 0, vr.length - 1 ); }
	else{
	 	vr = vr.replace( "-", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( ",", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	tam = vr.length;	
	 		 	
		
	 	if (tecla != 0 && tecla != 9 && tecla != 16 ){
		
			if ( tam == tammax ){
				if ( prox == "senhaConta" || (document.frmFormulario.elements[prox] && document.frmFormulario.elements[prox].name == "senhaConta"))
				{
					if ( document.applets['tclJava'] )
						document.applets['tclJava'].setFocus();
					else if ( document.frmFormulario.senhaConta )
						document.frmFormulario.senhaConta.focus();
				}
				else if ( document.frmFormulario[prox] )
					document.frmFormulario[prox].focus();
			}
		}
	}
}

// Verifica se o campo é numerico
function isNumero(campo) {
var found = false, posicao = 0, nvar = "";

    // alert(campo.length);        
    
    while(!found && posicao < campo.length)
    {
       nvar = campo.substr( posicao, 1 );
       // alert(nvar);        
       
        if(nvar != "0" && nvar != "1"  && nvar != "2"  && nvar != "3"  && nvar != "4" &&
           nvar != "5" && nvar != "6"  && nvar != "7"  && nvar != "8"  && nvar != "9")
        {                
          found = true;
        }
        else
          posicao++;          
    }
    
    // alert(!found);      
    return !found;
    
}

function validaData(campoData) {
var ano = campoData.substr( 6, 4 ), 
    mes = campoData.substr( 3, 2 ),  
    dia = campoData.substr( 0, 2 );  
//  alert(campoData);
  
  // Valida o campo
  if (campoData.length > 10) {
     return false;
  }
  if (campoData.length < 8) {
     return false;
  }  
  if (dia == "" && mes == "" && ano == "") {
     return false;
  }
    
  // Valida o Ano
  if (!isNumero(ano)) {
     return false;
  }
  
  if (ano.length == 4) {
     if (ano < "1901" || ano > "2050") {
        return false;
     }     
  } else {          
     if (ano <= "00" || ano >= "20") {        
        return false;
     }       
  }
  

  // Valida o Mes
  if (!isNumero(mes)) {
     return false;
  }
  
  if (mes < "01" || mes > "12")  {
     return false;
  }  

  // Valida o Dia
  if (!isNumero(dia)) {
     return false;
  }  
  
  if (dia < "01" || dia > "31")  {
     return false;
  }  
  
return true;
}

function FormataData(campo,teclapres,input) {
	var tecla = teclapres.keyCode;
	var nvr2 = "";
	var ano;
	if (IsMSIE) {
		
	var strCheck = '0123456789';   
    var whichCode = (window.Event) ? teclapres.which : teclapres.keyCode;        
    if (whichCode == 13) return true;  // Enter
    key = String.fromCharCode(whichCode);  // Get key value from key code        
    
    if (strCheck.indexOf(key) == -1) return false;  // Not a valid key	
	
	vr = document.frmFormulario[campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;    
	        
	if ( tecla != 9 && tecla != 8 && tecla != 16 && tecla != 111 ){
	    //alert(vr.substr( tam - 2, tam ));
	    
		if ( tam > 3 && tam < 5 )
			document.frmFormulario[campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
			
		if ( tam >= 5 && tam <= 10 )
			document.frmFormulario[campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
			
		nvr2 = document.frmFormulario[campo].value + String.fromCharCode(teclapres.keyCode);
		// alert(nvr2);
			
        if (nvr2.length == 8)  {
                              
           if (validaData(nvr2)) {
              
              ano = nvr2.substr( 6, 4 ); 
              // alert(ano);
                            
              // document.frmFormulario[campo].value = nvr2;
              if (ano == "19") {                 
                 teclapres.returnValue = true;
                 return true;
              } else {              
                 document.frmFormulario[campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/20' + vr.substr( 4, 2 ) + String.fromCharCode(teclapres.keyCode); 
                 teclapres.returnValue = false;
                 
                 if (tecla != 9) 
                    input.form[(getIndex2(input)+1) % input.form.length].focus();                 
              }
           }               
           else {                                  
              document.frmFormulario[campo].focus();
              return true;
           }               
        }
			
        if (nvr2.length == 10)  {
           // alert(document.frmFormulario[campo].value);
           // validaData(document.frmFormulario[campo].value);
                              
           if (validaData(nvr2)) {
              if (tecla != 9) 
                 input.form[(getIndex2(input)+1) % input.form.length].focus();

              // alert(nvr2);
              document.frmFormulario[campo].value = nvr2;
              teclapres.returnValue = false;
           }
           else {
              document.frmFormulario[campo].value = nvr2;                    
              alert('Data inválida !!');
              document.frmFormulario[campo].focus();
              return false;
           }               
        }
	}

	}
     return true;
}


// Verificar erro de pagina quando digita 
function FormataCEP(campo, teclapres, input) {    
	var tecla = teclapres.keyCode;		
	//alert(tecla);
	var vr = document.frmFormulario[campo].value;		
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length+1;			
	
	if ( (tecla != 9) && (tecla != 8) ){	
	   if ( (tam > 5) && (tam < 10) ) {
			  document.frmFormulario[campo].value = vr.substr( 0, 5 ) + '-' + vr.substr( 5, tam ); 		  			  
			  
			  // alert(tecla);
			  
              if (document.frmFormulario[campo].value.length == 9)  {
                  if (tecla != 9) 
                    input.form[(getIndex2(input)+1) % input.form.length].focus();
               }			  		  
		}
	}
	return true;
}


function FormataMesAno(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.frmFormulario[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 7 )
			document.frmFormulario[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, tam ); }
}

function FormataPercentual(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.frmFormulario[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	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 <= 3 ){ 
	 		document.frmFormulario[campo].value = vr ; }
	 	if ( (tam > 3) && (tam <= 6) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 3 ) + ',' + vr.substr( tam - 3, tam ) ; }
	}		
	
}


function VerificaJava()
 	{
	if (navigator.javaEnabled())
		document.frmFormulario.javas.value="sim"
	}

function FormataCpf(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;		
	vr = document.frmFormulario[campo].value;
    // alert(tecla);
	
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;    
    
	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 <= 3 ){ 
	 		document.frmFormulario[campo].value = vr ; }
	 	if ( (tam > 3) && (tam <= 7) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 8) && (tam <= 11) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }	 		 	
	}	
			
}

function FormataCartaoCredito(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.frmFormulario[campo].value;

	if ( tecla == 8 || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105) )
	{
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( ",", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( "-", "" );
		vr = vr.replace( "-", "" );
		vr = vr.replace( "-", "" );
		vr = vr.replace( "-", "" );
		vr = vr.replace( "-", "" );
		tam = vr.length;

		if (tam < tammax && tecla != 8)
		   {tam = vr.length + 1 ; }

		if (tecla == 8 ) {tam = tam - 1 ; }

		if ( tam < 5 )
		   { document.frmFormulario[campo].value = vr ; }
	 	if ( ( tam >  4 ) && ( tam < 9 ) )
		   { document.frmFormulario[campo].value = vr.substr( 0, 4 ) + '.' + vr.substr( 4, tam-4 ) ; }
	 	if ( ( tam >  8 ) && ( tam < 13 ) )
		   { document.frmFormulario[campo].value = vr.substr( 0, 4 ) + '.' + vr.substr( 4, 4 ) + '.' + vr.substr( 8, tam-4 ) ; }
	 	if ( tam > 12 )
		   { document.frmFormulario[campo].value = vr.substr( 0, 4 ) + '.' + vr.substr( 4, 4 ) + '.' + vr.substr( 8, 4 ) + '.' + vr.substr( 12, tam-4 ); }
	}	
}

function FormataCgc(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.frmFormulario[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;

	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 <= 2 ){ 
	 		document.frmFormulario[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 6) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 7) && (tam <= 9) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 6 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 10) && (tam <= 12) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 13) && (tam <= 14) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.frmFormulario[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 ) ;}
	}		
}

function FormataTelefone(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.frmFormulario[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;

	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 <= 2 ){ 
	 		document.frmFormulario[campo].value = vr ; }
	 	if ( (tam > 4) ){
	 		document.frmFormulario[campo].value = vr.substr( 0, tam - 4 ) + '-' + vr.substr( tam - 4, tam ) ; }
	}		
}


function enviaSub() {
	document.frmFormulario.submit();
	return false;
}


function mudaFoco(campo)
{
	if(campo == "98") {
		//var nb = document.frmFormulario.elements[document.frmFormulario.elements.length - 1].name;
		//if(nb.indexOf(".x"))
		//	nb = nb.substring(0,nb.length-2);
		//document.frmFormulario.elements[nb].focus();
		return;
	}
	if( (campo == "senhaConta" || (document.frmFormulario.elements[campo] && document.frmFormulario.elements[campo].name == "senhaConta")) && document.applets['tclJava'] )
		document.applets.tclJava.setFocus();
	else if (document.frmFormulario.elements[campo])
		document.frmFormulario.elements[campo].focus();
}

function mostraBalao(mst) {
	if (mst) {
		document.all["balaoApplet"].style.visibility="visible";
	}
	else {
		document.all["balaoApplet"].style.visibility="hidden";
	}
}

function teclaTab(teclaPress) {
	if(teclaPress.keyCode == 9)
		focaApplet();
}

function focaApplet() {
	if (document.applets['tclJava'] ) {
		document.applets.tclJava.setFocus();
	}
}
	
function focaApplet2(nomeApplet) {
	if (document.applets[nomeApplet] ) {
		document.applets[nomeApplet].setFocus();
	}
}	

function setaCod(numCod) {
	if (document.frmFormulario.elements['numCod'])
		document.frmFormulario.elements['numCod'].value = numCod;
}

function TesteJF(teclapres) {
	var tecla = teclapres.keyCode;	
	alert( tecla )
}

// Funcao para abril janela links
function popUp (sURL, sName, dx, dy) {
    if (dx == "0" && dy == "0") {        
	window.open(sURL, sName);
    }
    else {
      window.open(sURL, sName, 'width='+dx+',height='+dy+',scrollbars=1,resizable=1');
    }
   
}

// Utilizado para formatar o campo de valor
function currencyFormat(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
len = fld.value.length;
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) fld.value = '';
if (len == 1) fld.value = '0'+ decSep + '0' + aux;
if (len == 2) fld.value = '0'+ decSep + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
fld.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}


// Mostra o campo no formado de valor
function JSmostraValor(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;

key = ' ';  // Get key value from key code

len = fld.value.length;
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';

//for(; i < len; i++)
//if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);

aux += key;
len = aux.length;

alert(len);
if (len == 0) fld.value = '';
if (len == 1) fld.value = '0'+ decSep + '0' + aux;
if (len == 2) fld.value = '0'+ decSep + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
fld.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}

// Permite posicionar nas letrar nos combos 
function PesquisaCombo(campo,teclapres,input) {
	var tecla = String.fromCharCode(teclapres.keyCode);
        var flag = "";
		
	vr = document.frmFormulario[campo].value;
	len = document.frmFormulario[campo].length;
	
	// alert(len);
	
    // alert(document.frmFormulario[campo].selectedIndex);
    // alert(document.frmFormulario[campo].options[0].value);
    //
    // alert(document.frmFormulario[campo].length); // tamanho 
    
    // alert(tecla);
    
    // alert(tecla);
    
    for(i = 0; i < len; i++) {
        
        vr = document.frmFormulario[campo].options[i].text;
        if (flag == "") {
           posicao=vr.indexOf("-" , 0);       
           // alert(posicao);
           if (vr.substr( posicao+2, 1 ) == tecla) {
              document.frmFormulario[campo].selectedIndex = i;
              flag = "0";
            }        
        }
     }
    
}

// Permite posicionar nas letrar das combos 
function PesquisaCombo2(campo,teclapres,input) {
	var tecla = String.fromCharCode(teclapres.keyCode);
	var tecla2 = teclapres.keyCode;
    var flag = "";
    var i, j;
		
	vr = document.frmFormulario[campo].value;
	len = document.frmFormulario[campo].length;
	
    // alert(tecla2);	
	if ((tecla2 == 35) || (tecla2 == 46)) {	   
	   document.frmFormulario["pesq"].value = "";
	   document.frmFormulario[campo].selectedIndex = 0;
	   
	   return true;
	}
	document.frmFormulario["pesq"].value = document.frmFormulario["pesq"].value + tecla;
	
	tecla = document.frmFormulario["pesq"].value;
	// alert(tecla);
	
	j = document.frmFormulario[campo].selectedIndex;
	alert(j);
    for(i = 0; i < len; i++) {
        
        vr = document.frmFormulario[campo].options[i].text;
        if (flag == "") {
           // posicao=vr.indexOf("-" , 0);       
           posicao=0;
                                 
           if (vr.substr( posicao, tecla.length ) == tecla) {              
              document.frmFormulario[campo].selectedIndex = i;
              flag = "0";
            }        
        }
     }
     alert(j);
     if (flag == "") {
        document.frmFormulario[campo].selectedIndex = j;     
     }   
    
}

// Tira os espaços em branco ( "  " ) de uma string
function TiraBranco(campo) {
    var vr = campo;
    var len = campo.length;

    for(i = 0; i < len; i++) {
       vr = vr.replace( "  ", " " );
    }
    return vr;
}


// Utilizado para formatar o campo de juros no formato 99.9999
// com 4 casas decimais
function decimal4Format(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
len = fld.value.length;
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;

//  Se o tamanho for maior de 99.9999 neste formata sair fora
if (len >= 7) {   
   aux2 = '';
   for (i = 0; i <= 6 ; i++) {
      aux2 += fld.value.charAt(i);                  
   }   
   fld.value = aux2;
   return true;
}

len = aux.length;
// alert(len);
if (len == 0) fld.value = '';
if (len == 1) fld.value = '0'+ decSep + '000' + aux;
if (len == 2) fld.value = '0'+ decSep + '00' + aux;
if (len == 3) fld.value = '0'+ decSep + '0' + aux;
if (len == 4) fld.value = '0'+ decSep + aux;
if (len > 4) {

aux2 = '';
for (j = 0, i = len - 5; i >= 0; i--) {
if (j == 5) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}

//alert(aux2);
fld.value = '';
len2 = aux2.length;

for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 4, len);
}

return false;
}

// Utilizado para formatar o campo de juros no formato 99.9999
// com 5 casas decimais
function decimal5Format(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
len = fld.value.length;
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;

//  Se o tamanho for maior de 99.99999 neste formata sair fora
if (len >= 8) {   
   aux2 = '';
   for (i = 0; i <= 7 ; i++) {
      aux2 += fld.value.charAt(i);                  
   }   
   fld.value = aux2;
   return true;
}

len = aux.length;
// alert(len);
if (len == 0) fld.value = '';
if (len == 1) fld.value = '0'+ decSep + '0000' + aux;
if (len == 2) fld.value = '0'+ decSep + '000' + aux;
if (len == 3) fld.value = '0'+ decSep + '00' + aux;
if (len == 4) fld.value = '0'+ decSep + '0' + aux;
if (len == 5) fld.value = '0'+ decSep + aux;
if (len > 5) {

aux2 = '';
for (j = 0, i = len - 6; i >= 0; i--) {
if (j == 6) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}

//alert(aux2);
fld.value = '';
len2 = aux2.length;

for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 5, len);
}

return false;
}


// Retorna o campo identificado pela opcao
//  o final do campo é = "_"
function retornaCampo(opcao, campo){
var i;
var nvar;
var len = campo.length;
var nresult = '';
var flag = "0";

   for (i = 0; i <= len -1 ; i++) {
        nvar = campo.charAt(i); 

        if (flag == '1') {
           if (nvar == '_') {
              return parseFloat(nresult);
           } else {
             nresult += nvar;
           }
        }       
        
        if (nvar == opcao) {
           flag = "1"
        } 
        
   }   
}


function round(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

// Formata o numero 1203483.09 para 1.203.483,09
function formatNumber(number) {
var len = len2 = 0;
var i = j = p = x = 0;
var num = number.toString();
var parteint = result = '';
var flag = comp = '';
var decSep = ','; // Define decional
var milSep = '.'; // Define milhar

len  = num.length;
len2 = len;

// Encontra decimal
i=num.indexOf("." , 1);        
if (i == -1) {   
   i = len -1;
   p = 0;
}
else {
   flag = '1';
   p = 1;
}

// alert(i);
// Parte inteira
for (x = i - p; x >= 0; x--) {
    nvar = num.charAt(x);  
    if (j == 3) {
       parteint += milSep + nvar;
       j = 0;
    } else {
      parteint += nvar;
    }
    j++;
}

parteint = parteint.toString();
len = parteint.length;
for (x = len-1; x >= 0; x--) {
    nvar = parteint.charAt(x);  
    result += nvar;
}
//alert(result);

// Parte decimal
nvar = num.substr(i + 1, len2-1);
len = nvar.length;
if (len == 0) { 
   comp = '00';
}
else {
    if (len == 1) { 
        comp = '0';    
    }
}

result += decSep + nvar + comp

return result;
}


// Permite posicionar nas letrar nos combos 
function PosicionaCombo(campo, campo_sele, teclapres,input) {
	var tecla = String.fromCharCode(teclapres.keyCode);
        var flag = "";
		
        vr2 = document.frmFormulario[campo].value;

        // alert(vr2.length);

	vr = document.frmFormulario[campo_sele].value;
	len = document.frmFormulario[campo_sele].length;
		
	// alert(len);
	    
    for(i = 0; i < len; i++) {
        
        vr = document.frmFormulario[campo_sele].options[i].text;
        // alert( vr ); 
        if (flag == "") {
           
           if (vr.substr( 0, vr2.length ) == vr2) {
              document.frmFormulario[campo_sele].selectedIndex = i;
              flag = "0";
            }        
        }
     }
    
}

// Atualiza campo relaciona com combo
function AtualizaCampoCombo(campo, campo_sele,input, e) {

   document.frmFormulario[campo].value = document.frmFormulario[campo_sele].value;

   autoTabsele(input, e)
}

// Funcao para abril janela links
function popUp (sURL, sName, dx, dy) {
	window.open(sURL, sName, 'width='+dx+',height='+dy+',scrollbars=1,resizable=1');
}

function popUp2 (sURL, sName, dx, dy) {
	window.open(sURL, sName, 'width='+dx+',height='+dy+',scrollbars=0,resizable=0');
}

function popUp3 (sURL, sName, dx, dy) {
    if (dx == "0" && dy == "0") {        
	window.open(sURL, sName);
    }
    else {
      window.open(sURL, sName, 'width='+dx+',height='+dy+',scrollbars=1,resizable=1');
    }
   
}

// Criptografa Senha
//  Opcao = "1" - Cripto
//          "0" - DesCripto
function criptografa(Senha, Opcao) {
    var i, x;    
    var vr = "";
    var vr2 = "";
    var len = Senha.length;            
    var CharsIn  = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()-_=+[{]}|;:,<.>/?";
    var CharsOut = "!@&*wxyzAB`~()-_rsqtH=+[{]}EFGkl,<.mnIJK34L0uvCD125MN#$%^opOYZ6789|;:>/?hijPQRSTabcWXdefgUV";
    var flag = "1";

    // Verifica se o caracter é valido
    for (i = 0; i <= len -1 ; i++) {                      
        vr = Senha.charAt(i);

        if (Opcao == "0" ) // DesCripto
        {
          if (CharsOut.indexOf(vr) == -1) {
             flag = "0";             
          }         
          
        } else             // Cripto
        {
          if (CharsIn.indexOf(vr) == -1) {
             flag = "0";
          }               
        }
    }    
    
    if (flag == "0") {
       alert("Existe caracter invalido !!");              
       return vr;
    } 
    
    // Executa Cripto ou  DesCripto
    for (i = 0; i <= len -1 ; i++) {                      
        vr = Senha.charAt(i);

        if (Opcao == "0" ) // DesCripto
        {
          x = CharsOut.indexOf(vr);          
          vr2 += CharsIn.charAt(x);
          
        } else             // Cripto
        {
          x = CharsIn.indexOf(vr);          
          vr2 += CharsOut.charAt(x);
        }
    }    
    
    return vr2;
}


function sair_AreaUsuario_OnClick() {
var flag;
var flag1;

    flag1 = "Deseja sair da área de usuário ?";
    flag = window.confirm(flag1); 

    return flag;
}

function bt_Voltar_OnClick(param) {
   self.location.href=param;
}	

function SomenteCodigo( xCampo ) {
var posicao
var result;       

       posicao=xCampo.indexOf("___", 1);
       result=xCampo.substring(0, posicao);

       return ( result );	       
}

function SomenteDescricao( xCampo ) {
var posicao
var result;       

       posicao=xCampo.indexOf("___", 1);        
       result=xCampo.substring(posicao+3, xCampo.length);
       
       return ( result );
}


//-->




