﻿ //*************************************************
 //* Variáveis e Constantes                        *
 //*************************************************

 var trmScrollGallery = null;
 var ScrollGalleryPosX = -1;
 var ScrollGalleryPosY = -1;

 var tmrOutGallery  = new Array(50);
 var tmrOverGallery = new Array(50);

 var tmrOutNoticias  = null;
 var tmrOverNoticias = false;

 var btnAguarde   = null;
 var StopNoticias = false;
 var trmNoticias  = null;

 //*************************************************
 //* Funcçoes                                      *
 //*************************************************
 function GetPageSession(Url)
 {
  if ((Url == null) || (Url.length == 0))
   return "";

  if (Url.toLowerCase().indexOf("?".toLowerCase()) < 0)
  {
   Url += "?ID=" + self.ID + "&SessionID=" + SessionID + "&Matricula="+ self.Matricula;
   return Url;
  }
         
  if (Url.toLowerCase().indexOf("&id=".toLowerCase())+Url.toLowerCase().indexOf("?id=".toLowerCase()) == -2)
  {
   Url += "&ID="+ID;
  }
  
  if (Url.toLowerCase().indexOf("&sessionid=".toLowerCase())+Url.toLowerCase().indexOf("?sessionid=".toLowerCase()) == -2)
  {
   Url += "&SessionID="+SessionID;
  }
  
  if (Url.toLowerCase().indexOf("&matricula=".toLowerCase()) + Url.toLowerCase().indexOf("?matricula=".toLowerCase()) == -2)
  {
   Url += "&Matricula="+Matricula;
  }

  return Url;
 } 

 //*************************************************
 //* Funções                                       *
 //*************************************************
 function PageBeforeReload(Sender)
 {
  try
  {

  }
  catch (e)
  {
   //faz nada
  }

  return true;
 }
 
 function PageAffterReload(Sender)
 {
  //*************************************************
  //* ASPX Events                                   *
  //*************************************************
  try
  {
   if (Sender.contentWindow.document.getElementById("AjaxKeyBorad") != null)
   {
    IW_LoadDigitalKeyBord();
   }
  }
  catch(e)
  {
   //
  }
  
  //*************************************************
  //* Eventos                                       *
  //*************************************************
  try
  {
   for (i = 0; i < ExpandIndex;i++)
   {
    Expand(Expand_Image[ExpandIndex],Expand_Block[ExpandIndex],Expand_Inner[ExpandIndex]);
   }
   ExpandIndex = 0;
  }
  catch (e)
  {  
   //faz nada
  }

  try
  {
   var formLogin = document.getElementById("formLogin");
   
   if ((formLogin != null) && (formLogin.Auto != null))
   {
    formLogin.Auto.value = 'SIM';
    formLogin.submit();
   } 
  }
  catch (e)
  {  
   //faz nada
  }
  return true;
 }
 

 function IntrawebAlterar(StrImg,Src)
 {
  var img = document.getElementById(StrImg);
  
  if(img == null)
  return;
  
   img.src = Src;
 }

 function SetClick(ButtonName)
 {
  __doPostBack(ButtonName, '');
 }

 function ActiveSeta(Sender,MouseOver)
 {    
  if (Sender.children[0].tagName.toUpperCase() == "IMG")
  {
   Imagem = Sender.children[0];
   
   if (Imagem)
   {
    if (MouseOver)
    {
     Imagem.src = "Imagens/SetaOver.gif"
    }
    else 
    {
     Imagem.src = "Imagens/SetaOut.GIF"
    }
   } 
  }
 }

function SelectBorder(Sender, Selected)
{
 if (Sender == null)
  return false;

 if (Selected)
 {
  Sender.style.backgroundImage = "url(Imagens/Selected.png)";
  Sender.style.border          = "1px solid rgb(153, 216, 242)";
  Sender.style.backgroundRepeat = "repeat";
 }
 else
 {
  Sender.style.backgroundRepeat = "no-repeat";
  Sender.style.backgroundImage  = "url(Imagens/branco.gif)";
  Sender.style.border           = "1px solid rgb(255, 255, 255)";
 }
 
}

//***********************************************************************************************************************************************************



function PrismaAction()
{
 formPesquisa = document.forms["formPesquisa"];
 
 if (formPesquisa != null)
 {
  formPesquisa.Busca[0].checked = true;
  formPesquisa.action = "busca.aspx";
  formPesquisa.target = "frmHome";
 }
}

