// SCRIPTS JS
//MÁSCARA DE VALORES PARA CPF E DATA
function Mascara(tipo, campo, teclaPress) {
	if (window.event)
	{
		var tecla = teclaPress.keyCode;
	} else {
		tecla = teclaPress.which;
	}
 
	var s = new String(campo.value);
	// Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
 
	tam = s.length + 1;
 
	if ( tecla != 9 && tecla != 8 ) {
		switch (tipo)
		{
		case 'CPF' :
			if (tam > 3 && tam < 7)
				campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
			if (tam >= 7 && tam < 10)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
			if (tam >= 10 && tam < 12)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
		break;
 
		case 'CNPJ' :
 
			if (tam > 2 && tam < 6)
				campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
			if (tam >= 6 && tam < 9)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
			if (tam >= 9 && tam < 13)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
			if (tam >= 13 && tam < 15)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
		break;
 
		case 'TEL' :
			if (tam > 2 && tam < 4)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
			if (tam >= 7 && tam < 11)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
		break;
 
		case 'DATA' :
			if (tam > 2 && tam < 4)
				campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
			if (tam > 4 && tam < 11)
				campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
		break;
		}
	}
}
// FIM script mascara de data e cpf e outros..

function DataHora(evento, objeto){
	var keypress=(window.event)?event.keyCode:evento.which;
	campo = eval (objeto);
	if (campo.value == '00/00/0000 00:00:00')
	{
		campo.value=""
	}

	caracteres = '0123456789';
	separacao1 = '/';
	separacao2 = ' ';
	separacao3 = ':';
	conjunto1 = 2;
	conjunto2 = 5;
	conjunto3 = 10;
	conjunto4 = 13;
	conjunto5 = 16;
	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (19))
	{
		if (campo.value.length == conjunto1 )
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto2)
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto3)
		campo.value = campo.value + separacao2;
		else if (campo.value.length == conjunto4)
		campo.value = campo.value + separacao3;
		else if (campo.value.length == conjunto5)
		campo.value = campo.value + separacao3;
	}
	else
		event.returnValue = false;
}


function informatica(theForm)
{

  if (theForm.windows.value == 0)
  {
    alert("Selecione seu nível de conhecimento em Windows ");
    theForm.windows.focus();
    return (false);
  }
  
    if (theForm.word.value == 0)
  {
    alert("Selecione seu nível de conhecimento em Word ");
    theForm.word.focus();
    return (false);
  }
  
      if (theForm.excel.value == 0)
  {
    alert("Selecione seu nível de conhecimento em Excel ");
    theForm.excel.focus();
    return (false);
  }

    if (theForm.power.value == 0)
  {
    alert("Selecione seu nível de conhecimento em Power Point ");
    theForm.power.focus();
    return (false);
  }
  
    if (theForm.access.value == 0)
  {
    alert("Selecione seu nível de conhecimento em Access ");
    theForm.access.focus();
    return (false);
  }
   
        if (theForm.digitacao.value == 0)
  {
    alert("Selecione seu nível de Digitação ");
    theForm.digitacao.focus();
    return (false);
  }
  
  return (true);
}

function checkDelete() {
	
	if (confirm("Tem certeza que deseja excluir o item selecionado?") == true) {
		return true;
	} else {
		return false;
	}
	
}

function login(theForm)
{
  if (theForm.usuario.value == "")
  {
    alert("Por favor, digite o nome do usuário.");
    theForm.usuario.focus();
    return (false);
  }

  if (theForm.senha.value == "")
  {
    alert("Por favor, digite a senha.");
    theForm.senha.focus();
    return (false);
  }

  return (true);
}

function upuser(theForm)
{
  if ((theForm.cpf.value).length != 11)
  {
    alert("Digite um CPF válido");
    theForm.cpf.focus();
    return (false);
  }
}


function caduser(theForm)
{
var reEmail = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

     if (reEmail.test(theForm.email.value) == false)
  {
    alert("Digite um email válido");
    theForm.email.focus();
    return (false);
  } 

  if ((theForm.cpf.value).length != 11)
  {
    alert("Digite um CPF válido");
    theForm.cpf.focus();
    return (false);
  }
  
  if ((theForm.senha.value).length < 5)
  {
    alert("O senha deve conter no mínimo 5 caracteres");
    theForm.senha.focus();
    return (false);
  }
    if (theForm.senha.value != theForm.resenha.value)
  {
    alert("As senhas não conferem");
    theForm.resenha.focus();
    return (false);
  } 

  return (true);
}

