function vercpf (cpf) 
{if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
return false;
add = 0;
for (i=0; i < 9; i ++)
add += parseInt(cpf.charAt(i)) * (10 - i);
rev = 11 - (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(9)))
return false;
add = 0;
for (i = 0; i < 10; i ++)
add += parseInt(cpf.charAt(i)) * (11 - i);
rev = 11 - (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(10)))
return false;
return true;}



function validaCNPJ(CNPJ) {
  erro = new String;
  if (CNPJ.length < 18) erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
  if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
  if (erro.length == 0) erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
  }
  //substituir os caracteres que nao sao numeros
  if(document.layers && parseInt(navigator.appVersion) == 4){
  x = CNPJ.substring(0,2);
  x += CNPJ.substring(3,6);
  x += CNPJ.substring(7,10);
  x += CNPJ.substring(11,15);
  x += CNPJ.substring(16,18);
  CNPJ = x; 
  } else {
  CNPJ = CNPJ.replace(".","");
  CNPJ = CNPJ.replace(".","");
  CNPJ = CNPJ.replace("-","");
  CNPJ = CNPJ.replace("/","");
  }
  var nonNumbers = /\D/;
  if (nonNumbers.test(CNPJ)) erro += "A verificacao de CNPJ suporta apenas numeros! \n\n"; 
  var a = [];
  var b = new Number;
  var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
  for (i=0; i<12; i++){
  a[i] = CNPJ.charAt(i);
  b += a[i] * c[i+1];
  }
  if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
  b = 0;
  for (y=0; y<13; y++) {
  b += (a[y] * c[y]); 
  }
  if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
  if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
  erro +="Digito verificador com problema!";
  }
  if (erro.length > 0){
  alert(erro);
  return false;
  } else {
 // alert("CNPJ valido!");
  }
  return true;
}

function validaFormGeral(){
	obj = document.getElementsByTagName("input");
	
	for (i=0;i<obj.length;i++){
		
		if (obj[i] != null){
			if (obj[i].className == "obrigatorio")
			{
				
				switch(obj[i].type)
				{
					
					case "text":
					
						if(obj[i].value == ""){
							
							obj[i].focus();
							alert("Preencha o campo "+obj[i].title)
							return false;
						}
											
						
						
						if (obj[i].name == "end_eletronico")
						{
							if (validaEmail(obj[i].value)== false)
							{
								alert("E-mail inválido");
								obj[i].focus();
								return false;
							}
						}
						if (obj[i].name == "ddd_telefone")
						{
							if (isNumeric(obj[i].value)== false)
							{
								alert("DDD inválido, digite somente números");
								obj[i].focus();
								return false;
							}
						}
						if (obj[i].name == "telefone")
						{
							if (isNumeric(obj[i].value)== false)
							{
								alert("Telefone, digite somente números");
								obj[i].focus();
								return false;
							}
						}
						
						break;						
				}
				
			}
			if (obj[i].className == "caixa")
			{
				if ((obj[i].name == "ddd_celular") && (obj[i].value != ""))
				{
					if (isNumeric(obj[i].value) == false)
					{
						alert("DDD inválido, digite somente números");
						obj[i].focus();
						return false;	
					}
				}
				if (obj[i].name == "celular")
				{
					
					if ( (obj[i].value != "") || (document.getElementById("ddd_celular").value != "") )
					{
						if(obj[i].value == "")
						{
							
							alert("Preencha o campo "+obj[i].title)
							obj[i].focus();
							return false;
						}
						if (isNumeric(obj[i].value) == false)
						{
							alert("Celular inválido, digite somente números");
							obj[i].focus();
							return false;	
						}
					}
				}
				if ( (obj[i].name == "ddd_telefone") && (obj[i].value != ""))
				{
					if (isNumeric(obj[i].value)== false)
					{
						alert("DDD inválido, digite somente números");
						obj[i].focus();
						return false;
					}
				}
				if (obj[i].name == "telefone")
				{
					if ( (obj[i].value != "") || (document.getElementById("ddd_telefone").value != "") )
					{
						
						if(obj[i].value == "")
						{
							
							alert("Preencha o campo "+obj[i].title)
							obj[i].focus();
							return false;
						}
						if (isNumeric(obj[i].value)== false)
						{
							alert("Telefone inválido, digite somente números");
							obj[i].focus();
							return false;
						}
					}
				}
				
				
			}
		}
		
	}
	return true;
}


function validaData(data)
{
	var expre =	/^(0?[1-9]|[12]\d|3[01])\/(0?[1-9]|1[0-2])\/(19|20)?\d{2}$/;
	if (expre.test(data) == false)
	{
		return false;
	}
	return true
}
function isNumeric(valor)
{
   	var valor_text;
    var vetor;
    var cont;

    valor_text = valor;
    vetor = "";
    cont = 0;    

    for(var i = 0; i < valor_text.length; i++)
    {
  		if (valor_text.charCodeAt(i) < 43 || valor_text.charCodeAt(i) > 58)
	  	{
		  vetor = vetor + valor_text.charAt(i);
		  cont++;
	 	}
	}
    
    if(cont == 0)
    {
  		return true;    
    }
    else
    {
  		return false;
    }
}
function validaEmail(email)
{
	
	var reTipo = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	return reTipo.test(email);

}
function validaData(data)
{
	var expre =	/^(0?[1-9]|[12]\d|3[01])\/(0?[1-9]|1[0-2])\/(19|20)?\d{2}$/;
	if (expre.test(data) == false)
	{
		return false
	}	
	return true;
}

function validaCont()
{
	if (validaFormGeral() == false)
	{
		return false;
	}
	if (document.getElementById("mensagem").value == "")
	{
		alert("Preencha o campo Mensagem");
		document.getElementById("mensagem").focus();
		return false;
	}
}
function validaTrab()
{
	if (validaFormGeral() == false)
	{
		return false;
	}
	
	if (document.getElementById("formacao").value == "")
	{
		alert("Informe sua formação escolar");
		document.getElementById("formacao").focus();
		return false;
	}
	if (document.getElementById("interesse").value == "")
	{
		alert("Informe sua área de interesse");
		document.getElementById("interesse").focus();
		return false;
	}
	if (document.getElementById("curriculo").value == "")
	{
		alert("Insira seu currículo");
		document.getElementById("curriculo").focus();
		return false;
	}
}
