//   Name:    JSValidationFuncs.js
//   Date:    06/25/03
//   Project: NORMA
//	 Desc:    Client side validation functions


// Returns true if string s is empty or 
// whitespace characters only
function isEmpty(s)
   {  
      var i; 
      var whitespace = " \t\n\r";
      if ((s.length == 0) || (s == null) ) return true;
    
      // Search through string's characters one by one
      // until we find a non-whitespace character.
      // When we do, return false; if we don't, return true.

      for (i = 0; i < s.length; i++)
         {   
           // Check that current character isn't whitespace.
           var c = s.charAt(i);

           if (whitespace.indexOf(c) == -1) return false;
         }

      // All characters are whitespace.
      return true;
   }

function isNotValidPhoneNo(s) 
   { 
      var stripped;    
      if (isEmpty(s)) return false;
      
      stripped = s.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
      if (isNaN(stripped)) return true;
   }
   
function isInvalidEmail(s)
   {   
    
      if (isEmpty(s)) return true;
      
      //is going to look for < to ensure you isn't adding script tags. 
      var illegalChars = /</
      if (illegalChars.test(s)) return true; 
   
      // there must be >= 1 character before @, so we start looking at character position 1 
      // (i.e. second character) 
      
      var i = 1;
      var sLength = s.length;

      // look for @
      while ((i < sLength) && (s.charAt(i) != "@"))
        { 
           i++
        }

      if ((i >= sLength) || (s.charAt(i) != "@")) return true;
      else i += 2;

      // look for .
      while ((i < sLength) && (s.charAt(i) != "."))
        { 
           i++
        }
      
      // there must be at least one character after the .
      if ((i >= sLength - 1) || (s.charAt(i) != ".")) return true;
      else return false;
   }
   
function isInvalidEntry(s)
   {   
      // allow only letters, numbers, and underscores
      var illegalChars = /\W/;
  
      if (illegalChars.test(s)) return true;
      else return false;
   }
   
function isInvalidInteger (s)
   {  
     var i;

      // Search through string's characters one by one
      // until we find a non-numeric character.
      // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return true;
    }
    // All characters are numbers.
    return false;
} 

function isDigit (c)
  {
    // Returns true if character c is a digit (0 .. 9).   
    return ((c >= "0") && (c <= "9"))
  }

function trimleft ( s )
  {
    return s.replace( /^\s*/, "" )
  }
  
function trimright ( s )
  {
    return s.replace( /\s*$/, "" );
  }
    
function trimcomplete ( s )
  {
    return trimright(trimleft(s));
  }
  
function isInvalidEntry2(s)
   {   
      // allow only letters, numbers, and underscores
      var illegalChars = /[$\\@\\\#%\^\&\*\(\)\[\]\+\{\}\'\~\=\|<>]/;
  
      if (illegalChars.test(s)) return true;
      else return false;
   }