﻿//** Verifica Matricula *************************************************************************************************************************
function IDN_VerificarMatricula(strMatricula,strGrupos)
{
 var edtMatricula = document.getElementById(strMatricula);
 var lstGrupos  = document.getElementById(strGrupos);
  
 if (!edtMatricula || !lstGrupos) 
 {
  alert(ComponentNotFound);
  return ;
 }                      
  
 try
 {
  edtMatricula.onblur();
  
  ShowAguarde(true);
  JRAjax.IDN_VerificarMatricula(ID,SessionID,edtMatricula.value,lstGrupos.value,strMatricula,strGrupos,cbk_IDN_VerificarMatricula);
 }
 catch(e)
 {
  ShowAguarde(false);
  alert(AjaxNotFound);
 } 
}

function cbk_IDN_VerificarMatricula(Request)
{
 try
 {
 
  if (!Request.value[0])
  {
   alert(Request.value[1]);
   
   var Comp = document.getElementById(Request.value[2]);
   
   if (Comp != null)
   {
    Comp.focus();
    Comp.select();
    Comp.style.backgroundColor = 'red';
   }
   return ;
  }
  
  if (Request.value[4])
  {
   ShowForm('Cadastrar Nova Senha!',Request.value[3]);
   return ;
  }
  else
  {
   //Redireciona a pagina
   LoadInnerHtml('tdHome',Request.value[3]);
  } 
 }
 finally
 {
  ShowAguarde(false);
 } 
}

//** Cadastrar Senha ***************************************************************************************************************************

function IDN_CadastrarSenha(Matricula,CodGrupo,FormName)
{
 try
 {
  var StrImg            = "<img src=\"imagens/branco.gif\" style=\"width:100%;height:1px\">";
  var edtCPF            = document.getElementById('CPF');
  var edtChave          = document.getElementById('Chave');
  var edtEMail          = document.getElementById('EMail');
  var edtSenha          = document.getElementById('Senha');
  var edtConfirmarSenha = document.getElementById('ConfirmarSenha');

  SetInnerHtml('lbCPF',StrImg);          
  SetInnerHtml('lbChave',StrImg);          
  SetInnerHtml('lbEMail',StrImg);          
  SetInnerHtml('lbSenha',StrImg);          
  SetInnerHtml('lbConfirmarSenha',StrImg);          

  if (
      (edtCPF            == null) ||
      (edtChave          == null) ||
      (edtEMail          == null) ||
      (edtSenha          == null) ||
      (edtConfirmarSenha == null)
     ) 
  {
   alert(ComponentNotFound);
   return;
  }   
  
  ShowAguarde(true);
  JRAjax.IDN_CadastrarSenha(ID,SessionID,Matricula,CodGrupo,edtCPF.value,edtChave.value,
                            edtEMail.value,edtSenha.value,edtConfirmarSenha.value, FormName, cbk_IDN_CadastrarSenha);
 }
 catch(e) 
 {
  ShowAguarde(false);
  alert(AjaxNotFound);
 }
}

function cbk_IDN_CadastrarSenha(Request)
{
 try
 {
  if (!Request.value[0])
  {
   var Ctrl = document.getElementById(Request.value[2]);
   
   if (Ctrl != null)
   {
    Ctrl.focus();
    SetInnerHtml('lb'+Request.value[2],Request.value[1]);
   }
   else
   {
    alert(Request.value[1]);
   }
   return false; 
  }
  
  var Func = new Function(Request.value[3]);
  Func();
 }
 catch(E)
 {
  alert(ComponentNotFound);
 }
 finally
 { 
  ShowAguarde(false);
 }
}

//** Verifica Senha *****************************************************************************************************************************

function IDN_VerificarSenha(Matricula,CodGrupo)
{
 var Senha      = document.getElementById("Senha");
 var SenhaIndex = document.getElementById("SenhaIndex");
 
 if ((Senha == null) || (SenhaIndex == null))
 {
  alert(ComponentNotFound);
  return;
 }

 try
 {
  ShowAguarde(true); 
  JRAjax.IDN_VerificarSenha(ID,SessionID,Matricula,CodGrupo,Senha.value,parseInt(SenhaIndex.value),cbk_IDN_VerificarSenha);
 }
 catch(e)
 {
  ShowAguarde(false); 
  alert(AjaxNotFound);
 } 
}

function cbk_IDN_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); 
 }
}

function IDN_AlterarSenha(FormName, Matricula, CodGrupo)
{
 var SenhaAtual     = document.getElementById("SenhaAtual");
 var NovaSenha      = document.getElementById("NovaSenha");
 var ConfirmarSenha = document.getElementById("ConfirmarSenha");
 
 if (!FormName || !Matricula || !CodGrupo || !SenhaAtual || !NovaSenha || !ConfirmarSenha)
  return alert(ComponentNotFound);
  
 try
 {
  JRAjax.IDN_AlterarSenha(ID, SessionID, FormName, Matricula, CodGrupo, SenhaAtual.value, NovaSenha.value, ConfirmarSenha.value, cbk_IDN_AlterarSenha);
 }
 catch(e)
 {
  alert(AjaxNotFound);
 }
 
}

function cbk_IDN_AlterarSenha(Request)
{
 if (!Request.value[0])
 {
  var Control = document.getElementById(Request.value[2]);
  
  alert(Request.value[1]);
  
  if (Control != null)
  {
   Control.focus();
   Control.style.backgroundColor = 'red';
  }
  return false;
 }
 
 try
 {
  new Function(Request.value[3])();
 }
 catch(e)
 {
  return alert('Falha ao alterar a senha!');
 }
}

//** Anexar Foto / Logow ******************************************************************************************************************

function IDN_AlterarFoto()
{
 var frmUpLoad = document.getElementById("frmUpLoad");
 
 if ((frmUpLoad == null) || (frmUpLoad.contentWindow == null))
  return;
 
 frmUpLoad.contentWindow.UpLoadFoto(); 
}