function GoogleAction()
{
 formPesquisa = document.forms["formPesquisa"];
 
 if (formPesquisa != null)
 {
  formPesquisa.Busca[1].checked = true;
  formPesquisa.action = "http://www.google.com.br/search";
  formPesquisa.target = "Google";
 }
 
}

var RecadoModified   = false;
var RecadoProcessing = false;

function ChageRecado(Sender)
{
 if (!RecadoProcessing)
 {
  RecadoModified = true;
 } 
}

function EnterRecados(Sender, Focused)
{
 RecadoProcessing = true;
 try
 {
  if (Focused && (!RecadoModified))
  {
   Sender.value = "";
   Sender.style.color = "black";
  }
  else
  if ((!Focused) && (!RecadoModified))
  {
   Sender.value = Sender.defaultValue; //"* Seu recado estará sujeito a aprovação.";
   Sender.style.color = "silver";
  }
 }
 finally
 {
  RecadoProcessing = false;
 }
}

function ReloadRecados()
{
 var tblRecados = self.document.getElementById("tblRecados");
 
 if (tblRecados != null)
 try
 {
  var iptRecados = self.document.getElementById("iptRecados");
  
  if ((iptRecados != null) && (iptRecados.value != ''))
  {
   tblRecados.innerHTML    = iptRecados.value;
   iptRecados.value        = '';
   RecadoModified   = false;
   RecadoProcessing = false;
   
   var Recado = self.document.getElementById("Recado");
   Recado.style.color = 'silver';
  }
 }
 catch(e)
 {
  alert('Erro ao carregar componente de Recados!');
 }
}

 function AjaxOpenNoticias(Index)
 {
  try
  {
   var divNoticia = document.getElementById('divNoticia');
   
   tmrOutNoticias = null;
   
   if (divNoticia != null)
   {
    JRAjax.ActionGetNoticia(Index, AjaxOpenNoticias_CallBack);      
   }      
  }
  catch(e)
  {
  }
 }
 
 function AjaxOpenNoticias_CallBack(Response)
 {
  var divNoticia = document.getElementById('divNoticia');
  
  if ((!Response.value[0]) || (divNoticia == null))
  {
   return;
  }
  
  try
  {
   if (!tmrOverNoticias)
   {
    var NHeight = parseInt(divNoticia.offsetHeight);
    
    divNoticia.innerHTML = Response.value[3];
    
    if (NHeight > parseInt(divNoticia.offsetHeight))
     divNoticia.style.height = NHeight.toString() + 'px';
   } 
  }
  catch(e)
  {
   alert('Erro');
  }
 }

 function ClearTrmOutGallery(Index)
 {
  for (Index = 0; Index < tmrOutGallery.length; Index++)
  try
  {
   if (tmrOutGallery[Index] != null)
   {
    clearTimeout(tmrOutGallery[Index]);
   }
   tmrOutGallery[Index]  = null;
   tmrOverGallery[Index] = false;
  }
  catch(e)
  {
  }
 }

 function ClearTrmOutNoticias()
 {
  try
  {
   if (tmrOutNoticias != null)
   {
    clearTimeout(tmrOutNoticias);
   }
  }
  catch(e)
  {
  }
  
  tmrOutNoticias  = null;
  tmrOverNoticias = false;
 }
 
 
 function StartGalleryTimeout(StrImgCapa, Index, CodGaleria, Ordem)
 {
  var StrCode = "LoadNextCapa('" + StrImgCapa + "'," + Index + "," + CodGaleria + "," + Ordem + ")";
  try
  {
   tmrOutGallery[Index] = setTimeout(StrCode,10000); 
  }
  catch(e) 
  {
  }
 }
 
 function StartNoticiaTimeout(Index)
 {
  var StrCode = "AjaxOpenNoticias(" + Index.toString() + ")";
  try
  {
   tmrOutNoticias = setTimeout(StrCode,20000); 
  }
  catch(e) 
  {
  }
 }
 
 ClearTrmOutGallery();
 ClearTrmOutNoticias();
 
 
 function GetHtmlEditor(IDEditor)
 {
  return $find(IDEditor);
 }
 
function envia(ImgFile, CodGaleria)
{
 try
 {
  JRAjax.AddAcessoGaleria(CodGaleria);
 }
 catch(e)
 {
  //faznada
 }
	document.superswf.SetVariable('gallery',ImgFile);
	document.superswf.SetVariable('vai',true);
	document.superswf.SetVariable('vai',true);
}

 function IntrawebAlterar(StrImg,Src)
 {
  var img = document.getElementById(StrImg);
  
  if(img == null)
  return;
  
   img.src=Src;
 }
 
 function Link_Mouse(StrLE,StrLC,StrLD,Cor)
 {
  var LE = document.getElementById(StrLE);
  var LC = document.getElementById(StrLC);
  var LD = document.getElementById(StrLD);
  
  if((LE != null) && (LC != null) && (LD != null))
  {
   LE.bgColor= Cor ;
   LC.bgColor= Cor ;
   LD.bgColor= Cor ;
  }
 }

