// number formatting function
// copyright Stephen Chapman 24th March 2006, 22nd August 2008
// permission to use this function is granted provided
// that this copyright notice is retained intact

function tbaFormatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2)
{
 // num   = Number to be formatted
 // dec   = Number of digits to the right of the decimal point
 // thou  = Thousands separator character
 // pnt   = Character used for the decimal point (i.e. . or ,)
 // curr1 = Currency Symbol if tight onto the number
 // curr2 = Currency Symbol if separated from number by a space
 // n1    = Negative indicator (like a -)
 // n2    = Second negative indicator, like if negative is shown as (3)

 var x = Math.round(num * Math.pow(10,dec));

 if (x >= 0)
  n1=n2='';

 var y = (''+Math.abs(x)).split('');

 var z = y.length - dec;
 if (z<0)
  z--;

 for(var i = z; i < 0; i++)
  y.unshift('0');

 if (z<0)
  z = 1;

 y.splice(z, 0, pnt);

 if(y[0] == pnt)
  y.unshift('0');

 while (z > 3)
 {
  z-=3;
  y.splice(z,0,thou);
 }

 var r = curr1+n1+y.join('')+n2+curr2;

 return r;
}


