String.prototype.trim = function(){
	return this.replace(/^\s+|\s+$/g, '');
};

function formatiereURI(str){
	str = encodeURIComponent(str);
	str = str.replace(/'/g, '%27');			//Single-Quote umwandeln
	return str;
}

function formatiereInput(nachricht){
	if(nachricht && nachricht != '')	return brEntfernen(decodeURIComponent(nachricht));
	
	return nachricht;
}

function formatiereDiv(nachricht){
	if(nachricht && nachricht != '')	return brHinzu(decodeURIComponent(nachricht));
	
	return nachricht;
}

function generatePictureRandomExtension(){
	return '?' + parseInt((Math.random()*20000), 10);
}

function formatiereBildLink(bild){
	bild = bild.split('?');
	return bild[0];
}

/**
 * 	Diese Funktion wandelt alle Bildpfade um und setzt die ROOTDIR richtig
 * 
 * @param html		Der HTML-Inhalt
 * @return HTML		Der neue HTML code
 */
function makeWysiwygPictures(html){
	html = html.replace(/src=["|'](\.\.\/)*/, 'src="');
	var pattern = /src=["|']/g;
	html = html.replace(pattern, 'src="' + ROOTDIR);
	
	return html;
}

function formateEuro(euro){
	//Falls nichts angegeben
	if(!euro || euro == '')		return '0,00';
	
	euro = euro.toString().replace(/\./g, ',');
	if(euro.match(/^\d+,\d$/g) != null)			euro += '0';		//Falls hinten eine 0 fehlt
	else if(euro.match(/^\d+,$/g) != null)		euro += '00';
	else if(euro.match(/^\d+$/g) != null)		euro += ',00';
	
	if(euro.match(/^\d+,\d\d\d+$/g) != null){
		//Es sind noch zu viele Zahlen am Ende
		euro = euro.substring(0, euro.split(',')[0].length+3);
	}
	
	return euro;
}

function checkMail(mail){
	//Regulärer Ausdruck welcher folgendes E-Mail-Format überprüft:
	//Am Anfang können beliebig viele Zeichen stehen gefolgt von einem @.
	//Nach dem @ muss ein Zeichen welches von a-z pder A-Z geht.
	//Die folgenden Zeichen können von a-z A-Z 0-9 und dem - sein.
	//Dann muss ein . folgen welcher wieder erst ein Zeichen zwischen a-z und A-Z haben muss
	//gefolgt von Zeichen die a-z A-Z 0-9 und dem - sein können.
	//Bsp.: a@b.c, 23@b3kD.dsd ...
	reg = /^.+@[a-zA-Z][a-zA-Z0-9-]*\.[a-zA-Z][a-zA-Z0-9\.-]*$/;
	exp = reg.exec(mail);
	
	return exp != null ? true : false;
}

function formatiereDate(dateType, date){
	var newDate = dateType;
	if(!date || !date.getDate){
		if(typeof(date) == 'string'){
			date = mysqlTimeStampToDate(date);
		}
		else		return false;	
	}
	
	if(date == null)		return '';
	
	newDate = newDate.replace(/d/g, ((date.getDate() <= 9 ? '0' : '') + date.getDate()));
	newDate = newDate.replace(/m/g, (((date.getMonth()+1) <= 9 ? '0' : '') +(date.getMonth()+1)));
	newDate = newDate.replace(/Y/g, date.getFullYear());
	newDate = newDate.replace(/H/g, ((date.getHours() <= 9 ? '0' : '') + date.getHours()));
	newDate = newDate.replace(/i/g, ((date.getMinutes() <= 9 ? '0' : '') + date.getMinutes()));
	newDate = newDate.replace(/s/g, ((date.getSeconds() <= 9 ? '0' : '') + date.getSeconds()));
	
	return newDate;
}

function mysqlTimeStampToDate(timestamp) {
	if(typeof(timestamp) != 'string')	return timestamp;
	if(timestamp.trim() == '')			return null;
    //function parses mysql datetime string and returns javascript Date object
    //input has to be in this format: 2007-06-05 15:26:02
    var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
    var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
    
    //Der Erste Wert muss über 0 sein, damit ein regulärer Wert heraus kommt
    if(parts[0] > 0){
    	return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
    }
    
    return null;
}

function clone(obj){
	if(obj == null || typeof(obj) != 'object')
        return obj;
		
    var temp = new obj.constructor(); // changed (twice)

    for(var key in obj)
        temp[key] = clone(obj[key]);

    return temp;
}

function getGETParamenter(){
	var gets = document.location.search.substr(1,document.location.search.length).split('&');
	var getAll = {};

	if(gets.length > 0){
		var i;
		for(i in gets){
			var temp = gets[i].split('=');
			
			if(temp.length > 0){
				getAll[temp[0]] = temp[1];
			}
		}
	}
	
	return getAll;
}


/**
 * Entfernt alle HTML-BRs
 * @param str
 * @return
 */
function brEntfernen(str){
	return str.replace(/<br>/g, '\n');
}

function brHinzu(str){
	return str.replace(/\n/g, '<br>');
}


/**
 * JHTML ZUSÄTZE
 */

/**
 * Füllt den Iframe
 * 
 * @param html		Der Wert, der in das IFrame geschrieben werden soll
 */
function fuelleIframe(element, html){
	//Body befüllen
	if(element == null){
		return $('.jhtmliframe').contents().find('.jhtmlBody').html(html);
	}
	else{
		//Alles aus dem Body zurück geben
		return $(element).find('.jhtmliframe').contents().find('.jhtmlBody').html(html);
	}
}

/**
 * Gibt den IFrame Inhalt als HTML zurück
 * 
 * @return String		Der HTML Wert des IFrames
 */
function gebeIframeInhalt(element){
	if(element == null){
		return $('.jhtmliframe').contents().find('.jhtmlBody').html();
	}
	else{
		//Alles aus dem Body zurück geben
		return $(element).find('.jhtmliframe').contents().find('.jhtmlBody').html();
	}
}

/**
 * Leert den IFrame
 */
function leereIframeInhalt(element){
	if(element == null){
		return $('.jhtmliframe').contents().find('.jhtmlBody').empty();
	}
	else{
		//Alles aus dem Body zurück geben
		return $(element).find('.jhtmliframe').contents().find('.jhtmlBody').empty();
	}
}
