function fcc_mudaAba(acao){
	var abaAtual = document.getElementById("fcc_abaAtual");
	var aba = "";
	
	if(acao=="avancar"){
		aba = parseInt(abaAtual.value) + 1;
	}else if(acao=="voltar"){
		aba = parseInt(abaAtual.value) - 1;
	}
	
	//validando a aba atual antes de trocar de aba	
	if(!validaAba(abaAtual.value)){
		return false;
	}
	
	//se a nova aba for a primeira oculta o botão de voltar
	if(aba==1){
		document.getElementById("fcc_btnVoltar").style.display = "none";
	}else{
		document.getElementById("fcc_btnVoltar").style.display = "block";
	}
	
	//se a nova aba for a ultima mostra o botão de gravar e oculta o de avançar
	if(aba==6){
		document.getElementById("fcc_btnAvancar").style.display = "none";
		document.getElementById("fcc_btnGravar").style.display = "block";
	}else{
		document.getElementById("fcc_btnAvancar").style.display = "block";
		document.getElementById("fcc_btnGravar").style.display = "";
	}	
	
	//percorrendo as 6 abas
	for(i=1;i<=6;i++){
		//se não for a aba que deve ser marcada
		if(i!=aba){
			//mudando o estilo da aba
			document.getElementById("fcc_aba"+i).className = "fcc_abaDesmarcada";
			//ocultando as outras abas
			document.getElementById("contAba"+i).style.display = "none";
		}else{
			//mudando o estilo da aba
			document.getElementById("fcc_aba"+i).className = "fcc_abaMarcada";
			//mostrando a aba atual
			document.getElementById("contAba"+i).style.display = "block";
			//armazenando a aba atual
			abaAtual.value = i;				
		}
	}
	
	scrollTo(0,0);
}

function validaApelido(){
	var iframeValidaApelido = document.getElementById("iframeValidaApelido");
	var apelido = document.getElementById("apelido");
	var base = document.getElementById("base").value;

	iframeValidaApelido.src = base+"util/validaApelidoAjax.php?acao=apelido&apelido="+apelido.value;
	//consultaAjaxTextNoLoad(base+'util/validaApelidoAjax.php','acao=apelido&apelido='+apelido.value,'post','iframeValidaApelido','');
	
	return true;
}

