//Valida currículo

//

function validaCampoCPF(theForm) {
  if (theForm.cpf.value == ""){
	alert ("'CPF' deve ser preenchido.");
	theForm.cpf.focus();
	return (false);
  }else{
    if (!ValidaCPF(theForm.cpf)){
		theForm.cpf.focus();
		return (false);
	}
  }
}

function validaSenha(theForm) {
	if (theForm.senha.value == ""){
  		alert ("'Senha' deve ser preenchida.");
		theForm.senha.focus();
		return (false);
  	}
}

//FUNCOES AUXILIARES
function getById(campo){
	object = (document.all) ? document.all[campo] : document.getElementById(campo);
	return object;
}

function ValidaCPF(theCPF)
{
  if (theCPF.value == "")
  {
    return (true);
  }
  if (!((theCPF.value.length == 11) || (theCPF.value.length == 14)))
  {
//    alert("Tamanho do CPF (11 posições) ou CNPJ (14 posições) inválido.");
    alert("Tamanho do CPF (11 posições) inválido.");
    theCPF.focus();
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = theCPF.value;
  var allValid = true;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
//    alert("Favor preencher somente com dígitos o campo CPF/CNPJ.");
    alert("Favor preencher somente com dígitos o campo CPF.");
    theCPF.focus();
    return (false);
  }

  var chkVal = allNum;
  var prsVal = parseFloat(allNum);
  if (chkVal != "" && !(prsVal > "0"))
  {
    alert("CPF zerado !");
    theCPF.focus();
    return (false);
  }

if (theCPF.value.length == 11)
{
  var tot = 0;

  for (i = 2;  i <= 10;  i++)
    tot += i * parseInt(checkStr.charAt(10 - i));

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(9)))
  {
//    alert("O dígito do CPF/CNPJ informado não confere !");
    alert("O dígito do CPF informado não confere !");
    theCPF.focus();
    return (false);
  }
  
  tot = 0;
  
  for (i = 2;  i <= 11;  i++)
    tot += i * parseInt(checkStr.charAt(11 - i));

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(10)))
  {
//    alert("O dígito do CPF/CNPJ informado não confere !");
    alert("O dígito do CPF informado não confere !");
    theCPF.focus();
    return (false);
  }
}
else
{
  var tot  = 0;
  var peso = 2;
  
  for (i = 0;  i <= 11;  i++)
  {
    tot += peso * parseInt(checkStr.charAt(11 - i));
    peso++;
    if (peso == 10)
    {
        peso = 2;
    }
  }

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(12)))
  {
//    alert("O dígito do CPF/CNPJ informado não confere !");
    alert("O dígito do CPF informado não confere !");
    theCPF.focus();
    return (false);
  }
  
  tot  = 0;
  peso = 2;
  
  for (i = 0;  i <= 12;  i++)
  {
    tot += peso * parseInt(checkStr.charAt(12 - i));
    peso++;
    if (peso == 10)
    {
        peso = 2;
    }
  }

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(13)))
  {
//    alert("O dígito do CPF/CNPJ informado não confere !");
    alert("O dígito do CPF informado não confere !");
    theCPF.focus();
    return (false);
  }
}
  return(true);
}


/*
*
* VALIDA CEP
*
*/
function isCep(campo) {
	// Se não houver um separador '-'...
	if (campo.indexOf("-") != 5) {
		return false;
	} else {
		aux = campo.split("-");
		// Se faltar o número antes ou depois do separador...
		if (aux.length != 2 || aux[0] == "" || aux[1] == "") {
			return false;
		} else {
			// Se não tiver o número certo de números
			if (!isNumber(aux[0]) || !isNumber(aux[1])) {
				return false;
			}
		}
	}
	return true;
}
//------------------------------------------------
// Nome: isNumber
// Parametros: 
//		inputVal - (valor a ser testado)
//
// Retorno:
//		true - (o valor inputVal é um número)
//		false - (o valor inputVal não é um número)
function isNumber(inputVal) {
	if (isNaN(inputVal)) {
		return false
	}
	return true
}
//------------------------------------------------
// Nome: isEmail
// Parametros: 
//		string - (e-mail a ser testado)
//
// Retorno:
//		true - (string é um e-mail válido)
//		false - (string é um e-mail inválido)
// OBS:
// 	Esta função só funcionará em Javascript1.2
function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
   	    return true;
    else
        return false;

}

//FIM FUNCOES

function Validacao1(theForm)
{
  if (theForm.cur_nome.value == ""){
  	alert ("'Nome' é um campo obrigatório.");
	theForm.cur_nome.focus();
	return (false);
  }
  if(theForm.elements[1].name == "cur_senha") {
	  if (theForm.cur_senha.value == ""){
		alert ("'Senha' é um campo obrigatório.");
		theForm.cur_senha.focus();
		return (false);
	  }
	  if (theForm.confirma.value == ""){
		alert ("'Comfirme a senha' é um campo obrigatório.");
		theForm.confirma.focus();
		return (false);
	  }
	  if(theForm.confirma.value != theForm.cur_senha.value) {
		alert ("'Comfirme a senha' é diferente do campo 'Senha'.");
		theForm.confirma.focus();
		return (false);
	  }
  }
  if (theForm.cur_email.value == ""){
  	alert ("'E-mail' é um campo obrigatório.");
	theForm.cur_email.focus();
	return (false);
  }	else {
  	if (!isEmail(theForm.cur_email.value)){
  		alert ("'E-mail' inválido.");
		theForm.cur_email.focus();
		return (false);
	}
  }
  if (theForm.cur_sexo.value == "-1")
  {
    alert ("'Sexo' é um campo obrigatório.");
	theForm.cur_sexo.focus();
	return (false);
  }
  if (theForm.cur_estadoCivil.value == "-1")
  {
    alert ("'Estado civil' é um campo obrigatório.");
	theForm.cur_estadoCivil.focus();
	return (false);
  }
  if (theForm.cur_cpf.value == ""){
	alert ("'CPF' é um campo obrigatório.");
	theForm.cur_cpf.focus();
	return (false);
  }else{
    if (!ValidaCPF(theForm.cur_cpf)){
		theForm.cur_cpf.focus();
		return (false);
	}
  }
  if (theForm.cur_rg.value == ""){
	alert ("'RG' é um campo obrigatório.");
	theForm.cur_rg.focus();
	return (false);
  }
  /*if (!isNumber(theForm.cur_rg.value)) {
  	alert ("'RG' não é um número.");
	theForm.cur_rg.focus();
	return (false);	
  }*/
  if (theForm.cur_orgEmissor.value == ""){
	alert ("'Órgão Emissor' é um campo obrigatório.");
	theForm.cur_orgEmissor.focus();
	return (false);
  }
  if ((theForm.cur_dia.value == "")||(theForm.cur_mes.value == "")||(theForm.cur_mes.value == "")){
  	alert ("'Data de nascimento' é um campo obrigatório.");
	theForm.cur_dia.focus();
	return (false);
  }
  if(!DataOk(theForm.cur_dia.value+"/"+theForm.cur_mes.value+"/"+theForm.cur_ano.value)) {
			alert("'Data de nascimento' não é uma data válida.");
			theForm.cur_dia.focus();
			return (false);
  }
  if (theForm.cur_empregado.value == "-1"){
  	alert ("'Está empregado atualmente?' é um campo obrigatório.");
	theForm.cur_empregado.focus();
	return (false);
  }
  return (true);
}

