//-------------------------- PRE-FUNÇÕES ------------------------------

function stringReplace(originalString, findText, replaceText) 
{ 
  var pos = 0;
		var len = findText.length;
		originalString = originalString.toString();
		
		pos = originalString.indexOf(findText);
  while (pos != -1) 
  {
    preString  = originalString.substring(0, pos);
    postString = originalString.substring(pos + len, originalString.length);
    originalString = preString + replaceText + postString;
    pos = originalString.indexOf(findText);
  }

		return originalString;
}

function selecao_ok(form_desvio,campo1,campo2)
{
		var i=0;
		var total=0;
		var indice=0;		
		var retorno=0;
		total =	eval("document.form_desvio."  + campo1 + ".value");
		for (i=0;i<total;i++){
				if (total==1){
						linha	=	eval("document.form_desvio." + campo2);
						if (linha.checked){
								retorno = i + 1;
						}
				}
				else{
						linha	=	eval("document.form_desvio." + campo2 + "[" + i + "].checked");
						if (linha==true){
								retorno = i + 1;
						}
				}				
		}		
		return retorno;
}

//--------------------------- VALIDAÇÕES -------------------------------

// Valida se o valor passado é um número.
// Passar um string com apenas o valor.
// ex: IsDate('12/03/2002','DD/MM/YYYY')
// ex: IsDate('03/2002','MM/YYYY')
//
function IsDate(valor,tipo)
{
	var data, dia="", mes="", ano="";
	tipo = tipo.toUpperCase();
	if (tipo=='DD/MM/YYYY') 
	{	
		dia = valor.substr(0,2);
		mes = valor.substr(3,2);
		ano = valor.substr(6,4);
	}
	else if (tipo == 'MM/YYYY') 
	{
		dia = '01';
		mes = valor.substr(1,2);
		ano = valor.substr(3,4);
	}	 
	if ( !ValidaInfo(dia,'DD') ||
		 !ValidaInfo(mes,'MM') )
		return false;
	return true;
}

function ValidaInfo(valor,tipo){
	
	tipo = tipo.toUpperCase();
	nvalor = parseInt(valor);
	
	// DIA
	if ( tipo == 'DD' )
	{
		if (nvalor > 31)
			return false;
	}
	// MES
	else if ( tipo == 'MM' )
	{
		if (nvalor > 12)
			return false;
	}
  // ANO
	else if (tipo == 'YYYY' )
	{
		if (nvalor < 1900)
			return false;
	}

	// HH
	else if ( tipo == 'HH' )
	{
		if (nvalor > 23)
			return false;
	}
	// MINUTO
	else if ( tipo == 'MI' )
	{
		if (nvalor > 59)
			return false;
	}
	return true;
}

/*
Rotina para validar o PIS/PASEP
para chamar basta:
retorno = valida_pis_pasep('nome_campo');
*/
function valida_pis_pasep(strCampo)
{
	var FTAP;
	var TOT;
	var I;
	
	campo = eval("document.form_desvio." + strCampo);
	
	if (parseFloat(campo.value) == 0)
		return false;
	
	if (campo.value.length != 11)
		return false;
	
	FTAP = "3298765432";
	TOT = 0;
		
	for (I=0;I<10;I++)
		{
//	    TOT = TOT + parseInt(campo.value.substring(I,1)) * parseInt(FTAP.substring(I,1));
	    TOT = TOT + parseInt(campo.value.substr(I,1)) * parseInt(FTAP.substr(I,1));
//		alert (parseInt(campo.value.substr(I,1)));
//		alert (parseInt(FTAP.substr(I,1)));
		}
		
	RESTO = parseInt(TOT % 11);
	
	if (RESTO != 0)
		RESTO = 11 - RESTO;
	if (((RESTO == 10) || (RESTO == 11)) && parseInt(campo.value.substr(10,1))==0)
	   return true;
	else 
	
	if (RESTO != parseInt(campo.value.substr(10,1)))
	   return false;
	
	return true;
}

// Preenche o valor com zeros até o tamnho especificado.
//
// Ex: 
// completaZeros('352', 6) 
// Retorna : '000352'
//
function completaZeros(campo, tamanho){

	valor		= campo.value;
	diferenca	= parseInt(tamanho - valor.length);
	complemento = new String("");
	
	if (diferenca > 0)
		for(i=1;i<=diferenca;i++)
			complemento = complemento + "0";
	
	campo.value = complemento.concat(valor);
}

// Somente numeros e caracteres (maiusculos ou minusculos), 
// qualquer outro caracter é rejeitado.
// Evento a ser utilizado: onChange
// Parâmetro: objeto-campo do formulário
function IsAlfaNum(campo){

 var cod_chave;
 
 for (var i=0; i < campo.value.length; i++)
 {	
    cod_chave = campo.value.charCodeAt(i);
	   if ( (cod_chave < '48' || cod_chave > '57')  &&
	        (cod_chave < '65' || cod_chave > '90')  &&
	        (cod_chave < '97' || cod_chave > '122') &&
	        (cod_chave < '192' || cod_chave > '196') &&
	        (cod_chave < '199' || cod_chave > '207') &&
	        (cod_chave < '210' || cod_chave > '214') &&
	        (cod_chave < '217' || cod_chave > '220') &&
	        (cod_chave < '224' || cod_chave > '228') &&
	        (cod_chave < '231' || cod_chave > '239') &&
	        (cod_chave < '242' || cod_chave > '246') &&
	        (cod_chave < '249' || cod_chave > '252') ) 
	   {
	   	return false;
	   }
 }
 
	return true;
}

// Valida se o valor passado é um número.
// Passar um string com apenas o valor.
// ex: IsNumeric('123,99')
function IsNumeric(valor)
{
	for (var i=0; i < valor.length; i++)
	{
		if (!parseFloat(valor.charAt(i)))
		{
			if(valor.charAt(i) != '0')
			{
				if(valor.charAt(i) != ',')
				{
					return false;
					break;
				}	// if(valor.charAt(i) != ',')
			}	// if(valor.charAt(i) != '0')
		}	// if (!parseFloat(valor.charAt(i)))
	}	// for (var i=0; i < valor.length; i++)
	return true;
}

function validarNumero(objNumero){

    if (document.all) // Internet Explorer
    	var tecla = event.keyCode;
    else if(document.layers) // Nestcape
    	var tecla = objNumero.which;

    if (tecla > 47 && tecla < 58) // numeros de 0 a 9
        return true;
    else
       {
           if (tecla != 8) // backspace
              event.keyCode = 0;
              //return false;
           else
              return true;
       }
}

/*
Valida se o valor numérico informado está dentro da Precisão do Oracle
Ex: 
    ValidaPrecisaoNumero('3256,958', ',', 5, 2) 
    Retorna : false
    ValidaPrecisaoNumero('625,74', ',', 5, 2) 
    Retorna : true
*/
function ValidaPrecisaoNumero(vValor, vSeparador, vTamOracle, vDecOracle) {

    var contador = 0;
	var tamanho = 0;
	var pos_separador = 0;
	var nInteiros = 0;
	var nDecimais = 0;
	
	if (!IsNumeric(vValor)){
	   alert("Valor não numérico!");
	   return false;
	}   
	
	pos_separador = vValor.indexOf(vSeparador);

	tamanho = vValor.length;	
	
	// Acha os Inteiros e os Decimais do valor informado
	if (pos_separador == -1)
	{
		nInteiros = tamanho;
	}
	else
	{
		nInteiros = pos_separador;
		nDecimais = tamanho - (nInteiros + 1);
	}	

	// Converte a precisão para saber o numero de casas inteiras e 
	// e decimais que o campo suporta.
	nMaxInteiros = parseInt(vTamOracle) - parseInt(vDecOracle);
	nMaxDecimais = parseInt(vDecOracle);
	
	/*
	alert("vValor [" + vValor + "]\n" + 
		  "vSeparador [" + vSeparador + "]\n" + 
		  "tamanho [" + String(tamanho) + "]\n" + 
	      "pos_separador [" + String(pos_separador) + "]\n" + 
	      "nInteiros [" + String(nInteiros) + "]\n" + 
	      "nDecimais [" + String(nDecimais) + "]\n" + 
	      "nMaxInteiros [" + String(nMaxInteiros) + "]\n" + 
	      "nMaxDecimais [" + String(nMaxDecimais)+ "]\n" +
	      "vDecOracle ["+ vDecOracle + "]\n" +
	      "vTamOracle ["+ vTamOracle + "]");
	*/

	// Valida a parte Inteira
	if (nMaxInteiros < nInteiros)
	{
		alert("Número de casas inteiras inválida !!");
		return false;
	}
		
	// Valida a parte Decimal
	if (nMaxDecimais < nDecimais)
	{
		alert("Número de casas decimais inválida !!");
		return false;
	}		
	return true;
}

function validacao_numero_troca(form_desvio,elemento) {
      var elem = stringReplace(elemento.value,",",".")
      for (var i=0; i<elem.length; i++) {
         if (!parseFloat(elem.charAt(i))) {
           if(elem.charAt(i) != '0') {
             if(elem.charAt(i) != '.') {
		        return false;
		        break;
             }	
           }
         }
      }        
      return true;
}