function caddadospessoais(theForm)
{
	  
var reData = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;

  if ((theForm.nome.value).length < 10)
  {
    alert("Informe o nome completo corretamente.");
    theForm.nome.focus();
    return (false);
  }

  if (theForm.rg.value == false)
  {
    alert("RG não informado");
    theForm.rg.focus();
    return (false);
  } 

  if (reData.test(theForm.nascimento.value) == false)
  {
    alert("Data de Nascimento inválida");
    theForm.nascimento.focus();
    return (false);
  } 
  if (theForm.sexo.value == 0)
  {
    alert("Sexo não Informado");
    theForm.sexo.focus();
    return (false);
  }

  if (theForm.estadocivil.value == 0)
  {
    alert("Estado Civil não Informado");
    theForm.estadocivil.focus();
    return (false);
  }

  if ((theForm.cep.value).length == 0)
  {
    alert("Informe o CEP corretamente.");
    theForm.cep.focus();
    return (false);
  }

  if ((theForm.endereco.value).length == 0)
  {
    alert("Informe um endereço corretamente.");
    theForm.endereco.focus();
    return (false);
  }
  
  if ((theForm.num.value).length == 0)
  {
    alert("Informe número corretamente.");
    theForm.num.focus();
    return (false);
  }


  if ((theForm.bairro.value).length < 2)
  {
    alert("Informe um bairro corretamente.");
    theForm.bairro.focus();
    return (false);
  } 
  
 
    if (theForm.uf.value == 0)
  {
    alert("Estado não Informado.");
    theForm.uf.focus();
    return (false);
  }
      if (theForm.nmcidade.value == 0)
  {
    alert("Cidade não Informada.");
    theForm.cidade.focus();
    return (false);
  }
 /*  
  if ((theForm.telefone.value).length != 14)
   {
     alert ("Informe o telefone corretamente.");
     theForm.telefone.focus();
      return (false);
   }
 */  
   if ((theForm.celular.value).length != 14)
   {
     alert ("Informe o celular corretamente.");
     theForm.celular.focus();
      return (false);
   }

      if (theForm.deficiencia.value == 0)
  {
    alert("Informe se portador de Defiência ou não.");
    theForm.deficiencia.focus();
    return (false);
  }
      if (theForm.deficiencia.value == 1){
		  
   		if (theForm.tp_deficiencia.value == 0){
			alert("Foi informado como sendo portador de deficiência. Por favor, especifique o tipo de deficiência");
			theForm.tp_deficiencia.focus();
			return (false);
  			}
			
			 if ((theForm.tipodeficiencia.value).length < 5){
   				 alert("Foi informado como sendo portador de deficiência. Por favor, especifique sua deficiência");
				 theForm.tipodeficiencia.focus();
				 return (false);
  			}
	 }

      if (theForm.perfil.value == 0)
  {
    alert("Informe corretamente o perfil profissional.");
    theForm.perfil.focus();
    return (false);
  }

        if (theForm.habilitacao.value == 0)
  {
    alert("Informe corretamente o tipo de Habilitação");
    theForm.habilitacao.focus();
    return (false);
  }
         
		if (theForm.escolaridade.value == 0)
  {
    alert("Informe corretamente a Escolaridade.");
    theForm.escolaridade.focus();
    return (false);
  }

		  if (theForm.trabalhando.value == 0)
  {
    alert("Informe se está trabalhando atualmente ou não.");
    theForm.trabalhando.focus();
    return (false);
  }
		  if (theForm.filhos.value == 0)
  {
    alert("Informe a quantidade de filhos");
    theForm.filhos.focus();
    return (false);
  }

		  if (theForm.noite.value == 0)
  {
    alert("Informe se aceita trabalhar a noite");
    theForm.noite.focus();
    return (false);
  }

	  if (theForm.fds.value == 0)
  {
    alert("Informe se aceita trabalhar final de semana e feriado");
    theForm.fds.focus();
    return (false);
  }

	  if (theForm.indicacao.value == 0)
  {
    alert("Informe se possui indicação");
    theForm.indicacao.focus();
    return (false);
  }

	   if (theForm.indicacao.value == 'S')
  {
			if ((theForm.nm_indicacao.value).length < 10)
		  {
			alert("Foi informado que possui indicação. Por favor informe o nome da indicação");
			theForm.nm_indicacao.focus();
			return (false);
		  }
			  if (theForm.setor_indicacao.value == 0)
		  {
			alert("Foi informado que possui indicação. Por favor informe em qual setor a indicação trabalha");
			theForm.setor_indicacao.focus();
			return (false);
		  }
  }
	


  return (true);
  
}

