/**
 * NM_Console.js
 *
 * wrapper class for firebug console
 * see also http://getfirebug.com/logging
 *
 * @author	Steffen Heinzelmann <shi@dmc.de>
 * @version $Id: NM_Console.js 67657 2010-07-19 07:37:18Z sheinzelmann $
 **/
var NM_Console = {

	/**
	 * flag, if NM_Console is active
	 *
	 * @access 	protected
	 * @var 	boolean blnActive
	 */
	blnActive: false,

	/**
	 * set activation status
	 *
	 * @access 	public
	 * @param	boolean blnActive
	 * @return  void
	 */
	setStatus: function( blnActive )
	{
		if( window.console && window.console.firebug )
		{
			this.blnActive = blnActive;
		}
		else
		{
			this.blnActive = false;
		}
	},

	/**
	 * return true if activation status is true
	 *
	 * @access 	public
	 * @return  boolean
	 */
	isActive: function()
	{
		return this.blnActive;
	},

	/**
	 * send a log msg to the console
	 *
	 * @access 	public
	 * @param	object objMsg (NM_ConsoleMsg)
	 * @return  void
	 */
	log: function( objMsg )
	{
		if( true == this.blnActive )
		{
			try { console.log( this.formatMsg( objMsg ) ) ; } catch( e ) {};
		}
	},

	/**
	 * send a debug msg to the console
	 *
	 * @access 	public
	 * @param	object objMsg (NM_ConsoleMsg)
	 * @return  void
	 */
	debug: function( objMsg )
	{
		if( true == this.blnActive )
		{
			try { console.debug( this.formatMsg( objMsg ) ) ; } catch( e ) {};
		}
	},

	/**
	 * send a info msg to the console
	 *
	 * @access 	public
	 * @param	object objMsg (NM_ConsoleMsg)
	 * @return  void
	 */
	info: function( objMsg )
	{
		if( true == this.blnActive )
		{
			try { console.info( this.formatMsg( objMsg ) ) ; } catch( e ) {};
		}
	},

	/**
	 * send a warning msg to the console
	 *
	 * @access 	public
	 * @param	object objMsg (NM_ConsoleMsg)
	 * @return  void
	 */
	warning: function( objMsg )
	{
		if( true == this.blnActive )
		{
			try { console.warn( this.formatMsg( objMsg ) ) ; } catch( e ) {};
		}
	},

	/**
	 * send a error msg to the console
	 *
	 * @access 	public
	 * @param	object objMsg (NM_ConsoleMsg)
	 * @return  void
	 */
	error: function( objMsg )
	{
		if( true == this.blnActive )
		{
			try { console.error( this.formatMsg( objMsg ) ) ; } catch( e ) {};
		}
	},

	/**
	 * send a group msg to the console and group the console output
	 *
	 * @access 	public
	 * @param	object objMsg (NM_ConsoleMsg)
	 * @return  void
	 */
	group: function( objMsg )
	{
		if( true == this.blnActive )
		{
			try { console.group( '[dmc] '+this.formatMsg( objMsg ) ) ; } catch( e ) {};
		}
	},

	/**
	 * ending group output
	 *
	 * @access 	public
	 * @return  void
	 */
	groupEnd: function()
	{
		if( true == this.blnActive )
		{
			try { console.groupEnd() } catch( e ) {};
		}
	},

	/**
	 * start a timer
	 *
	 * You must use the same timer msg for starting and ending the timer
	 *
	 * @access 	public
	 * @param	object objMsg (NM_ConsoleMsg)
	 * @return  void
	 */
	time: function( objMsg )
	{
		if( true == this.blnActive )
		{
			try { console.time( '[dmc] '+this.formatMsg( objMsg ) ) ; } catch( e ) {};
		}
	},

	/**
	 * end the timer
	 *
	 * @access 	public
	 * @param	object objMsg (NM_ConsoleMsg)
	 * @return  void
	 */
	timeEnd: function( objMsg )
	{
		if( true == this.blnActive )
		{
			try { console.timeEnd( '[dmc] '+this.formatMsg( objMsg ) ) ; } catch( e ) {};
		}
	},

	/**
	 * start profiling
	 *
	 * You must use the same profile msg for starting and ending the profiling
	 *
	 * @access 	public
	 * @param	object objMsg (NM_ConsoleMsg)
	 * @return  void
	 */
	profile: function( objMsg )
	{
		if( true == this.blnActive )
		{
			try { console.profile( '[dmc] '+this.formatMsg( objMsg ) ) ; } catch( e ) {};
		}
	},

	/**
	 * end profiling
	 *
	 * @access 	public
	 * @return  void
	 */
	profileEnd: function( objMsg )
	{
		if( true == this.blnActive )
		{
			try { console.profileEnd() ; } catch( e ) {};
		}
	},

	/**
	 * tracing
	 *
	 * @access 	public
	 * @return  void
	 */
	trace: function()
	{
		if( true == this.blnActive )
		{
			try { console.trace() ; } catch( e ) {};
		}
	},

	/**
	 * send an object snapshot to the console
	 *
	 * @access 	public
	 * @param	object objMsg (NM_ConsoleMsg)
	 * @param	object objData
	 * @return  void
	 */
	dir: function( objMsg, objData )
	{
		if( true == this.blnActive )
		{
			objMsg.msg = '[console.dir]: ' + objMsg.msg;
			this.group( objMsg );
			try { console.dir( objData ) ; } catch( e ) {};
			this.groupEnd();
		}
	},

	/**
	 * send an element snapshot to the console
	 *
	 * @access 	public
	 * @param	object objMsg (NM_ConsoleMsg)
	 * @param	xml xmlData
	 * @return  void
	 */
	dirxml: function( objMsg, xmlData )
	{
		if( true == this.blnActive )
		{
			objMsg.msg = '[console.dirxml]: ' + objMsg.msg;
			this.group( objMsg );
			try { console.dirxml( xmlData ) ; } catch( e ) {};
			this.groupEnd();
		}
	},

	/**
	 * formating the messages
	 *
	 * @access 	protected
	 * @param	object objMsg (NM_ConsoleMsg)
	 * @return  string
	 */
	formatMsg: function( objMsg )
	{
		if( objMsg.cntxt != '' )
		{
			return objMsg.cntxt+': '+objMsg.msg;
		}
		else
		{
			return objMsg.msg;
		}
	}

};

/**
 * NM_ConsoleMsg.js
 *
 * @author	Steffen Heinzelmann <shi@dmc.de>
 * @version $Id: NM_Console.js 67657 2010-07-19 07:37:18Z sheinzelmann $
 **/
var NM_ConsoleMsg = new Class( {

	/**
	 * the message context
	 *
	 * @access 	protected
	 * @var 	string cntxt
	 */
	cntxt: 'default',

	/**
	 * the message string
	 *
	 * @access 	protected
	 * @var 	string msg
	 */
	msg: '',

	/**
	 * constructor
	 *
	 * @access 	public
	 * @param	string strCntxt
	 * @param	string strMsg
	 * @return	void
	 */
	initialize: function( strCntxt, strMsg )
	{
		this.setContext( strCntxt );
		this.setMsg( strMsg );
	},

	/**
	 * set the message context
	 *
	 * @access 	public
	 * @param	string strCntxt
	 * @return	void
	 */
	setContext: function( strCntxt )
	{
		this.cntxt = strCntxt;
	},

	/**
	 * set the message string
	 *
	 * @access 	public
	 * @param	string strMsg
	 * @return	void
	 */
	setMsg: function( strMsg )
	{
		this.msg = strMsg;
	}

} );
