
/*************************************************************************************
 *
 * Filename       functions.js
 * 
 * Application    Aviation Information System (Java Version)
 * 
 * Purpose        To validate AIS user inputs like email and password.
 * 
 * Change History:
 *   04/20/2005              	Ram Pasala       	Creation.
 * 
 *************************************************************************************/

function ValidateEmail(theElement, theElementName) {
   var s = theElement;
   var filter=/^[A-Za-z0-9_][A-Za-z0-9\._-]*@[A-Za-z+0-9\._-]+\.[A-Za-z+0-9\._]+[A-Za-z]$/;
   if ( (s.value == "") || (!filter.test(s.value)) ) {
      s.value = "";
      s.focus();
      alert("Please enter a valid email address!" );
      return false;
   }
   return true;
}

function ValidatePasswdSubmit(theElement, theElementName) {
   var pw=theElement.value;
   var regexpAllowed = /^((\d)|[a-zA-Z]|[-]|[_]|[~]|[#]|[!]|[.]|[,])+$/;
   if(regexpAllowed.test(pw)) {
      return true;
   }
   else {
       return false;
   }
} //end function ValidatePasswdSubmit

function ValidatePasswdChange(theElement, theElementName) {
   var pw=theElement;
   var newString="";
   var msg="";
   var regexpAllowed = /^((\d)|[a-zA-Z]|[-]|[_]|[~]|[#]|[!]|[.]|[,])+$/;

   if( ! regexpAllowed.test(pw.value) ) {
      msg ="The "+theElementName+" field contains an illegal character. \n";
      msg+="Only non-space ASCII characters, numbers, or elements\nof the character set [-_~#!.,] are allowed.\n\n";
      msg+="\nPlease re-enter the "+theElementName+" value.";
      pw.value= "";
      pw.focus();
      alert(msg);
      return false;
   }
   else {
      return true;
   }
} //end function ValidatePasswdChange
