
	/** ===========================================================================================
	 */
	function get_format_number(item,decimals){
		var id 			= item.id;
		var value 		= item.value;
		var obj			= document.getElementById(id);
		value			= mtFormatNumber(value,decimals);
		obj.value 		= value;
	}


	/** ===========================================================================================
	 */
	function mtFormatNumber(tValue, tnDecimales){
		var sValue
		var lcParteEntera
		sValue = new String();
		lcParteEntera = new String();

		if (typeof(tValue) == "number")
		{
			sValue = tValue.toString();
		}
		else
		{
			sValue = tValue;
		}

		sValue = mtQuitaFormatoNumero(sValue, 2)

	    if (sValue.length == 0)
	    {
			return "";
		}

	    //  Parse the value into a float number
		var iValue = parseFloat(sValue);
		iValue = (Math.round(iValue * 100)) / 100;

		//  If the value is not a number, return an error
		if (isNaN(iValue))
		{
		    ReturnError("Not a valid amount");
		    return "";
	    }

	    //  Return the value to a string to apply formatting
	    sValue = iValue.toString();

	    //
	    //  Fill in zeros (if necessary) to show two digits to the right
	    //  of the decimal
	    //
	    if (sValue.indexOf(".") == -1)
	    {
	        sValue = sValue + ".00";
	    }
	    else
	    {
	        if (sValue.indexOf(".") == sValue.length - 1)
	        {
	            sValue = sValue + "00";
	        }
	        else if (sValue.indexOf(".") == sValue.length - 2)
	        {
	            sValue = sValue + "0";
	        }
	    }

	    //  Add commas if necessary
	    if (sValue.indexOf(".") > 3)
	    {
			lcEntero = sValue.substring(0, sValue.indexOf("."))

			lnLen = lcEntero.length;
			lnContador = 0
			lcParteEntera = ""
			for(i = lnLen;i > 0; i--)
			{
				lnContador = lnContador + 1;
				lcParteEntera = lcEntero.substr(i-1, 1) + lcParteEntera
				if (lnContador == 3)
				{
					lcParteEntera = "," + lcParteEntera;
					lnContador = 0;
				}
			}

			if (lcParteEntera.substr(0, 1) == ",")
			{
				lcParteEntera = lcParteEntera.substr(1, lcParteEntera.length - 1);
			}

	        /*sValue = sValue.substring(0,sValue.indexOf(".") - 3) + ","
	            + sValue.substring(sValue.indexOf(".") - 3,sValue.length);
	         */

			sValue = lcParteEntera + sValue.substring(sValue.indexOf("."), sValue.length);

	    }
		return sValue;
	}

	/** ===========================================================================================
	 */
	function mtQuitaFormatoNumero(tlcNumero, tnFormato)
	{
		var lcNumero, lcSeparadorDec, lcSeparadorMil

		lcNumero = new String()

		if (tnFormato==1)
		{
			lcSeparadorDec = ",";
			lcSeparadorMil = ".";
		}
		else
		{
			lcSeparadorDec = ".";
			lcSeparadorMil = ",";
		}

		lcNumero = tlcNumero;
		lcNumero = Replace(lcNumero, lcSeparadorMil, "");
		lcNumero = Replace(lcNumero, lcSeparadorDec, ".");

		return lcNumero;
	}

	/** ===========================================================================================
	 */
	function Replace(tsString, tsFind, tsReplacement)
	{
		var lnIndice, lcStr1, lcStr2, lnInicio, lcString
		var lsString
		lsString = new String();

		lsString = tsString;

		lnInicio = 0;
		lnIndice = lsString.indexOf(tsFind, lnInicio);

		while (lnIndice!=-1)
		{
			lcStr1 = lsString.substring(0,lnIndice);
			lcStr2 = lsString.substring(lnIndice + tsFind.length, lsString.length);
			lsString = lcStr1 + tsReplacement + lcStr2;
			lnInicio++;
			lnIndice = lsString.indexOf(tsFind, lnInicio);
		}

	//	lcString = tsString
		return lsString
	}