function Validacao2(theForm) {
  if (theForm.cur_endereco.value == ""){
  	alert ("'Endereço' é um campo obrigatório.");
	theForm.cur_endereco.focus();
	return (false);
  }
  if (theForm.cur_bairro.value == ""){
  	alert ("'Bairro' é um campo obrigatório.");
	theForm.cur_bairro.focus();
	return (false);
  }
  if (theForm.cur_cep.value == ""){
  	alert ("'CEP' é um campo obrigatório.");
	theForm.cur_cep.focus();
	return (false);
  } 
  if ( !isCep(theForm.cur_cep.value) ) {
	alert ("'CEP' inválido.");
	theForm.cur_cep.focus();
	return (false);
  }
  if (theForm.cur_uf.value == "-1"){
  	alert ("'Estado' é um campo obrigatório.");
	theForm.cur_uf.focus();
	return (false);
  }
  if (theForm.cur_cidade.value == ""){
  	alert ("'Cidade' é um campo obrigatório.");
	theForm.cur_cidade.focus();
	return (false);
  }
  if (theForm.cur_pais.value == ""){
  	alert ("'País' é um campo obrigatório.");
	theForm.cur_pais.focus();
	return (false);
  }
  if ((theForm.cur_telResPrefixo.value == "")||(theForm.cur_telRes.value == "")){
  	alert ("'Telefone residencial' é um campo obrigatório.");
	theForm.cur_telResPrefixo.focus();
	return (false);
  }
  if (!isNumber(theForm.cur_telResPrefixo.value)) {
  	alert ("O DDD do 'telefone residencial' não é um número.");
	theForm.cur_telResPrefixo.focus();
	return (false);	
  }
  if (!isNumber(theForm.cur_telRes.value)) {
  	alert ("O 'telefone residencial' não é um número.");
	theForm.cur_telRes.focus();
	return (false);	
  }
/*  if ((theForm.cur_telComPrefixo.value == "")||(theForm.cur_telCom.value == "")){
  	alert ("'Telefone comercial' é um campo obrigatório.");
	theForm.cur_telComPrefixo.focus();
	return (false);
  }
*/  if (!isNumber(theForm.cur_telComPrefixo.value)) {
  	alert ("O DDD do 'telefone residencial' não é um número.");
	theForm.cur_telComPrefixo.focus();
	return (false);	
  }
  if (!isNumber(theForm.cur_telCom.value)) {
  	alert ("O 'telefone comercial' não é um número.");
	theForm.cur_telCom.focus();
	return (false);	
  }
/*  if ((theForm.cur_celularPrefixo.value == "")||(theForm.cur_celular.value == "")){
  	alert ("'Celular' é um campo obrigatório.");
	theForm.cur_celularPrefixo.focus();
	return (false);
  }
*/  if (!isNumber(theForm.cur_celularPrefixo.value)) {
  	alert ("O DDD do 'celular' não é um número.");
	theForm.cur_celularPrefixo.focus();
	return (false);	
  }
  if (!isNumber(theForm.cur_celular.value)) {
  	alert ("O 'celular' não é um número.");
	theForm.cur_celular.focus();
	return (false);	
  }
/*  if ((theForm.cur_faxPrefixo.value == "")||(theForm.cur_fax.value == "")){
  	alert ("'Fax' é um campo obrigatório.");
	theForm.cur_faxPrefixo.focus();
	return (false);
  }
*/  if (!isNumber(theForm.cur_faxPrefixo.value)) {
  	alert ("O DDD do 'fax' não é um número.");
	theForm.cur_faxPrefixo.focus();
	return (false);	
  }
  if (!isNumber(theForm.cur_fax.value)) {
  	alert ("O 'fax' não é um número.");
	theForm.cur_fax.focus();
	return (false);	
  }
/*  if (theForm.cur_homePage.value == ""){
  	alert ("'Home Page' é um campo obrigatório.");
	theForm.cur_homePage.focus();
	return (false);
  }*/
  return (true);
}

