
	Message.load("direkt", "index.suchen.");
	windowOnLoad.add('Suche.init()');	


	var Suche = {
		init: function() {
			//////////////////////////
			// BEI ENTER SUCHE STARTEN
			//////////////////////////
			document.body.select("select").each(function(s) {
				s.observe("keypress", function(e) {
					if(e.keyCode == Event.KEY_RETURN) {
						this.form.submit();
					}
				});
			});
			
		
			$$("[name=liegeplatz]", "[name=plz]", "[name=umkreis]").invoke("observe", "change", Suche.checkUmkreis);			
			this.checkUmkreis();
			
			
			/////////////////////////	
			// AUTOVERFOLLSTÄNDIGUNG 
			/////////////////////////
			if($("textsuche"))
			$("textsuche").observe('keyup', function(e) {
				var laenge = $("textsuche").value.length;
				var anfrage = $("textsuche").value;
				
				if(laenge % 3 == 0 && laenge != 0) {										
					var typ = $$('input[name="typ"]')[0].value;
										
					new Ajax.Request("/ajax/ajax.suche.werften.php", {
						postBody: "typ=" + typ + "&suche=" + anfrage,
						
						onSuccess: function(r) {
							if(r.responseText != "false") {							
								if(!$("volltext")) {
									Suche.create();	
								}
								
								$("werftenlist").update(r.responseText);
							}
						}
					});					
				}
				
				if($("volltext") && laenge < 1) {
					Suche.kill();
				}
			});
			
			if(suchparams == "false") {
				return false;
			}
			
			
			
			fillForm(Global.suchparams);
		},
		
		
		checkUmkreis: function() {		
			if($$("[name=liegeplatz]")[0].value.empty()) {
				$$("[name=plz]", "[name=umkreis]").each(function(elem) {
					elem.disable();
					elem.setStyle({
						opacity: 0.5
					});
				});
			}
			else {
				$$("[name=plz]", "[name=umkreis]").each(function(elem) {
					elem.enable();
					elem.setStyle({
						opacity: 1
					});
				});
			}
		},
		
		
		checkDirekt: function(nr) {
			var pat = /[\D]/;
			
			if(pat.test(nr) || nr.empty()) {
				Message.post("direkt");
				return false;
			}
			
			return true;
		},
		
		
		kill: function() {
			$("volltext").remove();	
		},
		
		create: function() {
			var textpos = $("textsuche").cumulativeOffset();
			var textleft = parseInt(textpos.left) - 214;
			var texttop = parseInt(textpos.top);
			
			
			var div = Builder.node("div", {id: "volltext"}, [
						Builder.node("div", {className: "werften"}, [
							Builder.node("span", {onclick: "Suche.kill()", className: "werftenclose"}, "x")
						]),
						Builder.node("div", {id: "werftenlist"}, "werften")
			]);
			
			Element.extend(div);
			
			div.setStyle({
				position: "absolute",
				backgroundColor: "#F3F6FC",
				top: texttop + "px",
				left: textleft + "px",
				width: "200px",
				zIndex: "9999"
			});
			
			document.body.appendChild(div);				
		    
		},
		
		insert: function(wname) {
			$("textsuche").value = wname;
			this.kill();
		}
	};