/*
 * object_enh.js
 *
 * Copyright (C) 2006 - OS3 srl - http://www.os3.it
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
// PUBLIC: iterate
Object.prototype.iterate = function ( cback )
{
	var k;

	for ( k in this )
	{
		if ( typeof ( this [ k ] ) == 'function' ) continue;
		cback ( this [ k ], k );
	}
};

// PUBLIC: debugDump
Object.prototype.debugDump = function ( dump_funcs, lvl )
{
	var s = '';
	var k, v;

	if ( ! lvl ) lvl = '';

	for ( k in this )
	{
		if ( typeof ( this [ k ] ) == 'function' ) 
		{
			if ( dump_funcs ) s += lvl + 'function ' + k + ' ()\n';
		} else {
			if ( typeof ( this [ k ] ) == 'object' )
			{
				s += lvl + k + ":\n" + this [ k ].debugDump ( dump_funcs, lvl + "-----  " );
			} else {
				s += lvl + k + ": " + this [ k ] + "\n";
			}
		}
	}

	return s;
};

// PUBLIC: get
Object.prototype.get = function ( name, def_val )
{
	var res = this [ name ];

	if ( typeof ( res ) == 'undefined' ) return def_val;

	return res;
};

// PUBLIC: getName
Object.prototype.getName = function ()
{
	if ( this.name ) return this.name;

	var s = "" + this;
	var v = s.match ( /^function  *([_a-zA-Z$][_a-zA-Z0-9$]*)  *.*/ ); //new RegExp ( "^function  *(.*) *\(" ) )

	if ( ! v ) return '';

	return v [ 1 ];
};

// PUBLIC: inherits
Object.prototype.inherits = function ( p )
{
	var name;

	this.parent = p;
	for ( name in p )
		if ( typeof this [ name ] == 'undefined' ) this [ name ] = p [ name ];
};


// PUBLIC: clone
Object.prototype.clone = function ()
{
        var res ={};
        var name;

        for ( name in this ) res [ name ] = this [ name ];

        return res;
};


