function textInput(id){
	
	var textarea = document.getElementById(id);
	
	var captureSelection = function(){
		textarea.focus();
		wholeText = textarea.value;
		if(typeof textarea.selectionStart != 'undefined'){
			selStart = textarea.selectionStart;
			selEnd = textarea.selectionEnd;
			selType = 'sel';
			selText = wholeText.substr(selStart,selEnd-selStart);
			selLength = selText.length;
		}else{
			if(typeof document.selection != 'undefined'){
				range = document.selection.createRange();	
				selType = 'range';
				selText = range.text;
				selLength = selText.length;
			}else{
				selType = 'none';	
			}
		}
	}
	
	this.clear = function(){
		captureSelection();
		this.replaceSelection('',false);
	}
	
	this.replaceSelection = function(str,altTreatment){
		captureSelection();
		if(selType == 'sel'){
			var newText = wholeText.substr(0,selStart) + str + wholeText.substr(selEnd,(wholeText.length - selEnd));
			textarea.value = newText;
			textarea.selectionStart = selStart + str.length;
			textarea.selectionEnd = selStart + str.length;
		}else{
			if(selType == 'range'){
				range.text = str;
				range.select();
			}else{
				if(altTreatment) textarea.value += str;	
			}
		}
	}
	
	this.getSelectedText = function(){	//vom Objekt selbst nicht benötigt, sondern für den User gedacht
		captureSelection();
		if(selType != 'none'){
			return selText;
		}else return false;
	}
	
	this.getSelectionLength = function(){//vom Objekt selbst nicht benötigt, sondern für den User gedacht
		captureSelection();
		if(selType != 'none'){
			return selLength;
		}else return false;		
	}
	
	this.trim = function(str){
		str = str.replace(/^( )*/,'');
		str = str.replace(/( )*$/,'');
		return str;
	}
	
	this.isURL = function(str){
		var expression = /^([A-Za-z]+:\/\/)?[A-Za-z0-9-_]+((\.[A-Za-z0-9-_]+)?)((\.\w{2,})+)(([A-Za-z0-9-_%&\?\/.=]+)?)$/;
		str = this.trim(str);
		return expression.test(str);	
	}
	
	this.isMail = function(str){
		var expression = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
		str = this.trim(str);
		return expression.test(str);	
	}
	
	this.tagSelection = function(tag1,tag2,altTreatment){
		captureSelection();
		if(selType != 'none'){
			this.replaceSelection(tag1+selText+tag2,false);
			if(selLength == 0) this.moveCursor(-1*tag2.length);
		}else{
			if(altTreatment) this.replaceSelection(tag1+tag2,false);
		}
	}
	
	this.moveCursor = function(steps){
		captureSelection();
		if(selType == 'sel'){
			textarea.selectionStart = selStart+steps;
			textarea.selectionEnd = selStart+steps;
		}else{
			range.move('character',steps);
			range.select();
		}
	}
	
	this.focus = function(){
		textarea.focus();	
	}
	
	this.getSelType = function(){
		captureSelection();
		return selType;
	}
	
	this.saveSelection = function(){
		captureSelection();
		var arr = new Array();
		if(selType == 'range'){
			arr[0] = 'range';
			arr[1] = range;		
		}else{
			if(selType == 'sel'){
				arr[0] = selStart;
				arr[1] = selEnd;	
			}
		}
		return arr;	
	}
	
	this.loadSelection = function(selection){
		captureSelection();
		if(selection[0] == 'range'){
			selection[1].select();	
		}else{
			textarea.selectionStart = selection[0];
			textarea.selectionEnd = selection[1];
		}
	}
}
