// Modal Dialog Box
// copyright 8th July 2006 by Stephen Chapman
// http://javascript.about.com/
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration

function pageWidth() {
  return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}

function pageHeight() {
  return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
}

function posLeft() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;
}

function posTop() {
  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;
}

function scrollFix() {
  var obol=$('ol');obol.style.top=posTop()+'px';obol.style.left=posLeft()+'px'
}

function sizeFix() {
  var obol=$('ol');obol.style.height=pageHeight()+'px';obol.style.width=pageWidth()+'px';
}

function kp(e) {
  ky=e?e.which:event.keyCode;if(ky==88||ky==120)hm();return false
}

function inf(h) {
  tag=document.getElementsByTagName('select');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;tag=document.getElementsByTagName('iframe');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;tag=document.getElementsByTagName('object');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;
}

function sm(obl, wd, ht, tp) {
  var h='hidden';
  var b='block';
  var p='px';
  var obol=$('ol'); 
  if (!obol) {
    initmb();
    obol=$('ol');
  }
  obol.style.height=pageHeight()+p;
  obol.style.width=pageWidth()+p;
  obol.style.top=posTop()+p;
  obol.style.left=posLeft()+p;
  obol.style.zIndex=998;
  obol.style.display=b;
  if (typeof(wd) == 'undefined') {
    var els = $(obl).style;
    var originalVisibility = els.visibility;
    var originalPosition = els.position;
    var originalDisplay = els.display;
    els.visibility = 'hidden';
    if (originalPosition != 'fixed') // Switching fixed to absolute causes issues in Safari
      els.position = 'absolute';
    els.display = 'block';
    wd = $(obl).clientWidth;
    ht = $(obl).clientHeight;
    els.display = originalDisplay;
    els.position = originalPosition;
    els.visibility = originalVisibility;
  }
  if (typeof(tp) == 'undefined') tp=posTop()+((pageHeight()-ht)/2)-12;
  var lt=posLeft()+((pageWidth()-wd)/2)-12;
  var obbx=$(obl);
  obbx.style.top=(tp<0?0:tp)+p;
  obbx.style.left=(lt<0?0:lt)+p;
  obbx.style.width=wd+p;
  obbx.style.height=ht+p;
  obbx.style.zIndex=999;
  inf(h);
  obbx.style.display=b;
  return false;
}

function hm(el) {
  var v='visible';
  var n='none';
  $('ol').style.display=n;
  $(el).style.display=n;
  inf(v);
}

function initmb() {
  var obody=document.getElementsByTagName('body')[0];
  var obol=document.createElement('div');
  obol.setAttribute('id','ol');
  obol.style.display='none';
  obol.style.position='absolute';
  obol.style.top=0;
  obol.style.left=0;
  obol.style.zIndex=998;
  obol.style.width='100%';
  obody.appendChild(obol);
  window.addEvent('scroll', scrollFix); 
  window.addEvent('resize', sizeFix);
}

