/* ############################################################################################## */
/* bolay-2011                                                                                     */

/* ********************************************************************************************** */
/* file: all-pageHeadSearch.js                                                                    */
window.addEvent("domready", function() {
	var element = $("pageHeadSearch");
	if (element) {
		var form = {};
		var input = {};
		form.element = element.getElement("form");
		input.element = element.getElement("input[type=text]");
		if (form.element && input.element) {
			input.minLen = 3;
			form.message = "Bitte mindestens " + input.minLen
					+ " Zeichen eingeben.";
			input.element.addEvent("focus", function() {
				if (this.getProperty("value") == this.getProperty("title")) {
					this.setProperty("value", "");
					this.setStyle("text-align", "left");
				}
			});
			input.element.addEvent("blur", function() {
				this.setProperty("value", this.getProperty("value").trim());
				if (this.getProperty("value").length == 0) {
					this.setProperty("value", this.getProperty("title"));
				}
				if (this.getProperty("value") == this.getProperty("title")) {
					this.setStyle("text-align", "center");
				}
			});
			input.element.fireEvent("blur");
			form.element.addEvent("submit", function() {
				input.element.fireEvent("blur");
				var inputValue = input.element.getProperty("value");
				var inputTitle = input.element.getProperty("title")
				if (inputValue == inputTitle
						|| inputValue.length < input.minLen) {
					alert(form.message);
					input.element.focus();
					return false;
				}
			});
		}
	}
});
