var IE = (document.all) ? true : false;
var bDebug = false;  

function openpopup(winname, url, morefeatures) {
  var features = 'titlebar=no,status=no,toolbar=no,location=no,dependent=no,resizable=yes';
  if (bDebug)
    features += ',menubar=yes';
  else
    features += ',menubar=no';

  if (morefeatures != "")
    features += ','+morefeatures;

  var win = window.open(url, winname, features);
  win.opener = self;
  win.focus();
  return win;
}

function move2center(mainwin, subwin) {
  var xIndent = (screen.width - subwin.outerWidth) / 2;
  var yIndent = (screen.height - subwin.outerHeight) / 2;
  subwin.moveTo(xIndent, yIndent);
}

function dialog(url, name, morefeatures) {
  var size = windows[name];

  if (size != null)
  {
    if (morefeatures != "")
      morefeatures += ",";

    morefeatures += "width=" + size.w + ",height=" + size.h;
  }
  var dialog = openpopup(name, url, morefeatures);
  move2center(window, dialog);
}

function drucken(button) {
  button.style.visibility = "hidden";
  try { window.print(); } catch (e) {}
}

function Size(w, h) {
  this.w = w;
  this.h = h;
}

function showimage(url) {
	var win = window.open('', 'image', 'dependent=yes,titlebar=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbar=no');
	var doc = win.document;
	
	doc.open();
	doc.writeln('<html><head><title>Bild</title>');
	base = document.getElementsByTagName('base')[0];
	doc.writeln('<base href="' + base.getAttribute('href') + '">');
	doc.writeln('</head>');
	doc.writeln('<body style="margin:0; background:#FFFFFF;" onload="setSize()">');
	doc.writeln('<img src="' + url + '" border="0">');
	doc.writeln('<script type="text/javascript">');
	doc.writeln('function setSize() {');
	doc.writeln('  var img = document.images[0];');
	doc.writeln('  if (window.innerWidth) {');
	doc.writeln('    var iWidth = window.innerWidth;');
	doc.writeln('    var iHeight = window.innerHeight;');
	doc.writeln('  } else {');
	doc.writeln('    var iWidth = document.body.clientWidth;');
	doc.writeln('    var iHeight = document.body.clientHeight;');
	doc.writeln('  }');
	doc.writeln('  window.resizeBy(img.width - iWidth, img.height - iHeight);');
	doc.writeln('}');
	doc.writeln('</script>');
	doc.writeln('<br>');
	doc.writeln('</body></html>');
	doc.close();
	win.focus();
}

// set window sizes
var windows = new Array();

windows["dispHelp"] = new Size(750,480);
windows["da_edit"]  = new Size(620,600);
windows["crm"]      = new Size(620,480);
windows["Data"]     = new Size(800,500);
windows["Doc"]      = new Size(700,500);
windows["Manual"]   = new Size(750,480);
windows["Letter"]   = new Size(1000,600);
windows["Calc"]     = new Size(650,700);
windows["Help"]     = new Size(700,600);

windows["Admin"]       = new Size(800,620);
windows["Post Manual"] = new Size(800,500); 

// for debug mode: advance window size to be able to see the whole debug console
if (bDebug && bEnlargeWindows)
{
  for (var wname in windows)
  {
    if (wname == "Admin")
      continue;

    windows[wname].w = 950;
    windows[wname].h = 900;
  }
}

function consoleMoveStart(event) {
  if (!IE) {
    window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
  }
  document.onmousemove = consoleMove;
  document.onmouseup = consoleMoveStop;
  event.cancelBubble = true;
}

function consoleMove(event) {
  if (!event) event = window.event;
  console = document.getElementById("debugconsole");
  console.style.top = getPosY(event) + 'px';
}

function consoleMoveStop(event) {
  if (!event) event = window.event;
  document.onmousemove = null;
  document.onmouseup = null;
}

function getPosY(event) {
  return IE ? event.clientY : event.pageY;
}