	var lastFocus = "self";

	// subwindow object holders
	if (! windows)
		var windows = new Array();

	function newWindow(url, wname)
	{
		// Constructor for the window
		/* This function should be called to create a new window only from the createWindow function */
		var features = "";
		if (arguments[2] != null)
			features = arguments[2];
		
		return window.open(url, wname, features);	
	}
	function createWindow(url, wname)
	{
		wname = wname.toString();
		url = url.toString();

		if (arguments[2] != null)
			var changeLocation = false;
		else
			var changeLocation = true;
			
		var features = arguments[2] == null ? "" : arguments[2];
		if (!windows[wname] || windows[wname].closed)
			windows[wname] = newWindow(url, wname, features);
		else
		{
			//alert('createWindow');
			//var currentLocation = windows[wname].location.toString();
			//alert('createWindow 1');
			
			//currentLocation = currentLocation.substring(currentLocation.lastIndexOf("/") + 1, currentLocation.length);
			//newLocation = url.substring(url.lastIndexOf("/") + 1, url.length);
			
			//alert('createWindow a');
		
			//if (currentLocation != newLocation) {
			if (changeLocation)
				windows[wname].location = url;
			//}
			//alert('createWindow b');
		}
		if (windows[wname])
			windows[wname].focus();
		else
			alert("A new browser window couldn't be opened. Check that popups are allowed and try again.");
	}
	
	function closeWindows()
	{
		// Close all windows created by createWindow
		/* To close an indivual window its close method should be used. */
		/* This function should be called during the onload event to automatically close all open windows. */
		for (w in windows)
		{
			if (!windows[w].closed)
				windows[w].close();
		}
	}
	
	function closeWindow(wname)
	{
		if (!windows[wname].closed)
			windows[wname].close();
		if (!windows[wname] || windows[wname].closed)
		{
			self.focus();
		}
		else
		{
			if (lastFocus != "self" && !windows[lastFocus].closed)
				windows[lastFocus].focus();
			else
				self.focus();
		}
		lastFocus="self";
	}
	
	


