var objLoginBoxUsername;
var objLoginBoxPassword;
var objLoginBoxSubmit;
var blnLoginBoxEventTracking;

function fnValidateLoginBox()
{
	if(objLoginBoxUsername.val().length == 0)
	{
		alert("Username is required.");
		objLoginBoxUsername.focus();
		if (blnLoginBoxEventTracking) Envirofone.fnTrackEvent('Required: Username');
		return false;
	}
	else if(objLoginBoxPassword.val().length == 0)
	{
		alert("Password is required.");
		objLoginBoxPassword.focus();
		if (blnLoginBoxEventTracking) Envirofone.fnTrackEvent('Required: Password');
		return false;
	}
	else
	{
		return true;
	}
}

function fnDefaultButtonLoginBox(event)
{
	var intKeyCode = (event.keyCode ? event.keyCode : event.which);
	
	if(intKeyCode == 3 || intKeyCode == 13)
	{
		event.preventDefault();
		objLoginBoxSubmit.click();
	}
}

$(document).ready(
	function()
	{
		blnLoginBoxEventTracking = ((typeof Envirofone != 'undefined') === true);
		
		var objDiv = $('div.useraccount.login');

		objLoginBoxUsername = objDiv.find("input[id$='TxtUsername']");
		objLoginBoxPassword = objDiv.find("input[id$='TxtPassword']");
		objLoginBoxSubmit = objDiv.find("input[id$='BtnLogin']");

		objLoginBoxUsername.bind('keypress',fnDefaultButtonLoginBox);
		objLoginBoxPassword.bind('keypress',fnDefaultButtonLoginBox);
		objLoginBoxSubmit.bind('click',fnValidateLoginBox);
	}
);