// JavaScript Document

var msgWindow = null;
var refElm    = { e : null, offsetHeight : 24 };

function getTextHeight() {
  if (document.documentElement) {
    refElm.e                = document.createElement('div');
    refElm.e.style.position = 'absolute';
    refElm.e.style.left     = '-99px';
    refElm.e.style.top      = '-99px';
    refElm.e.appendChild(document.createTextNode('Hg'));
    document.body.appendChild(refElm.e);
  }
  else
    refElm.e = refElm;
}


function openWinCaption(url, width, height, noCaption, scrollBars) {

  if (!refElm.e) getTextHeight();

  if (!window.open) return true;
  var x = (screen.width -width)  >> (window.opera ? 2 : 1);
  var y = (screen.height-height) >> (window.opera ? 2 : 1);

  if (msgWindow &&
      (typeof(msgWindow.closed)!='undefined') &&
      !msgWindow.closed) msgWindow.close();

  msgWindow = window.open(url, 'w_' + self.name,
    'width='    + width  +
    ',height='  + (height + (noCaption ? 0 : refElm.e.offsetHeight)) +
    ',left='    + x +
    ',top='     + y +
    ',screenX=' + x +
    ',screenY=' + y +
    ',scrollbars=' + (scrollBars ? scrollBars : 'no'));

  if (!msgWindow) return true;
  msgWindow.focus();
  return false;
}


function openWin(url, width, height) {
    return openWinCaption(url, width, height, true, 'yes');
}

  
function CloseIt() {
  close();
}


function openWinImg(url, width, height) {

  if (openWinCaption('', width, height, true)) return true;

  msgWindow.document.open();
  msgWindow.document.write('<html><head>' +
    '<title><\/title>' +
    '<meta http-equiv="imagetoolbar" content="no">' +
    '<style type = "text/css">' +
    'html, body, img {'    +
      'display  : block;'  +
      'margin   : 0;'      +
      'padding  : 0;'      +
      'overflow : hidden;' +
      'width    :' + width + 'px;' +
    '}' +
    '<\/style>' +
	'<\/head><body marginheight="0" marginwidth="0">' +
    '<img src="' + url + '" alt="">' +
    '<\/body><\/html>'
  );
  msgWindow.document.close();
  return false;
}

//=============================================================================

var chromeWidth, chromeHeight;

function getElmObj(id, win) {
  if (typeof win=='undefined') win = self;
  return document.getElementById ?
  win.document.getElementById(id) : document.all ?
  win.document.all[id] : document.layers ?
  win.document.layers[id] : null;
}

function getInnerWidth() {
  return window.innerWidth ?
  self.innerWidth :
  (document.body && document.body.clientWidth) ?
  document.body.clientWidth : 0;
}

function getInnerHeight() {
  return window.innerHeight ?
  self.innerHeight :
  (document.body && document.body.clientHeight) ?
  document.body.clientHeight : 0;
}

function checkViewportsize() {
  var img    = document.images[0];
  var cap    = getElmObj('tekst');
  var width  = parseInt(img.width);
  var height = parseInt(document.images[0].height) +
    parseInt(document.layers ? cap.clip.height : cap.offsetHeight);

  if (width != getInnerWidth() || height != getInnerHeight()) {
    resizeTo(width + chromeWidth, height + chromeHeight);
    if (document.layers && !navigator.rload) {
      navigator.rload = true;
      location.reload();
    }
  }

  if (document.getElementById)
    setTimeout('checkViewportsize()', 300);
}

function popupWinOnload() {

  if (window.outerHeight) {
    var w = outerWidth;
    var h = outerHeight;
  }
  else {
    var w = getInnerWidth()  + 10;
    var h = getInnerHeight() + 30;
  }

  resizeTo(w, h);
  chromeWidth  = w - getInnerWidth();
  chromeHeight = h - getInnerHeight();

  checkViewportsize();
}

