function SetCookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}


function HashedResponse() 
{
	if (document.entry.username.value != "" && document.entry.password.value != "")
  	{
		var invalid = "."; // Invalid character is a dot
		if (document.entry.username.value.indexOf(invalid) > -1) 
//		if (document.entry.username.value.charAt(0) = " ") 
		{
			alert("Please use SPACE between you first and last name.");
		}
		else
		{
	  
    		// calculate the hashes
	    	ha1 = hex_md5(document.entry.password.value.toLowerCase())
		    ha2 = hex_md5(TrimString(document.entry.username.value) + ":" + ha1);
    		hash = TrimString(document.entry.username.value) + ":" + ha2
	    	document.entry.password.value = "";
		    SetCookie("wcauth", hash, 0, "/");
		    if (document.entry.mode[0].checked)
	    	    document.login.mode.value = document.entry.mode[0].value;
	    	else
    	    	document.login.mode.value = document.entry.mode[1].value;
			document.login.submit();
			return;
		}
  	}
  	alert("Please enter your login id and password!");
}

function TrimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}



function PrintLoginForm(title) {
  document.writeln('<form name="entry">');
  document.writeln('<table width="180" border="0" cellspacing="0" cellpadding="7" align="left" bgcolor="#A4D3EE"><tr><td>');
  document.writeln('<table width="180" border="0" cellspacing="0" cellpadding="3" align="left" bgcolor="#A4D3EE">');
  document.writeln('<tr>');
  document.writeln('<td COLSPAN="2" valign="Middle"><FONT SIZE="+1" color="RED">Login to Ability Online</FONT></td>');
  document.writeln('</tr>');
  document.writeln('<tr valign=top align=left>');
  document.writeln('<td valign="Middle"><FONT COLOR="BLACK">Username:</FONT></td>');
  document.writeln('<td colspan=2><input type="text" name="username" value="" size=18 maxlength=32></td>');
  document.writeln('</tr>');
  document.writeln('<tr valign=top align=left>');
  document.writeln('<td valign="Middle"><FONT COLOR="BLACK">Password:</FONT></td>');
  document.writeln('<td colspan=2><input type="password" name="password" value="" size=18 maxlength=32></td>');
  document.writeln('</tr>');
  document.writeln('<td><input type="hidden" name="mode" value="html" checked> <input type="hidden" name="mode" value="client" disabled></td>');
  document.writeln('<td align=right> <input onClick="HashedResponse(); return false;" type="submit"  value="&nbsp;Login&nbsp;"></td>');
  document.writeln('</tr>');
  document.writeln('<tr>');

  if (document.URL.charAt(4) == "s")
    {document.writeln('<td COLSPAN="2" ALIGN="RIGHT"><FONT COLOR="BLACK" ALIGN="RIGHT">Mode: <a href="http://10.10.10.215" CLASS="login"><font color="blue"><b>Standard</b></font></a> | <B>Secure</B> </FONT><A accesskey="H" HREF="/public/newhelp.htm" target="_blank"><img src="/public/graphics/helpicon.gif" align="bottom" border="0" ALT="Help"></A></td>');}
  else
    document.writeln('<td COLSPAN="2" ALIGN="RIGHT"><FONT COLOR="BLACK" ALIGN="RIGHT">Mode: <B>Standard</B> | <a href="https://10.10.10.215" CLASS="login"><font color="blue"><b>Secure</b></font></a> </FONT><A accesskey="H" HREF="/public/newhelp.htm" target="_blank"><img src="/public/graphics/helpicon.gif" align="bottom" border="0" ALT="Help"></A></td>');

  document.writeln('</tr>');
  document.writeln('<tr>');
  document.writeln('<td COLSPAN="2" ALIGN="RIGHT"><A HREF="/public/code/html-fp" CLASS="login"><FONT COLOR="#0b0c5f">Forgot your Password?</FONT></A></td>');
  document.writeln('</tr>');
  document.writeln('<tr>');
  document.writeln('<td COLSPAN="2" ALIGN="RIGHT"><A HREF="/public/code/html-ps" CLASS="login"><FONT COLOR="#0b0c5f">Having trouble logging in or have comments?</FONT></A><br><HR></td>');
  document.writeln('</tr>');
  document.writeln('<tr>');
  document.writeln('<td COLSPAN="2" ALIGN="LEFT"><FONT COLOR="BLACK">New? Not Registered?</FONT></td>');
  document.writeln('</tr>');
  document.writeln('<tr>');
  document.writeln('<td COLSPAN="2" valign="Middle"><A href="https://www.ablelink.org/public/safety.htm" alt="New User" CLASS="login"><FONT SIZE="+0" color="BLUE"><B>Register Now</B></FONT> - it&#039;s FREE</A></td>');
  document.writeln('</tr>');
  document.writeln('<tr>');
  document.writeln('</td></tr>');
  
  document.writeln('<tr>');
  document.writeln('<td COLSPAN="2" valign="Middle">');

  document.writeln('<table width="100%" border="0" cellspacing="0" cellpadding="3" align="left" bgcolor="#3C468D">');
  document.writeln('<tr>');
  document.writeln('<td valign="Middle"><FONT SIZE="-1">About Us</FONT></td>');
  document.writeln('</tr>');
  document.writeln('<tr>');
  document.writeln('<td valign="Middle"><FONT SIZE="-1">Donation/Sponsorship</FONT></td>');
  document.writeln('</tr>');
  document.writeln('<tr>');
  document.writeln('<td valign="Middle"><FONT SIZE="-1">Volunteers</FONT></td>');
  document.writeln('</tr>');
  document.writeln('<tr>');
  document.writeln('<td valign="Middle"><FONT SIZE="-1">News</FONT></td>');
  document.writeln('</tr>');
  document.writeln('<tr>');
  document.writeln('<td valign="Middle"><FONT SIZE="-1">Events</FONT></td>');
  document.writeln('</tr>');
  document.writeln('<tr>');
  document.writeln('<td valign="Middle"><FONT SIZE="-1">Resources</FONT></td>');
  document.writeln('</tr>');
  document.writeln('<tr>');
  document.writeln('<td valign="Middle"><FONT SIZE="-1">Contact Us</FONT></td>');
  document.writeln('</tr>');
  document.writeln('</table>');

  document.writeln('</td>');
  document.writeln('</tr>');

  document.writeln('</table>');
  document.writeln('</td></tr></table>');
  document.writeln('</form>');
  document.writeln('<form name="login" action="/login" method=get>');
  document.writeln('<input type="hidden" name="js"  value="1">');
  document.writeln('<input type="hidden" name="mode"  value="">');
  document.writeln('</form>');

}


