// debug tip: var.toSource()


// toggle
function toggleDiv(idDiv,idA,classA0,classA1){
	var objDiv = null;
	var objA = null;
	var classAClosed = "clo";
	var classAOpen = "ope";
	if(document.getElementById(idDiv)) objDiv = document.getElementById(idDiv);
	if(document.getElementById(idA)) objA = document.getElementById(idA);
	if(classA0!=undefined) classAClosed = classA0;
	if(classA1!=undefined) classAOpen = classA1;
	if(objDiv!=null){
		if(objDiv.style.display=="none"){
			objDiv.style.display = "";
			if(objA!=null) objA.className = classAOpen;
		}else if(objDiv.style.display==""){
			objDiv.style.display = "none";
			if(objA!=null) objA.className = classAClosed;
		}
	}
	return false;
}


// menusub ein/aus-klappen
function toggleMenusub(idDiv, idA){
	var classAClosed = "clo";
	var classAOpen = "ope";
	if($("#"+idDiv).length>0){
		if($("#"+idDiv).css("display")=="none"){
			$("#"+idDiv).slideDown("slow");
		}else{
			$("#"+idDiv).slideUp("slow");
		}
		$("#"+idA).toggleClass("open");
	}
	return false;
}


// bild gross anzeigen
var theWindow;
function openPic(url,winName,winParams)	{
	theWindow = window.open(url,winName,winParams);	
	if(theWindow)	theWindow.focus();
}


// rgb to hex
function rgb2hex(rgb){
	rgb = rgb.toLowerCase();
	if(rgb.substr(0,1)=="#") return rgb;
	rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
	function hex(x){
		return ("0" + parseInt(x).toString(16)).slice(-2);
	}
	var ret = "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
	return ret.toLowerCase();
}


// kwWort
kwWort = function(){
	var wortKey;
	var wortVal;
	var i;
	var k;
	this.wortKey = [];
	this.wortVal = [];
	this.i = 0;
	this.k = -1;
	this.add = function(_key,_val){
		this.wortKey[this.i] = _key;
		this.wortVal[this.i] = _val;
		++this.i;
	}
	this.get = function(_key){
		this.k = jQuery.inArray(_key,this.wortKey);
		if(this.k>-1) return this.wortVal[this.k];
		return 'Fehler! Wort nicht definiert';
	}
}


// kwDialog
kwDialog = function(_width, _height, _classname, _html, _url, _urldata){
	var url;
	var urldata;
	var html;
	var classname;
	// jquery ui dialog
	var width;
	var height;
	var minWidth;
	var minHeight;
	var maxWidth;
	var maxHeight;
	var modal;
	var position;
	var resizable;
	// set default
	this.url = "";
	this.urldata = "";
	this.html = "";
	this.classname = "fenster";
	this.width = 400;
	this.height = 150;
	this.minWidth = 150;
	this.minHeight = 150;
	this.maxWidth = false;
	this.maxHeight = false;
	this.modal = true;
	this.position = "center";
	this.resizable = false;
	// übergabe einlesen
	if(_width!=undefined && _width!=null) this.width = _width;
	if(_height!=undefined && _height!=null) this.height = _height;
	if(_classname!=undefined && _classname!=null) this.classname = _classname;
	if(_html!=undefined && _html!=null) this.html = _html;
	if(_url!=undefined && _url!=null) this.url = _url;
	if(_urldata!=undefined && _urldata!=null) this.urldata = _urldata;
}
kwDialog.prototype = {
	setUrl : function(_url){
		this.url = _url;
	}
	,
	setUrldata : function(_urldata){
		this.urldata = _urldata;
	}
	,
	setHtml : function(_html){
		this.html = _html;
	}
	,
	setSize : function(_width, _height){
		this.width = _width;
		this.height = _height;		
	}
	,
	setClassname : function(_classname){
		this.classname = _classname;
	}
	,
	show : function(){
		// html element anlegen
		if($("#kwDialog").length==0) this.createKwDialog();
		// ladeicon anzeigen
		if($("#kwDialog > h1").length>0) $("#kwDialog > h1").html("<img src=\"http://www.kirchenweb.ch/_kirchenweb_site/_images/iconLaden.gif\" alt=\"\" />");
		// html inhalt laden
		if(this.html!=""){
			$("#kwDialog").html(this.html);
		}else if(this.url!=""){
			$.post(this.url, this.urldata, function(data){ $("#kwDialog").html(data); } );
		}
		// anzeigen
		$("#kwDialogHintergrund").css("display","block");
		$("#kwDialogHintergrund").css("width",$(document).width());
		$("#kwDialogHintergrund").css("height",$(document).height());
		$("#kwDialog").attr("className",this.classname);
		$("#kwDialog").css("display","block");
		$("#kwDialog").css("left",Math.max(0,$(window).width()-this.width)/2);
		$("#kwDialog").css("top",$(window).scrollTop()+Math.max(0,$(window).height()-this.height)/2);
		$("#kwDialog").css("width",this.width);
		$("#kwDialog").css("height",this.height);
	}
	,
	hide : function(){
		// hide dialog
		$("#kwDialog").css("display", "none");
		$("#kwDialog").html("");
		$("#kwDialogHintergrund").css("display", "none");
		return false;
	}
	,
	createKwDialog : function(){
		$("body").append($("<div/>", {id:"kwDialogHintergrund"}));
		$("body").append($("<div/>", {id:"kwDialog", className: this.classname}));
		$("#kwDialog").html("<h1><img src=\"http://www.kirchenweb.ch/_kirchenweb_site/_images/iconLaden.gif\" alt=\"\" /></h1>");
	}
}
$(function(){
	$(window).resize(function(){
		$("#kwDialogHintergrund").css("width",$(document).width());
		$("#kwDialogHintergrund").css("height",$(document).height());
		$("#kwDialog").css("left",Math.max(0,$(window).width()-$("#kwDialog").width())/2);
	});
});


