// Variables

var imageWindow = null;
var popupWindow = null;
var flashWindow = null;

//--------------------------------------------------------------- showPopup -

function printPage(url,width,height) {
// ***************************************************************************
// * Method.....: printPage()
// * Description: Print Preview of HTML page in external window
// ***************************************************************************

  showPopup(url,width,height);
  setTimeout("popupWindow.print()",3000);
}

//--------------------------------------------------------------- showPopup -

function showPopup(url,width,height) {
// ***************************************************************************
// * Method.....: showPopup()
// * Description: Show HTML page in external window
// ***************************************************************************

  if (popupWindow != null) {
    popupWindow.close();
    popupWindow = null;
  }
  popupWindow = window.open("","popupWindow","dependent=yes,directories=no,hotkeys=no,location=no,menubar=no,status=no,toolbar=no,width=" + width + ",height=" + height + ",scrollbars=yes,resizable=yes");
  popupWindow.moveTo(50,50);
  popupWindow.document.location = url;
  popupWindow.focus();
};

//---------------------------------------------------------------- showImage -

function hideImage() {
// ***************************************************************************
// * Method.....: hideImage()
// * Description: Close external image window
// ***************************************************************************

  if (imageWindow != null) {
    imageWindow.close();
    imageWindow = null;
  }
}	  

function loadImage(image,alt,repeat) {
// ***************************************************************************
// * Method.....: loadImage()
// * Description: Load image for external window
// ***************************************************************************

  var img = new Image();
  img.src = image;
  if (img.width == 0) {
    if (repeat > 0) {
    // Image Dimension is not clear because of "still loading". Window has standard dimensions. Reload for right dimensions.
      window.setTimeout("loadImage('" + image + "','" + alt + "','" + --repeat + "')",1000);
    }
    else {
      hideImage();
      alert('Image\n\n"' + alt + '"\n\ncould not be loaded.\nYou may try again.');
    }
  }
  else {
    showImage(image,alt);
  }
}

function showImage(image,alt) {
// ***************************************************************************
// * Method.....: showImage()
// * Description: Show image in external window
// ***************************************************************************

  if ((image != "") && (alt != "")) {
    var img = new Image();
    img.src = image;
    hideImage();
    if (img.width == 0) {
    // Image Dimension is not clear because of "still loading". Window has standard dimensions. Reload for right dimensions.
      window.setTimeout("loadImage('" + image + "','" + alt + "','" + 10 + "')",1000);
      imageWindow = window.open("","imageWindow",
                                "dependent=yes,directories=no,hotkeys=no,location=no,menubar=no,status=no,toolbar=no,width=300,height=30");
      imageWindow.father = self;
      imageWindow.moveTo(50,50);
      imageWindow.document.open("text/html");
      imageWindow.document.write('<HTML><HEAD><TITLE>Load Image</TITLE><LINK REL="stylesheet" TYPE="text/css" MEDIA="screen" HREF="res/rain-webs.css"></HEAD><BODY><p><center><br>Loading...<br><br>Please, wait.</center></p></BODY></HTML>');
      imageWindow.document.close();
      imageWindow.focus();
    }
    else {
      imageWindow = window.open("","imageWindow",
                                "dependent=yes,directories=no,hotkeys=no,location=no,menubar=no,status=no,toolbar=no,width=" + 
                                (img.width + 30) + ",height=" + 
                                (img.height + 50));
      imageWindow.moveTo(50,50);
      imageWindow.document.open("text/html");
      imageWindow.document.write('<HTML><HEAD><TITLE>' + alt + 
                                 '</TITLE><LINK REL="stylesheet" TYPE="text/css" MEDIA="screen" HREF="res/rain-webs.css"></HEAD><BODY><TABLE width="100%"><TR><TD><IMG SRC="images/clear.gif" ALIGN="LEFT" WIDTH="1" HEIGHT="15" BORDER="0"></TD></TR><TR><TD><center><img src="' + img.src + '" width="' + 
                                 img.width + '" height="' + 
                                 img.height + '" border="0" alt="' + alt + 
                                 '"></center></TD></TR></TABLE></BODY></HTML>');
      imageWindow.document.close();
      imageWindow.focus();
    }
  }
  else {
    alert("Sorry, no image (description) found.");
  }
}