function validarHora(strHora){

	strHora = new String(strHora);

	horas = strHora.substr(0,2);
	minutos = strHora.substr(3,2);
	doispontos = strHora.substr(2,1);
	
	if (strHora == ''){
		return true;
	}

	if (strHora.length != 5 || strHora == 'hh:mm'){
		return false;
	}
	
	if (doispontos != ':') {
                return false;
	}
	
	// not a number
	if(isNaN(horas % 2) || isNaN(minutos % 2)){
		return false;
	}

	if(horas > 23){
		return false;
	}

	if(minutos > 59){
		return false;
	}

	return true;
}

function verHora(odjHora){
	if(validarHora(odjHora.value) == false){
		alert('Esta não é uma hora válida.\nDigite a hora no formato: HH:MM');
		odjHora.focus();
		odjHora.select();
	}
}

function verData(odjData){
	if(validarData(odjData.value) == false){
		alert('Esta não é uma data válida.\nDigite a data no formato: DD/MM/AAAA');
		odjData.focus();
		odjData.select();
	}
}

function validacao_texto(form_desvio,elemento) {
      
   if (elemento.value == "") {
      return false;
   }
   return true;
}

function validacao_numero(form_desvio,elemento) {
   elemento1 = elemento.value
   for (var i=0; i<elemento1.length; i++){
      if (!parseFloat(elemento1.charAt(i))){
        if(elemento1.charAt(i) != '0') {
          if(elemento1.charAt(i) != '.') {
 			return false;
 			break;
          }
        }
      }
   }
   return true;
}

function validacao_numero2(form_desvio,elemento) {
      
   for (var i=0; i<elemento.value.length; i++) {
      if (!parseFloat(elemento.value.charAt(i))) {
        if(elemento.value.charAt(i) != '0') {
 			          return false;
 			          break;
        }
      }
   }        
   return true;
}


function valida_caracteres_invalidos(form_desvio,elemento) {
 	var campo="";
 	var invalidChars="";
 	var badChar="";
     invalidChars="'";
 	campo=elemento.value;
      for (i=0; i<invalidChars.length; i++) {
         badChar = invalidChars.charAt(i);
         if (campo.indexOf(badChar,0) > -1) {
            return false;
         }
      }
   return true;
}

function validarData(strData){

	strData = new String(strData);

	dia = strData.substr(0,2);
	mes = strData.substr(3,2);
	ano = strData.substr(6,4);

	if (strData == ''){
		return true;
	}

	if (strData.length != 10 || strData == 'dd/mm/aaaa'){
		return false;
	}
	
	if ((strData.substr(2,1) != '/') || (strData.substr(5,1) != '/')) {
                return false;
	}
	
	
	var Dias_Mes = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	if (mes == '02') {
	   if ((ano % 400 == 0) || ((ano % 4 == 0) && (ano % 100 != 0))) {
	      Dias_Mes[1] = 29;
	   }
	}

	// not a number
	if(isNaN(dia % 2) || isNaN(mes % 2) || isNaN(ano % 2)){
		return false;
	}

	I = mes - 1;
	
	if(I < 0 || I > 11){
		return false;
	}

	if( (dia < 0 || dia > Dias_Mes[I])  ){
		return false;
	}else{
		return true;
	}
}
/*
function validarData2(strData){

	strData = new String(strData);

	dia = strData.substr(0,2);
	mes = strData.substr(3,2);
	ano = strData.substr(6,4);

	if (strData == ''){
		return true;
	}

	if (strData.length != 10 || strData == 'dd/mm/aaaa'){
		return false;
	}
	
	if ((strData.substr(2,1) != '.') || (strData.substr(5,1) != '.')) {
                return false;
	}
	
	
	var Dias_Mes = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	if (mes == '02') {
	   if ((ano % 400 == 0) || ((ano % 4 == 0) && (ano % 100 != 0))) {
	      Dias_Mes[1] = 29;
	   }
	}

	// not a number
	if(isNaN(dia % 2) || isNaN(mes % 2) || isNaN(ano % 2)){
		return false;
	}

	I = mes - 1;
	
	if(I < 0 || I > 11){
		return false;
	}

	if( (dia < 0 || dia > Dias_Mes[I])  ){
		return false;
	}else{
		return true;
	}
}
*/
//Antiga Função de Validar data
function validacao_data2(form_desvio,elemento) 
{

   var tam=(elemento.value.length);
   var dia="", mes="", ano="", barra1="", barra2="";

   if (tam > 10) {
      return false;
   }
   for (var i=0; i<tam; i++) {
      if (i < 2) { 
        dia=(dia + elemento.value.charAt(i)); 
      }
      if (i == 2) {
         barra1=(elemento.value.charAt(i)); 
      }
      if ((i > 2) && (i < 5)) {
         mes=(mes + elemento.value.charAt(i)); 
      }
      if (i == 5) {
         barra2=(elemento.value.charAt(i)); 
      }
      if (i > 5) {
         ano=(ano + elemento.value.charAt(i)); 
      }
   }
   if (eval((dia == 0) || (mes == 0) || (ano == 0))) {
      return false;
   } 
   if (eval((parseFloat(mes) == 02) && (parseFloat(dia) > 29))) {
      return false;
   }

   if (eval((parseFloat(mes) == 04)  && (parseFloat(dia) > 30))) {
      return false;
   }
   if (eval((parseFloat(mes) == 06)  && (parseFloat(dia) > 30))) {
      return false;
   }
   if (eval((parseFloat(mes) == 09)  && (parseFloat(dia) > 30))) {
      return false;
   }
   if (eval((parseFloat(mes) == 11)  && (parseFloat(dia) > 30))) {
      return false;
   }
   if (eval(parseFloat(dia) > 31)) {
      return false;
   }
   if (eval(parseFloat(mes) > 12)) {
      return false;
   }
   if (eval(parseFloat(ano) < 1900)) {
      return false;
   }
   if (barra1 != "/") {
      return false;
   }
   if (barra2 != "/") {
      return false;
   }
   for (var i=0; i<dia.length; i++) {
      if (!parseFloat(dia.charAt(i))) {
        if(dia.charAt(i) != '0') {
          return false;
          break;
        }
      }
   }        
   for (var i=0; i<mes.length; i++) {
      if (!parseFloat(mes.charAt(i))) {
        if(mes.charAt(i) != '0') {
          return false;
          break;
        }
      }
   }        
   for (var i=0; i<ano.length; i++) {
      if (!parseFloat(ano.charAt(i))) {
        if(ano.charAt(i) != '0') {
          return false;
          break;
        }
      }
   }        
   return true;
}

//Valida a data, verificando inclusive se é ano bisexto
function validacao_data(form_desvio,elemento) 
{   
   var campo    = elemento.value;
                  
   var retorno  = 0;
   var maiorDia = 0;
                    
   var dd       = campo.slice(0,2);
   var mm       = campo.slice(3,5);
   var yyyy     = campo.slice(6,10);
                  
   var barra1   = campo.slice(2,3);
   var barra2   = campo.slice(5,6);
                    
   if((mm == 4) || (mm == 6) || (mm == 9) || (mm == 11))
     { 
      maiorDia = 30;
     }
   else if(mm == 2)
     {
      maiorDia = (yyyy % 4 == 0) ? 29 : 28;    
     }
   else
     {
      maiorDia = 31;
     }
   
   if ((barra1 != "/") || (barra2 != "/"))
    {
      retorno = 1;
    }
   if((dd <= 0) || (dd > maiorDia))
    { 
      retorno = 1;
    }
   else if((mm <= 0) || (mm > 12))
    { 
      retorno = 1;
    }
   else if((yyyy < 1900) )
    { 
      retorno = 1;
    } 
   if(retorno == 1)
   { 
     return false;
   }
   else
   { 
      return true;
   }
}

function validacao_data_mes_ano(form_submit,elemento){

   var tam=(elemento.value.length);
   var mes="", ano="", barra1="";
   if (tam > 7) {
      return false;
   }
   for (var i=0; i<tam; i++) {
      if (i < 2) { 
        mes=(mes + elemento.value.charAt(i)) }
      if (i == 2) {
         barra1=(elemento.value.charAt(i)) }
      if (i > 2) {
         ano=(ano + elemento.value.charAt(i)) }
   }       
   if (eval((mes == 0) || (ano == 0))) {
      return false;
   } 
   if (parseInt(mes) > 12) {
      return false;
   }
   if (parseInt(ano) < 1900) {
      return false;
   }
   if (barra1 != "/") {
      return false;
   }
     
   for (var i=0; i<mes.length; i++) {
      if (!parseFloat(mes.charAt(i))) {
        if(mes.charAt(i) != '0') {
          return false;
          break;
        }
      }
   }        
   for (var i=0; i<ano.length; i++) {
      if (!parseFloat(ano.charAt(i))) {
        if(ano.charAt(i) != '0') {
          return false;
          break;
        }
      }
   }        
   return true;
}

function validExclusao(form_desvio) {
	
 	ok=confirm("Confirma a Exclusão?");
 	if (ok == false) {
 	   return false;
 	}
 	if (ok == true) {
 		document.form_desvio.onsubmit="";
 		document.form_desvio.submit();
 	}	
 }

