<!--

function Number_toNonExpString() {
  var s = this.toString();
  var eLoc = s.indexOf("e");
  if (eLoc > 0) {
    var n = parseFloat(s.substring(0, eLoc));
    var e = parseInt(s.substring(eLoc+1));

    s = String(n);
    var dLoc = s.indexOf(".");
    var n1 = "";
    var n2 = "";
    if (dLoc > 0) {
      n1 = s.substring(0, dLoc);
      n2 = s.substring(dLoc + 1);
    } else {
      n1 = s;
    }

    if (e < 0) {
      for (var i=0; i<Math.abs(e); i++) n1 = "0" + n1;
      s = n1.substring(0, 1) + "." + n1.substring(1) + n2;

    } else if (e > 0) {
      var n2Len = n2.length;
      for (var i=0; i<Math.abs(e)-n2Len; i++) n2 += "0";
      s = n1 + n2;
    }
  }

  return s;
}

Number.prototype.toNonExpString = Number_toNonExpString;


function DecimalFormat(aPattern) {
  this._Format = String(aPattern);
}
DecimalFormat.prototype.separator = ',';
DecimalFormat.prototype.decpoint = '.';
DecimalFormat.prototype.percent = '%';
DecimalFormat.prototype.currency = '$';
DecimalFormat.prototype.format = DecimalFormat_format;
DecimalFormat.prototype._strip = DecimalFormat_strip;
DecimalFormat.prototype._separate = DecimalFormat_separate;


function DecimalFormat_format(number) {  // use: format(number)
  var format = this._Format;
  if (number - 0 != number) return null;  // if number is NaN return null
  var useSeparator = format.indexOf(this.separator) != -1;  // use separators in number
  var usePercent = format.indexOf(this.percent) != -1;  // convert output to percentage
  var useCurrency = format.indexOf(this.currency) != -1;  // use currency format
  var isNegative = (number < 0);
  number = Math.abs (number);
  if (usePercent) number *= 100;
  format = this._strip(format, this.separator + this.percent + this.currency);  // remove key characters
  number = number.toNonExpString();  // convert number input to string

   // split input value into LHS and RHS using decpoint as divider
  var dec = number.indexOf(this.decpoint) != -1;
  var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
  var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";

   // split format string into LHS and RHS using decpoint as divider
  dec = format.indexOf(this.decpoint) != -1;
  var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
  var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

   // adjust decimal places by cropping or adding zeros to LHS of number
  if (srightEnd.length < nrightEnd.length) {
    var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
    nrightEnd = nrightEnd.substring(0, srightEnd.length);
    if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);  // round up

// patch provided by Patti Marcoux 1999/08/06
    while (srightEnd.length > nrightEnd.length) {
      nrightEnd = "0" + nrightEnd;
    }

    if (srightEnd.length < nrightEnd.length) {
      nrightEnd = nrightEnd.substring(1);
      nleftEnd = (nleftEnd - 0) + 1;
    }
  } else {
    for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
      if (srightEnd.charAt(i) == "0") nrightEnd += "0";  // append zero to RHS of number
      else break;
    }
  }

   // adjust leading zeros
  sleftEnd = this._strip(sleftEnd, "#");  // remove hashes from LHS of format
  while (sleftEnd.length > nleftEnd.length) {
    nleftEnd = "0" + nleftEnd;  // prepend zero to LHS of number
  }

  if (useSeparator) nleftEnd = this._separate(nleftEnd, this.separator);  // add separator
  var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : "");  // combine parts
  output = ((useCurrency) ? this.currency : "") + output + ((usePercent) ? this.percent : "");
  if (isNegative) {
    // patch suggested by Tom Denn 25/4/2001
    output = (useCurrency) ? "(" + output + ")" : "-" + output;
  }
  return output;
}

function DecimalFormat_strip(input, chars) {  // strip all characters in 'chars' from input
  var output = "";  // initialise output string
  for (var i=0; i < input.length; i++)
    if (chars.indexOf(input.charAt(i)) == -1)
      output += input.charAt(i);
  return output;
}

function DecimalFormat_separate(input, separator) {  // format input using 'separator' to mark 000's
  input = "" + input;
  var output = "";  // initialise output string
  for (var i=0; i < input.length; i++) {
    if (i != 0 && (input.length - i) % 3 == 0) output += separator;
    output += input.charAt(i);
  }
  return output;
}

//-->
