/**
 * $ debug.js,v 1.5 2005/06/07 13:06:32 gyuris Exp $
 * @package  lib.debug
 * @author   Gyuris Gellért
 * @see      browserCheck, prototype_A
 */
/**
 * list - kilistázza egy objektum elemeit.
 * @param oObj Object  A elem, amelyre kíváncsiak vagyunk.
 */
function list( oObj ) {
	function listWidthBrowsers5( oObj ) {
		var i, sHTML, oChild, elListWindow, sFunction;
		// segédfunkció a hibaüzenetek meghatározásához
		function errorMessage( e ) {
			var sError = ( new String( navigator.product ).toLowerCase() == 'gecko' ) ? e : e.number + '; ' + e.description;
			return sError;
		};
		// segédfunkció az elemek legyártásához
		function addItem( strHTML, oStyle, oParent ) {
			var k, elItem;
			elItem = document.createElement('DIV');
			for ( k in oStyle ) {
				elItem.style[k] = oStyle[k];
			};
			elItem.innerHTML = strHTML;
			if ( oParent ) {
				oParent.appendChild( elItem );
			}
			else {
				return elItem;
			};
		}
		if ( !window.innerWidth ) { 
			window.innerWidth = ( document.body ) ? document.body.offsetWidth : 800;
			window.innerHeight = ( document.body ) ? document.body.offsetHeight : 600;
		}
		if ( document.body && document.body.appendChild ) {
			elListWindow = addItem( '', style = {
				position : 'absolute', 
				top : '10px', 
				right : '10px', 
				width : Math.floor( window.innerWidth * 2/5 ) + 'px',
				height : window.innerHeight - 30 + 'px',
				zIndex : '1000',
				overflow : 'auto',
				backgroundColor : 'silver',
				fontFamily : 'Verdana, sans-serif',
				fontSize : '11px',
				textAlign : 'left',
				padding : '5px',
				paddingBottom : '20px',
				border : '1px solid black' } );
		};
		sFunction = "function doList() {\n" +
					"    if ( oObj == null ) {\n" +
					"        addItem( '&#8501; null', style = { color : 'darkblue', fontWeight : 'bold', fontFamily : 'Lucida sans Unicode, sans-serif', fontSize : '14px' }, elListWindow ) }\n" + 
					"     else {\n" + 
					"        try { addItem( '&#8501; ' + eval( oObj ), style = { color : 'darkblue', fontWeight : 'bold', fontFamily : 'Lucida sans Unicode, sans-serif', fontSize : '14px' }, elListWindow ) }\n" +
					"        catch( e ) { addItem( 'ERROR: [' + i + ' : ' + errorMessage( e ) + ']', style = { color : 'red', fontFamily : 'Lucida sans Unicode, sans-serif' }, elListWindow ) }\n" + 
					"        for ( i in oObj ) {\n" + 
					"            try {\n" + 
					"                oChild = oObj[i];\n" + 
					"                if      ( typeof( oChild ) == 'object'   )  {\n" +
					"                    if      ( oChild instanceof Array    )  addItem( i + ' [' + oChild.length + '] ',                  style = { color : 'deeppink' }, elListWindow )\n" + 
					"                    else if ( oChild instanceof Date     )  addItem( i + ' &raquo; ' + oChild,                         style = { color : 'black' }, elListWindow )\n" + 
					"                    else if ( oChild instanceof RegExp   )  addItem( i + ' &#8250; ' + oChild,                         style = { color : 'midnightblue' }, elListWindow )\n" + 
					"                    else if ( oChild instanceof Object   )  addItem( '&rarr; ' + i + ' ',                              style = { color : 'darkblue' }, elListWindow )\n" + 
					"                    else if ( oChild == null             )  addItem( i + ' &bull; ',                                   style = { color : 'darkblue' }, elListWindow )\n" + 
					"                    else                                    addItem( '&rarr; ' + i + ' ',                              style = { color : 'darkblue' }, elListWindow )\n" + 
					"                }\n" +  
					"                else if ( typeof( oChild ) == 'number'   )  addItem( i + ' = '       + oChild,                         style = { color : 'darkmagenta' }, elListWindow )\n" + 
					"                else if ( typeof( oChild ) == 'string'   )  addItem( i + ' : &quot;' + oChild.escapeHTML() + '&quot;', style = { color : 'darkred' }, elListWindow )\n" + 
					"                else if ( typeof( oChild ) == 'function' )  addItem( ' &fnof; ' + i,                                   style = { color : 'green' }, elListWindow )\n" + 
					"                else if ( typeof( oChild ) == 'boolean'  )  addItem( i + ' &rsaquo;&rsaquo; ' + oChild,                style = { color : 'mediumvioletred' }, elListWindow )\n" + 
					"                else                                        addItem( i + ' &ne; '    + oChild,                         style = { color : 'red' }, elListWindow )\n" + 
					"            }\n" + 
					"            catch( e ) { addItem( i + ' &#8212; ERROR: ' + errorMessage( e ), style = { color : 'red' }, elListWindow ) }\n" + 
					"        }\n" + 
					"    }\n" +
					"}";
		eval( sFunction );
		doList();
		document.body.appendChild( elListWindow );
	};
	function listWidthBrowsers4( oObj ) {
		var i, str = '';
		for ( i in oObj ) {
			str += i + ' = ' + oObj[i] + '\n';
		}
		alert( str );
	};
	if ( is.ns4 || is.opera5 || is.opera6 ) {
		listWidthBrowsers4( oObj );
	}
	else {
		listWidthBrowsers5( oObj );
	};
};
/**
 * workload - terhelési vizsgálat
 */
