var popupWindow;

function newWindow(page, size) 
{
	/*
	newWindow(page, [size, [option1,option2..optionN]);

	option MAY TAKE THE FOLLOWING PARAMETERS:
	'toolbar'
	'menubar'
	'location'
	'status'
	'scrollbars'
	'resize'
	'directories'
	*/

	// *** window feature defaults (0 = Off, 1 = On)

	var toolbar	= 0;
	var menubar	= 0;
	var location	= 0;
	var status	= 0;
	var scrollbars	= 0;
	var resizable	= 0;
	var directories	= 0;

	// *** window width & height settings for each numbered size, and default size

	switch(size)
	{
		case 1:
			width=850;
			height=700;
			break;
		case 2:
			width=650;
			height=400;
			break;
		case 3:
			width=650;
			height=570;
			break;
		case 4:
			width=600;
			height=600;
			break;
		default:
			width=400;
			height=400;
	}	


	// *** do not modify past this point

	var args = newWindow.arguments;
		
	for (var i=isNaN(args[1]) ? 1 : 2; i<args.length; i++) {
		switch(args[i])
		{
			case "toolbar":
				toolbar = 1;
				break;
			case "menubar":
				menubar = 1;
				break;
			case "location":
				location = 1;
				break;
			case "status":
				status = 1;
				break;
			case "scrollbars":
				scrollbars = 1;
				break;
			case "resize":
				resizable = 1;
				break;
			case "directories":
				directories = 1;
		}
	}

	var x = (640 - width)/2;
	var y = (480 - height)/2;

	if (screen)
	{
		y = (screen.availHeight - height)/2;
		x = (screen.availWidth - width)/2;
	}

	var features =
        'width='	+ width +
        ',height='	+ height +
        ',screenX='	+ x +
        ',screenY='	+ y +
        ',left='	+ x +
        ',top='		+ y +
        ',directories='	+ directories +
        ',location='	+ location +
        ',menubar='	+ menubar +
        ',scrollbars='	+ scrollbars +
        ',status='	+ status +
        ',toolbar='	+ toolbar +
        ',resizable='	+ resizable;

	popClose();
	popupWindow = window.open(page, 'popupWindow', features);

	//if (popupWindow.resizeTo)
	//{
	//	popupWindow.resizeTo(width,height);
	//}
}

function popClose() {
	if (popupWindow != null) {
  		if (!popupWindow.closed) {
  			popupWindow.close();
			return false;
  		}
	}
}