function Validacao3(theForm) {
   if (theForm.elements['are_interesse[]'].selectedIndex == "-1") {
  	alert ("'Área de interesse' é um campo obrigatório.");
	theForm.elements['are_interesse[]'].focus();
	return (false);
  }
  if ((!theForm.elements['vin[estagio][tipo]'].checked)&&(!theForm.elements['vin[clt][tipo]'].checked)&&(!theForm.elements['vin[pj][tipo]'].checked)&&(!theForm.elements['vin[cooperativa][tipo]'].checked)){
  	alert ("'Tipo de vínculo' tem que ter pelo menos um campo marcado.");
	theForm.elements['vin[estagio][tipo]'].focus();
	return (false);
  }
 if ((theForm.elements['vin[estagio][tipo]'].checked)&&(theForm.elements['vin[estagio][salario]'].value == "")) {
  	alert("Você marcou o campo 'Estágio', por favor insira um valor no campo 'Pretensão salarial'");
	theForm.elements['vin[estagio][salario]'].focus();
	return (false);
  }
   if ((theForm.elements['vin[clt][tipo]'].checked)&&(theForm.elements['vin[clt][salario]'].value == "")) {
  	alert("Você marcou o campo 'CLT', por favor insira um valor no campo 'Pretensão salarial'");
	theForm.elements['vin[clt][salario]'].focus();
	return (false);
  }
  if ((theForm.elements['vin[pj][tipo]'].checked)&&(theForm.elements['vin[pj][salario]'].value == "")) {
  	alert("Você marcou o campo 'Pessoa jurídica', por favor insira um valor no campo 'Pretensão salarial'");
	theForm.elements['vin[pj][salario]'].focus();
	return (false);
  }
  if ((theForm.elements['vin[cooperativa][tipo]'].checked)&&(theForm.elements['vin[cooperativa][salario]'].value == "")) {
  	alert("Você marcou o campo 'Filiado á cooperativa', por favor insira um valor no campo 'Pretensão salarial'");
	theForm.elements['vin[cooperativa][salario]'].focus();
	return (false);
  }
  if (theForm.cur_objetivos.value == ""){
  	alert ("Por favor, 'Faça uma breve descrição dos objetivos pretendidos na empresa'");
	theForm.cur_objetivos.focus();
	return (false);
  }
  if (theForm.cur_autoCritica.value == ""){
  	alert ("Por favor, 'faça uma auto-crítica e fale um pouco do seu perfil'");
	theForm.cur_autoCritica.focus();
	return (false);
  }
  return (true);
}

function Validacao4(theForm) {
  if ((theForm.elements['idi[port][nivel]'].selectedIndex == '0')&&(theForm.elements['idi[ing][nivel]'].selectedIndex == '0')&&(theForm.elements['idi[esp][nivel]'].selectedIndex == '0')){
  	alert ("'Idioma' tem que ter pelo menos um campo marcado.");
	theForm.elements['idi[port][nivel]'].focus();
	return (false);
  }
	
  /*if ((theForm.elements['idi[port][idioma]'].checked)&&((!theForm.elements['idi[port][nivel]']['0'].checked)&&(!theForm.elements['idi[port][nivel]']['1'].checked)&&(!theForm.elements['idi[port][nivel]']['2'].checked))) {
  	alert("Você marcou o idioma 'Português'. Por favor, marque um nível");
	theForm.elements['idi[port][idioma]'].focus();
	return (false);
  }
  if ((theForm.elements['idi[ing][idioma]'].checked)&&((!theForm.elements['idi[ing][nivel]']['0'].checked)&&(!theForm.elements['idi[ing][nivel]']['1'].checked)&&(!theForm.elements['idi[ing][nivel]']['2'].checked))) {
  	alert("Você marcou o idioma 'Inglês'. Por favor, marque um nível");
	theForm.elements['idi[ing][nivel]'].focus();
	return (false);
  }
  if ((theForm.elements['idi[esp][idioma]'].checked)&&((!theForm.elements['idi[esp][nivel]']['0'].checked)&&(!theForm.elements['idi[esp][nivel]']['1'].checked)&&(!theForm.elements['idi[esp][nivel]']['2'].checked))) {
  	alert("Você marcou o idioma 'Espanhol'. Por favor, marque um nível");
	theForm.elements['idi[esp][nivel]'].focus();
	return (false);
  }*/

/*  if (theForm.cur_idiomaOutro.value == ""){
  	alert ("'Outros' é um campo obrigatório");
	theForm.cur_idiomaOutro.focus();
	return (false);
  }
*/
  return (true);
}

function Validacao5(theForm) {
  	if((theForm.elements['for[grau]'].value!="-1")||(theForm.elements['for[curso]'].value!="")
||(theForm.elements['for[ini_dia]'].value!="")||(theForm.elements['for[ini_mes]'].value!="")
||(theForm.elements['for[ini_ano]'].value!="")||(theForm.elements['for[fim_dia]'].value!="")||(theForm.elements['for[fim_mes]'].value!="")
||(theForm.elements['for[fim_ano]'].value!="")||(theForm.elements['for[instituicao]'].value!="")
||(theForm.elements['for[status]']['0'].checked)||(theForm.elements['for[status]']['1'].checked)) {
	  if(theForm.elements['for[grau]'].value=="-1") {
	  		alert("'Grau de formação' é um campo obrigatório.");
			theForm.elements['for[grau]'].focus();
			return (false);
	  }
	  if(theForm.elements['for[curso]'].value=="") {
	  		alert("'Curso' é um campo obrigatório.");
			theForm.elements['for[curso]'].focus();
			return (false);
	  }
	  if((theForm.elements['for[ini_dia]'].value=="")||(theForm.elements['for[ini_mes]'].value=="")||(theForm.elements['for[ini_ano]'].value=="")) {
	  		alert("'Data de início' é um campo obrigatório.");
			theForm.elements['for[ini_dia]'].focus();
			return (false);
	  }
	  if(!(DataOk(theForm.elements['for[ini_dia]'].value+"/"+theForm.elements['for[ini_mes]'].value+"/"+theForm.elements['for[ini_ano]'].value))) {
			alert("'Data de início' não é uma data válida.");
			theForm.elements['for[ini_dia]'].focus();
			return (false);
	  }
	 /* if((theForm.elements['for[fim_dia]'].value=="")||(theForm.elements['for[fim_mes]'].value=="")||(theForm.elements['for[fim_ano]'].value=="")) {
	  		alert("'Data de fim' é um campo obrigatório.");
			theForm.elements['for[fim_dia]'].focus();
			return (false);
	  }*/
	  if ((theForm.elements['for[fim_dia]'].value!="")||(theForm.elements['for[fim_mes]'].value!="")||(theForm.elements['for[fim_ano]'].value!="")) {
	  	if(!DataOk(theForm.elements['for[fim_dia]'].value+"/"+theForm.elements['for[fim_mes]'].value+"/"+theForm.elements['for[fim_ano]'].value)) {
			alert("'Data de fim' não é uma data válida.");
			theForm.elements['for[fim_dia]'].focus();
			return (false);
	  	}
	  }
	  if(theForm.elements['for[instituicao]'].value == "") {
	  		alert("'Instituição' é um campo obrigatório.");
			theForm.elements['for[instituicao]'].focus();
			return (false);
	  }
	  if((!theForm.elements['for[status]']['0'].checked)&&(!theForm.elements['for[status]']['1'].checked)) {
	  		alert("Selecione um campo de status do seu curso, ou 'Concluído' ou 'Semestre'. ");
			theForm.elements['for[status]']['0'].focus();
			return (false);
	  }
	  if((theForm.elements['for[status]']['1'].checked)&&(theForm.elements['for[semestre]'].value == "")) {
	  		alert("Você selecionou o campo 'Semestre', por favor indique em qual semestre está");
			theForm.elements['for[semestre]'].focus();
			return (false);
	  }
	}
  return (true);
}

