// format currency
/////////////////////////////////////////////////////////////////////////////////////////////////
//Thanks to the absence of Any comments... actual programmer has to interpret this function by himself
// Changes done /**/ : Now this function will Format the currency to return only 2 digits after "."
/////////////////////////////////////////////////////////////////////////////////////////////////
function currencyFormat(currencyValue)
{
	var indexOfPoint;
	var currencyLenght;
	var beforePointLen;
	var afterPointLen;
	var formattedCurrencyBeforePoint; 
	var formattedCurrencyAfterPoint; 

	indexOfPoint = currencyValue.toString().indexOf(".");

	currencyLenght = currencyValue.toString().length;
	if ( indexOfPoint==-1 ) // if there is no "."
	{ 
		formattedCurrencyAfterPoint = "";
		if (currencyLenght > 3 )
		{
			formattedCurrencyBeforePoint = currencyValue.toString().substr(0,currencyLenght-3) + "," + currencyValue.toString().substr(currencyLenght-3,currencyLenght);
		}
		else
		{
			formattedCurrencyBeforePoint = currencyValue.toString().substr(0,currencyLenght);
		}
		formattedCurrencyAfterPoint = ".00" ;
	
	}
	else
	{ 
		beforePointLen = indexOfPoint;
		if (beforePointLen > 3 )
		{
			currencyBeforePoint = currencyValue.toString().substr(0,beforePointLen);
			formattedCurrencyBeforePoint = currencyBeforePoint.toString().substr(0,beforePointLen - 3) + "," + currencyBeforePoint.toString().substr( beforePointLen -3,beforePointLen);
		}
		else
		{
			currencyBeforePoint = currencyValue.toString().substr(0,beforePointLen);
			formattedCurrencyBeforePoint = currencyBeforePoint;
		}			
		afterPointLen = currencyLenght - beforePointLen-1;
		if 	(afterPointLen > 1 )  //??? is supposed to be 2?? in admin .js it is.
		{
				//formattedCurrencyAfterPoint = currencyValue.toString().substr(indexOfPoint,afterPointLen+1) ;
				//new Change by Javier Lopez... format to only 2 digits the price
				formattedCurrencyAfterPoint = currencyValue.toString().substr(indexOfPoint,2+1) ;
		}		
		else // len=1
		{
			formattedCurrencyAfterPoint = currencyValue.toString().substr(indexOfPoint,afterPointLen+1)+"0" ;
		}
			
	}
	return formattedCurrencyBeforePoint+formattedCurrencyAfterPoint;

}