function cadarea(theForm)
{
  if ((theForm.nomearea.value).length < 5)
  {
    alert("Digite corretamente o Nome da Área Profissional");
    theForm.nomearea.focus();
    return (false);
  }
  if (theForm.escolaridade.value == 0)
  {
    alert("Informe a escolaridade do cargo");
    theForm.escolaridade.focus();
    return (false);
  }
  
  return (true);
}

function cadobjetivos(theForm)
{
  if ((theForm.objetivos.value).length < 25)
  {
    alert("Descreva com mais detalhes seus objetivos");
    theForm.objetivos.focus();
    return (false);
  }
  return (true);
}

function cadcursos(theForm)
{

var reData = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;

  if ((theForm.instituicao.value).length < 4)
  {
    alert("Digite o nome completo da Instituição de Ensino.");
    theForm.instituicao.focus();
    return (false);
  }
    if ((theForm.curso.value).length < 5)
  {
    alert("Digite corretamente o nome do curso.");
    theForm.curso.focus();
    return (false);
  }
	if (theForm.turno.value == 0)
  {
    alert("Informe o turno do curso.");
    theForm.turno.focus();
    return (false);
  }
	if (theForm.tipo.value == 0)
  {
    alert("Informe o tipo do curso.");
    theForm.tipo.focus();
    return (false);
  }  
	if (theForm.concluido.value == 0)
  {
    alert("Determine se o curso já foi concluído ou não");
    theForm.concluido.focus();
    return (false);
  }
   
    if ((theForm.termino.value).length == 0)
  {
    alert("Informe a previsão ou data de Término do Curso.");
    theForm.termino.focus();
    return (false);
  }
  
      if (reData.test(theForm.termino.value) == false)
  {
    alert("Informe a data ou previsão de Término do Curso.");
    theForm.termino.focus();
    return (false);
  }
  
  return (true);
}

function cadespec(theForm)
{

var reData = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;

  if ((theForm.instituicao.value).length < 4)
  {
    alert("Digite o nome completo da Instituição de Ensino.");
    theForm.instituicao.focus();
    return (false);
  }
    if ((theForm.curso.value).length < 5)
  {
    alert("Digite corretamente o nome do curso.");
    theForm.curso.focus();
    return (false);
  }
	if (theForm.concluido.value == 0)
  {
    alert("Determine se o curso já foi concluído ou não");
    theForm.concluido.focus();
    return (false);
  }
   
    if ((theForm.termino.value).length == 0)
  {
    alert("Informe a previsão ou data de Término do Curso.");
    theForm.termino.focus();
    return (false);
  }
  

  
  return (true);
}


function cadexperiencias(theForm)
{
var reData = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;

  if ((theForm.empresa.value).length < 5)
  {
    alert("Digite o nome completo da Empresa.");
    theForm.empresa.focus();
    return (false);
  }
    if ((theForm.cargo.value).length < 5)
  {
    alert("Digite corretamente o cargo.");
    theForm.cargo.focus();
    return (false);
  }
    if (reData.test(theForm.inicio.value) == false)
  {
    alert("Data de Início da Experiência Inválida");
    theForm.inicio.focus();
    return (false);
  }
if (theForm.atualmente.checked == false)
{
		if (reData.test(theForm.termino.value) == false)
		{
			alert("Data de Término da Experiência Inválida");
			theForm.termino.focus();
			return (false);
		  }
}

if (theForm.atualmente.checked == true)
{
		if ((theForm.termino.value).length > 0)
	  {
		alert("Foi informado como trabalhando Atualmente. Não Informar data de Término.");
		theForm.termino.focus();
		return (false);
	  }
}
  if ((theForm.atribuicoes.value).length < 20)
  {
    alert("Informe as atividades realizadas com no mínino 20 caracteres.");
    theForm.atribuicoes.focus();
    return (false);
  }
  if ((theForm.salario.value).length == 0)
  {
    alert("Valor do salário Inválido.");
    theForm.salario.focus();
    return (false);
  }
  if ((theForm.contato.value).length == 0)
  {
    alert("Nome do responsável Inválido.");
    theForm.contato.focus();
    return (false);
  }
   if ((theForm.telefone.value).length == 0)
  {
    alert("Telefone do responsável Inválido.");
    theForm.telefone.focus();
    return (false);
  }
 /* if ((theForm.contato.value).length < 4)
  {
    alert("Informe o nome do Contato corretamente.");
    theForm.contato.focus();
    return (false);
  } 

  if ((theForm.telefone.value).length == 0)
  {
    alert("Informe o telefone de Contato.");
    theForm.telefone.focus();
    return (false);
  } */

  return (true);
}

