
  function submitForm(){
    if(validateForm()){
      document.getElementById('subscription-form').submit()
    }
  }
  
  function validateForm(){
		var message = ""
		var highlighColour = '#F4D8D6';
		document.getElementById('name').style.backgroundColor = '#FFFFFF';
		document.getElementById('email').style.backgroundColor = '#FFFFFF';
		document.getElementById('password').style.backgroundColor = '#FFFFFF';
		document.getElementById('postcode').style.backgroundColor = '#FFFFFF';
		document.getElementById('dob_day').style.backgroundColor = '#FFFFFF';
		document.getElementById('dob_month').style.backgroundColor = '#FFFFFF';
		document.getElementById('gender').style.backgroundColor = '#FFFFFF';
		document.getElementById('age').style.backgroundColor = '#FFFFFF';
		if(document.getElementById('capatcha')) document.getElementById('capatcha').style.backgroundColor = '#FFFFFF';
		
		if (document.getElementById('name').value == ""){
		  document.getElementById('name').style.backgroundColor = highlighColour ;
		  message += "   Name missing\n";
		}
		if (!validateEmailAddress(document.getElementById('email'))){
		  document.getElementById('email').style.backgroundColor = highlighColour ;
		  message += "   Invalid email address\n";
		}
		if (!validatePassword(document.getElementById('password'))){
		  document.getElementById('password').style.backgroundColor = highlighColour ;
		  message += "   Invalid password - must be at least 5 characters long\n";
		}
		if (!validatePostcode(document.getElementById('postcode'))){
		  document.getElementById('postcode').style.backgroundColor = highlighColour ;
		  message += "   Postcode missing or wrong format\n";
		}
		if (document.getElementById('dob_day').value == "" || document.getElementById('dob_month').value == "" ){
		  document.getElementById('dob_day').style.backgroundColor = highlighColour ;
		  document.getElementById('dob_month').style.backgroundColor = highlighColour ;
		  message += "   Birthday not complete\n";
		}
		if (document.getElementById('gender').value == ""){
		  document.getElementById('gender').style.backgroundColor = highlighColour ;
		  message += "   Please specify your gender\n";
		}
		if (document.getElementById('age').value == ""){
		  document.getElementById('age').style.backgroundColor = highlighColour ;
		  message += "   Please specify your age\n";
		}
		if(document.getElementById('capatcha')){
  		if (document.getElementById('capatcha').value == ""){
  		  document.getElementById('capatcha').style.backgroundColor = highlighColour ;
  		  message += "   Verification text missing\n";
  		}
  	}
		if(document.getElementById('capatcha')) if(document.getElementById('capatcha').value == "") document.getElementById('capatcha').focus();
		if(document.getElementById('age').value == "") document.getElementById('age').focus();
		if(document.getElementById('gender').value == "") document.getElementById('gender').focus();
		if(document.getElementById('dob_month').value == "") document.getElementById('dob_month').focus();
		if(document.getElementById('dob_day').value == "") document.getElementById('dob_day').focus();
		if(!validatePostcode(document.getElementById('postcode'))) document.getElementById('postcode').focus();
		if(!validatePassword(document.getElementById('password'))) document.getElementById('password').focus();
		if(!validateEmailAddress(document.getElementById('email'))) document.getElementById('email').focus();
		if(document.getElementById('name').value == "") document.getElementById('name').focus();
		
		if (message.length == 0){
			return true;
		}
		else {
			message = "Please check the following information:\n\n" + message;
			alert(message);
			return false;
		}
  }

  
  
