// Function list
// error(element, msg)             agumant passed is a form object and a string that is the text for the error message to be displayed in an alert
// isWhitespace()                  arguemnt passed is a string. Returns true if it contains only whitespace characters
// isAlphanumeric()                argument passed is a string. Returns true if the string contains only alphanumeric characters
// isLetter()                      argument passed is a char. Returns true if char is a-z or A-Z
// isPermitChar(c,permitChars)     arguments passed are a char and an array of "permitted" chars. Returns true if char is in the list of those permitted
// hasPermittedChars(s, okChars    arguments passed are a char and an array of "permitted"chars.  Returns true if char is in the list of those permitted
// isValidPassword(s)              argument passed is a string. Returns false if the string contains & ' "        
// hasSpecialCharOrDigit(s)        argument passed is a string. Returns true if the string contains a character that is either not alphanumeric or is a digit
// isEmail(s)                      argument passed is a string. Returns true if string is of the form a@b.c
// parseEmail                      parses email address delimited by semi-colons
// isValidEmail(s)                 checks the email field to be sure that it is not whitespace and is of the correct form
// hasSpecialChars(s)              argument passed is a string. Returns true if string contains & " ' < >
// charsOutOfRange(s)              argument passed is a string. Returns true if character in the string are not in the ASCII range 32-125

var ce = 'Please correct your entry.';
var decimalPointDelimiter = '.';
var EmptyOK = true;
function error(el,msg) {
alert(msg);
el.focus();
return false;
}
var whitespace = " \t\n\r";
function isWhitespace (s){
if((s == null) || (s.length == 0)) return true; for(var i = 0; i < s.length; i++){
       if (whitespace.indexOf(s.charAt(i)) == -1) return false;
  }
  return true;
}
function isLetter (c){return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) ) }
function isDigit (c){return ((c >= "0") && (c <= "9")) }
function isInteger(s)
{  
    for (var i = 0; i < s.length; i++)
    { 
        var c = s.charAt(i);
        if (!isDigit(c))
        return false;
    }
    return true;
}
function isAlphanumeric(s)
{  
    for (var i = 0; i < s.length; i++)
    { 
        var c = s.charAt(i);
        if (! (isLetter(c)||isDigit(c)))
        return false;
    }
    return true;
}
function isPermitChar(c, permitChars)
{
   var isPermitted = false;
   for( var i=0; i < permitChars.length; i++){
      if((c == permitChars[i]) && (isPermitted == false)){
         isPermitted = true;
      }
   }
   return isPermitted;   
}
function hasPermittedChars(s,okChars){
     var isValidStr = true;
     for(i = 0; i < s.length; i++)
     {
        var c = s.charAt(i);
        if ((isPermitChar(c,okChars) || isLetter(c) || isDigit(c)) && (isValidStr == true)){ 
           isValidStr = true;
        } 
        else{
           isValidStr = false; 
           break;   
        }
    }
  return isValidStr; 
}

function isValidPassword(s)
{   
	var i;
	var isValid = true;   
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if(( c == "\"" ) || (c == "'" ) || ( c == "&")){
			isValid = false;
		}    
	}
	return isValid;
}
function hasSpecialCharOrDigit(s)
{
 	var i;
	var isValid = false;   
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if(isDigit(c) || (!(isLetter(c)||isDigit(c)))){
          isValid = true;
        } 
	} 
    return isValid;
}
function isEmail(s){ 
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@")){ i++ }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != ".")){ i++ }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
function parseEmail(s){
    var emailArr = new Array();
    var j=0;
    emailArr[j] = '';
    for(i=0; i < s.length; i++){
       if (s.charAt(i) != ';'){
          emailArr[j] += s.charAt(i);
       }
       else{
          j++; 
          emailArr[j] = '';
       }
    }   
    return emailArr;
}
function isValidEmail(email_value){
   var invalidEmail = false;
   if(!isWhitespace(email_value))
   { 
       if(!isEmail(email_value)){
          invalidEmail = true;
       }
   }
   if(invalidEmail == true){
   return false;
   }
   else{
      return true;
   }
}
function hasSpecialChars(s)
{   
	var isDb = false;   
	for (var i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if(( c == "\"" ) || (c == "'" ) || ( c == "&")|| (c == "<" ) || ( c == ">")){
			isDb = true;
		}    
	}
	return isDb;
}
function charsOutOfRange(s){
    for(var j=0; j < s.length; j++)
    {
       var c = s.charCodeAt(j)
       if((c < 32) || (c > 126))
       {
          return true;
       } 
    }
    return false;
}
// isFloat (STRING s [, BOOLEAN emptyOK]) True if string s is an unsigned floating point (real) number. Also returns true for unsigned integers.
function isFloat (s, e_ok)
{ 
    var i;
	if(e_ok == null || e_ok == 'undefined')
	   e_ok = true;
    var seenDecimalPoint = false;
	if(isWhitespace(s) && (e_ok == true))
	  return true;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }
    // All characters are numbers.
    return true;
}
