/*****************************************************************************************
 * SVN-Version-information:
 * ------------------------
 * $LastChangedRevision: 4170 $
 * $LastChangedBy: nils $
 * $LastChangedDate: 2008-02-07 09:32:25 +0100 (Do, 07 Feb 2008) $
 * $HeadURL: svn://10.72.51.50/DevFSFS/php5/lib/trunk/javascript/StickyPopup.js $
 *****************************************************************************************/

//browsers
var ie=document.all;

/**
 * class for a popup that sticks on top until it is closed.
 * TODO: test in other browsers - only tested in firefox 2 and internet explorer 7 .
 */
function StickyPopup(url, framename, width, height, scrollbars) /* class */
{
	var settings;
	settings = "dependent=yes,top=20,left=20,scrollbars="+ (scrollbars ? "yes" : "no") + 
				",location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	
	if(width)
		settings += ",width="+width;
	if(height)
		settings += ",height="+height;

	var winHandle=window.open(url, framename, settings);

	winHandle.focus();

	window.onfocus = function ()
	{
		if(!winHandle) 
		{
			return;
		}
		if(winHandle.closed)
		{
			winHandle = null;
		 	return;
		}
		if(ie)
			winHandle.focus();
		else 
			this.blur();
	};
	var onUnloadFunc;
	if(!ie)
	{
		winHandle.onbeforeunload = function()
		{
			winHandle.onbeforeunload = null;
			winHandle.onfocus = null;
			winHandle = null;
		  	if(onUnloadFunc)
			  	eval(onUnloadFunc);
			onUnloadFunc = null;
		};
	}
	

	this.setOnUnload = function(onUnload)
	{
		onUnloadFunc = onUnload;
	}
	
	this.close = function()
	{
		winHandle.document.getElementById('content').innerHTML = "Fenster kann geschlossen werden.";
		//winHandle.onbeforeunload = null;
		winHandle.onfocus = null;
		winHandle.close();
		if(onUnloadFunc)
		  	eval(onUnloadFunc);

		winHandle = null;
		onUnloadFunc = null;
		//winHandle.focus();
	}
}
