// call this script using the following include:
/* ********************* snip below this line *********************
<SCRIPT TYPE="text/javascript" 
   SRC="http://nfc.arizona.edu/js/popup_window.js" 
   CHARSET="ISO-8859-1">
<!-- hide from old browsers

   // DEFINES:  the function "popup_window (window_url, window_name, window_features);"
            //  the function "popup_window_close()" for closing the window if it exists
            //  object self.name="main_window" for using HTML links to target main window
            //  var "new_window" for keeping track if the new window is open

   // PURPOSE:  Opens a new window and 
            //  allows the same link to be reused to bring the new window to the top
            //  allows for cross-controlling between two windows via JS and HTML targets

   // REQUIRES: the popup window must be closed if the main page (the opener) is unloaded
            //  use this code:  <body onUnload="new_window.close();">

	// VERSION 1.0b  Febraury 7, 2000

// stop hiding form old browsers -->
</SCRIPT>
********************* snip above this line ********************* */

// Standardized PopUp Window Opening JavaScript

// VERSION HISTORY:
	// VERSION 1.0b  Febraury 7, 2000 (about a week prior to actually)
	// goal was to create a popoup window button which would ALWAY work when clicked
		// see testing below for more information
		// LOTS of different methods and scripts were researched and tested

// SOURCES: (roughly in order of perceived usefulness):
// http://www.infohiway.com/javascript/n/n0100b.htm
// http://webreference.com/js/column7/
// http://www.devguru.com/index.asp?page=/Technologies/ecmascript/quickref/win_open.html
// http://developer.netscape.com/docs/manuals/communicator/jsref/win.htm
// http://www.webreference.com/javascript/960826/windows_frames.html
// http://builder.cnet.com/Programming/Kahn/092497/toolwb.html

// KNOWN ISSUES:
	//if this page is reloaded, it will forget what new_windows it had opened
		// and be unable to focus() on it or close() it (or do anything with it)
		// the only true way around this was a method using cookies
		// however, the cookies method would crash IE5 under specific conditions
				// if the main window was closed manually while leaving the new_window open
				// and then another window was opened manually, produced a IE5.01 crash (98 & NT)
		// the best work around is to close the new_window on unLoad of the main page

// TESTING:
	// This script was tested successfully on current versions of NS and IE on Win98, NT, and Mac
	// Test date February 2, 2000
	// features tested:
		// link and form buttons open window (or brings previously opened window to top) consistently
		// links and buttons work even after new window closed manually by user
		// links and buttons work even after new window URL changed by user (returns to original URL)
		// links and buttons work even after main page is reloaded or URL changed by user
			// (unload causes the new window to close, but the link will successfully open it again)

// WARNING: Be sure to close the new_window on unLoad of this page!
	// use:  <body onUnload="new_window.close();">
	// if you forget the links to open the new_window won't work if the main_window is reloaded!

self.name="main_window"; // name this window, "main_window" in case the popup needs to target links
var new_window = null; // resets this global variable when page is executed

function popup_window (window_url, window_name, window_features) {
	if (new_window && !new_window.closed && new_window.name != window_name) {
		// if the new_window already exists and it isn't closed then just bring it to the top
		new_window.focus();
		if (new_window.location.href != window_url) {
			new_window.location.href = window_url;
		}
	} else {
		// open a window and make sure that the window can access values from this window
		new_window = window.open(window_url,window_name,window_features);
		if (new_window.opener == null)  {
			// if something went wrong (I presume this is for browser backwards compatibility)
			new_window.opener = self;
		}
		new_window.opener.name = self.name;
	}
}

function popup_window_close() {
	if (new_window) {
		new_window.close();
		new_window = null;
	}
}
