﻿function ValidateEmailLogin() {
  var errMsg, errFlag, focusField, TestPattern, PatternResult;
  
    errMsg = "Please complete the following first.\n\n";
    errFlag = 0;

    if (document.form_emaillogin.email.value == "Email Address") {
      if (errFlag == 0) {
        focusField = document.form_emaillogin.email;
        errFlag = 1;
      }
      errMsg = errMsg + " - We really need an actual email address here.     \n";
    }
    else {
      // Check the format of the eMail Address
      TestPattern = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/ ;
      PatternResult = document.form_emaillogin.email.value.match(TestPattern);
      if (PatternResult == null) {
        errMsg = errMsg + " - Hmmm.. that email address doesn't look like its correctly formatted?  Try again.     \n";
        if (errFlag == 0) {
          focusField = document.form_emaillogin.email;
          errFlag = 1;
    } } }

  // if there is no error, then submit the form
    if (errFlag == 0) {
      // document.form_emaillogin.action = "http://mail.betterconnect.co.za/Login.aspx";
      document.form_emaillogin.submit();
      return true;
    }
    else {
      alert(errMsg);
      focusField.focus();
      return false;
    }
}
