/**
 * @namespace window.logger
 * @author patrickc   
 * @sdoc logger.sdoc
 * @version 2.4
 */
 
 

/** @id Logger */
 function Logger(){
	// methods
	this.log 			= Log;
	this.review 		= Review;
	this.reset 			= Reset;
	this.error			= _Error;
	
	// params
	this.messageList 	= new Array;
	this.debug			= ( (window.location.host.toString().toLowerCase().match('localhost')?true:false ) || window.location.hash == "#debug" );
	this.loggingUrl		= '/clientsideJsErrorLogger.php';
	this.version		= 2.4;


	/** @id Logger.Log */
	function Log(m) {
		if (!this.debug){return;}
		if (window.console) {
			console.log(m);
		} else if (window.opera) {
			opera.postError(m);
		}
		this.messageList.push(m);
	}


	/** @id Logger.Review */
	function Review() {
		alert(this.messageList.join("\n"))
	}

	/** @id Logger.Reset */
	function Reset(){
		this.messageList = null;
		this.messageList = new Array;
	}
	

	/** @id Logger._Error */
	function _Error(err,msg)
	{
		this.log('**ERROR**\n'+ msg);
		if (this.debug){
			msg = (err && err.message) ? msg + "\n\t" + err.message : msg ;
			if (window.console) {
				console.log(msg);
			} else if (window.opera) {
				opera.postError(msg);
			} else {
				alert(msg);	
			}
		} else {
			// TODO: capture more browser info
			// TODO: add fancy Ajax post request
			try {
				var params = 'page='+ 		escape(document.title) ;
				params+= '&amp;message='+ 	escape(msg) ;
				params+= '&amp;browser='+ 	escape(navigator.userAgent) ;
				params+= '&amp;os='+ 		escape(navigator.platform) ;
				var img = new Image;
				img.src = this.loggingUrl +'?'+ params;  
			} catch (e){
				// doing nothing 
			}	
		}
	}
 }
 
 var logger = new Logger;
 
