function RTrim(campo){

	y=true;
	while(y==true){
		x = campo.length;
		if(Right(campo,1)==' '){
			campo = Left(campo,x-1);
			y=true;
		}
		else{
			y=false
		}
	}
	return campo;
}

	
function LTrim(campo){

	y=true;
	while(y==true){
		x = campo.length-1;
		if(Left(campo,1)==' '){
			campo = Right(campo,x);
			y=true;
		}
		else{
			y=false;
		}
	}
	return campo;
}

	
function Trim(campo){

	return RTrim(LTrim(campo));
}
//Recupera o indice do objeto corrente do formulário

function getIndex(what,which) {
	for (var i=0;i < what.elements.length;i++)
		if (what.elements[i].name == which)
			return i;
	return -1;
}

function FormataData(pForm, pCampo,pTeclaPres) {
	var wTecla = pTeclaPres.keyCode;
	wVr = pForm[pCampo].value;
	wVr = wVr.replace( ".", "" );
	wVr = wVr.replace( "/", "" );
	wVr = wVr.replace( "/", "" );
	wTam = wVr.length + 1;
	
	if ( wTecla != 9 && wTecla != 8 ){
		if (( wTam > 2 && wTam < 5 ) && (wTecla != 111))
			pForm[pCampo].value = wVr.substr( 0, wTam - 2 ) + '/' + wVr.substr( wTam - 2, wTam );
		
		if (( wTam >= 5 && wTam <= 10 ) && (wTecla != 111))
			pForm[pCampo].value = wVr.substr( 0, 2 ) + '/' + wVr.substr( 2, 2 ) + '/' + wVr.substr( 4, 4 ); 

		} 
} 

function VerificaData(pForm, pCampo, pDtProibida) {

	var wHoje = new Date();
	var wAUX, wAUX2, wDataValida;
	wAUX2 = "";
	wAUX = pForm[pCampo].value;
	
	if (wAUX == "") {
		return false;
	} 

	if (pDtProibida != "") {
		wAUX2 = pDtProibida;
		var wFrescuraSIAPI = new Date(wAUX2.substr(6, 4), wAUX2.substr(3,2) - 1, wAUX2.substr(0,2))
	}

	if (wAUX == "" || wAUX.length < 10) {
		alert("Tamanho de Data Incorreto. Digite a data no formato DD/MM/AAAA.");
		// pForm[pCampo].value = "";
		pForm[pCampo].focus(); 
		return false;
	} 

	wDataValida = SbrebowsDataSdruxula(wAUX.substr(0,2),wAUX.substr(3,2), wAUX.substr(6, 4));

	if (!wDataValida) {
		alert("Data Inválida.");
		// pForm[pCampo].value = "";
		pForm[pCampo].focus(); 
		return false;
	} else {
		var wDtRef = new Date(wAUX.substr(6, 4), wAUX.substr(3,2) - 1, wAUX.substr(0,2))
		if (Date.parse(wDtRef) >= Date.parse(wHoje)) {
		alert("Data não pode ser maior que a Data Atual. Redigite-a");
		// pForm[pCampo].value = "";
		pForm[pCampo].focus();
		return false;
		} else {

		if (wAUX2 != "" && Date.parse(wDtRef) > Date.parse(wFrescuraSIAPI)) {
			alert("Data não pode ser maior que " + pDtProibida + ". Redigite-a");
			// pForm[pCampo].value = "";
			pForm[pCampo].focus();
			return false; 
		}

	}

	return true;
  }
}

// Rotinas de validação adaptadas de funções obtidas na net.
// Data : 21/10/1999

function IniObjJScript(ParObjeto, ParValor)
// Lógica de apresentação de conteúdo de de BD em tela:
// Lê-se do BD para a Variável ASP e daí para a variável de tela.
// Daí a necessidade de se inicializar os campos de tela individualmente.
{
   ParObjeto.value = ParValor;
}

// Desabilita Objetos JScript de Tela de acordo com o resultado da Expressão Lógica
// passada como parâmetro 
function Desabilita(ParObjeto, ParExprLogica)
{
   ParObjeto.disabled = eval(ParExprLogica);
}

