var ready = false;


addListener(window, 'load', initPage, false);

function addListener(element, type, expression, bubbling)
  {
    bubbling = bubbling || false;
    if(window.addEventListener)      // Standard 
      {
        element.addEventListener(type, expression, bubbling);
        return true;
        }
      else if(window.attachEvent)   // IE
            {
              element.attachEvent('on' + type, expression);
              return true;
              }
            else return false;
    }



function initPage()
  {
    ready = true;
    if (typeof alert_message == 'string' ) { if (alert_message != '' ) { window.alert(alert_message); alert_message = ''; }}
    if (document.getElementById('login_id')) document.getElementById('login_id').focus();
    
    if (document.getElementById('vedet-vice_anch')) addListener(document.getElementById('vedet-vice_anch'), 'click', showIFrame, false);
    addListener(document.getElementById('black-cover'), 'click', hideIFrame, false);
    addListener(document.getElementById('iframe-box'), 'click', hideIFrame, false);
    }
    


function showIFrame(e)
  { 
    x = 550;  // šířka iFrame
    y = 550;  // výška iFrame

    imgPos = checkPosition(x,y);

    showBlackCover(blackCoverHeight);
    showIFrameNow('iframe-box',x,y,imgPos[0],imgPos[1]);

    stopWorking(e);
    }


function showBlackCover(blackCoverHeight)    // zobrazení černého podkladu
  {
    document.getElementById('black-cover').style.height = blackCoverHeight + 'px';
    document.getElementById('black-cover').style.display = 'block';
    }


function showIFrameNow(elem,x,y,imgPosX,imgPosY)    // zobrazení iFrame
  {
    document.getElementById(elem).style.width = x + 'px';
    document.getElementById(elem).style.height = y + 'px';
    document.getElementById(elem).style.left = imgPosX + 'px';
    document.getElementById(elem).style.top = imgPosY + 'px';
    document.getElementById(elem).style.display = 'block';
    }

function hideIFrame()
  {
    document.getElementById('iframe-box').style.display = 'none';
    document.getElementById('black-cover').style.display = 'none';
    }


function getScreenWidth()
  {
    var screenWidth;
    if (window.innerWidth) screenWidth = window.innerWidth;  // NN4, Opera, Mozilla 
      else  if (document.documentElement && document.documentElement.clientWidth) screenWidth = document.documentElement.clientWidth;  // MSIE6 in standard mode  
              else if (document.body && document.body.clientWidth) screenWidth = document.body.clientWidth;  // older MSIE + MSIE6 in quirk mode
    return screenWidth;
      }

function getScreenHeight()
  {
    var screenHeight;
    if (window.innerHeight) screenHeight = window.innerHeight;  // NN4, Opera, Mozilla 
      else  if (document.documentElement && document.documentElement.clientHeight) screenHeight = document.documentElement.clientHeight;  // MSIE6 in standard mode  
              else if (document.body && document.body.clientHeight) screenHeight = document.body.clientHeight;  // older MSIE + MSIE6 in quirk mode
    return screenHeight;
      }

function getPageXScroll()
  {
  	var xScroll;
  	if (self.pageXOffset) xScroll = self.pageXOffset;
      else  if (document.documentElement && document.documentElement.scrollTop) xScroll = document.documentElement.scrollLeft;  // Explorer 6 Strict
              else if (document.body) xScroll = document.body.scrollLeft;  // all other Explorers
    return xScroll;
    }

function getPageYScroll()
  {
  	var yScroll;
  	if (self.pageYOffset) yScroll = self.pageYOffset;
      else  if (document.documentElement && document.documentElement.scrollTop) yScroll = document.documentElement.scrollTop;  // Explorer 6 Strict
              else if (document.body) yScroll = document.body.scrollTop;  // all other Explorers
    return yScroll;
    }

function getPosY()
  {
    var PosY = 0;
    var obj = document.getElementById('height-diag');
    if (obj.offsetParent) 
      {
      do {PosY += obj.offsetTop;}
        while (obj = obj.offsetParent);
        }
    return PosY;
    }


function checkPosition(x,y)
  {
    pageHeight = getPosY() + 21;
    screenWidth = getScreenWidth();
    screenHeight = getScreenHeight();
    if ((pageHeight) >= screenHeight) blackCoverHeight = pageHeight;
      else blackCoverHeight = screenHeight;
    
    pageOffsetX = getPageXScroll();
    pageOffsetY = getPageYScroll();
    imgPosX = Math.round((screenWidth - x) / 2) + pageOffsetX;
    imgPosY = Math.round((screenHeight - y) / 2) + pageOffsetY;
    if (imgPosX < 0) imgPosX = 0;
    if (imgPosY < 0) imgPosY = 0;

    if ((y + imgPosY) > blackCoverHeight) blackCoverHeight = y + imgPosY;

    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))  //test for MSIE x.x
      {
        var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
        if (ieversion <= 6) document.getElementById('black-cover').style.position = 'absolute';
        }
    return[imgPosX,imgPosY];
    }


function stopWorking(e)
  {
    if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false; }
    if (e && e.preventDefault && e.stopPropagation) {
      e.preventDefault();
      e.stopPropagation(); }
    }