function isCPF(st){

	st2 = "";

	if (st == "")
	{
	  return false;
	}
	
	cnpjO = stringReplace(st,".","");
	cnpjO = stringReplace(cnpjO,"/","");
	cnpjO = stringReplace(cnpjO,"-","");

	st = cnpjO;
	if ((st == '11111111111') ||
          (st == '22222222222') ||
          (st == '33333333333') ||
          (st == '44444444444') ||
          (st == '55555555555') ||
          (st == '66666666666') ||
          (st == '77777777777') ||
          (st == '88888888888') ||
          (st == '99999999999') ||
          (st == '00000000000') ) 
	{
	  return false;
	}
	
		
	l = st.length;

	for (i = 0; i < l; i++) {
	  caracter = st.substring(i,i+1);
	  if ((caracter >= '0') && (caracter <= '9'));
	     st2 = st2 + caracter;
	}
	if ((st2.length > 11) || (st2.length < 10)) {
	   return false;
	}   
	if (st2.length==10) {
	   st2 = '0' + st2;
	}   
	digito1 = st2.substring(9,10);
	digito2 = st2.substring(10,11);
	digito1 = parseInt(digito1,10);
	digito2 = parseInt(digito2,10);
	sum = 0; mul = 10;
	for (i = 0; i < 9 ; i++) {
	    digit = st2.substring(i,i+1);
	    tproduct = parseInt(digit ,10) * mul;
	    sum += tproduct;
	    mul--;
	}
	dig1 = ( sum % 11 );
	if ( dig1==0 || dig1==1 ) {
	   dig1=0;
	} else {
	  dig1 = 11 - dig1;
	}  
	if (dig1!=digito1) {
	  return false;
	}  


	sum = 0;
	mul = 11;
	for (i = 0; i < 10 ; i++) {
	    digit = st2.substring(i,i+1);
	    tproduct = parseInt(digit ,10)* mul;
	    sum += tproduct;
	    mul--;
	}
	dig2 = (sum % 11);
	if ( dig2==0 || dig2==1 ) {
	  dig2=0;
	} else {
	  dig2 = 11 - dig2;  
	}  
	if (dig2 != digito2) {
	  return false;
	}  
	return true;
}
  
function isCGC(x) {
	strNum = "";  
	if (x == "") {
	  return false;
	}
	cnpjO = stringReplace(x,".","");
	cnpjO = stringReplace(cnpjO,"/","");
	cnpjO = stringReplace(cnpjO,"-","");

	x = cnpjO;
	
	//alert(x);

	l = x.length;
	for (i = 0; i < l; i++) {
	  caracter = x.substring(i,i+1)
	  if ((caracter >= '0') && (caracter <= '9'))
	     strNum = strNum + caracter;
	}
      
	strMul = "6543298765432";
	iValido = 1;
	if(strNum.length != 14) 
	    return(false);
	iSoma = 0;
	strNum_base = strNum.substring(0,12); 
	iLenNum_base = strNum_base.length - 1;
	iLenMul = strMul.length - 1;
	for(i = 0;i < 12; i++)
	   iSoma = iSoma +
	parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
	parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10)
	iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
	if(iSoma == 11 || iSoma == 10)
	  iSoma = 0;
	strNum_base = strNum_base + iSoma; 
	iSoma = 0;
	iLenNum_base = strNum_base.length - 1
	for(i=0; i < 13; i++)
	   iSoma = iSoma +
	parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
	parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10)
	iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
	if(iSoma == 11 || iSoma == 10)
	  iSoma = 0;
	strNum_base = strNum_base + iSoma; 
	if(strNum != strNum_base)
	  return(false);
	return(true);
}

function validarEmail(campo){
if (campo.value == ""){
		alert("O e-mail deve ser informado.");
		return "false";
	} 
	else{
		prim = campo.value.indexOf("@");
		if(prim < 2){	
			alert("O e-mail nao esta correto.");
			return "false";
		}
		if(campo.value.indexOf("@",prim + 1) != -1){
			alert("O e-mail nao esta correto.");
			return "false";
		}
		if(campo.value.indexOf(".") < 1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}		
		if(campo.value.indexOf("!") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}				
		if(campo.value.indexOf("¹") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}						
		if(campo.value.indexOf("²") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}				
		if(campo.value.indexOf("#") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}				
		if(campo.value.indexOf("³") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}				
		if(campo.value.indexOf("$") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}				
		if(campo.value.indexOf("£") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}				
		if(campo.value.indexOf("%") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}						
		if(campo.value.indexOf("¢") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}						
		if(campo.value.indexOf("¨") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}						
		if(campo.value.indexOf("¬") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}						
		if(campo.value.indexOf("&") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}						
		if(campo.value.indexOf("*") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}						
		if(campo.value.indexOf("(") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}						
		if(campo.value.indexOf(")") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}						
		if(campo.value.indexOf("=") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}						
		if(campo.value.indexOf("+") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}						
		if(campo.value.indexOf("§") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}						
		if(campo.value.indexOf("]") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}						
		if(campo.value.indexOf("}") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}						
		if(campo.value.indexOf("º") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}								
		if(campo.value.indexOf("´") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}								
		if(campo.value.indexOf("`") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}								
		if(campo.value.indexOf("[") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}								
		if(campo.value.indexOf("{") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}								
		if(campo.value.indexOf("ª") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}								
		if(campo.value.indexOf("ç") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}								
		if(campo.value.indexOf("~") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}								
		if(campo.value.indexOf("^") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}								
		if(campo.value.indexOf("|") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}								
		if(campo.value.indexOf(",") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}								
		if(campo.value.indexOf("<") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}										
		if(campo.value.indexOf(">") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}
		if(campo.value.indexOf("..") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}												
		if(campo.value.indexOf(";") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}										
		if(campo.value.indexOf(":") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}										
		if(campo.value.indexOf("/") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}										
		if(campo.value.indexOf("?") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}										
		if(campo.value.indexOf("°") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}										
		if(campo.value.indexOf(" ") != -1){
	  		alert("O e-mail nao esta correto.");
			return "false";
		}	
		if(campo.value.indexOf(".@") > 0){
			alert("O e-mail nao esta correto.");
			return "false";
		}
		if(campo.value.indexOf("@.") > 0){
			alert("O e-mail nao esta correto.");
			return "false";
		}
		if(campo.value.indexOf(".br.") > 0){
			alert("O e-mail nao esta correto.");
			return "false";
		}
		if(campo.value.indexOf(".",campo.value.length -2) > 0){
			alert("O e-mail nao esta correto.");
			return "false";
		}
	}
   return true;
}

//--------------------------- FUNÇÕES COM NUMEROS -------------------------------

function conta_numero_apos_virgula(elemento) {
	snumero = "";
	for (var i=0; i<elemento.length; i++) {
      if (elemento.charAt(i) == '.') {
	       var x = i;
	       var t = parseFloat(elemento.length - x);
      }  	
	}
	return t;
}

/* 
  Objetivo:  Truncar um valor (pNumero) pelo número de casas decimais (Casas) informado.
             Preencher com zeros as casas decimais pelo número de casas decimais (Casas) informado.
  Exemplo 1: arredonda(984.9876,2)
  Resultado: 984.98
  
  Exemplo 2: arredonda(984.9,2)
  Resultado: 984.90

  Exemplo 3: arredonda(984,2)
  Resultado: 984.00
*/
function arredonda(pNumero,Casas)
{
	var numero_round = "";
	var strNumero = pNumero.toString();
	var bol_negativo=false;
	var bol_tem_ponto=false;
	var strDecimal = "";
	var strDecimal_Fmt = "";
	var i = 0;
	
	if (pNumero < 0)
	{
	  pNumero = pNumero * -1.00;
	  strNumero = pNumero.toString();
	  bol_negativo=true;
	}		
	
	var nPonto = strNumero.indexOf(".");
	
	if (nPonto == -1)
	{
	 	numero_round  = strNumero + ".00";		
	 	bol_tem_ponto = true;
	}
	else
	{
    numero_round = strNumero.substr(0,nPonto + Casas + 1);
	 	numero_round = Math.round(1000*numero_round)/1000;
	 	strNumero  = numero_round.toString();
	 	strInteiro = strNumero.substr(0,nPonto);
	 	strDecimal = strNumero.substr(nPonto + 1,Casas);
	 	i = 0;
	 	while (i<Casas)
	 	{
	 	  if (strDecimal.charAt(i) == "")
	 	  {
	 	    strDecimal_Fmt = strDecimal_Fmt + "0";
	 	  }
	 	  else
	 	  {
	 	    strDecimal_Fmt = strDecimal_Fmt + strDecimal.charAt(i);
	 	  }
	 	  
	 	  i = i + 1;
	 	}
	 	numero_round = strInteiro + "." + strDecimal_Fmt;
	}
		
	if (bol_negativo==false)
	{
	  return numero_round;
	}
	else
	{
	  return "-" + numero_round;
	}
}

//---------------------- COMPARA DATAS ----------------------------

