
var imgRoot = "images/";
var loginLabel = "ISL Email Address";
var useSSL = false;

if (typeof(nUseSSL) != 'undefined'){
  useSSL = nUseSSL;
}

if (loginDomain != "")
  loginLabel = "User Name";

if(loginBoxBGColor){
  if (loginBoxBGColor == ""){
    loginBoxBGColor = "#FFFFFF";
  }
}
else{
  var loginBoxBGColor = "#FFFFFF";
}

  document.write("<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 BGCOLOR='" + loginBoxBGColor + "'>" +
    "<FORM NAME='webmailUsLoginForm' ACTION='https://webmail.mailtrust.com/email' METHOD=POST ONSUBMIT='submitWebmailLogin()'>" +
    "<INPUT TYPE=HIDDEN NAME='passed' VALUE='login_parse'>" +
    "<INPUT TYPE=HIDDEN NAME='first' VALUE='1'>" +
    "<INPUT TYPE=HIDDEN NAME='sessionID' VALUE=''>" +
    "<INPUT TYPE=HIDDEN NAME='user_name' VALUE=''>" +
    "<INPUT TYPE=HIDDEN NAME='hostname' VALUE=''>" +
    "<TR>" +
     "<TD WIDTH=167 VALIGN=TOP ALIGN=LEFT>" +
      "<FONT FACE='" + loginBoxFontStyle + "' COLOR='" + loginBoxFontColor + "' SIZE='2'>" + loginLabel + ":<BR>" +
      // "<IMG SRC='" + imgRoot + "spacer.gif' WIDTH=1 HEIGHT=3><BR>" +
      "<INPUT TYPE=TEXT NAME='emailAddr' class='flat' STYLE='width:147px;'><BR>" +
      // "<IMG SRC='" + imgRoot + "spacer.gif' WIDTH=1 HEIGHT=5><BR>" +
      "Password:<BR>" +
      // "<IMG SRC='" + imgRoot + "spacer.gif' WIDTH=1 HEIGHT=3><BR>" +
      "<INPUT TYPE=PASSWORD NAME='password' class='flat' STYLE='width:87px;'>" +
      "<INPUT TYPE=SUBMIT VALUE='Log-In'>");

      // <BR>" +
      // "<IMG SRC='" + imgRoot + "spacer.gif' WIDTH=1 HEIGHT=9><BR>" +
      // "<INPUT TYPE=CHECKBOX NAME='remember' STYLE='width:12px;'>&nbsp;Remember my info<BR>" +
      // "<IMG SRC='" + imgRoot + "spacer.gif' WIDTH=1 HEIGHT=3><BR>");

  if(typeof(nUseSSL) != 'undefined'){
    if (!useSSL){
      document.write("<INPUT TYPE=CHECKBOX NAME='useSSL' STYLE='width:12px;'>&nbsp;Use SSL (Secure)&nbsp;<IMG SRC='" +
					 imgRoot + "ssllogo.gif' WIDTH=12 HEIGHT=15><BR>");
    }
  }
  else{
    document.write("<INPUT TYPE=CHECKBOX NAME='useSSL' STYLE='width:12px;'>&nbsp;Use SSL (Secure)&nbsp;<IMG SRC='" +
				   imgRoot + "ssllogo.gif' WIDTH=12 HEIGHT=15><BR>");
  }

   document.write(
      "</FONT>" +
     "</TD>" +
    "</TR>" +
    "</FORM>" +
   "</TABLE>");

  //Check for "remember me" cookie
var bites = document.cookie.split("; ");
function getCookie(name) {
  for (i=0; i < bites.length; i++) {
    nextbite = bites[i].split("="); // break into name and value
    if (nextbite[0] == name) // if name matches
      return unescape(nextbite[1]); // return value
  }
  return null; // if no match return null
}
var emailCookie = getCookie("emailAddr");
var passCookie = getCookie("password");
var useSSLCookie = getCookie("useSSL");

//login stuff
function setupSession () {

  var splitStrArray = document.webmailUsLoginForm.emailAddr.value.split('@');
  document.webmailUsLoginForm.user_name.value = splitStrArray[0];

  if(loginDomain != "")
    document.webmailUsLoginForm.hostname.value = loginDomain;
  else
    document.webmailUsLoginForm.hostname.value = splitStrArray[1];

  today = new Date();
  document.webmailUsLoginForm.sessionID.value = today.getTime();

  //If "remember" checkbox is checked, drop cookie to remeber "user_name" & "hostname"
  //Else if not checked, delete any existing cookie
  if (document.webmailUsLoginForm.remember.checked) {
    var nextYearDate = new Date(today.getYear()+1,today.getMonth(),today.getDate(),today.getHours(),today.getMinutes(),today.getSeconds());
    document.cookie="emailAddr=" + document.webmailUsLoginForm.emailAddr.value + "; expires=" + nextYearDate.toGMTString() + ";";
    document.cookie="password=" + document.webmailUsLoginForm.password.value + "; expires=" + nextYearDate.toGMTString() + ";";
    if(document.webmailUsLoginForm.useSSL)
      document.cookie="useSSL=" +document.webmailUsLoginForm.useSSL.checked + "; expires=" + nextYearDate.toGMTString() + ";";
  }
  else {
    document.cookie="emailAddr=; expires=Sun, 01-Jan-1995 01:00:00 GMT;";
    document.cookie="password=; expires=Sun, 01-Jan-1995 01:00:00 GMT;";
  }

  document.webmailUsLoginForm.action = 'https://webmail.mailtrust.com/email';

  //If "useSSL" checbox is checked
  if (typeof(document.webmailUsLoginForm.useSSL) != 'undefined'){
    if (document.webmailUsLoginForm.useSSL.checked)
      document.webmailUsLoginForm.action = 'https://webmail.mailtrust.com/email';
    else
      document.webmailUsLoginForm.action = 'https://webmail.mailtrust.com/email';
  }

  if(typeof(nUseSSL) != 'undefined'){
    if(useSSL)
      document.webmailUsLoginForm.action = 'https://webmail.mailtrust.com/email';
  }


}

//Prevent multiple form submissions
var alreadySubmitted = 0;
function submitWebmailLogin() {

  if (!alreadySubmitted) {
    alreadySubmitted = 1;
    setupSession();
    return true;
  }
  else {
    return false;
  }
}

//emailCookie & passCookied retrieved earlier
if ((emailCookie != null) && (passCookie != null)){
  document.webmailUsLoginForm.emailAddr.value = emailCookie;
  document.webmailUsLoginForm.password.value = passCookie;
  document.webmailUsLoginForm.remember.defaultChecked = true;
  document.webmailUsLoginForm.remember.checked = true;

  if(document.webmailUsLoginForm.useSSL){
    if (useSSLCookie == "true")
      document.webmailUsLoginForm.useSSL.checked = true;
    else
      document.webmailUsLoginForm.useSSL.checked = false;
  }
}