function Validacao6(theForm) {
  	if((theForm.elements['exp[ini_dia]'].value!="")||(theForm.elements['exp[ini_mes]'].value!="")
||(theForm.elements['exp[ini_ano]'].value!="")||(theForm.elements['exp[fim_dia]'].value!="")||(theForm.elements['exp[fim_mes]'].value!="")
||(theForm.elements['exp[fim_ano]'].value!="")||(theForm.elements['exp[empresa]'].value!="")||(theForm.elements['exp[ultimoCargo]'].value!="")
||(theForm.elements['exp[realizacoes]'].value!="")) {
	  if((theForm.elements['exp[ini_dia]'].value=="")||(theForm.elements['exp[ini_mes]'].value=="")||(theForm.elements['exp[ini_ano]'].value=="")) {
	  		alert("'Data de início' é um campo obrigatório.");
			theForm.elements['exp[ini_dia]'].focus();
			return (false);
	  }
	  //alert(DataOk(theForm.elements['exp[ini_dia]'].value+"/"+theForm.elements['exp[ini_mes]'].value+"/"+theForm.elements['exp[ini_ano]'].value));
	  if(!(DataOk(theForm.elements['exp[ini_dia]'].value+"/"+theForm.elements['exp[ini_mes]'].value+"/"+theForm.elements['exp[ini_ano]'].value))) {
			alert("'Data de início' não é uma data válida.");
			theForm.elements['exp[ini_dia]'].focus();
			return (false);
	  }
	  /*if((theForm.elements['exp[fim_dia]'].value=="")||(theForm.elements['exp[fim_mes]'].value=="")||(theForm.elements['exp[fim_ano]'].value=="")) {
	  		alert("'Data de fim' é um campo obrigatório.");
			theForm.elements['exp[fim_dia]'].focus();
			return (false);
	  }*/
	  if((theForm.elements['exp[fim_dia]'].value!="")||(theForm.elements['exp[fim_mes]'].value!="")||(theForm.elements['exp[fim_ano]'].value!="")) {
	  	if(!DataOk(theForm.elements['exp[fim_dia]'].value+"/"+theForm.elements['exp[fim_mes]'].value+"/"+theForm.elements['exp[fim_ano]'].value)) {
			alert("'Data de saída' não é uma data válida.");
			theForm.elements['exp[fim_dia]'].focus();
			return (false);
	  	}
	  }
	  if(theForm.elements['exp[empresa]'].value=="") {
	  		alert("'Empresa' é um campo obrigatório.");
			theForm.elements['exp[empresa]'].focus();
			return (false);
	  }
	  if(theForm.elements['exp[ultimoCargo]'].value=="") {
	  		alert("'Último cargo' é um campo obrigatório.");
			theForm.elements['exp[ultimoCargo]'].focus();
			return (false);
	  }
	  if(theForm.elements['exp[realizacoes]'].value=="") {
	  		alert("'Atribuições/realizações no cargo' é um campo obrigatório.");
			theForm.elements['exp[realizacoes]'].focus();
			return (false);
	  }
	}
  return (true);
}


