//Início das funções das máscaras.

function mascara(o,f)
{
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara()
{
    v_obj.value=v_fun(v_obj.value)
}

function leech(v)
{
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}

function soNumeros(v)
{
    return v.replace(/\D/g,"")
}

function format_telefone(v)
{
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function format_hora(v)
{    
	v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
	v=v.replace(/^(\d{2})(\d)/,"$1:$2")
	return v  
}   

function format_data(v)
{
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/(\d{2})(\d)/,"$1/$2")    //Coloca barra entre o segundo e o terceiro dígitos
	v=v.replace(/(\d{2})(\d)/,"$1/$2")    //Coloca barra entre o quarto e o quinto dígitos
	return v
}

function format_cep(v)
{
    v=v.replace(/\D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

//Fim das funções da máscaras.

function Foco() 
{
	document.getElementById('enter').pagina_p.focus()
	document.getElementById('enter').pagina_p.select() 
}

//#### Início do código de reconhecer ENTER no formulário de login  ####
function submitenter(myfield,e)
{
	var keycode;
	if(window.event) keycode = window.event.keyCode;
	else if(e) keycode = e.which;
	else return true;

	if(keycode == 13)
   	{
   		return valida_login(this);
   	}
	else
   	return true;
}
//##### Fim do código de reconhecer ENTER no formulário de login  ######

function valida_login() 
{
	if(document.getElementById('form_login').US08CPF.value.length < 1)
	{
		alert('O campo [CPF] não foi preenchido.');
		document.getElementById('form_login').US08CPF.focus();
		return false;
	}
	if(document.getElementById('form_login').US08SENHA.value.length < 1)
	{
		alert('O campo [Senha] não foi preenchido.');
		document.getElementById('form_login').US08SENHA.focus();
		return false; 
	}
	document.getElementById('form_login').submit(); 
}

function valida_consulta() 
{
	if(document.getElementById('form_consulta').US08CPF.value.length < 1)
	{
		alert('O campo [CPF] não foi preenchido.');
		document.getElementById('form_consulta').US08CPF.focus();
		return false;
	}
	document.getElementById('form_consulta').submit(); 
}

function valida_alterar_senha() 
{
	if(document.getElementById('form_alterar_senha').US08SENHA.value < 1)
	{
		alert('O campo [Nova Senha] não foi preenchido.');
		document.getElementById('form_alterar_senha').US08SENHA.focus(); 
		return false;
	}
	if(document.getElementById('form_alterar_senha').US08SENHA.value != document.getElementById('form_alterar_senha').senha.value)
	{
		alert('O campo [Nova senha] e [Confirmar senha] tem que ser iguais.');
		document.getElementById('form_alterar_senha').US08SENHA.focus();
		return false; 
	}
	document.getElementById('form_alterar_senha').submit(); 
}

function verifica_opcao(valor)
{
  if(valor == '2')
  {
	  	document.getElementById('curso').style.display         = 'block';
		document.getElementById('curso_ano').style.display     = 'block';
		document.getElementById('pos_graduacao').style.display = 'block';
        document.getElementById('curso').disabled              = false;
		document.getElementById('curso_ano').disabled          = false;
        document.getElementById('pos_graduacao').disabled      = false;
		
		verifica_opcao2(document.getElementById('US08CURPOS').value)
  }
  else
  {
	  	document.getElementById('curso').style.display         = 'none';
		document.getElementById('curso_ano').style.display     = 'none';
		document.getElementById('pos_graduacao').style.display = 'none';
	  	document.getElementById('curso').disabled              = true;
		document.getElementById('curso_ano').disabled          = true;
	  	document.getElementById('pos_graduacao').disabled      = true;
		
		document.getElementById('titulacao').style.display = 'none';
		document.getElementById('area').style.display      = 'none';
		document.getElementById('pos_ano').style.display   = 'none';
	  	document.getElementById('titulacao').disabled      = true;
		document.getElementById('area').disabled           = true;
		document.getElementById('pos_ano').disabled        = true;
  }  
}

function verifica_opcao2(valor)
{
  if(valor == '1')
  {
	  	document.getElementById('titulacao').style.display = 'block';
		document.getElementById('area').style.display      = 'block';
		document.getElementById('pos_ano').style.display   = 'block';
        document.getElementById('titulacao').disabled      = false;
		document.getElementById('area').disabled           = false;
		document.getElementById('pos_ano').disabled        = false;
  }
  else
  {
	  	document.getElementById('titulacao').style.display = 'none';
		document.getElementById('area').style.display      = 'none';
		document.getElementById('pos_ano').style.display   = 'none';
	  	document.getElementById('titulacao').disabled      = true;
		document.getElementById('area').disabled           = true;
		document.getElementById('pos_ano').disabled        = true;
  } 
}

function verifica_opcao3(valor)
{
  if(document.getElementById('form_cadastro').US08CURDIST_S.checked == true)
  {
	  	document.getElementById('experiencia').style.display = 'block';
        document.getElementById('experiencia').disabled      = false;
  }
  else
  {
	  	document.getElementById('experiencia').style.display = 'none';
	  	document.getElementById('experiencia').disabled      = true;
  }
	  
}

function valida_cadastro(form, tipo) 
{
	if(document.getElementById(form).US08NOME.value.length < 1)
	{
		alert('O campo [Nome Completo] não foi preenchido.');
		document.getElementById(form).US08NOME.focus();
		return false;
	}
	if(document.getElementById(form).US08DTNASC.value.length < 1)
	{
		alert('O campo [Nascimento] não foi preenchido.');
		document.getElementById(form).US08DTNASC.focus();
		return false; 
	}
	if(document.getElementById(form).US08SEXO_M.checked == false && document.getElementById(form).US08SEXO_F.checked == false)
	{
		alert('O campo [Sexo] não foi preenchido.');
		return false; 
	}
	if(document.getElementById(form).US08NATURAL.value.length < 1)
	{
		alert('O campo [Naturalidade] não foi preenchido.');
		document.getElementById(form).US08NATURAL.focus();
		return false; 
	}
	if(document.getElementById(form).US08NACION.value.length < 1)
	{
		alert('O campo [Nacionalidade] não foi preenchido.');
		document.getElementById(form).US08NACION.focus();
		return false; 
	}
	if(document.getElementById(form).US08ENDERECO.value.length < 1)
	{
		alert('O campo [Endereço] não foi preenchido.');
		document.getElementById(form).US08ENDERECO.focus();
		return false; 
	}
	if(document.getElementById(form).US08BAIRRO.value.length < 1)
	{
		alert('O campo [Bairro] não foi preenchido.');
		document.getElementById(form).US08BAIRRO.focus();
		return false; 
	}
	if(document.getElementById(form).US08CEP.value.length < 1)
	{
		alert('O campo [CEP] não foi preenchido.');
		document.getElementById(form).US08CEP.focus();
		return false; 
	}
	if(document.getElementById(form).estado.value == '0')
	{
		alert('O campo [Estado] não foi preenchido.');
		document.getElementById(form).estado.focus(); 
		return false; 
	}
	if(document.getElementById(form).cidade.value == '0')
	{
		alert('O campo [Cidade] não foi preenchido.');
		document.getElementById(form).cidade.focus(); 
		return false; 
	}
	if(document.getElementById(form).US08TELRES.value.length < 1)
	{
		alert('O campo [Telefone] não foi preenchido.');
		document.getElementById(form).US08TELRES.focus();
		return false; 
	}
	if(document.getElementById(form).US08IDENT.value.length < 1)
	{
		alert('O campo [Identidade] não foi preenchido.');
		document.getElementById(form).US08IDENT.focus();
		return false; 
	}
	if(document.getElementById(form).US08ORGAOEMI.value.length < 1)
	{
		alert('O campo [Orgão Emissor] não foi preenchido.');
		document.getElementById(form).US08ORGAOEMI.focus();
		return false; 
	}
	if(document.getElementById(form).US08PAI.value.length < 1)
	{
		alert('O campo [Nome do Pai] não foi preenchido.');
		document.getElementById(form).US08PAI.focus();
		return false; 
	}
	if(document.getElementById(form).US08MAE.value.length < 1)
	{
		alert('O campo [Nome da Mãe] não foi preenchido.');
		document.getElementById(form).US08MAE.focus();
		return false; 
	}
	if(document.getElementById(form).US08ESTCIVIL.value == '0')
	{
		alert('O campo [Estado Civil] não foi preenchido.');
		document.getElementById(form).US08ESTCIVIL.focus(); 
		return false;
	}
	if(document.getElementById(form).escolaridade.value == '0')
	{
		alert('O campo [Grau de Escolaridade] não foi preenchido.');
		document.getElementById(form).escolaridade.focus();
		return false; 
	}
	if(document.getElementById(form).escolaridade.value == '1')
	{
		if(document.getElementById(form).FK08050CODIGO.value == '0')
		{	
			alert('O campo [Instituição] não foi preenchido.');
			document.getElementById(form).FK08050CODIGO.focus();
			return false; 
		}
	}
	if(document.getElementById(form).escolaridade.value == '2')
	{
		if(document.getElementById(form).FK08051CODIGO.value == '0')
		{	
			alert('O campo [Curso] não foi preenchido.');
			document.getElementById(form).FK08051CODIGO.focus();
			return false; 
		}
		if(document.getElementById(form).FK08050CODIGO.value == '0')
		{	
			alert('O campo [Instituição] não foi preenchido.');
			document.getElementById(form).FK08050CODIGO.focus();
			return false; 
		}
		if(document.getElementById(form).US08051ANO.value == '0')
		{
			alert('O campo [Ano de Conclusão] não foi preenchido.');
			document.getElementById(form).US08051ANO.focus();
			return false; 
		} 
		if(document.getElementById(form).US08CURPOS.value == '0')
		{	
			alert('O campo [Possui Pós-Graduação] não foi preenchido.');
			document.getElementById(form).US08CURPOS.focus();
			return false; 
		}
		if(document.getElementById(form).US08CURPOS.value == '1')
		{	
			if(document.getElementById(form).US08TITULACAO.value == '0')
			{	
				alert('O campo [Titulação] não foi preenchido.');
				document.getElementById(form).US08TITULACAO.focus();
				return false; 
			}
			if(document.getElementById(form).US08AREA.value.length < 1)
			{
				alert('O campo [Área] não foi preenchido.');
				document.getElementById(form).US08AREA.focus();
				return false; 
			}
			if(document.getElementById(form).US08POS_ANO.value == '0')
			{
				alert('O campo [Ano de Conclusão] não foi preenchido.');
				document.getElementById(form).US08POS_ANO.focus();
				return false; 
			} 
		}
	}
	if((tipo == 'incluir' || tipo == 'atualizar') && document.getElementById(form).US08CURRICULO.value == '')
	{
		alert("O campo [Anexar Currículo] não foi preenchido.");
		document.getElementById(form).US08CURRICULO.focus(); 
		return false;
	}
	if(tipo == 'incluir' || tipo == 'atualizar')
	{
		if(document.getElementById(form).US08CURDIST_S.checked == false && document.getElementById(form).US08CURDIST_N.checked == false)
		{
			alert('A pergunta [Já realizou algum curso a distância?] não foi respondida.');
			return false;
		}
	
		if(document.getElementById(form).US08CURDIST_S.checked == true)
		{
			if(document.getElementById(form).US08EXPERIENCIA_E.checked == false && document.getElementById(form).US08EXPERIENCIA_B.checked == false && document.getElementById(form).US08EXPERIENCIA_R.checked == false)
			{
				alert('A pergunta [Como foi a experiência?] não foi respondida.');
				return false;
			}
		}
		if(document.getElementById(form).US08INTERNET_S.checked == false && document.getElementById(form).US08INTERNET_N.checked == false)
		{
			alert('A pergunta [Você tem acesso a internet em casa?] não foi respondida.');
			return false;
		}
		if(document.getElementById(form).US08UTILCOMPUT.value ==  '0')
		{
			alert('A pergunta [Com que frequencia você utiliza o computador?] não foi respondida.')
			document.getElementById(form).US08UTILCOMPUT.focus();
			return false; 
		}
	}
	if(document.getElementById(form).US08EMAIL.value < 1)
	{
		alert('O campo [E-mail] não foi preenchido.');
		document.getElementById(form).US08EMAIL.focus(); 
		return false;
	}
	if(tipo == 'incluir')
	{
		if(document.getElementById(form).email.value < 1)
		{
			alert('O campo [Confirmar E-mail] não foi preenchido.');
			document.getElementById(form).email.focus(); 
			return false;
		}
		if(document.getElementById(form).US08EMAIL.value != document.getElementById(form).email.value)
		{
			alert('O campo [E-mail] e [Confirmar E-mail] tem que ser iguais.');
			document.getElementById(form).US08EMAIL.focus();
			return false; 
		}
		if(document.getElementById(form).US08SENHA.value.length < 1)
		{
			alert('O campo [Senha] não foi preenchido.');
			document.getElementById(form).US08SENHA.focus();
			return false;
		}
	}
	if(document.getElementById(form).ASSINATURA.checked == false)
	{
		alert('Você deve confirmar que seus dados são verdadeiros!');
		document.getElementById(form).ASSINATURA.focus();
		return false;
	}
	if(tipo == 'alterar')
	{
		if(confirm('Tem certeza que deseja alterar os dados?'))
		{ 
    		document.getElementById(form).submit(); 
		} 
	}
	else
	{
		document.getElementById(form).submit();
	}
}

function valida_inscricao(form) 
{
	if(document.getElementById(form).US01CODIGO.value ==  '0')
	{
		alert('O campo [Curso] não foi preenchido.')
		document.getElementById(form).US01CODIGO.focus();
		return false; 
	}
	if(document.getElementById(form).FK0907CODIGO_P0.value ==  '0')
	{
		alert('O campo [Polo (Opção 1)] não foi preenchido.')
		document.getElementById(form).FK0907CODIGO_P0.focus();
		return false; 
	}
	if(document.getElementById(form).FK0907CODIGO_P0.value ==  '0')
	{
		alert('O campo [Polo (Opção 2)] não foi preenchido.')
		document.getElementById(form).FK0907CODIGO_P1.focus();
		return false; 
	}
	if(document.getElementById(form).FK0907CODIGO_P0.value ==  document.getElementById(form).FK0907CODIGO_P1.value)
	{
		alert('O campo [Polo (Opção 1)] não não pode ser igual ao campo [Polo (Opção 2)].')
		document.getElementById(form).FK0907CODIGO_P0.focus();
		return false; 
	}
	if(document.getElementById(form).US09TAREFA_CASA.checked == false && document.getElementById(form).US09TAREFA_POLO.checked == false)
	{
		alert('A pergunta [Pensa em realizar parte do curso à distância em casa ou no polo?] não foi respondida.');
		return false; 
	}
	if(document.getElementById(form).US09DISPONIB.value ==  '0')
	{
		alert('A pergunta [Disponibilidade de horários para realizar os momentos presenciais?] não foi respondida.')
		document.getElementById(form).US09DISPONIB.focus();
		return false; 
	}
	if(document.getElementById(form).US09INFSABER.value ==  '0')
	{
		alert('A pergunta [Como você ficou sabendo da oferta desse curso?] não foi respondida.')
		document.getElementById(form).US09INFSABER.focus();
		return false; 
	}
	else
	{
		document.getElementById(form).submit();
	}
}
