$(document).ready(function() {

  $("#emailforgotpass").focus();

  $("#forgotpassbutton").on("click", function() {

         // Verify if the email address is correctly formatted
         var emailforgotpreq = $("#emailforgotpass").val();

         if (emailforgotpreq == '') {
             var messageEmail = "Please enter your email address !";
             alert(messageEmail);
         } else if (/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/.test(emailforgotpreq)) {
             var messageEmail = '';
         } else {
             var messageEmail = "The email address is not valid !";
             alert(messageEmail);
           }

         if (messageEmail == '') {

               $.ajax({
                 type: "POST",
                 url: "regain-access.php",
                 dataType: "JSON",
                 data: {
                        emailforgot: emailforgotpreq,
                        messageToUser: messageEmail,
                        verifyToken: getVerifyToken
                       },
                 success: function(reqresponse) {
                     if (reqresponse.result == 'success') {
                         $("#submitmessage").empty();
                         $("#submitmessage").append("<span>"+reqresponse.messageonrequest+"</span>");
                         $("#submitmessage").css("color", "#10ba65");
                     } else {
                         $("#submitmessage").empty();
                         $("#submitmessage").append("<span>"+reqresponse.messageonrequest+"</span>");
                         $("#submitmessage").css("color", "#AC1F23");
                       }
                 },
                 error: function(reqresponse) {
                     $("#submitmessage").empty();
                     $("#submitmessage").append("<span>An error occurred while processing data !</span>");
                     $("#submitmessage").css("color", "#AC1F23");

                 }

               });
         }
  });

});
