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(' ')<0 && str.indexOf('#')<0)
    {	for(var I =1;I <256;I++){
			if(I==30)
			{
				I=80;
			}
			if(str.indexOf(unescape("%"+I))> -1 || str.indexOf(",")> -1 || str.indexOf(":")> -1 || str.indexOf("/")> -1 || str.indexOf(";")> -1 || str.indexOf("www.")> -1 || str.indexOf("WWW.")> -1 || str.indexOf("+")> -1 || str.indexOf("*")> -1 || str.indexOf("~")> -1 || str.indexOf("^")> -1 || str.indexOf("=")> -1 || str.indexOf("\\")> -1 || str.indexOf("ª")> -1 || str.indexOf("º")> -1 || str.indexOf("°")> -1 || str.indexOf("|")> -1 || str.indexOf("¹")> -1 || str.indexOf("²")> -1 || str.indexOf("£")> -1 || str.indexOf("¢")> -1 || str.indexOf("¬")> -1 || str.indexOf("§")> -1 || str.indexOf("@.")> -1)
			{
				alert("E-mail Inválido !!!");
				I=256;
				testresults=false;
				email.focus();
				return (testresults);
			}
		}
	
        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
}

//Função nova que valida o email 
function checaEmail(email) {

	if (email.value == "") {
		alert("Informe seu e-mail.");
		email.focus();
		email.select();
		return false;
	} else {
		prim = email.value.indexOf("@")
		if(prim < 2) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
		if(email.value.indexOf("@",prim + 1) != -1) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
		if(email.value.indexOf(".") < 1) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
		if(email.value.indexOf(" ") != -1) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
		if(email.value.indexOf("zipmeil.com") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
		if(email.value.indexOf("hotmeil.com") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
		if(email.value.indexOf(".@") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
		if(email.value.indexOf("@.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
		if(email.value.indexOf(".com.br.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
		if(email.value.indexOf("/") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
		if(email.value.indexOf("[") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
		if(email.value.indexOf("]") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
		if(email.value.indexOf("(") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
		if(email.value.indexOf(")") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
		if(email.value.indexOf("..") > 0) {
			alert("O e-mail informado parece não estar correto.");
			email.focus();
			email.select();
			return false;
		}
	}
		return false;
}
//Fim da Validacao por Email

//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 TestaData2(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;
				}
		  }
		}
  }
	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!=""){
  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 < 300)||(sal > 19999)) {
		alert('O salário deve estar entre R$300,00 e R$19.999,00 !');
		controle.value='';
  }
}
function ValidaCNPJ(s)
{
	var c = s.value.substr(0,12);
	var dv = s.value.substr(12,2);
	var d1 = 0;
	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
	if (d1 == 0) return false;
		d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)	{
		alert("CNPJ Invalido");
		s.value="";
		s.focus();
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1){
		alert("CNPJ Invalido");
		s.value="";
		s.focus();
		return false;
		
	}
	return true;
	
} 



function ValidaCNPJSemLimpar(s)
{
	var c = s.value.substr(0,12);
	var dv = s.value.substr(12,2);
	var d1 = 0;
	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
	if (d1 == 0) return false;
		d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)	{
		alert("CNPJ Invalido");
		s.focus();
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1){
		alert("CNPJ Invalido");
		s.focus();
		return false;
		
	}
	return true;
	
}

	
