function prepmyval (val)
{
	val += '';
	val = val.replace (',', '');
	val *= 1;
	
	return val;
}

function NumberFormat (val)
{
	this.val = prepmyval (val);
	this.dec = 2;

	this.setPlaces = function (dec)
	{
		this.dec = dec * 1;
	}
	
	this.toFormatted = function ()
	{
		var strval = this.val + '';
		
		var auxx = strval.split ('.');
		var nodecs = auxx[1] ? false : true;
		
		var aux = strval.split ('');
		if (!aux.length || nodecs)
		{
			var tmpval = auxx[0];
			if (this.dec > 0)
			{
				tmpval += '.'
				for (var i = 0; i < this.dec; i ++)
				{
					tmpval += '0';
				}
			}
			
			return this.prepout (tmpval);
		}
		else
		{
			var tmpval = '';
			var deccount = -1;
			
			for (var i = 0; i < aux.length; i ++)
			{
				if (aux[i] == '.' && this.dec == 0) return this.prepout (tmpval);
				else if (aux[i] == '.' || deccount >= 0) deccount ++;
				
				if (deccount >= 0)
				{
					tmpval += aux[i];
					if (deccount == this.dec) return this.prepout (tmpval);
				}
				else if (aux[i] != null) tmpval += aux[i];
				else return this.prepout (tmpval);
			}
			
			return this.prepout (tmpval);
		}
	}
	
	this.prepout = function (val)
	{
		var strval = val + '';
		var aux = strval.split ('.');
		var decval = aux[1];
		var auxx = aux[0].split ('');
		
		if (auxx.length > 3)
		{
			var out = '';
			for (var i = 0; i < auxx.length; i ++)
			{
				out += auxx[auxx.length - (i + 1)];
			}
			
			var aux = out.split ('');
			out = '';
			var tcount = 0;
			for (var i = 0; i < aux.length; i ++)
			{
				tcount ++;
				if (tcount == 2 && i < (aux.length - 1))
				{
					out += ',' + aux[aux.length - (i + 1)];
				}
				else out += aux[aux.length - (i + 1)];
			}
			
			if (decval) out += '.' + decval;
			
			return out;
		}
		else return strval;
	}
}