// JavaScript Document

function trace( input ){
	
	input  =  str_htmlEntities( input );
	
	document.write( "<pre>" );
	document.write( input );
	document.write( "\r\n" );
	document.write( "</pre>" );
	
}


function objToStr( Obj , level , recursionLevel ){
	if( !recursionLevel )  var recursionLevel = 0;
	
	var output = "";
	if( !level )  level = 0;
	
	if( level==recursionLevel )  return "*Max recursion level reached*";
	
	var indent = str_repeat("    ", level);
	
	for(  var i in Obj  ) {
		output += "\r\n";
		switch(   typeof( Obj[i] )    ) {
			case "object":
				output   +=   indent  +  i  +  " = "  +  "["  +  typeof( Obj[i] )  +  "]  {"   ;
				output   +=   objToStr( Obj[i], level+1 , recursionLevel )  ;
				output   +=   "\r\n";
				output   +=   indent + "}" ;
			break;
			case "string":
				output   +=   (  indent  +  i  +  " = \""  +  Obj[i]  +  "\""  );
			break;
			case "undefined":
				output  +=  "undefined"  ;
				break;
			default:
				output   +=   (  indent  +  i  +  " = "  +  Obj[i]  );
		}
	}
	return output;
/*
*/	
}
function deb( Var , recursionLevel){
	if( !recursionLevel )  var recursionLevel = 1;
	
	var output = "";
	var varType = typeof( Var );
	
	output  +=  "<--  Debugger Report: " + varType  ;
	output += "\r\n";

	switch( varType ){
		case "object":
			output  +=  objToStr( Var , 0 , recursionLevel )  ;
			break;
		case "boolean":
			output  +=  Var ? "true" : "false"  ;
			break;
		case "undefined":
			output  +=  "undefined"  ;
			break;
		default:
			output  +=  Var  ;
			break;
			
	}
	output += "\r\n";
	output += "Debugger Report  -->" ;
	
	
	trace( output );
}




function debug(msg) {

    // If we haven't already created a box within which to display

    // our debugging messages, then do so now. Note that to avoid

    // using another global variable, we store the box node as

    // a proprty of this function.

    if (!debug.box) {

        // Create a new <div> element

        debug.box = document.createElement("div");

        // Specify what it looks like using CSS style attributes

        debug.box.setAttribute("style", 

                               "background-color: white; " +

                               "font-family: monospace; " +

                               "border: solid black 3px; " +

                               "padding: 10px;");

        

        // Append our new <div> element to the end of the document

        document.body.appendChild(debug.box);



        // Now add a title to our <div>. Note that the innerHTML property is

        // used to parse a fragment of HTML and insert it into the document.

        // innerHTML is not part of the W3C DOM standard, but it is supported

        // by Netscape 6 and Internet Explorer 4 and later. We can avoid 

        // the use of innerHTML by explicitly creating the <h1> element,

        // setting its style attribute, adding a Text node to it, and 

        // inserting it into the document, but this is a nice shortcut.

        debug.box.innerHTML = "<h1 style='text-align:center'>Debugging Output</h1>";

    }



    // When we get here, debug.box refers to a <div> element into which

    // we can insert our debugging message.

    // First create a <p> node to hold the message.

    var p = document.createElement("p");

    // Now create a text node containing the message, and add it to the <p>

    p.appendChild(document.createTextNode(msg));

    // And append the <p> node to the <div> that holds the debugging output

    debug.box.appendChild(p);

}

