/**
 * This file contains the validation functions for the volunteer form.
 *
 * @author Daniel J. Summers <daniel@djs-consulting.com>
 * @version $Id: volunteer.js 222 2010-02-27 23:31:19Z summersd $
 * @package TCMS
 * @subpackage View
 */
var tcmsVolunteer = {

	/**
	 * Show or hide the row of "day of week" checkboxes based on whether the "Weekly"
	 * availability box is selected.
	 */
	showHideDayOfWeek : function() {
		if ($("#chkAvailability1").is(":checked")) {
			// Show it - weekly availability is checked.
			$("#tblDayOfWeek").fadeIn();
		}
		else {
			// Hide it - weekly availability is not checked.
			$("#tblDayOfWeek").fadeOut();
		}
	},

	/**
	 * This function validates the input data for the volunteer to ensure that is complete.
	 *
	 * @return boolean False if there's an error, true otherwise.
	 */
	validateVolunteer : function() {
	
		// First name must be input.
		if (!tcms.validateString("txtFirstName", "You must enter your first name.")) {
			return false;
		}
		// Last name must be input.
		if (!tcms.validateString("txtLastName", "You must enter your last name.")) {
			return false;
		}
		// Birthdate must be valid if input.
		if (!tcms.validateStandardDateTime("volBirthdate", "", true, false, true, "Birthdate")) {
			return false;
		}
		// Started Date must be valid if available and input.
		if (0 != $(tcms.jqId("txtvolStartedMonth")).length) {
			if (!tcms.validateStandardDateTime("volStarted", "", true, false, true,
					"Volunteer Started Date")) {
				return false;
			}
		}
		// Contact information must be input.
		if (!tcmsContact.validateContact()) {
			return false;
		}
		// At least one General Availability must be checked.
		if (!tcms.validateOptionGroup("volAvailability[]",
				"You must select a general availability", "lblAvailability", "required")) {
			return false;
		}
		// If "Weekly" availability is checked, at least one weekday must be checked.
		if ($(tcms.jqId("chkAvailability1")).is(":checked")) {
			if (!tcms.validateOptionGroup("volDayOfWeek[]", "You must select a day of the week",
					"lblDayOfWeek",	"required")) {
				return false;
			}
		}
		// At least one Time of Day must be checked.
		if (!tcms.validateOptionGroup("volTimeOfDay[]", "You must select a time of day",
				"lblTimeOfDay", "required")) {
			return false;
		}
		// At least one box under the "How You Can Help" section must be checked.
		if (!tcms.validateOptionGroup("volRequestArea[]",
				"You must select at least one way you can help.\nSurely you can pray?  :)",
				"", "")) {
			return false;
		}
		// The "consent" box must be checked.
		if (!$(tcms.jqId("chkConsent")).is(":checked")) {
			return tcms.errorField("chkConsent", "You must check the \"Consent\" box.");
		}
		else {
			tcms.validField("lblConsent");
		}
		// It's good to go!
		return true;
	}
};
