function verificaEmail(v,alertar) {
	if((alertar == 'undefined') || (alertar == null)){alertar=0;}
	var filtro=/^.+@.+\..{2,3}$/;
	if (filtro.test(v.value) == false) {
		if (alertar==1){ alert("E-Mail Incorreto!"); }
		return false;
	}
	else{ return true; alert("true");}
}
function verificaTel(c){
	if (c.value=="" || c.value==null) { return false;} 
	else{
	c.value=c.value.replace(/\D/g,"") //Remove tudo o que não é dígito
	return true;
	}
}

function formatar_mascara(src, mascara, tam) {
	var campo = src.value.length;
	var saida = mascara.substring(0,1);
	var texto = mascara.substring(campo);
	if(texto.substring(0,1) != saida) {
		src.value += texto.substring(0,1);
	}
	if (src.value.length>=tam) {
		src.value=src.value.substring(0,tam);
	}
}
function verificaCampo(src){
	campo = src.value;
	campo=campo.toString();
	campo=campo.replace(/^\s+|\s+$/g,"");
	src.value=campo;
	if (src.value == '' || src.value == null){return false;} 
	else {return true;}
}
function limpanews(){
d = document.newsl;

if (d.newsmail.value == ""){
d.newsemail.value="insira seu e-mail aqui";
} else {
	if(d.newsmail.value == "insira seu e-mail aqui"){
	d.newsemail.value='';
	}
}
d.style.backgroundColor=blue;
document.getElementById[newsmail].style.backgroundColor = blue;
}
function conta(){
       document.ftrabconosco.char.value= 250 - document.ftrabconosco.apresenta.value.length + " caracteres restantes"
	   document.ftrabconosco.char2.value= 250 - document.ftrabconosco.experiencia.value.length + " caracteres restantes"
	   document.ftrabconosco.char3.value= 250 - document.ftrabconosco.formacao.value.length + " caracteres restantes"
	   document.ftrabconosco.char4.value= "Total de " + document.ftrabconosco.curriculo.value.length + " caracteres"
}
//validar trabalhe conosco
function validaTudo(){
var f = document.ftrabconosco;
var alerta = 0;
var msg = new String("Por favor preencha o(s) seguinte(s) campo(s) corretamente: \n");

if (!verificaCampo(f.nome)) { alerta=1; msg = msg + "*Nome\n";}
if (!validarCPF(f.cpf)) { alerta=1; msg = msg + "*CPF\n";}
if (!verificaEmail(f.email)) { alerta=1; msg = msg + "*E-Mail\n";}
if (!verificaTel(f.tel)) { alerta=1; msg = msg + "*Telefone\n";}
//if (!f.trabtipo.checked) { alerta=1; msg = msg + "*Tipo do trabalho\n";}
if (!f.trabtipo.selectedIndex!=0) { alerta = 1; msg = msg + "*Tipo do trabalho\n";}
if (!f.interesse.selectedIndex!=0) { alerta = 1; msg = msg + "*Area de Interesse\n";}
if (!f.comosoube.selectedIndex!=0) { alerta = 1; msg = msg + "*Como chegou ao site\n";}
if (f.apresenta.value=="" || f.apresenta.value==null) { alerta = 1; msg = msg + "*Apresentação\n";} 
if (f.website.value=="http://") { f.website.value = "";}

if (alerta == 0){ return true;} 
else { alert(msg); return false; }
}
//validar contato
function validaContato(){
var f = document.fcontato;
var alerta = 0;
var msg = new String("Por favor preencha o(s) seguinte(s) campo(s): \n");

if (!verificaCampo(f.name)){alerta=1; msg = msg + "*Nome\n";}
if (!verificaEmail(f.email)) { alerta=1; msg = msg + "*E-Mail\n";}
if (!f.subject.selectedIndex!=0) { alerta = 1; msg = msg + "*Assunto\n";}
if (!verificaCampo(f.msg)){alerta=1; msg = msg + "*Mensagem\n";}

if (alerta == 0){ return true;} 
else { alert(msg); return false; }

}

// validar cpf novoo

function validarCPF(c){
   var cpf = c.value;
   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
   if(!filtro.test(cpf)){
     window.alert("CPF inválido. Tente novamente.");
	 return false;
   }
   
   cpf = remove(cpf, ".");
   cpf = remove(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"){
	  window.alert("CPF inválido. Tente novamente.");
	  return false;
   }

   soma = 0;
   for(i = 0; i < 9; i++)
   	 soma += parseInt(cpf.charAt(i)) * (10 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
	 resto = 0;
   if(resto != parseInt(cpf.charAt(9))){
	 window.alert("CPF inválido. Tente novamente.");
	 return false;
   }
   soma = 0;
   for(i = 0; i < 10; i ++)
	 soma += parseInt(cpf.charAt(i)) * (11 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
	 resto = 0;
   if(resto != parseInt(cpf.charAt(10))){
     window.alert("CPF inválido. Tente novamente.");
	 return false;
   }
   return true;
 }
 
 function remove(str, sub) {
   i = str.indexOf(sub);
   r = "";
   if (i == -1) return str;
   r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
   return r;
 }



