// JavaScript Document
// Form validation functions

$(document).ready(function() {
	// general contact
	if ($("form#f1").length > 0) {
		$("form#f1").validate({
			rules: {
					first_name: "required",
					last_name: "required",
					email: {
							required: true,
							email: true,
							remote: "services/check-email.php"
					},
					email2: {
						equalTo: "#email"	
					},
					password: {
						required: true,
						minLength: 6
					},
					password2: {
						equalTo: "#password"
					},
					phone: "required",
					address: "required",
					city: "required",
					state: "required",
					zip: {
						required: true,
						maxLength: 5,
						minLength: 5,
						number: true
					},
					"child_firstname[]" : "required",
					"child_lastname[]" : "required",
					"child_bday[]" : {
						required: true//,
						//remote: "services/kid-bday.php"
					},
					certify: "required"
			},
			messages: {
				first_name: "<strong>Your first name is required.</strong>",
				last_name: "<strong>Your last name is required.</strong>",
				email: {
					required: "<strong>Please enter your email address.</strong>",
					email: "<strong>You must enter a valid email address.</strong>",
					remote: "<strong>The email address you've entered is already in our system, have you <a href='forgot.php'>forgotten your password</a>?</strong>"
				},
				email2: "<strong>Please confirm your email.</strong>",
				password: {
					required: "<strong>You must enter a password.</strong>",
					minLength: "<strong>Your password must be at least 6 characters long.</strong>"
				},
				password2: "<strong>The passwords do not match.</strong>",
				"child_firstname[]": "<strong>You must provide a First Name</strong>",
				"child_lastname[]": "<strong>You must provide a Last Name</strong>",
				"child_bday[]": {
					required: "<strong>You must provide a Birthdate.</strong>"//,
					//remote: "<strong>The date provided did not match the correct format (MM/YYYY)</strong>"
				},
				phone: "<strong>Your phone number is required.</strong>",
				address: "<strong>Your address is required.</strong>",
				city: "<strong>Your city is required.</strong>",
				state: "<strong>Your state is required.</strong>",
				zip: "<strong>Your must enter a valid zip code.</strong>",
				certify: "<strong>You must check the box in order to sign up.</strong>"
			}
		});
  	}
	
	// family pass signup!
	if ($("form#family_pass").length > 0) {
		$("form#family_pass").validate({
			rules: {
					first_name: "required",
					last_name: "required",
					"fam_firstname[]" : "required",
					"fam_lastname[]" : "required",
					address: "required",
					city: "required",
					state: {
						required: true,
						maxlength: 2,
						minlength: 2
					},
					zip: {
						required: true,
						maxlength: 5,
						minlength: 5,
						number: true
					},
					cvv: {
						required: true,
						minlength: 3,
						maxlength: 4,
						number: true
					},
					cc: {
						required: true,
						creditcard: true
					},
					month: "required",
					year: "required"
			},
			messages: {
				first_name: "<strong>Your first name is required.</strong>",
				last_name: "<strong>Your last name is required.</strong>",
				"fam_firstname[]": "<strong>You must provide a First Name</strong>",
				"fam_lastname[]": "<strong>You must provide a Last Name</strong>",
				address: "<strong>Your billing address is required.</strong>",
				city: "<strong>Your billing city is required.</strong>",
				state: {
					required: "<strong>You must enter your billing state.</strong>",
					maxlength: "<strong>Enter the two digit abbreviation for your state.</strong>",
					minlength: "<strong>Enter the two digit abbreviation for your state.</strong>"
				},
				zip: {
					required: "<strong>You must enter your billing zip code.</strong>",
					maxlength: "<strong>Enter your 5-digit zip code.</strong>",
					minlength: "<strong>Enter your 5-digit zip code.</strong>",
					number: "<strong>Your zip code must only consist of numbers.</strong>"
				},
				cvv: {
					required: "<strong>Please enter the CVV, found on the back of your credit card.</strong>",
					minlength: "<strong>The CVV is at least 3 numbers.</strong>",
					maxlength: "<strong>The CVV is at most 4 numbers.</strong>",
					number: "<strong>The CVV can only consist of numbers.</strong>"
				},
				cc: {
					required: "<strong>You must enter your credit card number.</strong>",
					creditcard: "<strong>You must enter a valid credit card.</strong>"
				},
				month: "<strong>You must provide an expiration month.</strong>",
				year: "<strong>You must provide an expiration year.</strong>"
				
			},
			submitHandler: function(form) {
				// disable the submit button
				$('#purchase-family-pass').attr('disabled', 'disabled');
				$('#purchase-family-pass').val('Processing... Please Wait');
				form.submit();
			}
		});
  	}

	// contact form on state.php
	if ($("form#contact_form").length > 0) {
		$("form#contact_form").validate({
			rules: {
					first_name: "required",
					center_name: "required",
					email: {
							required: true,
							email: true
					},
					verify: "required"
			},
			messages: {
				first_name: "<strong>Your first name is required.</strong>",
				center_name: "<strong>The bowling center name is required.</strong>",
				email: "<strong>You must enter a valid email address.</strong>",
				verify: "<strong>You must answer the question about the sun.</strong>"
			}
	
		});
	}
	
	// contact form on contact.php
	if ($("form#contact_form2").length > 0) {
		$("form#contact_form2").validate({
			rules: {
					first_name: "required",
					email: {
							required: true,
							email: true
					},
					verify: "required"
			},
			messages: {
				first_name: "<strong>Your first name is required.</strong>",
				email: "<strong>You must enter a valid email address.</strong>",
				verify: "<strong>You must answer the question about the sun.</strong>"
			}
	
		});
	}
	
	// Self Update Form (user_account.php
	if ($("form#self-kids").length > 0) {
		$("form#self-kids").validate({
			rules: {
					
					"kid_firstname[]" : "required",
					"kid_lastname[]" : "required",
					"kid_bday[]" : {
						required: true//,
						//remote: "services/kid-bday.php"
					}
			},
			messages: {
				"kid_firstname[]": "<strong>You must provide a First Name</strong>",
				"kid_lastname[]": "<strong>You must provide a Last Name</strong>",
				"kid_bday[]": {
					required: "<strong>You must provide a Birthdate.</strong>"//,
					//remote: "<strong>The date provided did not match the correct format (MM/YYYY)</strong>"
				}
			}
		});
  	}
});