function comp_data2(form_desvio,data1,data2,formato,comparacao){ 
    // data1: valor
    // data2: valor
	// formato: 1. dia, mes, ano; 2. mes e ano
	// comparacao: ">="
	if ((data1 != "") && (data2 != ""))
	{
		var dia1 = "";
		var mes1 = "";
		var ano1 = "";
		var dia2 = "";
		var mes2 = "";
		var ano2 = "";
		var dc1 = "";
		var dc2 = "";

		for (var i = 0; i < data1.length; i++)
		{
			if (i < 2)
			{ 
				dia1 = (dia1 + (data1.charAt(i)));
			} 
			else 
			{
				if ((i > 2) && (i < 5)) 
				{
					mes1 = (mes1 + (data1.charAt(i)));
				} 
				else 
				{
					if (i > 5) 
					{
						ano1 = (ano1 + (data1.charAt(i)));
					}
				}
			}			
		}

		if (formato == 1)
		{
			dc1 = ( ano1 + mes1 + dia1 );
		}
		else
		{
			dc1 = ( ano1 + mes1 );
		}

		for (var i = 0; i < data2.length; i++)
		{
			if (i < 2)
			{ 
				dia2 = (dia2 + (data2.charAt(i)));
			} 
			else
			{
				if ((i > 2) && (i < 5))
				{
					mes2 = (mes2 + (data2.charAt(i)));
				} 
				else 
				{
					if (i > 5) 
					{
						ano2 = (ano2 + (data2.charAt(i)));
					}
				}
			}			
		}

		if (formato == 1)
		{
			  dc2 = ( ano2 + mes2 + dia2 );
		}
		else
		{
			dc2 = ( ano2 + mes2 );
		}
			
		expressao = eval("parseFloat(dc1) "+comparacao+" parseFloat(dc2)");

		if (expressao)
		{
			return true;
		}
	}
	return false;
}
	
function comp_data(form_desvio,data1,data2){ 
 var elemento1;
 var elemento2;
 elemento1 = eval("document.form_desvio." + data1 + ".value");
 elemento2 = eval("document.form_desvio." + data2 + ".value");
	if ((elemento1 != "") && (elemento2 != "")){
			var dia1 = "";
			var mes1 = "";
			var ano1 = "";
			var dia2 = "";
			var mes2 = "";
			var ano2 = "";
			var dc1 = "";
			var dc2 = "";
			for (var i = 0; i < elemento1.length; i++){
				if (i < 2){ 
					dia1 = (dia1 + (elemento1.charAt(i)));
				} 
				else {
					if ((i > 2) && (i < 5)) {
						mes1 = (mes1 + (elemento1.charAt(i)));
					} 
					else {
						if (i > 5) {
							ano1 = (ano1 + (elemento1.charAt(i)));
												
						}
					}
				}			
			}
			dc1 = ( ano1 + mes1 + dia1 );        
			for (var i = 0; i < elemento2.length; i++){
				if (i < 2){ 
					dia2 = (dia2 + (elemento2.charAt(i)));
				} 
				else{
					if ((i > 2) && (i < 5)){
							mes2 = (mes2 + (elemento2.charAt(i)));
					} 
					else {
						if (i > 5) {
								ano2 = (ano2 + (elemento2.charAt(i)));
						}
					}
				}			
			}
			dc2 = ( ano2 + mes2 + dia2 );
			data_n1=parseFloat(dc1);
			data_n2=parseFloat(dc2);
			//alert(dc1 + ' : ' + dc2);
			if (data_n1 > data_n2){
						return false;
			}
	}
	return true;
}

function comp_data_mmmaa(form_desvio,data1,data2){ 
	var elemento1;
	var elemento2;
	elemento1 = eval("form_desvio." + data1 + ".value");
	elemento2 = eval("form_desvio." + data2 + ".value");
	if ((elemento1 != "") && (elemento2 != "")){
			var dia1 = "";
			var mes1 = "";
			var ano1 = "";
			var dia2 = "";
			var mes2 = "";
			var ano2 = "";
			var dc1 = "";
			var dc2 = "";
			for (var i = 0; i < elemento1.length; i++){
					if (i < 2) {
						mes1 = (mes1 + (elemento1.charAt(i)));
					} 
					else {
						if (i > 2) {
							ano1 = (ano1 + (elemento1.charAt(i)));
						}
					}
			}
			dc1 = ( ano1 + mes1 );
			for (var i = 0; i < elemento2.length; i++){
					if (i < 2){
							mes2 = (mes2 + (elemento2.charAt(i)));
					} 
					else {
						if (i > 2) {
								ano2 = (ano2 + (elemento2.charAt(i)));
						}
					}
			}
			dc2 = ( ano2 + mes2 );
			data_n1=dc1;
			data_n2=dc2;
			if (data_n1 > data_n2){
				return false;
			}
	}
	return true;
}

//--------------------------- FORMATAÇÕES -------------------------------

function formata_hora(campo) {
	var valor;
	elemento = eval("document.form_desvio." + campo);
	valor = elemento.value;
	if (elemento.value.length == 1)
	{
		if (elemento.value > 2)
		{
			valor = "0" + elemento.value + ":";
		}
	}
	if (elemento.value.length == 2)
	{
		if (elemento.value > 23)
		{
			valor = elemento.value.charAt(0);
		}
		else
		{
			valor = elemento.value + ":";
		}
	}
	if (elemento.value.length == 4)
	{
		if (elemento.value.charAt(3) > 5)
		{
			valor = elemento.value.charAt(0) + elemento.value.charAt(1) + elemento.value.charAt(2);
		}
		else
		{
			valor = elemento.value;
		}
	}		
	return valor;
}

function formata_data(campo,full){
	s1 = campo;	
	s2 = s1.length;	
	if (s2 != 0){
			if (s2 == 2){
				campo = ( s1 + '/' );
			}		
		}
	if (full==true){
		if (s2 == 5){
				campo = ( s1 + '/' );
		}
	}
	return campo;
}

function formata_data_ddmmyyyy(campo)
{
	campo = eval("document.form_desvio." + campo );
	valor = campo.value;
	s1 = valor;
	s2 = s1.length;				
	if (s2 != 0) {
		if (s2 == 2) {
			valor = ( s1 + '/' );
			campo.value = valor;
			return;
		}
	}
	if (s2 == 5){
		valor = ( s1 + '/' );
		campo.value = valor;
		return;
	}
}

function formata_data_mmyyyy(campo){

	campo = eval("document.form_desvio." + campo );
	valor = campo.value;
	s1 = valor;
	s2 = s1.length;				
	if (s2 != 0) {
		if (s2 == 2) {
			valor = ( s1 + '/' );
			campo.value = valor;
			return;
		}
	}
}

function formata_cpf_onkeyup(campo){
	campo = eval("document.form_desvio." + campo );
	valor = campo.value;
	s1 = valor;
	s2 = s1.length;				
	if (s2 != 0) {
		if (s2 == 3) {
			valor = ( s1 + '.' );
			campo.value = valor;
			return;
		}
	}
	if (s2 == 7){
		valor = ( s1 + '.' );
		campo.value = valor;
		return;
	}
	if (s2 == 11){
		valor = ( s1 + '-' );
		campo.value = valor;
		return;
	}
	
}

function formata_cgc_onkeyup(campo){
	campo = eval("document.form_desvio." + campo );
	valor = campo.value;
	s1 = valor;
	s2 = s1.length;				
	if (s2 != 0) {
		if (s2 == 2) {
			valor = ( s1 + '.' );
			campo.value = valor;
			return;
		}
	}
	if (s2 == 6){
		valor = ( s1 + '.' );
		campo.value = valor;
		return;
	}
	if (s2 == 10){
		valor = ( s1 + '/' );
		campo.value = valor;
		return;
	}
	if (s2 == 15){
		valor = ( s1 + '-' );
		campo.value = valor;
		return;
	}
	
}

function formata_cpf(campo){
		s1 = campo;	
		s2 = s1.length;	
		if (s2 != 0){
			if (s2 == 3){
				campo = ( s1 + '.' );
			}
			if (s2 == 7){
				campo = ( s1 + '.' );
			}
			if (s2 == 11){
				campo = ( s1 + '-' );
			}

		}
		return campo;
	}

function formata_cgc(campo){
	s1 = campo;	
	s2 = s1.length;	
	if (s2 != 0){
		if (s2 == 2){
			campo = ( s1 + '.' );
		}
		if (s2 == 6){
			campo = ( s1 + '.' );
		}
		if (s2 == 10){
			campo = ( s1 + '/' );
		}
		if (s2 == 15){
			campo = ( s1 + '-' );
		}

	}
	return campo;
}

function formata_cep(campo){
	campo = eval("document.form_desvio." + campo );
	valor = campo.value;
	s1 = valor;
	s2 = s1.length;				
	if (s2 != 0) {
		if (s2 == 2) {
			valor = ( s1 + '.' );
			campo.value = valor;
			return;
		}
	}
	if (s2 == 6){
		valor = ( s1 + '-' );
		campo.value = valor;
		return;
	}
	
}

function ConverteCep(str) {
    var out = "", flag = 0;
    for (i = 0; i < str.length; i++){
    		if (str.charAt(i) != "." && str.charAt(i) != "-") {
    				out += str.charAt(i);
    				flag = 0;
    		}
    		else {
    				if(flag == 0){
    						out += "";
    						flag = 1;
    				}
    		}
    }
    return out;
}

function FormataCPF(Campo, teclapres){

	var tecla = teclapres.keyCode ? teclapres.keyCode : teclapres.which ? teclapres.which : teclapres.charCode;
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("-", "");
	tam = vr.length + 1;
	if (tecla != 9 && tecla !=8)
	{
		if (tam > 3 && tam < 7)
			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
		if (tam >= 7 && tam <10)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
		if (tam >= 10 && tam < 12)
			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
	}
	return isNumeric(teclapres);
}

