function trocaClasse(radio)
{
    if (radio=='Cursando')
    	document.getElementById('inscrito_cursando').className = 'nao_oculto';
    else
      if (radio=='Formado')
      	document.getElementById('inscrito_cursando').className = 'oculto';
}

function trocaClasse1()
{
  if (document.getElementById('instituicao').value == '0')
     document.getElementById('outra_instituicao').className = 'nao_oculto';
  else
     document.getElementById('outra_instituicao').className = 'oculto';
}

function trocaClasse2()
{
  if (document.getElementById('curso').value == 0)
     document.getElementById('outro_curso').className = 'nao_oculto';
  else
     document.getElementById('outro_curso').className = 'oculto';
}

function trocaClasse3()
{
  if (document.getElementById('bolsa').value == '-1')
  {
     document.getElementById('outra_bolsa').className = 'nao_oculto';
     document.getElementById('porcentagem_bolsa').className = 'nao_oculto';
  }
  else
  {
     document.getElementById('outra_bolsa').className = 'oculto';
     if(document.getElementById('bolsa').value == '0')
        document.getElementById('porcentagem_bolsa').className = 'oculto';
     else
        document.getElementById('porcentagem_bolsa').className = 'nao_oculto';
  }
}

function trocaClasse4()
{
	// alert(document.getElementById('rsim').checked)
    if (document.getElementById('rnao').checked)
	{
		document.getElementById('motivos').className = 'nao_oculto';
	}
	else
	{
		document.getElementById('motivos').className = 'oculto';
	}
}

function numero(e)
{
   if (window.event) //IE
   {
    tecla = e.keyCode;
   }

   else if (e.which) //FF
   {
    tecla = e.which;
   }
    //teclas dos numemros(0 - 9) de 48 a 57
   //techa==8 é para permitir o backspace funcionar para apagar

   if ( (tecla >= 48 && tecla <= 57)||(tecla == 8 ) ) {
      return true;
   }
   else
   {
       return false;
   }
}

function somente_numero(e)
{
   if (window.event) //IE
   {
    tecla = e.keyCode;
   }

   else if (e.which) //FF
   {
    tecla = e.which;
   }
    //teclas dos numemros(0 - 9) de 48 a 57
   //techa==8 é para permitir o backspace funcionar para apagar

   if ( (tecla >= 48 && tecla <= 57)||(tecla == 8 ) ) {
      return true;
   }
   else
   {
       return false;
   }
}

function sonumero(evtKeyPress, traco_ponto)
{
	var nTecla;
	nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
	if(nTecla > 47 && nTecla < 58)
	{
		return true;
	}
	else
	{
		if ((nTecla == 8) || (nTecla==9)) return true;
		else if((traco_ponto == 1) && (nTecla==45 || nTecla==46)) return true;
		else
		{
			return false;
		}
	}
}

function valida()
{

	if (document.cadastro.nome.value.length<10)
	{
	   alert("Nome do inscrito inválido!");
	   document.cadastro.nome.focus();
	   return false;
	}
	if (ValidarCPF(document.cadastro.cpf)==false)
	{
		alert('CPF inválido');
		document.cadastro.cpf.focus();
		return false;
	}

	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.cadastro.email.value)))
	{
	   alert("Email inválido!");
	   document.cadastro.email.focus();
	   return false;
	}

    if (document.cadastro.telefone_ddd.value.length<2)
	{
	   alert("DDD do telefone está incompleto!");
	   document.cadastro.telefone_ddd.focus();
	   return false;
	}
	
    if (document.cadastro.telefone.value.length<8)
	{
	   alert("Número do telefone de contato está incompleto!");
	   document.cadastro.telefone.focus();
	   return false;
	}

    if (document.cadastro.celular_ddd.value.length<2)
	{
	   alert("DDD do celular está incompleto!");
	   document.cadastro.celular_ddd.focus();
	   return false;
	}

    if (document.cadastro.celular.value.length<8)
	{
	   alert("Número do celular de contato está incompleto!");
	   document.cadastro.celular.focus();
	   return false;
	}

	if (document.cadastro.instituicao.value==-1)
	{
	   alert("Instituição de ensino não foi informada!");
	   document.cadastro.instituicao.focus();
	   return false;
	}
 	else
      if ((document.cadastro.instituicao.value==0) && (document.cadastro.outrainst.value.length==0))
      {
	      alert("Instituição de ensino não foi informada!");
	      document.cadastro.outrainst.focus();
	      return false;
      }

	if (document.cadastro.cursointeresse.value==-1)
	{
	   alert("O curso de interesse no Unileste não foi informado!");
	   document.cadastro.cursointeresse.focus();
	   return false;
	}
    return true;
}

function valida_contato()
{

	if (document.cadastro.nome.value.length<10)
	{
	   alert("Nome do inscrito inválido!");
	   document.cadastro.nome.focus();
	   return false;
	}
	if (ValidarCPF(document.cadastro.cpf)==false)
	{
		alert('CPF inválido');
		document.cadastro.cpf.focus();
		return false;
	}

	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.cadastro.email.value)))
	{
	   alert("Email inválido!");
	   document.cadastro.email.focus();
	   return false;
	}

    if (document.cadastro.telefone.value.length<10)
	{
	   alert("Número do telefone de contato está incompleto!");
	   document.cadastro.telefone.focus();
	   return false;
	}

    if (document.cadastro.celular.value.length<10)
	{
	   alert("Número do celular de contato está incompleto!");
	   document.cadastro.celular.focus();
	   return false;
	}

	if (document.cadastro.instituicao.value==-1)
	{
	   alert("Instituição de ensino não foi informada!");
	   document.cadastro.instituicao.focus();
	   return false;
	}
 	else
      if ((document.cadastro.instituicao.value==0) && (document.cadastro.outrainst.value.length==0))
      {
	      alert("Instituição de ensino não foi informada!");
	      document.cadastro.outrainst.focus();
	      return false;
      }

	if (document.cadastro.cursointeresse.value==-1)
	{
	   alert("O curso de interesse no Unileste não foi informado!");
	   document.cadastro.cursointeresse.focus();
	   return false;
	}
    return true;
}

function valida_cpf(event, objeto){
	if(sonumero(event, 0))
	{
		var keypress=(window.event)?event.keyCode:event.which;
		campo = eval (objeto);
		caracteres = '0123456789';
		if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (15))
		{
			tam_cac = campo.value.length;
			if ( tam_cac == 3 || tam_cac == 7 || tam_cac == 8) campo.value = campo.value + '.';
			else if(tam_cac == 11) campo.value = campo.value + '-';
		}
		else
		{
			event.returnValue = false;
		}
	}
	else
	{
		return false;
	}
}

function ValidarCPF(Objcpf)
{
	var cpf = Objcpf.value;
	exp = /\.|\-/g
	cpf = cpf.toString().replace( exp, "" );
	var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));
	var soma1=0, soma2=0;
	var vlr =11;

	for(i=0;i<9;i++){
		soma1+=eval(cpf.charAt(i)*(vlr-1));
		soma2+=eval(cpf.charAt(i)*vlr);
		vlr--;
	}
	soma1 = (((soma1*10)%11)==10 ? 0:((soma1*10)%11));
	soma2=(((soma2+(2*soma1))*10)%11)==10 ? 0: (((soma2+(2*soma1))*10)%11);

	var digitoGerado=(soma1*10)+soma2;
	if(digitoGerado!=digitoDigitado)
		return false;
	else
		if(cpf=='00000000000')
			return false;
		else	
			return true;
}