// popup.js

var WinWidthMin = 600;   //  Deklaration mit 'const' 
var WinHeightMin = 800;  //  in Java-Version 1.0 
var WinWidthMax = 1024;  //  leider noch nicht
var WinHeightMax = 768;  //  möglich...

var PicFileName = "";
var PicSizeX = 0;
var PicSizeY = 0;

var VidFileName = "";
var VidSizeX = 0;
var VidSizeY = 0;

function WinSizeX(VarMult) {
  var WinSize = Math.max(Math.ceil(screen.availWidth * VarMult), WinWidthMin * VarMult);
  WinSize = Math.min(WinSize, WinWidthMax * VarMult);
  return WinSize;
}

function WinSizeY(VarMult) {
  var WinSize = Math.max(Math.ceil(screen.availHeight * VarMult), WinHeightMax * VarMult);
  WinSize = Math.min(WinSize, WinHeightMax * VarMult);
  return WinSize;
}

function WinOpenX(VarSize) {
  var WinPos = Math.max(Math.ceil((screen.availWidth - VarSize) / 2), 0);
  return WinPos;
}

function WinOpenY(VarSize) {
  var WinPos = Math.max(Math.ceil((screen.availHeight - VarSize) / 2), 0);  
  // fünf Prozent nach oben verschieben wg. Taskleiste... (hoffentlich hat keiner die Taskleiste oben)
  WinPos = Math.max(WinPos - Math.floor(screen.availHeight * 0.05), 0);  
  return WinPos;
}

function NoSpaces(VarTxt) {
  // für Netscape für Argumente bei 'window.open' unbedingt notwendig...
  var CharPos = "";
  CharPos = VarTxt.indexOf(" ");
  while (CharPos >= 0) {
    VarTxt = VarTxt.substring(0,CharPos,VarTxt) + VarTxt.substring(CharPos+1,VarTxt.length,VarTxt);
    CharPos = VarTxt.indexOf(" ");
  }
  return VarTxt;
}

function PopupImage(PicFileName, PicSizeX, PicSizeY ) {
  SizeX = Math.ceil(PicSizeX+50);
  SizeY = Math.ceil(PicSizeY+50);
  SizeY = SizeY + 25;
  OpenX = WinOpenX(SizeX);
  OpenY = WinOpenY(SizeY);
  WinOpnOpt = "left=" + OpenX + ", top=" + OpenY + ", width=" + SizeX + ", height=" + SizeY
  WinOpnOpt = WinOpnOpt + ", menubar=no, toolbar=no, location=no, status=no";   
  htmltxt = "";
  htmltxt += '<html>\n';
  htmltxt += '<head>\n';
  htmltxt += '<title>Bild: ';
  htmltxt += PicFileName;
  htmltxt += '</title>\n';
  htmltxt += '<base href="http://www.robatum.de/">\n';
  htmltxt += '</head><body background="./gifs/area_grey.gif" bgcolor="#C0C0C0">\n';
  htmltxt += '<p style="line-height: 125%; word-spacing: 0; margin-top: 12" align="center">\n';
  htmltxt += '<img src="';
  htmltxt += PicFileName;
  htmltxt += '" border="1" width="';
  htmltxt += PicSizeX;
  htmltxt += '" height="';
  htmltxt += PicSizeY;
  htmltxt += '" >\n';
  htmltxt += '</p>\n';
  htmltxt += '<p style="line-height: 125%" align="center">\n';
  htmltxt += '<div align="center">\n';
  htmltxt += '<form action="">\n';  
  htmltxt += '<font size="4">\n';
  htmltxt += '<input type="button" value="Fenster schließen" onclick="javascript:top.close()">\n';
  htmltxt += '</font></p>\n';
  htmltxt += '</form>\n';  
  htmltxt += '</div>\n';
  htmltxt += '</body>\n';
  htmltxt += '</html>\n';
  if ((typeof(PUW) == "object") && (PUW.closed == false)) PUW.close();
  PUW = window.open("","Popup",NoSpaces(WinOpnOpt));
  PUW.document.open;
  PUW.document.writeln(htmltxt);
  PUW.document.close;
  PUW.focus();
}