function validaAba(aba){
	/* se for a primeira aba */
	if(aba==1){			
		/* INI - campos da aba 1 */
		var apelido = document.getElementById("apelido");
		var statusValidApelido = document.getElementById("statusValidApelido");
		var cpf = document.getElementById("cpf");
		var statusCpf = document.getElementById("statusValidCpf");
		var rg = document.getElementById("rg");
		var nome = document.getElementById("nome");		
		//var certificado_militar = document.getElementById("certificado_militar");
		var estado_civil = document.getElementById("estado_civil");
		var naturalidade = document.getElementById("naturalidade");
		var data_nascimento = document.getElementById("data_nascimento");
		var telefone_candidato = document.getElementById("telefone_candidato");
		var celular_pessoal = document.getElementById("celular_pessoal");
		var email_pessoal = document.getElementById("email_pessoal");
		var foto = document.getElementById("foto");
		var tag = document.getElementById("tag");
		/* FIM - campos da aba 1 */
		
		/* INI - VALIDANDO A ABA 1 */			
		if(apelido.value==""){
			alert("Informe o APELIDO!");
			apelido.focus();
			return false;
		}else {
			if(statusValidApelido.value=="0"){
				alert("ERRO! Clique no botao VERIFICAR, para conferir a disponibilidade de uso do apelido!");
				apelido.focus();
				return false;
			}else if(statusValidApelido.value=="1"){
				alert("ERRO! Ja existe uma pessoa com esse apelido. Por favor informe outro!");
				apelido.focus();
				return false;
			}
		}
		if(cpf.value==""){
			alert("Informe o CPF!");
			cpf.focus();
			return false;
		}							
		if(!validacpf(cpf.value)){
			alert("Cpf invalido!");
			cpf.focus();
			return false;
		}
		if(statusCpf.value==0){
			alert("ERRO! Esse cpf ja esta cadastrado em nosso sistema!");
			cpf.focus();
			return false;
		}
		if(rg.value==""){
			alert("Informe o RG!");
			rg.focus();
			return false;
		}
		if(nome.value==""){
			alert("Informe o NOME!");
			nome.focus();
			return false;
		}			
		if(estado_civil.value==""){
			alert("Selecione o ESTADO CIVIL!");
			estado_civil.focus();
			return false;
		}
		if(naturalidade.value==""){
			alert("Informe a NATURALIDADE!");
			naturalidade.focus();
			return false;
		}
		if(data_nascimento.value==""){
			alert("Informe a DATA DE NASCIMENTO!");
			data_nascimento.focus();
			return false;
		}
		if(telefone_candidato.value==""){
			alert("Informe o TELEFONE!");
			telefone_candidato.focus();
			return false;
		}
		if(email_pessoal.value==""){
			alert("Informe o EMAIL!");
			email_pessoal.focus();
			return false;
		}else{
			if(!validaMail(email_pessoal.value)){
				alert("Informe um email valido!");
				email_pessoal.focus();
				return false;
			}
		}
		if(foto.value!=""){
			var aux = foto.value.split(".");
			var formatoImg = aux[aux.length-1];
			
			if((formatoImg!="jpg") && (formatoImg!="jpeg")){
				alert("ERRO! Selecione uma imagem com formato .jpg");
				foto.focus();
				return false;
			}
		}
		if(tag.value==""){
			alert("Informe pelo menos uma META TAG!");
			tag.focus();
			return false;
		}
		/* FIM - VALIDANDO A ABA 1 */			
		return true;
	}else if(aba==2){
		var cep  = document.getElementById("cep");
		var cmpl = document.getElementById("complemento");
		var pont = document.getElementById("ponto_referencia");
		var id_log = document.getElementById("id_log");
		
		if(id_log.value==""){
			alert("Por favor pesquise o seu endereço!");				
			return false;
		}else{
			if(cmpl.value==""){
				alert("Informe o COMPLEMENTO!");
				cmpl.focus();
				return false;
			}
			if(pont.value==""){
				alert("Informe o PONTO DE REFERENCIA!");
				pont.focus();
				return false;
			}
		}
		
		return true;
	}else if(aba==3){
		var grau  = document.getElementById("grau");
		
		if(grau.value==""){
			alert("Por favor selecione o GRAU DE FORMACAO!");
			grau.focus();
			return false;
		}
	}else if(aba==4){
		SelectAll(document.getElementById('interessado'));
		
		var tipo = document.getElementById("tipo_curriculum");
		var area = document.getElementById("id_area");
		var inte = document.getElementById("interessado");
		var hora = document.getElementById("horario_disponivel");
		var pret = document.getElementById("pretensao_salarial");
		var nego = document.getElementById("negocia");
		
		if(tipo.value==""){
			alert("Selecione um TIPO DE CURRICULUM!");
			tipo.focus();
			return false;
		}
		if(inte.selectedIndex==-1){
			alert("Selecione pelo menos uma AREA DE INTERESSE!");
			area.focus();
			return false;
		}
		if(hora.value==""){
			alert("Selecione um HORARIO DISPONIVEL!");
			hora.focus();
			return false;
		}
		if(nego.checked==false){
			if(pret.value==""){
				alert("Por favor, preencha o campo PRETENSAO SALARIAL ou clique em ABERTO A NEGOCIACAO!");
				pret.focus();
				return false;
			}
		}		
		return true;
	}

	return true;
}

