//** Processo Seletivo Verificar CPF ************************************************************************************************************

function IWPM_VerificarCPF(CodPreMatricula,CPF,CPFDependente,JaCadastrado)
{
 try
 {   
  ShowAguarde(true);
  JRAjax.IWPM_VerificarCPF(ID,SessionID,CodPreMatricula,CPF,CPFDependente,JaCadastrado,cbk_IWPM_VerificarCPF)
 }
 catch(e)
 {
  alert(AjaxNotFound);
  ShowAguarde(false);
  return false;
 }
}

function cbk_IWPM_VerificarCPF(Request)
{
 ShowAguarde(false);
 
 if (!Request.value[0])
 {
  alert(Request.value[1]); 
  return false; 
 }
 
 try
 {
  new Function(Request.value[2])(); 
 }
 catch(e)
 {
  alert('Erro ao executar a sua solicitação!');
 }
}

//** Alterar Senha do usuário ******************************************************************************************************************

function IWPM_AlterarSenha(FormName, Matricula, CPFDependente, CodPreMatricula)
{
 var SenhaAtual     = document.getElementById("SenhaAtual");
 var NovaSenha      = document.getElementById("NovaSenha");
 var ConfirmarSenha = document.getElementById("ConfirmarSenha");
 
 if (!FormName || !Matricula || !CPFDependente || !CodPreMatricula || !SenhaAtual || !NovaSenha || !ConfirmarSenha)
  return alert(ComponentNotFound);
  
 try
 {
  JRAjax.IWPM_AlterarSenha(ID, SessionID, FormName, Matricula, CPFDependente, CodPreMatricula, SenhaAtual.value, NovaSenha.value, ConfirmarSenha.value, cbk_GenericCallBack);
 }
 catch(e)
 {
  alert(AjaxNotFound);
 }

}

//** Processo Seletivo Efetuar Inscricao ********************************************************************************************************

