//Exibir o Span na tela
/*if(typeof document.attachEvent!='undefined') {
   window.attachEvent('onload',init);
   document.attachEvent('onmousemove',moveMouse);
   document.attachEvent('onclick',checkMove);
} else {
   window.addEventListener('load',init,false);
   document.addEventListener('mousemove',moveMouse,false);
   document.addEventListener('click',checkMove,false);
  }  */
  
//Validação do Email
function ValidaEmail(cadastro){
  var obj = eval("document.forms[0].email");
  var txt = obj.value;
  if((txt.length != 0) && ((txt.indexOf("@") < 1) || (txt.indexOf('.') < 7))) {
     alert('E-MAIL incorreto!')
	 document.forms[0].email.focus();
	 document.forms[0].email.select();
     return false;
  }
}

//Validação do Email
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);
}

//Transforma o CPF na mascara 999.999.999-99
function TransformaCPF(cpf){
   var mydata = '';
   mydata = mydata + cpf.value;
   if (mydata.length == 3){
      mydata = mydata + '.';
      cpf.value = mydata;
   }
   if (mydata.length == 7){
      mydata = mydata + '.';
      cpf.value = mydata;
   }
   if (mydata.length == 11){
      mydata = mydata + '-';
      cpf.value = mydata;
   }
}

//Validação do CPF
function Verifica_CPF(campo) {
   var cpf = campo.value; // Recebe o valor digitado no campo
   var CPF = cpf.substr(0,3)+cpf.substr(4,3)+cpf.substr(8,3)+cpf.substr(12,2);
   // Aqui começa a checagem do CPF
   var POSICAO, I, SOMA, DV, DV_INFORMADO;
   var DIGITO = new Array(10);
   DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado
   // Desemembra o número do CPF na array DIGITO
   for(I=0; I<=8; I++) {
      DIGITO[I] = CPF.substr( I, 1);
   }
   // Calcula o valor do 10º dígito da verificação
   POSICAO = 10;
   SOMA = 0;
   for (I=0; I<=8; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
   DIGITO[9] = SOMA % 11;
   if (DIGITO[9] < 2) {
        DIGITO[9] = 0;
   } else{
        DIGITO[9] = 11 - DIGITO[9];
     }
   // Calcula o valor do 11º dígito da verificação
   POSICAO = 11;
   SOMA = 0;
   for (I=0; I<=9; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
   DIGITO[10] = SOMA % 11;
   if (DIGITO[10] < 2) {
        DIGITO[10] = 0;
   } else{
        DIGITO[10] = 11 - DIGITO[10];
     }
   // Verifica se os valores dos dígitos verificadores conferem
   DV = DIGITO[9] * 10 + DIGITO[10];
   if(DV != DV_INFORMADO || CPF == '11111111111') {
      alert('CPF inválido');
      //campo.value = ''; //para limpar o campo
      campo.focus();
      return false;
   }
}

/*//Validação do Título de Eleitor
function VerificaTituloEleitor(campo) {
   var te = campo.value;
   if(te.length == 0){
      return true;
   }
   if(!(isInteger(te))){
      alert("O Título de Eleitor deve ser numérico!");
      campo.focus();
      campo.select();
      return false
   }
   if(!(te.length == 12)){
      alert("O número do Título de Eleitor esta incompleto!");
      campo.focus();
      campo.select();
      return false
   }
   te = te.value.substr(11,2);
   j = te.value.substr(9,2);
   if((j<1) || (j>28)){
      alert("O número do Título de Eleitor esta inválido!");
      campo.focus();
      campo.select();
      return false
   }
   var d1 = 0;
   for(i=0;i<9;i++){
      d1 += te.value.charAt(i)*(10-i);
   }
   d1 = (d1 % 11);
   if(d1 <= 1){
      if(j <= 2){
         d1 = 1 - d1;
      } else{
           d1 = 0;
        }
   } else{
        d1 = 11 - d1;
     }
   if(te.charAt(0) != d1){
      alert("O número do Título de Eleitor esta inválido!");
      campo.focus();
      campo.select();
      return false
   }
   d1 *= 2;
   for(i=9;i<11;i++){
      d1 += te.value.charAt(i)*(13-i);
   }
   d1 = (d1 % 11);
   if(d1 <= 1){
      if(j <= 2){
         d1 = 1 - d1;
      } else{
           d1 = 0;
        }
   } else{
        d1 = 11 - d1;
     }
   if(te.charAt(1) != d1){
      alert("O número do Título de Eleitor esta inválido!");
      campo.focus();
      campo.select();
      return false
   }
   alert("O número do seu Título de Eleitor esta correto, PARABÉNS!");
   return true;
}


//Validação do Título de Eleitor   ainda não esta correta deve ser revista
function Verifica_TituloEleitor(campo) {
   var te = campo.value;
   if(te.length == 0){
      alet("TE não pode ser fazio");
      return false;
   }
   if(te.isInteger){
       if(te.length != 12){
          alert("A quantidade de números do Título de Eleitor não esta correta!");
          campo.focus();
          campo.select();
          return false;
       }
       te = te.substr(11,2);
       var j = te.substr(9,2);
       if((j<1) || (j>28)){
          alert("O número do Título de Eleitor esta inválido!");
          campo.focus();
          campo.select();
          return false;
       }
       var d1 = 0;
       for(i=0;i<9;i++){
          d1 += te.charAt(i)*(10-i);
       }
       d1 = (d1 % 11);
       if(d1 <= 1){
          if(j <= 2){
             d1 = 1 - d1;
          } else{
               d1 = 0;
            }
       } else{
            d1 = 11 - d1;
         }
       if(te.charAt(0) != d1){
          alert("O número do Título de Eleitor esta inválido!");
          campo.focus();
          campo.select();
          return false;
       }
       d1 *= 2;
       for(i=9;i<11;i++){
          d1 += te.charAt(i)*(13-i);
       }
       d1 = (d1 % 11);
       if(d1 <= 1){
          if(j <= 2){
             d1 = 1 - d1;
          } else{
               d1 = 0;
            }
       } else{
            d1 = 11 - d1;
         }
       if(te.charAt(1) != d1){
          alert("O número do Título de Eleitor esta inválido!");
          campo.focus();
          campo.select();
          return false;
       }
       alert("O número do seu Título de Eleitor esta correto, PARABÉNS!");
       return true;
    } else{
         alert("O Título de Eleitor deve ser numérico!");
         campo.focus();
         campo.select();
         return false;
      }
}
*/

//Transforma a Data de Nascimento na máscara dd/mm/aaaa
function TransformaDataNascimento(nascimento){
   var mydata = '';
   mydata = mydata + nascimento.value;
   if (mydata.length == 2){
      mydata = mydata + '/';
      nascimento.value = mydata;
   }
   if (mydata.length == 5){
      mydata = mydata + '/';
      nascimento.value = mydata;
   }
}

//Verificar o Ano Bissexto
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);
}

