﻿var bGlobalOnLoadBaseDone = false;

var bGlobalWantedResize = false;
var iGlobalBoxPanelStepHeight = 13;
var iGlobalBoxPanelInitialHeight = 26;
var iGlobalBoxPanelActualHeight = 0;
var iGlobalBoxPanelWantedHeight = 0;
var bGlobalLogoutWanted = false;

String.prototype.lpad = function(padString, length)
{
	var str = this;
    while (str.length < length)
        str = padString + str;
    return str;
}
 
String.prototype.rpad = function(padString, length)
{
	var str = this;
    while (str.length < length)
        str = str + padString;
    return str;
}

String.prototype.removezeros = function()
{
	var str = this;
   var bJeste = false;
   if (str.length > 0)
   {
      if (str.substring(0, 1) == "0")
      {
         bJeste = true;
      }
   }
   while (bJeste)
   {
      str = str.substring(1);

      bJeste = false;
      if (str.length > 0)
      {
         if (str.substring(0, 1) == "0")
         {
            bJeste = true;
         }
      }
   }
   return str;
}

Array.prototype.addItem = function(oToAdd)
{
   if (!this.contains(oToAdd))
   {
      this[this.length] = oToAdd;
   }
}

Array.prototype.removeItem = function(oToRemove)
{
   var j = 0;
   while (j < this.length)
   {
      if (this[j] == oToRemove)
      {
         this.splice(j, 1);
      }
      else
      {
         j++;
      }
   }
}

function NavigatorIsIE60Old()
{
   var sNavigator = navigator.userAgent;
   return (sNavigator.indexOf("MSIE 6.0") != -1);
}

function NavigatorIsIE70Old()
{
   var sNavigator = navigator.userAgent;
   return (sNavigator.indexOf("MSIE 7.0") != -1);
}

function NavigatorIsIEOld()
{
   var sNavigator = navigator.userAgent;
   return (sNavigator.indexOf("MSIE 6.0") != -1 || sNavigator.indexOf("MSIE 7.0") != -1);
}

function onClickPanelHide()
{
   iGlobalBoxPanelWantedHeight = 0;  
}

function onClickPanelShow()
{
   iGlobalBoxPanelWantedHeight = iGlobalBoxPanelInitialHeight;
   var box = Tygrik.System.ByID("Box");
   if (box != null)
   {
      box.style.zIndex = 1000;
   }
}

function onClickLogout()
{
   bGlobalLogoutWanted = true;
   onClickPanelHide();
}

function doLogout()
{
   document.Panel.submit();
}

function onTimer()
{
   doResize();
   setTimeout('onTimer()', 100);
}

function onResize()
{
   var iWindows = Tygrik.Window.qWindows.length;
   for (var iWindow = 0; iWindow < iWindows; iWindow++)
   {
      var oWindowNow = Tygrik.Window.qWindows[iWindow];
      oWindowNow.onResize();
   }  

   bGlobalWantedResize = true;
}

function doResize()
{	
   if (bGlobalWantedResize || 
       iGlobalBoxPanelActualHeight != iGlobalBoxPanelWantedHeight)
   {
      if (iGlobalBoxPanelActualHeight != iGlobalBoxPanelWantedHeight)
      {
         if (iGlobalBoxPanelActualHeight > iGlobalBoxPanelWantedHeight)
         {
            iGlobalBoxPanelActualHeight = iGlobalBoxPanelActualHeight - iGlobalBoxPanelStepHeight;
         }     
         if (iGlobalBoxPanelActualHeight < iGlobalBoxPanelWantedHeight)
         {
            iGlobalBoxPanelActualHeight = iGlobalBoxPanelActualHeight + iGlobalBoxPanelStepHeight;
         }
      }
        
      var box = Tygrik.System.ByID("Box");
      if (box != null)
      {
           var iBoxMainHeight = box.clientHeight;// - iGlobalBoxPanelActualHeight;
           var iBoxMainWidth = box.clientWidth;
           var boxPanel = Tygrik.System.ByID("BoxPanel");
           var boxMain = Tygrik.System.ByID("BoxMain");
           var boxMainArea = Tygrik.System.ByID("BoxMainArea");
/*
           boxPanel.style.height = ((iGlobalBoxPanelActualHeight) + 'px');
           if (!NavigatorIsIEOld() && boxMainArea.clientWidth != 0)
           {
              boxPanel.style.width = ((boxMainArea.clientWidth) + 'px');
           }
*/           //boxMain.style.height = ((iBoxMainHeight) + 'px'); // roztazeni na celou vysku okna

           bGlobalWantedResize = false;
           
           if (iGlobalBoxPanelActualHeight == iGlobalBoxPanelWantedHeight)
           {
               if (iGlobalBoxPanelActualHeight == 0)
               {
                  box.style.zIndex = -1000;
                  if (bGlobalLogoutWanted)
                  {
                     bGlobalLogoutWanted = false;
                     doLogout();
                  }
               }
               else
               {
                  box.style.zIndex = 1000;
               }
           }
               
      }
   }
}

function PanelInitialShowen()
{
   iGlobalBoxPanelActualHeight = iGlobalBoxPanelInitialHeight;
   iGlobalBoxPanelWantedHeight = iGlobalBoxPanelInitialHeight;
}

function PanelInitialHidden()
{
   iGlobalBoxPanelActualHeight = 0;
   iGlobalBoxPanelWantedHeight = 0;
}

function onLoadBase()
{
   if (!bGlobalOnLoadBaseDone)
   {
      onResize();
      window.onresize = onResize;
      setTimeout('onTimer()', 10);
      bGlobalOnLoadBaseDone = true;
   }

      //document.onmousedown = dragHandlerX;
}
/*

   var savedTarget=null;                           // The target layer (effectively vidPane)
   var orgCursor=null;                             // The original mouse style so we can restore it
   var dragOK=false;                               // True if we're allowed to move the element under mouse
   var dragXoffset=0;                              // How much we've moved the element on the horozontal
   var dragYoffset=0;                              // How much we've moved the element on the verticle

   function moveHandler(e){
      if (e == null) { e = window.event } 
      if (e.button<=1 && dragOK){
         savedTarget.style.left=e.clientX-dragXoffset+'px';
         savedTarget.style.top=e.clientY-dragYoffset+'px';
         return false;
      }
   }
 
   function cleanup(e) {
      document.onmousemove=null;
      document.onmouseup=null;
      savedTarget.style.cursor=orgCursor;
      dragOK=false;
   }
 
   function dragHandlerX(e){
      var htype='-moz-grabbing';
      if (e == null) { e = window.event; htype='move';} 
      var target = e.target != null ? e.target : e.srcElement;
      orgCursor=target.style.cursor;
      if (target.className=="ClassDivWindowDefaultTitle") {
//         savedTarget=target;
savedTarget=Tygrik.System.ByID("Window");
         target.style.cursor=htype;
         dragOK=true;
         dragXoffset=e.clientX-parseInt(savedTarget.style.left);
         dragYoffset=e.clientY-parseInt(savedTarget.style.top);
         document.onmousemove=moveHandler;
         document.onmouseup=cleanup;
         return false;
      }
   }
*/

