$(document).ready(function() {
	// validate signup form on keyup and submit
	var validator = $("#memberapp").validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'You missed 1 field. It has been highlighted below'
					: 'You missed ' + errors + ' fields.  They have been highlighted below';
				$("div.errormsg span").html(message);
				$("div.errormsg").show();
			} else {
				$("div.errormsg").hide();
			}
		},
	
	rules: {
			OrgName: "required",
			NonProfit: "required",
			SeasonofOperation: "required",
			MainPhone: "required",
			PhysicalAddress: "required",
			PhysicalCity: "required",
			PhysicalState: "required",
			PhysicalZipCode: "required",
			pfirstname: "required",
			plastname: "required",
			pjobtitle: "required",
			pphone: "required",
			email: {
				required: true,
				email: true,
			},
			Terms: "required",
			Representative: "required",
			Network: "required",
			Referral: "required"
		},
		messages: {
			OrgName: "",
			NonProfit: "",
			SeasonofOperation: "",
			MainPhone: "",
			PhysicalAddress: "",
			PhysicalCity: "",
			PhysicalState: "",
			PhysicalZipCode: "",
			pfirstname: "",
			plastname: "",
			pjobtitle: "",
			pphone: "",
			email: {
				required: "Please enter a valid email address",
				minlength: "Please enter a valid email address",
			},
			Terms: "",
			Representative: "",
			Network: "",
			Referral: ""
		},
		// the errorPlacement has to take the table layout into account
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo( element.parent() );
			else if ( element.is(":checkbox") )
				error.appendTo ( element.parent() );
			else
				error.appendTo( element.parent().next() );
		},

		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
	});
 
	});

