
var INCLUDED_FILES = [];

if(!window.console) {
    window.console = new function() {
	this.log = function(str) {};
    };
}

// our inheritance
// Inspired by base2 and Prototype
(function() {
  var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
  // The base Class implementation (does nothing)
  this.Class = function(){};

  // Create a new Class that inherits from this class
  Class.extend = function(prop) {
    var _super = this.prototype;

    // Instantiate a base class (but only create the instance,
    // don't run the init constructor)
    initializing = true;
    var prototype = new this();
    initializing = false;

    // Copy the properties over onto the new prototype
    for (var name in prop) {
      // Check if we're overwriting an existing function
      prototype[name] = typeof prop[name] == "function" &&
        typeof _super[name] == "function" && fnTest.test(prop[name]) ?
        (function(name, fn){
          return function() {
            var tmp = this._super;

            // Add a new ._super() method that is the same method
            // but on the super-class
            this._super = _super[name];

            // The method only need to be bound temporarily, so we
            // remove it when we're done executing
            var ret = fn.apply(this, arguments);
            this._super = tmp;

            return ret;
          };
        })(name, prop[name]) :
        prop[name];
    }

    // The dummy class constructor
    function Class() {
      // All construction is actually done in the init method
      if ( !initializing && this.init )
        this.init.apply(this, arguments);
    }

    // Populate our constructed prototype object
    Class.prototype = prototype;

    // Enforce the constructor to be what we expect
    Class.constructor = Class;

    // And make this class extendable
    Class.extend = arguments.callee;

    return Class;
  };
})();



function getType(obj)
/**
 * Get the name of the Type of the object. For mozilla, we can get it from the constructor.name.
 * Otherwise, we can get it from quickly parsing the constructor code
 */
{
	//For Mozilla and maybe some others, we can get the name of
	// the function just by asking for it. That gives us
	// the type name.
	if(obj.constructor.name)
		return obj.constructor.name;

	//For other browsers that don't have that field, we'll have
	// to parse the actual function code to get the name of
	// the constructor function, and therefore the type.
	else
	{
		constructor = obj.constructor.toString();

		reg = /\s*function\s+(\w+)\s*\(/;
		res = reg.exec(constructor);
		return res[1];
	}
}

function isA(obj, type)
/**
 * Determine if an object is an arbitrary type.
 */
{
	return getType(obj) == type;
}


function isArray(obj)
/**
 * Example function showing how to use isA (in case it's not obvious enough)
 * is determine if an object is a certain type, in this case, Array.
 */
{
	return isA(obj, "Array");
}

function require(_js) {
	if(! ArrayFunction.inArray(INCLUDED_FILES,_js)) {
		ArrayFunction.add(INCLUDED_FILES,_js);
		$("head").append('<script type="text/javascript" src="'+_js+'">');
	}
}

function include(_js, _callback) {
	if(! ArrayFunction.inArray(INCLUDED_FILES,_js)) {
		ArrayFunction.add(INCLUDED_FILES,_js);
		$.getScript(_js, _callback);
	} else {
		_callback();
	}
}

// Transformation eines Formulars in ein Objekt
function form2Obj(frm){
	f = document.forms[frm]; 
	s = {};
	for(ele=0;ele<f.elements.length;ele++) s[f.elements[ele].name] = f.elements[ele].value;
	return s;
}

// Finally...
function print_r(arr,level) 
{
	var dumped_text = "";
	if(!level) level = 0;

	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";

	if(typeof(arr) == 'object') 
	{
		for(var item in arr) 
		{
			var value = arr[item];

			if(typeof(value) == 'object') 
			{
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} 
			else
			{
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} 
	else
	{
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

