function validateForm(form) {
if(typeof(form)=="undefined"){form=0;}
	
	var i;
	var txt = "";
	radChecked = new Array();
	var el = document.forms[form].elements;

	for (i = 0; i < el.length; i++) {

		if (el[i].title != "") {

			if (el[i].type == "radio") {

				var found = false;

				var radiogroup = el[el[i].name];

				for (x = 0; x < radChecked.length; x++) {

					if (radChecked[x] == radiogroup)

						found = true;

				}

				if (!found) {

					var btn = valButton(radiogroup);

					if (btn == null) {

						radChecked[radChecked.length + 1] = radiogroup;

						txt += el[i].title + "\n";

					}

				}

			}

			else if (el[i].value == "") {

				txt += el[i].title + "\n";

			}

		}

	}

	if (txt != "") {

		alert("Please complete the following fields: \n\n" + txt)

		return false;

	}

	else {

		// now ensure that the email address works					

		var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";

		var regex = new RegExp(emailReg);

		if (regex.test(document.forms[form].CTCT_EMAILADDRESS.value)) {

			//Compare to second address

			if (document.forms[form].CTCT_EMAILADDRESS.value !=

					document.forms[form].CTCT_EMAILADDRESS_COMP.value) {

					alert("Comparison email address does not match.");

					return false;

			}

					

			return true;

		}

		else {

			alert("Please enter a valid E-mail address.");

			return false;

		}

	}

}

function checkMaxLength() {

	var txt = "";

	var el = document.forms[form].elements;

	for (i = 0; i < el.length; i++) {

		if (el[i].type == "text") {

			if (el[i].value.length > el[i].maxLength) {

				txt += el[i].id + "\n";

			}

		}

	}

	if (txt != "")

		txt = "The following fields exceed maximum characters allowed.\n\n" + txt;

	return txt;

}

function valButton(btn) {

	var cnt = -1;

	for (var i = btn.length - 1; i > -1; i--) {

		if (btn[i].checked) { cnt = i; i = -1; }

	}

	if (cnt > -1) return btn[cnt].value;

	else return null;

}

