var Debug = {
	debugOutput: null,
	specialchars: function (str) {
		str = str.replace(/&/g, '&amp;');
		str = str.replace(/</g, '&lt;');
		str = str.replace(/>/g, '&gt;');
		str = str.replace(/"/g, '&quot;');
		str = str.replace(/'/g, '&#039;');
		return str;
	},
	clear: function() {
		this.debugOutput.innerHTML = "";
	},
	init: function(outputNode) {
		if (typeof(outputNode) != "undefined") {
			this.debugOutput = outputNode;
		}
	},
	output: function(msg, clearfirst) {
		if (this.debugOutput != null) {
			if (clearfirst) {
				this.debugOutput.innerHTML = this.specialchars(msg) + "<br />";
			} else {
				this.debugOutput.innerHTML += this.specialchars(msg) + "<br />";
			}
		}
	},
	outputLiteral: function(msg, clearfirst) {
		if (this.debugOutput != null) {
			if (clearfirst) {
				this.debugOutput.innerHTML = msg + "<br />";
			} else {
				this.debugOutput.innerHTML += msg + "<br />";
			}
		}
	},
	showProperties: function(obj, maxdepth, depth, parent) {
		if (typeof(maxdepth) == "undefined") { maxdepth = 0; }
		if (typeof(depth) == "undefined") { depth = 0; }
		if (depth > maxdepth) { return; }
		if (obj != null) {
			for (i in obj) {
				msg = "";
				for (j=0; j < depth; j++) {
					msg += "&nbsp;&nbsp;&nbsp;";
				}
				if (obj[i] != null) {
					msg += i.toString() + ": " + typeof(obj[i]);
					msg += " = <span style=\"color: #999999\">";
					if (typeof(obj[i]) == "string") { msg += "\""; }
					if (typeof(obj[i].toString) != "undefined") {
						msg += this.specialchars(obj[i].toString());
					} else {
						msg += this.specialchars(obj[i]);
					}
					if (typeof(obj[i]) == "string") { msg += "\""; }
					msg += "</span>";
					Debug.outputLiteral(msg, false);
				}
				if (typeof(obj[i]) != "string") {
					if (i.toString() != "parentNode") {
						try {
							if (parent) {
								Debug.showProperties(obj[i], maxdepth, depth+1, parent + "." + i);
							} else {
								Debug.showProperties(obj[i], maxdepth, depth+1, i);
							}
						} catch(e) {
						}
					}
				}
			}
		}
	}
}