<!-- hide from older browsers
// Copyright© 2000-2004 The Gator Group, Inc.
//
// various 'utility' functions
//
// definitions
var LONG_ZIP_LEN  = 9;
var SHORT_ZIP_LEN = 5;

//
// UTILITY FUNCTIONS
//
// (1) inquiries     e.g. isSpace(ch);
// (2) conversions   e.g. secsToMilliSecs(secs);
// (3) calculations  e.g. milliSecsPerYear();
// (4) generic       e.g. isValid(value); digitsOnly();
//
function isSpace(ch)
{ return(ch == ' '); }
function isTab(ch)
{ return(ch == '\t'); }
function isNull(ch)
{ return(ch == '\0'); }
function isNewLine(ch)
{ return(ch == '\n'); }
function isCarriageRtn(ch)
{ return(ch == '\r'); }
function isDigit(ch)
{ return(((ch) >= ('0')) && ((ch) <= ('9'))); }
function isAlpha(ch)
{
  return((((ch) >= ('a')) && ((ch) <= ('z'))) ||
         (((ch) >= ('A')) && ((ch) <= ('Z'))));
}
function isUpper(ch)
{ return(((ch) >= ('A')) && ((ch) <= ('Z'))); }
function isLower(ch)
{ return(((ch) >= ('a')) && ((ch) <= ('z'))); }
function isWhiteSpace(ch)
{
  return(((ch) == ('\n')) || ((ch) == ('\t')) ||
         ((ch) == ('\f')) || ((ch) == ('\r')) ||
         ((ch) == (' ')));
}
function isAlphaNumeric(ch)
{ return((isDigit(ch)) || (isAlpha(ch))); }
function isDecimal(ch)
{ return(ch == '.'); }
function isPeriod(ch)
{ return(isDecimal(ch)); }
function isEven(x)
{ return(((x)%(2)) == 0); }
function isOdd(x)
{ return(!isEven(x)); }
function isLeapYear(x)
{
  return(((((x)%4)   == 0) &&
         ((((x)%100) != 0) ||
          (((x)%400)  == 0))));
}
function isFebruary(m)
{ return(m == 2); }
function is30DayMonth(m)
{
  return(((m) == (4)) || ((m) == (6)) ||
         ((m) == (9)) || ((m) == (11)));
}
function is31DayMonth(m)
{
  return(((m) == (1)) || ((m) == (3))  ||
         ((m) == (5)) || ((m) == (7))  ||
         ((m) == (8)) || ((m) == (10)) ||
         ((m) == (12)));
}
function secsToMilliSecs(secs)
{ return((secs) * (1000)); }
function minsToSecs(mins)
{ return((mins) * (60)); }
function hoursToSecs(hours)
{ return((hours) * (3600)); }
function daysToSecs(days)
{ return((days) * (3600) * (24)); }
function secsPerYear()
{ return((60) * (60) * (24) * (365)); }
function milliSecsPerYear()
{ return((60) * (60) * (24) * (365) * (1000)); }
//    
// these functions are used with the character codes (number 
// that represents the actual character) passed in
// 
// returns true if the char code is a backspace
// returns false otherwise
function isBackspaceCode(chCode)
{
  return((chCode == 8) ? true : false);
}
// returns true if the char code is a digit
// returns false otherwise
function isDigitCode(chCode)
{
  // 0 thru 9
  if((chCode > 47) && (chCode < 58))
    return(true);
  return(false);
}
// returns true if the char code is an upper
// or lower case letter, returns false otherwise
function isAlphaCode(chCode)
{
  // letters a - z [ 97 - 122 ]
  // letters A - Z [ 65 - 90 ]
  if(((chCode > 96) && (chCode < 123)) ||
     ((chCode > 64) && (chCode < 91)))
    return(true);
  return(false);
}
// returns true if the char code is a space
// returns false otherwise
function isSpaceCode(chCode)
{
  return((chCode == 32) ? true : false);
}
// returns true if the char code is a pound sign
// returns false otherwise
function isPoundSignCode(chCode)
{
  return((chCode == 35) ? true : false);
}
// returns true if the char code is a single quote
// returns false otherwise
function isSingleQuoteCode(chCode)
{
  return((chCode == 39) ? true : false);
}
// returns true if the char code is a comma
// returns false otherwise
function isCommaCode(chCode)
{
  return((chCode == 44) ? true : false);
}
// returns true if the char code is a hyphen
// returns false otherwise
function isHyphenCode(chCode)
{
  return((chCode == 45) ? true : false);
}
// returns true if the char code is a period
// returns false otherwise
function isPeriodCode(chCode)
{
  return((chCode == 46) ? true : false);
}
//
// validation functions
//
// function for checking validity of a value
function isValid(value)
{
  if((value == null) || (value == "") || 
     (value == "undefined") || (value == "null"))
    return(false);
  return(true);
}
// function for checking to see if a string is all digits
function isNumericString(s)
{
  if(!isValid(s))
    return(false);

  // make sure the number is all digits..
  var len = s.length;
  for(var i = 0; i < len; i++)
  {
    var c = s.charAt(i);
    if(!isDigit(c))
      return(false);
  } // end for()
  // ok, it is a numeric string
  return(true);
}
// function for checking to see if a string is 
// all digits and / or letters
function isAlphaNumericString(s)
{
  if(!isValid(s))
    return(false);

  // make sure the number is all digits..
  var len = s.length;
  for(var i = 0; i < len; i++)
  {
    var c = s.charAt(i);
    if(!isAlphaNumeric(c))
      return(false);
  } // end for()
  // ok, it is an alpha-numeric string
  return(true);
}
// validate an email address
// JS book pg. 133
function isValidEmail(email)
{
  var i;
  var badChar;
    
  //
  // ruling out:  space, double quotes, forward slash, 
  //              backslash, colon, comma, semicolon,
  //              pipe symbol, carat, and asterisk
  // before change ==>  var invalidChars = " /:,;";
  //
  var invalidChars = ' "/\\:,;|^*';
    
  if(!isValid(email))
    return(false);
  for(var i = 0; i < invalidChars.length; i++)
  {
    // check the entire string from [0]
    // for each bad character
    badChar = invalidChars.charAt(i);
    if(email.indexOf(badChar, 0) > -1)
      return(false);
  }
  // the "@" must be present
  var atPos = email.indexOf("@", 1);
  if(atPos == -1)
    return(false);
  // it cannot be at the end position either
  if(email.indexOf("@", atPos+1) > -1)
    return(false);
  // now check to make sure there is a period
  // and that it is after the '@' sign and there
  // are at least two chars after the email address
  var periodPos = email.indexOf(".", atPos);
  if(periodPos == -1)
    return(false);
  if((periodPos + 3) > email.length)
    return(false);
  if((periodPos - atPos) < 2)
    return(false);
  return(true);
}
// checks to ensure the zip code is valid
// acceptable formats:  99999 OR 999999999
function isValidZipCode(zip)
{
  if(!isValid(zip))
    return(false);
  var len = zip.length;
  if((len != SHORT_ZIP_LEN) && (len != LONG_ZIP_LEN))
    return(false);
  if(!isNumericString(zip))
    return(false);

  // ok, its valid...
  return(true);
}
// checks to ensure the field has data 
// and the data is all numeric
function isValidNumericField(data)
{
  return(isNumericString(data));
}
// checks to ensure the field has data 
// and the data is all numeric
function isValidAlphaNumericField(data)
{
  return(isAlphaNumericString(data));
}
// checks to ensure the field has data 
function isValidTextField(data)
{
  return(isValid(data));
}
//
// only allows digits (0 - 9) to be accepted in the input field
//
// NOTE:  this function works in both Netscape and Internet Explorer
// but it must be called like the following code demonstrates
// using the onKeyPress() event:
//
// <input name="quantity" type="text" value="qty" size="2" maxlength="2" 
//  onKeyPress="return(digitsOnly((navigator.appName == 'Netscape') ? 
//                           event : window.event));">
//
// THIS IS BECAUSE Navigator ONLY RESPONDS to 'event', 
// BUT Internet Explorer ONLY RESPONDS TO 'window.event' 
//
function digitsOnly(e)
{
  var charCode = ((navigator.appName == "Netscape") ? e.which : e.keyCode);

  // always allow a backspace, in case the user goofed
  // code is 8 in Navigator, no code shown in IE
  if(isBackspaceCode(charCode))
    return(true);
        
  // digits 0 thru 9 [ 48 - 57 ]
  if(isDigitCode(charCode))
    return(true);
    
  // no go, ...
  return(false);
}
    
