
function trim(str)
{
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
              
function checkFields() {
	missinginfo = "";
	if (document.getElementById("userTitle").selectedIndex == 0){

	missinginfo += "\n     -  Title";
	}
	if (trim(document.touchForm.forename.value) == '') {
	missinginfo += "\n     -  First Name";
	}
	if (trim(document.touchForm.surname.value) == '') {
	missinginfo += "\n     -  Surname";
	}
	if (trim(document.touchForm.age.value) == '') {
	missinginfo += "\n     -  Age";
	}
	if (trim(document.touchForm.address1.value) == '') {
	missinginfo += "\n     -  Address";
	}
	if (trim(document.touchForm.postcode.value) == '') {
	missinginfo += "\n     -  Post Code";
	}
	if (trim(document.touchForm.daytel.value) == '') {
	missinginfo += "\n     -  Daytime Telephone Number";
	}
	if (trim(document.touchForm.email.value) == '') {
	missinginfo += "\n     -  Email";
	}

	if (missinginfo != "") {
	missinginfo = "Please enter:\n" +
	missinginfo;
		alert(missinginfo);
		return false;
	}
	else{
	if(validate_form(trim(document.touchForm.email.id)) == true){
	  return true;
	}
	}
}
function checkFields2(form) {
	missinginfo = "";
	if (document.getElementById("userTitle").selectedIndex == 0){

	missinginfo += "\n     -  Title";
	}
	if (trim(form.forename.value) == '') {
	missinginfo += "\n     -  First Name";
	}
	if (trim(form.surname.value) == '') {
	missinginfo += "\n     -  Surname";
	}
	
	if (trim(form.daytel.value) == '') {
	missinginfo += "\n     -  Daytime Telephone Number";
	}
	if (trim(form.email.value) == '') {
	missinginfo += "\n     -  Email";
	}

	if (missinginfo != '') {
	missinginfo = "Please enter:\n" +
	missinginfo;
		alert(missinginfo);
		return false;
	}
	else{
	if(validate_form(trim(form.email.id)) == true){
	  return true;
	}
	}
}



function validate_form(element){
	var emailRegxp = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	var email = document.getElementById(element).value;
	if (emailRegxp.test(email) != true){
		alert('Please enter a valid email');
		return false;
	}else{
		return true;
	}
}


var digitsOnly = /[1234567890]/g; 
var integerOnly = /[0-9\.]/g; 
var alphaOnly = /[A-Z]/g; 
function restrictCharacters(myfield, e, restrictionType) { 
if (!e) var e = window.event 
if (e.keyCode) code = e.keyCode; 
else if (e.which) code = e.which; 
var character = String.fromCharCode(code); 
// if they pressed esc... remove focus from field... 
if (code==27) { this.blur(); return false; } 
// ignore if they are press other keys 
// strange because code: 39 is the down key AND ' key... 
// and DEL also equals . 
if (!e.ctrlKey && code!=9 && code!=8 && code!=36 && code!=37 && code!=38 && (code!=39 || (code==39 && character=="'")) && code!=40) { 
if (character.match(restrictionType)) { 
return true; 
} else { 
return false; 
} 
} 
} 