//------------------------ FUNÇÕES DE MASCARA ---------------------------

/*
Passar uma string contendo o tipo a validar.
Evento a ser utilizado: onKeyPress
Ex: MascData('dd/mm/yyyy');
Ex: MascData('mm/yyyy');
*/
function MascData(tipo){

	var valor, novo_valor, mes;
	
	valor = event.srcElement.value;
	
	tipo = tipo.toUpperCase();
	
	// Numerico
	if ( (event.keyCode < '48' || event.keyCode > '57') &&
	     (event.keyCode != '8') ) 
	{
		event.returnValue=false;
		//event.keyCode = '127';
	}
	else
	{
		novo_valor = event.srcElement.value + String.fromCharCode(event.keyCode);
		
		if (tipo == 'MM/YYYY') 
		{
		  if ((valor.length + 1) == 2 )
			{
			  if (novo_valor.toString() == '00')
			 	{
			 	  event.returnValue=false; 				 	
			 		return; 
			 	}  
			
				if ( ValidaInfo(novo_valor,'MM') )
				  event.srcElement.value = novo_valor + '/';
			  event.returnValue=false;	
      }
			// ANO
			if ((valor.length + 1) == 7 ) 
			{
				ano = novo_valor.substr(3,4);
				
				if ( ValidaInfo(ano,'YYYY') )
					event.srcElement.value = novo_valor;
				else	
					event.srcElement.value = novo_valor.substr(0,3);
        event.returnValue=false;						
			}	// if ( (valor.length + 1) == 10 ) 

		}
		else
		{
			if ( tipo == 'DD/MM/YYYY' )
			{
				// DIA
				if ( (valor.length + 1) == 2 ) 
				{
 				  if (novo_valor.toString() == '00')
 				 	{
 				 	  event.returnValue=false; 				 	
 				 		return; 
 				 	}  
          
					if ( ValidaInfo(novo_valor,'DD') )
						event.srcElement.value = novo_valor + '/';
					event.returnValue=false;
				}	// if ( (valor.length + 1) == 2 ) 
			
				// MES
				if ( (valor.length + 1) == 5 ) 
				{
					mes = novo_valor.substr(3,2);
					
 				  if (mes.toString() == '00')
 				 	{
 				 	  event.returnValue=false; 				 	
 				 		return; 
 				 	}  
					
					if ( ValidaInfo(mes,'MM') )
						event.srcElement.value = novo_valor + '/';
					event.returnValue=false;
				}	// if ( (valor.length + 1) == 5 ) 
				
				// ANO
				if ( (valor.length + 1) == 10 ) 
				{
					ano = novo_valor.substr(6,4);
					
					if ( ValidaInfo(ano,'YYYY') )
						event.srcElement.value = novo_valor;
					else	
						event.srcElement.value = novo_valor.substr(0,6);
												
					event.returnValue=false;
				}	// if ( (valor.length + 1) == 10 ) 
			}	// if ( tipo == 'DD/MM/YYYY' )
		}	// if ( ( tipo == 'MM/YYYY' ) &&
	}	// if ( (event.keyCode < '48' || event.keyCode > '57') ...
}

/*
Passar uma string contendo o tipo a validar.
Evento a ser utilizado: onKeyPress
Ex: MascData2('dd.mm.yyyy');
Ex: MascData2('mm.yyyy');
*/
function MascData2(tipo){

	var valor, novo_valor, mes;
	
	valor = event.srcElement.value;
	
	tipo = tipo.toUpperCase();
	
	// Numerico
	if ( (event.keyCode < '48' || event.keyCode > '57') &&
	     (event.keyCode != '8') ) 
	{
		event.returnValue=false;
		//event.keyCode = '127';
	}
	else
	{
		novo_valor = event.srcElement.value + String.fromCharCode(event.keyCode);
		
		if (tipo == 'MM.YYYY') 
		{
		  if ((valor.length + 1) == 2 )
			{
			  if (novo_valor.toString() == '00')
			 	{
			 	  event.returnValue=false; 				 	
			 		return; 
			 	}  
			
				if ( ValidaInfo(novo_valor,'MM') )
				  event.srcElement.value = novo_valor + '.';
			  event.returnValue=false;	
      }
			// ANO
			if ((valor.length + 1) == 7 ) 
			{
				ano = novo_valor.substr(3,4);
				
				if ( ValidaInfo(ano,'YYYY') )
					event.srcElement.value = novo_valor;
				else	
					event.srcElement.value = novo_valor.substr(0,3);
        event.returnValue=false;						
			}	// if ( (valor.length + 1) == 10 ) 

		}
		else
		{
			if ( tipo == 'DD.MM.YYYY' )
			{
				// DIA
				if ( (valor.length + 1) == 2 ) 
				{
 				  if (novo_valor.toString() == '00')
 				 	{
 				 	  event.returnValue=false; 				 	
 				 		return; 
 				 	}  
          
					if ( ValidaInfo(novo_valor,'DD') )
						event.srcElement.value = novo_valor + '.';
					event.returnValue=false;
				}	// if ( (valor.length + 1) == 2 ) 
			
				// MES
				if ( (valor.length + 1) == 5 ) 
				{
					mes = novo_valor.substr(3,2);
					
 				  if (mes.toString() == '00')
 				 	{
 				 	  event.returnValue=false; 				 	
 				 		return; 
 				 	}  
					
					if ( ValidaInfo(mes,'MM') )
						event.srcElement.value = novo_valor + '.';
					event.returnValue=false;
				}	// if ( (valor.length + 1) == 5 ) 
				
				// ANO
				if ( (valor.length + 1) == 10 ) 
				{
					ano = novo_valor.substr(6,4);
					
					if ( ValidaInfo(ano,'YYYY') )
						event.srcElement.value = novo_valor;
					else	
						event.srcElement.value = novo_valor.substr(0,6);
												
					event.returnValue=false;
				}	// if ( (valor.length + 1) == 10 ) 
			}	// if ( tipo == 'DD.MM.YYYY' )
		}	// if ( ( tipo == 'MM.YYYY' ) &&
	}	// if ( (event.keyCode < '48' || event.keyCode > '57') ...
}

// Ex: onKeypress = 'javascript:MascCpf();'
function MascCpf(){

	var valor;
	
	valor = event.srcElement.value;
	
	// Numerico
	if ( (event.keyCode < '48' || event.keyCode > '57') &&
	     (event.keyCode != '8') ) 
	{
		event.returnValue=false;
	}
	else
	{
		if ( ( (valor.length + 1) == 3 ) ||
			 ( (valor.length + 1) == 7 ) ) 
		{
			event.srcElement.value += String.fromCharCode(event.keyCode) + '.';
			event.returnValue=false;
		}
		else
		{
			if ( ( (valor.length + 1) == 11 ) ) 
			{
				event.srcElement.value += String.fromCharCode(event.keyCode) + '-';
				event.returnValue=false;
			}
		}
	}
}

// Ex: onKeypress = 'javascript:MascCgc();'
function MascCgc(){

	var valor;
	
	valor = event.srcElement.value;
	
	// Numerico
	if ( (event.keyCode < '48' || event.keyCode > '57') &&
	     (event.keyCode != '8') ) 
	{
		event.returnValue=false;
	}
	else
	{
		if ( ( (valor.length + 1) == 2 ) ||
			 ( (valor.length + 1) == 6 ) ) 
		{
			event.srcElement.value += String.fromCharCode(event.keyCode) + '.';
			event.returnValue=false;
		}
		else
		{
			if ( ( (valor.length + 1) == 10 ) ) 
			{
				event.srcElement.value += String.fromCharCode(event.keyCode) + '/';
				event.returnValue=false;
			}
			else
			{
				if ( ( (valor.length + 1) == 15 ) ) 
				{
					event.srcElement.value += String.fromCharCode(event.keyCode) + '-';
					event.returnValue=false;
				}
			}
		}
	}
}

// Ex: onKeypress = 'javascript:MascCep();'
//
function MascCep()
{
	var valor;
	
	valor = event.srcElement.value;
	
	// Numerico
	if ( (event.keyCode < '48' || event.keyCode > '57') &&
	     (event.keyCode != '8') ) 
	{
		event.returnValue=false;
	}
	else
	{
		if ( ( (valor.length + 1) == 2 ) ) 
		{
			event.srcElement.value += String.fromCharCode(event.keyCode) + '.';
			event.returnValue=false;
		}
		else
		{
			if ( ( (valor.length + 1) == 6 ) ) 
			{
				event.srcElement.value += String.fromCharCode(event.keyCode) + '-';
				event.returnValue=false;
			}
		}
	}
}


