// Allows one to execute some JavaScript on the fly from the debug window.
function execute(code)
	{
	with (top)
		{ debug(eval(code)); }
	}

function debug(statement,debug_level)
	{
	// If the window is undefined or was closed, create it and write some header info
	if ( (typeof(debug_window) == 'undefined')  || ( (typeof(debug_window) == 'object') && (typeof(debug_window.document) != 'object') ) )
		{
		debug_window = window.open("","debug_window","width=350,height=300,resizable,scrollbars,status");
		debug_window.document.write("<head>\n<title>Debug</title>\n<style type='text/css'>\nbody {font-family: Arial; font-size: 8pt;}\n.time {font-family: Arial; font-size: 8pt;}\n.debug {font-family: Arial; font-size: 8pt;}\n.bold {font-family: Arial; font-size: 8pt; font-weight: bold;}\n.small {font-family: Arial; font-size: 8pt;}\n</style>\n</head>\n\n");
		debug_window.document.write("<form name='debugForm'><input type='text' class='small' name='debugCode'><input type='button' value='debug' onclick='window.opener.execute(debugCode.value)' class='small'></form>");
		debug_row_color = ["#FFFFFF","#D0D0D0","#66CCFF","#CCFFCC","#FFFFCC","#FF9999","#FFCC99","#CCCCFF"];
		debug_count = 0;
		}
		
	// Update a count of the debug statments to alternate color
	debug_count++;
	
	// Setup time stamp for debug statment
	var this_date = new Date();
	var this_time = this_date.getHours() + ":" + this_date.getMinutes() + ":" + this_date.getSeconds() + ":" + this_date.getMilliseconds();
	
	// Choose color for the row
	if ( (typeof(debug_level) != 'undefined') && (debug_level != null) && (parseInt(debug_level) >= 0))
		{ this_row_color = debug_row_color[parseInt(debug_level) % debug_row_color.length]; }
	else
		{ this_row_color = debug_row_color[(debug_count % 2)]; }
	
	// Write table header
	debug_window.document.write("<table cellpadding='0' cellspacing='0'><tr bgcolor='" + this_row_color + "'><td width='75' class='time' valign='top'>" + this_time + "&nbsp;&nbsp;</td><td class='debug'>");
	
	// If we're debugging an object, loop through and display all properties
	if ( typeof(statement) == 'object' )
		{
		var obj_properties = "";
		
		if ( typeof(statement.name) != 'undefined')
			{ obj_properties += "\n<tr><td class='bold'>Object Name</td><td class='bold'>" + statement.name + "</td></tr>"; }
		
		for (var property in statement)
			{
			var property_value = ( property.indexOf("data") != 0 ) ? statement[property] : "[Unable to display]";
			obj_properties += "\n<tr><td>" + property + "</td><td>" + property_value + "</td></tr>";
			}
		debug_window.document.write("\n<table cellpadding='0' cellspacing='0' border='1' class='debug'>" + obj_properties + "\n</table>\n");
		}
	else
		{ debug_window.document.write(statement); }
		
	// Write table footer
	debug_window.document.write("</td></tr></table><hr width='100%'>\n");
	}
	
// if ( top.location.href.indexOf("debug=true") >= 0 )
//	{ debug("<b>" + self.name + "</b><br />" + self.location.href,7); }
