function checkForm(terms) {

	var theform = document.forms['theform'];
	var i;
	var field;
	var error;
	var count=0;
	
	/* Look at all the elements of the form and pull out the Required Fields */
	
	var a = new Array; // Where our required fields will be stored

	for (i=0;i<theform.length;i++) { // Loop through all the elements of the form
			
		if(theform.elements[i]["id"]=='required') { // Found a required field!
			a[count] = theform.elements[i]["name"]; // Store it for now (we`ll check it later)
			count = (count+1);
		}
		
		if(theform.elements[i]["name"]=='terms_agreed')
			termsAgreed = theform.elements[i];
	}
	
	/* Go through our Required fields and check that none of them have been left empty */ 
	
	for (i = a.length-1; i>=0; i--) { // Loop through the required fields
			
		field = a[i];
			
		if (theform[field].value=='') { // This required field is empty!
			
			// Flag the field to the user
			document.all['_'+field].innerHTML = '<font color=red>Required field incomplete</font>';
			error = true; // We are now destined to return false!
		} else // This required field is complete...
			document.all['_'+field].innerHTML = ''; // Make sure this is not flagged as incomplete
	}

	if (error==true) // We`ve found incomplete fields!
		return false;
	
	// Do we need to check that terms and conditions have been agreed upon?
	if (terms=='check_terms') {
		
		if (termsAgreed["checked"]!=true) {
		
			alert('You must check the checkbox to indicate that you agree to our Terms & Conditions.');
			return false;
		}
	}
	// Everything is OK!
	return true;
}
