
// flag indicating whether or not user login input was successfully validated i.e. not empty
var validated = true;

// defaults to loginNameTxtBox, but set via dynamically rendered declaration of this variable value from asp.net code behind

var LoginFocusObjectId = "loginNameTxtBox"; 


// called on window load to set textbox focus

function setLoginFocus()
{
	document.getElementById(LoginFocusObjectId).focus();
}
					
function swapClass(obj,ClassName)
{
	document.getElementById(obj).className = ClassName
}

// clears login name and passwors input textboxes
function clearBoxes()
{
	document.getElementById("loginNameTxtBox").value = "";
	document.getElementById("passwordTxtBox").value = "";
}

// clears all validation messages (as they may still exist on screen from a previous failed login attempt)
function clearPreviousMessages()
{

	document.getElementById("passwordMsg").style.display = "none";      
	document.getElementById("loginNameMsg").style.display = "none";
	//document.getElementById("pleaseCompleteMsg").style.display = "none";
}
    
// VALIDATES REQUIRED LOG IN DETAILS HAVE BEEN ENTERED BEFORE SUBMISSION TO SERVER    

function validateLogin()
{
	clearPreviousMessages();
	validated = true;

       // check password textbox is not empty

       if( !checkValueEntered( document.getElementById("passwordTxtBox").value ) )
       {
            validated = false;
            document.getElementById("passwordMsg").style.display = "block";      
		//	document.getElementById("pleaseCompleteMsg").style.display = "block";
			setLoginFocus("passwordTxtBox");
       }

       // check login name textbox is not empty
        
       if( !checkValueEntered( document.getElementById("loginNameTxtBox").value ) )
       {
            validated = false;
            document.getElementById("loginNameMsg").style.display = "block";
			//document.getElementById("pleaseCompleteMsg").style.display = "block";      
			setLoginFocus("loginNameTxtBox");
       }

       return validated
   
}
    

// CHECKS TEXTBOX IS NOT EMPTY
    
function checkValueEntered( elemValue ) 
{
	var str = elemValue;
	var re = /.+/;

	if( !str.match(re) ) 
	{
		return false;
	}
	
	else
	{
	   return true;
	}

}
    
    // SET TEXTBOX FOCUS ON PAGE LOAD
    
    window.onload = setLoginFocus
    
    