// Checks the email address
function checkForEmail(fld) {
  if (fld.value.search(/[\w\-_]+\@[\w\-_]+\.[\w\-_]+/) == -1) {
    return false;
  } else {
    return true;
  }
}

/* Checks the length of the search phrase in the search box */
function checkLogin(frm) {
  var Msg = '';
  if (frm.email.value.length < 3) {
    Msg += 'You must enter an email address of 3 characters or more\n';
  } else if (!checkForEmail(frm.email)) {
    Msg += 'Please enter a valid email address\n';
  }
  if (frm.password.value.length < 6) {
    Msg += 'You must enter a password of 6 characters or more';
  }

  if (Msg) {
    alert(Msg);
    return false;
  } else {
    return true;
  }
}

// Check that the registration details have been submitted correctly
function checkRegistration(frm) {
  var Msg = ''
  if (frm.email.value == '') {
    Msg += 'Please enter your email address\n';
  } else if (!checkForEmail(frm.email)) {
    Msg += 'Please enter a valid email address\n';
  }
  if (frm.first_name.value == '') {
    Msg += 'Please enter your first name\n';
  }
  if (frm.last_name.value == '') {
    Msg += 'Please enter your last name\n';
  }
  if (frm.address.value == '') {
    Msg += 'Please enter your address\n';
  }
  if (frm.county.value == '') {
    Msg += 'Please enter your county\n';
  }
  if (frm.city.value == '') {
    Msg += 'Please enter your city\n';
  }
  if (frm.postcode.value == '') {
    Msg += 'Please enter your postcode\n';
  }
  if (frm.telephone.value == '') {
    Msg += 'Please enter your telephone\n';
  }
  if (frm.password.value == '') {
    Msg += 'Please choose a login password\n';
  } else if (frm.password.value.length < 6 || frm.password.value.match(/ /)) {
    Msg += 'Please choose a login password of at least 6 characters in length (no spaces)\n';
  } else if (frm.passwordtwo.value == '') {
    Msg += 'Please choose a login confirmation password\n';
  } else if (frm.passwordtwo.value.length < 6 || frm.passwordtwo.value.match(/ /)) {
    Msg += 'Please choose a login confirmation password of at least 6 characters in length (no spaces)\n';
  } else if (frm.password.value != frm.passwordtwo.value) {
    Msg += 'The admin login and admin login confirmation password do not match\n';
  }

  if (Msg) {
    alert(Msg);
    return false;
  } else {
    return true;
  }
}