function loadEndereco(){		
	var cep = document.getElementById("cep");
	var base = document.getElementById("base").value;
	
	if(cep.value==""){
		alert("Preencha o campo CEP!");
		cep.focus();
		return false;
	}else{
		if(cep.value.length<5){
			alert("Informe pelo menos 5 digitos do cep!");
			cep.focus();
			return false;
		}
	}	
	
	consultaAjaxText(base+'site_candidatos/ctrlImplementa.php','acao=buscaCep&cep='+cep.value,'post','contAba2','carregando...');		
}

function pesquisaCepByEnd(){
	var txtLog = document.getElementById("txtLog");
	var uf = document.getElementById("uf");
	var cidade = document.getElementById("cidade");
	var tipo_logra = document.getElementById("tipo_logra");
	var nlac = document.getElementById("nlac");
	var base = document.getElementById("base").value;
	
	if(txtLog.value==""){
		alert("Por favor informe pelo menos uma parte do seu logradouro!");
		txtLog.focus();
		return false;
	}
	if(uf.value==""){
		alert("Por favor selecione o UF!");
		uf.focus();
		return false;
	}
	if(cidade.value==""){
		alert("Por favor selecione a CIDADE!");
		cidade.focus();
		return false;
	}
	
	consultaAjaxText(base+'site_candidatos/ctrlImplementa.php','acao=buscaCepByEnd&txtLog='+txtLog.value+"&id_estado="+uf.value+"&id_cidade="+cidade.value+"&id_tipo_logra="+tipo_logra.value+"&nlac"+nlac.value+"&mostraCeps=yes",'post','contAba2','carregando...');
}

function ocultaMostraIdioma(status,idIdioma){
	//se estiver marcando
	if(status==true){
		document.getElementById("fcc_nivelIdioma"+idIdioma).style.display = "block";
	}else{
		document.getElementById("fcc_nivelIdioma"+idIdioma).style.display = "none";
	}
}

function validaCpfUnico(cpf){
	var iframeValidaCpf = document.getElementById("iframeValidaCpf");
	var base = document.getElementById("base").value;

	iframeValidaCpf.src=base+'util/validaCpfCnpjAjax.php?acao=cpf&cpf='+cpf;
	//consultaAjaxTextNoLoad(base+'util/validaCpfCnpjAjax.php','acao=cpf&cpf='+cpf,'post','iframeValidaCpf','');
}

function carregaAreas(id_area){
	var base = document.getElementById("base").value;
	var areas = document.getElementById("areas");
	var nomeArea = document.createElement("div");
	nomeArea.setAttribute('id','subAreas'+id_area);
	areas.appendChild(nomeArea);
	var nomeAreaMarcada = document.createElement("div");
	nomeAreaMarcada.setAttribute('id','subAreasMarcadas'+id_area);
	areas.appendChild(nomeAreaMarcada);
	consultaAjaxText(base+'util/ctrlAreaInt.php','ac=buscaSubArea&valor='+id_area+'&metodo=filtrarPorAreaAtivos&chk=0','post','subAreas'+id_area,'carregando...');
	document.getElementById("areas").style.display = "";
}

function removerAreas(id_area){
	var div = document.getElementById("subAreas"+id_area);
	var div1 = document.getElementById("subAreasMarcadas"+id_area);
	var areas = document.getElementById("areas");
	areas.removeChild(div);
	areas.removeChild(div1);		
}

function carregaAreasCadastradas(id_area){
	var sis = document.getElementById("sis").value;
	var inscricao = document.getElementById("inscricao").value;
	var areas = document.getElementById("areas");
	var nomeArea = document.createElement("div");
	nomeArea.setAttribute('id','subAreas'+id_area);
	areas.appendChild(nomeArea);
	var nomeAreaMarcada = document.createElement("div");
	nomeAreaMarcada.setAttribute('id','subAreasMarcadas'+id_area);
	areas.appendChild(nomeAreaMarcada);
	consultaAjaxText(sis+'util/ctrlAreaInt.php','ac=candSubArea&valor='+inscricao+'&valor1='+id_area+'&metodo=recuperarSubAreasPorCand','post','subAreas'+id_area,'carregando...');
	document.getElementById("areas").style.display = "";
}

