$(document).ready(function() {
	// Part of phone validation
	jQuery.validator.addMethod("phoneInternational", function(phone_number, element) {
		phone_number = phone_number.replace(/\s+/g, ""); 
		return this.optional(element) || phone_number.length > 9 && 
		phone_number.match(/^[+]?([0-9]\d{1,3}-?)?(\([1-9]\d{2}\)|[1-9]\d{2})-?[1-9]\d{2}-?\d{4}$/);
	}, "Please specify a valid phone number");
	
	// Form validation
	$("#contactForm2").validate({
		 //As soon as a key within a form field in "myform" is release then start 
		event: "keyup",
		
		highlight: function(element, errorClass) {
			$(element).effect("highlight", {}, 2000); 
		},
		
		errorPlacement: function(error, element) {
			error.insertAfter(element);
			$("label.error + span").remove();
		},

		//Here the rules for the individual inputs are defined.
		rules: {
			//for id's and classes
			last_name: {
				required: true,
				minlength: 2
			},
			company: {
				required: true,
				minlength: 2
			},
			title: {
				required: true,
				minlength: 2
			},
			phone: {
 				required: true,
 				phoneInternational: true
 			},
			email: {
				required: true,
				//It is an E-Mail address
				email: true
			}
		},
		
		//Here the error messages for all rules are defined.
		messages: {
			last_name: {
				required: "Please type in your name.",
				minlength: "Please type in your name."
			},
			company: {
				required: "Please type in the name of your company.",
				minlength: "Please type in the name of your company."
			},
			title: {
				required: "Please type in your title.",
				minlength: "Please type in your title."
			},
			phone: {
 				required: "Please type in the primary contact's phone number.",
 				phoneInternational: "Ex: (608) 123-1234 or 608-123-1234 or +49 123-123-4567"
 			},
			email: {
				required: "Please type in your email address.",
				email: "Your email address must be in the format of name@domain.com."
			}
		}

	});

	// For Calendar
	$('#dueDate').datepicker();
});
