  // Returns true if character is a lowercase or uppercase letter
  function isLetter(c) {  
    return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
  }
  
  // Returns true if character c is a digit (0 .. 9).
  function isDigit(c) {  
    return ((c >= "0") && (c <= "9"))
  }
  
  function isWhite(c) {  
    return ((c == ' ') || (c == '\t') || (c == '\n') || (c== '\r'))
  }
  
  
  function isEmailChar(s) { 
    // Search through string's characters one by one
        // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (var i = 0; i < s.length; i++) {   
    
      // Check that current character is number or letter.
      var c = s.charAt(i)

      if (!(    isLetter(c)
          ||  isDigit(c)
          ||  c == "."
          ||  c == "-"
          ||  c == "_"
          ||  c == "@"
        )) {
        return false
      }
    }
    // All characters are numbers or letters.
    return true
  }


  function echeck(email) {
    var result = false;
    var theStr = new String(email);
    var index = theStr.indexOf("@");
  
    if (index > 0) {
      var pindex = theStr.indexOf(".", index);
      if ((pindex > index+1) && (theStr.length > pindex+1)) {
        result = true;
      }
    }
    return result;
  }





  // validates update form 
  
  function validate(frm)
  {
    var msg="";

    // Make sure all of the fields are valid
    if ((frm.email.value.length > 0) && ((!echeck(frm.email.value) || frm.email.value.length < 3)))
      msg += " * Please check your email address to ensure that it is correct\n";

    if ((frm.email.value.length > 0) && (!isEmailChar(frm.email.value)))
      msg += " * The email address you have entered contains invalid characters\n";


    if (msg == ""){
      return true
    } else {
      alert(msg)
      return false
    }
  }

    
    
