//***********************************************************************************************
//  Windows 1.00  --  This notice must remain untouched at all times.
//  Copyright Alfred Kaliwoda 2002. All rights reserved. (POLAND)
//  http://www.alfs.prv.pl
//  Last modified: 20-03-2002.
//***********************************************************************************************
//  This script can be use by free and commercial
//  Only one condition is don't remove this comment
//  In case of modification of script must be paste note about changes
//***********************************************************************************************
//  Windows 1.00  --  Ten tekst nie może być usuwany.
//  Prawa autorskie: Alfred Kaliwoda 2002. Wszystkie prawa zastrzeżone. (POLSKA)
//  http://www.alfs.prv.pl
//  ostatnia modyfikacja: 20-03-2002.
//***********************************************************************************************
//  Skrypt ten może być używany zarówno w produktach darmowych, jak i komercyjnych
//  Jedynym warunkiem jest pozostawienie całego tego komentarza
//  W przypadku modyfikacji skryptu, należy pod tym komentarzem zamieścić adnotacje o zmianach
//***********************************************************************************************

function AutoScrollBars(pWindow)
{
	var wndBorderWidth = 4;
	var wndBordersFullWidth = wndBorderWidth*2;
	
	var i = 0;
	var vOldSize = 0;
	
	i = 0;
	while ((pWindow == null) && (i++ < 1000));
	
	if (pWindow == null)
	{
		return;
	}
	
	i = 0;
	while ((pWindow.document == null) && (i++ < 1000));
	
	if (pWindow.document == null)
	{
		return;
	}
	
	i = 0;
	while ((pWindow.document.body == null) && (i++ < 1000));
	
	if (pWindow.document.body == null)
	{
		return;
	}
	
	pWindow.moveTo(0, 0);
	
	if (pWindow.document.body.offsetWidth > screen.Width)
	{
		pWindow.resizeTo(screen.Width, pWindow.document.body.offsetHeight + wndBordersFullWidth);
	}
	
	if (pWindow.document.body.offsetHeight > screen.Height)
	{
		pWindow.resizeTo(pWindow.document.body.offsetWidth + wndBordersFullWidth, screen.Height);
	}
	
	if ((pWindow.document.body.offsetWidth < screen.Width) &&
		(pWindow.document.body.clientWidth + wndBordersFullWidth < pWindow.document.body.scrollWidth))
	{
		pWindow.resizeBy(pWindow.document.body.scrollWidth - pWindow.document.body.clientWidth, 0);
	}
	
	if ((pWindow.document.body.offsetHeight < screen.Height) &&
		(pWindow.document.body.clientHeight + wndBordersFullWidth < pWindow.document.body.scrollHeight))
	{
		pWindow.resizeBy(0, pWindow.document.body.scrollHeight - pWindow.document.body.clientHeight);
	}
	
	if (pWindow.document.body.offsetWidth > screen.Width)
	{
		pWindow.resizeTo(screen.Width, pWindow.document.body.offsetHeight + wndBordersFullWidth);
	}
	
	if (pWindow.document.body.offsetHeight > screen.Height)
	{
		pWindow.resizeTo(pWindow.document.body.offsetWidth + wndBordersFullWidth, screen.Height);
	}
}

function OpenWindow(pURL, pName, pWidth, pHeight, pScrollbars, pToolbar, pResizeable, pLeft, pTop)
{
	var vWindow = null;
	
	if (pScrollbars == null)
	{
		pScrollbars = "yes";
	}
	
	if (pToolbar == null)
	{
		pToolbar = "no";
	}
	
	if (pResizeable == null)
	{
		pResizeable = "no";
	}
	
	if (pLeft == null)
	{
		pLeft = "0";
	}
	
	if (pTop == null)
	{
		pTop = "0";
	}
	
	vWindow = window.open(pURL ,pName, "width=" + pWidth + ",height=" + pHeight + ",toolbar=" + pToolbar + ",resizable=" + pResizeable + ",scrollbars=" + pScrollbars + ",left=" + pLeft + ",top=" + pTop);
	
	return (vWindow);
}

function OpenWindowAuto(pURL, pName, pWidth, pHeight)
{
	var vWindow = null;
	
	var vScrollbars = "yes";
	var vToolbar = "no";
	var vResizeable = "no";
	
	pWidth = Number(pWidth);
	pHeight = Number(pHeight);
	
	if ((pWidth >= 1024) || (pHeight >= 1024))
	{
		vScrollbars = "yes";
	}
	else
	{
		vScrollbars = "no";
	}
	
	vWindow = OpenWindow(pURL, pName, pWidth, pHeight, vScrollbars, vToolbar, vResizeable, 0, 0);
	
	AutoScrollBars(vWindow);
	
	return (vWindow);
}
