

  // Creates the user account from its form
  // the form name is 'resgistrationForm'
  function registerUser() {

    // Form validation
    var myForm = document.registrationForm;
    resetFormErrors(myForm);

    // we start with mandatory fields
    checkMandatoryTextField(myForm.firstname);
    checkMandatoryTextField(myForm.lastname);
    checkMandatoryTextField(myForm.birthYear);
    checkMandatoryTextField(myForm.contactAddress);
    checkMandatoryTextField(myForm.contactTown);
    checkMandatoryTextField(myForm.contactPostalCode);
    checkMandatoryTextField(myForm.contactTel);
    checkMandatoryTextField(myForm.contactEmail);

    if(hasFormErrors()==true) {
      displayFormErrors();
      return; // no need to go further
    }

    // format validation
    checkTextareaField(myForm.medicalCondition,200);
    checkYearField(myForm.birthYear);
    checkEmailField(myForm.contactEmail);

    if(hasFormErrors()==true) {
      displayFormErrors();
      return; // no need to go further
    }

      document.registrationForm.submit();
  }