function ValidacaoGeral(theForm)
{
  if (theForm.cur_nome.value == ""){
  	alert ("'Nome' é um campo obrigatório.");
	theForm.cur_nome.focus();
	return (false);
  }
  if (theForm.cur_senha.value == ""){
  	alert ("'Senha' é um campo obrigatório.");
	theForm.cur_senha.focus();
	return (false);
  }
  if (theForm.confirma.value == ""){
  	alert ("'Comfirme a senha' é um campo obrigatório.");
	theForm.confirma.focus();
	return (false);
  }
  if (theForm.cur_email.value == ""){
  	alert ("'E-mail' é um campo obrigatório.");
	theForm.cur_email.focus();
	return (false);
  }	else {
  	if (!isEmail(theForm.cur_email.value)){
  		alert ("'E-mail' inválido.");
		theForm.cur_email.focus();
		return (false);
	}
  }
  if (theForm.cur_sexo.value == "-1")
  {
    alert ("'Sexo' é um campo obrigatório.");
	theForm.cur_sexo.focus();
	return (false);
  }
  if (theForm.cur_estadoCivil.value == "-1")
  {
    alert ("'Estado civil' é um campo obrigatório.");
	theForm.cur_estadoCivil.focus();
	return (false);
  }
  if (theForm.cur_cpf.value == ""){
	alert ("'CPF' é um campo obrigatório.");
	theForm.cur_cpf.focus();
	return (false);
  }else{
    if (!ValidaCPF(theForm.cur_cpf)){
		theForm.cur_cpf.focus();
		return (false);
	}
  }
  if (theForm.cur_rg.value == ""){
	alert ("'RG' é um campo obrigatório.");
	theForm.cur_rg.focus();
	return (false);
  }
  if (!isNumber(theForm.cur_rg.value)) {
  	alert ("'RG' não é um número.");
	theForm.cur_rg.focus();
	return (false);	
  }
  if (theForm.cur_orgEmissor.value == ""){
	alert ("'Órgão Emissor' é um campo obrigatório.");
	theForm.cur_orgEmissor.focus();
	return (false);
  }
  if ((theForm.cur_dia.value == "")||(theForm.cur_mes.value == "")||(theForm.cur_mes.value == "")){
  	alert ("'Data de nascimento' é um campo obrigatório.");
	theForm.cur_dia.focus();
	return (false);
  }
  if(!DataOk(theForm.cur_dia.value+"/"+theForm.cur_mes.value+"/"+theForm.cur_ano.value)) {
			alert("'Data de nascimento' não é uma data válida.");
			theForm.cur_dia.focus();
			return (false);
  }
  if (theForm.cur_empregado.value == "-1"){
  	alert ("'Está empregado atualmente?' é um campo obrigatório.");
	theForm.cur_empregado.focus();
	return (false);
  }
  if (theForm.cur_endereco.value == ""){
  	alert ("'Endereço' é um campo obrigatório.");
	theForm.cur_endereco.focus();
	return (false);
  }
  if (theForm.cur_bairro.value == ""){
  	alert ("'Bairro' é um campo obrigatório.");
	theForm.cur_bairro.focus();
	return (false);
  }
  if (theForm.cur_cep.value == ""){
  	alert ("'CEP' é um campo obrigatório.");
	theForm.cur_cep.focus();
	return (false);
  } 
  if ( !isCep(theForm.cur_cep.value) ) {
	alert ("'CEP' inválido.");
	theForm.cur_cep.focus();
	return (false);
  }
  if (theForm.cur_uf.value == "-1"){
  	alert ("'Estado' é um campo obrigatório.");
	theForm.cur_uf.focus();
	return (false);
  }
  if (theForm.cur_cidade.value == ""){
  	alert ("'Cidade' é um campo obrigatório.");
	theForm.cur_cidade.focus();
	return (false);
  }
  if (theForm.cur_pais.value == ""){
  	alert ("'País' é um campo obrigatório.");
	theForm.cur_pais.focus();
	return (false);
  }
  if ((theForm.cur_telResPrefixo.value == "")||(theForm.cur_telRes.value == "")){
  	alert ("'Telefone residencial' é um campo obrigatório.");
	theForm.cur_telResPrefixo.focus();
	return (false);
  }
  if (!isNumber(theForm.cur_telResPrefixo.value)) {
  	alert ("O DDD do 'telefone residencial' não é um número.");
	theForm.cur_telResPrefixo.focus();
	return (false);	
  }
  if (!isNumber(theForm.cur_telRes.value)) {
  	alert ("O 'telefone residencial' não é um número.");
	theForm.cur_telRes.focus();
	return (false);	
  }
/*  if ((theForm.cur_telComPrefixo.value == "")||(theForm.cur_telCom.value == "")){
  	alert ("'Telefone comercial' é um campo obrigatório.");
	theForm.cur_telComPrefixo.focus();
	return (false);
  }
*/  if (!isNumber(theForm.cur_telComPrefixo.value)) {
  	alert ("O DDD do 'telefone residencial' não é um número.");
	theForm.cur_telComPrefixo.focus();
	return (false);	
  }
  if (!isNumber(theForm.cur_telCom.value)) {
  	alert ("O 'telefone comercial' não é um número.");
	theForm.cur_telCom.focus();
	return (false);	
  }
/*  if ((theForm.cur_celularPrefixo.value == "")||(theForm.cur_celular.value == "")){
  	alert ("'Celular' é um campo obrigatório.");
	theForm.cur_celularPrefixo.focus();
	return (false);
  }
*/  if (!isNumber(theForm.cur_celularPrefixo.value)) {
  	alert ("O DDD do 'celular' não é um número.");
	theForm.cur_celularPrefixo.focus();
	return (false);	
  }
  if (!isNumber(theForm.cur_celular.value)) {
  	alert ("O 'celular' não é um número.");
	theForm.cur_celular.focus();
	return (false);	
  }
/*  if ((theForm.cur_faxPrefixo.value == "")||(theForm.cur_fax.value == "")){
  	alert ("'Fax' é um campo obrigatório.");
	theForm.cur_faxPrefixo.focus();
	return (false);
  }
*/  if (!isNumber(theForm.cur_faxPrefixo.value)) {
  	alert ("O DDD do 'fax' não é um número.");
	theForm.cur_faxPrefixo.focus();
	return (false);	
  }
  if (!isNumber(theForm.cur_fax.value)) {
  	alert ("O 'fax' não é um número.");
	theForm.cur_fax.focus();
	return (false);	
  }
/*  if (theForm.cur_homePage.value == ""){
  	alert ("'Home Page' é um campo obrigatório.");
	theForm.cur_homePage.focus();
	return (false);
  }
*/  //alert (theForm.elements['are_interesse[]'].selectedIndex);
  //return (false);
  if (theForm.elements['are_interesse[]'].selectedIndex == "-1") {
  	alert ("'Área de interesse' é um campo obrigatório.");
	theForm.elements['are_interesse[]'].focus();
	return (false);
  }
  if ((!theForm.elements['vin[estagio][tipo]'].checked)&&(!theForm.elements['vin[clt][tipo]'].checked)&&(!theForm.elements['vin[pj][tipo]'].checked)&&(!theForm.elements['vin[cooperativa][tipo]'].checked)){
  	alert ("'Tipo de vínculo' tem que ter pelo menos um campo marcado.");
	theForm.elements['vin[estagio][tipo]'].focus();
	return (false);
  }
 if ((theForm.elements['vin[estagio][tipo]'].checked)&&(theForm.elements['vin[estagio][salario]'].value == "")) {
  	alert("Você marcou o campo 'Estágio', por favor insira um valor no campo 'Pretensão salarial'");
	theForm.elements['vin[estagio][salario]'].focus();
	return (false);
  }
   if ((theForm.elements['vin[clt][tipo]'].checked)&&(theForm.elements['vin[clt][salario]'].value == "")) {
  	alert("Você marcou o campo 'CLT', por favor insira um valor no campo 'Pretensão salarial'");
	theForm.elements['vin[clt][salario]'].focus();
	return (false);
  }
  if ((theForm.elements['vin[pj][tipo]'].checked)&&(theForm.elements['vin[pj][salario]'].value == "")) {
  	alert("Você marcou o campo 'Pessoa jurídica', por favor insira um valor no campo 'Pretensão salarial'");
	theForm.elements['vin[pj][salario]'].focus();
	return (false);
  }
  if ((theForm.elements['vin[cooperativa][tipo]'].checked)&&(theForm.elements['vin[cooperativa][salario]'].value == "")) {
  	alert("Você marcou o campo 'Filiado á cooperativa', por favor insira um valor no campo 'Pretensão salarial'");
	theForm.elements['vin[cooperativa][salario]'].focus();
	return (false);
  }
  if (theForm.cur_objetivos.value == ""){
  	alert ("Por favor, 'Faça uma breve descrição dos objetivos pretendidos na empresa'");
	theForm.cur_objetivos.focus();
	return (false);
  }
  if (theForm.cur_autoCritica.value == ""){
  	alert ("Por favor, 'faça uma auto-crítica e fale um pouco do seu perfil'");
	theForm.cur_autoCritica.focus();
	return (false);
  }
  if ((!theForm.elements['idi[port][idioma]'].checked)&&(!theForm.elements['idi[ing][idioma]'].checked)&&(!theForm.elements['idi[esp][idioma]'].checked)){
  	alert ("'Idioma' tem que ter pelo menos um campo marcado.");
	theForm.elements['idi[port][idioma]'].focus();
	return (false);
  }
	
  if ((theForm.elements['idi[port][idioma]'].checked)&&((!theForm.elements['idi[port][nivel]']['0'].checked)&&(!theForm.elements['idi[port][nivel]']['1'].checked)&&(!theForm.elements['idi[port][nivel]']['2'].checked))) {
  	alert("Você marcou o idioma 'Português'. Por favor, marque um nível");
	theForm.elements['idi[port][idioma]'].focus();
	return (false);
  }
  if ((theForm.elements['idi[ing][idioma]'].checked)&&((!theForm.elements['idi[ing][nivel]']['0'].checked)&&(!theForm.elements['idi[ing][nivel]']['1'].checked)&&(!theForm.elements['idi[ing][nivel]']['2'].checked))) {
  	alert("Você marcou o idioma 'Inglês'. Por favor, marque um nível");
	theForm.elements['idi[ing][nivel]'].focus();
	return (false);
  }
  if ((theForm.elements['idi[esp][idioma]'].checked)&&((!theForm.elements['idi[esp][nivel]']['0'].checked)&&(!theForm.elements['idi[esp][nivel]']['1'].checked)&&(!theForm.elements['idi[esp][nivel]']['2'].checked))) {
  	alert("Você marcou o idioma 'Espanhol'. Por favor, marque um nível");
	theForm.elements['idi[esp][nivel]'].focus();
	return (false);
  }

/*  if (theForm.cur_idiomaOutro.value == ""){
  	alert ("'Outros' é um campo obrigatório");
	theForm.cur_idiomaOutro.focus();
	return (false);
  }
*/
  for(i=1;i<=4;i++) {
  	if((theForm.elements['for['+i+'][grau]'].value!="-1")||(theForm.elements['for['+i+'][curso]'].value!="")
||(theForm.elements['for['+i+'][ini_dia]'].value!="")||(theForm.elements['for['+i+'][ini_mes]'].value!="")
||(theForm.elements['for['+i+'][ini_ano]'].value!="")||(theForm.elements['for['+i+'][fim_dia]'].value!="")||(theForm.elements['for['+i+'][fim_mes]'].value!="")
||(theForm.elements['for['+i+'][fim_ano]'].value!="")||(theForm.elements['for['+i+'][instituicao]'].value!="")
||(theForm.elements['for['+i+'][status]']['0'].checked)||(theForm.elements['for['+i+'][status]']['1'].checked)) {
	  if(theForm.elements['for['+i+'][grau]'].value=="-1") {
	  		alert("'Grau de formação' é um campo obrigatório.");
			theForm.elements['for['+i+'][grau]'].focus();
			return (false);
	  }
	  if(theForm.elements['for['+i+'][curso]'].value=="") {
	  		alert("'Curso' é um campo obrigatório.");
			theForm.elements['for['+i+'][curso]'].focus();
			return (false);
	  }
	  if((theForm.elements['for['+i+'][ini_dia]'].value=="")||(theForm.elements['for['+i+'][ini_mes]'].value=="")||(theForm.elements['for['+i+'][ini_ano]'].value=="")) {
	  		alert("'Data de início' é um campo obrigatório.");
			theForm.elements['for['+i+'][ini_dia]'].focus();
			return (false);
	  }
	  if(!(DataOk(theForm.elements['for['+j+'][ini_dia]'].value+"/"+theForm.elements['for['+j+'][ini_mes]'].value+"/"+theForm.elements['for['+j+'][ini_ano]'].value))) {
			alert("'Data de início' não é uma data válida.");
			theForm.elements['for['+j+'][ini_dia]'].focus();
			return (false);
	  }
	  if((theForm.elements['for['+i+'][fim_dia]'].value=="")||(theForm.elements['for['+i+'][fim_mes]'].value=="")||(theForm.elements['for['+i+'][fim_ano]'].value=="")) {
	  		alert("'Data de fim' é um campo obrigatório.");
			theForm.elements['for['+i+'][fim_dia]'].focus();
			return (false);
	  }
	  if(!DataOk(theForm.elements['for['+j+'][fim_dia]'].value+"/"+theForm.elements['for['+j+'][fim_mes]'].value+"/"+theForm.elements['for['+j+'][fim_ano]'].value)) {
			alert("'Data de fim' não é uma data válida.");
			theForm.elements['for['+j+'][fim_dia]'].focus();
			return (false);
	  }
	  if(theForm.elements['for['+i+'][instituicao]'].value == "") {
	  		alert("'Instituição' é um campo obrigatório.");
			theForm.elements['for['+i+'][instituicao]'].focus();
			return (false);
	  }
	  if((!theForm.elements['for['+i+'][status]']['0'].checked)&&(!theForm.elements['for['+i+'][status]']['1'].checked)) {
	  		alert("Selecione um campo de status do seu curso, ou 'Concluído' ou 'Semestre'. ");
			theForm.elements['for['+i+'][status]']['0'].focus();
			return (false);
	  }
	  if((theForm.elements['for['+i+'][status]']['1'].checked)&&(theForm.elements['for['+i+'][semestre]'].value == "")) {
	  		alert("Você selecionou o campo 'Semestre', por favor indique em qual semestre está");
			theForm.elements['for['+i+'][semestre]'].focus();
			return (false);
	  }
	}
  }
  for(j=1;j<=7;j++) {
  	if((theForm.elements['exp['+j+'][ini_dia]'].value!="")||(theForm.elements['exp['+j+'][ini_mes]'].value!="")
||(theForm.elements['exp['+j+'][ini_ano]'].value!="")||(theForm.elements['exp['+j+'][fim_dia]'].value!="")||(theForm.elements['exp['+j+'][fim_mes]'].value!="")
||(theForm.elements['exp['+j+'][fim_ano]'].value!="")||(theForm.elements['exp['+j+'][empresa]'].value!="")||(theForm.elements['exp['+j+'][ultimoCargo]'].value!="")
||(theForm.elements['exp['+j+'][realizacoes]'].value!="")) {
	  if((theForm.elements['exp['+j+'][ini_dia]'].value=="")||(theForm.elements['exp['+j+'][ini_mes]'].value=="")||(theForm.elements['exp['+j+'][ini_ano]'].value=="")) {
	  		alert("'Data de início' é um campo obrigatório.");
			theForm.elements['exp['+j+'][ini_dia]'].focus();
			return (false);
	  }
	  //alert(DataOk(theForm.elements['exp['+j+'][ini_dia]'].value+"/"+theForm.elements['exp['+j+'][ini_mes]'].value+"/"+theForm.elements['exp['+j+'][ini_ano]'].value));
	  if(!(DataOk(theForm.elements['exp['+j+'][ini_dia]'].value+"/"+theForm.elements['exp['+j+'][ini_mes]'].value+"/"+theForm.elements['exp['+j+'][ini_ano]'].value))) {
			alert("'Data de início' não é uma data válida.");
			theForm.elements['exp['+j+'][ini_dia]'].focus();
			return (false);
	  }
	  if((theForm.elements['exp['+j+'][fim_dia]'].value=="")||(theForm.elements['exp['+j+'][fim_mes]'].value=="")||(theForm.elements['exp['+j+'][fim_ano]'].value=="")) {
	  		alert("'Data de fim' é um campo obrigatório.");
			theForm.elements['exp['+j+'][fim_dia]'].focus();
			return (false);
	  }
	  if(!DataOk(theForm.elements['exp['+j+'][fim_dia]'].value+"/"+theForm.elements['exp['+j+'][fim_mes]'].value+"/"+theForm.elements['exp['+j+'][fim_ano]'].value)) {
			alert("'Data de fim' não é uma data válida.");
			theForm.elements['exp['+j+'][fim_dia]'].focus();
			return (false);
	  }
	  if(theForm.elements['exp['+j+'][empresa]'].value=="") {
	  		alert("'Empresa' é um campo obrigatório.");
			theForm.elements['exp['+j+'][empresa]'].focus();
			return (false);
	  }
	  if(theForm.elements['exp['+j+'][ultimoCargo]'].value=="") {
	  		alert("'Último cargo' é um campo obrigatório.");
			theForm.elements['exp['+j+'][ultimoCargo]'].focus();
			return (false);
	  }
	  if(theForm.elements['exp['+j+'][realizacoes]'].value=="") {
	  		alert("'Atribuições/realizações no cargo' é um campo obrigatório.");
			theForm.elements['exp['+j+'][realizacoes]'].focus();
			return (false);
	  }
	}
  }
  return (true);
}


