// 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 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.corel.value == 0)
  {
    alert("Selecione seu nível de conhecimento em Corel Draw ");
    theForm.corel.focus();
    return (false);
  }
  
          if (theForm.photo.value == 0)
  {
    alert("Selecione seu nível de conhecimento em Photoshop ");
    theForm.photo.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 caduser(theForm)
{
var reEmail = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

  if ((theForm.usuario.value).length < 5)
  {
    alert("O usuário deve conter no mínimo 5 caracteres");
    theForm.usuario.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);
  }
    /*  if (reEmail.test(theForm.email.value) == false)
  {
    alert("Digite um email válido");
    theForm.email.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.estadocivil.value == 0)
  {
    alert("Estado Civil não Informado");
    theForm.estadocivil.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.endereco.value).length < 8)
  {
    alert("Informe um endereço corretamente.");
    theForm.endereco.focus();
    return (false);
  }
  if ((theForm.bairro.value).length < 2)
  {
    alert("Informe um bairro corretamente.");
    theForm.bairro.focus();
    return (false);
  }
    if (theForm.listEstados.value == 0)
  {
    alert("Estado não Informado.");
    theForm.listEstados.focus();
    return (false);
  }
      if (theForm.listCidades.value == 0)
  {
    alert("Cidade não Informada.");
    theForm.listCidades.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.celular.value).length > 0) { 
 		 if (isNaN(theForm.celular.value)){
    			 alert ("Informe apenas números no campo Celular. Não use espaço ou caracteres especiais ex: ( ) / - .");
    			 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);
  }

  return (true);
  
}

function cadarea(theForm)
{
  if ((theForm.nomearea.value).length < 5)
  {
    alert("Digite corretamente o Nome da Área Profissional");
    theForm.nomearea.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.concluido.value).length == 0)
  {
    alert("Determine se o curso já foi concluído ou não");
    theForm.concluido.focus();
    return (false);
  }
  
   /* if (reData.test(theForm.inicio.value) == false)
  {
    alert("Data de Início do Curso inválida");
    theForm.inicio.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 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 < 30)
  {
    alert("Informe as atribuições do cargo com no mínino 30 caracteres.");
    theForm.atribuicoes.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 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";
	  }	  
   }