// methods for printing debug information to a window.
// include this file before other js files
var errWindow = null;
var ERROR = 0;
var DEBUG = 1;
var INFO  = 2;	
var curLevel = INFO;
var strBuffer = new StringBuffer();

// set the desired loggerm setting emptyLogger will disable all javascript logoutput
// var logger = premiLogger;
var logger = emptyLogger;

function emptyLogger(theHeader,theStr,theLevel,theColor) {
	// just throw it away
}

function getClockTime(theLevel) {
	var now = new Date();
	return "<table style='margin:0px;display:inline'><tr><td style='width:5px;height:5px;background-color:"+getColor(theLevel)+";'></td></tr></table>&nbsp;<i>"+now.getHours()+":"+now.getMinutes()+":"+now.getSeconds()+"</i>";
}

function getColor(theLevel) {
	if (theLevel==ERROR) return "#7F0000";
	if (theLevel==DEBUG) return "#7F7F00";
	if (theLevel==INFO) return "#007f00";
}

function premiLogger(theHeader,theStr,theLevel,theColor) {
	if (theLevel<=curLevel) {
		if ((errWindow==null) || (errWindow.closed)) {
			htmlPage = toUrl("resources/dbg.html");
			errWindow = window.open(htmlPage,"debug","width=700,height=450,resizable=yes,scrollbars=yes");
		}
		if (theColor==null) theColor="#000";
		strBuffer.append("<div style='color:"+theColor+";'>");
		strBuffer.append(getClockTime(theLevel));
		strBuffer.append("<b> "+theHeader+":</b>");
		strBuffer.append("<br><span style='margin-left:15px'>").append(theStr).append("</span></div>");
		
		var aObj = errWindow.document.getElementById("dbgData");
		if (aObj)
			aObj.innerHTML = strBuffer.toString();
	}
}
