<!--
//***************************************************************************************************************
//Filename		:  login.js
//Author	    :  Soholife
//Date/Time		:  8/13/2002
//Purpose	    :  This page contains functions used for JavaScript login form field
//
//Parameters	:  
//Revisions		:  <03/26/2003,Kevin Chang ,add the key event handler and trim for password.>
//***************************************************************************************************************

//Add the key event hander
//Netscape 4.x
if(document.layers)
{
	document.captureEvents(Event.KEYPRESS)
	document.onkeypress=doEnterKey;
}
//Internet Explorer 4/5/5.5/6.0
if(document.all)
{
	//document.onkeydown=doEnterKey;
	document.onkeypress=doEnterKey;
}
else
{
	//Netscape 6/7 
	if(document.getElementById)
	{
		document.addEventListener("keydown",doEnterKey,false);
		//document.addEventListener("keypress",doEnterKey,false);
	}
}

function doEnterKey(e)
{
	//Netscape 4.x
	if (document.layers)
	{
		if(parseInt(e.which)==13)
		{
			if(e.target==document.frmLogin.txtPassword)
			{
				validate();
			}
		}
	}

	//Internet Explorer 4/5/5.5/6.0
	if (document.all)
	{
		if(parseInt(event.keyCode)==13)
			if(event.srcElement==document.frmLogin.txtPassword)
			{
				validate();
			}

	}
	else
	{
		//Netscape 6/7 
		if (document.getElementById)
		{
			if(parseInt(e.keyCode)==13)
				if(e.target==document.frmLogin.txtPassword)
				{
					validate();
				}
		}
	}
}

function validate()
{
	// remove the space from the string head and tail
	String.prototype.Trim = function()
	{
		return( (this.replace(/^\W+/,'')).replace(/\W+$/,'') );
	}
	
	var sUsername = document.frmLogin.txtUserLoginId.value;
	var sPassword = document.frmLogin.txtPassword.value;
	
	sPassword = sPassword.Trim();

	if (sUsername == "")
	{
		alert("Please enter your username.");
		return false;
	}
	else if (sPassword == "") 
	{
		alert("Please enter your password.");
		return false;
	}

	document.frmLogin.submit();
}
//-->