// Tipo 'hh:mi', 'hh:mi:ss'
// Ex: onKeypress = "javascript:MascHora('hh:mi');"
//
function MascHora(tipo)
{
	var valor, novo_valor, minuto;
	
	valor = event.srcElement.value;
	
	tipo = tipo.toUpperCase();
	
	// Numerico
	if ( (event.keyCode < '48' || event.keyCode > '57') &&
	     (event.keyCode != '8') ) 
	{
		event.returnValue=false;
	}
	else
	{
		novo_valor = event.srcElement.value + String.fromCharCode(event.keyCode);
		// HORA
		if ( (valor.length + 1) == 2 )
		{
			if ( ValidaInfo(novo_valor,'HH') )
				event.srcElement.value = novo_valor + ':';
			event.returnValue=false;

		}	
		
		// MINUTO
		if ( ( (valor.length + 1) == 5 ) ) 
		{
			minuto = novo_valor.substr(3,2);
							
			if ( ValidaInfo(minuto,'MI') )

				if ( tipo == 'HH:MI:SS' ) 
				{
					event.srcElement.value = novo_valor + ':';
				}
				else
				{
					event.srcElement.value = novo_valor;
				}
				
			event.returnValue=false;
		}

		// SEGUNDO
		if ( ( (valor.length + 1) == 8 ) ) 
		{
			segundo = novo_valor.substr(5,2);
							
			if ( ValidaInfo(minuto,'SS') )
			{
			}
			event.returnValue=false;
		}

	}	// if ( (event.keyCode < '48' || event.keyCode > '57') ...
}

// Somente numeros e ponto, qualquer outro caracter é rejeitado.
// Evento a ser utilizado: onKeyPress
// 44 - Virgula (,)
// 46 - Ponto (.)
//
function MascNum()
{
    var conteudo;
	conteudo = event.srcElement.value;
	
	// Procura se o usuario já digitou uma virgula, 
	// caso positivo entao rejeita.
//	alert(conteudo);
	if ( (event.keyCode == '44' && conteudo.indexOf(",") > 0 ) || 
		 (event.keyCode == '44' && conteudo == ",") )
		event.returnValue=false;
	    
	if ( (event.keyCode < '48' || event.keyCode > '57') &&
	     (event.keyCode != '44') &&
	     (event.keyCode != '8') ) 
		event.returnValue=false;

//alert(event.keyCode );
	if ( event.keyCode == '44' && conteudo.length == 0 )
	{
		event.srcElement.value = "0";
	}
	    
	return;
}

// Somente numeros inteiros, qualquer outro caracter é rejeitado.
// Evento a ser utilizado: onKeyPress
//
function MascInteiro()
{
	//alert(event.keyCode);
	if ( (event.keyCode < '48' || event.keyCode > '57') &&
	     (event.keyCode != '8') ) 
		event.returnValue=false;

	return;
}

// Somente caracteres (maiusculos e minusculos), 
// qualquer outro caracter é rejeitado.
// Evento a ser utilizado: onKeyPress
// sTipoCaixa - U(pper) / L(ower) / N(ormal) - Indica se a máscara deve ficar em Caixa Alta ou Baixa.
// 
function MascAlfa(sTipoCaixa)
{
	// keycode que serão aceitos qdo o usuário digitar:
	//  8 - Backspace
	// 32 - Space
    // 40 - Parenteses Esquerdo (
    // 41 - Parenteses Direito )
    // 44 - Virgula (,)
    // 45 - Subtracao (-)
    // 46 - Ponto (.)
	// 47 - Barra (/)
	// 58 - Dois Pontos (:)
	// 64 - Arroba (@)
    // demais numeração acima de 192, caracteres com acentuação
    //
    var tecla, novo_valor;
	
	//alert (event.keyCode);
	
	sTipoCaixa = sTipoCaixa.toUpperCase();

	if ( (event.keyCode < '65' || event.keyCode > '90') &&
	     (event.keyCode < '97' || event.keyCode > '122') &&
	     (event.keyCode < '192' || event.keyCode > '196') &&
	     (event.keyCode < '199' || event.keyCode > '207') &&
	     (event.keyCode < '210' || event.keyCode > '214') &&
	     (event.keyCode < '217' || event.keyCode > '220') &&
	     (event.keyCode < '224' || event.keyCode > '228') &&
	     (event.keyCode < '231' || event.keyCode > '239') &&
	     (event.keyCode < '242' || event.keyCode > '246') &&
	     (event.keyCode < '249' || event.keyCode > '252') &&
	     (event.keyCode != '8')  &&
	     (event.keyCode != '32') && 
	     (event.keyCode != '40') &&
	     (event.keyCode != '41') &&
	     (event.keyCode != '44') &&
	     (event.keyCode != '45') &&
	     (event.keyCode != '46') &&
	     (event.keyCode != '47') &&
	     (event.keyCode != '58') &&
	     (event.keyCode != '64') )
	{
		event.returnValue=false;
		return;
	}
	
	if ( (event.keyCode != '8')  &&
	     (event.keyCode != '32') && 
	     (event.keyCode != '40') &&
	     (event.keyCode != '41') &&
	     (event.keyCode != '44') &&
	     (event.keyCode != '45') &&
	     (event.keyCode != '46') &&
	     (event.keyCode != '47') &&
	     (event.keyCode != '58') &&
	     (event.keyCode != '64') ) 
	{
		// Caixa Baixa
		if ( (sTipoCaixa == "L") &&
		     (event.keyCode < '224' || event.keyCode > '228') &&
		     (event.keyCode < '231' || event.keyCode > '239') &&
		     (event.keyCode < '242' || event.keyCode > '246') &&
		     (event.keyCode < '249' || event.keyCode > '252') &&
		     (event.keyCode < '97' || event.keyCode > '122') )
			event.keyCode = event.keyCode + 32;
	

		// Caixa Alta
		if ( (sTipoCaixa == "U") &&
		     (event.keyCode < '65' || event.keyCode > '90') )
			event.keyCode = event.keyCode - 32;
	}
	
	//alert (event.keyCode);

	return;
}

// Somente numeros e caracteres (maiusculos e minusculos), 
// qualquer outro caracter é rejeitado.
// Evento a ser utilizado: onKeyPress
// sTipoCaixa - U(pper) / L(ower) / N(ormal) - Indica se a máscara deve ficar em Caixa Alta ou Baixa.
// 
function MascAlfaNum(sTipoCaixa)
{
	// keycode que serão aceitos qdo o usuário digitar:
	//  8 - Backspace
	// 32 - Space
    // 40 - Parenteses Esquerdo (
    // 41 - Parenteses Direito )
    // 44 - Virgula (,)
    // 45 - Subtracao (-)
    // 46 - Ponto (.)
	// 47 - Barra (/)
	// 58 - Dois Pontos (:)
	// 64 - Arroba (@)
    var tecla, novo_valor;
	
	//alert (event.keyCode);

	sTipoCaixa = sTipoCaixa.toUpperCase();
	
	if ( (event.keyCode < '48' || event.keyCode > '57')  &&
	     (event.keyCode < '65' || event.keyCode > '90')  &&
	     (event.keyCode < '97' || event.keyCode > '122') &&
	     (event.keyCode < '192' || event.keyCode > '196') &&
	     (event.keyCode < '199' || event.keyCode > '207') &&
	     (event.keyCode < '210' || event.keyCode > '214') &&
	     (event.keyCode < '217' || event.keyCode > '220') &&
	     (event.keyCode < '224' || event.keyCode > '228') &&
	     (event.keyCode < '231' || event.keyCode > '239') &&
	     (event.keyCode < '242' || event.keyCode > '246') &&
	     (event.keyCode < '249' || event.keyCode > '252') &&
	     (event.keyCode != '8')  &&
	     (event.keyCode != '13')  &&
	     (event.keyCode != '32') && 
	     (event.keyCode != '40') &&
	     (event.keyCode != '41') &&
	     (event.keyCode != '44') &&
	     (event.keyCode != '45') &&
	     (event.keyCode != '46') &&
	     (event.keyCode != '47') &&
	     (event.keyCode != '58') &&
	     (event.keyCode != '64') ) 
	{
		event.returnValue=false;
		return;
	}

	if ( (event.keyCode < '48' || event.keyCode > '57')  &&
	     (event.keyCode != '8')  &&
	     (event.keyCode != '13')  &&
	     (event.keyCode != '32') && 
	     (event.keyCode != '40') &&
	     (event.keyCode != '41') &&
	     (event.keyCode != '44') &&
	     (event.keyCode != '45') &&
	     (event.keyCode != '46') &&
	     (event.keyCode != '47') &&
	     (event.keyCode != '58') &&
	     (event.keyCode != '64') ) 
	{
		// Caixa Baixa
		if ( (sTipoCaixa == "L") &&
		     (event.keyCode < '224' || event.keyCode > '228') &&
		     (event.keyCode < '231' || event.keyCode > '239') &&
		     (event.keyCode < '242' || event.keyCode > '246') &&
		     (event.keyCode < '249' || event.keyCode > '252') &&
		     (event.keyCode < '97' || event.keyCode > '122') )
			event.keyCode = event.keyCode + 32;
	

		// Caixa Alta
		if ( (sTipoCaixa == "U") &&
		     (event.keyCode < '65' || event.keyCode > '90') )
			event.keyCode = event.keyCode - 32;
	}

	//alert (event.keyCode);

	
	return;
}