// verifica se campo esta vazio
function CampoOK( campo, nome )
{
  	if ( campo.value=="" || campo.length==0 )
	{
      alert("O campo '" + nome + "' deve ser informado!");
      campo.focus();
      return(false);
	}
	else
       return(true);
}

//-------------------------------
function ValidaTitulo(Titulo) {
	var  Soma=0;
	var i = 0;
	var j = 0;
	var DV1c = "";
	var DV2c = "";
	var Sequencial = Titulo.substr(0,9);
	var UF = Titulo.substr(9, 2);
	var DV1 = Titulo.charAt(11);
	var DV2 = Titulo.charAt(12);
	var controle = "";
	var ContIni = 2;
	var ContFim = 10;
	for (j = 1; j <= 2; j++)
	{
		Soma = 0;
		for (i = ContIni; i<= ContFim; i++)
		{
			Soma = Soma + (Sequencial.charAt(i-2) * (ContFim + 2 - i));
       }
		Digito = Soma % 11;
		if ((UF == "01") || (UF == "02")) 
		{
			if (Digito == 1) 
				Digito = 0;
			else 	if  (Digito == 0) 
						Digito = 1;
					else
						Digito = 11 - Digito;
		}
		else {
			if ((Digito == 1) || (Digito == 0))
				Digito = 0;
			else
				Digito = 11 - Digito;
		}
		if (j == 1)
			DV1c = Digito;
		else
			DV2c = Digito;

		ContFim = 4;
		controle = controle + Digito;
		Sequencial = UF + controle; 
	} 
	if ((DV1 != DV1c) || (DV2 != DV2c)) 
		return false;
	else
		return true;
}

//-------------------------------
function ValidaCPF(rcpf1,rcpf2,c) {
  d1 = 0;
  for (i=0;i<9;i++) 
    d1 += rcpf1.charAt(i)*(10-i);
  d1 = 11 - (d1 % 11);
  if (d1>9) d1 = 0;
  
  if (rcpf2.charAt(0) != d1) 
    return false;
  
  d1 *= 2;
  for (i=0;i<9;i++) 
    d1 += rcpf1.charAt(i)*(11-i);
  d1 = 11 - (d1 % 11);
  if (d1>9) d1 = 0;
  
  if (rcpf2.charAt(1) != d1) 
    return false;
  return true;
}

//-------------------------------
function isDigit (c){   
   return ((c >= "0") && (c <= "9"))
}  

