//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;
		}
	}
}

function ClickButton(btnID)
{
    var btn = document.getElementById(btnID);
    
    if (!btn)
    {
        return;
    }
    
    btn.click();
}

// function to click a button when 'Enter' is pressed from a control on the page
function KeyDownHandler(btn,evt)
{
    //test for FireFox and handle the event accordingly
    var ff = typeof evt.which != "undefined";
    var key = (ff) ? evt.which : event.keyCode;
    // process only the Enter key
    if (key == 13)
    {
        // cancel the default submit
        if(ff)
        {
            evt.returnValue=false;
            evt.cancel = true;
        }
        else
        {
            event.returnValue=false;
            event.cancel = true;
        }
        // submit the form by programmatically clicking the specified button
        btn.click();
    }
    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;
}
