/* form script - version 1.02 - 03.08.2005 */
/* copyright art of vision - multimedia 2004 */

var dF;
var foIniF;
var foSubF;
var foChkInputF=1;

var foLine = "\n";
for (var x=0;x<60;x++) {
	foLine += " -";
}
foLine += "\n\n";

function foIni() {
	dF = document.forms[0];
	for (var foKey in foFieldsH) {
		if (foFieldsH[foKey]["layout"] == "line") {
			foFieldsH[foKey]["layout"] = foLine;
		}
	}
	foIniF=1;
}

function foSub() {

	if (foIniF) {

		var foErrF=0;
		var foEroS="";
		var foCtrlF=1;

		for (var foKey in foFieldsH) {

			var foTyp = foFieldsH[foKey]["type"];
			var foEle = eval('dF.' + foKey);

			if (foTyp == "txt") {
				foFieldsH[foKey]["data"] = foEle.value;
			}
			else if (foTyp == "sel") {
				foFieldsH[foKey]["data"] = foEle.options[foEle.selectedIndex].value;
			}
			else if (foTyp == "chk") {
				if (foEle.checked) {
					foFieldsH[foKey]["data"] = foEle.value;
				}
				else {
					foFieldsH[foKey]["data"] = "";
				}
			}
			else if (foTyp == "rad") {
				for (var x=0;x<foEle.length;x++) {
					if (foEle[x].checked) {
						foFieldsH[foKey]["data"] = foEle[x].value;
						break;
					}
				}
			}

			if (foFieldsH[foKey]["mand"] > 0) {
				if (! foFieldsH[foKey]["data"] || foFieldsH[foKey]["data"] == "") {
					foFieldsH[foKey]["error"] = 1;
					foErrF=1;
				}
				else {
					foFieldsH[foKey]["error"] = 0;
				}
			}
		}

		if (foErrF) {
			var foEroS = "\n\n\nBitte füllen Sie noch folgende Felder aus:\n\n";
			for (var foKey in foFieldsH) {
				if (foFieldsH[foKey]["error"]) {
					foEroS += "\t" + foFieldsH[foKey]["trans"] + "\n";
				}
			}
			foEroS += "\n\n";
			alert(foEroS);
		}

		else {
			if (foFieldsH["EMail"] && ! foChkEmSynt(foFieldsH["EMail"]["data"])) {
				foCtrlF=0;
				alert("\n\nBitte überprüfen Sie die Syntax der E-Mail Adresse!\n\n");
			}
			if (foCtrlF) {
				foFinSub();
			}
		}
	}
}

function foFinSub() {
	var foCtrlF;
	if (! foSubF) {
		var subS = "\nBitte überprüfen Sie Ihre Angaben!\n\n";
		subS += foLine;
		for (var foKey in foFieldsH) {
			if (foFieldsH[foKey]["data"] || foFieldsH[foKey]["mand"] > -1) {
				if (foFieldsH[foKey]["layout"]) {
					subS += foFieldsH[foKey]["layout"];
				}
				if (foKey != "Termin") {
					subS += foFieldsH[foKey]["trans"] + ": " + foFieldsH[foKey]["data"] + "\n";
				}
				else {
					subS += foFieldsH[foKey]["trans"] + ": " + terminDataH[foFieldsH[foKey]["data"] ] + "\n";
				}
			}
		}
		subS += foLine;
		subS += "\n\n";

		if (foChkInputF) {
			foCtrlF = confirm(subS);
		}
		else {
			foCtrlF = 1;
		}
		if (foCtrlF) {
			foSubF = 1;
			dF.submit();
		}
	}
	else {
		alert("\n\nSie haben das Formular bereits abgeschickt.\n\n");
	}
}

function foChkEmSynt(eM) {
	if (eM) {
		var e1 = eM.indexOf("@");
		var e2 = eM.lastIndexOf(".");
		if (e1 > -1 && e2 > -1) {
			var e3 = eM.lastIndexOf("@");
			if (e1 < (e2 - 2) && e1 == e3) {
				var e4 = eM.length;
				if (e1 > 0 && e2 < (e4 - 2) && (e4 - e2 < 6)) {
					return(1);
				}
			}
		}
	}
	return(0);
}


