﻿$(document).ready(function(){


/*
==============================================
	Forms & Validation
	
	The validate jQuery plugin is used here.
	Find the relevant documentation here:
	
	Home Page with demos
	http://docs.jquery.com/Plugins/Validation
	
	Plugin Options
	http://docs.jquery.com/Plugins/Validation/validate#toptions
	
	Documentation
	http://bassistance.de/jquery-plugins/jquery-plugin-validation/
	Lots more demos
	http://jquery.bassistance.de/validate/demo/
	
==============================================
*/

if ($("#OrderProspectus").length) {
	
	$("#OrderProspectus").validate({

/* 
	Normally and error class is added to the input element - I'm adding it to the parent div
	so we can show our error cross
*/			
		highlight: function(element, errorClass) {
     	$(element).parent().parent().addClass(errorClass);
  		},
  		unhighlight: function(element, errorClass) {
     	$(element).parent().parent().removeClass(errorClass);
	  	},
		

/* 
	Create an error container with an unordered list
*/			

		errorContainer: "#error-list",
		errorLabelContainer: $("#error-list ul"),
		wrapper: 'li',

/* 
	The default will put focus on the first erroneous input. I wish to disable this function.
	If there are errors, I wish to scroll to the error container instead
*/			

		focusInvalid: false,
		
		invalidHandler: function(form, validator) {
      var errors = validator.numberOfInvalids();
      if (errors) {
        $.scrollTo('#error-anchor');
      }
    },

/* 
	Here are our field rules and their corresponding messages
*/			

		rules: {
			ProspectusType: {required:true},
			FirstName: "required",
			LastName: "required",
			Address1: "required",
			Country: "required",
						
			Email: {
				required: true,
				email: true
			},
			ConfirmEmail: {
				required: true,
				email: true,
				equalTo: "#Email"
			},
			ContactPhoneNumber: {
				required: true
			},			
			
			SchoolCollegeName: {
				required: true
			},						
			
			SchoolAddress1: {
				required: true
			},				
			SchoolCountry: {
				required: true
			},									
			Agree: "required"
		},
		messages: {
			ProspectusType: {
				required: "Please select the prospectus you would like sent"
			},
			FirstName: "Please enter your First Name",
			LastName: "Please enter your Last Name",			
			Address1: "Please enter your Address",
			Country: "Please enter your Country",
			Email: {
				required: "Please enter your Email address",
				email: "Please enter the email address in the format name@domain.com"
			},
			ConfirmEmail: {
				required: "Please enter your Email address",
				email: "Please enter the email address in the format name@domain.com",
				equalTo: "Confirm Email and Email should be the same"
			},
			Country: "Please enter your Country",
			ContactPhoneNumber: "Please provide a Contact Phone Number",						
			SchoolCollegeName: "Please provide the name of your Current School or College",						
			SchoolAddress1: "Please provide the address of your Current School or College",						
			SchoolCountry: "Please provide the country of your Current School or College",						
			Agree: "Please tick the box to indicate you agree with our 'Use of data statement'"
		}
	});
	}	
	
if ($("#PostgraduateOpenDayForm").length) {

	$("#PostgraduateOpenDayForm").validate({

/* 
	Normally and error class is added to the input element - I'm adding it to the parent div
	so we can show our error cross
*/			
		highlight: function(element, errorClass) {
     	$(element).parent().parent().addClass(errorClass);
  		},
  		unhighlight: function(element, errorClass) {
     	$(element).parent().parent().removeClass(errorClass);
	  	},
		

/* 
	Create an error container with an unordered list
*/			

		errorContainer: "#error-list",
		errorLabelContainer: $("#error-list ul"),
		wrapper: 'li',

/* 
	The default will put focus on the first erroneous input. I wish to disable this function.
	If there are errors, I wish to scroll to the error container instead
*/			

		focusInvalid: false,
		
		invalidHandler: function(form, validator) {
      var errors = validator.numberOfInvalids();
      if (errors) {
        $.scrollTo('#error-anchor');
      }
    },

/* 
	Here are our field rules and their corresponding messages
*/			

		rules: {
			FirstName: "required",
			LastName: "required",
			Address1: "required",
			Country: "required",	
			Email: {
				required: true,
				email: true
			},
			ConfirmEmail: {
				required: true,
				email: true,
				equalTo: "#Email"
			},
			ContactPhoneNumber: {
				required: true
			},	
			Agree: "required"
		},
		messages: {
			FirstName: "Please enter your First Name",
			LastName: "Please enter your Last Name",			
			Address1: "Please enter your Address",
			Country: "Please enter your Country",
			Email: {
				required: "Please enter your Email address",
				email: "Please enter the email address in the format name@domain.com"
			},
			ConfirmEmail: {
				required: "Please enter your Email address",
				email: "Please enter the email address in the format name@domain.com",
				equalTo: "Confirm Email and Email should be the same"
			},
			ContactPhoneNumber: "Please provide a Contact Phone Number",	
			Agree: "Please tick the box to indicate you agree with our 'Use of data statement'"					
		}
	});
	}	
	
	
if ($("#DonateForm").length) {

	$("#DonateForm").validate({

/* 
	Normally and error class is added to the input element - I'm adding it to the parent div
	so we can show our error cross
*/			
		highlight: function(element, errorClass) {
     	$(element).parent().parent().addClass(errorClass);
  		},
  		unhighlight: function(element, errorClass) {
     	$(element).parent().parent().removeClass(errorClass);
	  	},
		

/* 
	Create an error container with an unordered list
*/			

		errorContainer: "#error-list",
		errorLabelContainer: $("#error-list ul"),
		wrapper: 'li',

/* 
	The default will put focus on the first erroneous input. I wish to disable this function.
	If there are errors, I wish to scroll to the error container instead
*/			

		focusInvalid: false,
		
		invalidHandler: function(form, validator) {
      var errors = validator.numberOfInvalids();
      if (errors) {
        $.scrollTo('#error-anchor');
      }
    },

/* 
	Here are our field rules and their corresponding messages
*/			

		rules: {
			FirstName: "required",
			LastName: "required",
			Address1: "required",
			Country: "required",
						
			Email: {
				required: true,
				email: true
			},

			ContactPhoneNumber: {
				required: true
			},			
			GiftAmount: "required"
		},
		messages: {
			FirstName: "Please enter your First Name",
			LastName: "Please enter your Last Name",			
			Address1: "Please enter your Address",
			Country: "Please enter your Country",
			Email: {
				required: "Please enter your Email address",
				email: "Please enter the email address in the format name@domain.com"
			},
			Country: "Please enter your Country",
			ContactPhoneNumber: "Please provide a Contact Phone Number",						
			GiftAmount: "Please enter the amount of your Gift"
		}
	});
	}	
	
	
});