function IWPM_EfetuarInscricao(FormName, CodPreMatricula ,CPF)
{
 var edtCPFDependente         = document.getElementById("CPFDependente");
 var edtNome                  = document.getElementById("Nome");
 var edtRG                    = document.getElementById("RG");
 var edtDataNasc              = document.getElementById("DataNasc");
 var edtEndereco              = document.getElementById("Endereco");
 var edtComplemento           = document.getElementById("Complemento");
 var edtNumero                = document.getElementById("Numero");
 var edtBairro                = document.getElementById("Bairro");
 var edtCidade                = document.getElementById("Cidade");
 var edtUF                    = document.getElementById("UF");
 var edtCEP                   = document.getElementById("CEP");
 var edtTelefone              = document.getElementById("Telefone");
 var edtCelular               = document.getElementById("Celular");
 var edtEMail                 = document.getElementById("EMail");
 var edtSenha                 = document.getElementById("Senha");
 var edtConfirmarSenha        = document.getElementById("ConfirmarSenha");
 var edtDeficiencia           = document.getElementById("Deficiencia");
 var chkSexoMasculino         = document.getElementById("SexoMasculino");
 var chkSexoFeminino          = document.getElementById("SexoFeminino");
 var chkEstadoCivilSolteiro   = document.getElementById("EstadoCivilSolteiro");
 var chkEstadoCivilCasado     = document.getElementById("EstadoCivilCasado");
 var chkEstadoCivilDivorciado = document.getElementById("EstadoCivilDivorciado");
 var chkEstadoCivilViuvo      = document.getElementById("EstadoCivilViuvo");
 var chkHabilidadeDestro      = document.getElementById("HabilidadeDestro");
 var chkHabilidadeCanhoto     = document.getElementById("HabilidadeCanhoto");
 var chkDeficienteSim         = document.getElementById("DeficienteSim");
 var chkDeficienteNao         = document.getElementById("DeficienteNao");
 var edtRG_OrgaoExpeditor     = document.getElementById("RG_OrgaoExpeditor");
 var edtRG_DataExpedicao      = document.getElementById("RG_DataExpedicao");
 var edtProfissao             = document.getElementById("Profissao");
 var edtNacionalidade         = document.getElementById("Nacionalidade");
 var edtNaturalidade          = document.getElementById("Naturalidade");
 var edtUFNascimento          = document.getElementById("UFNascimento");
 var edtMae                   = document.getElementById("Mae");
 var edtPai                   = document.getElementById("Pai");
  
 if (
     (edtCPFDependente         == null) ||
     (edtNome                  == null) ||
     (edtRG                    == null) ||
     (edtDataNasc              == null) ||
     (edtEndereco              == null) ||
     (edtComplemento           == null) ||
     (edtNumero                == null) ||
     (edtBairro                == null) ||
     (edtCidade                == null) ||
     (edtUF                    == null) ||
     (edtCEP                   == null) ||
     (edtTelefone              == null) ||
     (edtCelular               == null) ||
     (edtEMail                 == null) ||
     (edtSenha                 == null) ||
     (edtConfirmarSenha        == null) ||
     (chkSexoMasculino         == null) ||
     (chkSexoFeminino          == null) ||
     (chkEstadoCivilSolteiro   == null) ||
     (chkEstadoCivilCasado     == null) ||
     (chkEstadoCivilDivorciado == null) ||
     (chkEstadoCivilViuvo      == null) ||
     (chkHabilidadeDestro      == null) ||
     (chkHabilidadeCanhoto     == null) ||
     (chkDeficienteSim         == null) ||
     (chkDeficienteNao         == null) ||
     ((chkDeficienteSim.checked) && (edtDeficiencia == null)) ||
     (edtRG_OrgaoExpeditor     == null) ||
     (edtRG_DataExpedicao      == null) ||
     (edtProfissao             == null) ||
     (edtNacionalidade         == null) ||
     (edtNaturalidade          == null) ||
     (edtUFNascimento          == null) ||
     (edtMae                   == null) ||
     (edtPai                   == null) 
    )                              
 {
  return alert(ComponentNotFound);
 } 
 
 var CPFDependente         = (edtCPFDependente         != null) ? edtCPFDependente.value         : "0";
 var Nome                  = (edtNome                  != null) ? edtNome.value                  : "";
 var RG                    = (edtRG                    != null) ? edtRG.value                    : "";
 var DataNasc              = (edtDataNasc              != null) ? edtDataNasc.value              : "";
 var Endereco              = (edtEndereco              != null) ? edtEndereco.value              : "";
 var Complemento           = (edtComplemento           != null) ? edtComplemento.value           : "";
 var Numero                = (edtNumero                != null) ? edtNumero.value                : "";
 var Bairro                = (edtBairro                != null) ? edtBairro.value                : "";
 var Cidade                = (edtCidade                != null) ? edtCidade.value                : "";
 var UF                    = (edtUF                    != null) ? edtUF.value                    : "";
 var CEP                   = (edtCEP                   != null) ? edtCEP.value                   : "";
 var Telefone              = (edtTelefone              != null) ? edtTelefone.value              : "";
 var Celular               = (edtCelular               != null) ? edtCelular.value               : "";
 var EMail                 = (edtEMail                 != null) ? edtEMail.value                 : "";
 var Senha                 = (edtSenha                 != null) ? edtSenha.value                 : "";
 var ConfirmarSenha        = (edtConfirmarSenha        != null) ? edtConfirmarSenha.value        : "";
 var Deficiencia           = (edtDeficiencia           != null) ? edtDeficiencia.value           : "";
 var SexoMasculino         = (chkSexoMasculino         != null) ? chkSexoMasculino.checked       : false;
 var HabilidadeDestro      = (chkHabilidadeDestro      != null) ? chkHabilidadeDestro.checked    : false;
 var Deficiente            = (chkDeficienteSim         != null) ? chkDeficienteSim.checked       : false;
 var RG_OrgaoExpeditor     = (edtRG_OrgaoExpeditor     != null) ? edtRG_OrgaoExpeditor.value     : "";
 var RG_DataExpedicao      = (edtRG_DataExpedicao      != null) ? edtRG_DataExpedicao.value      : "";
 var Profissao             = (edtProfissao             != null) ? edtProfissao.value             : "";
 var Nacionalidade         = (edtNacionalidade         != null) ? edtNacionalidade.value         : "";
 var Naturalidade          = (edtNaturalidade          != null) ? edtNaturalidade.value          : "";
 var UFNascimento          = (edtUFNascimento          != null) ? edtUFNascimento.value          : "";
 var Mae                   = (edtMae                   != null) ? edtMae.value                   : "";
 var Pai                   = (edtPai                   != null) ? edtPai.value                   : "";
 
 if (chkEstadoCivilSolteiro.checked)
  EstadoCivil = "SOLTEIRO(A)"
 else 
 if (chkEstadoCivilCasado.checked)
  EstadoCivil = "CASADO(A)"
 else 
 if (chkEstadoCivilDivorciado.checked)
  EstadoCivil = "DIVORCIADO(A)"
 else 
 if (chkEstadoCivilViuvo.checked)
  EstadoCivil = "VIÚVO(A)";
 else 
  return alert('Estado Civil não definido!');

 try
 {
  ShowAguarde(true);
  JRAjax.IWPM_EfetuarInscricao(ID,SessionID, FormName, CodPreMatricula, CPF, CPFDependente,
                               Nome,SexoMasculino,RG,DataNasc,EstadoCivil,HabilidadeDestro,Deficiente,Deficiencia,
                               Endereco,Complemento,Numero,Bairro,Cidade,UF,CEP,Telefone,Celular,EMail,Senha,ConfirmarSenha,
                               RG_OrgaoExpeditor,RG_DataExpedicao,Profissao,Nacionalidade,Naturalidade,UFNascimento,
                               Mae,Pai,
                               cbk_IWPM_EfetuarInscricao);
 }
 catch(e)
 {
  ShowAguarde(false);
  alert(AjaxNotFound);
 }
}

