// JavaScript Document

function formata_milhar(argumento){
	if (argumento.value.length == 3){
		argumento.value = argumento.value + '.';
	}
	if (argumento.value.length == 7){
		argumento.value = argumento.value + '.';
	}	
/*	if (argumento.value.length == 11){
		argumento.value = argumento.value + '.';
	}		*/
}


function altera_legenda(argumento){
	var legenda = document.getElementById("legenda");
	legenda.innerHTML = argumento;
}

// Exemplo: onKeyDown='formatabb("valorJuros", 17, event)'
function formatabb(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;1
	vr = document.formu[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.formu[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.formu[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.formu[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.formu[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.formu[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.formu[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 ) ;}
	}

	for (var ct = 0; ct < document.formu.elements.length; ct++) {
		if (document.formu.elements[ct].name == document.formu.elements[campo].name) {
			if ( !teclapres.shiftKey && tecla == 9 && document.formu.elements[ct+1] && document.formu.elements[ct+1].name == "senhaConta" && document.applets['tclJava'] ){
				document.applets['tclJava'].setFocus();
			}	
		}
	}
}

// onKeyPress="chkNumero();"
function chkNumero() {
 if (event.keyCode == '13') 
 {
 }
 else if (event.keyCode < '48' || event.keyCode > '58')
 {
  alert('Digite apenas números!'); 
  event.keyCode = '127';
  }
}




function isBissexto(iAno)
{
	var bRet
	bRet = false
	if (iAno % 4 == 0 && (iAno % 100 !=0 || iAno % 400 ==0 ))
		bRet = true
	return bRet
}

function verifica_data(oData) 
{
	date = oData.value;
	sMsg = 'Por favor, digite uma data válida';
	
	if	((date.length < 10) && (date != ""))
		{
		window.alert('Por favor, digite uma data válida, formato aceito: dd/mm/aaaa.');
		if	((typeof(oData) == 'object') && (oData.type != 'hidden'))
			{
			oData.focus();
			oData.value="";
			}
		return(false);
		}

	if	(date != "") 
		{
		if	(date.indexOf("/")==date.lastIndexOf("/"))
			{
			// se houver menos que duas barras caia fora
			window.alert('Por favor, digite uma data válida, formato aceito: dd/mm/aaaa.');
			if	((typeof(oData) == 'object') && (oData.type != 'hidden'))
				{
				oData.focus();
				oData.value="";
				}
			return(false);
			}

		day  =date.substr(0,date.indexOf("/"))
		month=date.substr(date.indexOf("/")+1,date.lastIndexOf("/")-date.indexOf("/")-1)
		year =date.substr(date.lastIndexOf("/")+1,date.length-date.lastIndexOf("/")-1)

		if	(isNaN(day) || isNaN(month) || isNaN(year)) 
			{
			window.alert('Por favor, digite uma data válida, formato aceito: dd/mm/aaaa.');
			if	((typeof(oData) == 'object') && (oData.type != 'hidden'))
				{
				oData.focus();
				oData.value="";
				}
			return(false);
			}
			
		if	(day<1 || day>31 || month<1 || month>12 || year<1800 || year>2200) 
			{
			window.alert('Por favor, digite uma data válida, formato aceito: dd/mm/aaaa.');
			if	((typeof(oData) == 'object') && (oData.type != 'hidden'))
				{
				oData.focus();
				oData.value="";
				}
			return(false);
			}

		// Janeiro, Março, Maio, Julho, Agosto, Outubro, Dezembro
		if	(((month == "01") ||
			  (month == "03") ||
			  (month == "07") ||
			  (month == "08") ||
			  (month == "10") ||
			  (month == "12")) && 
			 ((day <= "0")	  ||
			  (day > "31")))
			{
			window.alert(sMsg);
			if	((typeof(oData) == 'object')&& (oData.type != 'hidden'))
				{
				oData.focus();
				oData.value="";
				}
			 
			return(false);
			}
			 
		// Fevereiro
		if	(month == "02")
			{
			if	((isBissexto(year)==false) &&
				 (day > 28))
				{
				window.alert(sMsg);
				if	((typeof(oData) == 'object') && (oData.type != 'hidden'))
					{
					oData.focus();
					oData.value="";
					}
				return(false);
				}
			
			if	(day > 29)
				{
				window.alert(sMsg);
				if	((typeof(oData) == 'object')&& (oData.type != 'hidden'))
					{
					oData.focus();
					oData.value="";
					}
				return(false);
				}
			}

		// Abril, Junho, Setembro, Novembro
		if	(((month == "04") ||
			  (month == "06") ||
			  (month == "09") ||		
			  (month == "11")) &&
			 ((day <= "0")    ||
			  (day > "30")))
			{
			window.alert(sMsg);
			if	((typeof(oData) == 'object')&& (oData.type != 'hidden'))
				{
				oData.focus();
				oData.value="";
				}
			return(false);
			}

		return(true);
		}
}

function verifica_data_mes(oData) 
{
	date = oData.value;
	sMsg = 'Por favor, digite uma válida válida';
	
	if	((date.length < 7) && (date != ""))
		{
		window.alert('Por favor, digite uma data válida, formato aceito: mm/aaaa.');
		if	((typeof(oData) == 'object') && (oData.type != 'hidden'))
			{
			oData.focus();
			oData.value="";
			}
		return(false);
		}

	if	(date != "") 
		{
		if	(date.indexOf(""))
			{
			alert("aqui")
			// se houver menos que duas barras caia fora
			window.alert('Por favor, digite uma data válida, formato aceito: mm/aaaa.');
			if	((typeof(oData) == 'object') && (oData.type != 'hidden'))
				{
				oData.focus();
				oData.value="";
				}
			return(false);
			}

		
		month=date.substr(0,date.indexOf("/")) 
		year =date.substr(date.lastIndexOf("/")+1,date.length-date.lastIndexOf("/")-1)
		if	( isNaN(month) || isNaN(year)) 
			{
			window.alert('Por favor, digite uma data válida, formato aceito: mm/aaaa.');
			if	((typeof(oData) == 'object') && (oData.type != 'hidden'))
				{
				oData.focus();
				oData.value="";
				}
			return(false);
			}
			
		if	(month<1 || month>12 || year<1800 || year>2200) 
			{
			window.alert('Por favor, digite uma data válida, formato aceito: mm/aaaa.');
			if	((typeof(oData) == 'object') && (oData.type != 'hidden'))
				{
				oData.focus();
				oData.value="";
				}
			return(false);
			}

						 
	}
}



function verifica_hora(horae) 
{
	hora = horae.value;
	sMsg = 'Por favor, digite um horário válido, formato aceito: 00h - 23h';
	
	if	((hora.length < 8) && (hora != ""))
		{
//		window.alert(sMsg + '1');
		window.alert(sMsg);
		if	((typeof(horae) == 'object') && (horae.type != 'hidden'))
			{
			horae.focus();
			horae.value="";
			}
		return(false);
		}

	if	(hora != "") 
		{
		if	(hora.indexOf(":")==hora.lastIndexOf(":"))
			{
			// se houver menos que duas barras caia fora
//			window.alert(sMsg + '2');
			window.alert(sMsg);
			if	((typeof(horae) == 'object') && (horae.type != 'hidden'))
				{
				horae.focus();
				horae.value="";
				}
			return(false);
			}

		horas  =hora.substr(0,hora.indexOf(":"))
		minutos=hora.substr(hora.indexOf(":")+1,hora.lastIndexOf(":")-hora.indexOf(":")-1)
		segundos =hora.substr(hora.lastIndexOf(":")+1,hora.length-hora.lastIndexOf(":")-1)

		if	(isNaN(horas) || isNaN(minutos) || isNaN(segundos)) 
			{
	//		window.alert(sMsg + '3');
			window.alert(sMsg);	
			if	((typeof(horae) == 'object') && (horae.type != 'hidden'))
				{
				horae.focus();
				horae.value="";
				}
			return(false);
			}
			
		if	(horas>23 || minutos>59 || segundos>59) 
			{
//			window.alert(sMsg + '4');
			window.alert(sMsg);
			if	((typeof(horae) == 'object') && (horae.type != 'hidden'))
				{
				horae.focus();
				horae.value="";
				}
			return(false);
			}
		return(true);
		}
}





function verifica_email(field) {

// Note: The next expression must be all on one line...
//       allow no spaces, linefeeds, or carriage returns!
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

if (goodEmail){
   good = true
   return true;
} else {
   alert('Favor entrar com um endereço de e-mail válido!')
   field.focus()
   field.select()
   good = false
   return false;
   }
}

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function


function verifica_cpf(CPF){
	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
		CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
		CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
		CPF == "88888888888" || CPF == "99999999999")
		return false;
	soma = 0;
	for (i=0; i < 9; i ++)
		soma += parseInt(CPF.charAt(i)) * (10 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(9)))
		return false;
	soma = 0;
	for (i = 0; i < 10; i ++)
		soma += parseInt(CPF.charAt(i)) * (11 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(10)))
		return false;
	return true;
}



function valida_data_composta(dia, mes, ano){
	if ((dia.value > 0) && (dia.value < 31)){
		if ((mes.value > 0) && (mes.value < 12)){
			if (ano.value > 0){
				return true;
			}
		}
	}
	alert('Favor preencher com uma data correta!');
	return false;
}

function verifica_vazio(campo, nome_campo){
	if (campo.value == ''){
		alert('O campo ' + nome_campo + ' não pode ser vazio!');
		campo.focus();
		return false;		
	}
	else
	{
		return true;
	}
}


function formata_data(argumento){
	if (argumento.value.length == 2){
		argumento.value = argumento.value + '/';
	}
	if (argumento.value.length == 5){
		argumento.value = argumento.value + '/';
	}
}
function formata_da_mes_ano(argumento){
    if (argumento.value.length == 2){
		argumento.value = argumento.value + '/';
	}
}


function formata_hora2(argumento){
	if (argumento.value.length == 2){
		argumento.value = argumento.value + ':';
	}
	if (argumento.value.length == 5){
		argumento.value = argumento.value + ':';
	}
}


function formata_hora(argumento){
	if (argumento.value.length == 2){
		argumento.value = argumento.value + ':';
	}
}


function formata_cpf(argumento){

	if (argumento.value.length == 3){
		argumento.value = argumento.value + '.';
	}
	if (argumento.value.length == 7){
		argumento.value = argumento.value + '.';
	}
	if (argumento.value.length == 11){
		argumento.value = argumento.value + '-';
	}
}


function formata_cep(argumento){
	if (argumento.value.length == 5){
		argumento.value = argumento.value + '-';
	}
}

function verifica_email(campo)
{
	var EmailOk  = true
	var AtSym    = campo.value.indexOf('@')
	var Period   = campo.value.lastIndexOf('.')
	var Space    = campo.value.indexOf(' ')
	var Length   = campo.value.length - 1   // Array is from 0 to length-1

	if ((AtSym < 1) ||                     // '@' cannot be in first position
	    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
	    (Period == Length ) ||             // Must be atleast one valid char after '.'
	    (Space  != -1))                    // No empty spaces permitted
	   {
	      EmailOk = false;
	      window.alert('Por favor, o endereço de e-mail digitado está incorreto.');
	      campo.value = "";
          campo.focus()
	   }
	return EmailOk
}


			
function maiusculo(argumento){
	argumento.value = toUpperCase(argumento.value);
}


function popup(janela)
{
	var popup_window;
	popup_window = window.open(janela,"Selecione","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=300,height=320,left=105,top=90");
}

function popupKIT(janela)
{
	var popup_window;
	popup_window = window.open(janela,"Selecione","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=600,height=640,left=105,top=90");
}

function formata_cnpj(argumento){
	if (argumento.value.length == 2){
		argumento.value = argumento.value + '.';
	}
	if (argumento.value.length == 6){
		argumento.value = argumento.value + '.';
	}
	if (argumento.value.length == 10){
		argumento.value = argumento.value + '/';
	}
	if (argumento.value.length == 15){
		argumento.value = argumento.value + '-';
	}						
}


function verifica_cnpj(argumento){
/*	if (TESTA(argumento,'CNPJ')){
	}
	else
	{
		alert('O campo CNPJ está inválido!');
		return false;
	}*/
}

function isNUMB(c)
{
if((cx=c.indexOf(","))!=-1)
{
c = c.substring(0,cx)+"."+c.substring(cx+1);
}
if((parseFloat(c) / c != 1))
{
if(parseFloat(c) * c == 0)
{
return(1);
}
else
{
return(0);
}
}
else
{
return(1);
}
}

function LIMP(c)
{
while((cx=c.indexOf("-"))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf("/"))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf(","))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf("."))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf("("))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf(")"))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
while((cx=c.indexOf(" "))!=-1)
{
c = c.substring(0,cx)+c.substring(cx+1);
}
return(c);
}