/* VALIDACAO DE DATA!! */
//-----------------------------------------------------------------
//valida a data digitada no formato DD/MM/AAAA 
function DataOk(data)
{
	var iDia ;
	var iMes ;
	var iAno ;
	iDia = data.substr(0, 2);
	iMes = data.substr(3, 2);
	iAno = data.substr(6, 4);
	// a linha abaixo serve para delimitar os anos. hoje, 15/09/2003. Provavelmente não há ninguém nascido antes de 1880 e nenhuma pessoa com idade menor que 11 anos assistirá ao evento
	if (iAno < "1880" || iAno > "5000")
		return (false);
	if ((iAno - "1980" < 0) && (iAno - "2080" > 0))
		return (false);
	if (iMes - "12" > 0)
		return (false);
	if ((iMes == "01") || (iMes == "03") || (iMes == "05") || 
       (iMes == "07") || (iMes == "08") || (iMes == "10") || 
       (iMes == "12"))
		return ((iDia - "01" >= 0) && (iDia - "31" <= 0));
	if ((iMes == "04") || (iMes == "06") || (iMes == "09") || 
       (iMes == 11))
		return ((iDia - "01" >= 0) && (iDia - "30" <= 0));
	if (iMes == "02")
	{
		return (((iDia - "01" >= 0) && (iDia - "28" <= 0)) ||
					((iDia == "29") && (parseFloat(iAno) % 4 == 0)));
	}
	return (false);  
}
//-----------------------------------------------------------------