// Somente caracteres (maiusculos e minusculos), 
// qualquer outro caracter é rejeitado.
// Evento a ser utilizado: onKeyPress
// 
function MascEmail()
{
	// keycode que serão aceitos qdo o usuário digitar:
	//  8 - Backspace
	// 32 - Space
    // 45 - Subtracao (-)
    // 46 - Ponto (.)
	// 64 - Arroba (@)
	// 95 - Underline (_)
    // demais numeração acima de 192, caracteres com acentuação
    //
    var tecla, novo_valor;
	
//	alert (event.keyCode);
	
	if ( (event.keyCode < '48' || event.keyCode > '57') &&
             (event.keyCode < '65' || event.keyCode > '90') &&
	     (event.keyCode < '97' || event.keyCode > '122') &&
	     (event.keyCode < '192' || event.keyCode > '196') &&
	     (event.keyCode < '199' || event.keyCode > '207') &&
	     (event.keyCode < '210' || event.keyCode > '214') &&
	     (event.keyCode < '217' || event.keyCode > '220') &&
	     (event.keyCode < '224' || event.keyCode > '228') &&
	     (event.keyCode < '231' || event.keyCode > '239') &&
	     (event.keyCode < '242' || event.keyCode > '246') &&
	     (event.keyCode < '249' || event.keyCode > '252') &&
	     (event.keyCode != '8')  &&
	     (event.keyCode != '32') && 
	     (event.keyCode != '45') &&
	     (event.keyCode != '46') &&
	     (event.keyCode != '64') &&
	     (event.keyCode != '95') ) 
	{
		event.returnValue=false;
		return;
	}
	
	// Caixa Baixa
	if ( (event.keyCode < '224' || event.keyCode > '228') &&
	     (event.keyCode < '48' || event.keyCode > '57')  &&
	     (event.keyCode < '231' || event.keyCode > '239') &&
	     (event.keyCode < '242' || event.keyCode > '246') &&
	     (event.keyCode < '249' || event.keyCode > '252') &&
	     (event.keyCode < '97' || event.keyCode > '122') &&
	     (event.keyCode != '8')  &&
	     (event.keyCode != '32') && 
	     (event.keyCode != '45') &&
	     (event.keyCode != '46') &&
	     (event.keyCode != '64') &&
	     (event.keyCode != '95') ) 
		event.keyCode = event.keyCode + 32;
	//alert (event.keyCode);
	return;
}

function MascCampoZero(objetoTxt,numCasasDec) 
  { 
    // onKeyDown="MascCampoZero(this,'0000')"
    // O numCasasDec tem que ser do mesmo tamanho que o maxLength  
     
    var excluir;
  
    //TRATA DELETE E BACKSPACE 
    excluir = 0;
    if ((event.keyCode == '8' ) || (event.keyCode == '46'))     
      excluir = 1;
  
    //TECLADO NUMERICO
    if (event.keyCode >= '96' && event.keyCode <= '105') 
      event.keyCode = event.keyCode - 48;  //converte para numero padrao

    if (excluir == 1)
      {  
        objetoTxt.value = "0" + objetoTxt.value.substr(0,(numCasasDec.length-1));      
      }
      
    // TRATA DIFERENTE DE NUMEROS
    if ((event.keyCode < '48' || event.keyCode > '57') && (event.keyCode != '9'))
    {
      event.returnValue=false;
      return;
    }  
  
    if (event.keyCode == '9')
      return;
  
    if (excluir == 0)
      {
        //TRATA MAXLENGTH DEFININDO TAMANHO MAXIMO DO CAMPO
        if ((objetoTxt.maxLength) && (objetoTxt.value.substr(0,1)!='0'))
          {
            event.returnValue=false;
            return;           
          }

         objetoTxt.value = objetoTxt.value.substr(1,(numCasasDec.length - 1)) + (event.keyCode - 48);  
      }   

    event.returnValue=false;
    return;     
  }

function formataNumero(objetoTxt,numCasasDec,usaMascara){

  //     Cadu - 01/07/2005
  //      esta função formata um campo numérico, podendo ou não conter casas decimais
  //      propriedades da caixa de texto para uso desta funcao :
  //
  //     ex.: onkeydown="formataNumero(this,2)" value='0,00' style='text-align: right;' maxlength='10'
  //     ex.: onkeydown="formataNumero(this,3)" value='0,000' style='text-align: right;' maxlength='10'
  //     ex.: onkeydown="formataNumero(this,0)" value='0' style='text-align: right;' maxlength='10'
  //     ex.: onkeydown="formataNumero(this,0)" value='' style='text-align: right;' maxlength='10' porem se o 
  //                                                                                               usuario preencher
  //                                                                                               e apagar,
  //                                                                                               ficara com 0.      
  //        
  //    OBS:  Caso o valor venha do asp, precisa vir formatado conforme a mascara. Ex.:(#.###.###.###,##)
  //    OBS2: o Maxlength é tratado aqui e não conta com '.', mas conta com a ','
  //    OBS3: Para remover os pontos da parte inteira, em javascript "string = string.replace(/\./g,'');"   
  //    OBS4: usaMascara é opcional, se colocar 'N', ele permite apagar a mascara 0,00
  var fracionario;
  var inteiro;
  var separadorDec;
  var funcao;
  var excluir;
  var novoValor;
  var ponto;
  
  if (usaMascara == '')
  {
    usaMascara = 'S';
  }
  
  //define o separador utilizado, ou nenhum se casas decimais = 0
  if (numCasasDec == 0)
    separadorDec='';
  else
    separadorDec=',';  
  
  if (event.keyCode >= '96' && event.keyCode <= '105') //teclado Numerico
    event.keyCode = event.keyCode - 48;  //converte para numero padrao
    

  // trata diferente de numeros  
  if ( (event.keyCode < '48' || event.keyCode > '57') && (event.keyCode != '8') && (event.keyCode != '46') )  
  {
    event.returnValue=false;
    return;
  }  

  //trata delete e backspace 
  if ((event.keyCode == '8' || event.keyCode == '46'))       
    excluir = 1;
  else
    excluir = 0;    
  
  novoValor = objetoTxt.value;
  
  if (excluir == 0)
  {
    //trata maxLength
    if ((objetoTxt.maxLength) && (objetoTxt.maxLength <= novoValor.replace(/\./g,'').length) && (novoValor.substr(0,1)!='0'))
      return; 
    //define tamanho maximo do campo
    if (((novoValor.replace(',','').length)-numCasasDec) > 12) //1.000.000.000,00
    {
      alert("O número excede o limite de 9.999.999.999,99");
      event.returnValue=false;       
      return;
    }
    //inclui valor
    novoValor = novoValor + (event.keyCode - 48);
  }
  
  //monta novo valor
  novoValor = novoValor.replace(separadorDec,'');
  if (numCasasDec == 0) // se o numero é inteiro
  {
    fracionario = '';      
    inteiro     = novoValor.substr(0,(novoValor.length)-excluir);
  }
  else
  {
    fracionario     = novoValor.substr((novoValor.length)-(numCasasDec)-excluir,numCasasDec);
    inteiro         = novoValor.substr(0,(novoValor.length)-(numCasasDec)-excluir);
  }  
  if (!inteiro)
    temp=0; //parte inteira temporaria
  else
  {
    inteiro = inteiro.replace(/\./g,'');  
    if (parseFloat(inteiro) <= 999)
      temp = parseFloat(inteiro);
    else
    {
      temp = '';
      ponto = '';
      while (inteiro.length > 0)
      {
        if (inteiro.length >=3)
        {
          temp = inteiro.substr((inteiro.length-3),3) + ponto + temp;
          inteiro = inteiro.substr(0,(inteiro.length-3));
          ponto = '.';
        }
        else
        {
          temp = inteiro + '.' + temp;
          inteiro = '';
        }      
      } 
    }
  }
  valor = temp + separadorDec + fracionario; 
  
  temp = valor.replace(/\./g,'');
  temp = temp.replace(/\,/g,'.');
  if ((usaMascara == "N") && (parseFloat(temp) == 0) && (excluir == 1)) 
  {
    valor = '';
  }    
  objetoTxt.value = valor;

  event.returnValue=false;
  return;     
}

function maskDate(vCampo){
    // dd/mm/yyyy
    var m = vCampo.value;
    var tecla = event.keyCode;
    
    // numeros de 0 a 9
    if ((tecla > 47 && tecla < 58) || (tecla > 95 && tecla < 106)) {
        if(m.length == 10){
            return false
        }

        m = m.replace('/', '').replace('/', '');
        vDia = m.substr(0, 2)
        vMes = m.substr(2, 2)
        vAno = m.substr(4, 4)
        
        if(m.length < 2){
          vCampo.value = vDia;
        }else if(m.length < 4){
          vCampo.value = vDia +"/"+ vMes;
        }else{
          vCampo.value = vDia +"/"+ vMes +"/"+ vAno;
        }
            
    }else{
        // backspace
        if (tecla != 8 && tecla != 9){
            event.keyCode = 0;
            return false;
        }else{
            return true;        
        }
    }
}

function maskHour(vCampo){
    // hh:mm
    
    //alert(oi);
    
    var m = vCampo.value;
    var tecla = event.keyCode;
    
    // numeros de 0 a 9
    if ((tecla > 47 && tecla < 58) || (tecla > 95 && tecla < 106)) {
        if(m.length == 10){
            return false
        }

        m = m.replace(':', '');
        vHora = m.substr(0, 2)
        vMin = m.substr(2, 2)
        
        if(m.length < 2){
           vCampo.value = vHora;
        }else{
          vCampo.value = vHora +":"+ vMin;
        }
            
    }else{
        // backspace
        if (tecla != 8 && tecla != 9){
            event.keyCode = 0;
            return false;
        }else{
            return true;        
        }
    }
}

