/*******************************************************************
*
* File    : debug.js
*
* Created : 2000/08/16
*
* Author  : Roy Whittle  (Roy@Whittle.com) www.Roy.Whittle.com
*
* Purpose : To create a debug window that can be used to output
*		trace & debug information without using alerts which
*		cause execution to stop. Initialy created to help
*		debug navbuddy.
*
* History
* Date         Version        Description
*
* 2000-08-16	1.0		Initial version
* 2000-08-17	1.1		Added enter2 & displayObj & indentation
***********************************************************************/

function openDebugWin(w,h)
{
      var dw = window.open("","dbwin","width="+w*8.5+",height="+h*17.5);

	var str="<html><head><title>Debug Window</title><body bgcolor='black' text='white link='yellow'><form NAME='frm'><textarea name='txt' cols='"+w+"' rows='"+h+"'></textarea></form></body></html>"

	dw.document.write(str);
	dw.document.close();
	return dw;
}


function DebugWindow(w,h)
{
	if(!w)w=60;
	if(!h)h=20;
	this.dbWin = openDebugWin(w,h);
	this.offset="";
}
function fName(func)
{
	var str;

	str=func.toString().match(/function (\w*)/)[1];
	if(!str || str=="") str="anon";

	return(str);
}
DebugWindow.prototype.out = function(str)
{
	if(this.dbWin.closed)
		this.dbWin = openDebugWin(60,20);

	this.dbWin.document.frm.txt.value += this.offset + str + "\n";
	this.dbWin.focus();
}

DebugWindow.prototype.enter = function()
{
	this.out("<Enter>:"+fName(arguments.caller.callee) );
	this.offset += "    ";
}
DebugWindow.prototype.enter2 = function()
{
	var str=arguments.caller[0];
	for(i=1 ; i<arguments.caller.length ; i++)
		str += "," + arguments.caller[i];

	this.out("<Enter2>:"+fName(arguments.caller.callee)+"("+str+")" );
	this.offset += "    ";
}
DebugWindow.prototype.exit = function()
{
	if(this.offset.length > 3)
		this.offset = this.offset.slice(4);
	this.out("<Exit >:"+fName(arguments.caller.callee) );
}
DebugWindow.prototype.displayObjFull = function(obj)
{
	for(i in obj)
		this.out(i+"=["+obj[i]+"]");
}
DebugWindow.prototype.displayObj = function(obj)
{
	for(i in obj)
		if(obj[i].toString().indexOf("function") == -1)
			this.out(i+"=["+obj[i]+"]");
}

