function CheckForm(formid){

	var fieldsArray = new Array();



	/* ############### EDIT THESE VARIABLES FOR ENQUIRY FORM... ########################################### */

	/* list of names of all fields that need validating and their associated labels (as they should appear in alert box) */
	fieldsArray["name"] = "Name";
	fieldsArray["email"] = "Email";
	fieldsArray["message"] = "Enquiry";

	var emailfieldsArray = new Array(
		/* comma-separated list of names of all email fields that need validating */
		"email"
	);

	var selectfieldsArray = new Array(
		/* comma-separated list of names of all select fields that need validating */
		/* The value of the "-- Select one --" item in the list should be set to "select" for this to work */
	);

	var radiofieldsArray = new Array(
		/* comma-seperated list of all radio groups that need validating */
	);

	/* #################################################################################################### */




	var alertmessage = "";
	var radio_fieldname = "";
	var radio_selected_flag = 0;

	//Loop through each form field and for each field...
	for (var i=0; i < document.getElementById(formid).length; i++) {


		//If an unselected radio button was detected during the last iteration of the loop (see end of loop code)...
		if (radio_fieldname != "") {

			//if the loop has moved past the last radio button in the named group...
			if (radio_fieldname != document.getElementById(formid).elements[i].name) {

				//If flag shows that no radio buttons in the group were selected...
				if (radio_selected_flag == 0) { //create error text
					alertmessage += '- ' + fieldsArray[radio_fieldname]  + '\n';
				}
				else { //a radio button was selected, so simply set flag back to 0 and move on.
					radio_selected_flag = 0;
				}

				//reset fieldname
				radio_fieldname = "";

			}
		}


		//...loop through each field in the array of fields to validate.
		for (var array_item in fieldsArray) {

			//If the current form field is in the array of fields to validate...
			if (document.getElementById(formid).elements[i].name == array_item) {

				//...check if field value is blank.
				if(document.getElementById(formid).elements[i].value == "") {

					alertmessage += '- ' + fieldsArray[array_item]  + '\n';

				}
				//If it's not blank...
				else {



					//...loop through the array of email fields.
					for (var j=0; j < emailfieldsArray.length; j++) {

						//If the current field exists in the array of email fields...
						if (emailfieldsArray[j] == array_item) {

							//...validate the email address.
							var email = document.getElementById(formid).elements[array_item].value;
							invalidChars = " /:,;?()"
							incorrect ='';
							for (k=0; k<invalidChars.length; k++){
								badChar = invalidChars.charAt(k)
								if(email.indexOf(badChar,0) > -1){
									incorrect += '- Invalid Email Address\n';
									break;
								}
							}
							atPos = email.indexOf("@",1)
							if(atPos == -1){
								incorrect += '- Invalid Email Address\n';
							}
							if(email.indexOf("@",atPos+1) > -1){
								incorrect += '- Invalid Email Address\n';
							}
							periodPos = email.indexOf(".",atPos)
							if(periodPos == -1){
								incorrect += '- Invalid Email Address\n';
							}
							if(periodPos+3 > email.length){
								incorrect += '- Invalid Email Address\n';
							}
							if(incorrect != ''){
								alertmessage += '- Invalid Email Address\n';
							}

						}

					}


					//...loop through the array of select fields.
					for (var j=0; j < selectfieldsArray.length; j++) {

						//If the current field exists in the array of select fields...
						if (selectfieldsArray[j] == array_item) {

							//...validate the select field
							if(document.getElementById(formid).elements[i].value == "select") {

								alertmessage += '- ' + fieldsArray[array_item]  + '\n';

							}

						}

					}


					//...loop through the array of radio fields.
					for (var k=0; k < radiofieldsArray.length; k++) {

						//If the current field exists in the array of radio fields...
						if (radiofieldsArray[k] == array_item) {

							//...and the radio button isn't selected...
							if(document.getElementById(formid).elements[i].checked == false) {

								//...set the value of radio_fieldname variable to the name of the current form field
								radio_fieldname = array_item;

								//this is checked at the start of the next iteration of the main loop and action taken if necessary

							}
							else {
								radio_selected_flag = 1; //create a flag to show that one of the radio buttons is selected
							}

						}

					}



				}

			}

		}

	}

	if(alertmessage == ""){
		return true;
	}
	else{
		TopMessage = "You have not entered the following form elements correctly: \n\n";
        BottomMessage = "\nPlease correct these fields to continue";
        alertmessage = TopMessage + alertmessage + BottomMessage;
        alert(alertmessage);
		return false;
	}
}