function trim(str){ //trim leading/trailing spaces.
   return str.replace(/^\s*|\s*$/g,"");
}

function IsEmpty(aTextField) {

   if ((aTextField.value.length==0) || (aTextField.value==null)) {
	  aTextField.focus()
	  return true;
   }
   else { 
	return false; 
   }
}
	
function ValidateAlphanumeric(checkStr){
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'-"; //apostrophe & dash allowed for names
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		if(checkOK.indexOf(ch)<0) return false
	}
	return true;
}

function checkEntry(TextField){
	TextField.value=trim(TextField.value)
	var blank=false
	if ((TextField.value.length==0) || (TextField.value==null)) {
		blank=true;
		}
	if ( (blank=false) && (!ValidateAlphanumeric(TextField.value)) ) {
		alert('We can only accept alphanumeric characters in this entry\n\nPlease check your entry and remove any special characters such as these:\n\n $ £ " \' * % ; , . + ! * ( ) < >');
		TextField.focus();
		}
}

	function ValidateTelNo(checkStr){
		var checkOK = "0123456789()-+ ";
		var allValid = true;
		for (i = 0;  i < checkStr.length;  i++) {
			ch = checkStr.charAt(i);
			if(checkOK.indexOf(ch)<0) return false
		}
		return true;
	}
	function checknumeric(field){
		pattern = /^[0-9]*$/;
		if(pattern.test(field.value)==false) return false;
		return true;
	}
	function isEmail(email) {

			var iChars = "*|,\":<>[]{}`\;()&$#%";
			for (var i = 0; i < email.length; i++) {
      			if (iChars.indexOf(email.charAt(i)) != -1){
					alert("There are characters in your email address which are not allowed in email addesses.\n\nYou may have typed it in incorrectly. Please check the address carefully."); 
         			return false;
				}	
  			 }
			 if(-1 == email.indexOf("@")) { 
		       alert("The email address entered is not a valid email address.\n\nYou may have typed it in incorrectly. Please check the address carefully."); 
		       return false; 
		       }
		    if(-1 == email.indexOf(".")) { 
		       alert("The email address must have a suffix such as .com, .org or .co.uk."); 
		       return false; 
		       }
		    if(-1 != email.indexOf(" ")) { 
		       alert("The email you have entered has a space in it. Valid email addresses cannot have any spaces" ); 
		       return false; 
		       }
		    if(email.length == (email.value.indexOf("@")+1) ) {
		       alert("The email address entered is not a valid email address.\n\n You may have typed it in incorrectly. Please check the address carefully.");
		       return false;
		       }
		  return true;
	}