function VerifyCNPJ(CNPJ)
{
CNPJ = LIMP(CNPJ);
if(isNUMB(CNPJ) != 1)
{
return(0);
}
else
{
if(CNPJ == 0)
{
return(0);
}
else
{
g=CNPJ.length-2;
if(RealTestaCNPJ(CNPJ,g) == 1)
{
g=CNPJ.length-1;
if(RealTestaCNPJ(CNPJ,g) == 1)
{
return(1);
}
else
{
return(0);
}
}
else
{
return(0);
}
}
}
}
function RealTestaCNPJ(CNPJ,g)
{
var VerCNPJ=0;
var ind=2;
var tam;
for(f=g;f>0;f--)
{
VerCNPJ+=parseInt(CNPJ.charAt(f-1))*ind;
if(ind>8)
{
ind=2;
}
else
{
ind++;
}
}
VerCNPJ%=11;
if(VerCNPJ==0 || VerCNPJ==1)
{
VerCNPJ=0;
}
else
{
VerCNPJ=11-VerCNPJ;
}
if(VerCNPJ!=parseInt(CNPJ.charAt(g)))
{
return(0);
}
else
{
return(1);
}
}

function formata_moeda(campo){
		if (isNaN(campo.value)){
			alert('Insira um valor de moeda válido!');
			campo.focus();
			campo.select();
			return false;
		}
		campo.value = replaceSubstring(campo.value, ',', '.');
		if ((campo.value.indexOf('.') == '-1') && (campo.value.length > 0)){
				campo.value = campo.value + '.00';
		}
		if (campo.value.indexOf('.') == (campo.value.length - 2)){
			campo.value = campo.value + '0';
		}
		if (campo.value.indexOf('.') == (campo.value.length - 1)){
			campo.value = campo.value + '00';
		}
		return true;
}