// kwMitteilung
function kwMitteilung(_str, _opt, _zeit){
	var t = 4000; // 4s
	if(_zeit!=null && _zeit!=undefined && _zeit>0 && _zeit<600000) t = parseInt(_zeit,10);
	// mitteilung erstellen
	if($("#kwMitteilung").length==0){
		$("body").append($("<div/>", {id:"kwMitteilung"}));
		$("#kwMitteilung").append($("<div/>", {className:"info"}));
		$("#kwMitteilung").append($("<div/>", {id:"kwMitteilungText"}));
		$("#kwMitteilung").css("top","-55px");
	}
	// text einfügen
	$("#kwMitteilungText").html(_str);
	// animieren
	$("#kwMitteilung").css("left",Math.max(0,$(window).width()-$("#kwMitteilung").width())/2);
	if(_opt=="ein"){
		$("#kwMitteilung").stop().animate({"top": "0"}, "slow");
	}else if(_opt=="aus"){
		$("#kwMitteilung").stop().animate({"top": "0"}, "slow").delay(t).animate({"top": "-55px"}, "slow");
	}else{
		$("#kwMitteilung").stop().animate({"top": "0"}, "slow").delay(t).animate({"top": "-55px"}, "slow");
	}
	return false;
}


// textvorschlag (basic)
kwTextvorschlag = function(_id,_worte){
	var id;
	var pos;
	var anz;
	var strText;
	var strVorschlag;
	var arrData;
	var actionClick;
	var worte;
	// set default
	this.id = "tv";
	this.pos = -1;
	this.anz = 0;
	this.strText = "";
	this.strVorschlag = "";
	this.arrData = [];
	this.actionClick = "";
	this.worte = _worte;
	// uebergabe einlesen
	if(_id!=undefined && _id!=null) this.id = _id;
}
kwTextvorschlag.prototype = {
	init : function(){
		$("#"+this.id).after($("<ul/>", {id:this.id+"_liste"}));
		$("#"+this.id+"_liste").css({"position": "absolute", "display": "none", "list-style-type": "none", "max-height": "250px", "overflow": "auto", "padding": "0", "background": "#fff", "border": "1px solid #c8d6dd", "z-index": "100"});
		// eventhandler
		var obj = this;
		$("#"+this.id).bind("keydown", function(e){ obj.eventKeydown(e); });
		$("#"+this.id).bind("keyup", function(e){ obj.eventKeyup(e); });
		$("body").bind("click", function(e){ obj.eventClickBody(e); });
		// get data
		if(typeof this.getData=="function") this.getData();
	}
	,
	eventKeydown : function(_e){
		if(_e.keyCode=="9" || _e.keyCode=="13"){
			// key TAB, ENTER
			if(this.pos>=0){
				_e.preventDefault();
				this.setVorschlag();
			}
		}else if(_e.keyCode=="40"){
			// key DOWN
			_e.preventDefault();
			if(this.pos==-1 || this.pos==this.anz-1){
				this.selectVorschlag(0);
			}else{
				this.selectVorschlag(++this.pos);
			}
		}else if(_e.keyCode=="38"){
			// key UP
			_e.preventDefault();
			if(this.pos==-1 || this.pos==0){
				this.pos = this.anz-1;
				this.selectVorschlag(this.pos);
			}else{
				this.selectVorschlag(--this.pos);
			}
		}
	}
	,
	eventKeyup : function(_e){
		if(_e.keyCode=="13" || _e.keyCode=="9"){
			// key ENTER, TAB
		}else if(_e.keyCode=="40" || _e.keyCode=="38"){
			// key DOWN, UP
		}else{
			this.getVorschlagliste();
		}
	}
	,
	eventClick : function(_e){
		this.setVorschlag(_e.target.id.substr(this.id.length+1));
		if(this.actionClick!="") eval(this.actionClick+"();");
		return false;
	}
	,
	getVorschlagliste : function(){
		this.strText = $("#"+this.id).val();
		if(this.strText.length>0){
			// spezifische daten
			this.strVorschlag = "";
			if(typeof this.getVorschlag=="function") this.strVorschlag = this.getVorschlag();
			// info anzeigen keine treffer
			if(this.strVorschlag=="") this.strVorschlag = "<li id=\"kt_"+this.id+"\" style=\"padding:2px;\">"+this.worte.keinElementGefunden+"</li>";
			// ausgabe anzeigen
			$("#"+this.id+"_liste").html(this.strVorschlag);
			if(this.strVorschlag>""){
				$("#"+this.id+"_liste").css("display","block");
				// eventhandler für vorschläge
				var obj = this;
				$("#"+this.id+"_liste > li > a").bind("click", function(e){ return obj.eventClick(e); });
			}
		}else{
			// ausgabe ausblenden
			$("#"+this.id+"_liste").css("display","none");
			$("#"+this.id+"_liste").html("");
		}
	}
	,
	setVorschlag : function(_int){
		// position übernehmen
		if(_int!=undefined && _int!=null) this.pos = _int;
		// vorschlag übernehmen
		if($("#"+this.id+"_"+this.pos).is("[title]")){
			this.strText = $("#"+this.id+"_"+this.pos).attr("title");
		}else{
			this.strText = $("#"+this.id+"_"+this.pos).html();
		}
		$("#"+this.id).val(this.strText);
		// vorschläge ausblenden
		$("#"+this.id+"_liste").css("display","none");
		$("#"+this.id+"_liste").html("");
		// zurücksetzten
		$("#"+this.id).focus();
		this.pos = -1;
		this.anz = 0;
	}
	,
	selectVorschlag : function(_int){
		// position übernehmen
		if(_int!=undefined && _int!=null) this.pos = _int;
		// alle zurücksetzten
		$("#"+this.id+"_liste > li > a").attr("class","");
		// gewählter eintrag markieren
		$("#"+this.id+"_"+_int).attr("class","aktiv");
	}
	,
	setActionClick : function(_fc){
		this.actionClick = _fc;
	}
	,
	eventClickBody : function(_e){
		if(_e.target.id != this.id && _e.target.parentNode.id != this.id+"_liste"){
			$("#"+this.id+"_liste").css("display","none");
		}
	}
}


