/* 	
	------------------------------------------------------------------------------
	/framework/classes/js/debug.js
	
	Gelijkaardige klasse aan de trace-klasse in asp.net
	Bevat functie die string-waarde accepteert en ze op het einde van de pagina
	toont, net zoals de trace.warn functie van MS.
	
   	------------------------------------------------------------------------------
    
    VERSION HISTORY:
 	   20050807		1.0		PFAS	Initial version
	
	------------------------------------------------------------------------------
*/


function Debug() {

	//alert("new debug");
	// standard properties
	this.times = new Array();
	this.sources = new Array();
	this.messages = new Array();
	this.colors = new Array();
	
	this.num_of_messages = 0;
	
	
	
	this.getTime = Debug_getTime;
	this.getElapsedTime = Debug_getElapsedTime;
	this.write = Debug_write;
	
	
	this.timer_start = this.getTime();
	
	
}

function Debug_getTime() {
	
    var nowtime = new Date();
    min = nowtime.getMinutes();
    sec = nowtime.getSeconds();
    milli = nowtime.getMilliseconds();
    
    sec = sec + (60*min);
    
    return "" + sec + "." + milli;
    
   // var milsec = TimeFormat(nowtime,"L");
    //var elapsedTime = DateDiff("s",CreateDateTime(1969,12,31,19,0,0),nowtime) & (NumberFormat((1000-milsec),"000"));
    //return(elapsedTime);
}

function Debug_getElapsedTime() {
	var nowtime = new Date();
    min = nowtime.getMinutes();
    sec = nowtime.getSeconds();
    milli = nowtime.getMilliseconds();
    
    sec = sec + (60*min);
    
    
    timestamp = "" + sec + "." + milli;
    
    return timestamp - this.timer_start;
    
}


// write() - voegt een item toe aan de lijst
	// ------------------------------------------------------------------------------
function Debug_write(msg, msgSource, color) {
	//alert("debug.write " + msg);
	if (msgSource == undefined) {
		msgSource = "";
	}
	if (color == undefined) {
		color = "#000000";
	}
	this.messages[this.num_of_messages] = msg;
	this.times[this.num_of_messages] =  Math.round(this.getElapsedTime()*100000)/100000;
	this.colors[this.num_of_messages] = color;
	this.sources[this.num_of_messages] = msgSource;
	//alert(this.num_of_messages + " - " + this.times[this.num_of_messages] + " - " + this.messages[this.num_of_messages] + " - " + this.colors[this.num_of_messages]);
	
	
	
	var table = document.getElementById("jsDebug");
	//alert("table is " + table);
	if (table) {
		
		tablerow = document.createElement("TR");
	
		tablecell = document.createElement("TD");
		mytext = document.createTextNode(fillWithZeroesFront(fillWithZeroesBack(this.times[this.num_of_messages], 9), 11));
		tablecell.appendChild(mytext);
		tablecell.setAttribute("style", "font-family: Arial; font-size: 11px; width: 150px;padding: 2px;");
		tablerow.appendChild(tablecell);
		
		tablecell = document.createElement("TD");
		mytext = document.createTextNode(this.sources[this.num_of_messages]);
		tablecell.appendChild(mytext);
		tablecell.setAttribute("style", "font-family: Arial; font-size: 11px; width: 150px;padding: 2px;");
		tablerow.appendChild(tablecell);
	
		tablecell = document.createElement("TD");
		mytext = document.createTextNode(this.messages[this.num_of_messages]);
		tablecell.appendChild(mytext);
		tablecell.setAttribute("style", "font-family: Arial; font-size: 11px; padding: 2px;");
		tablerow.appendChild(tablecell);
	
		tablebody = document.getElementById("jsDebugBody");
		if (!tablebody) {
			tablebody = document.createElement("TBODY");
			tablebody.id = "jsDebugBody";
			
			
			tableheader = document.createElement("TR");
			
			tablecell = document.createElement("TD");
			tablecell.setAttribute("colspan", "3");
			tablecell.setAttribute("style", "font-family: Arial; font-size: 11px;padding: 2px;background-color: #000000;color: #FFFFFF;");
			mytext = document.createTextNode("Javascript debug information");
			tablecell.appendChild(mytext);
			tableheader.appendChild(tablecell);
			tablebody.appendChild(tableheader);
			
			tablebody.appendChild(tablerow);
			table.appendChild(tablebody);	
		}
		else {
			tablebody.appendChild(tablerow);
		}
		
	}
	
	
	this.num_of_messages++;	
	
	
}







