//<script language="javascript">
/////////////////////////////////////////////////////////////
//
// popup - implement a pop up message window class
// Copyright (c) 2000 by Bob Clary, All Rights Reserved
//
/////////////////////////////////////////////////////////////

registerFile('popup.js', 'oop.js');

_classes.registerClass('MessageWindow');

function MessageWindow(id, message)
{
	_classes.defineClass('MessageWindow', _prototype_func);
	
	this.init(id, message);
	
	function _prototype_func()
	{
		MessageWindow.prototype.init = init;
		function init(id, message)
		{
			var features = 'height=130,width=130,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes';

			this.id		= id;
			this.wnd	= window.open('', 'popup_' + id, features);
			
			if (!this.wnd)
				return;
			
			// mozilla throws an exception componet has no such interface
			//this.wnd.focus();

			// note mozilla won't display the message when writing to the 
			// document but will do so 'belatedly' when using innerHTML
			// closing the message window's document helps somewhat.
			// it appears the text isn't rendered until the opening window
			// finishes loading.
			var s = '';
			s += '<html>';
			s += '<body style="background-color: white; padding: 10px; margin: 0px; padding: 0px;">';
			s += '<div style="padding: 10px;">';
			s += message;
			s += '</div>';
			s += '</body></html>';
			this.wnd.document.write(s);
			//this.wnd.document.body.innerHTML = s;
			this.wnd.document.close();
		}
		
		
		MessageWindow.prototype.close = close;
		function close()
		{
			if (!this.wnd || this.wnd.closed)
				return;
				
			// mozilla throws an exception componet has no such interface
			//this.wnd.blur();
			// mozilla throws an exception componet has no such interface
			this.wnd.close();
			//window.focus();
		}
	}
}

_classes.registerClass('PopupWindow');

function PopupWindow(id, message)
{
	_classes.defineClass('PopupWindow', _prototype_func);
	
	this.init(id, message);
	
	function _prototype_func()
	{
		PopupWindow.prototype.init = init;
		function init(id, message)
		{
			this.id = id;
			
			div = document.getElementById('popup_' + id);
		
			if (!div)
			{
				if (document.body)
				{
					div							= document.createElement('div');
					div.id						= 'popup_' + id;
					div.style.position			= 'absolute';
					div.style.visibility		= 'visible';
					div.style.zIndex			= -1;
					div.style.backgroundColor	= '#d6d6ce';
					div.style.padding			= '10px';
					div.style.borderTop			= '#808080 4px solid';
					div.style.borderRight		= '#f0f0f0 4px solid';
					div.style.borderBottom		= '#f0f0f0 4px solid';
					div.style.borderLeft		= '#808080 4px solid';

					document.body.appendChild(div);
				}

				var bodyHeight; 
				var bodyWidth;
					
				if (is_ie5 || document.body.offsetWidth)
				{
					bodyHeight = document.body.offsetHeight;
					bodyWidth  = document.body.offsetWidth;
				}
				else
				{
					bodyHeight = document.width;
					bodyWidth  = document.height;
				}
			
				div.innerHTML = message;
		
				if (div.offsetWidth > bodyWidth)
					div.style.width = bodyWidth;
					
				if (div.offsetHeight > bodyHeight)
					div.style.height = bodyHeight;
					
				div.style.left	= (bodyWidth  - div.offsetWidth)/2;
				div.style.top	= (bodyHeight - div.offsetHeight)/2;

			}
			
			
			div.style.zIndex		= 1;
			div.style.visibility = 'visible';
		}
		
		PopupWindow.prototype.close = close;
		function close()
		{
			var div = document.getElementById('popup_' + this.id);
			if (!div)
				return;
					
			div.style.zIndex		= -1;
			div.style.visibility	= 'hidden';
		}
	}
}

//</script>
