// Declare popup windows array
var	popupWin = new Array;

// Constructor function	to create miniwin object
function popupWinObject(winUrl,winName,winWidth,winHeight,winScrollbars,winRef,winFeatures)
{
	this.winUrl = winUrl;
	this.winName =	winName;
	this.winWidth = winWidth;
	this.winHeight	= winHeight;
	this.winScrollbars	= winScrollbars;
	this.winRef = winRef;
	this.winFeatures =	winFeatures;
}

function popupWindow(winUrl,winName,width,height,scrollbars)
{
	var	winNum	= popupWin.length;
	var	found =	false;

	for	( var num=0; num<popupWin.length; num++	) {
		if ( winUrl == popupWin[num].winUrl && winName == popupWin[num].winName )	{
			winNum	= num;
			found =	true;
			break;
		}
	}

	if ( !found	) {
		popupWin[winNum] =	new	popupWinObject	(winUrl,winName,width,height,scrollbars,null,""	);
	}

	var	mw = popupWin[winNum];

	// If mini window exists
	if ( remote_window_open(mw.winRef)	== true) {
		// Bring existing window to	top
		mw.winRef.focus ();
		return ( mw.winRef	);
	}

	mw.winFeatures	= mini_window_features(mw.winWidth,mw.winHeight,mw.winScrollbars);
	mw.winRef = window.open(mw.winUrl,mw.winName,mw.winFeatures);

	return (mw.winRef);
}

function mini_window_features(width,height,scrollbars)
{

	if ( typeof(scrollbars)	== "string") {
		scrollbars = scrollbars.toLowerCase();
		if ( scrollbars	!= "no"	) {
			scrollbars = "yes";
		}
	} else if (typeof(scrollbars) == "boolean")	{
		scrollbars = ( scrollbars == true )	? "yes"	: "no";
	} else if (typeof(scrollbars) == "number") {
		scrollbars = (scrollbars>0)	? "yes":"no";
	} else {
		scrollbars = "yes";
	}

	var	winFeatures = "directories=no";
	winFeatures +=	",height=" + height;
	winFeatures +=	",width=" +	width;

	if ( document.all || document.layers ||	document.getElementById	) {
		winFeatures +=	",top="	+ (	( screen.height	- height ) / 2 - 10	);
		winFeatures +=	",left=" + ( ( screen.width	- width	) /	2 +	1 );
	}
	winFeatures +=	",location=no";
	winFeatures +=	",menubar=no";
	winFeatures +=	",scrollbars=" + scrollbars;
	winFeatures +=	",status=no";
	winFeatures +=	",toolbar=no";
	winFeatures +=	",resizable=no";

	return (winFeatures);
}

// Check if remote window is open
function remote_window_open(window_reference)
{
	if ( window_reference != null && window_reference.closed ==	false )
		return ( true );

	return ( false );
}
