// JavaScript Document
var tracedepth=0;
var max_trace_depth=0;

function debug(msg) {
	if (debug.arguments.length==2) {
		msg="<textarea rows=10 cols=20 style='width:600px;height:360px'>"+msg.escapeHTML()+"</textarea>";
	}
	try {
		if (typeof w == "undefined" || w.closed) {
			w=window.open('','w','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=640,height=400');
			w.moveTo(screen.availWidth-640, 0);
		}
		w.document.write(msg+"<br>");
	}
	catch (e) {
		try{ $('debug_container').innerHTML += msg+"<br>"; }
		catch(e) {
			var div=document.createElement('div');
			div.id='debug_container';
			div.innerHTML=msg+'<br />';
			document.body.appendChild(div);
		}
	}
}
function trace(o) {
	var out="";
	var nofunctions = (trace.arguments.length>1 && trace.arguments[1]);
	var onlynumbers = (nofunctions && trace.arguments[1] == 2);
	var do_return  = (trace.arguments.length>2 && trace.arguments[2]);
	
	try {
		for (z in o) {
			try {
				if (o[z]!="" && o[z]!=null)
					if (onlynumbers && typeof o[z] != "number") {
						continue;
					}
					if (z.indexOf("HTML")!=-1) out+=z+" = [..HTML-Code..]; <br>\n";
					if (typeof o[z] == "function" && nofunctions) {
						out += z+": [..Function..]<br>\n";
						continue;
					}
					if (typeof o[z] == "object") {
						out += z+" : {<div style='margin-left: 20px'>";
						if (++tracedepth>max_trace_depth || z.indexOf('parent')!=-1 || z.indexOf('own')!=-1) out += " [ object ] ";
						else out += trace(o[z], nofunctions, true);
						tracedepth--;
						out += "</div>}<br>";
					}
					else out+=z+" = "+o[z]+"; <br>";
			}
			catch(e) {
				out+="<i>Fehler in "+z+": "+e+"</i><br />\n";
			}
		}
	}
	catch(ee) {
		out+="<b>Fatal Error in tracing: "+ee+"</b>";
	}
	if (do_return) return out;
	else debug(out)
}
