
/**
 * Validates the content of the fields in the main contact form.
 * Checks for required fields, and checks that text entered in the email field is
 * textually a valid email address (disallowing entry of multiple addresses)
 * 
 * @return true if all fields are valid, false otherwise
 */
function validateForm() {
	
	// get the entered values for the name and email fields
	var name = document.getElementById( "form_name" );
	var email = document.getElementById( "form_email" );
	
	//clear any existing warnings
	clearForm();
	
	var submit = true;
	
	// no name was entered
	if( name.value == "" ) {
		submit = false;
		document.getElementById( "form_label_name" ).className = "important";
		document.getElementById( "form_name_warning" ).innerHTML = "Please enter your name";
	}
	
	//no email was entered
	if( email.value == "" ) {
		submit = false;
		document.getElementById( "form_label_email" ).className = "important";
		document.getElementById( "form_email_warning" ).innerHTML = "Please enter your email address";
	}
	else { //check that it's a 'valid' email address
		
		var mailInfo = email.value.toString();
	    
		//check that the text entered in the email field is a single, properly formatted email address
		if( ( mailInfo.length < 6 ) || 			// minimum length
	    	( mailInfo.indexOf( "," ) >= 0 ) || // no commas (multiple addresses)
	    	( mailInfo.indexOf( ";" ) >= 0 ) || // no semi-colons (multiple addresses)
	    	( mailInfo.indexOf( ":" ) >= 0 ) || // no colons
	    	( mailInfo.indexOf( "/" ) >= 0 ) || // no slashes
	    	( mailInfo.indexOf( " " ) >= 0 ) || // no spaces (multiple addresses)
	    	( mailInfo.indexOf( "@" ) <= 0 ) || // make sure there is an @ symbol
	    	( mailInfo.indexOf( "@" ) != mailInfo.lastIndexOf( "@" ) ) ) // make sure there is only one @ symbol
	    {
	    	submit = false;
			document.getElementById( "form_label_email" ).className = "important";
			document.getElementById( "form_email_warning" ).innerHTML = "Please enter a valid email address";
	    }
	}
	
	return submit;
}

/**
 * Clears any warnings or highlighting for the form fields.
 * 
 * @return
 */
function clearForm() {
	
	//clear any styling classes
	document.getElementById( "form_label_email" ).className = "";
	document.getElementById( "form_label_name" ).className = "";
	
	//clear any warning messages
	document.getElementById( "form_email_warning" ).innerHTML = "";
	document.getElementById( "form_name_warning" ).innerHTML = "";
	
	return true;
}