function flash(Div, X)
{

 Bloco = document.getElementById(Div);
 
 if (!Bloco)
 {
  return;
 }
 
 if(X==true)
 {
 Bloco.style.visibility="visible";
 }
 else if(X==false)
 {
 Bloco.style.visibility="hidden";
 }

}

function PositionGallery(strStaticButtons)
{
 var StaticButtons = self.document.getElementById(strStaticButtons);

 if (StaticButtons == null)
 {
  FreeScrollGallery();
  return;
 }

 var dsocleft = ScrollX();
 var dsoctop  = ScrollY();
 
 if (
     (ScrollGalleryPosX >= 0) && 
     (ScrollGalleryPosY >= 0) &&
     (
      (ScrollGalleryPosX != dsocleft) ||
      (ScrollGalleryPosY != dsoctop)
     ) 
    )
 {
  self.window.scrollTo(ScrollGalleryPosX,ScrollGalleryPosY);
 }   

}
   
function altera_flash(strStaticButtons,Visible)
{
 var ieHoffset_extra = 15;
 var Hoffset         = 800; // largura
 var Voffset         = 10; //altura

 var StaticButtons = document.getElementById(strStaticButtons);
 var Filtro        = document.getElementById("Filtro");
 var frmPrincipal  = document.getElementById("tblPrincipal");
 var dsocleft = ScrollX();
 var dsoctop  = ScrollY();
 
 if ((Filtro != null) && (StaticButtons != null))
 {
  var window_width    = frmPrincipal.offsetWidth;
  var window_height   = frmPrincipal.offsetHeight;
  
  if (document.body.clientWidth > window_width)
   window_width = document.body.clientWidth;
  if (document.body.clientHeight > window_height)
   window_height = document.body.clientHeight;
  
  Filtro.style.visibility        = Visible;
  StaticButtons.style.visibility = Visible;
  
  if (Visible.toLowerCase() == 'visible')
  {
   Filtro.style.left   = 0+'px';
   Filtro.style.top    = 0+'px';
   Filtro.style.width  = window_width+'px';
   Filtro.style.height = window_height+'px';

   SetScrollGallery(strStaticButtons);

   var window_width         = document.body.clientWidth + ieHoffset_extra;
   var window_height        = document.body.clientHeight;
   StaticButtons.style.left = dsocleft+ parseInt(window_width  / 2) - (StaticButtons.offsetWidth  / 2);
   StaticButtons.style.top  = dsoctop + parseInt(window_height / 2) - (StaticButtons.offsetHeight / 2);

   ScrollGalleryPosX = ScrollX();
   ScrollGalleryPosY = ScrollY();
   
  }
  else
  {
   FreeScrollGallery();
   Filtro.style.left   = '0px';
   Filtro.style.top    = '0px';
   Filtro.style.width  = '1px';
   Filtro.style.height = '1px';
   
   StaticButtons.style.left = 0;
   StaticButtons.style.top  = 0;
  } 

 } 
 else
 {
  FreeScrollGallery();
  return;
 }
}

function SetScrollGallery(strStaticButtons)
{
 trmScrollGallery = setInterval("PositionGallery('" + strStaticButtons + "')",20);
}