// textvorschlag (pro)
kwTextvorschlagPro = function(_id){
	// Definitionen
	var id; // html id von suchfeld
	var pos; // auswahl position
	var anz; // anzahl treffer
	var strBegriff; // ganzes Such-Pattern
	var strSuchwort; // letztes suchwort
	var strVorschlag; // hinterlegter Vorschlag
	var strListe; // Vorschlagliste HTML
	var data; // NEU - Begriffliste als Objekt
	var listenFocus; // flag Focus Listener
	var listenEnter; // flag Komplettierung mit Enter
	// Defaultwerte
	this.id = "tvpro";
	this.pos = -1;
	this.anz = 0;
	this.strBegriff = "";
	this.strSuchwort = "";
	this.strVorschlag = "";
	this.strListe = "";
	this.data = [];
	this.listenFocus = false;
	this.listenEnter = false;
	// Uebergabe einlesen
	if(_id!=undefined && _id!=null) this.id = _id;
}
kwTextvorschlagPro.prototype = {
	// Initialisierung
	init : function(){
		// Einfuegen Layer, Vorschlag-Feld & Liste
		$("#"+this.id).after($("<a/>", {id:this.id+"_submit",  href:""}));
		$("#"+this.id).before($("<input/>", {id:this.id+"_vorschlag", type:"text", name:this.id+"_inputV", autocomplete:"off"}));
		$("#"+this.id).wrap($("<div/>", {id:this.id+"_layerS"}));
		$("#"+this.id+"_vorschlag").wrap($("<div/>", {id:this.id+"_layerV"}));
		$("#"+this.id).after($("<a/>", {id:this.id+"_reset",  href:""}));
		$("#"+this.id).after($("<ul/>", {id:this.id+"_liste"}));
		// CSS Suchlayer
		$("#"+this.id+"_layerS").css({
			"position": "relative",
			"z-index": "2"
		});
		// CSS Suchfeld (IE laesst Focus durch transparenten Hintergrund)
		$("#"+this.id).css("background", "transparent url(http://www.kirchenweb.ch/_kirchenweb_site/_images/transparent.gif) 0 0 repeat");
		// CSS Vorschlaglayer
		$("#"+this.id+"_layerV").css({"position": "absolute",	"z-index": "1"});
		// Eventhandler binden
		var obj = this;
		$("#"+this.id).bind("keydown", function(e){ obj.eventKeydown(e); });
		$("#"+this.id).bind("keyup", function(e){ obj.eventKeyup(e); });
		$("#"+this.id).bind("focus", function(e){ obj.eventFocus(e); });
		$("#"+this.id+"_submit").bind("click", function(e){ return obj.eventClickSubmit(e); });
		$("#"+this.id+"_reset").bind("click", function(e){ return obj.eventClickReset(e); });
		$("body").bind("click", function(e){ obj.eventClickBody(e); });
		// Daten laden
		if(typeof this.initData=="function") this.initData();
	}
	,
	eventKeydown : function(_e){
		if(_e.keyCode == "9"){
			// Key TAB
			_e.preventDefault();
			this.setVorschlag();
		}else if(_e.keyCode == "13"){
			// Key ENTER
			_e.preventDefault();
			var vorschlag = $("#"+this.id).val();
			if(this.pos == -1 && !this.listenEnter){
				this.loadSuche(vorschlag);
				$("#"+this.id+"_vorschlag").val("");
				this.resetVorschlag();
			}
			else
				this.setVorschlag();
		}else if(_e.keyCode == "40"){
			// Key DOWN
			_e.preventDefault();
			if(this.pos == -1 || this.pos == this.anz-1){
				this.selectEintrag(0);
				this.pos = 0;
			}else{
				this.selectEintrag(++this.pos);
			}
		}else if(_e.keyCode == "38"){
			// Key UP
			_e.preventDefault();
			if (this.pos == -1 || this.pos == 0){
				this.selectEintrag(this.anz-1);
				this.pos = this.anz-1;
			}else{
				this.selectEintrag(--this.pos);
			}
		}else if(_e.keyCode == "27"){
			// Key ESC
			_e.preventDefault();
			$("#"+this.id).val("");
			$("#"+this.id+"_vorschlag").val("");
			this.resetVorschlag();
		}else{
			// Wenn Zeichen, Vorschlagfeld leeren
			$("#"+this.id+"_vorschlag").val("");
		}
	}
	,
	eventKeyup : function(_e){
		// Key nicht DOWN / UP / TAB / ENTER
		if(_e.keyCode != "40" && _e.keyCode != "38" && _e.keyCode != "9" && _e.keyCode != "13"){
			// Input einlesen & verarbeiten
			this.getBegriff();
			// Vorschlag generieren
			this.getVorschlag(this.strSuchwort);
		}
	}
	,
	eventFocus : function(_e){
		if(this.listenFocus){
			// Input einlesen & verarbeiten
			this.getBegriff();
			// Vorschlag generieren
			this.getVorschlag(this.strSuchwort);
		}
	}
	,
	eventMouseoverListe : function(_e){
		this.pos = _e.target.id.substr(this.id.length+3);
		this.selectEintrag(this.pos);
	}
	,
	eventClickListe : function(_e){
		this.listenFocus = false;
		$("#"+this.id).focus();
		this.setVorschlag();
	}
	,
	eventClickSubmit : function(_e){
		var tmp = $("#"+this.id).val();
		this.loadSuche(tmp);
		$("#"+this.id+"_vorschlag").val("");
		this.resetVorschlag();
		this.listenFocus = false;
		$("#"+this.id).focus();
		return false;
	}
	,
	eventClickReset : function(_e){
		$("#"+this.id).val("");
		$("#"+this.id+"_vorschlag").val("");
		this.loadSuche("");
		this.hideReset();
		this.resetVorschlag();
		this.listenFocus = false;
		$("#"+this.id).focus();
		return false;
	}
	,
	eventClickBody : function(_e){
		if(_e.target.id != this.id && _e.target.id != this.id+"_vorschlag" && _e.target.id != this.id+"_submit" && _e.target.id != this.id+"_reset" && _e.target.parentNode.id != this.id+"_liste"){
			$("#"+this.id+"_vorschlag").val("");
			this.hideListe();
			this.listenFocus = true;
		}
	}
	,
	getBegriff : function(){
		var tmp = $("#"+this.id).val();
		this.strBegriff = tmp;
		// Reset Button
		if(tmp.length > 0)
			this.showReset();
		else
			this.hideReset();
		// Suchwort herausfiltern
		tmp = tmp.split(",");
		suchwort = this.lTrim(tmp[tmp.length-1]);
		this.strSuchwort = suchwort;
	}
	,
	getVorschlag : function(_begriff){
		// aufruf bei jeder änderung, liste, vorschlagtext anzeigen
		this.listenEnter = false;
		if(_begriff!="" && _begriff.length>1){
			this.getVorschlagListe(_begriff);
		}else{
			// Zuruecksetzen, wenn Input leer
			this.resetVorschlag();
		}
	}
	,
	showListe : function(){
		var tmp = this.strVorschlag;
		$("#"+this.id+"_liste").html(tmp);
		$("#"+this.id+"_liste").css({ "display": "block" });
		// Eventhandler für Vorschlaege
		var obj = this;
		$("#"+this.id+"_liste > li").bind("mouseover", function(e){ obj.eventMouseoverListe(e); });
		$("#"+this.id+"_liste > li").bind("click", function(e){ obj.eventClickListe(e); });
		// CSS Vorschlaege
		$("#"+this.id+"_liste > li").css({"cursor": "pointer"});
	}
	,
	showReset : function(){
		$("#"+this.id+"_reset").css("display", "block");
	}
	,
	hideListe : function(){
		$("#"+this.id+"_liste").css("display", "none");
	}
	,
	hideReset : function(){
		$("#"+this.id+"_reset").css("display", "none");
	}
	,
	selectEintrag : function(_id){
		$("#"+this.id+"_liste > li").removeClass("aktiv");
		$("#"+this.id+"Tv_"+_id).addClass("aktiv");
		$("#"+this.id+"_vorschlag").val(this.strBegriff + $("#"+this.id+"Tv_"+_id).html().substr(this.strSuchwort.length));
		this.strVorschlag = $("#"+this.id+"Tv_"+_id).html();
	}
	,
	setVorschlag : function(){
		var tmp = $("#"+this.id+"_vorschlag").val();
		if(tmp != ""){
			$("#"+this.id).val(tmp + ", ");
		}else{
			tmp = $("#"+this.id).val();
			$("#"+this.id).val(tmp + ", ");
		}
		this.resetVorschlag();
	}
	,
	resetVorschlag : function(){
		this.hideListe();
		$("#"+this.id+"_liste").html("");
		this.pos = -1;
		this.anz = 0;
		this.strBegriff = "";
		this.strSuchwort = "";
		this.strVorschlag = "";
		this.strListe = "";
	}
	,
	lTrim : function(text){
		// trim Links, vlg. jQuery 1.4.2
		var trim = /^(\s|\u00A0)+/g;
		return (text || "").replace(trim, "");
	}
	,
	initData : function(){
		// spezifisch überschreiben (Daten in this.data laden, format JSON)
	}
	,
	loadSuche : function(_begriff){
		// spezifisch überschreiben (Suche absenden, Rückgabe anzeigen)
	}
	,
	getVorschlagListe : function(_begriff){
		// spezifisch überschreiben (Aufruf bei jeder änderung evt. liste, vorschlagtext anzeigen)
	}
}


