/*
	file name 	:	popup.js
	
 	Open a popup browser window, optionaly writes specified html/text in the window

 	Author		: 	Svilen Ivanov - Studio VISIA Inc.
 	Revision	: 	1.1;

	Date		:	2001/05/10
*/

var handle = null;

function Popup (name, url, width, height, scrollbars, resizable, left,
				top, menubar, toolbar, loc_bar, statusbar, directories) {
	var html = "";
	if (!url.indexOf ("WRITE_HTML"))	{	
		url = url.substr (10);
		html = url;
		url = '';
	}
	var xcen, ycen;						// center coordinates
	var nn		= document.layers?1:0;	// browser detection

	width	=	width	?	width	:	300;			// create default values
	height	=	height	?	height	:	300;			// for window's width and height
	xcen	=	(screen.availWidth - width) / 2;		// center the new
	ycen	=	(screen.availHeight - height)	/ 2;	// window on the screen

	// create window.open() parameters and default values
	directories	=	directories	?	',directories=yes'		:	',directories=no';
	loc_bar		=	loc_bar		?	',location=yes'			:	',location=no';
	statusbar	=	statusbar	?	',status=yes'			:	',status=no';
	toolbar		=	toolbar		?	',toolbar=yes'			:	',toolbar=no';
	menubar		=	menubar		?	',menubar=yes'			:	',menubar=no';
	resizable	=	resizable	?	',resizable=yes'		:	',resizable=no';
	scrollbars	=	scrollbars	?	',scrollbars=yes'		:	',scrollbars=no';
	width		=	width		?	( 'width='   + width  )	:	'width=300';
	height		=	height		?	( ',height=' + height )	:	',height=300';
	left		=	left		?	( ( nn ? ',screenX=':',left=' ) + left ) : ( ( nn ?',screenX=':',left=' ) + xcen );
	top		=	top 		?	( ( nn ? ',screenY=':',top='  ) + top  ) : ( ( nn ?',screenY=':',top='  ) + ycen );


	if (handle && handle.name == name) {
//		handle.wnd.close();
	} else {
		handle = new Object();
	}
	
	handle.wnd = window.open	(	url, name, width + height + scrollbars + resizable +
									left + top + menubar + toolbar + loc_bar + statusbar +
									directories 
								);
	handle.name = name;
	handle.wnd.focus(); // always set focus on the new window
	if (url == '')	{
		handle.wnd.document.write (html);
		handle.wnd.document.close ();
	}
	
}