let isEmailValid = false
let isPasswordValid = false

// check if email already exist
$('#inputEmail').change(function () {
  const email = $('#inputEmail').val()
  $.get('email/' + email, function (data) {
    $('#emailWarning').empty()
    isEmailValid = data
    if (!isEmailValid) {
      $('#emailWarning').html('Mit dieser E-Mail-Adresse existiert bereits ein Benutzerkonto in unserem Transferportal.')
    }
    switchSubmitButton()
  })
    .fail(function () {
      console.log('cannot check email')
    })
})

// check password
$('#inputPassword').on('keyup', function () {
  isPasswordValid = checkPasswordReq($('#inputPassword').val())
  $('#passwordWarning').empty()
  if (!isPasswordValid) {
    // $('#passwordWarning').html('Must be at least 8 characters')
    $('#passwordWarning').html('Das Passwort muss mindestens 8 Zeichen haben')
  }
  switchSubmitButton()
})

function switchSubmitButton () {
  if (isEmailValid && isPasswordValid) {
    $('#submitBtn').prop('disabled', false)
  } else {
    $('#submitBtn').prop('disabled', true)
  }
}
