function checkForm(theForm) {

	var blnValid = true;
	var arrFocus = [];
	var strFocus = '';
	var strMsg = 'There was a problem with the information you have provided in this form:\n\n';
	
	var patternHTML;
	patternHTML = /[<|\[](.|\n)+?[>|\]]/ig;
	
	var patternLink;
	patternLink = /href|http:\/\/|https:\/\/|ftp:\/\/|file:\/\/|mailto:|www\./ig;
	
	var patternAlphaNumeric;
	patternAlphaNumeric = /^([0-9a-zA-Z\-' ]+)$/;
	
	var patternEmail;
	patternEmail = /^\w+(['\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/;
	
	
	if (theForm.name.value == '') {
		blnValid = false;
		arrFocus.push('name');
		strMsg += '- You did not provide your name.\n';
	} else if (!patternAlphaNumeric.test(theForm.name.value)) {
		blnValid = false;
		arrFocus.push('name');
		strMsg += '- Your name contains invalid characters. Please use alphabetic characters only.\n';
	}
	
	if (theForm.name.value.length > 50) {
		blnValid = false;
		arrFocus.push('name');
		strMsg += '- Your name contains more than 50 characters. Please do not exceed 50 characters.\n';
	}
	
	if (theForm.organisation.value != '' && !patternAlphaNumeric.test(theForm.organisation.value)) {
		blnValid = false;
		arrFocus.push('organisation');
		strMsg += '- Your organisation contains invalid characters. Please use alphabetic characters only.\n';
	}
	
	if (theForm.organisation.value.length > 50) {
		blnValid = false;
		arrFocus.push('organisation');
		strMsg += '- Your organisation contains more than 50 characters. Please do not exceed 50 characters.\n';
	}
	
	if (theForm.email.value != '' && (!patternEmail.test(theForm.email.value) || theForm.email.value.length > 320)) {
		blnValid = false;
		arrFocus.push('email');
		strMsg += '- Your email address does not look correct. Please provide a valid email address\n   (e.g. your.name@somewhere.net).\n';
	}
	
	if (theForm.comments.value == '') {
		blnValid = false;
		arrFocus.push('comments');
		strMsg += '- You did not provide your queries or comments.\n';
	} else if (patternHTML.test(theForm.comments.value) || patternLink.test(theForm.comments.value)) {
		blnValid = false;
		arrFocus.push('comments');
		strMsg += '- Your comments appear to contain HTML and/or hyperlinks. Please use plain text only.\n';
	}
	
	if (theForm.comments.value.length > 1500) {
		blnValid = false;
		arrFocus.push('comments');
		strMsg += '- Your comments contain ' + theForm.comments.value.length + ' characters. Please do not exceed 1500 characters.\n';
	}
	
	
	strMsg += '\nPlease correct the above issues before submitting this form.\n\nThank-you.';
	
	if (!blnValid) {
		alert(strMsg);
		strFocus = 'theForm.' + arrFocus[0] + '.focus()';
		eval(strFocus);
	}
	
	return blnValid;

}

function checkLimit(obj,max) {

	if (obj.value.length>max) { 
		obj.value = obj.value.substring(0,max);
		alert('Your comments have reached the maximum limit of ' + max + ' characters.');
	}
	
	showCharCount(obj.value.length);
}

function showCharCount(count) {
	if (document.getElementById && document.getElementById("counter")) {
		document.getElementById("counter").value = count;
	}
}