function checkNavegador (){
	try{
		return new XMLHttpRequest();
	}catch(ee){
		try{
		  return new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
		  try{
			 return new ActiveXObject("Microsoft.XMLHTTP");
		   }catch(E){
			 return false;
		   }
		}
	}	
}
//###################################################################################
function valCampTrabConosco() {
	if ($("#nome").val().length == 0) {
		alert(VldEndALERTcmpnome);
        $("#nome").focus();
        return false;
	}
       
	if ($("#sexo").val().length == 0) {
		alert(VldEndALERTcmpsexo);
        $("#sexo").focus();
        return false;
	}
	var data_nasc = $("#data_nasc_b3").val() + "-" + $("#data_nasc_b1").val() + "-" + $("#data_nasc_b2").val();
	if (!limpa_string(data_nasc)) {
		alert(VldEndALERTcmpdatanasc);
        $("#data_nasc_b1").focus();
        return false;
	}
	$("#data_nasc").val(data_nasc);
	
  
	var cpf_cob = $("#cpf_b1").val() + $("#cpf_b2").val() + $("#cpf_b3").val() + $("#cpf_b4").val();

	if (cpf_cob.length == 0) {
		alert(VldEndALERTcmpcpf);
		$("#cpf_b1").focus();
		return false;
	}

	s = limpa_string(cpf_cob);
	if (s.length == 11) {
		if (valida_CPF(cpf_cob) == false ) {
			alert(VldEndALERTcmpcpfinc);
			$("#cpf_b1").focus();
			return false;
		}
	}else{
		alert(VldEndALERTcmpcpfinc);
		$("#cpf_b1").focus();
		return false;
	}

	$("#cpf").val(cpf_cob);
	if ($("#rg").val().length == 0) {
		alert(VldEndALERTcmprg);
		$("#rg").focus();
		return false;
	}
	if ($("#endereco").val().length == 0) {
		alert(VldEndALERTcmpend);
		$("#endereco").focus();
		return false;
	}
     
	if ($("#numero").val().length == 0) {
		alert(VldEndALERTcmpnum);
		$("#numero").focus();
		return false;
	}

	if ($("#cep").val().length == 0) {
		alert(VldEndALERTcmpcep);
		$("#cep").focus();
		return false;
	}
	
	if ($("#cep").val().length < 8) {
		alert(VldEndALERTcmptamcep);
		$("#cep").focus();
		return false;
	}
	
	if ($("#cidade").val().length == 0) {
		alert(VldEndALERTcmpcidade);
		$("#cidade").focus();
		return false;
	}
	
	if ($("#email").val().length == 0) {
	  alert(CkLoginALERTcmpemail);
	  $("#email").focus();
	  return false;
	}
	if (!checkMail($("#email").val())) {
	  alert(CkLoginALERTcmpemailinc); 
	  $("#email").focus();
	  return false;
	}

	if ($("#bairro").val().length == 0) {
		alert(VldEndALERTcmpbairro);
		$("#bairro").focus();
		return false;
	}

	if ($("#pretensao_salarial").val().length == 0) {
		alert(VldEndALERTcmpprentensao_salarial);
		$("#pretensao_salarial").focus();
		return false;
	}
	
	if ($("#como_conheceu").val().length == 0) {
		alert(VldEndALERTcmpcomoconheceu);
		$("#como_conheceu").focus();
		return false;
	}
	
	if ($("#curriculum_arq").val().length == 0) {
		alert(VldEndALERTcmpcurriculum_arq);
		$("#curriculum_arq").focus();
		return false;
	}
	
	cadastrarCurriculo();
	// Caso as informações estiverem corretas a função ira retorna true 
	return true;
}


function cadastrarCurriculo(){
	// Formata o cep e encaminha para a pagina em php 
	xmlhttp = checkNavegador(); // Verifica qual o navegador esta sendo utilizado 
	xmlhttp.open("POST", "./actions/consulta.php", true);	
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	xmlhttp.setRequestHeader("Pragma", "no-cache");
	xmlhttp.onreadystatechange =  function (){
		if (xmlhttp.readyState == 1) {
			$("#cadNewCurrilo").get(0).disabled = true
			$("#aguarde_car").html("<b>Aguarde carregando!</b>");
		}
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
				alert(xmlhttp.responseText)
				if (xmlhttp.responseText == 0){
					document.frmTrabConosco.submit();
				} else {
					$("#cadNewCurrilo").get(0).disabled = false
					$("#aguarde_car").html("<font color=red><b>Seu curriculo já esta cadastrado em nossa base de dados!</b></font>");
				}
			}
		}
	};// Processamento do sistema 
	xmlhttp.send("action=1&cpf="+$("#cpf").val());
}


//###################################################################################
function logAberturaChamado() {
	
	var usuario = $("#usuario").val();
	var senha = $("#senha").val();
	
	if (usuario.length == 0) {
		alert(VldPwdALERTcampousuario);
        $("#usuario").focus();
        return false;
	}
       
	if (senha.length == 0) {
		alert(VldPwdALERTcamposenha);
        $("#senha").focus();
        return false;
	}
	
	// Formata o cep e encaminha para a pagina em php 
	xmlhttp = checkNavegador(); // Verifica qual o navegador esta sendo utilizado 
	xmlhttp.open("POST", "./actions/consulta.php", true);	
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	xmlhttp.setRequestHeader("Pragma", "no-cache");
	xmlhttp.onreadystatechange =  function (){
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
				//alert(xmlhttp.responseText)
				if (xmlhttp.responseText == 0){
					location.replace("abrir_chamado.php");
				} else {
					alert('Usuario ou senha invalidos!')
				}
			}
		}
	};// Processamento do sistema 
	xmlhttp.send("action=2&usuario="+usuario+"&senha="+senha);
}



//###################################################################################
// Função criar para realizar o cadastro dos chamados via site
//###################################################################################

function cadastrarChamado() {
	
	var os_texto = $("#os_texto").val();
	
	if (os_texto.length == 0) {
		alert("Campo solicitação é obrigatório.");
        $("#os_texto").focus();
        return false;
	}
	document.frmCadChamado.submit();
}



function alterarSenhaAtual(){
	var senha = $("#senha").val();
	var nova_senha = $("#nova_senha").val();
	var conf_nova_senha = $("#conf_nova_senha").val();

	if (senha.length == 0) {
		alert("Campo Senha é obrigatório.");
        $("#senha").focus();
        return false;
	}
	if (nova_senha.length == 0) {
		alert("Campo Nova Senha é obrigatório.");
        $("#nova_senha").focus();
        return false;
	}
	
	if (conf_nova_senha.length == 0) {
		alert("Campo Confirmar Nova Senha é obrigatório.");
        $("#conf_nova_senha").focus();
        return false;
	}
	
	if (nova_senha != conf_nova_senha ){
		alert("As Senhas não Conferem é obrigatório.");
		$("#nova_senha").val("");
		$("#conf_nova_senha").val("");		
        $("#nova_senha").focus();	
	} 
	
	// Formata o cep e encaminha para a pagina em php 
	xmlhttp = checkNavegador(); // Verifica qual o navegador esta sendo utilizado 
	xmlhttp.open("POST", "./actions/consulta.php", true);	
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	xmlhttp.setRequestHeader("Pragma", "no-cache");
	xmlhttp.onreadystatechange =  function (){
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
				//alert(xmlhttp.responseText)
				if (xmlhttp.responseText == 0){
					document.frmAltSenhaAtual.submit();
				} else {
					alert('Senha Atual invalida!')
				}
			}
		}
	};// Processamento do sistema 
	xmlhttp.send("action=3&senha="+senha);
}