/****************************************************************************
A simple popup debug output window for JavaScript.   Author: Jennifer Palonus
                                                     Graphical Dynamics, Inc.
I assume there are better ones out there.

TO USE:
1. Create a new DebugLogger object. 

2. Call write, writeln, or writep, supplying it with the string to output.

 Date	Who	Changes
------- --- -----------------------------------------------------------------
29jan08	jlp	Created.
08feb08		
****************************************************************************/


/****************************************************************************
Constructor.

dbg = new DebugLogger ([show=true]);
****************************************************************************/
function DebugLogger ()
	{
	this.showWindow = arguments.length>0 ? arguments[0] : true;
	
	if (this.showWindow)
		{
		this.window = window.open ("", "DebugLogger", "width=500,height=900,left=20, resizable,scrollbars");
		this.doc = this.window.document;
//		this.doc.body.style.fontFamily = "Lucida Console,Courier,Monospace";
//		this.doc.body.style.fontSize = "8pt";
		this.doc.writeln ("<pre>\r\n");
		}
	}
	
/****************************************************************************
write (msg);

Writes out some text to the debug window, without adding a new line.
****************************************************************************/
DebugLogger.prototype.write = function (p_sText)
	{
	var sText;
	
	// Sanity checks.
	if (!this.doc)
		{return;
		}
	
	if (this.showWindow)
		{
		p_sText = p_sText.replace (" ", "&nbsp;");
		this.doc.write (p_sText);
//alert ("innerHTML="+this.doc.body.innerHTML);
		
		if (this.doc.body.scrollIntoView)
			{this.doc.body.scrollIntoView (false);
			}
		}
	}
	
/****************************************************************************
writeln (msg);

Writes out a line of text to the debug window. (Adds a <br> to the end.)
****************************************************************************/
DebugLogger.prototype.writeln = function (p_sText)
	{
	var sText;
	
	// Sanity checks.
	if (!this.doc)
		{return;
		}
	
	if (this.showWindow)
		{
		p_sText = p_sText.replace (" ", "&nbsp;");
		this.doc.writeln (p_sText);
		
		if (this.doc.body.scrollIntoView)
			{this.doc.body.scrollIntoView (false);
			}
		}
	}
	
/****************************************************************************
writep (msg);

Writes out a line of text to the debug window inside a <p>.
****************************************************************************/
DebugLogger.prototype.writep = function (p_sText)
	{
	var sText;
	
	// Sanity checks.
	if (!this.doc)
		{return;
		}
	
	if (this.showWindow)
		{
//		p_sText = p_sText.replace (" ", "&nbsp;");
		this.doc.writeln (p_sText + "\r\n");
		
		if (this.doc.body.scrollIntoView)
			{this.doc.body.scrollIntoView (false);
			}
		}
	}
	