// textvorschlag (multi)
kwTextvorschlagMulti = function(_id, _obj, _objId, _meth){
	// Definitionen
	var id; // html id von suchfeld
	var pos; // auswahl position
	var anz; // anzahl treffer
	var strBegriff; // ganzes Such-Pattern
	var strSuchwort; // letztes suchwort
	var strListe; // Vorschlagliste HTML
	var listenFocus; // flag Focus Listener
	var ajaxObjekt;
	var ajaxObjektId;
	var ajaxMethode;
	// Defaultwerte
	this.id = "tvmulti";
	this.pos = -1;
	this.anz = 0;
	this.strBegriff = "";
	this.strSuchwort = "";
	this.strListe = "";
	this.listenFocus = false;
	this.ajaxObjekt = "";
	this.ajaxObjektId = 0;
	this.ajaxMethode = "";
	// Uebergabe einlesen
	if(_id!=undefined && _id!=null) this.id = _id;
	if(_obj!=undefined && _obj!=null) this.ajaxObjekt = _obj;
	if(_objId!=undefined && _objId!=null) this.ajaxObjektId = _objId;
	if(_meth!=undefined && _meth!=null) this.ajaxMethode = _meth;
}
kwTextvorschlagMulti.prototype = {
	// Initialisierung
	init : function(){
		// Einfuegen Layer & Liste
		$("#"+this.id).wrap($("<div/>", {id:this.id+"_layerS"}));
		$("#"+this.id).after($("<ul/>", {id:this.id+"_liste", "class":"kwMultiListe"}));
		// Eventhandler binden
		var obj = this;
		$("#"+this.id).bind("keydown", function(e){ obj.eventKeydown(e); });
		$("#"+this.id).bind("keyup", function(e){ obj.eventKeyup(e); });
		$("#"+this.id).bind("focus", function(e){ obj.eventFocus(e); });
		$("body").bind("click", function(e){ obj.eventClickBody(e); });
	}
	,
	eventKeydown : function(_e){
		if(_e.keyCode == "13"){
			// Key ENTER
			_e.preventDefault();
			if(this.pos != -1){
				this.setVorschlag();
			}
		}else if(_e.keyCode == "40"){
			// Key DOWN
			_e.preventDefault();
			if(this.pos == -1 || this.pos == this.anz-1){
				this.selectEintrag(0);
				this.pos = 0;
			}else{
				this.selectEintrag(++this.pos);
			}
		}else if(_e.keyCode == "38"){
			// Key UP
			_e.preventDefault();
			if (this.pos == -1 || this.pos == 0){
				this.selectEintrag(this.anz-1);
				this.pos = this.anz-1;
			}else{
				this.selectEintrag(--this.pos);
			}
		}else if(_e.keyCode == "27"){
			// Key ESC
			_e.preventDefault();
			$("#"+this.id).val("");
			this.resetVorschlag();
		}
	}
	,
	eventKeyup : function(_e){
		// Key nicht DOWN / UP / ENTER / ESC
		if(_e.keyCode!="40" && _e.keyCode!="38" && _e.keyCode!="13" && _e.keyCode!="27"){
			// Input einlesen & verarbeiten
			this.getBegriff();
			// Vorschlag generieren
			this.getVorschlag(this.strSuchwort);
		}
	}
	,
	eventFocus : function(_e){
		if(this.listenFocus){
			// Input einlesen & verarbeiten
			this.getBegriff();
			// Vorschlag generieren
			this.getVorschlag(this.strSuchwort);
		}
	}
	,
	eventMouseoverListe : function(_e){
		this.pos = _e.target.id.substr(this.id.length+3);
		this.selectEintrag(this.pos);
	}
	,
	eventClickListe : function(_e){
		this.listenFocus = false;
		$("#"+this.id).focus();
		this.setVorschlag();
	}
	,
	eventClickBody : function(_e){
		if(_e.target.id!=this.id && _e.target.parentNode && _e.target.parentNode.id!=this.id+"_liste"){
			this.hideListe();
			this.listenFocus = true;
		}
	}
	,
	getBegriff : function(){
		var tmp = $("#"+this.id).val();
		tmp = tmp.split(",");
		// Begriff aufstellen
		this.strBegriff = "";
		for(i=0; i<tmp.length-1; i++){
			this.strBegriff += this.lTrim(tmp[i])+", ";
		}
		// Suchwort herausfiltern
		suchwort = this.lTrim(tmp[tmp.length-1]);
		this.strSuchwort = suchwort;
	}
	,
	getVorschlag : function(_begriff){
		// aufruf bei jeder änderung, liste anzeigen
		if(_begriff!="" && _begriff.length>1){
			this.getVorschlagListe(_begriff);
		}else{
			// zuruecksetzen, wenn input leer
			this.resetVorschlag();
		}
	}
	,
	getVorschlagListe : function(_begriff){
		var obj = this;
		// ajax abfrage
		$.post("ajaxFormSetData.php", { objtyp: obj.ajaxObjekt,	id: obj.ajaxObjektId, f: obj.ajaxMethode, v1: _begriff}, function(data){
			if(data.substr(0,2) == "OK"){
				// berechnung treffer
				var treffer = $.parseJSON(data.substr(2));
				// ausgabe vorschlagliste
				if(treffer.length>0){
					var innerListe = "";
					// Liste generieren
					for(i=0; i<treffer.length; ++i){
						if(treffer[i].w!=undefined){
							innerListe += "<li id=\""+obj.id+"Tv_"+i+"\" title=\""+treffer[i].w+"\">"+treffer[i].v+"</li>";
						}else{
							innerListe += "<li id=\""+obj.id+"Tv_"+i+"\">"+treffer[i].v+"</li>";
						}
					}
					obj.anz = treffer.length;
					obj.pos = -1;
					obj.strListe = innerListe;
					obj.showListe();
				}else{
					obj.resetVorschlag();
				}
			}
		});
	}
	,
	showListe : function(){
		var tmp = this.strListe;
		$("#"+this.id+"_liste").html(tmp);
		$("#"+this.id+"_liste").css({ "display": "block" });
		// Eventhandler für Vorschlaege
		var obj = this;
		$("#"+this.id+"_liste > li").bind("mouseover", function(e){ obj.eventMouseoverListe(e); });
		$("#"+this.id+"_liste > li").bind("click", function(e){ obj.eventClickListe(e); });
		// CSS Vorschlaege
		$("#"+this.id+"_liste > li").css({"cursor": "pointer"});
	}
	,
	hideListe : function(){
		$("#"+this.id+"_liste").css("display", "none");
	}
	,
	selectEintrag : function(_id){
		$("#"+this.id+"_liste > li").removeClass("aktiv");
		$("#"+this.id+"Tv_"+_id).addClass("aktiv");
		if($("#"+this.id+"Tv_"+_id).is("[title]")){
			this.strSuchwort = $("#"+this.id+"Tv_"+_id).attr("title");
		}else{
			this.strSuchwort = $("#"+this.id+"Tv_"+_id).html();
		}
	}
	,
	setVorschlag : function(){
		$("#"+this.id).val(this.strBegriff + this.strSuchwort + ", ");
		this.resetVorschlag();
	}
	,
	resetVorschlag : function(){
		this.hideListe();
		$("#"+this.id+"_liste").html("");
		this.pos = -1;
		this.anz = 0;
		this.strBegriff = "";
		this.strSuchwort = "";
		this.strListe = "";
	}
	,
	lTrim : function(text){
		// trim Links, vlg. jQuery 1.4.2
		var trim = /^(\s|\u00A0)+/g;
		return (text || "").replace(trim, "");
	}
}

