/* This must load with any other file that uses it. */
var DebuggerObj;  var jsDebuggerHtml="";
function Debugger(tail, runtime){
	var log = this;
	this.tail = (tail)?tail:true;
	this.runtime = (runtime)?runtime:true;
	this.infoArray = new Array();
	this.warnArray = new Array();
	this.errorArray = new Array();
	this.info = function(name,message){
		var debug = new Debug(name,message);
		debug.message +="\n";
		log.infoArray.push(debug);
	}
	this.warn = function(name,message){
		var debug = new Debug(name,message);
		debug.message +="\n";
		log.warnArray.push(debug);
	}
	this.error = function(name,message){
		var debug = new Debug(name,message);
		debug.message +="\n";
		log.errorArray.push(debug);
	}
	this.properties = function(obj){
		if(obj.name||obj.id) log.info("propertiesOf"+(obj.name|obj.id),"****************************\nProperties of "+(obj.name|obj.id));
		for(var property in obj){
			if(typeof obj[property] != "function"){
				log.info("PropertiesItem"+obj[property]," > Property:   "+ property +" : "+ obj[property]);
			}
		}
	}
}
function getFunctionName() {
    var ownName = arguments.callee.toString();
    ownName = ownName.substr('function '.length);        // trim off "function "
    ownName = ownName.substr(0, ownName.indexOf('('));        // trim off everything after the function name
    return ownName;
}

function Debug(name,message){
	this.name=name;
	this.message = message;
	this.date = (new Date()).toString();
}
function debuggerAction(a){
	var objArry= new Array();;
	if(a==0) {
//		objArry   = new Array();
		log.infoArray  = new Array();
		log.warnArray  = new Array();
		log.errorArray = new Array();
	}
	if(a==1) objArry= log.infoArray;
	if(a==2) objArry= log.warnArray;
	if(a==3) objArry= log.errorArray;
	if(DebuggerObj){
		DebuggerObj.value="";
		for(i=0; i<objArry.length; i++){
			DebuggerObj.value+=objArry[i].message;
			if(log.tail==true){
				DebuggerObj.scrollTop = DebuggerObj.scrollHeight;
			}
		}
	}
}
var debugExtensionHTML="<tr><td id='ExtCol1'></td><td id='ExtCol2'></td><td id='ExtCol3'></td><td id='ExtCol4'></td></tr>";
function setDebugHtml(logWindow){
	jsDebuggerHtml = '' +
	'<style>.debugger {font-size: 11px;font-family: Courier New;line-height: 16px;word-spacing: 1px;letter-spacing: 1px;padding: 8px;width: 100%;border: dotted 1px #ccc}</style>'+
	'<table border="0" cellspacing="2" cellpadding="0" width="100%">' +
	'<tr>' +
	'	<td colspan="4"><textarea ID="'+logWindow+'" rows="25" cols="95" class="debugger"></textarea></td>' +
	'</tr>' +
	'<tr>' +
	'	<td width="25%"><button name="buttonName" type="button" onclick="debuggerAction(1)" style="width:100%">Info</button></td>' +
	'	<td width="25%"><button name="buttonName" type="button" onclick="debuggerAction(2)" style="width:100%">Warnings</button></td>' +
	'	<td width="25%"><button name="buttonName" type="button" onclick="debuggerAction(3)" style="width:100%">Errors</button></td>' +
	'	<td width="25%"><button name="buttonName" type="button" onclick="debuggerAction(0)" style="width:100%">Clear All</button></td>' +
	'</tr>'+debugExtensionHTML+
	'</table>';
	return jsDebuggerHtml;
}		
function initDebuggerOnPage(){
	var tail = "";
	var runtime = "";
	try{
		var loggerWindow = "LoggerWindow";
		htmlBox = document.getElementById("jsLogger");
		if(htmlBox){
			tail = htmlBox.getAttribute("tail");
			runtime = htmlBox.getAttribute("runtime");
			htmlBox.innerHTML=setDebugHtml(loggerWindow);
			log = new Debugger();
			DebuggerObj = document.getElementById(loggerWindow);
			debuggerAction("1");
		}
	} catch (E){}
	log.info("DebuggerLoaded","Debugger Loaded.\ntail="+tail+"\nruntime="+runtime);
}
function getLoggerProperties(obj){
	var temp = "Proprties for: "+component.name;
	for(var property in component){
		if(typeof component[property] != "function"){
			temp +=" > Property:   "+ property +" : "+ component[property];
		}
	}
	return temp;
}
function trim(strng){
	try{
		var start=false; var end=false; var i=0; var e=0;
		for(i=0; i<strng.length(); i++){
			if(!start){
				if(strng.substring(i,i+1)==" "){
					break;
				} else { start=true; }
			}
		}
		for(e=strng.length(); e<i; e--){
			if(!end){
				if(strng.substring(e-1,e)==" "){
					break;
				} else { end=true; }
			}
		}
		return strng.substring(i,e);
	} catch(eX){}
	return strng;
}
var log = new Debugger("","");