﻿
function hideDiv() {
    if (document.getElementById) { // DOM3 = IE5, NS6
      document.getElementById('hideshow').style.visibility = 'hidden';
  } else { 
    if (document.layers) { // Netscape 4 
      document.hideshow.visibility = 'hidden';
    } else { // IE 4 
      document.all.hideshow.style.visibility = 'hidden';
    } 
  } 
}
function getDivState() {
    if (document.getElementById) { // DOM3 = IE5, NS6
        return (document.getElementById('hideshow').style.visibility);
    } else {
        if (document.layers) { // Netscape 4 
            return(document.hideshow.visibility);
        } else { // IE 4
            return (document.all.hideshow.style.visibility);
        }
    }
    return ("");
}

function showDiv() {
  if (document.getElementById) { // DOM3 = IE5, NS6
    document.getElementById('hideshow').style.visibility = 'visible';
  } else { 
    if (document.layers) { // Netscape 4
      document.hideshow.visibility = 'visible';
    } 
    else { // IE 4 
      document.all.hideshow.style.visibility = 'visible';
    }
  }
  centerPopupBlock();
}

var centerPopupOnResize = function()
{
  var elmHideShow = document.getElementById("hideshow");
  if (elmHideShow.style.visibility == "visible")
  {
    centerPopupBlock();  
  }
}

function centerPopupBlock()
{
  var elmPopupBlock = document.getElementById("popup-block");
  var sizePopup = { width: elmPopupBlock.offsetWidth, height: elmPopupBlock.offsetHeight };
  var locPopup = center(sizePopup);
  elmPopupBlock.style.position = "absolute";
  elmPopupBlock.style.top = locPopup.y + "px";
  elmPopupBlock.style.left = locPopup.x + "px";
  elmPopupBlock.style.minHeight = "200px"; // When we change panes, leaving this alone may cause blank space.
  window.onresize = centerPopupOnResize;
}

window.size = function()
{
  var w = 0;
  var h = 0;
  // IE
  if (!window.innerWidth)
  {
    // strict mode
    if (!(document.documentElement.clientWidth == 0))
    {
      w = document.documentElement.clientWidth;
      h = document.documentElement.clientHeight;
    }
    else
    {
      w = document.body.clientWidth;
      h = document.body.clientHeight;
    }
  }
  else
  {
    // w3c
    w = window.innerWidth;
    h = window.innerHeight;  
  }
  return { width:w, height:h };
}

window.center = function()
{
  var hWnd = (arguments[0] != null) ? arguments[0] : { width: 0, height: 0 };
  var _x = 0;
  var _y = 0;
  var offsetX = 0;
  var offsetY = 0;
  //IE
  if (!window.pageYOffset)
  {
    //strict mode
    if (!(document.documentElement.scrollTop == 0))
    {
      offsetY = document.documentElement.scrollTop;
      offsetX = document.documentElement.scrollLeft;
    }
    //quirks mode
    else
    {
      offsetY = document.body.scrollTop;
      offsetX = document.body.scrollLeft;
    }
  }
  //w3c
  else
  {
    offsetX = window.pageXOffset;
    offsetY = window.pageYOffset;
  }
  _x = ((this.size().width - hWnd.width) / 2) + offsetX;
  _y = ((this.size().height - hWnd.height) / 2) + offsetY;
  return { x: _x, y: _y };
}

keyboardAction = function(e) {
    if (getDivState() != 'visible')
        return;
    var keycode = key = escape = null;
    keycode = (e == null) ? event.keyCode : e.which;
    key = String.fromCharCode(keycode).toLowerCase();
    escape = (e == null) ? 27 : e.DOM_VK_ESCAPE;
    if ((key == 'x') || (key == 'c') || (keycode == escape)) {
        hideDiv();
    } else if ((key == 'p') || (keycode == 37)) {
        goPage(-1);
    } else if ((key == 'n') || (keycode == 39)) {
        goPage(1);
    }
};

document.onkeydown = this.keyboardAction;