//inverte data para formato AAAA/MM/DD
function InverteData(szOrig)
{
	// Procura pela primeira barra
	temBarra = 1;
	if (szOrig.indexOf("/", 1) == -1)
		temBarra = 0;

	szDia = szOrig.substring(0, 2);
	szMes = szOrig.substring(2 + temBarra, 4 + temBarra);
  	if (szOrig.length > 5)
		szAno = szOrig.substring(4 + (2 * temBarra), szOrig.length)
	else
		szAno = "00";
   return (szAno + szMes + szDia);
} 

// valida data pela posição das barras
function DataValida(szOrig, bSoMes)
{
	// Procura pela primeira barra, se não tem cai fora.
	psBarra1 = szOrig.indexOf("/", 1);
	if (psBarra1 == -1)
	{
		if ((bSoMes == true) && (strlen(szOrig) == 4))
		{
			szDia = "01";
			szMes = szOrig.substring(0, 2);
			szAno = szOrig.substring(2, 4);
		}
		else
      	if (szOrig.length == 8)
      	{
			szDia = szOrig.substring(0, 2);
			szMes = szOrig.substring(2, 4);
			szAno = szOrig.substring(4, 8);
		}
			return (false);
   }
	else
   {
		// Procura pela segunda barra, se não tem o formato é MM/AA.
		psBarra2 = szOrig.indexOf("/", psBarra1 + 1);
		if (psBarra2 == -1)
		{
			if (bSoMes == false)
				return (false);
			szDia = "01";
			psBarra2 = psBarra1;
			psBarra1 = 1;
		}

		// Se o formato é DD/MM/AA, pega o dia.
		else
		{
			szDia = szOrig.substring(0, psBarra1);
			psBarra1 = psBarra1 + 1;
		}

		// Pega o mês.
		szMes = szOrig.substring(psBarra1, psBarra2);
		szAno = szOrig.substring(psBarra2 + 1, szOrig.length)

   }
	// Verifica se houve erro nas conversões ou nos valores obtidos.
	return (DataOk(szDia, szMes, szAno));
} 

