/*
	Popup Class.

	Javascript 1.1

	Author: Toby Boudreaux
	
	Date: 2003.8.13

	Version: 0.1

	USAGE:

		//	instantiate a new popup manager
		var tsp_popUpMan = new TSP_PopUpManager(false, false);

		//	set the defaults
		tsp_popUpMan.setDefaults(400, 300, 1, 0, 'yes', 'no', 'no');

		//	in the link(s) you want to trigger the popup, call:
		tsp_popUpMan.open('index.php', 'tobyjoe');

*/

//	Args:
//		tsp_allowMultiples
//			boolean, whether to allow multiple windows to pop, or to use the same window (if still open)
//		tsp_allowOverrides
//			boolean, whether to override window args passed into the open() call
function TSP_PopUpManager(tsp_allowMultiples, tsp_allowOverrides){
	this._allowMultiples		=	tsp_allowMultiples;
	this._allowOverrides		=	tsp_allowOverrides;
	this._defaults				=	new Object();
	this._wins					=	new Array();
	this._winsCount				=	0;

	//	initial defaults settings
	this._defaults.width			=	800;
	this._defaults.height			=	600;
	this._defaults.title			=	'window';
	this._defaults.toolbar			=	1;
	this._defaults.menubar			=	1;
	this._defaults.scrollbars		=	'yes';
	this._defaults.resizable		=	'yes';
	this._defaults.center			=	1;
}

//	Args:
//		width
//			integer, window width
//		height
//			integer, window height
//		title
//			string, title of new window, unseen
//		toolbar
//			integer boolean, whether to show toolbar
//		menubar
//			integer boolean, whether to show menubar
//		scrollbars
//			string (yes/no), whether to show scrollbars
//		resizable
//			string (yes/no), whether to allow window resizing
//		center
//			integer boolean, whether to center the new window
TSP_PopUpManager.prototype.setDefaults = function(width, height, title, toolbar, menubar, scrollbars, resizable, center){
	this._defaults.width			=	width;
	this._defaults.height			=	height;
	this._defaults.title			=	title;
	this._defaults.toolbar			=	toolbar;
	this._defaults.menubar			=	menubar;
	this._defaults.scrollbars		=	scrollbars;
	this._defaults.resizable		=	resizable;
	this._defaults.center			=	center;
}

//	Args:
//		url
//			url of page you wish to open
//		width
//			width of the new window
//		height
//			height of the new window
//		toolbar
//			integer boolean, whether to show toolbar
//		menubar
//			integer boolean, whether to show menubar
//		scrollbars
//			string (yes/no), whether to show scrollbars
//		resizable
//			string (yes/no), whether to allow window resizing
//		center
//			integer boolean, whether to center the new window
TSP_PopUpManager.prototype.open = function(url, width, height, toolbar, menubar, scrollbars, resizable, center){
	if(this._allowMultiples){
		this._winsCount++;
		title = (this._defaults.title + this._winsCount);
	}else{
		title = this._defaults.title;
	}

	var args = '';
	if(this._allowOverrides){
		var w = width?width:this._defaults.width
		args += 'width=';
		args += w;
		var h = height?height:this._defaults.height;
		args += ',height=';
		args += h;
		args += ',toolbar=';
		args += toolbar?toolbar:this._defaults.toolbar;
		args += ',menubar=';
		args += menubar?menubar:this._defaults.menubar;
		args += ',scrollbars=';
		args += scrollbars?scrollbars:this._defaults.scrollbars;
		args += ',resizable=';
		args += resizable?resizable:this._defaults.resizable;
		if(center || this._defaults.center){
			args += ',left=';
			args += (screen.width - w)/2;
			args += ',top=';
			args += (screen.height - h)/2;
		}
	}else{
		args = 'width='+this._defaults.width+',height='+this._defaults.height+',toolbar='+this._defaults.toolbar+',menubar='+this._defaults.menubar+',scrollbars='+this._defaults.scrollbars+',resizable='+this._defaults.resizable;
		if(this._defaults.center){
			args += ',left=';
			args += (screen.width - this._defaults.width)/2;
			args += ',top=';
			args += (screen.height - this._defaults.height)/2;
		}
	}

	this._wins[this._winsCount] = window.open(url, title, args);
}


//	example usage
//var tsp_popUpMan = new TSP_PopUpManager(true, true);
//tsp_popUpMan.setDefaults(400, 300, 'window', 1, 0, 'yes', 'no', 'no');