//Validação do campo Data de Nascimeto juntamente com o período de 14 a 80 anos
function ValidaDataNascimento(nascimento){
   var strnasc = nascimento.value;
   if(strnasc.length != 10){
      alert("A DATA de seu nascimento está incompleta!");
      nascimento.focus();
      nascimento.select();
      return false;
   } else{
        var dia = parseInt(strnasc.substring(0,2),10);
        var mes = parseInt(strnasc.substring(3,5),10);
        var ano = parseInt(strnasc.substring(6,10),10);
        if(isNaN(dia) || isNaN(mes) || isNaN(ano)){
           alert("A Data de seu nascimento não pode contér caracteres nem símbolos");
           nascimento.focus();
           nascimento.select();
           return(false);
        }
        if(dia < 1 || dia > 31){
           alert("O DIA do seu nascimento não pode ser inferior a 1 ou superior a 31");
           nascimento.focus();
           return false;
        }
        if(mes < 1 || mes > 12){
           alert("O MÊS do seu nascimento não pode ser inferior a 1 ou superior a 12");
           nascimento.focus();
           return false;
        }
        if(ano < 1928 || ano > 1994){
           alert("O ANO do seu nascimento não pode ser inferior a 1928 ou superior a 1994");
           nascimento.focus();
           return false;
        }
        if(((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11)) && (dia > 30)){
           alert("O DIA do seu nascimento não pode ser superior a 30");
           nascimento.focus();
           return false;
        }
        /*if((mes == 2) && (dia > 28)){
           alert("O DIA do seu nascimento não pode ser superior a 28");
           document.cadastro.nascimento.focus();
           return false;
        }*/
        if((mes == 2) && (dia == 29) && !(FG_Bissexto(ano))){
           alert("O DIA do seu nascimento não pode ser superior a 28, não se trata de ano Bissexto");
           nascimento.focus();
           return false;
        }
     }
}

//Não permite incluir letras somente Números
function SomenteNumero(objeto){
   if(event.keyCode < 48 || event.keyCode > 57){
      alert("Este campo só aceita números");
      event.keyCode = 0;
   }
}

//Não permite incluir letras somente Números e Monta a mascara 9999-9999
function VerificaTelefone(objeto){
	if (objeto.value.indexOf("-") == -1 && objeto.value.length > 5){
		objeto.value = ""; 
	}
	if (objeto.value.length == 4){
		objeto.value +="-";
	}
	   if(event.keyCode < 48 || event.keyCode > 57){
      alert("Este campo só aceita números");
      event.keyCode = 0;
   }

}
//Carrega os campos do Ano quando for Estagiário ou os campos Empresa, Data Emissão/Demissão e Atribuições
function camadaSelect(idCamada, Campo, Foco, Valor, Tipo){ // <select>
   if(Tipo == "!=") {
	  if(d.getElementById(Campo).value != Valor) {
		 Ativo = true;
	     d.getElementById(idCamada).style.display = "block"
	  } else{
		   Ativo = false;
		   d.getElementById(idCamada).style.display = "none"
		}
   } else{
		if(d.getElementById(Campo).value == Valor) {
		   Ativo = true;
		   d.getElementById(idCamada).style.display = "block"
		} else{
			 Ativo = false;
			 d.getElementById(idCamada).style.display = "none"
		  }
	 }
	 if(Foco && Ativo) {
		d.getElementById(Foco).focus();
     }
	 return;
}

