// JavaScript Document

$(document).ready(function(){
	$("#mainForm").validate({
		errorClass: "invalid",
		wrapper: "li",
		rules: {
			emailPrimary: {
				required: true,
				email: true
			},
			parent1EmailPrimary: {
				required: true,
				email: true
			},
			confirmParent1EmailPrimary: {
				equalTo: "#pg_email"
			},
			parent1PhonePh1: {
				required: true,
				digits: true,
				rangelength: [3, 3]
			},
			parent1PhonePh2: {
				required: true,
				digits: true,
				rangelength: [3, 3]
			},
			parent1PhonePh3: {
				required: true,
				digits: true,
				rangelength: [4, 4]
			},
			zip: {
				required: true,
				digits: true,
				rangelength: [5, 5]
			}	
		},
		messages: {
			firstName: "Please enter first name.",
			lastName: "Please enter last name.",
			emailPrimary: {
				required: "Please enter an email address.",
				email: "Invalid email address."
			},
			sport: "Please select a sport.",
			highSchoolGradYear: "Please select the year you will graduate from high school.",
			highSchoolStateId: "Please select high school state.",
			highSchoolId: "Please select high school.",
			parent1FirstName: "Please enter parent/guardian first name.",
			parent1LastName: "Please enter parent/guardian last name.",
			parent1Relationship: "Please select parent/guardian's relationship to you.",
			parent1PhonePh1: "Please enter a complete phone number.",
			parent1PhonePh2: "Please complete phone number.",
			parent1PhonePh3: "Please complete phone number.",
			parent1EmailPrimary: "Please enter parent email address.",
			confirmParent1EmailPrimary: {
				required: "Please re-enter parent email address",
				equalTo: "Email addresses do not match."
			},
			city: "Please enter city name.",
			stateId: "Please select state.",
			zip: "Please enter 5 digit zip code.",
			parent2PhonePh1: "Please enter a valid phone number.",
			parent2PhonePh2: "Please enter a valid phone number.",
			parent2PhonePh3: "Please enter a valid phone number.",
			parent2EmailPrimary: "Please a enter valid email address."
		},
		errorPlacement: function(error, element) {
			var eName = $(element).attr("name");
			switch(eName) {
				case "emailPrimary": case "firstName":
				case "lastName": case "commitmentLevel":
				case "highSchoolGradYear": case "highSchoolStateId": case "highSchoolId":
				case "sport": case "highSchoolName":
				error.appendTo("#saError"); break;
				
				case "parent1FirstName": case "parent1LastName": case "parent1Relationship":
				case "parent1PhonePh1": case "parent1PhonePh2": case "parent1PhonePh3":
				case "parent1EmailPrimary": case "confirmParent1EmailPrimary":
				case "city": case "stateId": case "zip":
				error.appendTo("#pgError"); break;
				
				default: error.appendTo($(element).after());
			}
		},
		highlight: function(element, errorClass) {
			if ( $(element).attr("type") != "radio")
				$(element).css({ border: '1px solid #CC0000'});
		},
		unhighlight: function(element, errorClass) {
			if ( $(element).attr("type") != "radio")
				$(element).css({ border: '1px solid #71178a'});
		}
	});
	$("#regForm").validate({
		errorClass: "invalid",
		wrapper: "li",
		rules: { 
			coachEmailPrimary: {
				required: true, 
				email: true
			}, 
			firstName: "required",
			lastName: "required"
		},
		messages: {
			firstName: "Please enter first name.",
			lastName: "Please enter last name.",
			entryFrom: "Please select either Student-Athlete or Parent/Guardian.",
			coachEmailPrimary: {
				required: "Please enter an email address.",
				email: "Invalid e-mail address." 
			}
		},
		errorPlacement: function(error, element) {
				error.appendTo("#lfError");			
		},
		highlight: function(element, errorClass) {
			if ( $(element).attr("type") != "radio")
				$(element).css({ border: '1px solid #CC0000'});
		},
		unhighlight: function(element, errorClass) {
			if ( $(element).attr("type") != "radio")
			$(element).css({ border: '1px solid #71178a'});
		}
	});
	$("#mainForm").bind("submit", function() {
		$(this).validate();
		var valid = $(this).valid();
		if(valid) {
			$("#submitButton").attr('disabled','disabled');
			return true;
		} else
			return false;
	});
});













$(document).ready(function(){
	$("#phoneNumberForm").validate({
		wrapper: "li",
		rules: {
			homePhonePh1: {
				required: true,
				digits: true,
				rangelength: [3, 3]
				
			},
			homePhonePh2: {
				required: true,
				digits: true,
				rangelength: [3, 3]
				
			},
			homePhonePh3: {
				required: true,
				digits: true,
				rangelength: [4, 4]
			
			}	
		},
		messages: {
			homePhonePh1: "- Please enter a valid phone number in box 1. ",
			homePhonePh2: "- Please enter a valid phone number in box 2. ",
			homePhonePh3: "- Please enter a valid phone number in box 3. ",
		},
		errorPlacement: function(error, element) {
			var eName = $(element).attr("name");
			switch(eName) {
				case "homePhonePh1":
				case "homePhonePh2": 
				case "homePhonePh3": 
				error.appendTo("#saError"); break;
				
				default: error.appendTo($(element).after());
			}
		},
		highlight: function(element, errorClass) {
			if ( $(element).attr("type") != "radio")
				$(element).css({ border: '1px solid #CC0000'});
		},
		unhighlight: function(element, errorClass) {
			if ( $(element).attr("type") != "radio")
				$(element).css({ border: '1px solid #71178a'});
		}
	});

	$("#phoneNumberForm").bind("submit", function() {
		$(this).validate();
		var valid = $(this).valid();
		if(valid) {
			$("#submitButton").attr('disabled','disabled');
			return true;
		} else
			return false;
	});
});
