    // CheckNumeric - Check to see if:
    //                Field is numeric
    //                Field has too many decimal positions
    //                Field is outside of the acceptible range (optional)
    function CheckNumeric(fname, decimals, min, max, mask, dont_mask, msg, leading_zeros_ok)
    {
      if (typeof fname == "undefined") return true;
      if  (isWhitespace(fname.value)) return true;
      if (typeof(msg) == "undefined") 
        msg1 = "Field: " + fname.name + " Value: " + fname.value + " - is not a number"
      else
        msg1 = msg;
      var num = "";
      var numbers = "0123456789"; // strictly number and later "." if decimal places ok
      var okchars = " 0123456789"; // will add any masking chars to this list later
      var onechar;
      var tmp;
      var decimal_cnt = 0;
      var decimal_pos = 0;

      // go through the mask and find any other characters besides numbers
      // that will be ok in the input string
      if (typeof mask == "undefined") mask = "";
      for (i=0; i<mask.length; i++)
      {
        onechar = mask.charAt(i);
        if (onechar != "#") okchars = okchars + onechar;
      }
      
      // now, find out if a decimal point will be allowed
      if (parseInt(decimals, 10) > 0)
      {
        numbers = numbers + ".";
        if (numbers.indexOf(".") == -1) okchars = okchars + ".";
      }
      
      //  now go through the input string and make sure that only "ok characters" exist
      for (i=0; i<fname.value.length; i++)
      {
        onechar = fname.value.charAt(i);
        tmp = okchars.indexOf(onechar);
        if (tmp == -1)
        {
          if (!(i==0 && onechar == "-"))
          {
            SetError(fname, msg1);
            return false;
          }
        }
        
        // now, build up a string of just the numeric characters in the input string
        if (numbers.indexOf(onechar) != -1)
        {
          num = num + onechar;
          if (onechar == ".")
          {
            decimal_cnt = decimal_cnt + 1;
            decimal_pos = num.length;
          }
        }
        else
        {
          if (i==0 && onechar == "-") num = num + onechar;
        }
      }

      // if more than one decimal point entered - complain
      if (decimal_cnt > 1)
      {
        SetError(fname, msg1);
        return false;
      }

      // find out the number of decimal places entered
      // complain if too many decimal positions entered
      if (typeof(msg) == "undefined") 
        msg1 = "Field: " + fname.name + " Value: " + fname.value + " - more than " + decimals + " decimals were entered"
      else
        msg1 = msg;
      var num_len = num.length;
      var fsize = num_len - decimal_pos;
      if  (decimal_pos == 0) fsize = 0;
      if (fsize > decimals)
      {
        SetError(fname, msg1);
        return false;
      }

      // now check for the min and max values
      // complain if the range is exceeded
      if (typeof(msg) == "undefined") 
        msg1 = "Field: " + fname.name + " Value: " + fname.value + " - must be between " + min + " to " + max
      else
        msg1 = msg;
      if (isNaN(min) || isNaN(max)) return true;
      var fval = parseFloat(num);
      if (fval < parseFloat(min) || fval > parseFloat(max))
      {
        SetError(fname, msg1);
        fname.focus();
        return false;
      }

      // mask the number if a mask was given
      // put the masked value into the field
      if (dont_mask) mask = '';
      if (mask != "") num = FormatNumber(num, decimals, mask, leading_zeros_ok);
      fname.value = num;
      ClearError(fname);
      return true;
    }

    function RoundToNdp(X, N) 
    { 
      var T = Number('1e'+N)
      return Math.round(X*T)/T 
    }

