/*
Filename:  popup.js
Desc:      Generic Popup Window Handler
Copyright: Relevant Arts Enterprise, Inc. <http://www.relevantarts.com/>
Author:    John A. Lock <jlock@relevantarts.com>
Created:   1999-Apr-29 v1.0
Modified:  1999-Jul-17 v1.1 Modified to support display of full HTML
               pages or standalone images.
           1999-Jul-31 v1.2 Changed timing of window write to avoid
               errors in MSIE on slow PCs.
           1999-Dec-29 v1.3 Modified to add "Close" button on image
               only popups.
           2001-Jun-25 v1.4 Modified to remove the "init" window. And
               quit supporting 3.0 browsers.
           2003-Jul-11 v1.5 Modified to allow right/left positioning
					     of popup
					 2004-Feb-26 v2.0 Modified to center image popups vertically
					    and horizontally in window
					2005-Apr-15 v2.1 Modified to force a reload after generating an image
					    popup to get rid of scroll bars in Gecko-based browsers
*/

var WinString;
var PopupWin;
var popup_image_path = "img/";

// Display the popup window (closing any open ones first)
function popup(WinType,WinWidth,WinHeight,WinURL,WinScroll,Position) {
	if (!document.images) return;
	ClosePopup();
	// If it's an image popup, add 17 to the height to allow for the 
	// close button at the bottom.
	if (WinType == "image") {
		WinHeight = parseInt(WinHeight) + 17;
	}

	// Find out if we need a scrollbar or not
	if (WinScroll == "noscroll") {
		var ScrollVal = "no";
	}
	else {
		var ScrollVal = "yes";
	}

	// Set the screen position for the popup
	if (Position == "right") {
		if (navigator.appName.indexOf("Microsoft") != -1) {
			WinX = self.screenLeft + (document.body.clientWidth - WinWidth);
			WinY = self.screenTop - 100;
		}
		else {
			WinX = self.screenX + (self.outerWidth - WinWidth - 20);
			WinY = self.screenY + 20;
		}
	}
	else {
		if (navigator.appName.indexOf("Microsoft") != -1) {
			WinX = self.screenLeft + 20;
			WinY = self.screenTop - 100;
		}
		else {
			WinX = self.screenX + 20;
			WinY = self.screenY + 20;
		}
	}

	// Build a string to pass to the display function
	WinString = "width=" + 
		WinWidth +
		",height=" +
		WinHeight +
		",toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=" +
		ScrollVal +
		",resizable=yes,top=" +
		WinY +
		",left=" +
		WinX;

	// Display the appropriate popup type
	if (WinType == "page") {
		DisplayPage(WinURL, WinString);
	}
	else {
		DisplayImage(WinURL, WinString);
	}
}

// Display the passed HTML Page in a popup window
function DisplayPage(WinURL, WinString) {
	PopupWin = window.open(WinURL,'PopupWin',WinString);
	if (PopupWin.opener == null) {
		PopupWin.opener = window;
	}
	if (navigator.appName.indexOf("Netscape") != -1) {
		PopupWin.location.href = WinURL;
	}
}

// Display the passed image in a popup window
function DisplayImage(WinURL, WinString) {
	PopupWin = window.open('','PopupWin',WinString);
	if (PopupWin.opener == null) {
		PopupWin.opener = window;
	}
	PopupWin.document.write("<html><head><title>Popup Window</title><meta http-equiv='imagetoolbar' content='no'></head>");
	PopupWin.document.write("<body bgcolor='#000000' topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'>");
	PopupWin.document.write("<table width='100%' cellspacing='0' cellpadding='0' border='0'>");
	PopupWin.document.write("<tr><td><table cellspacing='0' cellpadding='0' border='0' align='center'>");
	PopupWin.document.write("<tr><td align='center'><a href='javascript:window.close()'><img src='" + WinURL + "' border='0'></a><br>");
	PopupWin.document.write("<a href='javascript:window.close()'><img src='" + popup_image_path + "clicktoclose.gif' border='0'></a>");
	PopupWin.document.write("</td></tr></table></td></tr></table></body></html>");
	PopupWin.document.close();
	if (navigator.userAgent.indexOf("Safari") == -1) {
		PopupWin.location.reload();
	}
}

// Close the popup window
function ClosePopup() {
	if (PopupWin && !PopupWin.closed) {
		PopupWin.close();
	}
}
