// ------------------------------------------------------------------
// When Login button is clicked this function will be called
// ------------------------------------------------------------------
function fnLoginClick() {
  var sUserName =
  fnTrimAll ( String ( document.Login.txtUserName.value ),' ')
  var sUserPassword = String(document.Login.txtPassword.value)

  // ---------------------------------------------
  // This will contain the whole message generated

  var sMessageText = ""

  // ------------------------------------
  // UserName length must be > 4
  // -----------------------------------------------------------------------------
  // This variable will check whether there exists a username or not is exist then prompt him for changing password
  // -----------------------------------------------------------------------------
  // var bUserOk = false;

  if( parseInt(String(sUserName).length) < 4 )
  {
    if ( String(sMessageText).length == 0 )
    {
      sMessageText = sMessageText + "- Username must be of minimum 4 characters.";
      document.Login.txtUserName.focus();
    }
    else
    {
      sMessageText = sMessageText + "\n- Username must be of minimum 4 characters.";
    }
  }

  // -----------------------
  // Check for password.

  if( String(sUserPassword).length < 1 )
  {
    var sPasswordLengthMsg = String("- Password was not entered.")
    if ( String(sMessageText).length == 0 )
    {
      sMessageText = sMessageText + String(sPasswordLengthMsg)
      document.Login.txtPassword.focus()
    }
    else
    {
      sMessageText = sMessageText + String("\n") + String(sPasswordLengthMsg)
    }
  }
  // ------------------------------------------------------------------------
  // Check for error message length not 0 then display message

  if(String(sMessageText).length != 0)
  {
    alert ( sMessageText );
    event.returnValue = false;
  }
  else
  {
    document.Login.action = "https://secure.legacynet.com/Login/LoginReg_Login.asp";
    event.returnValue = false;
    document.Login.submit()
  }
}

// Function which will not allow special character
// Write this function on KeyPress Event
function fnResSpecialUserName() {
  var rRegExp = /^(([0-9]|[a-z]|[A-Z])*)$/
  if(!rRegExp.test(String.fromCharCode(window.event.keyCode))) {
    window.event.keyCode = '';
  }
}


// This function replaces the string which is passed as an argument with the Character contained in the sChar 
function fnTrimAll(sSTR, sChar)
{
   return String(sSTR).replace(new RegExp("^" + sChar + "*|" + sChar + "*$", "g"), "")
}