/*//Limpa os campos Função e Área
function limpaSelect(destino) {
	var obj = d.getElementById(destino);
	obj.options.length = 0;
	eval(obj.options[obj.options.length] = new Option('Função não encontrada!',''));
	d.getElementById('nomeFuncao').value = '';
	d.getElementById('divArea').innerHTML = 'Seleciona a função';
}*/

//Conta a quantidade de caracteres e ao mesmo tempo não permite ser digitado mais nenhum acima do Limite
function contador(Campo, idContador, Limite){
   var Maximo = Limite ? Limite : 500;
   var field = d.getElementById(Campo);
   var txtField = d.getElementById(idContador);
   if(field && field.value.length > Maximo){
      field.value = field.value.substring(0, Maximo);
      alert("Limite de "+Maximo+" letras.");
   }
   if(txtField){
      txtField.innerHTML = Maximo - field.value.length;
   }
}

//Mensagem do link de Alteração no Cad5.php
function Mensagem(valor){
   if(valor == 1){
      alert("Para ALTERAR o registro você deve excluir e em seguida incluir um novo");
   }
}

//Exclui experiência
function ExcluirExperiencia(url,confirma){
   if(confirma){
      var pergunta = confirm(confirma)
	  if(pergunta == true){
		 variavel = 1;
	  } else{
	       variavel = 0;
	    }
   }
   if(variavel == 1){
      var req2 = null;
      if(window.XMLHttpRequest){
         req2 = new XMLHttpRequest();
         //req2.onreadystatechange = processReqChange;
         req2.open('GET',url,true);
         req2.send(null);
      } else if(window.ActiveXObject){
           req2 = new ActiveXObject('Microsoft.XMLHTTP');
           if(req2){
              //req2.onreadystatechange = processReqChange;
              req2.open('GET',url,true);
              req2.send();
           }
        }
      alert("Seu Registro foi EXCLUÍDO.");
      location.href='cad5.php';
   }
}

//Carregar a tabela CBO com o que foi digitado na pesquisa
function loadXMLDoc(url,valor){
   req = null;
   if (window.XMLHttpRequest) {
       req = new XMLHttpRequest();
       req.onreadystatechange = processReqChange;
       req.open("GET", url+'?categoria='+valor, true);
       req.send(null);
   } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url+'?categoria='+valor, true);
            req.send();
        }
     }
}
function processReqChange(){   //Verifica quando o estado esta completado
   if (req.readyState == 4) {
       if (req.status == 200) {
           document.getElementById('atualiza').innerHTML = req.responseText;
       } else {
            alert("Houve um problema ao obter os dados:\n" + req.statusText);
         }
   }
}
function Atualiza(valor){   //Recebe o valor digitado na pesquisa
    loadXMLDoc("localiza_cbo.php",valor);
}

//Exibir o envio de vaga para um amigo
function checar() {
if (document.indique.radio.checked == true) {
  document.getElementById('texto').style.display='block';
  } else {
  document.getElementById('texto').style.display='none' ;
  }
}

//Envia um email de vagas para um amigo
function envia() {
   if(document.indique.nome.value == ''){
      alert('O campo Nome é de preenchimento obrigatório.');
      document.indique.nome.focus();
      return false;
   } else if(document.indique.nome_amigo.value == ''){
      alert('O campo Nome do Amigo é de preenchimento obrigatório.');
      document.indique.nome_amigo.focus();
      return false;
   } else if(document.indique.email_amigo.value == ''){
	  alert('O campo E-mail é de preenchimento obrigatório.');
	  document.indique.email_amigo.focus();
	  return false;
   } else if(document.indique.mensagem.value == ''){
	  alert('O campo Mensagem é de preenchimento obrigatório.');
	  document.indique.mensagem.focus();
	  return false;
   }
}

//Valida o E-MAIL digitado pelo usuário .
function ValidarEmail_Cadastro(campo){
   var EMail = campo.value;
   //var EMail = document.indique.email_amigo.value;
   if(EMail.indexOf("@") < 0){
      alert("E-MAIL inválido!");
      campo.focus();
      return false;
   }
   if(EMail.indexOf(".") < 0){
      alert("E-MAIL inválido!");
      campo.focus();
      return false;
      }
   if(ContemDominio(EMail, " ;,:/$!#%^&*()+[]{}|\\~`'\"")){
      alert("E-MAIL inválido!");
      campo.focus();
      return false;
   }
   return true;
}

function ContemDominio(StrDado, Dominio){
   var i, j;
   if(StrDado != ""){
      for(i=0; i<StrDado.length; i++){
          for(j=0; j<Dominio.length; j++){
              if(StrDado.substr(i,1) == Dominio.substr(j,1)){
                 return true;
              }
		  }
	   }
   }
   return false;
}


