/* -----------------------------------------------------------------------------
    @AUTHOR:  Zdenek Benak, zdenek.benak@centrum.cz
    @YEAR:    2006
    @PROJECT: MAppEngine
    @FILE:    inc/m_browser.js
    @DESCR:   funkce pro praci s udalostmi mysi, zjistovani delek, ...
 * -------------------------------------------------------------------------- */


// -------------------------------- VAR INIT -----------------------------------

  var IE    = document.all?true:false;
  var NS    = document.layers?true:false;
  var NS6   = document.getElementById&&!document.all?true:false;
  var Opera = navigator.userAgent.indexOf("Opera")>-1;

  var isMinNS4  = (navigator.appName.indexOf("Netscape")>=0&&parseFloat(navigator.appVersion)>=4)?1:0;
  var isMinIE4  = (document.all)?1:0;
  var isMinIE5  = (isMinIE4&&navigator.appVersion.indexOf("5.")>=0)?1:0;
  var isGecko   = (navigator.userAgent.indexOf("Netscape")<0 && navigator.userAgent.indexOf("Gecko")>=0);
  var isMinNS4  = isGecko?false:isMinNS4;
  

// -------------------------- zpracovani stisku klaves -------------------------

    function GetKey(e)
    {
      var code;

      // nastaveni pro IE
      if (!e) var e = window.event;
      // IE a Mozilla
      if (e.keyCode) code = e.keyCode;
      // NN4
      else if (e.which) code = e.which;
      
      return code;
    }
    
    function EnterPressed(e)
    {
      return (GetKey(e)==13);
    }
    
    function NumericPressed(e)
    {
      k = GetKey(e);
      return (k>=48 && k<=57||k==32||k==43||k==45);
    }
    function NumericInputPressed(e)
    {
      k = GetKey(e);
      return ((k>=48 && k<=57)||k<=32||k==43||k==45||(k>=37 && k<=46));
    }
    
    function FloatNumericPressed(e)
    {
      k = GetKey(e);
      if ((k>=48 && k<=57)||k==32||k==43||k==44||k==45||k==46) return true;
      return false;
    }
    
    function FloatNumericInputPressed(e)
    {
      k = GetKey(e);
      if ((k>=48 && k<=57)||k<=32||k==43||k==44||k==45||k==46||(k>=37 && k<=46)) return true;
      return false;
    }
    

// ---------------------------- zjisteni pozice mysi ---------------------------

   function GetMouseX(e)
   {
    if (isMinIE4) return window.event.clientX;
    else          return e.clientX;
   }
   
   function GetMouseY(e)
   {
    if (isMinIE4) return window.event.clientY;
    else          return e.clientY;
   }


// ---------------------------- zjisteni sirky okna ----------------------------

  function GetWindowWidth()
  {
    var w_width = 640;

    if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
      //IE 6+ in 'standards compliant mode'
      w_width = document.documentElement.clientWidth;
    }

    else
    {
      //IE 4 compatible
      if (document.body && (document.body.clientWidth || document.body.clientHeight))
      {
        w_width = document.body.clientWidth;
      }
    }

    // ns4 only
    if (document.layers)
    {
      w_width = window.innerWidth;
    }

    return w_width;
  }
    
// ---------------------------- zjisteni vysky okna ----------------------------

  function GetWindowHeight()
  {
    var w_height = 480;
    
    if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
      //IE 6+ in 'standards compliant mode'
      w_height = document.documentElement.clientHeight;
    }
    else
    {
      //IE 4 compatible
      if (document.body && ( document.body.clientWidth || document.body.clientHeight))
      {
        w_height = document.body.clientHeight;
      }
    }

    // ns4 only
    if (document.layers)
    {
      w_height = window.innerHeight;
    }

    return w_height;
  }
  
    
// ----------------------------- zjisteni scroll X -----------------------------

  function GetPageOffsetX()
  {
    if(isMinIE4)
    {
      if (document.documentElement && document.documentElement.scrollLeft) return(document.documentElement.scrollLeft);
      else                                                                 return(document.body.scrollLeft);
    }
    else  return(window.pageXOffset);
  }

// ----------------------------- zjisteni scroll Y -----------------------------

  function GetPageOffsetY()
  {
    if(isMinIE4)
    {
      if (document.documentElement && document.documentElement.scrollTop) return(document.documentElement.scrollTop);
      else                                                                return(document.body.scrollTop);
    }
    else return(window.pageYOffset);
  }

// ------------------------------- GetPageWidth --------------------------------

  function GetPageWidth()
  {
    if(isMinNS4)return document.width;
    if(isMinIE4)return document.body.scrollWidth;
    if(isGecko )return document.body.scrollWidth;
    return-1;
  }

// ------------------------------- GetPageHeight -------------------------------

  function GetPageHeight()
  {
    if(isMinNS4)return document.height;
    if(isMinIE4)return document.body.scrollHeight;
    if(isGecko )return document.body.scrollHeight;
    return-1;
  }

// ------------------------------ GetElementWidth ------------------------------

  function GetElementWidth(layer)
  {
    if(isMinNS4){if(layer.document.width)   return layer.document.width;else    return layer.clip.right-layer.clip.left;}
    if(isMinIE4){if(layer.style.pixelWidth  )return layer.style.pixelWidth;else return layer.clientWidth;}
    if(isGecko) {if(layer.style.pixelWidth) return layer.style.pixelWidth;else  return layer.clientWidth;}
    return-1;
  }
  
// ----------------------------- GetElementHeight ------------------------------

  function GetElementHeight(layer)
  {
    if(isMinNS4){if(layer.document.height)   return layer.document.height;else   return layer.clip.bottom-layer.clip.top;}
    if(isMinIE4){if(layer.style.pixelHeight) return layer.style.pixelHeight;else return layer.clientHeight;}
    if(isGecko) {if(layer.style.pixelHeight) return layer.style.pixelHeight;else return layer.clientHeight;}
    return-1;
  }
  
// ------------------------------- GetElementLeft ------------------------------

  function GetElementLeft(layer)
  {
    if(isMinNS4) return layer.left;
    if(isMinIE4) return layer.style.pixelLeft;
    if(isGecko)  return parseInt(layer.style.left);
    return-1;
  }

// ------------------------------- GetElementTop -------------------------------
  function GetElementTop(layer)
  {
    if(isMinNS4) return layer.top;
    if(isMinIE4) return layer.style.pixelTop;
    if(isGecko)  return parseInt(layer.style.top);
    return-1;
  }

// ------------------------------ GetElementRight ------------------------------

  function GetElementRight(layer)
  {
    if(isMinNS4) return getLeft(layer) + getWidth(layer);
    if(isMinIE4) return getLeft(layer) + getWidth(layer);
    if(isGecko)  return getLeft(layer) + getWidth(layer);
    return-1;
  }
  
// ------------------------------ GetElementBottom ------------------------------

  function GetElementBottom(layer)
  {
    if(isMinNS4) return layer.top            + getHeight(layer);
    if(isMinIE4) return layer.style.pixelTop + getHeight(layer);
    if(isGecko)  return layer.style.pixelTop + getHeight(layer);
    return-1;
  }
