function CheckSignup() {

  if (document.getElementById('firstname').value == "") {
    alert('Please provide your first name');
    document.getElementById('firstname').focus();
    return false;
  }
  if (document.getElementById('lastname').value == "") {
    alert('Please provide your last name');
    document.getElementById('lastname').focus();
    return false;
  }
  if (document.getElementById('email').value == "") {
    alert('Please provide your email address');
    document.getElementById('email').focus();
    return false;
  }
  if(!checkEmail(document.getElementById('email'))) {
    document.getElementById('email').focus();
    return false;
  }
  if (document.getElementById('password1').value == "") {
    alert('Please provide a password for your account');
    document.getElementById('password1').focus();
    return false;
  }
  if (document.getElementById('password1').value != document.getElementById('password2').value) {
    alert('Please check that your confirmation password matches the first');
    document.getElementById('password1').focus();
    return false;
  }
  if (document.getElementById('math').value != 2) {
    alert('Please answer this simple maths question to continue');
    document.getElementById('math').focus();
    return false;
  }
  return true;
}


function CheckContact() {

  if (document.getElementById('firstname').value == "") {
    alert('Please provide your first name');
    document.getElementById('firstname').focus();
    return false;
  }
  if (document.getElementById('lastname').value == "") {
    alert('Please provide your last name');
    document.getElementById('lastname').focus();
    return false;
  }
  if (document.getElementById('email').value == "") {
    alert('Please provide your email address');
    document.getElementById('email').focus();
    return false;
  }
  if(!checkEmail(document.getElementById('email'))) {
    document.getElementById('email').focus();
    return false;
  }
  if (document.getElementById('password1').value == "") {
    alert('Please provide a password for your account');
    document.getElementById('password1').focus();
    return false;
  }
  if (document.getElementById('password1').value != document.getElementById('password2').value) {
    alert('Please check that your confirmation password matches the first');
    document.getElementById('password1').focus();
    return false;
  }
  if (document.getElementById('phone').value == "" || document.getElementById('phone').value.length<8) {
    alert('Please provide a phone contact');
    document.getElementById('phone').focus();
    return false;
  }
  if (document.getElementById('math').value != 2) {
    alert('Please answer this simple maths question to continue');
    document.getElementById('math').focus();
    return false;
  }
  return true;
}

 function checkEmail ( addressField ) {

      if ( noAtSign ( addressField.value ) )
          alert ( "Uh oh! Your email address needs to have a '@' character" );
      else if ( nothingBeforeAt ( addressField.value ) )
          alert ( "Uh oh! An email address must contain at least one character before the '@' character" );
      else if ( noLeftBracket ( addressField.value ) )
          alert ( "Uh oh! The email address contains a right square bracket ']',\nbut no corresponding left square bracket '['" );
      else if ( noRightBracket ( addressField.value ) )
          alert ( "Uh oh! The email address contains a left square bracket '[',\nbut no corresponding right square bracket ']'" );
      else if ( noValidPeriod ( addressField.value ) )
          alert ( "Uh oh! An email address must contain a period ('.') character" );
      else if ( noValidSuffix ( addressField.value ) )
          alert ( "Uh oh! An email address must contain a two or three character suffix" );
      else
          return true;

      return false;
  }

  function linkCheckValidation ( formField ) {
      if ( checkValidation ( formField ) == true ) {
          return true;
      }

      return ( false );
  }

  function stringEmpty ( address ) {
      // CHECK THAT THE STRING IS NOT EMPTY
      if ( address.length < 1 ) {
          return ( true );
      } else {
          return ( false );
      }
  }

  function noAtSign ( address ) {
      // CHECK THAT THERE IS AN '@' CHARACTER IN THE STRING
      if ( address.indexOf ( '@', 0 ) == -1 ) {
          return ( true )
      } else {
          return ( false );
      }
  }

  function nothingBeforeAt ( address ) {
      // CHECK THERE IS AT LEAST ONE CHARACTER BEFORE THE '@' CHARACTER
      if ( address.indexOf ( '@', 0 ) < 1 ) {
          return ( true )
      } else {
          return ( false );
      }
  }

  function noLeftBracket ( address ) {
      // IF email ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR LEFT BRACKET
      if ( address.indexOf ( '[', 0 ) == -1 && address.charAt ( address.length - 1 ) == ']' ) {
          return ( true )
      } else {
          return ( false );
      }
  }

  function noRightBracket ( address ) {
      // IF email ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR RIGHT BRACKET
      if ( address.indexOf ( '[', 0 ) > -1 && address.charAt ( address.length - 1 ) != ']' ) {
          return ( true );
      } else {
          return ( false );
      }
  }

  function noValidPeriod ( address ) {
      // IF email ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
      if ( address.indexOf ( '@', 0 ) > 1 && address.charAt ( address.length - 1 ) == ']' )
          return ( false );

      // CHECK THAT THERE IS AT LEAST ONE PERIOD IN THE STRING
      if ( address.indexOf ( '.', 0 ) == -1 )
          return ( true );

      return ( false );
  }

  function noValidSuffix ( address ) {
      // IF email ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
      if ( address.indexOf ( '@', 0 ) > 1 && address.charAt ( address.length - 1 ) == ']' )
          return ( false );

      // CHECK THAT THERE IS A TWO OR THREE CHARACTER SUFFIX AFTER THE LAST PERIOD
      var len = address.length;
      var pos = address.lastIndexOf ( '.', len - 1 ) + 1;
      if ( ( len - pos ) < 2 || ( len - pos ) > 3 ) {
          return ( true );
      } else {
          return ( false );
      }
  }
