
/*
 * **************************** STRING *****************************************
 */
String.prototype.trim = function()
{
	return $.trim(this);
};

String.prototype.toObject = function()
{
	return eval('('+this+')');
};

String.prototype.toInt = function()
{
	var tmp = this.replace(/[^0-9]/g, '');
	if(tmp.length > 0)
	{
		return parseInt(tmp);
	}
	return 0;
};

String.prototype.ucFirst = function () {
	return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
};

/*
 * **************************** ARRAY ******************************************
 */

/**
 * †berprŸft ob ein Wert in dem Array bereits vorhanden ist
 * @param value mixed		Wert der gesucht wird
 * @param propterty string	Name der Property die verglichen werden soll (wenn value ein Object ist)
 * 
 * @return bool				true wenn der Wert gefunden wurde, sonst false
 */
Array.prototype.hasValue = function(value, property)
{
	for(i = 0; i < this.length; i++)
	{
		if(typeof(value) == 'object')
		{
			if(this[i][property] == value[property])
			{
				return true;
			}
		}
		else
		{
			if(this[i] == value)
				return true;
		}
	}
	return false;
};

Array.prototype.remove = function(value, property)
{
	for(i = 0; i < this.length; i++)
	{
		if(typeof(value) == 'Object')
		{
			if(this[i][propterty] == value[property])
			{
				this.splice(i,1);
				return true;
			}
		}
		else
		{
			if(this[i] == value)
			{
				this.splice(i,1);
				return true;
			}
		}
	}
	return false;
};

Array.prototype.clone = function()
{
	var clone = new Array();
	
	for(i in this)
	{
		clone[i] = this[i];
	}
	
	return clone;
};

/*
 * **************************** OBJECT *****************************************
 */
getObjectPropertyByValue = function(object,value)
{
	for(i in object)
	{
		if(object[i] == value)
		{
			return i.toString();
		}
	}
};

/*
 * **************************** DATE *******************************************
 */
/**
 * Formatiert einen Timestamp nach dem angegebenen Format
 * @param format 	Datums- /Zeitformat
 * 					d = Tag
 * 					m = Monat
 * 					y = Jahr 2-stellig
 * 					Y = Jahr 4-stellig
 * 					H = Stunden
 * 					i = Minuten
 * 					s = Sekunden
 * @return Formatierter Timestring
 */
Date.prototype.toFormattedString = function(format)
{
	var result = format.replace('d',this.getDate());
	result = result.replace('m',(this.getMonth()+1));
	result = result.replace('y',this.getFullYear().toString().substring(2));
	result = result.replace('Y',this.getFullYear());
	result = result.replace('H',this.getHours());
	result = result.replace('i',this.getMinutes());
	result = result.replace('s',this.getSeconds());
	
	return result;
};

Date.prototype.toShortDateString = function()
{
	return this.toFormattedString('d.m.Y');
};

Date.prototype.toShortTimeString = function()
{
	return this.toFormattedString('H:i');
};

Date.prototype.toDateTimeString = function()
{
	return this.toShortDateString() + ' ' + this.toShortTimeString();
};