function carregaSubAreas(){
	var sis = document.getElementById("sis").value;
	var areas = new Array(document.getElementById("interessado").length);
	for(var i=0;i<areas.length;i++){
		if(document.getElementById("interessado").options[i].selected == true){
			//alert(document.getElementById("id_area").options[i].value);
			carregaAreasCadastradas(document.getElementById("interessado").options[i].value);
		}
	}
}
function criaExp(num_div){
	var divMae = document.getElementById("exps");
	var divPadrao = document.getElementById("expPadrao");
	var divFilho = document.createElement("div");
	//var btnNovo = document.getElementById("btnNovaExp");
	var num = parseInt(num_div);
	divFilho = divPadrao.cloneNode(true);
	divFilho.setAttribute('id','exp'+num);
	divFilho.style.display = "";
	divMae.appendChild(divFilho);
	var excluir = document.createElement("div");
	excluir.setAttribute("id","excluir");
	divFilho.appendChild(excluir);
	excluir.innerHTML = "<input type='button' name='btnExcluir' id='btnExcluir' onclick='return delExp("+num+");' value='Excluir' class='fcc_expExclui' />";
	num++;
	//btnNovo.setAttribute('onclick','criaExp('+num+')');
	var hd_exp_num = document.getElementById("hd_exp_num");
	hd_exp_num.value = num;
}
function delExp(num){
	var divMae = document.getElementById("exps");
	var divExcluir = document.getElementById("exp"+num);
	if(!confirm('Deseja realmente excluir este REGISTRO?')){
		return false;
	}else{
		divMae.removeChild(divExcluir);
		return true;
	}
}
function criaCurso(num_div){
	var divMae = document.getElementById("curs");
	var divPadrao = document.getElementById("curPadrao");
	var divFilho = document.createElement("div");
	//var btnNovo = document.getElementById("btnNovaExp");
	var num = parseInt(num_div);
	divFilho = divPadrao.cloneNode(true);
	divFilho.setAttribute('id','cur'+num);
	divFilho.style.display = "";
	divMae.appendChild(divFilho);
	var excluir = document.createElement("div");
	excluir.setAttribute("id","excluir");
	divFilho.appendChild(excluir);
	excluir.innerHTML = "<input type='button' name='btnExcluir' id='btnExcluir' onclick='return delCurso("+num+");' value='Excluir' class='fcc_expExclui' />";
	num++;
	//btnNovo.setAttribute('onclick','criaExp('+num+')');
	var hd_cur_num = document.getElementById("hd_cur_num");
	hd_cur_num.value = num;
}
function delCurso(num){
	var divMae = document.getElementById("curs");
	var divExcluir = document.getElementById("cur"+num);
	if(!confirm('Deseja realmente excluir este REGISTRO?')){
		return false;
	}else{
		divMae.removeChild(divExcluir);
		return true;
	}
}

function desabilitaPretensao(chk){
	var pretensao	= document.getElementById("pretensao_salarial");
	if(chk==true){
		pretensao.value = "";
		pretensao.disabled = true;
	}else{
		pretensao.value = "";
		pretensao.disabled = false;
	}
}

function desmarca_radio(valor){
	var radio = document.getElementsByName('idioma_nivel['+valor+']');
	var check = document.getElementById("id_idioma"+valor);
	if (check.checked)	{		
		radio[0].checked = true;
		for(i=0; radio.length > i; i++){
			radio[i].disabled='';							
		}	
	}
	else {
		for(i=0; radio.length > i; i++){
			if (radio[i].checked){
				radio[i].checked = false;						
			}
			radio[i].disabled='disabled';					
		}
	}	
}