// Modifié le 2007-02-10
function pwFormatCurrency(price,dot,nocolor,currency,symbol_override)
{
	var symbol = '$';
	
	if(typeof symbol_override != 'undefined')
	{
		symbol = symbol_override;
	}
	var mystr = "<span style='white-space:nowrap'";
	if( !nocolor && price < 0 )
	{
		mystr+= " class='negativ'";
	}
	mystr+= ">";
	if(dot==''||typeof dot == 'undefined' )dot='.';
	if( typeof currency == 'undefined' ) currency = 'CAN'
	if( currency=='USD' ) mystr+= symbol;
	mystr+= pwNumberFormat(price, 2, dot, ' ');
	if(currency!='USD') mystr+= ' '+symbol;
	mystr+= "</span>";
	return mystr;
}

var pw_currencies={
	1:{'short_fr':'# $','short_en':'$#','long_fr':'# $ CAD','long_en':'$# CAD'},
	2:{'short_fr':'# €','short_en':'€#','long_fr':'# EUR','long_en':'# EUR'},
	3:{'short_fr':'# $','short_en':'$#','long_fr':'# $ USD','long_en':'$# USD'}};
function pwCurrenciesFormat(price, label, nobr, fkcurrencies, lang)
{
	if(label!='short' && label!='long' ) label='short';	
	var dot='.';
	if(lang=='fr')dot=',';
	if(!fkcurrencies)fkcurrencies=1;	

	var out="<span";
	if(nobr!=false)out=out+" style='white-space:nowrap'";
	if(price<0)out=out+" class='negativ'";
	out=out+">";
	
	var p=new String(pw_currencies[fkcurrencies][label+'_'+lang]);
	out=out+p.replace(/\#/, pwNumberFormat(price, 2, dot, ' '));
	
	out=out+"</span>";

	return out;
}

// number_format(number, decimals, comma, formatSeparator)
function pwNumberFormat(a, b, c, d)
{
	a=Math.round(a*Math.pow(10,b))/Math.pow(10,b);
	e=a+'';
	f=e.split('.');
	if(!f[0]) f[0]='0';
	if(!f[1]) f[1]='';
	if(f[1].length < b)
	{
		g=f[1];
		for(i=f[1].length+1; i<=b; i++)
		{
			g+='0';
		}
		f[1]=g;
	}
	if(d!='' && f[0].length>3)
	{
		h=f[0];
		f[0]='';
		for(j=3; j<h.length; j+=3)
		{
			i=h.slice(h.length-j, h.length-j+3);
			f[0]=d+i+f[0]+'';
		}
		j=h.substr(0,(h.length%3 == 0) ? 3 : (h.length%3));
		f[0]=j+f[0];
	}
	c=(b<=0) ? '': c;
	return f[0]+c+f[1];
}