//////////////////////// OLD FUNCTION ////////////////////////////////////
//function digitsOnly(e)
//    {
//    var charCode = ((navigator.appName == "Netscape") ? e.which : e.keyCode);
//    if((charCode > 31) && ((charCode < 48) || (charCode > 57)))
//        return(false);
//    return(true);
//    }
//
//////////////////////// END OLD FUNCTION ////////////////////////////////

// allows digits, upper and lower case letters only
function alphaNumOnly(e)
{
  var charCode = ((navigator.appName == "Netscape") ? e.which : e.keyCode);

  // always allow a backspace, in case the user goofed
  // code is 8 in Navigator, no code shown in IE
  if(isBackspaceCode(charCode))
    return(true);
        
  // digits 0 thru 9 [ 48 - 57 ]
  if(isDigitCode(charCode))
    return(true);
        
  // letters a thru z and A thru Z
  if(isAlphaCode(charCode))
    return(true);
    
  // no go, ...
  return(false);
}
// allows digits, upper and lower case letters,
// space, single quote, comma, hyphen, # sign, and period
function alphaNumPlusOnly(e)
{
  var charCode = ((navigator.appName == "Netscape") ? e.which : e.keyCode);

  // always allow a backspace, in case the user goofed
  // code is 8 in Navigator, no code shown in IE
  if(isBackspaceCode(charCode))
    return(true);
        
    // digits 0 thru 9 [ 48 - 57 ]
  if(isDigitCode(charCode))
    return(true);
        
    // letters a thru z and A thru Z
  if(isAlphaCode(charCode))
    return(true);

  // space, pound sign, single quote, comma, hyphen, period
  // 32     35          39            44     45      46
  if((isSpaceCode(charCode))       || 
     (isPoundSignCode(charCode))   || 
     (isSingleQuoteCode(charCode)) || 
     (isCommaCode(charCode))       ||
     (isHyphenCode(charCode))      ||
     (isPeriodCode(charCode)))
      return(true);  
    
  // no go, ...
  return(false);
}
// disallows certain characters from being entered
// disallowed characters:  
// " & | ` ~ ^ * < > ? / \ $ % { } + = [ ] ( ) # @ _ 
function denySpecialChars(e)
{
  var charCode = ((navigator.appName == "Netscape") ? e.which : e.keyCode);

  // always allow a backspace, in case the user goofed
  // code is 8 in Navigator, no code shown in IE
  if(isBackspaceCode(charCode))
    return(true);
        
  // disallowed characters
  if(charCode == 47)
    return(false);
  if((charCode > 33) && (charCode < 39))
    return(false);
  if((charCode > 39) && (charCode < 44))
    return(false);
  if((charCode > 59) && (charCode < 65))
    return(false);
  if((charCode > 90) && (charCode < 97))
    return(false);
  if((charCode > 122) && (charCode < 127))
    return(false);
    
  // ok, allow it ...
  return(true);
}
// only allows x number of characters to be accepted in the input field
// function is quite useful for a text area as it doesn't have a
// max length type attribute
//
// NOTE:  this function works in both Netscape and Internet Explorer
// but it must be called like the following code demonstrates
// using the onKeyPress() event:
//
// <!-- for text areas DO NOT leave a space between <textarea></textarea> -->
// <!-- unless we want an initial value                                   -->
// <textarea name="notes" cols="52" rows="3" 
// onKeyPress="return(limitChars(((navigator.appName == 'Netscape') ? 
//               event : window.event), this, MAX_COMMENT_LEN));"></textarea>
//
// THIS IS BECAUSE Navigator ONLY RESPONDS to 'event', 
// BUT Internet Explorer ONLY REPSPONDS TO 'window.event' 
//
function limitChars(e, field, maxchars)
{
  var c = field.value;
  var num = c.length;

  if(num >= maxchars)
    return(false);
  return(true);
}
// frame buster
function frameBuster()
{
  if(top != self)
  {
    top.location = location;
  }
}
// force frame
function forceFrame(frameSetToLoad)
{
  if(top.location == self.location)
  {
    parent.location.href=frameSetToLoad;
  }
}
//
// function for checking if the string contains
// US or United States or USA or usa
// returns true if so, otherwise false
//
function isCountryUSA(value)
{
  // default is USA
  if(!isValid(value))
  {
    return(true);
  }
  if((value == "US")  || (value == "us") ||
     (value == "USA") || (value == "usa"))
  {
    return(true);
  }
  if(value == "United States")
  {
    return(true);
  }
  // ok, it is another country
  return(false);
}
// end hide -->