var openedWin = null;
var wpercent = 100;
function launch ()
{
	var args = launch.arguments;
	var url = args[0];
	var width = args[1];
	var height = args[2];
	if (!url || !width || !height)
	{
		alert ("Error");
	}
	else
	{
		var scr_w = screen.availWidth;
		var scr_h = screen.availHeight;
		var target_w = 0;
		var target_h = 0;
		wpercent = 100;
		if (width >= scr_w || height >= scr_h)
		{
			if ((width + 8) >= (height + 27))
			{
				target_w = scr_w - 8;
				wpercent = Math.floor ((target_w * 100) / width);
				target_h = Math.floor ((height * wpercent) / 100) - 27;
				wpercent = Math.floor ((target_h * 100) / height);
				target_w = Math.floor ((width * wpercent) / 100);
				width = target_w;
				height = target_h;
			}
			else if ((height + 27) > (width + 8))
			{
				target_h = scr_h - 27;
				wpercent = Math.floor ((target_h * 100) / height);
				target_w = Math.floor ((width * wpercent) / 100) - 8;
				wpercent = Math.floor ((target_w * 100) / width);
				target_h = Math.floor ((height * wpercent) / 100);
				width = target_w;
				height = target_h;
			}
		}
		_launch (url, width, height);
	}
}
function _launch ()
{
	closeChild ();
	var args = _launch.arguments;
	var url = args[0];
	var width = args[1];
	var height = args[2];
	var resizable = args[3] ? "yes" : "no";
	var scrollbars = args[4] ? "yes" : "no";
	var toolbar = args[5] ? "yes" : "no";
	var menubar = args[6] ? "yes" : "no";
	var status = args[7] ? "yes" : "no";
	var address = args[8] ? "yes" : "no";
	var directories = args[9] ? "yes" : "no";
	var NewX = Math.floor ((screen.availWidth - (width + 8)) / 2);
	if (NewX < 0)
	{
		NewX = 0;
	}
	var NewY = Math.floor ((screen.availHeight - (height + 27)) / 2);
	if (NewY < 0)
	{
		NewY = 0;
	}
	var params = '';
	params += "width=" + width;
	params += ",height=" + height;
	params += ",screenx=" + NewX;
	params += ",screeny=" + NewY;
	params += ",left=" + NewX;
	params += ",top=" + NewY;
	params += ",resizable=" + resizable;
	params += ",scrollbars=" + scrollbars;
	params += ",toolbar=" + toolbar;
	params += ",menubar=" + menubar;
	params += ",status=" + status;
	params += ",location=" + address;
	params += ",directories=" + directories;
	openedWin = window.open (url, "", params);
}
function closeChild ()
{
	if (openedWin != null)
	{
		if (!openedWin.closed)
		{
			openedWin.close ();
		}
	}
}
onunload = closeChild;
