Function.prototype.contents = function()
{
	return this.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1]
};

Function.prototype.params = function()
{
	if (this.prototype.Parameters)
		return this.prototype.Parameters;
	var s = this.toString().match(/\((.*?)\)/)[1].match(/[\w]+/g) || [];
	return s;
};
	
String.prototype.parseBoolean = function()
{
	switch(this.toLowerCase())
	{
                case "true": case "yes": case "1": return true;
		default: return false;
       	}
};

String.prototype.padZeros = function(length) 
{ 
	var str = '' + this;
	while (str.length < length)
	{
		str = '0' + str;
	}
	return str; 
};

String.prototype.chunk = function(n)
{
	if (typeof n=='undefined') n=2;
	return this.match(RegExp('.{1,'+n+'}','g'));
};

String.prototype.trim = function()
{
	var str = this.replace(/^\s\s*/, ''),
	ws = /\s/, i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1)
};

Number.prototype.padZeros = function(length) 
{ 
	var str = '' + this;
	return str.padZeros(length); 
};

Date.prototype.format = function(formatString) 
{
	if (formatString)
	{
		var seperators = formatString.split(/[\w]/g);
		var tokens = formatString.split(/-|:| |\//);
		var token;
		var str = '';
		for (var i=0; i<tokens.length; i++)
		{
			token = tokens[i];
				
			switch(token)
			{
				case 'dd':
					str += this.getDate().padZeros(2);
  					break;
				case 'mm':
					str += (this.getMonth()+1).padZeros(2);
  					break;
				case 'yy':
					var y = this.getFullYear().toString()
					str += y[2]+y[3];
  					break;
				case 'yyyy':
					str += this.getFullYear();
  					break;

				case 'HH':
					str += this.getHours().padZeros(2);
 					break;
				case 'MM':
					str += this.getMinutes().padZeros(2);
  					break;
				case 'SS':
					str += this.getSeconds().padZeros(2);
  					break;
				case 'MS':
					str += this.getMilliseconds().padZeros(3);
					break;
				default:
					str += token;
			}
			str += seperators[i+1];
		}
		return str;
	}
	else 
		return this.toString(); 
};

if (!Array.prototype.indexOf)
{
    /**
     * Add array.indexOf() functionality (exists in >FF 1.5 but not in IE)
     *
     * @param {Object} elem Element to find.
     * @param {Number} [from] Position in array to look from.
     */
    Array.prototype.indexOf = function(elem /*, from*/) {
        var len = this.length;

        var from = Number(arguments[1]) || 0;
        from = (from < 0) ? Math.ceil(from) : Math.floor(from);
        if (from < 0) {
            from += len;
        }

        for (; from < len; from++) {
            if (from in this && this[from] === elem) {
                return from;
            }
        }

        return -1;
    };
};

if(!Array.prototype.map)
{
	Array.prototype.map = function(fnc)
	{
		var a = new Array(this.length);
    		for (var i = 0; i < this.length; i++)
        		a[i] = fnc(this[i]);
    		return a;
	};
};

if (!Array.prototype.remove)
{
	Array.prototype.remove=function(s)
	{
		var i = this.indexOf(s);
		if(i != -1) this.splice(i, 1);
	}
};

if (!Array.prototype.has)
{
	Array.prototype.has = function(p_val)
	{
		for(var i = 0, l = this.length; i < l; i++)
		{
			if(this[i] == p_val)
			{
				return true;
			}
		}
		return false;
	}
}

if (!Array.prototype.compare)
{
Array.prototype.compare = function(arr) {
    if (this.length != arr.length) return false;
    for (var i = 0; i < arr.length; i++) {
        if (this[i].compare) { //likely nested array
            if (!this[i].compare(arr[i])) return false;
            else continue;
        }
        if (this[i] != arr[i]) return false;
    }
    return true;
}
}
