gvar="";

function removeCurrencyFormat(field){
	retVal=field.value.replace(",","");
	retVal=retVal.replace(",",""); //incase there are two commas
	return retVal;
}

function currency(fieldName) {
	//-- Returns passed number as string in xxx,xxx format.
	anynum=removeCurrencyFormat(fieldName);

	if(anynum.length < 3){return;}
	if(isNaN(anynum)){
		anynum = gvar;
		anynum=gvar.replace(",","");
		anynum=anynum.replace(",",""); //incase there are two commas
	}
	anynum=eval(anynum);
	workNum=Math.abs((Math.round(anynum*100)/100));
	workStr=""+workNum;
	if (workStr.indexOf(".")==-1){
		workStr+=".00";
	}
	dStr=workStr.substr(0,workStr.indexOf("."));
	dNum=dStr-0;
	pStr=workStr.substr(workStr.indexOf("."));
	while (pStr.length<3){
		pStr+="0";
	}

	//--- Adds comma in thousands place.
	if (dNum>=1000) {
		dLen=dStr.length;
		dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen);
	}

	//-- Adds comma in millions place.
	if (dNum>=1000000) {
		dLen=dStr.length;
		dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen);
	}
	retval = dStr
	//-- Put numbers in parentheses if negative.
	if (anynum<0) {retval="("+retval+")"}
	fieldName.value=retval
	
}
