/*  -------------------  Get 'ThisDoc' from calling code ------------------- */

	var GetKey;
	var keycounter=0;
	var HasInfo;

	var TestedLogonNam = false ;
	var TestedLogonPwd = false ;
	var TestedLogonPIN = false ;
	var TestedCheckBox = false;
	
/* -------------------------------------- Key Capture ------------------------------- */
	if (document.layers)
		document.captureEvents(Event.KEYPRESS)
	function GetKeyVal(e){
		if (document.layers){
			GetKey = e.which;
			if (e.which==13) {
				TestKey(ThisDoc)
			}
		}
		else if (document.all){
			GetKey = event.keyCode;
			if (event.keyCode==13) {
				TestKey(ThisDoc)
			}

		}
		
		/* Escape and backspace to exit */
		if (ThisDoc.LogonName.value=="" && GetKey == 8)
			SeeYa();

		if (GetKey == 27)
			SeeYa();

	}
	document.onkeypress=GetKeyVal
/* ------------------------------------ End of Key Capture ---------------------------- */

/* ---------------------  Document Specific Cookie Functions --------------------- */

	/*  Cookie names:
		UType
		LNam
		LPwd
		LPin
	*/

	
	/* Read cookie to populate form
	   ---------------------------- */
	var HasInfo = false;
	
	var LogonNam = ReadCookie("LNam")
	if (LogonNam)	{	
		ThisDoc.LogonName.value = LogonNam;
		HasInfo = true;
	}
	else {
		HasInfo = false;
	}

	var LogonPwd = ReadCookie("LPwd")
	if (LogonPwd)	{	
		ThisDoc.LogonPwd.value = LogonPwd;
		HasInfo = true;
	}
	else {
		HasInfo = false;
	}
	
	var LogonPIN = ReadCookie("LPin")
	if (LogonPIN)	{	
		ThisDoc.LogonID.value = LogonPIN;
		HasInfo = true;
	}
	else {
		HasInfo = false;
	}
	
	if (HasInfo == true) {
		ThisDoc.SaveInfoBox.checked=true;
		ThisDoc.LogonButton.focus();
	}
	

	/* See if it was invalid */
	if (ThisDoc.InValidAccess.value =="YES") {
		alert("Invalid access information. Please try again.");
		ToastCookie();
		ClearVars();
		ThisDoc.InValidAccess.value ="NO";
	}


function Remember() {

	expdate = new Date();
	// Cookie expires in 1 year
	expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 

	WhichVER == "GRAF"
	WriteCookie("RVer", WhichVER, expdate)

	if (ThisDoc.SaveInfoBox.checked == true) {
		LogonNam = ThisDoc.LogonName.value;
		LogonPwd = ThisDoc.LogonPwd.value;
		LogonPIN = ThisDoc.LogonID.value;
			
		WriteCookie("LNam", LogonNam, expdate)
		WriteCookie("LPwd", LogonPwd, expdate)
		WriteCookie("LPin", LogonPIN, expdate)
	}
	else {
		ToastCookie();
	}

}

function ToastCookie() {
	LogonNam = "NULL";
	LogonPwd = "NULL";
	LogonPIN = "NULL";

	/* Set to expire NOW */
	expdate = new Date();
	expdate.setTime(expdate.getTime())
	
	WriteCookie("LNam", LogonNam, expdate)
	WriteCookie("LPwd", LogonPwd, expdate)
	WriteCookie("LPin", LogonPIN, expdate)
}

function ClearVars(){
	ThisDoc.LogonName.value = "";
	ThisDoc.LogonPwd.value = "";
	ThisDoc.LogonID.value = "";
	ThisDoc.SaveInfoBox.checked=false;
	ThisDoc.LogonName.focus();
}

/* --------------------------  Generic Cookie Functions -------------------------- */

function ReadCookie(CookieName) {
	var prefix = CookieName + "="
	var cookieStartIndex = document.cookie.indexOf(prefix)
	if (cookieStartIndex == -1)
		return null
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

function WriteCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + 
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "")

	document.cookie = curCookie
 }

/* -----------------------  End of Generic Cookie Functions ----------------------- */

function TestKey(form,k)
{
	if (form.LogonName.value == "") {
		if (TestedLogonNam == true)
			alert("Please enter your LOGON NAME");
		TestedLogonNam = true ;
		form.LogonName.focus();
		return(false);
	}
	else if (form.LogonPwd.value == "") {
		if (TestedLogonPwd == true)
			alert("Please enter your PASSWORD");
		TestedLogonPwd = true ;
		form.LogonPwd.focus();
		return(false);
	}
	else if (form.LogonID.value == "") {
		if (TestedLogonPIN == true)
			alert("Please enter your PIN");
		TestedLogonPIN = true;
		form.LogonID.focus();
		return(false);
	}
	else if (TestPIN(form) == false) {
		return(false);
	}

	if (k != 1) {
		if (TestedCheckBox == false && HasInfo == false){
			if (ThisDoc.SaveInfoBox.checked != true) {
				TestedCheckBox = true;
				form.SaveInfoBox.focus();
				return(false);
			}
		}
	}
	
	form.submit();
	return(true);
	
}


function TestPIN (form) {
var checkOK = "0123456789";
	var checkStr = form.LogonID.value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
			break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
	}
	if (!allValid)
	{
		alert("Please enter a valid PIN");
		form.LogonID.value = "";
		form.LogonID.focus();
		return (false);
	}
	else {
		return (true);
	}

}

function ZapStuff(form) {
	form.LogonName.value = "";
	form.LogonPwd.value = "";
	form.LogonID.value = "";
	form.LogonName.focus();
}


function SeeYa()
{
	location.href= BackTo
	// history.go(-1);
}
