/*=======================================================================*/
/* Erweiterungen der String-Klasse                                       */
/*=======================================================================*/

if (!String.prototype.trim) String.prototype.trim = function ()
{
	return this.replace(/^\s+/, "").replace(/\s+$/, "");
}

if (!String.prototype.startsWith) String.prototype.startsWith = function (s)
{
	return this.indexOf (s) == 0;
}

if (!String.prototype.endsWith) String.prototype.endsWith = function (s)
{
	var i = this.lastIndexOf (s);
	return (i >= 0) && (i == (this.length - s.length));
}

if (!String.prototype.replaceAll) String.prototype.replaceAll = function (source, replacement)
{
	text = this;
	while ( text.indexOf(source) != -1)
    {
        text = text.replace(source, replacement);
    }
    return text;
}
if (!String.prototype.replaceAllWith) String.prototype.replaceAllWith = function (replacement)
{
	text = "";
	for (var iii = 0; iii < this.length; iii++)
	{
		text += replacement;
		
	}
    return text;
}


/*=======================================================================*/
/* Erweiterungen der Array-Klasse                                       */
/*=======================================================================*/
if (!Array.prototype.indexOf) Array.prototype.indexOf = function (o)
{
    for (var i = 0, len = this.length; i < len; i++)
      if (this[i] == o) return i;
    return -1;
}

if (!Array.prototype.contains) Array.prototype.contains = function (o)
{
    return this.indexOf (o) >= 0;
}

/**
 * Erweiterungen für die Function
 */
/**
 * Erzeugt ein Delegate für eine Funktion
 *
 * @param   obj	    Das neue this-Objekt, welches in der Funktion mit this angesprochen
 *		    werden kann
 * @param   args    Array mit Übergabeparameter an die Funktion
 *
 * @return	    Delegate-Funktion
 */
if (!Function.prototype.delegate) Function.prototype.delegate = function (obj, args) {
	var params = args || arguments;
	var f = function() {
		var target = arguments.callee.target;
		var func = arguments.callee.func;
		return func.apply(target, params);
	};

	f.target = obj;
	f.func = this;

	return f;
}
/**
 * Führt eine Funktion nach eine definierten Zeit aus
 *
 * @param   millis  Die Zeit in Millisekunden, in der die Funktion ausgeführt
 *		    werden soll
 * @param   obj	    Das neue this-Objekt, kann in der Funktion mit this angesprochen
 *		    werden
 * @param   args    Array mit Übergabeparameter an die Funktion
 */
if (!Function.prototype.defer) Function.prototype.defer = function (millis, obj, args) {
	var fn = this.delegate(obj, args);
	if (millis > 0) {
		setTimeout(fn, millis);
	} else {
		fn();
	}
}
