
/**
 * The Client side logging facility.
 * @param debug 	set to enable logging
 * @param aa		reference to an AgentAbstractor instance.
 * @param ref		optional url or tag refernce for output window.
 */
function Logger(debug, aa, ref){
	
	var me = this;
	var logWin;
	var url = 'logger.php';
	var dumpWin;
	if (typeof(ref) == 'string') {
		url = ref;
	} else if (typeof(ref) == 'object') {
		dumpWin = ref;
	}
	var DEBUG = false;


// **********************************************
	
	/**
	*  Turns logging window on or off.
	*/
	this.setDebug = function( weDo ){
		if(typeof(weDo) == 'undefined'){
			return DEBUG;
		}
		if( weDo ){
			var dWidth = screen.availWidth;
			var dHeight = screen.availHeight * .25;
			var dTop = screen.availHeight * .75;
			if (typeof(dumpWin) == 'undefined') {
				if (typeof(logWin) == 'undefined' || logWin.closed) {
					logWin = window.open(url, 'loggerOut');
				}

				logWin.document.open();
				logWin.document.write("<html><body><form name='standard' action='links.php'>");
				logWin.document.write("<form name='standard' action='logger.php'>");
				logWin.document.write("<input type='button' value='Clear Log'");
				logWin.document.write(" onclick='document.standard.stuff.value=\"\";'><br>");
				logWin.document.write("<textarea cols='60' rows='20' name='stuff'></textarea>");
				logWin.document.write("</form></body></html>");
				logWin.document.close();

				logWin.focus();
				dumpWin = logWin.document.standard.stuff;
			}
			DEBUG = true;
		}
		return DEBUG;
	}


// ****************************************
  /**
   *  Append 'thisString' to the log.
   */
	this.dump = function( thisString ){
		if(DEBUG){
			if (typeof(dumpWin) == 'undefined') {
				dumpWin = logWin.document.standard.stuff;
			}
			if (null != thisString && 
				'object' == typeof(thisString) && 
				'number' == typeof(thisString.length)) {
				me.dumpHash('array:', thisString);
				return;
			}
			dumpWin.value += thisString + "\n";
		}
	}

	
  /**
   *  Append 'thisString' to the log.
   */
	this.dumpHash = function(thisString, thisObject, prefix){
		if(DEBUG){
			if (typeof(prefix) == 'undefined') {
				prefix = '';
			}
			prefix += '  ';
			if (null != thisObject && 
				'object' == typeof(thisObject) && 
				'number' == typeof(thisObject.length)) {
				me.dump(thisString);
				for (var i in thisObject) {
					me.dumpHash(prefix+"'"+i+"' => ", thisObject[i], prefix);
				}
			} else {
				me.dump(thisString+thisObject);
			}
		}
	}

	
// ****************************************
	/**
	*  Returns debug status.
	*/
	if(debug){
		me.setDebug(true);
	}
}

