/******************************************************************************
 * Class used for debugging javascript
 * use it like this:
 * 
 * 	var dw = new DebugWindow();
 * 	dw.openWindow();
 * 	dw.debug( "This is a test" );
 * 
 * The output for the above would look something like:
 * 
 * 	Thursday, July 14, 2005 11:47:23: This is a test
 * 
 *****************************************************************************/

var debugWindowCollection = new Object();

function getDebugWindow( name ) {
	if( debugWindowCollection[ name ] ) {
		return debugWindowCollection[ name ];
	} else {
		return new DebugWindow();
	}
}

function DebugWindow( name ) {

	if( name ) {
		if( debugWindowCollection[ name ] ) {
			return debugWindowCollection[ name ];
		}
	} else {
		name = "window_" + Math.random() * 0xffe543;
	}
	this.name = name;

	this.openWindow = function() {
		this.win = window.open( "", "debugwindow", "width=500, height=400, resizable=yes, scrollbars=yes" );
		this.win.opener = window;
		this.initWindow();
	};

	this.closeWindow = function() {
		this.win.close();
	};

	this.initWindow = function() {
		this.win.document.open();
		this.win.document.write( "<html><head><title>Debug Window</title></head><body bgcolor='black'><span style='font-family: courier new; font-size: 12px; color: #eeeeee; white-space: nowrap;'>" );
	};

	this.deInitWindow = function() {
		this.win.document.write( "</style></body></html>" );
		this.win.document.close();
	};

	this.setPrefix = function( pre ) {
		this.prefix = pre;
	};
	
	this.clearPrefix = function() {
		this.prefix = null;
	};

	this.debug = function( msg ) {
		var date = new Date();
		this.win.document.write( date.toLocaleString() + ": " );
		if( this.prefix ) {
			this.win.document.write( this.prefix );
		}
		this.win.document.write( msg );
		this.win.document.write( "<br />" );
	};

	return this;
}