function testLoginInput(loginText, loginField)
{
	if (notBlank(loginText)) 
	{
		if (loginField == "Username") var minLen = 3;
		else var minLen = 6;
		if (minMaxLength(loginText, minLen, 20)) 
		{
			if (onlyCharsNums(loginText)) return true;
			else
			{
				if (loginField == "Username") document.getElementById("unstatdiv").innerHTML = "<div class='woopsie'>ERROR: Username may only have alphanumeric characters.</div>";
				else document.getElementById("passstatdiv").innerHTML = "<div class='woopsie'>ERROR: Password may only have alphanumeric characters.</div>";
				return false;
			}
		}
		else
		{
			if (loginField == "Username") document.getElementById("unstatdiv").innerHTML = "<div class='woopsie'>ERROR: Username must have a minimum of 3 and a maximum of 20 alphanumeric characters.</div>";
			else document.getElementById("passstatdiv").innerHTML = "<div class='woopsie'>ERROR: Password must have a minimum of 6 and a maximum of 15 alphanumeric characters.</div>";
			return false;
		}
	}
	else
	{
		if (loginField == "Username") document.getElementById("unstatdiv").innerHTML = "<div class='woopsie'>ERROR: Username cannot be blank.</div>";
		else document.getElementById("passstatdiv").innerHTML = "<div class='woopsie'>ERROR: Password cannot be blank.</div>";
		return false;
	}
}

function processLogin()
{
	var username = document.forms.loginform.username.value;
	var password = document.forms.loginform.password.value;
	
	document.getElementById("unstatdiv").innerHTML = "";
	document.getElementById("passstatdiv").innerHTML = "";
	
	if (testLoginInput(username, "Username"))
	{
		if (testLoginInput(password, "Password"))
		{
			sendToStatus(1, "Processing Login...");
			var formObject = document.getElementById('loginformid'); 
			YAHOO.util.Connect.setForm(formObject); 
			YAHOO.util.Connect.asyncRequest('GET', 'ajax/logmein.php', handleLogin, null);
		}
		else
		{
			document.forms.loginform.password.focus();
			document.forms.loginform.password.select();
		}
	}
	else 
	{
		document.forms.loginform.username.focus();
		document.forms.loginform.username.select();
	}
}

var sendLoginSuccess = function(o){ 
	var results = o.responseText.split('|');
	var respStat = parseInt(results[0]);
	var respText = results[1];
	var username = results[2];
	if (respStat == 2)
	{
		document.getElementById("headright").innerHTML = "";
		window.location = "/";
	}
	sendToStatus(respStat, respText);
}; 

var handleLogin = { success:sendLoginSuccess };