//-------------------------------
function isInteger (s) {
    var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return false;
     
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

//-------------------------------
function isEmpty(s){
    return ((s == null) || (s.length == 0))
}

//-------------------------------
// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// 
// isIntegerInRange = true se s &eacute; inteiro dentro dos limites, inclusive
// 
// emptyOK se for opcional deve ser true
function isIntegerInRange (s, a, b){
   if (isEmpty(s)) return false;
    if (!isInteger(s)) return false;
    var num = (s);
    
    return ((num >= a) && (num <= b));
}
//-------------------------------
function isMes (s){
   if (isEmpty(s)) return false;
   return isIntegerInRange (s, 1, 12);
}
//-------------------------------
function isDia (s) {
    if (isEmpty(s)) return false;
    return isIntegerInRange (s, 1, 31);
}
//-------------------------------
function isAno (s) {
    if (isEmpty(s)) return false;
    if (!isInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}
//-------------------------------
function diasInFevereiro (ano){
    return (  ((ano % 4 == 0) && ( (!(ano % 100 == 0)) || (ano % 400 == 0) ) ) ? 29 : 28 );
}

//-------------------------------
function ValidaData (dia, mes, ano, nome) {
  dias = new Array(13);
  dias[1] = 31;
  dias[2] = 29;   // deve ser verificado o caso de anos bissextos
  dias[3] = 31;
  dias[4] = 30;
  dias[5] = 31;
  dias[6] = 30;
  dias[7] = 31;
  dias[8] = 31;
  dias[9] = 30;
  dias[10] = 31;
  dias[11] = 30;
  dias[12] = 31;

  if (mes > 12){ 
     alert("Data inválido no campo '" + nome + "'");
	 return false; 
  }
  
  alert(dia);
  alert(dias[mes]);
  
  if (dia > dias[mes]){ 
     alert("Data inválido no campo '" + nome + "'"); 
	 return false; 
  }
  if ((mes == 2) && (dia > diasInFevereiro(ano))){ 
     alert("Dia inválido no campo '" + nome + "'"); 
	 return false; 
  }
  if (ano < 1000)
  {
     alert("O Ano deve ter 4 digitos: '" + nome + "'"); 
	 return false; 
  }	 
  return true;
}

//-------------------------------
function ValidaHora( hora, minutos, nome ){
   if ( hora.value<0 || hora.value>23 ){
     alert("Hora inválida no campo '" + nome + "'"); 
	 hora.focus(); 
	 return false; 
   }
   if ( minutos.value<0 || minutos.value>59 ){
     alert("Minutos inválidos no campo '" + nome + "'"); 
	 minutos.focus(); 
	 return false; 
   }
   return true;
}

//-------------------------------
function ValidaInteiro( n, minimo, maximo, nome ){
    if ( !isInteger(n.value) ){
       alert("Valor inválido no campo '" + nome + "'.");
	   n.focus();
	   return false;
    }
    if ( n.value<minimo || n.value>maximo ){
       alert("O valor do campo '" + nome + "' deve estar entre " + minimo + " e " + maximo + ".");
	   n.focus();
	   return false;
	}
    return true;
}


//-------------------------------
function ValidaSexoMFJ( s, nome ){
  if ( s.value!="M" && s.value!="F" && s.value!="J" )
  {
     alert("Valor incorreto no campo '" + nome + "'. Use M(masculino), F(feminino) ou J(jurídico).");
     s.focus();
	 return false;
  }
  return true;
}

//-------------------------------
function ValidaSexoMF( s, nome ){
  if ( s.value!="M" && s.value!="F" )
  {
     alert("Valor incorreto no campo '" + nome + "'. Use M(masculino) ou F(feminino).");
     s.focus();
	 return false;
  }
  return true;
}

//-------------------------------
function ValidaInt( campo, nome ){
  if ( !isInteger(campo.value) )
  {
     alert("Valor inválido no campo '" + nome + "'. Digite apenas números inteiros.");
     campo.focus();
	 return false;
  }
  return true;
}


//-------------------------------
function ValidaOpcnInteiro ( Campo, Nome, Vazia ){
  if ( isEmpty(Campo.Value) ){
     if ( Vazia ) return true;
	 alert("O campo '" + Nome + "' deve ser informado.");
	 Campo.focus();
	 return false;
  }
  if ( !isInteger(Campo.value) )
  {
     alert("Valor inválido no campo '" + Nome + "'. Digite apenas números inteiros.");
     Campo.focus();
	 return false;
  }
}

//-------------------------------
function ValidaReal( campo, nome ){
var s,m,i,c
s=new String(campo.value);
m=new String("");
for(i=0;i<s.length;i++){
   c=s.charAt(i);
   if ( c=="," ) 
      m=m+".";
   else
   if ( c!="." )
      m=m+c;
}

  if ( isNaN(Number(m)) )
  {
     alert("Valor inválido no campo '" + nome + "'.");
     campo.focus();
	 return false;
  }
  return true;
}

//validar e-mail
function ValidaEmail()
{
	if ( (window.event.keyCode>=65) && (window.event.keyCode<=90) ) //letras maiúsculas
		{
			window.event.keyCode=window.event.keyCode+32;  //tranforma letras maiúsculas em minúsculas
			return(true);
		}
	else
		{
			if ( ((window.event.keyCode>=97) && (window.event.keyCode<=122)) //letras minúsculas
				 || ((window.event.keyCode>=48) && (window.event.keyCode<=57))  //números
				 || (window.event.keyCode==46)   //ponto
				 || (window.event.keyCode==59)   //ponto e vírgula
				 || (window.event.keyCode==64)   //arroba
				 || (window.event.keyCode==95) ) //underline
				{
					return(true);
				}
			else
				{
					window.event.keyCode=0;
					return(false);				
				}
		}
}


//validar UserID
function ValidaUserID()
{
	if ( (window.event.keyCode>=65) && (window.event.keyCode<=90) ) //letras maiúsculas
		{
			//window.event.keyCode=window.event.keyCode+32;  //tranforma letras maiúsculas em minúsculas
			return(true);
		}
	else
		{
			if ( ((window.event.keyCode>=97) && (window.event.keyCode<=122)) //letras minúsculas
				 || ((window.event.keyCode>=48) && (window.event.keyCode<=57))  //números
				 || (window.event.keyCode==46)   //ponto
				 || (window.event.keyCode==95) ) //underline
				{
					return(true);
				}
			else
				{
					window.event.keyCode=0;
					return(false);				
				}
		}
}


//função: SomNumOuVirgula
//deve ser colocada no evento onkeypress de um objeto "input", para que
//o usuário digite apenas números ou vírgula
function SomNumOuVirgula()
{
  if ( ((window.event.keyCode>=48) && (window.event.keyCode<=57)) || (window.event.keyCode==44) )
     return(true)
  else
  {
     window.event.keyCode=0;
     return(false);
  }
}

//função: SomNum
//usada no evento "onkeypress" de um objeto "input", permite a digitação apenas de números
function SomNum()
{
	if ( (window.event.keyCode>=48) && (window.event.keyCode<=57) )
		return(true)
	else
	{
		window.event.keyCode=0;
		return(false);
	}
}

function SomData()
{
	if ( ((window.event.keyCode>=47) && (window.event.keyCode<=57)) )
		return(true)
	else
	{
		window.event.keyCode=0;
		return(false);
	}
}

function SoMaiuscula(campo)
{
	campo.value=campo.value.toUpperCase();
	return(campo);
}

function SoMinuscula(campo)
{
	campo.value=campo.value.toLowerCase();
	return(campo);
}


function SemAspas()
{
	//39: aspas simples    34: aspas duplas
	if ( (window.event.keyCode == 34) || (window.event.keyCode == 39) )
	{
		window.event.keyCode=0;
		return(false);
	}
}

function TrataTecla( vetor )
{
	Tam = vetor.length;
	for (i = 0; i <= Tam; i++)
	{
		if (  window.event.keyCode == vetor[i] )
		{
			window.event.keyCode = 0;
			return(false);
		}
	}
	return(true);
}

function ForcaTecla( vetor )
{
	Tam = vetor.length;
	MesmaTecla=false;
	for (i = 0; i < Tam; i++)
	{
		if (  window.event.keyCode == vetor[i] )
		{
		    MesmaTecla=true;
		}
	}
	if ( MesmaTecla==false ) {
    	window.event.keyCode = 0;
		return(false);
	}
	return(true);
}



function TudoIgual(field) {
  var str = field.value, primeiro='';
  for(i = 0; i < str.length; i++)
    if (str.charAt(i)>='0' && str.charAt(i)<='9')
      if (primeiro=='') primeiro = str.charAt(i);
      else if (str.charAt(i) != primeiro) return 0;
  return 1;
}

function CriaArray(n) {
  this.length=n;
  for (var i=1; i<=n; i++) this[i]=0;
  return this;
}

function Str2Int(str) {
  var value=0, i=0, digit=0;
  for(i=0; i < str.length; i++) {
    if (str.charAt(i)=='0') digit=0;
    if (str.charAt(i)=='1') digit=1;
    if (str.charAt(i)=='2') digit=2;
    if (str.charAt(i)=='3') digit=3;
    if (str.charAt(i)=='4') digit=4;
    if (str.charAt(i)=='5') digit=5;
    if (str.charAt(i)=='6') digit=6;
    if (str.charAt(i)=='7') digit=7;
    if (str.charAt(i)=='8') digit=8;
    if (str.charAt(i)=='9') digit=9;
    value=value+digit*Math.pow(10,str.length-i-1);
  }
  return value;
}

function Verifica_CPF_CGC(field) {

  var cpf='', cgc='', digito='', digitoc='', temp='', k=0; i=0, j=0, soma=0, mt=0, dg='';
 if (field.value=='') return; else cpf = field.value;

  if (((cpf.length > 13) && (cpf.length < 19)) && (cpf.substring(3,4) !='.')){
  if (cpf.length == 18) {
     temp = cpf.substring(0,2) + cpf.substring(3,6) + cpf.substring(7,10) + cpf.substring(11,15) + cpf.substring(16,18);
  }
  if (cpf.length == 16) {
     temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(9,13) + cpf.substring(14,16);
  }
  if (cpf.length == 15 && cpf.substring(12,13) == '-') {
     temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(8,12) + cpf.substring(13,15);
  }
  if (cpf.length == 15 && cpf.substring(8,9) == '/') {
     temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(9,13) + cpf.substring(13,15);
  }
  if (cpf.length == 14) {
     temp = cpf.substring(0,2) + cpf.substring(2,5) + cpf.substring(5,8) + cpf.substring(8,12) + cpf.substring(12,14);
  }
	  cgc = temp.substring(0,12);
	  digito = temp.substring(12,14);
   	  mult = '543298765432';
	  for (j = 1; j <= 2; j++) {
	    soma = 0;
	    for (i = 0; i <= 11; i++) {
	      k = i + 1;
	      soma += parseInt((cgc.substring(i,k)) * (mult.substring(i,k)));
	    }

	      if (j == 2){
			soma = soma + (2 * digitoc);
	      }
	      		digitoc = ((soma * 10) % 11);
	      if (digitoc == 10){
			digitoc = 0;
	      }
	     dg +=digitoc;
      	     mult = '654329876543';
	  }
	  //if (dg != digito || TudoIgual(field)) {
	  if (dg != digito) {	  
	    alert('O CGC informado não é válido!');
	    field.value = '';
	    field.focus();
	    return;
	    } 
	  else {
	    field.value=temp.substring(0,2)+'.'+temp.substring(2,5)+'.'+temp.substring(5,8)+'/'+temp.substring(8,12)+'-'+temp.substring(12,14);

	    return true;
	  }

  }
  else {
  if (cpf.length < 11) {
	alert( 'Informação inválida. Verifique!');
	field.value = '';
	field.focus();
	return false;
  }

  if (cpf.length == 11) {
     temp = cpf.substring(0,3) + cpf.substring(3,6) + cpf.substring(6,9) + cpf.substring(9,11);
  }
  if (cpf.length == 12) {
     temp = cpf.substring(0,3) + cpf.substring(3,6) + cpf.substring(6,9) + cpf.substring(10,12);
  } 
  if (cpf.length == 14) {
     temp = cpf.substring(0,3) + cpf.substring(4,7) + cpf.substring(8,11) + cpf.substring(12,15);
  }
	  cpf = temp.substring(0,9);
	  digito = temp.substring(9,11);
	  for (j = 1; j <= 2; j++) {
	    soma = 0;
	    mt = 2;
	    for (i = 8 + j; i >= 1; i--) {
	      soma += parseInt(cpf.charAt(i-1),10) * mt;
	      mt++;
	    }
	    dg = 11 - (soma % 11);
	    if (dg > 9) {dg = 0};
	    cpf += dg;
	  }

	  //if (digito != cpf.substring(9,11) || TudoIgual(field)) {
	  if (digito != cpf.substring(9,11)) {	  
	    alert('O CPF informado não é válido!');
	    field.value = '';
	    field.focus();
	    return true;
	    } 
	  else {
	    field.value=cpf.substring(0,3)+'.'+cpf.substring(3,6)+'.'+cpf.substring(6,9)+'-'+cpf.substring(9,11);
	    return true;
	  }
  } // fim if (cpf.length < 15)

return true;
}

function ChecaCartao(field) {

	var cartao = field.value;

  	if (cartao.length > 19 ) {
		alert('O Número do Cartão é inválido');
    		field.focus();
		return (false);
        }

	  	sum = 0; mul = 1;
		l = cartao.length;
	for (i = 0; i < l; i++) {
		digit = cartao.substring(l-i-1,l-i);
		tproduct = parseInt(digit ,10)*mul;
		if (tproduct >= 10)
	  		sum += (tproduct % 10) + 1;
		else
	  		sum += tproduct;
		if (mul == 1)
	  		mul++;
		else
		  	mul--;
	 }
	  	if ((sum % 10) == 0)
			return (true);
	  	else {
			alert('O Número do Cartão é inválido');
    			field.focus();
			return (false);
		}

}


function Virg2Ponto( campo ){
var s,m,i,c
s=new String(campo);
m=new String("");
for(i=0;i<s.length;i++){
   c=s.charAt(i);
   if ( c=="," ) 
      m=m+".";
   else
   if ( c=="." )
      m=m+",";
   else
      m=m+c;
}
return(m);
}

function Ponto2Virg( campo ){
var s,m,i,c
s=new String(campo);
m=new String("");
//alert("["+s.toUpperCase()+"]");
for(i=0;i<s.length;i++){
   c=s.charAt(i);
   if ( c=="." ) 
      m=m+",";
   else
   if ( c=="," )
      m=m+".";
   else
      m=m+c;
}
m=FormataDecimal(m);
return(m);
}

function FormataDecimal(campo) // Formata campos para duas casas decimais
{
   var StrCampo, StrDecimal, IntTempTam, IntCampoTam, IntPosVirg;
   StrCampo = new String(campo);
   IntCampoTam = StrCampo.length;
   IntPosVirg = StrCampo.indexOf(",");
   if (IntPosVirg > 0)
   {
      StrDecimal = StrCampo.slice(IntPosVirg+1, IntCampoTam);
      IntTempTam = StrDecimal.length;
   }
   else  
      IntTempTam = 0;
	  
   if (IntTempTam == 0)
   {
      StrCampo = StrCampo + ",00";
   }
   if (IntTempTam == 1)
   {
      StrCampo = StrCampo + "0";
   }
   if (IntTempTam > 2)
   {
      StrCampo = StrCampo.slice(0, IntPosVirg+3);
   }
   return(StrCampo);
}

function isReal( campo ){
var s,m,i,c
s=new String(campo.value);
m=new String("");
for(i=0;i<s.length;i++){
   c=s.charAt(i);
   if ( c=="," ) 
      m=m+".";
   else
   if ( c!="." )
      m=m+c;
}

  if ( isNaN(Number(m)) )
  {
     //alert("Valor inválido no campo '" + nome + "'.");
     campo.focus();
	 return false;
  }
  return true;
}

// Compara duas datas e retorna:
// -1 ->  se data1<data2
//  0 ->  se data1=data2
//  1 ->  se data1>data2
function ComparaDatas( dia1, mes1, ano1, dia2, mes2, ano2 ){
  var data1 = new Date(ano1,mes1,dia1)
  var data2 = new Date(ano2,mes2,dia2)
  
  var tm1=data1.valueOf();
  var tm2=data2.valueOf();
  if ( tm1<tm2 )  return(-1);
  if ( tm1==tm2 ) return(0);
  if ( tm1>tm2 )  return(1);
}

// Retira espaços no inicio e fim de uma string
function trim( s ){
   var m = new String( s );
   var i=0;

   while ( m.charCodeAt(0)==32 ) m=m.substr(1,m.length-1);           // retira espacos no inicio
   while ( m.charCodeAt(m.length-1)==32 ) m=m.substr(0,m.length-1);  // retira espacos no fim
   return(m);
}

function ConsisteCPF(nu_cpf)
{
 if (nu_cpf == null)
    {
     return false;
    }
 if (nu_cpf.length != 11)
    {
     return false;
    }
 for (i=0;i<nu_cpf.length;i++)
     {
      if (!((nu_cpf.substring(i,i+1) >= '0') && (nu_cpf.substring(i,i+1) <= '9')))
         {
          return false;
         }
     }
 nu_cpf_dv=nu_cpf.substring(9,11);
 nu_cpf = nu_cpf.substring(0,9);
 for (k=1;k<3;k++)
     {
      soma = 0;
      multi = 1;
      for (i=nu_cpf.length-1;i>=0;i--)
          {
          multi++;
          soma += (parseInt(nu_cpf.substring(i,i+1),10) * multi); 
           }
      resto = (soma % 11);
      dv =0;
      if (resto > 1)
         {
          dv= 11 - resto;
         }
      nu_cpf +=dv; 
     }
return (nu_cpf_dv == nu_cpf.substring(9,11));
}
function ValidaTexto(valor) {
	var i;
	// Testa se string vazia
	if (valor==''){
		return false;
	}
	else {
		// Testa se string só tem espaços
		for (i=0; i<valor.length; i++) {
			if (valor.substring(i,i+1)!=' ') return true;
		}
		return false;
	}
}

function FG_ValidaEmail(email) {
   if(email.indexOf('@') == -1) return false; 
   else return true;
}


//sergio 23/11/2002
var testresults

function checkemail(email){
 var str=email.value
 var filter=/^.+@.+\..{2,3}$/

 if (filter.test(str) && str.indexOf('@')>0 && str.indexOf(' ')<1 && str.indexOf('#')<1)
    testresults=true
 else {
    alert("E-mail Inválido !!!")
    testresults=false
    email.focus();
}
 return (testresults)
}

function checkbae(email){
if (email.value!="")
{
return checkemail(email)}
else
return true
}

//sergio
function TemProtocolo(endereco) {
	index = endereco.indexOf(':');
	if (index!=-1) {
		if (endereco.substring(index+1,index+3)=='//') {
			return true;
		}
		else {
			return false;
		}
	}
	else {
		return false;
	}
}
function FG_TiraBrancosData(Texto) 
{
  i=0;
	auxiliar="";
	while (i < Texto.length)
	{
	    if (Texto.charAt(i) == " ")
	       auxiliar = auxiliar + "";
	    else
		auxiliar = auxiliar + Texto.charAt(i);
		i++;
	}
	return auxiliar
}
function FG_ValData(SData)
{
 var Sano;
 var Smes;
 var Sdia;
  SData = FG_TiraBrancosData(SData);
  if ( !(SData.length==10) ) {
     return (false);
	  };
  Sdia = SData.substring(0,2);
  if (isNaN(Sdia)) {
     return(false);
	 };  
  Sdia = parseInt(Sdia,10);
  Smes = SData.substring(3,5);
  if (isNaN(Smes)) {
     return(false);
	 };  
  Smes = parseInt(Smes,10);
  Sano = SData.substring(6,10); 
  if (isNaN(Sano)) {
     return(false);
	 };  
  Sano = parseInt(Sano,10); 
  if ( Sano<0 ) { 
      return (false);
	  };
  if (Sano>2079) {
      return (false);
  }; 
  if (Sano<1900) {
      return (false);
  }; 
  if ((Sdia<1) || (Sdia>31)) { 
      return (false);
	  };
  if ((Smes<1) || (Smes>12)) { 
     return (false);
	  };
  if ( ((Smes==4) || (Smes==6) || (Smes==9) || (Smes==11)) && (Sdia > 30) ) {
      return (false);
  };
  if ( (Smes == 2) &&(Sdia > 29)) { 
     return (false);
	  };
  if ( (Smes == 2) && (Sdia == 29) && !(FG_Bissexto(Sano))) { 
     return (false);
	  };
   return (true);
}
function FG_Bissexto(ano)
{
  var resto;
  if (ano == 0) {
  return(true);
  }
  resto = (ano % 400);
  if (resto == 0) {
  return (true);
  }
  resto = (ano % 100);
  if (resto == 0) {
  return (false);
  }
  resto = (ano % 4);
  if (resto == 0) {
  return (true);
  }
  return (false);
}
function Data(dd,mm,aa){
  this.dia = dd;
  this.mes = mm;
  this.ano = aa;
  return this;
}
function TestaData(objdata,objidade){
	strnasc = objdata.value;
  if ((FG_ValData(strnasc))&&(strnasc.substring(2,3)=='/')&&(strnasc.substring(5,6)=='/')) {
	  dd = parseInt(strnasc.substring(0,2),10);
	  mm = parseInt(strnasc.substring(3,5),10);
	  aa = parseInt(strnasc.substring(6,strnasc.length),10);
		nasc  = new Data(dd,mm,aa);
		auxi  = new Date();
		if (auxi.getYear()==99) anocerto = 1999;
		else                    anocerto = 2000 + auxi.getYear();
		hoje  = new Data(auxi.getDate(),auxi.getMonth()+1,anocerto);
		idade = hoje.ano - nasc.ano;
		if (idade >= 0) {
		  difmes = hoje.mes - nasc.mes;
		  if (difmes < 0) idade = idade - 1;
		  else {
				if (difmes == 0) {
				  difdia = hoje.dia - nasc.dia;
				  if (difdia < 0) idade = idade - 1;
				}
		  }
		  if (idade >= 2000) idade = idade - 2000;
		  else               idade = idade;
		  if (idade > 100) idade = idade - 100;
		  else             idade = idade;
		  if ((objidade.name!='dump')&&((idade < 14)||(idade > 80))) {
				alert('A idade deve estar entre 14 e 80 anos!');
				objidade.value = '';
				objdata.focus();
				objdata.select();
		  }
		  else objidade.value = idade;
		}
  }
	else {
	  if (strnasc.length!=0) {
		  alert('Data inválida ou formato incorreto.\nFormato: dd/mm/aaaa.');
		  objdata.value  = '';
		  objidade.value = '';
		  objdata.focus();
		}
	}
}
function TestaNum(campo,digitos){
  if (campo.value.length < digitos) {
    alert('CEP inválido. Faltam dígitos.');
  }
  var num = parseInt(campo.value,10)
  if ((num == 0)&&(campo.value.length!=3)) {
    alert('CEP inválido. Não é um número.');
  }
}

function TestaDDD(campo,digitos){
  if (campo.value.length < digitos) {
    alert('DDD inválido. Faltam dígitos. Exemplo 041');
    campo.value = ''
    campo.focus();
    campo.select(); 
  }
 
}


function Tecla(e)  
			{  
				if(document.all)   
					var tecla = event.keyCode;  
				else if(document.layers)   
					var tecla = e.which;
				else if (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"))
					var tecla = e.which;

				
				if(tecla > 47 && tecla < 58)   
					return true;  
				else  
				{  
					if (tecla != 8)   
						return false;  
					else  
						return true;  
				}
			}  


function TestaSalario(controle){
  var sal = parseInt(controle.value,10)
  if ((sal < 180)||(sal > 4999)) {
		alert('O salário deve estar entre R$180,00 e R$4.999,00 !');
		controle.value='';
  }
}

function openWindow(url) {
  popupWin = window.open(url,'new_page','width=400,height=400')
}
function openWindow2(url) {
  popupWin = window.open(url,'new_page','width=400,height=450')
}
function openWindow3(url) {
  popupWin = window.open(url,'new_page','width=400,height=450,scrollbars=yes')
}
function openWindow4(url) {
  popupWin = window.open(url,'new_page','width=400,height=525')
}
function openWindow5(url) {
  popupWin = window.open(url,'new_page','width=580,height=550,scrollbars=yes,toolbars=yes,menubar=yes,resizable=yes')
}


// Função utilizada para validação de CPF e CNPJ
function modulo(str) {

   	soma=0;
   	ind=2;
   	for(pos=str.length-1;pos>-1;pos=pos-1) {
   		soma = soma + (parseInt(str.charAt(pos)) * ind);
   		ind++;
   		if(str.length>11) {
   			if(ind>9) ind=2;
   		}
	}
   	resto = soma - (Math.floor(soma / 11) * 11);
   	if(resto < 2) {
    	return 0
   	}
   	else {
   		return 11 - resto
   	}
}

// Função para validação do CPF
function VerificaCPF(valor) {

	primeiro=valor.substr(1,1);
	falso=true;
	size=valor.length;
	if (size!=11){
		return false;
	}
	size--;
	for (i=2; i<size-1; ++i){
		proximo=(valor.substr(i,1));
		if (primeiro!=proximo) {
			falso=false
		}
	}
	if (falso){
		return false;
	}
   	if(modulo(valor.substring(0,valor.length - 2)) + "" + modulo(valor.substring(0,valor.length - 1)) != valor.substring(valor.length - 2,valor.length)) {
   		return false;
   	}
   	return true
}


// Função para validação do cnpj
function VerificaCNPJ(valor) {

	primeiro=valor.substr(1,1);
	falso=true;
	size=valor.length;
	if (size!=14){
		return false;
	}
	size--;
	for (i=2; i<size-1; ++i){
		proximo=(valor.substr(i,1));
		if (primeiro!=proximo) {
			falso=false
		}
	}
	
	if (falso){
		return;
	}
	
   	if(modulo(valor.substring(0,valor.length - 2)) + "" + modulo(valor.substring(0,valor.length - 1)) !=valor.substring(valor.length - 2,valor.length)) {
   		return false;
   	}
   	return true
}