/* Script to open a popup window */

var newWindow = null;

// This function will work only with a special script page that handles the close button
function openNewWindow(page, width, height)
{
	var wsize;

	if (width == 0 && height == 0)
		wsize = "toolbar=0,scrollbars=1,status=0,menubar=0,resizable=1";
	else
		wsize = "toolbar=0,scrollbars=0,status=0,menubar=0,resizable=0,width="+width+",height="+height;

	if (newWindow)
		newWindow.close();

	newWindow = window.open(page,"",wsize);
	newWindow.window.focus();
}

function closeNewWindow()
{
	if (newWindow)
		newWindow.close();

	newWindow = null;
}

function destroyNewWindow()
{
	newWindow = null;
}

// This is a standard new window without creating window object
function openPageInNewWindow(page, width, height)
{
	var wsize;

	if (width == 0 && height == 0)
		wsize = "toolbar=0,scrollbars=1,status=0,menubar=0,resizable=1";
	else
	{
		var adjust_size = 0;

		if (height > screen.availHeight)
		{
			height = screen.availHeight;
			adjust_size = 1;
		}

		if (width > screen.availWidth)
		{
			width = screen.availWidth;
			adjust_size = 1;
		}

		if (adjust_size == 1)
			wsize = "toolbar=0,scrollbars=1,status=0,menubar=0,resizable=1,width="+width+",height="+height;
		else
			wsize = "toolbar=0,scrollbars=0,status=0,menubar=0,resizable=0,width="+width+",height="+height;
	}

	win = window.open(page,"Picture",wsize);
	win.window.focus();
}

// Open a new instance of browser
function createWindow(page)
{
	var xWin = window.open(page, "NowyDomArizona", "");
}
