﻿//** DelhiCallBack *************************************************************************************************************

function DelphiCallBack(Value)
{
 self.document.title = Value;
}

//** Verifica se o Editor Esta Aberto ******************************************************************************************

function VerificarEditor(FormName)
{
 var Form = document.getElementById('Form'+FormName);
 
 if (Form != null)
 {
  setTimeout("VerificarEditor('" + FormName + "');",500);
 }
 else
 {
  DelphiCallBack("IWHD_HideSaveButton");
 }

}

//** Ao Sair ********************************************************************************************************************

function IWHD_onClose()
{             
 DelphiCallBack("IWHD_DisableButtons");
 DelphiCallBack("IWHD_HideSaveButton");
 return false;
}

//** Ao Selecionar Usuario em Encaminhar para...

function IWHD_EncaminharSelectUser(Sender,FormName,Url)
{
 var divEditor = document.getElementById('divEditor');
 
 if (!divEditor)
  return false;

 if (Sender.value == '') 
 {
  divEditor.innerHTML = '<img src="imagens/branco.gif" width="100%" height="1" />';
  PositionForm(FormName);
  DelphiCallBack("IWHD_DisableSaveButton");
 }
 else
 {
  if (divEditor.innerHTML.length <= 100)
   LoadInnerHtml('divEditor',Url,FormName,true); 
 }
}

//** Verificar Login *******************************************************************************************************************

function IWHDK_VerificarMatricula()
{
 var edtEmail = document.getElementById('edtEmail');
 
 if (!edtEmail)
  return alert(ComponentNotFound);
  
 ShowAguarde(true);
 try
 {
  JRAjax.IWHDK_VerificarMatricula(ID,SessionID,edtEmail.value,cbk_GenericCallBack);
 }
 catch(E)
 {
  ShowAguarde(false);
  return alert(AjaxNotFound);
 } 
}


//** Verifica Senha *****************************************************************************************************************************

function IWHDK_VerificarSenha(Matricula)
{
 var Senha      = document.getElementById("Senha");
 var SenhaIndex = document.getElementById("SenhaIndex");
 
 if ((Senha == null) || (SenhaIndex == null))
 {
  alert(ComponentNotFound);
  return;
 }

 try
 {
  ShowAguarde(true); 
  JRAjax.IWHDK_VerificarSenha(ID,SessionID,Matricula,Senha.value,parseInt(SenhaIndex.value),cbk_IWHDK_VerificarSenha);
 }
 catch(e)
 {
  ShowAguarde(false); 
  alert(AjaxNotFound);
 } 
}

function cbk_IWHDK_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 Senha do usuário ******************************************************************************************************************

function IWHDK_AlterarSenha(FormName, Matricula)
{
 var SenhaAtual     = document.getElementById("SenhaAtual");
 var NovaSenha      = document.getElementById("NovaSenha");
 var ConfirmarSenha = document.getElementById("ConfirmarSenha");
 
 if (!FormName || !Matricula || !SenhaAtual || !NovaSenha || !ConfirmarSenha)
  return alert(ComponentNotFound);
  
 try
 {
  ShowAguarde(true);
  JRAjax.IWHDK_AlterarSenha(ID, SessionID, FormName, Matricula, SenhaAtual.value, NovaSenha.value, ConfirmarSenha.value, cbk_GenericCallBack);
 }
 catch(e)
 {
  alert(AjaxNotFound);
 }

}


//** Salvar Novo Chamado **************************************************************************************************************

