var arrWebFormsTypes = new Array("TextField", "TextArea", "ComboBox", "RadioButton", "CheckBox");

function sendForm(intForm){
	objForm = document.frmWebForm;
	strError = "";
	blnErrorFound = false;
	objDivError = document.getElementById('divErrorWebForm');

	for (i = 0; i < arrWebFormFields.length && !blnErrorFound; i++){
		/* Check obligatory */
		objField = eval("objForm." + arrWebFormFields[i][1]);
		strValue = "";

		if (arrWebFormFields[i][3] == 1 || arrWebFormsTypes[arrWebFormFields[i][2]] == "ComboBox"){
			switch (arrWebFormsTypes[arrWebFormFields[i][2]]){
				case "TextField":
				case "TextArea":
					strValue = objField.value;
					break;
				case "ComboBox":
					strValue = objField.options[objField.selectedIndex].value;
					break;
				case "RadioButton":
				case "CheckBox":
					strValue = objField.value;
					break;
			}

			if (strValue == "" || strValue == "0"){
				strError = arrWebFormFields[i][0] + " muss ausgefüllt werden!";
				blnErrorFound = true;
			}
		}
	}

	if (strError){
		objDivError.innerHTML = strError;
	}else{
		objDivError.innerHTML = "Daten werden gesendet...Bitte warten";
		sendWebFormEmail(intForm);
	}
}

function sendWebFormEmail(intForm){
	objAjax = Ajax();
	objForm = document.frmWebForm;
	objDivError = document.getElementById('divErrorWebForm');

	/* Parse Data */
	strURL = "webforms_send.php?intForm=" + intForm + "&";
	for (i = 0; i < arrWebFormFields.length && !blnErrorFound; i++){
		strURL += arrWebFormFields[i][1].replace(/ /g, '_');
		objField = eval("objForm." + arrWebFormFields[i][1]);
		switch (arrWebFormsTypes[arrWebFormFields[i][2]]){
			case "TextField":
			case "TextArea":
				strValue = objField.value;
				break;
			case "ComboBox":
				strValue = objField.options[objField.selectedIndex].value;
				break;
			case "RadioButton":
				strValue = (objField.selected) ? "selected" : "";
				break;
			case "CheckBox":
				strValue = (objField.checked) ? "checked" : "";
				break;
		}
		strURL += "=" + strValue + "&";
	}

	/* Send Data */
	objAjax.open("GET", strURL, true);
	function HttpRequest(){
		if (objAjax.readyState == 4){
			if (objAjax.responseText == "OK"){
				objDivError.innerHTML = (arrConfirmationMessages[intForm] != "") ? arrConfirmationMessages[intForm] : 'Formular erfolgreich versendet!';
				/* Clear all fields */
				for (i = 0; i < arrWebFormFields.length && !blnErrorFound; i++){
					objField = eval("objForm." + arrWebFormFields[i][1]);
					switch (arrWebFormsTypes[arrWebFormFields[i][2]]){
						case "TextField":
						case "TextArea":
							objField.value = "";
							break;
						case "ComboBox":
							objField.selectedIndex = 0;
							break;
						case "RadioButton":
							objField.selected = false;
							break;
						case "CheckBox":
							objField.checked = false;
							break;
					}
				}
			}else{
				objDivError.innerHTML = 'Form cannot be sended. Please retry.';
			}
		}
	};
	objAjax.onreadystatechange = HttpRequest;
	objAjax.send(null);
}

