/* EnterKeyHandler.js
*
* Purpose: To programmatically click a specified button when the user chooses to press the Enter rather than click the actual button.
*
*/

	
function EnterKeyHandler()
{
	// process only the Enter key
    if (event.keyCode == 13)
    {  
		//cancel the default submit
		//these two lines stops the event activated by the enter<BR>
        event.returnValue=false;
        event.cancel = true; 
      
		//***********Determine which button to programmmatically click ************************************
		
		
		//NOTE: The 'Login' button takes precedent over the 'Search' button.
		//If either Login text boxes have data then the Login button will be selected. 
		//The cs code behind handles validation process.
		
		//First Determine if the login area is visible. If user is already logged in then the area is hidden.
		if(document.getElementById("txtUserName") != null && document.getElementById("txtPassword") != null)	
		{		
				if(document.getElementById("txtUserName").value.replace(' ','').length > 0 || document.getElementById("txtPassword").value.replace(' ','').length > 0)
				{
					//submit the form by programmatically clicking the specified button
					document.getElementById('lnkloginhere').click(); 	
				}
				else
				{
					//submit the form by programmatically clicking the specified button
					document.getElementById('btnSearch').click(); 
				}		 
	   }
		else
		{
			//submit the form by programmatically clicking the specified button
			document.getElementById('btnSearch').click(); 
		}	


	}
	
}
