function setFocus(input)
{
	if(document.formLogin)
		document.formLogin.actnum.focus();
	if(input == 'true')
		window.blur();
}
/*
setLabel(id,		id of the tag to change
		 state)		state to change it to (true = RED, false = BLACK)

Sets the classname of a <label> to either 'label' or 'labelErr'.
When className is 'label', the label will be black indicating acceptable input.
When className is 'labelErr', the label will be red idicating invalid input.
*/
function setLabel(id, state)
{
	if(state)
		id.className="label";
	else
		id.className="labelErr";
}

/*
alpha(str)

Checks all characters in string 'str'.  If any are not A-Z (case insensitive) and
they are not a space, dash or a apostrophe, return false, otherwise return true
*/
function alpha(str)
{
	for(var x = 0; x < str.length; x++)
	{
		var ch = str.charAt(x);
		var code = ch.charCodeAt(0);
		if((code < 65) || (code > 123) || ((code > 90) && (code < 97)))
		{
			if((code == 32) || (code == 39) || (code == 45))
				continue;
			else
				return false;
		}
	}
	return true;
}

/*
alphanumeric(str)

Checks all characters in string 'str'.  If any are not A-Z (case insensitive) or 
0-9 return false, otherwise return true
*/
function alphanumeric(str)
{
	for(var x = 0; x < str.length; x++)
	{
		var ch = str.charAt(x);
		var code = ch.charCodeAt(0);
		if(code == 45 || ((code > 47) && (code < 58)) || ((code > 64) && (code < 91)) || ((code > 96) && (code < 123)))
			continue;
		else
			return false;
	}
	return true;
}

/*
validateActnum(field,	input field 
			   id)		id of label associated with 'field'

Checks if length is greater than 5 and that it is alphanumeric
then sets the color of the label */
function validateActnum(field, id)
{
		identity = document.getElementById(id);
		if(field.value.length > 5)
			setLabel(identity, (alphanumeric(field.value)));
		else
			setLabel(identity, false);
}
/*
validateName(field,	input field 
			   id)		id of label associated with 'field'

Checks if length is greater than 1 and that it is A-Z (case
insensitive) only then sets the color of the label 
(Name can be seperated by 1 dash, space, or apostrophe [i.e. hyphenated]
*/
function validateName(field, id)
{
		pattern = /^[A-Za-z]+[- ']{0,1}[A-Za-z]+$/;
		identity = document.getElementById(id);
		setLabel(identity, validateExpression(field.value, pattern));
}
/*
validateName(field,	input field 
			   id)		id of label associated with 'field'

Checks if length is greater than 1 and that it is A-Z (case
insensitive) only then sets the color of the label 
(Name can be seperated by 1 dash, space, or apostrophe [i.e. hyphenated]
*/
function validateMInitial(field, id)
{
		pattern = /^[A-Za-z]{1}$/;
		identity = document.getElementById(id);
		setLabel(identity, validateExpression(field.value, pattern));
}
/*
validateSSN(field,	input field 
			   id)		id of label associated with 'field'

Checks for valid SSN using the regular expression in 'pattern'
then sets the color of the label */
function validateSSN(field, id)
{
	    var pattern = /^([0-6]\d{2}|7[0-6]\d|77[0-2])([-])(\d{2})([-])(\d{4})$/;
		identity = document.getElementById(id);
		setLabel(identity, validateExpression(field.value, pattern));
}
/*
validateDOB(field,	input field 
			   id)		id of label associated with 'field'

Checks for valid date of birth using the regular expression in 
'pattern' then sets the color of the label */
function validateDOB(id)
{
		identity = document.getElementById(id);
		if((document.getElementById('month').value == "") || (document.getElementById('day').value == "") || (document.getElementById('year').value == ""))
			setLabel(identity, false);
		else
			setLabel(identity, true);
}



/*

validatePhone(field,	input field 

			   id)		id of label associated with 'field'



Checks for valid Phone number using the regular expression in 'pattern'

then sets the color of the label */

function validatePhone(field, id)
{
		pattern = /^[(]{0,1}[0-9]{3}[-. )]{1}[0-9]{3}[-. ]{1}[0-9]{4}$/;
		identity = document.getElementById(id);
		setLabel(identity, validateExpression(field.value, pattern));
		/*
		if(validateExpression(field.value, pattern))
			setLabel(identity, true);
		else
			setLabel(identity, false);
		*/
}

/*
validateExpression(str,		string to test 
				   id)		regexp pattern to test against

If 'str' matches regexp 'pattern' return true, otherwise return false */
function validateExpression(str, pattern)
{
    if (pattern.test(str)) { return true; } else { return false; }	
}

function validateSubmit()
{
	// Test all the inputs and set their text color according to error number (GOOD = Black, BAD = Red)
	// if any are RED then test will equal zero and user must fix the problem
	var test = 1;
	var id;
	validateActnum(document.formLogin.actnum, "id_actnum");
	id = document.getElementById("id_actnum");
	test = test & (id.className == "label");
	
	validateName(document.formLogin.fname, "id_fname");
	id = document.getElementById("id_fname");
	test = test & (id.className == "label");
	
/*	validateMInitial(document.formLogin.mname, "id_mname");
	id = document.getElementById("id_mname");
	test = test & (id.className == "label");*/

	validateName(document.formLogin.lname, "id_lname");
	id = document.getElementById("id_lname");
	test = test & (id.className == "label");
	
	validateSSN(document.formLogin.ssn, "id_ssn");
	id = document.getElementById("id_ssn");
	test = test & (id.className == "label");
	
	validateDOB("id_dob");
	id = document.getElementById("id_dob");
	test = test & (id.className == "label");
	
	validatePhone(document.formLogin.phone, "id_phone");
	id = document.getElementById("id_phone");
	test = test & (id.className == "label");
	
	if(test)
	{
		return true;
	}
	else
	{
		id = document.getElementById("inputCheck");
		id.className = "badInput";
		return false;
	}
}