/* WindowFactory.js verified 20001025 cm */
function WindowFactory__killKids(par){					/* kill children of a windowfactory, optionally whose opener is par */
	var win;
	for (var w in this.wins){								/* iterate over windows named in this factory */
		win = this.wins[w];									/* get next win */
		if ( win!=par && !win.closed && !win.isIcon ){		/* not the specified parent, not closed and not an icon? */
			if( !par || win.opener == par ){				/* no parent, or parent IS the opener: */
				//win.mother = null; 						/* solve cascade delete in IE: code running as window closing */
				//win.opener = null;						/* mother now eliminated on reload; use opener: but NS prompts. */
				win.isClosing = true;						/* THIS flag solves both issues */
				win.close();								/* finally, close the window (potentially trigger another onUnLoad) */
			}
		}
	}
}
function WindowFactory__iconifyWin(nm,newOpener){		/* iconify optionally as child of another win */
	var win	= this.wins[nm];								/* attempt to get the win by that name */
	if(newOpener){
		win.opener = newOpener;								/* if child of new wf, set opener to that wf's parent win */
	}
	if ( win && !win.isIcon ){								/* if win exists and isn't closed, iconify it: */
		var icon 	= new WindowFactoryIcon(win);			/* must create a 'placeholder' object for iconified window */
		win.close();										/* closed the original window (move to constructor) */
		this.wins[nm] = icon;								/* add icon object in its place */
		this.notify();										/* ultimately notify all observers */
	}
}
function WindowFactory__getWin(url,nm,wfeatures,desc){		/* return (and possibly construct) window with url,name,features, and text description  */
	var win = this.wins[nm];								/* try to get win from factory by name if it exists */
	if ( win && !win.closed && !win.isIcon ){				/* if exists AND not closed AND not iconified: */
		win.focus();											/* must focus first to address IE5 */
		win.location = url;										/* simply reset url */
	}else{													/* win nonexistent, closed, or iconified - requires open() */
		if (!wfeatures){wfeatures = this.defaults;}				/* window features optional, use wf defaults if undefined */
		if (win && !win.closed && win.isIcon){					/* if icon, retrieve those properties needed to reopen the window */
			url			= win.url;								/* override passed url */
			wfeatures 	= win.features;							/* get features of iconized window */
			desc		= win.desc;								/* get description of iconized window */
			win.isIcon	= false;								/* EXPERIMENTAL no longer an icon */
			this.notify();										/* EXPERIMENTAL */
		}
		win = window.open(url, nm, wfeatures);					/* open new win with specified url, name, and features */
		win.windowFactory 	= this;								/* add ref to windowFactory */
		win.mother			= this.mother;						/* ancestor win containing the windowFactory */
		//win.isIcon 			= false;							/* add isIcon property to created window */
		win.features 		= wfeatures;						/* add features property so icons remember */
		win.desc			= desc;
		this.wins[nm] 		= win;								/* assign ref to new win to wf */
	}
	return win;												/* return a handle to the win */
}
function WindowFactory__attach(observer){				/* attach observer */
	this.observers[this.observers.length]=observer;
}
function WindowFactory__detach(observer){				/* detach observer */
}
function WindowFactory__notify(){						/* notify observers (views) */
	for(var o in this.observers){
		this.observers[o].update();
	}
}
function WindowFactory(){								/* WindowFactory constructor */
	this.wins			= new Object();						/* bag of open, closed, or iconified wins */
	this.observers		= new Array();						/* bag of observers */
	this.mother			= window;							/* a reference to the window in which the wf lives (to TOP?) */
	this.defaults 		= "scrollbars=1,resizable=1,width=250,height=300,left=150,top=150";	/* make this a parm, or settable? */

	this.getWin 		= WindowFactory__getWin;			/* assign getWin() */
	this.iconifyWin		= WindowFactory__iconifyWin;		/* assign iconifyWin() */
	this.killKids 		= WindowFactory__killKids;			/* assign killKids() */
	this.notify			= WindowFactory__notify;			/* assign notify() */
	this.attach			= WindowFactory__attach;			/* assign attach() */
	this.detach			= WindowFactory__detach;			/* assign notify() */
}
function WindowFactoryIcon(win){						/* WindowFactoryIcon constructor - create icon from window */
	this.closed 		= false;							/* an icon is NOT closed - closed denotes a win with no other properties */
	this.isIcon 		= true;
	this.name			= win.name;							/* for display if no description */
	this.features		= win.features;						/* must remember original features */
	this.url 			= win.location.href;				/* once a window object is closed this property is gone and can't be set */
	this.desc			= win.desc;							/* description, if provided */
}
/* end WindowFactory definition */