function formatNumber2(n){
    // #######.##
    var m = String(n)
    var f = "";
    var vDecimalVirgula = false;
    var vDecimalPonto = false;
    var vParteInteira = "";
    var vParteReal = "";
    var vDecimal = "";

    if(m.charAt(m.length-3) == ","){
        vDecimalVirgula = true
    }
    m = m.replace(/,/, '')
    if(m.lastIndexOf(".")>0){
        vDecimalPonto = true
    }

    if (vDecimalVirgula) {
        vParteInteira = m.substr(0, m.length-2)
        vParteReal = m.substr(m.length-2,2)+0
    }
    if (vDecimalPonto) {
        p = m.lastIndexOf(".");
        vParteInteira = m.substr(0, p)
        vParteReal = m.slice(p+1)+0
    
    }
    if (!vDecimalVirgula && !vDecimalPonto) {
        vParteInteira = m
        vParteReal = "00"
    }

    vParteInteira = vParteInteira.replace(".", "")
    if (vParteReal.length > 2){
        vDecimal = vParteReal.substr(0,1)
        if (vParteReal.substr(2,1)>5){
            vDecimal += new Number(vParteReal.substr(1,1))+1
        }else{
            vDecimal += vParteReal.substr(1,1)
        }
    }else{
        vDecimal = vParteReal
    }

    return(vParteInteira +"."+ vDecimal)
}

function maskNumber(fld, milSep, decSep, e, maxlen){
	if (fld.readOnly) return false;
	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;
	if(maxlen > 0 && len == maxlen) return false;
	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;
}

function maskNumber2(vCampo){ 
    // ######.##
    var m = vCampo.value;
    var tecla = event.keyCode;
    
    // numeros de 0 a 9
    if ((tecla > 47 && tecla < 58) || (tecla > 95 && tecla < 106)) {
        if(m.length == 9){
            return false
        }
        m = m.replace(",", "")
        vParteInteira = m.substr(0, m.length-1)
        vParteReal = m.substr(m.length-1,1)
        vCampo.value = vParteInteira +","+ vParteReal;
    }else{
        // backspace
        if (tecla != 8 && tecla != 9){
            event.keyCode = 0;
            return false;
        }else{
            return true;        
        }
    }
}


//------------------------ OUTRAS FUNÇÕES ---------------------------

function maior_dia(mes, ano)
{
   var mDia;
   if((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11))
     { 
      mDia = 30;
     }
   else if(mes == 2)
     {
      mDia = (ano % 4 == 0) ? 29 : 28;    
     }
   else
     {
      mDia = 31;
     }
   return mDia; 
}

/* A função bypassa as teclas:
	08 - BACKSPACE
	09 - TAB
	46 - DELETE
	37 a 40 - 
*/ 
function contar_texto(form_desvio,elemento,tamanho){
	//alert(event.keyCode);
	if ( (event.keyCode < '37' || event.keyCode > '40') &&
	     (event.keyCode != 46) && 
	     (event.keyCode != 08) && 
	     (event.keyCode != 09) )
	{
		elemento1 = elemento.value;
		elemento2 = elemento1.length;
		if (elemento2 >= tamanho)
		{
			event.returnValue=false;
			elemento.value=elemento.value.substr(0,tamanho);
			alert("Você já digitou o limite máximo de " + tamanho + " caracteres");
			elemento.focus();
		}
	}	// if (event.keyCode != '46')
}

function marca_tudo(cont,campo) {
    /*
    Para esta função é necessário criar dentro do formulário um capo do tipo HIDDEN, de nome
    MARCACAO com o valor inicial igual a "D", como mostrado abaixo.

    <input type="hidden" name="marcacao" value="D">

    O uso da função é no evento ONCLICK, com a seguinte sintaxe:
    ... onClick="marca_tudo(nome_do_contador, nome_do_checkbox)" ...
    */

	cont = cont.value;
	checa=eval("document.form_desvio.marcacao.value");
	if(checa=="D")
	{
		for(x=0;x<cont;x++)
		{
			elemento = eval(campo + x );
			elemento.checked = true;
			document.form_desvio.marcacao.value = "M";
		}
	}
	else
	{
		for(x=0;x<cont;x++)
		{
			elemento = eval(campo + x );
			elemento.checked = false;
			document.form_desvio.marcacao.value = "D";
		}
	}
}

function retira_format_numero(elemento) {
    // Esta funcao retira a formatacao numerica, para o formato de trabalho
    // Ex: 325.632.124,28 para 325632124,28

	snumero = "";
	
	for (var i=0; i<elemento.length; i++) 
	{
		if (elemento.charAt(i) != '.') 
		{
			//if (elemento.charAt(i) == ',') 
			//{
			//	snumero += '.';
			//}
			//else
			//{	
				snumero += elemento.charAt(i);
			//}
		}	
	}
	return snumero;
}

function retira_format_cpf(elemento) {
	snumero = "";
	
	for (var i=0; i<elemento.length; i++) 
	{
		if ((elemento.charAt(i) != '.') && (elemento.charAt(i) != '-'))
		{			
			snumero += elemento.charAt(i);
		}
	}
	return snumero;
}

// Limpa todos os campos da tela exceto os listados na função
function LimparCampos(form_desvio)
{
	elementos = document.form_desvio.elements;
	tot = elementos.length;
	
	for( i=0; i<tot; i++ )
	{
//		alert(elementos[ i ].type);
		if ( ( elementos[ i ].name != 'acao' ) && 
    		     ( elementos[ i ].type != 'button' ) &&
                 ( elementos[ i ].type != 'submit' ) &&
		     ( elementos[ i ].name != 'act' ) && 
		     ( elementos[ i ].name != 'p1' ) && 
		     ( elementos[ i ].name != 'p2' ) && 
		     ( elementos[ i ].name != 'p3' ) && 
		     ( elementos[ i ].name != 'p4' ) && 
		     ( elementos[ i ].name != 'p5' ) && 
		     ( elementos[ i ].name != 'p6' ) && 
		     ( elementos[ i ].name != 'pgm_retorno' ) )
		{
			if ( elementos[ i ].type == 'checkbox' ||
                       elementos[ i ].type == 'radio' )
			{
				elementos[ i ].checked = false;
			}
			else
			{
				if ( elementos[ i ].type == 'select-multiple' )
				{
				}
				elementos[ i ].value = '';
			}
		}
	}

}

// Lista todos os campos da tela exceto os listados na função
function ListaCampos(form_desvio)
{
	elementos = document.form_desvio.elements;
	tot = elementos.length;
	
	for( i=0; i<tot; i++ )
	{
		if ( ( elementos[ i ].name != 'acao' ) && 
		     ( elementos[ i ].name != 'act' ) && 
		     ( elementos[ i ].name != 'p1' ) && 
		     ( elementos[ i ].name != 'p2' ) && 
		     ( elementos[ i ].name != 'p3' ) && 
		     ( elementos[ i ].name != 'p4' ) && 
		     ( elementos[ i ].name != 'p5' ) && 
		     ( elementos[ i ].name != 'p6' ) )
		{
			if ( elementos[ i ].type == 'checkbox' ||
				 elementos[ i ].type == 'radio' ||
				 elementos[ i ].type == 'text' ||
				 elementos[ i ].type == 'hidden' ||
				 elementos[ i ].type == 'select-one' ||
				 elementos[ i ].type == 'select-multiple' )
			{
				document.write ("Tipo = <b>" + elementos[ i ].type + "</b> / Nome = <b>" + elementos[ i ].name + "</b> / Valor = <b>" + elementos[ i ].value + "</b><br>");
			}
		}
	}

}

function AbilitaCampos(form_desvio){

	elementos = document.form_desvio.elements;
	tot = elementos.length;
	
	for( i=0; i<tot; i++ )
	{
		if ( elementos[ i ].disabled == true )
		{
			elementos[ i ].disabled = false;
		}
	}
}
/*
Habilita todos os campos desabilitados da tela para se seja possível
recuperar seu valor com Request.Form na página seguinte
*/
function HabilitaCampos(objForm)
{
	elementos = objForm.elements;
	tot = elementos.length;
	
	for( i=0; i<tot; i++ )
	{
		if ( elementos[ i ].disabled == true )
		{
			elementos[ i ].disabled = false;
		}
	}
}
/*
Desabilita todos os butões habilitados da tela para evitar
que o usuário fique clicando quando o sistema estiver lento.
CUIDADO: com os do tipo Submit
*/
function DesabilitaBotoes()
{
	tot = parseInt(document.form_desvio.acao.length);
	for( i=0; i < tot; i++ )
		if (document.form_desvio.acao[i].disabled == false)
			document.form_desvio.acao[i].disabled = true;
}

// valida tamanho de campo e passa para o seguinte
function validaTamanho(sOrigem, iTamanho, sDestino){

	var sValorAtual = document.getElementById(sOrigem).value;

	if (sValorAtual.length == iTamanho){
		document.getElementById(sDestino).focus();
	}
}

//Confere se há "espaços" no campo e os elimina
//onblur="this.value=this.value.trim();"
String.prototype.trim = function(){
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
