$(document).ready(function() {
	// validate signup form on keyup and submit
	$("#enrolmentForm").validate({
		rules: {
			terms: "required",
			surname: "required",
			first_name: "required",
			DOB_Day: {required: true, digits: true},
			DOB_month: {required: true, digits: true},
			DOB_Year: {required: true, digits: true},
			Home_Area_Code: {required: true, digits: true, minlength: 2},
			Home_Phone: {required: true, digits:true, minlength: 8, maxlength: 12},
			mobile: "digits",
			Home_Post_Code: "digits",
			Home_Email: "email",
			Postal_Post_Code: "digits",
			PO_Box_Post_Code: "digits",
			Employment_Organisation: {required: "#Invoice_employer:checked"},
			Employer_Postal_Post_Code: "digits",
			Employment_PO_Box_Post_Code: "digits",
			Employment_Telephone: "digits",
			Employment_Mobile: "digits",
			Invoice_details: {required: "#Invoice_other:checked"}
		},
		messages: {
			terms: "Please check to indicate that you have agreed to the terms and conditions and have read and understood Essentra's Learners Handbook and Enrolment Policy",
			surname: "Please enter your surname",
			first_name: "Please enter your first name",
			DOB_Day: "Please provide your day of birth",
			DOB_month: "Please provide your month of birth",
			DOB_Year: "Please provide your birth year",
			Home_Area_Code: {
				digits: "Please provide your home area code as digits only",
				minlength: "Please provide an area code with at least 2 digits"
			},
			Home_Phone: {
				digits: "Please provide your home phone as digits only",
				minlength: "Please provide a phone number with at least 8 digits",
				maxlength: "Please provide a phone number with at most 12 digits"
			},
			Employment_Organisation: "If your employer will be invoiced, please provide the organisation name",
			Home_Email: {email: "Please provide a valid email address"},
			mobile: {digits: "Please provide your mobile number as digits only"},
			Home_Post_Code: {digits: "Please provide your home post code as digits only"},
			Postal_Post_Code: {digits: "Please provide your postal address post code as digits only"},
			PO_Box_Post_Code: {digits: "Please provide your P.O. Box post code as digits only"},
			Employer_Postal_Post_Code: {digits: "Please provide your employment post code as digits only"},
			Employment_PO_Box_Post_Code: {digits: "Please provide your employment P.O. Box post code as digits only"},
			Employment_Telephone: {digits: "Please provide your employment phone number as digits only"},
			Employment_Mobile: {digits: "Please provide your employment mobile number as digits only"},
			Invoice_details: "Please provide details on how to invoice"
		}
	});
	
});

function printTextArea(id,name) {

	var TAContent = $('#'+id).val().replace(/\r?\n/g, "<br>\n");
	
	var TAPrint = window.open("", "", 'left=0,width=640,height=480,toolbar=no,header=no,location=no,resizable=no,scrollbars=yes,status=no');
	TAPrint.document.write('<html><head><title>Essentra Learning - ' + name + '</title></head><body>'+TAContent+'</body></html>');
	// this line keeps the window open in IE. Shrug.
	TAPrint.document.close();
	
	if (window.print) {
		TAPrint.print();
		TAPrint.close();
	}
	else {
		TAPrint.focus();
	}
}


