
//Class LittleWindow
//Purpose: 	If it is not open already, opens a browser window (with given URL, name, attributes) and returns a 
//			window object reference. 			
//		If that instance is open already and is blurred or minimized, brings it to focus.
//Author: Raymond Thompson
//Date: 1/30/2001 
//Version: 2.0 (added closeLastWin() function)



//**************************** Global variables ***************************************/

var WindowList;//used in "onMouseUp=" handler in web page to catch returned window object reference
				//ex: onMouseUp=" WindowList =LevelHelp.windowManage(WindowList)" 

//************************ LittleWindow Methods *****************************/

function windowFocus(){
//PRECONDITION: None
//POSTCONDITION: 	If the window does not exist yet or has been closed, it is opened 
//			Otherwise, it is brought to the front (focused)

	if (!this.LittleWindow || this.LittleWindow.closed){	//if this is the first window for the page or the window has been closed
		this.openWindow();									//open or re-open it
	}else{													//Otherwise
		this.LittleWindow.focus();							//bring it to the front
	}
}//end windowFocus
	
function windowManage(WindowList){
//DESCRIPTION: This method makes sure that the user can only open one LittleWindow at a time.
//PRECONDITION: None
//POSTCONDITION:
//		if the window exists and is the same window it is focused
//			if is is not the same window the old one is closed and the new one opened
//		if no window exists, one is opened
//		the object reference for the current window is returned for all cases

	//alert(WindowList);
	//alert(this.WindowName);

	
	if (WindowList){							//if this is not the first window open for the page
		if(WindowList == this.LittleWindow){	//if they have tried to open the same window again
				if(!WindowList.closed){			//if they have not closed that window 
					this.LittleWindow.focus();	//bring it to the front
				}else{							//otherwise
					this.openWindow();			//re-open it
				}
		}else{									//if they are opening a different window
			if(!WindowList.closed){				//if the last window isn't already closed
				WindowList.close();				//close it first
			}									//then
			this.openWindow();					//open the new window
		}	
	}else{										//if this is the first window for the page
		//if (WindowList != this.LittleWindow){		//if window name is not recognized
			//WindowList = this.LittleWindow;		//set window name to current window name			
			this.openWindow();					//open it
		//}						

	}
	return this.LittleWindow;					//return the current window object
}//end windowManage

function openWindow(){
//PRECONDITION: None
//POSTCONDITION: 	Window is opened with parameters passed to constructor during creation of instance
//			 		LittleWindow property is set to the window object reference
	this.LittleWindow = window.open(this.URL, this.WindowName, this.Attributes);
}//end openWindow

function closeWindow(){
//PRECONDITION: None
//POSTCONDITION: 	Window is closed
	if (this.LittleWindow){
		this.LittleWindow.close();
	}
}//end closeWindow

/****************** LittleWindow Constructor ****************************************/

function LittleWindow(URL, WindowName, Attributes){
//PRECONDITION: 	URL must be a string
//			WindowName must be a string with no spaces or special characters
//			Attributes must be a string
//POSTCONDITION: instance of LittleWindow object is created with given parameters

	//properties
	this.LittleWindow = null;
	this.URL = URL;
	this.WindowName = WindowName;
	this.Attributes = Attributes;
	

	//methods
	this.windowManage = windowManage;
	this.windowFocus = windowFocus;
	this.openWindow = openWindow;
	this.closeWindow = closeWindow;
	//this.closeLastWin = closeLastWin;
}





