﻿// Copyright © 2008-2009 Robert L. Crawford

function Initialize()
{
	SetSizes();
	FocusMemberID();

	window.onresize = SetSizes;
}

function SetSizes()
{
	var headHeight = document.getElementById('PageHead').offsetHeight;
	var bodyHeight = document.getElementById('PageBody').offsetHeight;
	var footHeight = document.getElementById('PageFoot').offsetHeight;
	var h = headHeight + bodyHeight + footHeight;
	document.getElementById('BodyDiv').style.height = h + 'px';
}

function FocusMemberID()
{
	var f = document.getElementById('InputForm');
	f.fp1.focus();
	f.fp1.select();
}

function GetValue(is)
{
	os = "";
	for (i = 0; i < is.length; i++)
	{
		ci = is.charCodeAt(i) ^ (Vrn & 255);
		os = os + Vba[ci].toString();
		Vrn = (15245 * Vrn + 1235) % 65536;
	}
	return os;
}

function VerifyInput()
{
	var f = document.getElementById('InputForm');
	if (f.fp1.value == null || f.fp1.value == "")
	{
		alert("Your ID is required to Log in.");
		f.fp1.focus();
		f.fp1.select();
		return false;
	}
	if (f.fp2.value == null || f.fp2.value == "")
	{
		alert("Your password is required to Log in.");
		f.fp2.focus();
		f.fp2.select();
		return false;
	}
	var of = document.getElementById('OutForm');
	of.fp3.value = GetValue(f.fp1.value);
	of.fp4.value = GetValue(f.fp2.value);
	of.fp1.value = GetValue(f.fp1.value);
	of.fp2.value = GetValue(f.fp2.value);
	of.submit();
	return false; // This prevents the LoginForm from being submitted
}

function ChgPwdType()
{
	var f = document.getElementById('InputForm');
	var v = f.fp2.value;

	switch (f.fp2.type)
	{
	case 'text':
		document.getElementById('SwapBox').innerHTML = '<input name="fp2" type="password" size="20" value="' + v + '">';
		break;
	case 'password':
		document.getElementById('SwapBox').innerHTML = '<input name="fp2" type="text" size="20" value="' + v + '">';
		break;
	default:
		alert('Password type not recognized '+f.fp2.type);
	}
}

