	/*--- global variables used by the validation functions below ---*/
		var total_errors;
		var warning;
		
	/*--- display's an error message on a form field when validation fails ---*/
		function displayMessage(message, field_div, error_class){
		
		// set the error class for the form element
			field_div.className = error_class;
			
		// if an error <div> exists, add the new message, otherwise append a new error <div> with the message
			if(document.getElementById(field_div.id+"_error")){
				var existing_error = document.getElementById(field_div.id+"_error");
				existing_error.firstChild.nodeValue = message;
			}else{
				// construct a new <div>, add the error message, and append to the field's parent as a new child element
				var newError = document.createElement('div');
				newError.setAttribute('id', field_div.id+"_error");
				var errorContent = document.createTextNode(message);
				newError.appendChild(errorContent);
				newError.className = 'error';
				field_div.parentNode.appendChild(newError);
			}
		}
		
		
	/*--- encapsulates the validate function so it can be assigned to an onChange function for each element ---*/
		function checkField(){
			validate(this);
		}
		
		
	/*--- validates specific types of form content (phone/fax, postal code, url, email, or basic text) ---*/
		function contentValidation(field){
		
			// validate phone/fax number
				if(/phone|fax/.test(field.id)){
					test = /^\+?[0-9 ()-.]+[0-9]$/.test(field.value);
					warning = "^ This does not appear to be a valid phone number";
					
			// validate zipcode
				}else if(/zip/.test(field.id)){
					test = /^[A-Z0-9 -]+$/.test(field.value);  
					warning = "^ This does not appear to be a valid postal code ";
			
			// validate url
				}else if(/url/.test(field.id)){
					test = /([\w]+)(\.[\w]{2,3}){1,2}$/.test(field.value);
					warning = "^ This does not appear to be a valid website url";
				
			// validate email	
				}else if (/email/.test(field.id)){
					test = /^([\w]+)(.[\w]+)*@([\w]+)(\.[\w]{2,3}){1,2}$/.test(field.value); 
					warning = "^ This does not appear to be a valid email";
			
			// otherwise validate basic text field
				}else{
					test = /[a-zA-z0-9]/.test(field.value);
				}
				
				return test;
		}
		
		
	/*--- checks the status of a field (required/not required) then runs the appropriate validation ---*/
		function validate(field){
			var test = true;
			var empty = false;
			warning = fields[field.id];
			
			// check to see if the field is required
				required = /required/.test(field.id);
			
			// check to see if the field is empty
				if(field.type != "select-one"){
					empty = /^\s*$/.test(field.value);
				}
				
			// if empty & required, validation automatically fails
				if(empty && required){
					test = false
					
			// otherwise validate for appropriate content
				}else if (!empty){     
					
				// first check for select list on default value
					if(field.type == "select-one"){
							if(field.selectedIndex == 0){
								test = false;
							}
					}else{
						test = contentValidation(field);
					}
						
				}
			
			// if the test has failed at any point, display the error message, otherwise hide it
			
			if(!test){
				displayMessage(warning, field, "alert");
				total_errors++;
				return false;
				
			}else{
				displayMessage("", field, "");
				return true;
			}
			
		}
	
	/*--- runs the validate() function above against all fields when form is submitted ---*/
		function validateAll(){
			total_errors = 0;
			
			if(document.getElementById){
				for(field in fields){
					field = document.getElementById(field);
					validate(field);
				}
			}
			if(total_errors > 0){
				alert("some required fields are missing");
				return false;
			}else{
				// alert("all required fields are complete!");
				return true;
			}
		}
		
	/*--- frontpage(?) generated function for adding new options to select lists ---*/
		function CheckForOther (item, origlen){
			var sitem = item.options[item.selectedIndex];
		
			if (item.selectedIndex == (item.length - 1))
				{
				var val = prompt ("ADD A NEW CHOICE:", "");
		
				if (val == null)
					item.selectedIndex = 0;
				else	
					{
					var slen = item.length;
		
					if (slen == origlen+1){
						item.options[slen] = new Option (sitem.text, sitem.value);
								}
					
					item.options[item.length-2].text = val;
					item.options[item.length-2].value = val;
					item.selectedIndex = item.length-2;
					}
				}
		}