function BasicFormValidator() {} // Constructor

// Default values for the BasicFormValidator class
BasicFormValidator.prototype.first_run = true;
BasicFormValidator.prototype.error_heading = "<h3>Oops</h3>";
BasicFormValidator.prototype.error_body = "<p>Something's not right. Please check the following errors and re-submit the form.</p>";
BasicFormValidator.prototype.show_error_list = true;
BasicFormValidator.prototype.show_form_message = true;
BasicFormValidator.prototype.required_fields = [];

// Class methods
BasicFormValidator.prototype.validate = function(evt, target_form) {
	var loop_count, loop_length, form_id, form_error_id;
	var form_errors, form_field;
	var form_error_message, error_list, field_label;
	
	// Check that we have the bare essentials
	if (!target_form) return;
	if (!this.required_fields) return;
	
	form_id = $(target_form).attr("id");
	form_error_id = form_id + "_error"; 
	
	// Clear any existing form errors
	if (!this.first_run) {
		$("div.field_error", target_form).removeClass("field_error");
		$("div").remove("#" + form_error_id);
	} // if
	
	// Check for any form errors
	loop_length = this.required_fields.length;
	form_errors = [];
	
	for (loop_count = 0; loop_count < loop_length; loop_count++) {
		form_field = $("#" + this.required_fields[loop_count])[0];
		if (form_field) {
			if (form_field.value == "") form_errors.push(this.required_fields[loop_count]);
		} // if
	} // for
	
	// If we have any errors, now is the time to do something about them
	if (form_errors.length > 0) {
	
		// Create the form message div, if required
		if (this.show_form_message) {
			form_error_message = document.createElement("div");
			$(form_error_message).attr("id", form_error_id);
			$(form_error_message).addClass("form_error");
			
			$(form_error_message).append(this.error_heading);
			$(form_error_message).append(this.error_body);		
		} // if
		
		// Create the error list, if required
		if (this.show_form_message && this.show_error_list) {
			error_list = document.createElement("ul");
			$(error_list).addClass("nav_list");
		} // if
		
		// Loop through the errors
		loop_length = form_errors.length;
		for (loop_count = 0; loop_count < loop_length; loop_count++) {
			field_wrapper = $("#" + form_errors[loop_count])[0];
			field_wrapper = $(field_wrapper).parent("div");
			field_wrapper.addClass("field_error");
			
			// Add an item to the error list, if required
			if (this.show_form_message && this.show_error_list) {
				field_label = $(field_wrapper).children("label")[0];
				field_label = field_label ? field_label.firstChild.nodeValue : "Unknown field name";
			
				$(error_list).append("<li><a href=\"#" + form_errors[loop_count] + "\" title=\"Jump to the '" + field_label + "' form field\">" + field_label + "</a></li>");
			} // if
		} // for
		
		// Append the list to the form error message, and the form error message to the document tree, if required
		if (this.show_form_message) {
			if (this.show_error_list) $(form_error_message).append(error_list);
			$(target_form).before(form_error_message);
			if (this.first_run) $(form_error_message).slideDown("slow");
		} // if
		
		// Prevent the default form submission from firing
		evt.preventDefault();
		
		this.first_run = false;
	} // if
} // validate