function cbk_IWPM_EfetuarInscricao(Request)
{
 ShowAguarde(false);
 
 if (!Request.value[0])
 {
  alert(Request.value[1]);
 
  var Control = document.getElementById(Request.value[2]);
  
  if (Control != null) 
  {
   Control.focus();
   
   if (Control.tagName.toUpperCase() == "INPUT")
    Control.style.backgroundColor = 'red';
  }
  
  return false;
 }
 
 try
 {
  new Function(Request.value[3])(); 
  return true;
 }
 catch(e)
 {}

 return false;
}


//** Processo Seletivo - Verificar Senha ********************************************************************************************************

function IWPM_VerificarSenha(CodPreMatricula, CPF, CPFDependente)
{
 var Senha      = document.getElementById("Senha");
 var SenhaIndex = document.getElementById("SenhaIndex");
 
 if ((Senha == null) || (SenhaIndex == null))
 {
  alert(ComponentNotFound);
  return;
 }

 try
 {
  ShowAguarde(true); 
  JRAjax.IWPM_VerificarSenha(ID,SessionID,CodPreMatricula,CPF,CPFDependente,Senha.value,parseInt(SenhaIndex.value),cbk_IWPM_VerificarSenha);
 }
 catch(e)
 {
  ShowAguarde(false); 
  alert(AjaxNotFound);
 } 
}

function cbk_IWPM_VerificarSenha(Request)
{
 var lbSenha    = document.getElementById("lbSenha");
 var SenhaIndex = document.getElementById("SenhaIndex");
 var Senha      = document.getElementById("Senha");
 
 ShowAguarde(false); 
 try
 {
  if ((lbSenha == null) || (SenhaIndex == null) || (Senha == null))
  {
   alert(ComponentNotFound);
   return ;
  }
  
  if (!Request.value[0])
  {
   IW_LoadDigitalKeyBord(false);
   
   if ((Request.value[1] != null) && (Request.value[1] != ""))
   {
    alert(Request.value[1]);
    return;
   }
   else
   {
    lbSenha.innerHTML   = Request.value[2];
    lbSenha.style.color = "Maroon";
    ;
   }  
   return;
  }
  
  //Senha Valida!
  lbSenha.innerHTML = "";
  lbSenha.style.color = "navy";
  Senha.value = "";

  //Scripts
  try
  {
   new Function(Request.value[3])();
  }
  catch(e)
  {}
  
 }
 catch(e)
 {
  alert('Erro: '+e.Message);
 }
 finally
 {
  ShowAguarde(false); 
 }
}


//** Alterar Dia de Vencimento da Pré-Matrícula ****************************************************************************************

function IWPM_AdicionarPreMatricula(FormName, Matricula, CPFDependente, CodPreMatricula)
{
 var lstTurmas = document.getElementById("lstTurmas");
 var edtDiaVencimento = document.getElementById("edtDiaVencimento");
 
 if (!FormName || !Matricula || !CodPreMatricula || !lstTurmas)
  return alert(ComponentNotFound);

 if (lstTurmas.selectedIndex <= 0)
 {
  return alert('É necessário que selecione uma turma');
  lstTurmas.focus();
 }
 
 var DiaVencimento = edtDiaVencimento.selectedIndex+1;
 
 try
 {
  var Str = lstTurmas.value; 
  var Periodo = Str.substring(0,7);
  var CodTurma = Str.substring(7,13);

  ShowAguarde(true);  
  JRAjax.IWPM_AdicionarPreMatricula(ID, SessionID, FormName, Matricula, CPFDependente, CodPreMatricula, Periodo, CodTurma, DiaVencimento, cbk_GenericCallBack);
 }
 catch(E)
 {
  ShowAguarde(false);
  return alert(AjaxNotFound); 
 }
}

//** Excluir Pré-Matrículas ************************************************************************************************

