/*
 * $Header: /Engine/debug.js   1   2004-07-27 16:36:00+02:00   eruis $
 * Created on:      15-April-2004
 * Original author: Eric Ruis
 *
 * Description:
 *	Implements a debug console window to which debug messages can be written
 *	if the debugWindow property debug is set to true.
 */
var _dbgConsole = null;

function dbg_openWindow() {
	if (_dbgConsole == null) {
		_dbgConsole = window.open("", "console", "width=600,height=300,resizable,scrollbars");
		_dbgConsole.document.open("text/plain");
	}
	// Note that we purposely do not call close(). Leaving the document window
	// open allows us to append to it later.
}

function dbg_write(msg) {
	if (this.debug) {
		try {
			dbg_openWindow();
			_dbgConsole.document.write(msg);
			_dbgConsole.scrollBy(0, 50)
		} catch (E) {
			// debug window not valid anymore. Retry with a new window.
			_dbgConsole = null;
			dbg_openWindow();
			_dbgConsole.document.write(msg);
			_dbgConsole.scrollBy(0, 50)
		}
	}
}

function dbg_writeline(msg) {
	if (this.debug) {
		try {
			dbg_openWindow();
			_dbgConsole.document.writeln(msg);
			_dbgConsole.scrollBy(0, 50)
		} catch (E) {
			// debug window not valid anymore. Retry with a new window.
			_dbgConsole = null;
			dbg_openWindow();
			_dbgConsole.document.write(msg);
			_dbgConsole.scrollBy(0, 50)
		}
	}
}

function debugWindow_setup() {
	// properties
	this.debug = false; // set this property to true to see debug messages

	// methods
	this.write = dbg_write;
	this.writeln = dbg_writeline;

	return this;
}

var debugWindow = new Object();
debugWindow = debugWindow_setup();