function validateEmail(addr,man,db) 
	{
	if (addr == '' && man) 
	{
	  if (db) alert('Please enter a valid email address');
	  return false;
	}
		                                
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
		                                
	for (i=0; i<invalidChars.length; i++) 
	{
	  if (addr.indexOf(invalidChars.charAt(i),0) > -1) 
	  {
	    if (db) alert('email address contains invalid characters');
	      return false;
	  }
	}
		                                
	for (i=0; i<addr.length; i++) 
	{
	  if (addr.charCodeAt(i)>127) 
	  {
	    if (db) alert("email address contains non ascii characters.");
	      return false;
	  }
	}

	var atPos = addr.indexOf('@',0);
		                                
	if (atPos == -1) 
	{
	  if (db) alert('email address must contain an @');
	    return false;
	}
	if (atPos == 0) 
	{
	  if (db) alert('email address must not start with @');
	    return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) 
	{
	  if (db) alert('email address must contain only one @');
	    return false;
	}

	if (addr.indexOf('.', atPos) == -1) 
	{
	  if (db) alert('email address must contain a period in the domain name');
	    return false;
	}
	if (addr.indexOf('@.',0) != -1) 
	{
	  if (db) alert('period must not immediately follow @ in email address');
	    return false;
	}
	if (addr.indexOf('.@',0) != -1)
	{
	  if (db) alert('period must not immediately precede @ in email address');
	    return false;
	}
	if (addr.indexOf('..',0) != -1) 
	{
	  if (db) alert('two periods must not be adjacent in email address');
	    return false;
	}

	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') 
	{
	  if (db) alert('invalid primary domain in email address');
	    return false;
	}
	return true;
	} 
	           		
function validateregisterform()
{
    var error = '';
    
    if (document.registerform.securitycheck.value == ''){
	    error = 'Please enter the security number into the box';
	    document.getElementById('securitycheck').className='errorformtext';
	    document.registerform.securitycheck.focus();
    }
    else
    {
	    document.getElementById('securitycheck').className='inputFields';
    }
    
    if (!document.registerform.consent.checked){
	    error = 'You must consent to Lullingstone Park Golf Course holding your details';
    }
    
    if (document.registerform.password.value != document.registerform.confirmpassword.value){
	    error = 'The passwords do not match';
	    document.getElementById('confirmpassword').className='errorformtext';
	    document.registerform.confirmpassword.focus();
    }
    else
    {
	    document.getElementById('confirmpassword').className='inputFields';
    }
    
    if (document.registerform.confirmpassword.value == ''){
	    error = 'Please confirm your password';
	    document.getElementById('confirmpassword').className='errorformtext';
	    document.registerform.confirmpassword.focus();
    }
    else
    {
	    document.getElementById('confirmpassword').className='inputFields';
    }
    
    if (document.registerform.password.value == ''){
	    error = 'Please enter the password you would like to use for your account';
	    document.getElementById('password').className='errorformtext';
	    document.registerform.password.focus();
    }
    else
    {
	    document.getElementById('password').className='inputFields';
    }
    
    if (document.registerform.telephone.value == ''){
	    error = 'Please enter your telephone number';
	    document.getElementById('telephone').className='errorformtext';
	    document.registerform.telephone.focus();
    }
    else
    {
	    document.getElementById('telephone').className='inputFields';
    }
    
    if (document.registerform.email.value != document.registerform.confirmemail.value){
	    error = 'The email addresses do not match';
	    document.getElementById('confirmemail').className='errorformtext';
	    document.registerform.confirmemail.focus();
    }
    else
    {
	    document.getElementById('confirmemail').className='inputFields';
    }
    
    if (document.registerform.confirmemail.value == ''){
	    error = 'Please confirm your email address';
	    document.getElementById('confirmemail').className='errorformtext';
	    document.registerform.confirmemail.focus();
    }
    else
    {
	    document.getElementById('confirmemail').className='inputFields';
    }
    
    if (!validateEmail(document.registerform.email.value,1,0)){
	    error = 'Please enter a valid email address';
	    document.getElementById('email').className='errorformtext';
	    document.registerform.email.focus();
    }
    else
    {
	    document.getElementById('email').className='inputFields';
    }
    
    if (document.registerform.postcode.value == ''){
	    error = 'Please enter your postcode';
	    document.getElementById('postcode').className='errorformtext';
	    document.registerform.postcode.focus();
    }
    else
    {
	    document.getElementById('postcode').className='inputFields';
    }
    
    if (document.registerform.address1.value == ''){
	    error = 'Please enter the first line of your address';
	    document.getElementById('address1').className='errorformtext';
	    document.registerform.address1.focus();
    }
    else
    {
	    document.getElementById('address1').className='inputFields';
    }
    
    if ((document.getElementById('dobday').selectedIndex == 30 || document.getElementById('dobday').selectedIndex == 31) && document.getElementById('dobmonth').selectedIndex == 2){
	    error = 'You have selected an invalid date.';
	    document.registerform.dobday.focus();
    }
    
    if (document.registerform.surname.value == ''){
	    error = 'Please enter your surname';
	    document.getElementById('surname').className='errorformtext';
	    document.registerform.surname.focus();
    }
    else
    {
	    document.getElementById('surname').className='inputFields';
    }
    
    if (document.registerform.forename.value == ''){
	    error = 'Please enter your forename';
	    document.getElementById('forename').className='errorformtext';
	    document.registerform.forename.focus();
    }
    else
    {
	    document.getElementById('forename').className='inputFields';
    }
	
	if (error == '')
	{
		return true;
	}
	else
	{
		alert(error);
		return false;
	}
}
