/******************************************************************************
 * popup.js
 *	
 *	Author: 	RWB
 *	Date:		03/29/01
 *	Purpose:	Opens a new window of definable size and properties
 *
 *	Attributes:
 *	url		- url to open in new window
 *	name		- name of new window
 *	width		- width in pixels of new window
 *	height	- height in pixels of new pixels
 *	menu		- 0= don't show menu bar
 *	tool		- 0= don't show tool bar
 *
 * Return:
 *	new window object named 'popup' with popup.name = 'name'
 *
 *	Modification List:
 *	20090903 RJM - REG-5823 // Add ifs around the window focus calls 
 *	20060227 RJM - MODIFICATION REG-730 // Add check for popup window before attempting to focus! (if(!popupWindow) return;)
 *  20041029 RJM - MODIFICATION // JS compatiblitlity for mozilla // issues with location.reload on inital popup call.
 *  20040629 RJM - MODIFICATION // tweak popup calles to exsisting window JS compatiblitlity
 *  20040518 RJM - MODIFICATION // tweak the dimensions of the refreshHelpWindow() window
 *  07/30/02 RWB - focus() on newly opened window
 *	03/29/01 RWB - Created
 *****************************************************************************/

/******************************************************************************
 * set global variables (in case 'popupWindow' window doesn't exist
 *****************************************************************************/
var helpWindow = null;
var searchWindow = null;

/******************************************************************************
 * open new window
 *****************************************************************************/
function popup(url, name, width, height, menu, tool) {	
	// close window, if one exists with the same name
	// problem is that if I resize and position the help window where I want it
	// and the close it and reopen, I lose my sizing and position
	// closePopup(name);
	
	// build features string
	var features = 'width=' + width + ',height=' + height +
		',resizable=yes,scrollbars=yes,status=yes,menubar=' + menu +',toolbar=' + tool;
	// open new window
	if (name == 'help') {
		helpWindow = window.open(url,name,features);
		// only reload the window if the url has in fact changed
		if (url == helpWindow.location){
			helpWindow.location.reload();	
		}
		if(helpWindow) helpWindow.focus();
	}
	else if (name == 'search') {
		searchWindow = window.open(url,name,features);
		if(searchWindow) searchWindow.focus();
	}
	else {
		popupWindow = window.open(url,name,features);
		if(popupWindow) popupWindow.focus();
	}
	// focus on new window and then close it	
}
/******************************************************************************
 * Close browser window named 'popupWindow', which was opened by popup()
 *****************************************************************************/
function closePopup(name) {
	// determine which window to close
	if (name == 'help') popupWindow = helpWindow;
	else if (name == 'search') popupWindow = searchWindow;
	
	// check if window is open, if so then close
	if (popupWindow != null) {
		if (!popupWindow.closed && popupWindow.name == name) {
			popupWindow.close();
		}
		popupWindow = null;
	}
}
/******************************************************************************
 * refresh Help window
 *****************************************************************************/
function refreshHelpWindow(url) {
		helpWindow = window.open(url,'help','width=760,height=425,resizable=yes,scrollbars=yes,menubar=0,status=1,toolbar=0,left=680,top=0');
		// only reload the window if the url has in fact changed
		if (url == helpWindow.location){
			helpWindow.location.reload();	
			helpWindow.focus();
		} else {
			// if you do NOT support the reload feature 
			// than this is the only way to handle popup reloads close and repoen
			helpWindow.close();
			helpWindow = window.open(url,'help','width=760,height=425,resizable=yes,scrollbars=yes,menubar=0,status=1,toolbar=0,left=680,top=0');
		}
}
