// To check if all the fields in the form are correctly filled.
// Validation - Reports if all the fields are filled out correctly

function checklogin()
{
 if (testformlogin()) return true;
 else return false;	
}		

function testformlogin()
{

  /* check for email field */
  if (document.login.username.value == "")
  {
   alert("The email field is blank.\n\nPlease enter the email address we have on record.");
   document.login.username.focus();      
   return false;       
  }   

  // Return false if e-mail field does not contain a '@' and '.' .

  if (document.login.username.value.indexOf ('@',0) == -1 || document.login.username.value.indexOf ('.',0) == -1)
  {      
   alert("The email address you have entered is invalid.\n\nPlease re-enter the correct email address we have on record.");      		
   document.login.username.focus();      
   document.login.username.select();      
   return false;      
  }  	

  /* check for password field */

  var password = document.login.password.value;
  if (password == "")
  {
   alert("The password field is blank.\n\nPlease enter the password we have on record.");
   document.login.password.focus();
   return false;
  }

  var password = document.login.password.value;
  for (var i = 0; i < password.length; i++)
  {
   var ch = password.substring(i,i+1);
   if ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch))
   {         
    alert("The password you have entered is invalid.\n\nPlease re-enter the correct password we have on record.");         			
    document.login.password.focus();         
    document.login.password.select();         
    return false;         
   }      
  }
	
 return true;
}

