

	function formatCurrency(number)
	{
		return formatIntlCurrency(number, '$');
	}


	/*
	===========================================================================
	
	=-=-=	formatCurrency()
	
	-----	This function accepts a number and turns it into $X,XXX.XX format
	-----	The argument must be numeric 
	
	=-=-=	returns number in "$X,XXX.XX"
	
	===========================================================================
	*/
	function formatIntlCurrency (number, sSymbol) 
	{
		var isNegative = false;
		
		if (number.indexOf("k") != -1 || number.indexOf("K") != -1)
		{
		    number = number.replace(/k|K/, "000");
		}
		
		number = currencyToNum(number, sSymbol);
		
		if (isNaN(number))
		{
			return (sSymbol + "0.00");
		}
		
		
		var num = new String (number);
		if (num.indexOf (".") == -1) 
		{
			intLen = num.length;
			toEnd = intLen;
			var strLeft = new String (num.substring (0, toEnd));
			var strRight = new String ("00");
		} 
		else 
		{
			pos = eval (num.indexOf ("."));
			var strLeft = new String (num.substring (0, pos));
			intToEnd = num.length;
			intThing = pos + 1;
			var strRight = new String (num.substring (intThing, intToEnd));
	
			if (strRight.length > 2) 
			{
				nextInt = strRight.charAt(2);
				if (nextInt >= 5) 
				{
					strRight = new String (strRight.substring (0, 2));
					strRight = new String (eval ((strRight * 1) + 1));
					if((strRight * 1) >= 100) 
					{
						strRight = "00";
						strLeft = new String (eval ((strLeft * 1) + 1));
					}
					if (strRight.length <= 1) 
					{
						strRight = new String ("0" + strRight);
					}
				} 
				else 
				{
					strRight = new String (strRight.substring (0, 2));
				}
			} 
			else 
			{
				if (strRight.length != 2)
					strRight = strRight + "0";
			}
		}
		
		if (strLeft.substring(0, 1) == "-")
		{
			isNegative = true;
			strLeft = strLeft.substring(1, strLeft.length);
		}
		
		if (strLeft.length > 3) 
		{
			var curPos = (strLeft.length - 3);
			while (curPos > 0) 
			{
				var remainingLeft = new String (strLeft.substring (0, curPos));
				var strLeftLeft = new String (strLeft.substring (0, curPos));
				var strLeftRight = new String (strLeft.substring (curPos, strLeft.length));
				strLeft = new String (strLeftLeft + "," + strLeftRight);
				curPos = (remainingLeft.length - 3);
			}
		}
	
		strWhole = strLeft + "." + strRight;
		if (!isNegative)
			finalValue = sSymbol + strWhole;
		else
			finalValue = "(" + sSymbol + strWhole + ")";
			
		return (finalValue);
	}
	
	
	
	
	
	/*
	===========================================================================
	
	=-=-=	stringToNum()
	
	-----	This function accepts a string and removes commas, dollar signs
	-----	and then rounds to max two figures to the right of the decimal 
	-----	point
	
	=-=-=	returns sInStr as a numeric equiv
	
	===========================================================================
	*/
	function stringToNum (sInStr) 
	{
		theString = new String (sInStr);
		theString = theString.replace (/\$/, "");
		theString = theString.replace (/\£/, "");
		theString = theString.replace (/,/g, "");
		theString = parseFloat (theString);
		return Math.round (theString * 100) / 100;
	}
	
	
	function currencyToNum (sInStr, sSymbol) 
	{
		if(!sSymbol)
		{
			sSymbol = "$";
		}
		
		theString = new String (sInStr);
		theString = eval('theString.replace (/\\' + sSymbol + '/, "")');
		theString = theString.replace (/,/g, "");
		
		if (theString.charAt(0) == "(" && theString.charAt(theString.length - 1) == ")")
		{
			theString = theString.replace(/\(|\)/g, "");
			theString = "-" + theString;
		}
					
		theString = parseFloat (theString);
		return Math.round (theString * 100) / 100;
	}