//To give focus to the Email field
function atLoad(strEmailPwd)
{
	if(strEmailPwd == "email")
	{
		var Element = document.getElementById('txtEMail');
		if(!Element)
			return;
		Element.focus();
	}
	else
	{
		var Element = document.getElementById('txtPassword');
		if(!Element)
			return;
		Element.focus();
	}
}

// To Validate Email and Password Fields
function ValidateLogIn()
{
	var objForm = document.forms[0];
	
	if(objForm.txtEMail.value == "")
	{
		alert("Email address should not be empty.");
		objForm.txtEMail.focus();
		return false;
	}
	else
	{
		if(CheckEmailFormat(objForm.txtEMail.value))
		{
			if(objForm.txtPassword.value == "")
			{
				alert("Password should not be empty.");
				objForm.txtPassword.focus();
				return false;
			}				
			else if(objForm.txtPassword.value.length < 4)
			{
				alert("You have entered an invalid password. Please re-enter your password.");
				objForm.txtPassword.value = "";
				objForm.txtPassword.focus();
				return false;
			}
			//Function to check for Special Characters
			return checkSpecialCharacters();
		}
		else
		{
			alert("You have entered an invalid email address. Please re-enter your email address.");
			objForm.txtEMail.select();
			objForm.txtPassword.value = "";
			return false;
		}
	}
}

//This function clear the login fields username and password.
//If input wrong username and password with special character.
//Then "A potentially dangerous" error comes.
function ClearLoginFields()
{
	var objForm = document.forms[0];

	objForm.txtEMail.value		= "";
	objForm.txtPassword.value	= "";
	
	return true;
}
