

function AttemptLogin()
{
	if (!IsValidEmail(document.LoginForm.EmailAddress.value))
	{
		FocusOnField(document.LoginForm.EmailAddress);
		ShowPopup(true, "ERROR", "Please enter a valid e-mail address.");	
	}
	else if(document.LoginForm.Password.value.length <= 0)
	{
		FocusOnField(document.LoginForm.Password);
		ShowPopup(true, "ERROR", "Please enter your password.");	
	}
	else
		AjaxCall("POST","login.php","SubmitLoginForm=848&EmailAddress=" + document.LoginForm.EmailAddress.value + "&Password=" + document.LoginForm.Password.value, "AfterAttemptLogin", true);
}


function AfterAttemptLogin(xml, text)
{
	/*
		1. If success, hide the login form and show the success message
		2. If failure, show the error message above the login form.
		
		<Data>
			<ErrorMessage>
			</ErrorMessage>
		</Data>
	*/
	
	var ErrorMessage = "";

	if (xml.getElementsByTagName("Data")[0].childNodes[0].childNodes[0])
		ErrorMessage = xml.getElementsByTagName("Data")[0].childNodes[0].childNodes[0].nodeValue;
		
	if (xml.getElementsByTagName("Data")[0].childNodes[1].childNodes[0])
		Firstname = xml.getElementsByTagName("Data")[0].childNodes[1].childNodes[0].nodeValue;

	if (ErrorMessage.length <= 0)
	{
		document.getElementById('WhiteContentWrapper').innerHTML = "<h2>You have successfully logged in!</h2>";
		document.getElementById('LoginWrapper').innerHTML = "Welcome back, " + Firstname;
	}
	else
		ShowPopup(true, "ERROR", ErrorMessage);
}
