// This script will convert a number to a fixed-length string.
// The number is padded on the left with zeros or trucated
// on the left to result in a string the size you specify.
//
// Date:     12/15/1999
// Author:   David Wickersham (skeezicks@cyberdude.com)
// Version:  1.0
//
// Installation Instructions:
// 1. Copy this script into a file named pad_number.js.
// 2. Use the script tag to incorporate pad_number.js 
//    into the head area of the html page:
//    <script language="javascript" src="[path]pad_number.js"></script>.
// 3. Call the function padNumber and pass it the number to
//    be transformed and the length of the string you want.
//    The return value of the function is the number converted
//    to a fixed_length string. Please note that if the number
//    passed is longer than the length specified the number will
//    be truncated on the left.
//
//    Examples:
//
//       my_string = padNumber(123,5);   my_string will equal "00123"
//
//       my_number = 1234;
//       my_string = padNumber(my_number,2);  my_string will equal "34"
//    
// Compatibility:
// Should run on all IE & Netscape browsers. Tested on IE 5 
// and Netscape 4.


function padNumber(number, len)  {
  var sub = 0;
  var string_num = number.toString();
  var diff = len - string_num.length;
  if (diff < 0)  {
    sub = len + diff - 1;
    string_num = string_num.slice(sub);
  }
  else  {
    for(sub = 0; sub < diff; sub++)  {
      string_num = "0" + string_num;
    }
  }
  return string_num;
}