function opcao_area(theForm){
   x =0;	
   if (theForm.opcao1.value == 0)
  {
	x = (x+1);
  }
   if (theForm.opcao2.value == 0)
  {
	x =(x+1);
  }
   if (theForm.opcao3.value == 0)
  {
	x =(x+1);
  }

  if (x >= 3) {
    alert("Indforme pelo menos uma das opções.");
    theForm.opcao1.focus();
    return (false);
  }
  return (true);
}

function alterasenha(theForm)
{
var reEmail = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
 
  if ((theForm.senha.value).length < 5)
  {
    alert("O senha deve conter no mínimo 5 caracteres");
    theForm.senha.focus();
    return (false);
  }
    if (theForm.senha.value != theForm.resenha.value)
  {
    alert("As senhas não conferem");
    theForm.resenha.focus();
    return (false);
  } 

  return (true);	
}

function cadareasatuacao(theForm)
{
  if (theForm.area.value == 0)
  {
    alert("Selecione a Área de Atuação a ser adicionada.");
    theForm.area.focus();
    return (false);
  }
  return (true);
}
 
 
   function Dados(valor) {
	  //verifica se o browser tem suporte a ajax
	  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
	  //se tiver suporte ajax
	  if(ajax) {
	     //deixa apenas o elemento 1 no option, os outros são excluídos
		 document.forms[0].listCidades.options.length = 1;
		    
		 idOpcao  = document.getElementById("opcoes");
		 
	     ajax.open("POST", "cidades.php", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 
		 ajax.onreadystatechange = function() {
            //enquanto estiver processando...emite a msg de carregando
//			if(ajax.readyState == 1) {
//			   idOpcao.innerHTML = "Carregando cidades...";   
//	        }
			//após ser processado - chama função processXML que vai varrer os dados
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
			      processXML(ajax.responseXML, form);
			   }
			   else {
			       //caso não seja um arquivo XML emite a mensagem abaixo
				   idOpcao.innerHTML = "Selecione um estado";
			   }
            }
         }
		 //passa o código do estado escolhido
	     var params = "estado="+valor;
         ajax.send(params);
      }
   }
   
   function processXML(obj, form){
      
	  	  //pega a tag cidade
      var dataArray   = obj.getElementsByTagName("cidade");
      
	  //total de elementos contidos na tag cidade
	  if(dataArray.length > 0) {
	     //percorre o arquivo XML paara extrair os dados
         for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			//contéudo dos campos no arquivo XML
			var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
			var descricao =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;
			
	        idOpcao.innerHTML = "Selecione";
			
			//cria um novo option dinamicamente  
			var novo = document.createElement("option");
			    //atribui um ID a esse elemento
			    novo.setAttribute("id", "opcoes");
				//atribui um valor
			    novo.value = codigo;
				//atribui um texto
			    novo.text  = descricao;
				//finalmente adiciona o novo elemento
				document.forms[0].listCidades.options.add(novo);
		 }
	  }
	  else {
	    //caso o XML volte vazio, printa a mensagem abaixo
		idOpcao.innerHTML = "Selecione um Estado";
	  }	  
   }
   
	function VerificaCPF () {
	if (vercpf(theForm.cpf.value)) 
	{document.form.submit();}else 
	{errors="1";if (errors) alert('CPF NaO VaLIDO');
	document.retorno = (errors == '');}}
	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;
	alert('O CPF INFORMADO e VaLIDO.');return false;}