//---------------------------------------------------------------- showFlash -

function showFlash(url,title,width,height) {
// ***************************************************************************
// * Method.....: showFlash()
// * Description: Show flash page in external window
// ***************************************************************************

  if (flashWindow != null) {
    flashWindow.close();
    flashWindow = null;
  }
  flashWindow = window.open("","flashWindow","dependent=yes,directories=no,hotkeys=no,location=no,menubar=no,status=no,toolbar=no,width=" + (width + 40) + ",height=" + (height + 40) + ",scrollbars=yes,resizable=yes");
  flashWindow.moveTo(50,50);
  flashWindow.document.open("text/html");
  flashWindow.document.write('<HTML><HEAD><TITLE>' + title + '</TITLE><LINK REL="stylesheet" TYPE="text/css" MEDIA="screen" HREF="res/rain-webs.css"></HEAD><BODY><p><center><OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0" ID="banner" WIDTH="' + width + '" HEIGHT="' + height + '"><PARAM NAME="movie" VALUE="' + url + '"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="quality" VALUE="high"><PARAM NAME="allowscriptaccess" VALUE="samedomain"><EMBED TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" WIDTH="' + width + '" HEIGHT="' + height + '" NAME="banner" SRC="' + url + '" BGCOLOR="#FFFFFF" QUALITY="high"></OBJECT></center></p></BODY></HTML>');
  flashWindow.document.close();
  flashWindow.focus();
};

function showImage(image,alt) {
// ***************************************************************************
// * Method.....: showImage()
// * Description: Show image in external window
// ***************************************************************************

  if ((image != "") && (alt != "")) {
    var img = new Image();
    img.src = image;
    hideImage();
    if (img.width == 0) {
    // Image Dimension is not clear because of "still loading". Window has standard dimensions. Reload for right dimensions.
      window.setTimeout("loadImage('" + image + "','" + alt + "','" + 10 + "')",1000);
      imageWindow = window.open("","imageWindow",
                                "dependent=yes,directories=no,hotkeys=no,location=no,menubar=no,status=no,toolbar=no,width=300,height=30");
      imageWindow.father = self;
      imageWindow.moveTo(50,50);
      imageWindow.document.open("text/html");
      imageWindow.document.write('<HTML><HEAD><TITLE>Load Image</TITLE><LINK REL="stylesheet" TYPE="text/css" MEDIA="screen" HREF="res/rain-webs.css"></HEAD><BODY><p><center><br>Loading...<br><br>Please, wait.</center></p></BODY></HTML>');
      imageWindow.document.close();
      imageWindow.focus();
    }
    else {
      imageWindow = window.open("","imageWindow",
                                "dependent=yes,directories=no,hotkeys=no,location=no,menubar=no,status=no,toolbar=no,width=" + 
                                (img.width + 30) + ",height=" + 
                                (img.height + 50));
      imageWindow.moveTo(50,50);
      imageWindow.document.open("text/html");
      imageWindow.document.write('<HTML><HEAD><TITLE>' + alt + 
                                 '</TITLE><LINK REL="stylesheet" TYPE="text/css" MEDIA="screen" HREF="res/rain-webs.css"></HEAD><BODY><TABLE width="100%"><TR><TD><IMG SRC="images/clear.gif" ALIGN="LEFT" WIDTH="1" HEIGHT="15" BORDER="0"></TD></TR><TR><TD><center><img src="' + img.src + '" width="' + 
                                 img.width + '" height="' + 
                                 img.height + '" border="0" alt="' + alt + 
                                 '"></center></TD></TR></TABLE></BODY></HTML>');
      imageWindow.document.close();
      imageWindow.focus();
    }
  }
  else {
    alert("Sorry, no image (description) found.");
  }
}