var defaultBg = "#FFFFFF";
var errorBg = "#f33";

function submitFormData(theForm) {
	document.forms[theForm].Vorname.style.backgroundColor = defaultBg;
	document.forms[theForm].Nachname.style.backgroundColor = defaultBg;
	document.forms[theForm].email.style.backgroundColor = defaultBg;
	document.forms[theForm].Telefon.style.backgroundColor = defaultBg;
	document.forms[theForm].Schule.style.backgroundColor = defaultBg;	
	document.forms[theForm].Schulstufe.style.backgroundColor = defaultBg;
	
	formError = 0;	

	if(document.forms[theForm].Vorname.value.search(reg_name)) {
		document.forms[theForm].Vorname.style.backgroundColor = errorBg;
		formError++;
	}

	if(document.forms[theForm].Nachname.value.search(reg_name)) {
		document.forms[theForm].Nachname.style.backgroundColor = errorBg;
		formError++;
	}
	
	if(document.forms[theForm].Telefon.value.search(reg_telvw)) {
		document.forms[theForm].Telefon.style.backgroundColor = errorBg;
		formError++;
	}

	if(document.forms[theForm].email.value.search(reg_email)) {
		document.forms[theForm].email.style.backgroundColor = errorBg;
		formError++;
	}
	
	if(document.forms[theForm].Schule.value.search(reg_name2)) {
		document.forms[theForm].Schule.style.backgroundColor = errorBg;
		formError++;
	}

	if(document.forms[theForm].Schulstufe.value.search(reg_name2)) {
		document.forms[theForm].Schulstufe.style.backgroundColor = errorBg;
		formError++;
	}

	errorMsg = unescape("Bitte f%FCllen Sie die rot hinterlegten Felder korrekt aus.");
	
	if(formError > 0) {
		alert(errorMsg);
	}
	else {
		updatePage(theForm);
	}		
}

function updatePage(theForm) {
	document.forms[theForm].submit();
}


function validAlk(theForm) {
	defaultBg = "#0097d8";
	document.forms[theForm].kgewicht.style.backgroundColor = defaultBg;
	document.forms[theForm].kgroesse.style.backgroundColor = defaultBg;
	document.forms[theForm].alter.style.backgroundColor = defaultBg;		
	document.forms[theForm].zeit.style.backgroundColor = defaultBg;

	formError = 0;
	listError = "";
	
	if($("#liste").is(':empty')) {
		formError++;
		listError = 'Klicke auf das "+", um Getr%E4nke hinzuzuf%FCgen.\n';
	}
	
	if(document.forms[theForm].kgewicht.value.search(reg_num)) {
		document.forms[theForm].kgewicht.style.backgroundColor = errorBg;
		formError++;
	}

	if(document.forms[theForm].kgroesse.value.search(reg_num)) {
		document.forms[theForm].kgroesse.style.backgroundColor = errorBg;
		formError++;
	}
	
	if(document.forms[theForm].alter.value.search(reg_num)) {
		document.forms[theForm].alter.style.backgroundColor = errorBg;
		formError++;
	}
	
	if(document.forms[theForm].zeit.value.search(reg_num)) {
		document.forms[theForm].zeit.style.backgroundColor = errorBg;
		formError++;
	}	
	
	errorMsg = unescape(listError+"Bitte f%FClle die rot hinterlegten Felder korrekt aus.");
	
	if(formError > 0) {
		alert(errorMsg);
	}
	else {
		berechneform(document.forms[theForm]);
	}		
}