function IWHDK_SalvarNovoChamado()
{
 var lstCategoria      = document.getElementById('lstCategoria');
 var lstDepartamentos  = document.getElementById('lstDepartamentos');
 var lstPrioridade     = document.getElementById('lstPrioridade');
 var edtSolicitante    = document.getElementById('edtSolicitante');
 var edtEMail          = document.getElementById('edtEMail');
 var edtTelefone       = document.getElementById('edtTelefone');
 var edtRamal          = document.getElementById('edtRamal');
 var edtAssunto        = document.getElementById('edtAssunto');
 var edtDadosSigilosos = document.getElementById('edtDadosSigilosos');
 var edtTextoAbertura = document.getElementById('edtTextoAbertura');
 
 if (!lstCategoria || !lstDepartamentos || !lstPrioridade || !edtSolicitante || 
     !edtEMail || !edtTelefone || !edtRamal || !edtAssunto || !edtDadosSigilosos || !edtTextoAbertura)
 {
  return alert(ComponentNotFound);
 }
 
 if (confirm('Deseja abrir um novo chamado?'))
 try
 {
  ShowAguarde(true);
  JRAjax.IWHDK_SalvarNovoChamado(ID, SessionID, lstCategoria.value, lstDepartamentos.value, lstPrioridade.value, edtSolicitante.value,
                                 edtEMail.value, edtTelefone.value, edtRamal.value, edtAssunto.value, edtDadosSigilosos.value, edtTextoAbertura.value, cbk_GenericCallBack);
 }
 catch(E)
 {
  ShowAguarde(false);
  return alert(AjaxNotFound);
 }

} 


//** Adicionar Comentario *************************************************************************************************************

function IWHDK_AdicionarComentario(CodHelpDesk)
{
 var edtComentario = document.getElementById('edtComentario');

 if ((edtComentario == null))
 {
  return alert(ComponentNotFound);
 } 
 
 if (confirm('Deseja adicionar um novo comentári ao chamado nº: ' + Space(CodHelpDesk,'0',10) + '?'))
 try
 {
  ShowAguarde(true);
  JRAjax.IWHDK_AdicionarComentario(ID, SessionID, CodHelpDesk,edtComentario.value, cbk_GenericCallBack);
 }
 catch(E)
 {
  ShowAguarde(false);
  return alert(AjaxNotFound);
 }

} 

//** Fechar Chamado *******************************************************************************************************************

function IWHDK_FecharChamado(CodHelpDesk)
{
 var edtTextoObsFechar = document.getElementById('edtTextoObsFechar');
 var chkAvaliacao5     = document.getElementById('chkAvaliacao5');
 var chkAvaliacao4     = document.getElementById('chkAvaliacao4');
 var chkAvaliacao3     = document.getElementById('chkAvaliacao3');
 var chkAvaliacao2     = document.getElementById('chkAvaliacao2');
 var chkAvaliacao1     = document.getElementById('chkAvaliacao1');
 
 if (!edtTextoObsFechar || !chkAvaliacao5 || !chkAvaliacao4 || !chkAvaliacao3 || !chkAvaliacao2 || !chkAvaliacao1)
 {
  return alert(ComponentNotFound);
 }

 var Avaliacao = (chkAvaliacao5.checked) ? 5 : (chkAvaliacao4.checked) ? 4 : (chkAvaliacao3.checked) ? 3 : (chkAvaliacao2.checked) ? 2 : (chkAvaliacao1.checked) ? 1 : 0;
                                              
 if (confirm('Deseja fechar o chamado nº: ' + Space(CodHelpDesk,'0',10) + '?'))
 try
 {
  ShowAguarde(true);
  JRAjax.IWHDK_FecharChamado(ID, SessionID, CodHelpDesk,edtTextoObsFechar.value, Avaliacao, cbk_GenericCallBack);
 }
 catch(E)
 {
  ShowAguarde(false);
  return alert(AjaxNotFound);
 }

} 

//** Reabrir Chamado ******************************************************************************************************************

function IWHDK_ReAbrirChamado(CodHelpDesk)
{
 var edtTextoReabertura = document.getElementById('edtTextoReabertura');
 
 if (!edtTextoReabertura)
 {
  return alert(ComponentNotFound);
 }
                                             
 if (confirm('Deseja reabrir o chamado nº: ' + Space(CodHelpDesk,'0',10) + '?'))
 try
 {
  ShowAguarde(true);
  JRAjax.IWHDK_ReAbrirChamado(ID, SessionID, CodHelpDesk,edtTextoReabertura.value, cbk_GenericCallBack);
 }
 catch(E)
 {
  ShowAguarde(false);
  return alert(AjaxNotFound);
 }

} 

//** Atualizar Tempo de Login Ativo

function IWHD_RefreshLogin()
{
 try
 {
  JRAjax.IWHD_RefreshLogin(ID,SessionID,cbk_GenericCallBack);
 }
 catch(E)
 {
  return false;
 } 
}

