/**
 * Initialiserungen beim Laden der Seite
 */
function initOnLoad () {
	initTextfields();
}

if (document.all) {
	Event.observe(window,'load', function () { initOnLoad(); });	// IE
} else {
	document.observe('dom:loaded', function () { initOnLoad(); });	// andere Browser
}

/**
 * Initialisieren der Textfelder, so dass diese ihre Vorbelegung (Label) entfernen, wenn man hineinklickt
 */
function initTextfields () {
	var tf = $$('input.textfield');
	
	for (var i=0; i<tf.length; i++) {
		if (tf[i].value.length==0) {
			tf[i].addClassName('empty');
		} else {
			tf[i].removeClassName('empty');
		}
		tf[i].observe('focus', textFieldOnFocus);
		tf[i].observe('blur', textFieldOnBlur);
	}
}
function textFieldOnFocus (e) {
	var tf = e.target;
	tf.removeClassName('empty');
}
function textFieldOnBlur (e) {
	var tf = e.target;
	if (tf.value.length==0) {
		tf.addClassName('empty');
	}
}

/**
 * Wechselt zu dem Tab, von dem aus diese Funktion gerufen wurde
 */
function showTab (tab) {	
	var current = $(tab);
	if (current) {
		var tabbox = current.up(1);
		var tabs = tabbox.select('.tabs a');
		var contents = tabbox.select('.tabcontents > div');
		for (var i=0; i<tabs.length; i++) {
			if (tabs[i] == current) {
				tabs[i].blur();
				tabs[i].addClassName('selected');
				if (contents[i]) contents[i].show();
			} else {
				tabs[i].removeClassName('selected');
				if (contents[i]) contents[i].hide();
			}
		}
	}
	return false;
}
