/**
 * Fügt einem Eingabefeld Focus und Blur Eventshandler hinzu.
 * Der Defaultwert des Feldes wird onFocus gemerkt und onBlur wiederhergstellt.
 *
 * @param String elem Eingebeelement
 * @param String text Standardwert setzen
 * @param Boolean empty_on_submit Standardwert vor Versundung aus Feld löschen
 * @return Object
 *
 * @authors		Martin Widemann
 * @copyright	Copyright 2008 - Netigo GmbH
 * @version		1.1
 * @modified	2008-04-18
 */
function Searchbox(elem, text, empty_on_submit){
	if(elem == void(0)){ throw 'Missing Parameter \'elem\' in Constructor \'Searchbox\'.'; } // if

	var searchbox = document.getElementById(elem);
	searchbox.first = true;
	searchbox.previous = null;

	if(text){
		searchbox.value = text;
	} // if

	if(empty_on_submit){
		searchbox.form.onsubmit = function(){
			if(searchbox.first && !searchbox.previous){
				searchbox.value = '';
			} // if
		} // function
	} // if

	searchbox.onfocus = function(){
		if(this.first && !this.previous){
			this.previous = this.value;
		}

		if(this.value == this.previous){
			this.value = '';
		}

		this.first = false;
	}
	
	searchbox.onblur = function(){
		if(this.value == ''){
			this.value = this.previous;
		}
	}

	return searchbox;
} // class