function FreeScrollGallery()
{
 if (trmScrollGallery != null)
 {
  ScrollGalleryPosX = -1;
  ScrollGalleryPosY = -1;
  clearInterval(trmScrollGallery);
  trmScrollGallery = null;
 } 
}
 
 
function SetSenha(Index)
{
 var S         = "";
 var lbSenha   = document.getElementById("lbSenha");
 var Senha = document.getElementById("Senha");

 if ((Senha == null) || (lbSenha == null))
  return;
  
 try
 {
  if (Index == "-")
  {
   S = Senha.value
   i = S.length-1

   if (i >= 0)
   {
    Senha.value = S.substring(0,i);
   }
  }
  else
  if (Senha.value.length < 06)
  {
   Senha.value = Senha.value + Index.toString();
  }

  S  = Senha.value + ""
  S2 = ""
  for (i = 1 ;i <= S.length;i++)
  {
   S2 = S2 + '*'
  }
  
  var lbSenha = document.getElementById("lbSenha");
  
  if (lbSenha != null)
  {
   lbSenha.innerHTML = (S2 == "") ? "&nbsp;" : S2;
   lbSenha.style.color = "navy"
  }
 }
 catch (e)
 {
  //faz nada
 } 
}


 //Ajax Scripts
 function SalvarRecado(CodRecado, strDe, strPara, strRecado, strResposta, strRespostaDe)
 {
  ShowAguarde(true);
  try
  {
   var edtDe         = document.getElementById(strDe);
   var edtPara       = document.getElementById(strPara);
   var edtRecado     = document.getElementById(strRecado);
   var edtResposta   = document.getElementById(strResposta);
   var edtRespostaDe = document.getElementById(strRespostaDe);
   
   if ((edtDe == null) || (edtPara == null) || (edtRecado == null) || (edtResposta == null) || (edtRespostaDe == null))  
   {
    alert(ComponentNotFound);
    return ;
   }  
  
   JRAjax.ActonSalvarRecado(CodRecado,edtDe.value,edtPara.value,edtRecado.value,edtResposta.value,edtRespostaDe.value,SalvarRecado_CallBack);
  }
  catch(e)
  {
   return alert(AjaxNotFound);
  }
 }

 function SalvarRecado_CallBack(Response)
 {
  ShowAguarde(false);
  
  if (!Response.value[0])
  {
   alert(Response.value[1]);
   return ;
  }
  
  try
  {
   var tdDe     = document.getElementById("fntDe" + Response.value[2]);
   var tdRecado = document.getElementById("fntRecado" + Response.value[2]);
   
   if ((tdDe != null) && (tdRecado != null))
   {
    tdDe.innerHTML = "&nbsp;"+Response.value[4];
    tdRecado.innerHTML = "&nbsp;"+Response.value[6];
    alert(Response.value[1]);
   }
   
  }
  catch(e) 
  {
  
  }
 }
 
 
 function ExcluirRecado(trName,trEditorName,CodRecado, De, Recado)
 {
  if (confirm("Deseja excluir o recado?\n\nDe: " + De + "\n" + Recado))
  try
  {
   JRAjax.ActonExcluirRecado(trName,trEditorName,CodRecado,ExcluirRecado_CallBack);
  }
  catch(e)
  {
   alert('Falha ao tentar excluir o registro!');
  }
 }

 function ExcluirRecado_CallBack(Response)
 {
  if (!Response.value[2])
  {
   alert('Falha ao excluir o registro!');
   return ;
  }
  
  try
  {
   var trName = Response.value[0];
   var Node = document.getElementById(trName);
   Node.innerHTML = "";
   Node.parentNode.removeChild(Node);

   var trName = Response.value[3];
   var Node = document.getElementById(trName);
   Node.innerHTML = "";
   Node.parentNode.removeChild(Node);
  }
  catch(e) 
  {
  
  }
 }

 function LiberarRecado(imgName,CodRecado)
 {
  try
  {
   JRAjax.ActonLiberarRecado(imgName,CodRecado,LiberarRecado_CallBack);
  }
  catch(e)
  {
   alert('Falha ao tentar Liberar/Bloquear o recado!');
  }
 }

 function LiberarRecado_CallBack(Response)
 {
  if (!Response.value[2])
  {
   alert('Falha ao Liberar/Bloquear o recado!');
   return ;
  }
  
  var imgName = Response.value[0];
  var Node = document.getElementById(imgName);
  Node.src = "Imagens/" + Response.value[3];
 }
 
 
 function MostrarRecado(trName,CodRecado,Cancel)
 {
  try
  {
   var Editor = document.getElementById(trName);
   
   if (Editor != null)
   {
    Cancel = (Cancel == null) ? (Editor.innerHTML.length > 100) : Cancel;
    JRAjax.ActonMostrarRecado(trName,CodRecado,Cancel,MostrarRecado_CallBack);
   }
   else
   {
    alert('Falha na visualização!\nComponente de Edição não foi carregado!');
   }
  }
  catch(e)
  {
   alert('Falha ao tentar editar o recado!');
  }
 }

 function MostrarRecado_CallBack(Response)
 {
   
  if (!Response.value[2])
  {
   alert('Falha ao editar o recado!');
   return ;
  }
  
  var imgName = Response.value[0];
  var Node = self.document.getElementById(imgName);
 
  if (Node != null)
  {
   Node.innerHTML = Response.value[3];
  }
  else
  {
   alert('Falha ao editar o recado!');
   return ;
  }
 }
