﻿//Consistências
function consistMailing(){ 
	OK = true;
	if (document.form_mailing.nome.value==""){
		alert ("Por favor, preencha o campo 'nome'.");
		document.form_mailing.nome.focus();
		document.form_mailing.nome.select();
		OK = false;
		return;
	}
	validarEmail(document.form_mailing.campo_especial_hb);
	if (OK == true) { document.form_mailing.submit() }
}

// Funções
function abrirJanela(){ window.open("recurso/recurso.html" , "recurso" , "status , scrollbars=no ,width=550, height=412 , top=20 , left=20"); };
function validarEmail(campo){ 
	if  (campo.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) {
		alert ("Por favor, digite o seu e-mail corretamente.")
		campo.focus();
		campo.select();
		OK = false
		return;	
	}
}
function noenter(){
  //evitando submit dos forms com enter
  return !(window.event && window.event.keyCode == 13); 
}

function buscaCidades(uf)
{
	//alert(document.getElementById('div_cidade'));
	if(uf!=''){
		loadAjax(document.getElementById('div_cidade'),"talentos_combo_cidade.asp?nome_uf=" + uf);
	}
}

function AbrirArquivo(td_arquivo,nome_campo,div_exclusao)
{
	window.open("arquivo_form.asp?campo=" + nome_campo + "&td=" + td_arquivo + "&arquivo_antigo=" + document.getElementById(nome_campo).value + "&div="+div_exclusao,"arquivo","width=300,height=150,location=no,status=no");
}

function excluirArquivo(td,campo,div_exclusao,id)
{
	if(confirm('Deseja excluir o arquivo?')){
		var arquivo
		arquivo = document.getElementById(campo).value;
		loadAjax(document.getElementById(div_exclusao),"arquivo_exclui.asp?arquivo=" + arquivo + "&id="+id);
		document.getElementById(campo).value = '';
		document.getElementById(td).innerHTML = "<a href=javascript:AbrirArquivo('"+td+"','"+campo+"','"+div_exclusao+"');>inserir arquivo</a>";
	}
}

function AbrirFoto(td_arquivo,nome_campo)
{
	window.open("foto_form.asp?campo=" + nome_campo + "&td=" + td_arquivo + "&arquivo_antigo=" + document.getElementById(nome_campo).value,"foto","width=300,height=150,location=no,status=no");
}

function excluirFoto(td,campo,div_exclusao)
{
	if(confirm('Deseja excluir o arquivo?')){
		var arquivo
		arquivo = document.getElementById(campo).value;
		loadAjax(document.getElementById(div_exclusao),"foto_exclui.asp?arquivo=" + arquivo);
		document.getElementById(campo).value = '';
		document.getElementById(td).innerHTML = "<a href=javascript:AbrirFoto('"+td+"','"+campo+"');>inserir imagem</a>";
	}
}

function validaData(campo){
	if(campo.value!=''){
		er = /^((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(!er.test(campo.value)){
			alert('Data inválida');
			campo.value = "";
		}
	}
}

function verificaSenha(){
	if(document.form.senha.value != document.form.senha2.value){
		alert('Senhas não conferem!');
		document.form.senha.value = "";
		document.form.senha2.value = "";
		return false;
	}
	return true;
}

function validaTalento(){
	msg = '';
	if(document.form.sexo.value==''){
		msg = msg + '\n- Sexo';
	}
	if(document.form.email.value==''){
		msg = msg + '\n- E-mail';
	}
	if(document.form.id_uf.value==''){
		msg = msg + '\n- Estado';
	}
	if(document.form.id_cidade.value==''){
		msg = msg + '\n- Cidade';
	}
	if(document.form.data.value==''){
		msg = msg + '\n- Data de Nascimento';
	}
	if((document.form.area_governo.checked==false)&&(document.form.area_empresa.checked==false)&&(document.form.area_3setor.checked==false)){
		msg = msg + '\n- Áreas de interesse';
	}
	if(document.form.curriculo.value==''){
		msg = msg + '\n- Currículo';
	}
	if(msg!=''){
		alert('Preencha os campos:'+msg);
		return false;
	}
	if(verificaSenha()==false){
		return false;
	}
	var atividade='', ano='', semestre='', projeto='';
	for(i=0;i<document.form.id_atividade.length;i++)
	{
		if(document.form.id_atividade[i].checked==true){
			if((document.form.ano[i].value=='')||(document.form.ano[i].semestre=='')||(document.form.id_projeto[i].value==''))
			{
				alert('Preencha corretamente a atividade realizada.');
				return false;
			}
			//Joga os valores nos hiddens
			atividade = atividade + document.form.id_atividade[i].value + ',';
			ano = ano + document.form.ano[i].value + ',';
			semestre = semestre + document.form.semestre[i].value + ',';
			projeto = projeto + document.form.id_projeto[i].value + ',';
		}
	}
	document.form.arr_atividade.value = atividade;
	document.form.arr_ano.value = ano;
	document.form.arr_semestre.value = semestre;
	document.form.arr_projeto.value = projeto;
	
	return true;
}