﻿ var LoginNeed     = "É necessário que efetue login no sistema!";

 var AguardeTimerOut = null;
 var trmScrollForm   = null;
 var ScrollFormPosX  = -1;
 var ScrollFormPosY  = -1;

 var btnAguarde      = null;
 var ExpandIndex     = 0;
 var Expand_Image    = new Array();
 var Expand_Block    = new Array();
 var Expand_Inner    = new Array();
 
 var FormMouseClick  = false;
 var FormMouseX      = 0;
 var FormMouseY      = 0;
 var InicialLeft     = 0;
 var InicialTop      = 0;
 var FormCount       = 0;
 var Forms           = new Array();
 var BallonCount     = 0;
 var Ballons         = new Array();
 var BallonInProcess = false;
 var trmBallon       = null;
 
 var TmpLoadNames    = new Array();
 var TmpLoadBgImg    = new Array();
 var TmpLoadBgPos    = new Array();
 var TmpLoadBgRep    = new Array();
 var TmpLoadInner    = new Array();
 var TmpLoadFormN    = new Array();
 var TmpLoadAutoA    = new Array();
 var TmpLoadUrlik    = new Array();
 var BookMarksForm   = "";
 var BackHomeUrl     = new Array();
 var BackUrl         = new Array();
 var trmHelpDesk     = null;
  
//** Page Loaded *****************************************************************************************************************
 
 function ShowAguarde(isVisible)
 {
  var btnAguarde = document.getElementById("btnAguarde");

  if (btnAguarde != null)
  {
   var W = window.document.body.clientWidth;
   var H = window.document.body.clientHeight;
   var L = ScrollX() + parseInt((W / 2) - (btnAguarde.offsetWidth / 2));
   var T = ScrollY() + parseInt((H / 2) - (btnAguarde.offsetHeight / 2));
   
   if (isVisible)
   {
    btnAguarde.style.left = L+'px';
    btnAguarde.style.top  = T+'px';
    btnAguarde.style.visibility = "visible";

    if (AguardeTimerOut)
     clearTimeout(AguardeTimerOut);

    AguardeTimerOut = setTimeout("ShowAguarde(false);", 10000); 
   } 
   else 
   {
    btnAguarde.style.visibility = "hidden";
    
    if (AguardeTimerOut)
     clearTimeout(AguardeTimerOut);
   } 
  }
 }

//** Impedir Seleção de Textos ***************************************************************************************************
 function disableselect(e)
 {
  return false;
  if (isIE)
   Sender = event.srcElement
  else
  if (e)
   Sender = e.target;
   
  if (Sender != null)
  try
  {
   if (
       (Sender.tagName.toUpperCase() == "INPUT") ||
       (Sender.tagName.toUpperCase() == "SELECT") ||
       (Sender.tagName.toUpperCase() == "RADIO") ||
       (Sender.tagName.toUpperCase() == "TEXTAREA")
      ) 
   {
    return true;
   }
   
   return false;
  }
  catch(e) 
  {
  // alert('Erro Select: '+e.Messagem);
   return false;
  }
 }

 function DisableSelectMode()
 {
  return true;
  try
  {
   document.onselectstart = disableselect
   
   if (window.sidebar)
   {
    document.onmousedown = disableselect;
    document.onclick = new Function("return true;");
   }
  }
  catch(e) 
  {
   alert('Erro Select: '+e.Messagem);
  }
 }
 
 DisableSelectMode();

