	// VARIABLES
	var marker = "*";
	// Declaring required variables for phone number checking
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;


	// Function used to limit the number of characters on an open text field to a maximum length
	function TAlimit(s) {
		var maxlength = 600; // Change number to your max length.
		if (s.value.length > maxlength) 
		s.value = s.value.substring(0,maxlength);
	}

	// Function to validate that mandatory fields are filled with data
	// also handles the changing of the label class to display as per the CSS class rule label.error
	// in the form_css.css style sheet and the addition of a marker to easily identify the fields that
	// have been missed.
	function validate_field (idIN, idLBL){
		marker_length = marker.length;
		errClass = "error";
		normClass = "mandatory";

		var errQs = document.getElementById(idIN);
		var errLbl = document.getElementById(idLBL);

		if ((errQs.value == "")||(errQs.value == " ")||(errQs.value == null))
		{
			if ((errLbl.innerHTML.substr(0,marker_length))!= marker)
			{
				errLbl.innerHTML = marker + errLbl.innerHTML;
			}
			errLbl.className = errClass;
			valid = false;
		}
		else
		{
			if ((errLbl.innerHTML.substr(0,marker_length)) == marker)
			{
				errLbl.innerHTML = errLbl.innerHTML.substr(marker_length);
			}
			errLbl.className = normClass;
		}

		return valid;
	}

	// Function to validate the email address
	function chk_email(idIN) {
		var email_addr = document.getElementById(idIN);
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email_addr.value))
		{
			return (true);
		}
		else
		{
		alert("Invalid E-mail Address! Please re-enter.");
		email_addr.focus();
		return (false);
		}
	}

	// The functions below all work together to validate phone numbers
	// -----<Start Phone Number Validation <<<
	function isInteger(s){
		var i;
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}


	function stripCharsInBag(s, bag) {
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
    		return returnString;
	}


	function checkInternationalPhone(strPhone){
		s=stripCharsInBag(strPhone,validWorldPhoneChars);
		return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
	}


	function chk_phone(idIN){
		var phone = document.getElementById(idIN);
	
		if (checkInternationalPhone(phone.value)==false)
		{
			alert("Please Enter a Valid Phone Number");
			phone.focus();
			return false;
		}
		return true;
	}
	// ----->>> end Phone Number Validation

	// Function to check the age. Both a minimum age and a value between minimum age and maximum age.
	function chk_age(idIN){
		minage = 18;
		maxage = 120;
		var years = document.getElementById(idIN);
	
		if ((years.value)<minage)
		{
			alert("You must be at least 18 to sign up for this program");
			years.focus();
			return false;
		}

		if (((years.value)<minage) || ((years.value)>maxage)|| !isInteger(years.value))
		{
			alert("You appear to have entered an invalid age. Please correct this and retry");
			years.focus();
			return false;
		}

		return true;
	}

	// This is the main form validation routine that is called from the HTML form tag
	function validate_form ( ){
		valid = true;
		errClass = "error";
		normClass = "mandatory";

		validate_field("full_name","fname_lbl");
		validate_field("email","email_lbl");

		if (!(valid))
		{
			alert ( "Please fill in all mandatory fields highlighted in yellow and preceeded by a ' " + marker + "'");
			return valid;
		}

		if (!(chk_email("email")))
		{
			valid = false;
			return valid;
		}
		
		return valid;
	}

	function setfocus(id) {
		var this_item = document.getElementById(id);
		this_item.focus();
	}