//  ************************************************
//  Customizable Settings - Begin
//  ************************************************
var intWidth		= 400;			// popup browser window width (pixels)
var intHeight		= 300;			// popup browser window height (pixels)
var intPosLeft		= 40;			// popup browser window position from left border of screen (pixels)
var intPosTop		= 30;			// popup browser window position from top border of screen (pixels)
var strName		= "My_Name";		// popup browser window name (alphanumeric and underscore only)

var blnScrollbars	= 1;			// 1=show scroll bars; 0=hide
var blnResizable	= 1;			// 1=allow resize; 0=no resize
var blnLocation		= 0;			// 1=show address/location bar; 0=hide
var blnMenubar		= 0;			// 1=show menu bar; 0=hide
var blnToolbar		= 0;			// 1=show tool bar; 0=hide
var blnStatus		= 0;			// 1=show status bar; 0=hide

var strFilePath = "";				// URL prefix (absolute or relative path) to place in front of the selected URL

//	strFilePath Usage
//	
//	if the pages (URLs) to be opened in the new window all have a common beginning
//	you can specify it here.  this can save repetition of keying in those characters
//	and downloading them to the client.
//	
//	Example:
//	
//	with:	var strFilePath = ""
//	your HTML is:
//		option value="../popupfolder/page1.htm"
//		option value="../popupfolder/page2.htm"
//		option value="../popupfolder/page3.htm"
//	
//	with: var strFilePath = "../popupfolder/"
//	your HTML is:
//		option value="page1.htm"
//		option value="page2.htm"
//		option value="page3.htm"
//	
//	If all links are on other sites, this could be "http://"
//	________________________________________________
	
var blnEnableSelfClose = true;			// DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING

//	blnEnableSelfClose Usage		// PLEASE READ THESE USAGE INSTRUCTIONS BEFORE CHANGING
//   
//	FALSE disables the self closing feature for the opening window
//	TRUE enables the self closing feature for the opening window
//	
//	This feature allows the page that opens the popup window to self close.
//	This feature should be turned off if using URLs from different servers.
//	
//	If the page which calls this function needs to be closed after opening the popup window,
//	enable this feature.  It is not very often where this is desirable.
//	
//	One scenario where this is helpful is if you have a main page of links or dropdown options
//	which use this function to popup a thumbnail image.  If that thumbnail image then uses this
//	same function to open the full size image in yet another popup window, you would likely want
//	the window with the thumbnail to self-close.
//	
//	* NOTE *  There is one type of page which will NOT self-close when this feature is enabled.
//	
//	Pages whose URL ends with a forward slash ("/") will NOT Self-Close.  This prevents a
//	page with a URL similar to   http://www.foo.com/   or   http://www.foo.com/~username/
//	from self-closing, commonly used for home or default pages.  All other pages close.
//	________________________________________________
	
var strSelfCloseException = "index";		// IGNORED IF  blnEnableSelfClose = false

//	strSelfCloseException Usage
//	
//	Pages whose URL contains the string "index" will NOT Self-Close.  This prevents commonly
//	named home or default pages from self-closing.  All other pages close (except "/" ending.)
//	
//	If you don't want to specify any exceptions, specify just a space character, as follows:
//	var strSelfCloseException = " ";
//	
//	This string is NOT case-sensitive.
//	________________________________________________
//	
//  ************************************************
//  Customizable Settings - End
//  ************************************************


var popupWin;    // initialize the variable used to identify the browser window handle

function openWindow(url, name, wd, ht, scroll) {

// openWindow Usage
//		openWindow('url_or_filename','window_name',width_number,height_number,scroll_-0or1)

//	Close any window previously opened
	if (popupWin) {					// determine if the browser window handle is still valid
		if (popupWin.closed == false) {		// if the handle is valid, see if the window is closed
			popupWin.close();		// if it isn't closed, close it
		}
	}
	
//	Set the parameters for the popup window
	var param = "width=" +wd +",height=" +ht;	// build the parameter string with width and height
	param = param +",scrollbars=" +scroll;		// add the scrollbars option to the parameter string
	param = param +",resizable=" +blnResizable;	// add the resizable option to the parameter string
	param = param +",location=" +blnLocation;	// add the location option to the parameter string
	param = param +",menubar=" +blnMenubar;		// add the menubar option to the parameter string
	param = param +",toolbar=" +blnToolbar;		// add the toolbar option to the parameter string
	param = param +",status=" +blnStatus;		// add the status option to the parameter string
	param = param +",screenX=" +intPosLeft;		// add the left screen position option to the parameter string for Netscape
	param = param +",screenY=" +intPosTop;		// add the top screen position option to the parameter string for Netscape
	param = param +",left=" +intPosLeft;		// add the left screen position option to the parameter string for MSIE
	param = param +",top=" +intPosTop;		// add the top screen position status option to the parameter string for MSIE
	
//	Determine the target URL for the popup window
	var url = strFilePath + url;			// concatenate the filepath to the url
	
//	Open the popup window
	popupWin = window.open(url, name, param);	// open the window
	popupWin.focus();				// bring the window to the top
	
//	Self-Close the opener window if enabled
	if (blnEnableSelfClose == true) {
		if (strSelfCloseException == "")		// disallow empty string, as all strings contain an empty string
			{strSelfCloseException = " "}		// replace the empty string with a space
			{strSelfCloseException = strSelfCloseException.toLowerCase();}		// force lowercase
					
		var selfurl = new String(self.location);	// identify the URL
		var urllength = selfurl.length;			// identify the URL length
		selfurl = selfurl.toLowerCase();		// force lowercase
		
//		Self-Close only if URL does NOT end in slash AND does NOT contain the exception string
		if (selfurl.indexOf(strSelfCloseException) == -1 && selfurl.charAt(urllength-1) != "/") {self.close();};
		
//		place focus back on the popup window again (it may lose focus on the self.close)
		popupWin.focus();
	}
}
