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.address.value.length > 300) {
		blnValid = false;
		arrFocus.push('address');
		strMsg += '- Your address contains more than 300 characters. Please do not exceed 300 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.repreaddress.value.length > 300) {
		blnValid = false;
		arrFocus.push('repreaddress');
		strMsg += '- Your Representative\'s address contains more than 300 characters. Please do not exceed 300 characters.\n';
	}
	
	if (theForm.comments.value == '') {
		blnValid = false;
		arrFocus.push('comments');
		strMsg += '- You did not provide an enquiry, comment or complaint.\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 > 750) {
		blnValid = false;
		arrFocus.push('comments');
		strMsg += '- Your comments contain ' + theForm.comments.value.length + ' characters. Please do not exceed 750 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,counterId) {
 
 if (obj.value.length>max) { 
  obj.value = obj.value.substring(0,max);
  alert('Character limit of ' + max + ' characters has been reached.');
 }
 
 showCharCount(obj.value.length,counterId);
}
 
function showCharCount(count,counterId) {
 if (document.getElementById && document.getElementById(counterId)) {
  document.getElementById(counterId).value = count;
 }
}