// JavaScript Document

var NumFormatter=new Class({
	Implements:[Options],
	options: {
		currencySymbol: "£",
		decimalSymbol: ".",
		decimalPlaces:2,
		separator:",",
		separatePlaces:3,
		currencyPos:"L"
	},
	initialize: function(options) {
		this.setOptions(options);
	},
	formatCurrency: function(num) {
		var str=this.formatNumber(num);
		if (this.options.currencyPos=="L") {
			str=this.options.currencySymbol+str;
		} else if (this.options.currencyPos=="R") {
			str=str+this.options.currencySymbol;
		}
		return str;
	},
	formatNumber: function(num) {
		var str=num.toFixed(this.options.decimalPlaces);
		var p=str.indexOf(".");
		if (this.options.decimalSymbol!=".") {
			str=str.replace(".",this.options.decimalSymbol);
	}
		while (p>this.options.separatePlaces+(num<0?1:0)) {
			p-=this.options.separatePlaces;
			str=str.substr(0,p)+this.options.separator+str.substr(p);
		}
		return str;
	}
		
});
