
function isUndefined(a) {
    return typeof a == "undefined";
} 

function checkWholeForm(formobj) {
	var errorMsg = "";
	var numErrors = 0;
	var EmailError = "A valid e-mail address must contain both '@' and '.'";
	
	if (isUndefined(window.SetLanguage)) {
		SetLanguage = "english";
	}
	if (SetLanguage == "gaelic") {
		var EmailError = "Seōladh post-d slān";
	}

	for (var i=0; i < fieldRequired.length; i++) {
		var obj = formobj.elements[fieldRequired[i]];
		if (obj) {
			if (obj.type == "checkbox") {
				if (!obj.checked) {
					errorMsg += ' - ' + fieldDescription[i] + '\n'; numErrors++;
				}
			} else if (obj.type == "select-one") {
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].value == "") {
					errorMsg += ' - ' + fieldDescription[i] + '\n'; numErrors++;
				}
			} else if (obj.type == "select-multiple") {
				if (obj.selectedIndex == -1) {
					errorMsg += ' - ' + fieldDescription[i] + '\n'; numErrors++;
				}
			} else if (obj.type == "text" || obj.type == "textarea") {
				if (obj.value == "" || obj.value == null) {
					errorMsg += ' - ' + fieldDescription[i] + '\n'; numErrors++;
				} else if (SelectEmail[i] == 1 && (obj.value.indexOf('@') == -1 || obj.value.indexOf('.') == -1)) {
					errorMsg += ' - ' + EmailError + '\n'; numErrors++;
				}
			} else {
				if (SelectRadio[i] == 1) {
					var radio_choice = 0;
					for (m = 0; m < obj.length; m++) {
						if (obj[m].checked) {
							radio_choice = 1;
						}
					}
					if (radio_choice == 0) {
						errorMsg += ' - ' + fieldDescription[i] + '\n'; numErrors++;
					}
				} else if (SelectCheck[i] == 1) {
					var checkbox_choice = 0;
					for (m = 0; m < obj.length; m++) {
						if (obj[m].checked) {
							checkbox_choice = 1;
						}
					}
					if (checkbox_choice == 0) {
						errorMsg += ' - ' + fieldDescription[i] + '\n'; numErrors++;
					}
				} else if (obj.value == "" || obj.value == null) {
					errorMsg += ' - ' + fieldDescription[i] + '\n'; numErrors++;
				}
			}
		}
	}

	if (numErrors > 0) {
		if (SetLanguage == "gaelic") {
			errorMessage = '\nLėon' + ((numErrors > 1) ? 'aibh na beārnan' : ' an beārn') + ' a tha aleantainn, ma se ur toil e:\n' + errorMsg;
		} else {
			errorMessage = '\nPlease complete the following field' + ((numErrors > 1) ? 's:\n' : ':\n') + errorMsg;
		}
		alert(errorMessage);
		return false;
	}
    return true;
}