//** Funções Diversas ************************************************************************************************************

 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 Expand(strSender,strBlock,strInnerBlock,imgExpand,imgColapse)
 {
  if (imgExpand == null)
  {
   imgExpand = "imagens/Expand.gif";
  }
  if (imgColapse == null)
  {
   imgColapse = "imagens/Colapse.gif";
  }

  if ((strInnerBlock == null) || (strInnerBlock == ""))
   return;

  var Sender     = document.getElementById(strSender);
  var Block      = document.getElementById(strBlock);
  var InnerBlock = document.getElementById(strInnerBlock);
  var Espandir   = (Sender.src.toLowerCase().indexOf(imgExpand.toLowerCase()) >= 0);

  if ((Espandir) && (Sender != null) && (Block != null) && (InnerBlock != null))
  {
   var HTML = InnerBlock.value;
           
   while (HTML.indexOf("[",0) >= 0)
    HTML = HTML.replace('[', '<');
   while (HTML.indexOf("]",0) >= 0)
    HTML = HTML.replace(']', '>');
   while (HTML.indexOf("´´",0) >= 0)
    HTML = HTML.replace('´´', '"');
   while (HTML.indexOf("`",0) >= 0)
    HTML = HTML.replace("`", "'");

   while (HTML.indexOf("#13",0) >= 0)
    HTML = HTML.replace("#13", "\n");
   while (HTML.indexOf("#10",0) >= 0)
    HTML = HTML.replace("#10", "\r");

   Block.innerHTML = HTML;
   Sender.src = imgColapse;
  }
  else
  if ((!Espandir) && (Sender != null) && (Block != null) && (InnerBlock != null))
  {
   Block.innerHTML = "<img src='Imagens/Branco.gif' width='100%' height='1'>";
   Sender.src = imgExpand;
  }
 }
 
 function ActonSubmit()
 {
  ShowAguarde(false);
  return ;  
 }
 
 //** Funções Dinamic Panel *******************************************************************************************************

 function PositionForm(strFormName)
 {
  var Form          = self.document.getElementById("Form"+strFormName);
  var Filtro        = document.getElementById("Filtro"+strFormName);
  var frmPrincipal  = document.getElementById("tblPrincipal") || document.getElementById("tdHome") || document.body;
  var dsocleft      = ScrollX();
  var dsoctop       = ScrollY();

  if ((Form == null))
  {
   FreeScrollForm();
   return;
  }
  
 
  if ((Filtro != null) && (Form != null) && ((ScrollFormPosX != dsocleft) || (ScrollFormPosY != dsoctop)))
  {
   var window_width         = document.body.clientWidth;
   var window_height        = document.body.clientHeight;
   X = dsocleft + parseInt(window_width  / 2) - parseInt(Form.offsetWidth  / 2);
   Y = dsoctop  + parseInt(window_height / 2) - parseInt(Form.offsetHeight / 2);
   
   Form.style.left = (X < dsocleft) ? (dsocleft+3)+'px' : X+'px';
   Form.style.top  = (Y < dsoctop) ? (dsoctop+3)+'px' : Y+'px';
   ScrollFormPosX = dsocleft;
   ScrollFormPosY = dsoctop;
  }
 }
    
 function ShowDinamicForm(strFormName, Width, Height)
 {
  var Hoffset         = 800; // largura
  var Voffset         = 10; //altura

  var Form          = document.getElementById("Form"+strFormName);
  var Filtro        = document.getElementById("Filtro"+strFormName);
  var frmPrincipal  = document.getElementById("tblPrincipal") || document.getElementById("tdHome") || document.body;
  var dsocleft = ScrollX();
  var dsoctop  = ScrollY();
  
  if ((Form != null) && ((Width != null) || (Height != null)))
  {
   Form.style.width  = parseInt(Width == null ? Form.offsetWidth : Width).toString()+'px';
   Form.style.height = parseInt(Height == null ? Form.offsetHeight : Height).toString()+'px';
  }
  
  if ((Filtro != null) && (Form != 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;
   if (document.body.offsetHeight > window_height)
    window_height = document.body.offsetHeight;
    
   window_height+=25; 
   
   Filtro.style.visibility = 'visible';
   Form.style.visibility   = 'visible';
   
   
   try
   {
    Filtro.style.left   = 0+'px';
    Filtro.style.top    = 0+'px';
    Filtro.style.width  = window_width+'px';
    Filtro.style.height = window_height+'px';

    SetScrollForm(strFormName);
   
    var window_width         = document.body.clientWidth;
    var window_height        = document.body.clientHeight;
    X = dsocleft + parseInt(window_width  / 2) - parseInt(Form.offsetWidth  / 2);
    Y = dsoctop  + parseInt(window_height / 2) - parseInt(Form.offsetHeight / 2);
    
    var NewX = parseInt((X < dsocleft) ? (dsocleft+3) : X);
    var NewY = parseInt((Y < dsoctop) ? (dsoctop+3) : Y);
    
    Form.style.left = NewX+'px';
    Form.style.top  = NewY+'px';

    ScrollFormPosX = ScrollX();
    ScrollFormPosY = ScrollY();
   }
   catch(e)
   {
    FreeScrollForm();
    CloseForm(strFormName);
   } 
   
  } 
  else
  {
   FreeScrollForm();
   return;
  }
 }

 function SetScrollForm(strForm)
 {
  trmScrollForm = setInterval("PositionForm('" + strForm + "')",200);
 }

 function FreeScrollForm()
 {
  if (trmScrollForm != null)
  {
   ScrollFormPosX = -1;
   ScrollFormPosY = -1;
   clearInterval(trmScrollForm);
   trmScrollForm = null;
  } 
 }


 function ShowLayer(Url,Text)
 {
  var Layer    = document.getElementById("Layer");
  var fntLayer = document.getElementById("fntLayer");
  
  if ((Layer != null) && (fntLayer != null))
  {
   Layer.src = Url;
   fntLayer.innerHTML = Text;
  }
  
 }

 function SetInnerHtml(strCtrl,HTML)
 {
  var Ctrl = document.getElementById(strCtrl);
  
  if (Ctrl != null)
  {
   Ctrl.innerHTML = HTML;
  }
  
 }
  
 //** Move o Ballon ****************************************************************************************************************
 function AddBallon(strBallonName)
 {
  try
  {
   for (i = 0;i < Ballons.length;i++)
   {
    if ((Ballons[i] == null) || (Ballons[i] == ""))
    {
     Ballons[i] = strBallonName;
     BallonCount++; 
     return;
    }
   }
   
   i = Ballons.length;
   Ballons[i] = strBallonName;
   BallonCount++; 
  }
  catch(e)
  {
   alert('Falha ao carregar o Ballonulário');
  } 
 }
 
 function BallonClose(strBallonName)
 {
  CloseBallon(strBallonName);
 }
 
 function CloseBallon()
 {
  if (trmBallon)
   clearTimeout(trmBallon);
  trmBallon = setTimeout("FreeBallon()",500); 
 }
 
 function FreeBallon()
 {
  for (i = 0; i < Ballons.length;i++)
  {
   var Ballon = document.getElementById(Ballons[i]);
  
   if (Ballon != null)
   {
    Opacity = parseFloat('0'+Ballon.style.opacity);
    Opacity += -0.1;
    
    if (Opacity <= 0)
    {
     Opacity = 0;
    }
    
    if (Opacity > 0)
    {
     Ballon.style.opacity = Opacity.toString();
     Ballon.style.filter  = 'revealTrans(opacity='+parseInt(Opacity*10).toString()+')';
     if (trmBallon)
      clearTimeout(trmBallon);
     trmBallon = setTimeout("FreeBallon()",20);
      
     continue;
    }
    else
    {
     try
     {
      Ballon.getElementsByTagName("td")[0].innerHTML = "";
     }
     catch(e)
     {
      //faz nada
     }
     document.body.removeChild(Ballon);
     Ballons[i] = null;
     BallonCount--;
    }
   }
  }
  if (BallonCount < 0)
   BallonCount = 0;
 }
  
 //** Move o Form ****************************************************************************************************************
 function AddForm(strFormName)
 {
  try
  {
   for (i = 0;i < Forms.length;i++)
   {
    if ((Forms[i] == null) || (Forms[i] == ""))
    {
     Forms[i] = strFormName;
     FormCount++; 
     return;
    }
   }
   
   i = Forms.length;
   Forms[i] = strFormName;
   FormCount++; 
  }
  catch(e)
  {
   alert('Falha ao carregar o formulário');
  } 
 }
 
 function CloseAllForm()
 {
  for (i = 0;i < Forms.length;i++)
  {
   if (Forms[i] != null)
   {
    CloseForm(Forms[i]);
   }
  }
 }
 
 function FormClose(strFormName)
 {
  CloseForm(strFormName);
 }
 
 function CloseForm(strFormName)
 {
  var Form   = document.getElementById('Form'+strFormName);
  var Filtro = document.getElementById('Filtro'+strFormName);
  
  if (Form != null)
  {
   try
   {
    Form.getElementsByTagName("td")[0].innerHTML = "";
   }
   catch(e)
   {
    //faz nada
   }
   document.body.removeChild(Form);
  }
  
  if (Filtro != null)
  {
   document.body.removeChild(Filtro);
  }
  
  for (i = 0; i < Forms.length;i++)
  {
   if (Forms[i] == strFormName)
    Forms[i] = null;
  }
  
  if (FormCount > 0)
   FormCount--; 
 }
 
 function DinamicFormsMouseDown(Sender,strFormName, Event)
 {
  var DinamicForm = document.getElementById('Form'+strFormName);

  if (DinamicForm != null)
  try
  {
   FormMouseX  = Event.clientX;
   FormMouseY  = Event.clientY;
   InicialLeft = DinamicForm.offsetLeft;
   InicialTop  = DinamicForm.offsetTop;
   
   document.getElementById("Filtro"+strFormName).onmousemove = Sender.onmousemove;
   document.getElementById("Filtro"+strFormName).onmouseup   = Sender.onmousemove;
   document.getElementById("Form"+strFormName).onmousemove  = Sender.onmousemove;
   document.getElementById("Form"+strFormName).onmouseup    = Sender.onmousemove;
   
   FormMouseClick = true;
  }
  catch(e) 
  {
   alert('Error: MouseDown');
  }
 }
 
 function DinamicFormsMouseMove(Sender,strFormName, Event)
 {
  var DinamicForm = document.getElementById('Form'+strFormName);
  var X = Event.clientX;
  var Y = Event.clientY;
  
  
  if ((FormMouseClick) && (DinamicForm != null))
  try
  {
   DinamicForm.style.left = parseInt(InicialLeft + X - FormMouseX)+'px';
   DinamicForm.style.top  = parseInt(InicialTop  + Y - FormMouseY)+'px';
  }
  catch(e)
  {
   alert('Error: MouseMove');
  }
 }
 
 function DinamicFormsMouseUp(Sender,strFormName, Event)
 {
  FormMouseClick = false;
  document.getElementById("Filtro"+strFormName).onmousemove = null;
  document.getElementById("Filtro"+strFormName).onmouseup   = null;
  document.getElementById("Form"+strFormName).onmousemove   = null;
  document.getElementById("Form"+strFormName).onmouseup     = null;
 }

 function Button(Sender, Down)
 {
  if (Sender == null)
   return ;

  if (Down)
  {
   Sender.style.backgroundImage = "url(Imagens/Button_Down.jpg)";
  }
  else
  {
   Sender.style.backgroundImage = "url(Imagens/Button_Up.jpg)";
  } 
 }

 function ButtonClick(Sender, Down)
 {
  if (Sender == null)
   return ;
                           
  var Child = document.getElementById(Sender.id + "Inner");
  
  if (!Child)
   return false;

  try
  {
   if (Down)
   {
    Sender.style.borderLeft   = 'solid 1px rgb(000,000,000)';
    Sender.style.borderTop    = 'solid 1px rgb(000,000,000)';
    Sender.style.borderRight  = 'solid 1px rgb(000,000,000)';
    Sender.style.borderBottom = 'solid 1px rgb(000,000,000)';

    Child.style.borderLeft   = 'solid 1px rgb(172,168,153)';
    Child.style.borderTop    = 'solid 1px rgb(172,168,153)';
    Child.style.borderRight  = 'solid 1px rgb(172,168,153)';
    Child.style.borderBottom = 'solid 1px rgb(172,168,153)';
   }
   else
   {
    Sender.style.borderLeft   = 'solid 1px rgb(255,255,255)';
    Sender.style.borderTop    = 'solid 1px rgb(255,255,255)';
    Sender.style.borderRight  = 'solid 1px rgb(113,111,100)';
    Sender.style.borderBottom = 'solid 1px rgb(113,111,100)';

    Child.style.borderLeft   = 'solid 1px rgb(241,239,226)';
    Child.style.borderTop    = 'solid 1px rgb(241,239,226)';
    Child.style.borderRight  = 'solid 1px rgb(172,168,153)';
    Child.style.borderBottom = 'solid 1px rgb(172,168,153)';
   } 
  }
  catch(e)
  {
  }
 }


function AddLoadHtml(StrSender,BgImg,BgPos,BgRep,InnerHtml,FormName,AutoAjuste,Url)
{
 var i     = 0;
 var Index = TmpLoadNames.length;
 
 for (i = 0;i < TmpLoadNames.length; i++)
 {
  if (TmpLoadNames[i] == null)
  {
   Index = i;
   break;
  }
  else
  if (TmpLoadNames[i].toString().toLocaleLowerCase() == StrSender.toString().toLocaleLowerCase())
  {
   return -1;  
  }
 }
 
 TmpLoadNames[Index] = StrSender;
 TmpLoadBgImg[Index] = BgImg;
 TmpLoadBgPos[Index] = BgPos;
 TmpLoadBgRep[Index] = BgRep;
 TmpLoadInner[Index] = InnerHtml;
 TmpLoadFormN[Index] = FormName;
 TmpLoadAutoA[Index] = AutoAjuste;
 TmpLoadUrlik[Index] = Url;
 
 return Index;
}

function GetLoadHtml(Index)
{
 try
 {
  if ((Index >= 0) && (Index < TmpLoadNames.length))
  {
   return {Name:TmpLoadNames[Index].toString(),BgImg:TmpLoadBgImg[Index].toString(),BgPos:TmpLoadBgPos[Index].toString(),BgRep:TmpLoadBgRep[Index].toString(),InnerHtml:TmpLoadInner[Index].toString(),FormName:TmpLoadFormN[Index].toString(),AutoAjuste:TmpLoadAutoA[Index].toString(),Url:TmpLoadUrlik[Index].toString()};
  } 
  else
  {
   return null;
  }
 }
 catch(e)
 {
  return null;
 }
}

function FreeLoadHtml(Index)
{
 if ((Index >= 0) && (Index < TmpLoadNames.length))
 {
  TmpLoadNames[Index] = "";
  TmpLoadBgImg[Index] = "";
  TmpLoadBgPos[Index] = "";
  TmpLoadBgRep[Index] = "";
  TmpLoadInner[Index] = "";
  TmpLoadFormN[Index] = "";
  TmpLoadAutoA[Index] = "";
  TmpLoadUrlik[Index] = "";

  TmpLoadNames[Index] = null;
  TmpLoadBgImg[Index] = null;
  TmpLoadBgPos[Index] = null;
  TmpLoadBgRep[Index] = null;
  TmpLoadInner[Index] = null;
  TmpLoadFormN[Index] = null;
  TmpLoadAutoA[Index] = null;
  TmpLoadUrlik[Index] = null;
  
 } 
 return null;
}