//transforma uma string em variável data
function StringToDate(szOrig, bSoMes)
{
  return (DataValida(szOrig, bSoMes))
}

//valida a string de data
function ValidacaoData(theData, strNomeCampo)
{
  if ((theData.value.length == 0) &&
      (strNomeCampo != "Data"))
  {
	return true
  }
  else
  {
    if ((theData.value.length != 10))
	{
		  alert("Preencha o campo de " + strNomeCampo + " no formato DD/MM/AAAA");
		  return (false);
	}
	else
	{
	   if ((theData.value.length == 8) && (theData.value.indexOf("/", 0) != -1))
	   {
		  alert("Preencha o campo de " + strNomeCampo + " no formato DDMMAAAA ou DD/MM/AAAA");
		  return (false);
		}
	}

    var checkOK = "0123456789/";
    var checkStr = theData.value;
    var allValid = true;
    for (i = 0;  i < checkStr.length;  i++)
    {
      ch = checkStr.charAt(i);
      for (j = 0;  j < checkOK.length;  j++)
        if (ch == checkOK.charAt(j))
          break;
      if (j == checkOK.length)
      {
        allValid = false;
        break;
      } 
    }
    if (!allValid)
    {
      alert("Preencha a data de " + strNomeCampo + " com números e barras.");
      return (false);
    }

    if ((StringToDate(DesformatoData(theData.value), false)))
    {
      alert(theData.value);
      alert("Data de " + strNomeCampo + " é inválida.");
      return (false);
  }
    return (true);
  }
}

//transforma a data em data juliana
function DataJuliana(iDia, iMes, iAno)
{
	var iTemp = (iMes - 14) / 12;

	return (iDia - 32075 + (1461 * (iAno + 4800 + iTemp) / 4) +
		(367 * (iMes - 2 - iTemp * 12) / 12) -
		(3 * ((iAno + 4900 + iTemp) / 100) / 4));
}

//tira as barras da data
function DesformatoData(strNumero)
{
	var intTamanho;
	var strResposta;

	strResposta = "";
	if (strNumero == "") 
		strResposta = "      "
	else
	    for (intTamanho = 0; intTamanho <strNumero.length; intTamanho++)
	        if (strNumero.charAt(intTamanho) != "/")
				strResposta = strResposta + strNumero.charAt(intTamanho);
	return strResposta;
}

//desformata a data
function DifData(theDataInicio, theDataFim)
{
	var theDataInicioAux = DesformatoData(theDataInicio.value);
	var theDataFimAux = DesformatoData(theDataFim.value);  
	var iDia1 = parseFloat(theDataInicioAux.substring(0, 2));
	var iMes1 = parseFloat(theDataInicioAux.substring(2, 4));
	var iAno1 = parseFloat(theDataInicioAux.substring(4, 8));
	var iDia2 = parseFloat(theDataFimAux.substring(0, 2));
	var iMes2 = parseFloat(theDataFimAux.substring(2, 4));
	var iAno2 = parseFloat(theDataFimAux.substring(4, 8));
 
 	return (DataJuliana(iDia2, iMes2, iAno2) -
		DataJuliana(iDia1, iMes1, iAno1));

}

// valida data em relação a valores mínimos
function ValidacaoDifData(theDataInicio, theDataFim)
{
  if ((theDataInicio.value.length != 0) &&
      (theDataFim.value.length != 0) &&
      (DifData(theDataInicio, theDataFim) < 0))
  {
    alert ("A data final do período deve ser maior ou igual à data inicial.");
    return (false);
  }

  return (true);
}

// valida data em relação a valores mínimos
function ValidacaoDifData(theDataInicio, theDataFim)
{
  if ((theDataInicio.value.length != 0) &&
      (theDataFim.value.length != 0) &&
      (DifData(theDataInicio, theDataFim) < 0))
  {
    alert ("A data final do período deve ser maior ou igual à data inicial.");
    return (false);
  }

  return (true);
}

function disableFields(campo){
	if ((campo.value != "cni")&&(campo.value != "sesi"))
		document.forms[0].unidadeFuncionario.disabled = true;
	else
		document.forms[0].unidadeFuncionario.disabled = false;
}

//para o Participante_v.tpl
function disableFields2(campo){
	if ((campo.value != "cni")&&(campo.value != "sesi"))
		document.forms[3].unidadeFuncionario.disabled = true;
	else
		document.forms[3].unidadeFuncionario.disabled = false;
}
