function isNumeric(sText, allowDec, allowNeg)
{
  var ValidChars = "0123456789";
  var IsNumber = true;
  var Char;

  if( sText.length <= 0 )
  {
    return false;
  }
  if( allowDec )
  {
    ValidChars = ValidChars + ".";
  }
  if( allowNeg )
  {
    ValidChars = ValidChars + "-";
  }

  for( i = 0; i < sText.length && IsNumber == true; i++ )
  {
    Char = sText.charAt(i);
    if( ValidChars.indexOf(Char) < 0 )
    {
      IsNumber = false;
    }
  }
  return IsNumber;
} 
function RTrim(str)
{
  // We don't want to trip JUST spaces, but also tabs,
  // line feeds, etc.  Add anything else you want to
  // "trim" here in Whitespace
  //var whitespace = new String(" \t\n\r");

  var s = new String(str);

  //Match spaces at end of text and replace with a null string
  s = s.replace(/\s+$/,'');

  //if( whitespace.indexOf(s.charAt(s.length-1)) != -1 )
  //{
  //  var i = s.length - 1;
  //  while( i >= 0 && whitespace.indexOf(s.charAt(i)) != -1 )
  //    i--;
  //  s = s.substring(0, i+1);
  //}

  return s;
}
function LTrim(str)
{
  var s = new String(str);

  //Match spaces at beginning of text and replace with a null string
  s = s.replace(/^\s+/,'');

  return s;
}
function emailCheck(emailStr)
{
  // checks if the e-mail address is valid
  //var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
  var emailPat = /^([A-Za-z0-9][A-Za-z0-9_\-\.]*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z0-9][A-Za-z0-9_\-\.]*(\.[A-Za-z]\w*)+)$/;
  var i;

  var ss = emailStr.split(";");
  for( i = 0; i < ss.length; i++ )
  {
    ss[i] = LTrim(ss[i]);
    var matchArray = ss[i].match(emailPat);
    if( matchArray == null )
    { 
      alert("The email \"" + ss[i] + "\" seems incorrect.\nPlease try again (check the '@' and '.'s in the email address)");
      return false;
    }
    // make sure the IP address domain is valid
    var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
    if( IPArray != null )
    {
      for( var i = 1; i <= 4; i++ )
      {
        if( IPArray[i] > 255 )
        {
          alert("Destination IP address is invalid!")
          return false;
        }
      }
    }
  }
  return true;
}
