
/**
JavaScript indended to be included on Animal websites during debugging.
*/

/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
*    The level - OPTIONAL
* output = s  : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and output =  a
* text that will be a more readable version of the
* array/hash/object that is given.
*/
function dump(input, indent)
{
	if( ! indent )
		indent = '';
		
	var output = '';
	
	switch( typeof(input) )
	{
		case 'boolean':
			output = "&lt;"+input+"&gt;";
			break;

		case 'number':
			if( isNaN(input) )
				output = "&lt;NaN&gt;";
			else if( input === Number.POSITIVE_INFINITY )
				output = '<+infinity>';
			else if( input === Number.NEGATIVE_INFINITY )
				output = '<-infinity>';
			else
				output = input;
			break;

		case 'string':
			output = "'"+input+"'";
			break;

		case 'undefined':
			output = "&lt;undefined&gt;";
			break;

		case 'function':
			output = '&lt;function&gt;';
			break;

		case 'object':
			if( input === null )
				output = "&lt;null&gt;";
			else
			{	
				var objName = 'object';
				
				if( input.constructor.name )
					objName = input.constructor.name;
				
				output = '\n' + indent + objName;
				if( input.length )
					output += '('+input.length + ')';
				output += ":\n";
		 		for(var key in input)
		 		{
		  			var value = input[key];
					output += indent + dump(key) +' => '+ 
						dump(value, indent+'    ') + "\n";
		 		}
				output = output;
			}
			break;

		default:
			output =  '&lt;unknown:'+typeof(input)+'&gt;';
			alert('Unknown Type: ' + typeof(input) );
	}
	
	return output;
}

