

function validateform() {
    valid = true;
	errormsg = "Please complete the following fields: \n";
	var formName = validateform.arguments[0];
	for(i=1; i < validateform.arguments.length; i=i+2) {
    	var fieldName = validateform.arguments[i];
		var displayName = validateform.arguments[i+1];
		//alert (eval("document."+formName+"."+fieldName+".type"));
		if ((eval("document."+formName+"."+fieldName+".type") == "text") || (eval("document."+formName+"."+fieldName+".type") == "select-one")) {
			if (eval("document."+formName+"."+fieldName+".value") == "") {
				valid = false;
				errormsg += displayName + "\n";
			}
			
			//Check to ensure a valid email address has been entered
			if (fieldName == "email") {
				var emailFilter = /^.+@.+\..{2,3}$/;
				var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
				emailAddress = eval("document."+formName+"."+fieldName+".value");
				if (!(emailFilter.test(emailAddress))) { 
					valid = false;
					errormsg += "Please Enter a Valid Email Address\n";
				}
				if (emailAddress.match(illegalChars)) {
					valid = false;
					errormsg += "Please Check your email address, it contains illegal characters.\n";
				}
			}
			//Check for valid second email address matches first email address
			if (fieldName == "email2") {
				emailAddress2 = eval("document."+formName+"."+fieldName+".value");
				if (!(emailAddress2 == emailAddress)) { 
					valid = false;
					errormsg += "Please ensure your confirmation email address matches your email address.\n";
				}
			}
		} else if ((eval("document."+formName+"."+fieldName+".type") == "password")) {
			if (fieldName == "password") {
				firstpassword = eval("document."+formName+"."+fieldName+".value");
				secondpassword = eval("document."+formName+"."+"password2"+".value");
				if (firstpassword != secondpassword) {
					valid = false;
					errormsg += "Passwords do not match" + "\n";
				}

			}


		} else {
			var btn = valButton1(eval("document."+formName+"."+fieldName+""));
			if (btn == null) {
				valid = false;
				errormsg += displayName + "\n";
			} else {
				//alert('Button value ' + btn + ' selected'); 
			}
		}
	}


	// var sessions = validateSessions(formName);
	//Override for form without sessions
	var sessions = true;
	
	//alert(sessions);
	if (!sessions) {
		valid = false;
		errormsg += "Select one session from each group" + "\n";	
	}


	if (valid == false) {
		alert(errormsg);
	}
    return valid;
}





function validateSessions(formName) {
	/*
	validsess = true;

	var thisform = formName;
	//alert(thisform);

	for ( var z in radio_groups ){
		myradiobutton = radio_groups[z];
		if (getSelectedRadio(eval("document."+thisform+"."+myradiobutton+"")) == -1) {
			validsess = false;
		}
	}

	for (i=0;i<check_groups.length; i++) {
		$checked = false;
		for (b=0;b<check_groups[i].length; b++) {
			var chks = document.getElementsByName('sess['+check_groups[i][b]+']');
			if (chks[0].checked){
				$checked = true;
			}
		}
		if (!$checked) {
			validsess = false;
		}
	}
	return validsess;
	*/
}
// JavaScript Document
