//-----------------------------------------------------------------------//
function formatCurrency(sCurrency, iPlaces)                              //
//-----------------------------------------------------------------------//
//          function name: formatCurrency()                              //
//             created by: Dustin Brown                                  //
//             created on: 2/20/2001                                     //
//                purpose: confirm that a given number is a valid        //
//                         currency and format that number to $99.99 for //
//                         a positive number; -$99.99 for a negative.    //
//             parameters: sCurrency - a number that is to be formatted  //
//                                     as a currency.                    //
//                returns: the newly formatted currency if 'sCurrency'   //
//                         is valid; a zero length string if it is not.  //
// include files required: validCurrency.js, roundNumber.js,             //
//                         outputComma.js                                //
//-----------------------------------------------------------------------//
{
	var n="";
	
	//if no iPlaces, default to 2
	if(iPlaces==null)iPlaces=2;
	
	//convert to string
	sCurrency = String(sCurrency);
	
	//check for a negative number
	if(sCurrency.indexOf("-")!=-1)n="-";
	
	//verify 'sCurrency' as a valid currency
	if(!validCurrency(sCurrency))return "";
	
	//remove all non-numeric characters except "."
	var ch;
	var temp="";
	for(var x=0;x<sCurrency.length;x++){
		ch=sCurrency.charAt(x);
		if((!isNaN(ch))||(ch=="."))temp+=ch;
	}
	sCurrency=temp;
	
	//round 'sCurrency' to iPlaces decimal places
	sCurrency=roundNumber(sCurrency, iPlaces)+"";
	
	//format sCurrency to -$99.99
	sCurrency=n+"$"+outputComma(sCurrency);
	
	//return the formatted currency
	return sCurrency;
}
//End function formatCurrency()------------------------------------------//