/*
name			: Debug Window
update			: 20040407
author			: Maurice van Creij
dependencies	: lib_debug.js
info			: http://www.woollymittens.nl/content/details.asp?id=20040407133610

history
20050511		: no prior updates report
*/

	debugLog = new Array();
	dbg = null;
	tellerX = 0;
	interval = 0;
	maxLength = 128;
	
	function debug(){
		// open the debug window if it isn't open yet
		if(dbg==null) dbg = window.open('','debugwindow','width=256,height=580,resizable=yes,scrollbars=yes')
		// add line count
		tellerX = tellerX + 1;
		// for all debugable arguments
		intDebugLine = debugLog.length;
		debugLog[intDebugLine] = '';
		for(var intA=0; intA<arguments.length; intA++){
			// recursive array splitter
			if(typeof(arguments[intA])=='object'){
				strArr2Str = '------Array-------<br />';
				plotArray(arguments[intA],0);
				strArr2Str += '---end-Array------<br />';
				arguments[intA] = strArr2Str;
			}
			// add a debug line
			debugLog[intDebugLine] += arguments[intA] + '&nbsp;';
		}
		// blit all debug lines
		if(tellerX>interval){
			dbg.document.open();
			dbg.document.write('<html><head><title>debug info</title></head><body>');
			tellerY = debugLog.length - 1;
			if(debugLog.length>maxLength){maxLines=maxLength}else{maxLines=debugLog.length}
			for(tellerZ=0 ; tellerZ < maxLines ; tellerZ++){
				dbg.document.writeln(debugLog[tellerY]+"<br />");
				tellerY = tellerY-1;
			}
			dbg.document.write('</body></html>');
			dbg.document.close();
			tellerX = 0;
		}
	}
	
	var strArr2Str= '';
	function plotArray(arrIn,intRecursion){
		// indentation
		var strSpacing = ''
		for(var intC=0; intC<intRecursion; intC++){
			strSpacing += '&nbsp;&nbsp;&nbsp;';
		}
		// plotting individual elements
		if(arrIn!=null){
			for(var intB=0; intB<arrIn.length; intB++){
				if(typeof(arrIn[intB])=='object'){
					plotArray(arrIn[intB],intRecursion+1)
				}else{
					strArr2Str += strSpacing + arrIn[intB] + '<br />'
				}
				// end of line
				if(intB==arrIn.length-1 && intRecursion==1){
					strArr2Str += '------------------<br />';
				}
			}
		}else{
			strArr2Str += 'NULL<br />';
		}
	}
	
	function debugClear(){
		debugLog.length = 0;
	}
	
	function debugHtml(string){
		string = '<xmp>' + string + '</xmp>'
		debug(string)
	}
