/*
This function was made to create popup windows.
One function creates a window, and the other destroys it
if the script has a problem opening the window, it will not be opened
if the function is called multiple times, the new window will replace the old one
*/

/* GLOBAL VARIABLES */

// this variable will hold the window obect
var popup = null;

/*  
  FUNCTION 1

  Name: CreateWindow() 
  Purpose: To Create & Center a popup window
  The window will be replaced by a new popup window
  if the popup is not closed first
*/

function CreateWindow (file, width, height, resize, scrollbars)
{
	var doCenter = false;

	if((popup == null) || popup.closed)
	{
		attribs = "";

		/*/ there's no popup displayed /*/

		// assemble some params
		if(resize) size = "yes"; else size = "yes";

		/*/
		/ / We want to center the pop-up; however, to do this we need to know the
		/ / screen size.  The screen object is only available in JavaScript 1.2 and
		/ / later (w/o Java and/or CGI helping), so we must check for the existance
		/ / of it in the window object to determine if we can get the screen size.
		/ /
		/ / It is safe to assume the window object exists because it was implemented
		/ / in the very first version of JavaScript (that's 1.0).
		/*/
		
		for(var item in window)
			{ if(item == "screen") { doCenter = true; break; } }
        // center the window
		if(doCenter)
		{	

			// if the screen is smaller than the window, override the resize setting
			if(screen.width <= width || screen.height <= height) size = "yes";

			WndTop  = (screen.height - height) / 2;
			WndLeft = (screen.width  - width)  / 2;

			// collect the attributes
			attribs = "width=" + width + ",height=" + height + ",resizable=yes,scrollbars=" + size + "," + 
			"status=no,toolbar=no,directories=no,menubar=no,location=no,top=" + WndTop + ",left=" + WndLeft;
		}
		else
		{
			/*
			    If the user is using Netscape then we can pull the info we need
			    using the AWT in Java (provided it is enabled).
			*/
			
			if(navigator.appName=="Netscape" && navigator.javaEnabled())
			{	/*/ center the window /*/

				var toolkit = java.awt.Toolkit.getDefaultToolkit();
				var screen_size = toolkit.getScreenSize();

				// if the screen is smaller than the window, override the resize setting
				if(screen_size.width <= width || screen_size.height <= height) size = "yes";

				WndTop  = (screen_size.height - height) / 2;
				WndLeft = (screen_size.width  - width)  / 2;

				// collect the attributes
				attribs = "width=" + width + ",height=" + height + ",resizable=yes,scrollbars=" + size + "," + 
				"status=no,toolbar=no,directories=no,menubar=no,location=no,top=" + WndTop + ",left=" + WndLeft;
			}
			else
			{	/*/ use the default window position /*/

				// override the resize setting
				size = "yes";

				// collect the attributes
				attribs = "width=" + width + ",height=" + height + ",resizable=yes,scrollbars=" + size + "," + 
				"status=no,toolbar=no,directories=no,menubar=no,location=no";

			}

		}

		// create the window
		popup = open(file, "", attribs);

	}
	else
	{
		// call destroy window
		DestroyWindow();
		// recurse, just once, to display the new window
		CreateWindow(file, width, height, resize);

	}


}

/*  
  FUNCTION 2

  Name: DestroyWindow() 
  Purpose: To Close the popup window
  The window will be replaced by a new popup window
  if the popup is not closed first
*/

function DestroyWindow (txtRegion)
{
	// if a popup window is open, close the window
	if(popup != null)
	{
		popup.close();
		popup=null;
	}
}