//-----------------------------------------------------------------
// File: wclogin.js
// Version: v6.1.451.9
// (c) Copyright 2005 Santronics Software, Inc.
//-----------------------------------------------------------------

var EnableSavePassword     = true;
var EnableSignup           = true;
var EnableSecuredMode      = false;
var EnableForgotPassword   = true;
var LoginPageTarget        = "_top";

function doWcGenerateUserHash(uid, pwd, pcase)
{
   // calculate the hash
   if (!pcase && pcase == 0) pwd = pwd.toLowerCase();
   var ha1 = hex_md5(pwd);
   var ha2 = hex_md5(uid + ":" + ha1);
   hash = uid + ":" + ha2
   return hash;
}

function doWcValidate()
{
   var pwd = document.entry.password.value;
   var uid = document.entry.username.value;
   if (uid == "") {
      alert("Please enter your login user name");
      document.entry.username.focus();
      return false;
   }
   if (pwd == "") {
      alert("Please enter your password!");
      document.entry.password.focus();
      return false;
   }
   return true;
}

function doWcLoginAction(pcase)
{
   if (doWcValidate())  {
      var pwd = document.entry.password.value;
      var uid = document.entry.username.value;
      hash = doWcGenerateUserHash(uid,pwd,pcase)
      SetCookie("wcauth", hash, 0, "/");
      var mode = "html";
      if (document.entry.mode) {
         if (document.entry.mode[0].checked)
             mode = document.entry.mode[0].value;
         else
             mode = document.entry.mode[1].value;
      }
      document.login.mode.value = mode;
      document.login.submit();
      return true;
   }
   return false;
}

function PrintLoginForm(title, defUserName, defCase) {
  var uname = defUserName?defUserName:"";
  var pcase = defCase?defCase:0;

  var formtag = "";
  formtag += '<form name="entry" id="entry" ';
  if (EnableSavePassword) {
     formtag += 'autocomplete="on" ';
     formtag += 'onSubmit="return doWcValidate();" ';
     formtag += 'action="javascript:doWcLoginAction('+pcase+');" ';
  } else {
     formtag += 'autocomplete="off" ';
     formtag += 'onSubmit="doWcLoginAction('+pcase+'); return false;"';
  }
  formtag += '>';
  document.writeln(formtag);

  var sBoxColor = "#CEE0CE";
  if (document.location.protocol == "https:") {
      sBoxColor = "#FFFFCC;"
  }

  document.writeln('<style>');
  document.writeln('.btnGrey { background-color:#ccc; border-width:1px; border-style:solid; border-color:#000000; font:bold 10.5px Verdana,Arial,Helvetica,sans-serif;cursor: pointer; }');
  document.writeln('.btnGreyOn { background-color:#666; border-width:1px; border-style:solid; border-color:#000000; color:#fff; font:bold 10.5px Verdana,Arial,Helvetica,sans-serif;cursor: pointer; }');
  document.writeln('.btnGreen { background-color:#9c6; border-width:1px; border-style:solid; border-color:#000000; font:bold 10.5px Verdana,Arial,Helvetica,sans-serif;cursor: pointer; }');
  document.writeln('.btnGreenOn { background-color:#693; border-width:1px; border-style:solid; border-color:#000000; color:#fff; font:bold 10.5px Verdana,Arial,Helvetica,sans-serif;cursor: pointer; }');
  document.writeln('</style>');

  document.writeln('<table id="loginTable" border="0" cellspacing="1" cellpadding="1" align="center" style="background-color:'+sBoxColor+'; border: 2px solid black;">');
  document.writeln('<tr><td colspan="2" align="left"><b>'+title+'</b></td><td align="right"><a href="/" target="_top" class="btnGrey" onmouseover="this.className=\'btnGreyOn\'" onmouseout="this.className=\'btnGrey\'" >&nbsp;home&nbsp;</a></td></tr>');

  document.writeln('<tr valign=top align=left>');
  document.writeln(' <td>Username:</td>');
  document.writeln(' <td><input type="text" name="username" value="'+uname+'" size=24 maxlength=32></td>');
  document.writeln(' <td>&nbsp;</td>');
  document.writeln('</tr>');

  document.writeln('<tr valign=top align=left>');
  document.writeln(' <td>Password:</td>');
  document.writeln(' <td><input type="password" name="password" value="" size=24 maxlength=32></td>');
  document.writeln(' <td><input type="submit"  value="&nbsp;Login&nbsp; &raquo;" class="btnGreen" onmouseover="this.className=\'btnGreenOn\'" onmouseout="this.className=\'btnGreen\'"></td>');
  document.writeln('</tr>');

  var args = document.location.search;
  var webmode = "checked";
  var navmode = "";
  if (args.toLowerCase().match("mode=client")) {
     webmode = "";
     navmode = "checked";
  }

  document.writeln('<tr>');
  document.writeln(' <td valign="top">Mode:</td>');
  document.writeln(' <td><input type="radio" name="mode" value="html" '+webmode+'>&nbsp;Use Web Browser<br>');
  document.writeln('     <input type="radio" name="mode" value="client" '+navmode+'>&nbsp;Use FidoTel Surfer&nbsp;</td>');
  document.writeln(' <td align=right> </td>');
  document.writeln('</tr>');

  if (EnableSecuredMode) {
     document.write('<tr>');
     var sProto = "http://";
     var sTxt   = "Switch to Unsecured Mode";
     var sImage = "unlock.gif";
     if (document.location.protocol == "http:") {
        sProto = "https://";
        sTxt   = "Switch to Secured Mode";
        sImage = "lock.gif";
     }
     var href = sProto+document.domain+document.location.pathname+document.location.search;
     document.write('<td colspan=3 align="center">');
     document.write('<a href="'+href+'">');
     document.write('<img src="/public/graphics/'+sImage+'" border="0">&nbsp;'+sTxt);
     document.write('</a>');
     document.write('</td>');
     document.writeln('</tr>');
  }

  if (EnableForgotPassword) {
     document.write('<tr>');
     document.write('<td colspan=3 align="center">');
     document.write('<a href="/public/forgotpassword.wct">Forgot your password?</a>');
     document.write('</td>');
     document.writeln('</tr>');
  }
  if (EnableSignup) {
     document.write('<tr>');
     document.write('<td colspan=3 align="center">');
     document.write('<a href="/Signup">Not registered? Create new account</a>');
     document.write('</td>');
     document.writeln('</tr>');
  }

  document.writeln('</table>');

  document.writeln('</form>');
  document.writeln('<form name="login" action="/login" method="get" target="'+LoginPageTarget+'">');
  document.writeln('<input type="hidden" name="js"  value="1">');
  document.writeln('<input type="hidden" name="mode"  value="">');
  document.writeln('</form>');

}