var workload = {
	timeInit : new Date(),
	timeA : null,
	timeB : null,
	times : [],
 	/**
 	 * Elindítja a terhelési vizsgálatot.
 	 */
	start : function() {
		this.timeA = new Date();	
	},
 	/**
 	 * Vizgsálati pontot ad hozzá
 	 * @param sComment String  A vizsgálati pont azonosítására szolgáló sztring.
 	 */
	addPoint : function( sComment ) {
		this.times[this.times.length] = { time : new Date(), comment : sComment };
	},
 	/**
 	 * A vizsgálat vége - a képernyőre kíírja a teljes az érékeket.
 	 */
	end : function() {
		var timeDifference, elListWindow, i;
		function addItem( strHTML, oStyle, oParent ) {
			var k, elItem;
			elItem = document.createElement('DIV');
			for ( k in oStyle ) {
				elItem.style[k] = oStyle[k];
			};
			elItem.innerHTML = strHTML;
			if ( oParent ) {
				oParent.appendChild( elItem );
			}
			else {
				return elItem;
			};
		};
		function getPrecisionDate( oDate ) {
			var s = '';
			s += oDate.getUTCHours()   + ':';
   			s += oDate.getUTCMinutes() + ':';
   			s += oDate.getUTCSeconds() + ' ';
   			s += oDate.getUTCMilliseconds();
			return s;
		};
		this.timeB = new Date();
		timeDifference = this.timeB - this.timeA;
		if ( !document.body || !document.body.appendChild ) {
			return alert( timeDifference );
		};
		elListWindow = addItem( '', style = {
			position : 'absolute', 
			top : '10px', 
			right : '10px', 
			zIndex : '1001',
			backgroundColor : 'silver',
			fontFamily : 'Verdana, sans-serif',
			fontSize : '11px',
			padding : '5px',
			border : '1px solid black' } );
		addItem( getPrecisionDate( this.timeInit ) + ' init',  style = { color: 'black' }, elListWindow );
		addItem( getPrecisionDate( this.timeA )    + ' start', style = { color: 'blue' }, elListWindow );
		for ( i = 0; i < this.times.length; i++ ) {
			addItem( getPrecisionDate( this.times[i].time ) + ' ' + this.times[i].comment, style = { color: 'red' }, elListWindow );
		};
		addItem( getPrecisionDate( this.timeB )    + ' end',  style = { color: 'blue' }, elListWindow );	
		addItem( '&rarr; ' + timeDifference,  style = { color: 'red' }, elListWindow  );
		document.body.appendChild( elListWindow );
	}
};
