
function ValidateForm(form) {
	var valid = true;
	var msg = "";
	
	// loop through all of the form elements
	for (var i = 0; i < form.elements.length; i++) {
		// check to see if the class name contains "required"
		if (form.elements[i].className.indexOf("required") != -1) {
			// check to see if the field has a value
			if (form.elements[i].value === "") {
				valid = false;
				// get the label text
				var labelText = $("label[for='" + form.elements[i].id + "']").text();
				msg += "Please provide a value for '" + labelText + "'.\n";
			}
		}
	}
	
	// if the form is not valid, display alert message
	if (!valid) alert(msg);
	
	return valid;
}

function CheckForms() {
	// get each form that contains the class "validate", then call ValidateForm()
	$(".validate").bind("submit", function () { return ValidateForm(this); });
}

$(document).ready(function(){
	CheckForms();
});