function IWPM_ExcluirEnturmacoes()
{
 var CodTurmas = new Array();
 var Periodos  = new Array();
 
 var Index = 0;
 var Idx = 0;
 var CheckBox = document.getElementById("chk[" + Index + "]");
 
 while (CheckBox != null)
 {
  if (CheckBox.checked)
  {
   var ObjCodTurma = document.getElementById("Turma[" + Index + "].CodTurma");
   var ObjPeriodo  = document.getElementById("Turma[" + Index + "].Periodo");
   
   if ((ObjCodTurma != null) && (ObjPeriodo != null))
   {
    CodTurmas[Idx] = ObjCodTurma.value;
    Periodos[Idx]  = ObjPeriodo.value;
    Idx++;
   }
  }
 
  Index++;
  var CheckBox = document.getElementById("chk[" + Index + "]");
 }
 
 if (confirm('Deseja excluir as Pre-Matriculas selecionadas?'))
 try
 {
  ShowAguarde(true);  
  JRAjax.IWPM_ExcluirEnturmacoes(ID, SessionID, Periodos, CodTurmas,cbk_GenericCallBack);
 }
 catch(E)
 {
  ShowAguarde(false);
  return alert(AjaxNotFound); 
 }
}


//** Detalhar Pré-Matrícula ************************************************************************************************

function IWPM_DetalharPreMatricula(FormName,MaisDetalhes)
{
 var lstTurmas = document.getElementById("lstTurmas");
 
 FormName = (FormName == null) ? "" : FormName;
 MaisDetalhes = (MaisDetalhes != null) && MaisDetalhes;
 
 if (!lstTurmas)
  return alert(ComponentNotFound);
 

 if (lstTurmas.selectedIndex <= 0)
 {
  SetInnerHtml("divDetalheTurmas","<img src='imagens/branco.gif' width='100%' height='1' />");
  
  if (MaisDetalhes)
  {
   SetInnerHtml("divMaisDetalheTurmas","<img src='imagens/branco.gif' width='100%' height='1' />");
  } 
  return true;
 }
 
 try
 {
  var Str = lstTurmas.value; 
  
  Periodo  = Str.substring(0,7);
  CodTurma = Str.substring(7,13);

  LoadInnerHtml("divDetalheTurmas", "WebPreMatricula/PreMatriculas/Detalhes.aspx?FormName=" + FormName + "&DetalheTurma=SIM&CodTurma=" + CodTurma + "&Periodo=" + Periodo + "&MaisDetalhes=" + ((MaisDetalhes) ? "SIM" : "NÃO").toString() );
  
  if (MaisDetalhes)
  {
   LoadInnerHtml("divMaisDetalheTurmas", "WebPreMatricula/PreMatriculas/ShowMaisDetalhes.aspx?CodTurma=" + CodTurma + "&Periodo=" + Periodo);
  } 
  
 }
 catch(E)
 {
  return alert("Falha ao carregar o detalhe da turma!"); 
 }
}

//** Visualizar Mais Detalhes da Pré-Matrícula ********************************************************************************************

function IWPM_VerMaisDetalhes(FormName, CodTurma, Periodo)
{
 FormName = (FormName == null) ? "" : FormName;
 CodTurma = (CodTurma == null) ? 0  : CodTurma;
 Periodo  = (Periodo  == null) ? "" : Periodo;
 
 FormClose(FormName);
 LoadInnerHtml("divIWPreMatricula", "WebPreMatricula/PreMatriculas/MaisDetalhes.aspx?FormName=" + FormName + "&CodTurma=" + CodTurma + "&Periodo=" + Periodo);
}

//** Alterar Dia de Vencimento da Pré-Matrícula ****************************************************************************************

function IWPM_AlterarPreMatricula(FormName, Matricula, CPFDependente, CodPreMatricula, CodTurma, Periodo)
{
 var edtDiaVencimento = document.getElementById("edtDiaVencimento");
 
 if (!FormName || !Matricula || !CPFDependente || !CodPreMatricula || !CodTurma || !Periodo || !edtDiaVencimento)
  return alert(ComponentNotFound);
 
 var DiaVencimento = edtDiaVencimento.selectedIndex+1;
 
 try
 {
  ShowAguarde(true);  
  JRAjax.IWPM_AlterarPreMatricula(ID, SessionID, FormName, Matricula, CPFDependente, CodPreMatricula, Periodo, CodTurma, DiaVencimento, cbk_GenericCallBack);
 }
 catch(E)
 {
  ShowAguarde(false);
  return alert(AjaxNotFound); 
 }
}

//** Auto Connect IntraNet Aluno *******************************************************************************************************

function IWPM_AutoConnectIWAluno()
{
 try
 {
  ShowAguarde(true);  
  JRAjax.IWPM_AutoConnectIWAluno(ID, SessionID, cbk_GenericCallBack);
 }
 catch(E)
 {
  ShowAguarde(false);
  return alert(AjaxNotFound); 
 }
}
