function fixupLogin()
{
	trim('login');
}

function validLogin()
{
	if (!validLoginID())
		return false;
	if (!validPassword())
		return false;
	if (warnIfBlank('password', 'Password'))
		return false;
	if (!verifyPassword())
		return false;
	return true;
}

function validLoginID() 
{ 
	field = getFormElement('login'); 
	if (field == null) 
		return true;
	if (warnIfBlank('login', 'Login ID')) 
		return false;
	str = field.value;
	if (str.length > 20)
	{
		field.select();
		field.focus();
		alert('Login ID cannot be longer than 20 characters, please choose a shorter ID.');
		return false;
	}
	for (i = 0; i < str.length; i++) 
	{ 
		ch = str.charAt(i);
		if (!isLower(ch) && !isUpper(ch)
		    && !isDigit(ch) && ch != '_' && ch != '-')
		{
			field.select();
			field.focus();
			alert('Login ID can only contain letters, digits, - or _');
			return false;
		}
	} 
	return true; 
} 

function validPassword()
{
	field = getFormElement('password');
	if (field == null)
		return true;
	pw = field.value;
	if (pw.len == 0)
		return true;
	if (pw.length > 20)
	{
		field.select();
		field.focus();
		alert('Password cannot be longer than 20 characters, please choose a shorter password.');
		return false;
	}
	if (pw.charAt(0) == ' ' || pw.charAt(pw.length - 1) == ' ')
	{
		field.select();
		field.focus();
		alert('Password cannot have leading or trailing spaces');
		return false;
	}
	return true;
}

function verifyPassword()
{
	pw = getFormElement('password');
	if (pw == null)
		return true;
	pw2 = getFormElement('password2');
	if (pw2.value != pw.value)
	{
		if (pw2.value.length < 1)
			pw2.value = ' ';
		pw2.select();
		pw2.focus();
		alert('Re-entered password does not match');
		return false;
	}
	return true;
}