function formata_moeda_especial(campo){
		var legenda = document.getElementById("botao_salvar");

		if (isNaN(campo.value)){
			alert('Insira um valor de moeda válido!');
			campo.focus();
			campo.select();
			legenda.innerHTML = 'Entre com um valor de moeda válido e pressione TAB após a confirmação';
			return false;
		}
		campo.value = replaceSubstring(campo.value, ',', '.');
		if ((campo.value.indexOf('.') == '-1') && (campo.value.length > 0)){
				campo.value = campo.value + '.00';
		}
		if (campo.value.indexOf('.') == (campo.value.length - 2)){
			campo.value = campo.value + '0';
		}
		if (campo.value.indexOf('.') == (campo.value.length - 1)){
			campo.value = campo.value + '00';
		}
		legenda.innerHTML = '<a href="#" onclick="javascript:postar_valor();"><img src="images/save.gif" width="16" height="16" border="0"></a>';	
		return true;
}

function formata_telefone(campo){
		if (campo.value.length == 1){
    	campo.value = '(' + campo.value;
		}
    if (campo.value.length == 3){
			campo.value = campo.value + ')';
		}
		if (campo.value.length == 8){
			campo.value = campo.value + '-';
		}
}

function formatabbcampo(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;1
	vr = 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 ){ 
	 		campo.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, 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 - 2, 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 - 2, 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 ) ;}
	}
/*
	for (var ct = 0; ct < document.formu.elements.length; ct++) {
		if (document.formu.elements[ct].name == document.formu.elements[campo].name) {
			if ( !teclapres.shiftKey && tecla == 9 && document.formu.elements[ct+1] && document.formu.elements[ct+1].name == "senhaConta" && document.applets['tclJava'] ){
				document.applets['tclJava'].setFocus();
			}	
		}
	}*/
}

function formatabbcampo2(campo,tammax) {
//	var tecla = teclapres.keyCode;1
	vr = 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 ){ 
	 		campo.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, 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 - 2, 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 - 2, 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 ) ;}
//	}
/*
	for (var ct = 0; ct < document.formu.elements.length; ct++) {
		if (document.formu.elements[ct].name == document.formu.elements[campo].name) {
			if ( !teclapres.shiftKey && tecla == 9 && document.formu.elements[ct+1] && document.formu.elements[ct+1].name == "senhaConta" && document.applets['tclJava'] ){
				document.applets['tclJava'].setFocus();
			}	
		}
	}*/
}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
//return (((sign)?'':'-') + '$' + num + '.' + cents);
valor =  String( (((sign)?'':'-') + num + '.' + cents) );
//alert(valor);
valor = valor.replace(".","A");
valor = valor.replace(/\,/g,'.');
valor = valor.replace("A",",");
//alert(valor);
return valor;
}

function checaemail(campo) {
	email = campo.value;
	var regex = new RegExp("^[a-zA-Z]+[a-zA-Z0-9_\.\-]*@[a-zA-Z0-9\.\-]+[\.]+(edu|org|com|net|biz|info|gov|web|[a-zA-Z]{2})$","i");	
	if (!regex.test(email) && email != "") {
		alert("Erro! Email Inválido.");
		campo.focus();
		return false;
	}
	return true;
}
