var amountValue; 
var curWithoutDec 	= "ADP;901;AFA;961;BEF;000;BIF;451;CLP;571;DJF;931;ESP;141;GNF;920;GRD;161;ITL;071;JPY;831;KMF;651;LUF;151;MGF;421;PTE;121;PYG;591;RWF;371;TJR;265;UGX;934;XAF;927;XOF;917;XPF;857;KRW;981;TRL;181;ISK;211";
var curWithThreeDec = "BHD;963;JOD;962;KWD;761;IQD;721;LYD;911;OMR;965;TND;321;";
var curWithFiveDec 	= "XBA;998;XBB;997;XBC;999;XBD;996;";

//-----------------------------------------------------------------------------

function BBLCheckDecAmount(strAmount, strCur, nDec) {
	return BBLCheckSignedAmount(strAmount, strCur, nDec, false);
}

function BBLCheckAmount(strAmount, strCur) {
	return BBLCheckSignedAmount(strAmount, strCur, -1, false);
}

function BBLCheckSignedAmount(strAmount, strCur, allowNegativeValue) {
	return BBLCheckSignedAmountMultiCCRY(strAmount, strCur, allowNegativeValue);
}

function BBLCheckSignedAmountMultiCCRY(strAmount, strCur, allowNegativeValue) {
	var i, c;

	var strTmp	= strtrim(strAmount);
	var strInt	= "";
	var strDec	= "";
	var len		= strTmp.length;

	if (len == 0) {

		if ( curWithoutDec.indexOf(strCur) != -1 || strCur == "   " ) {
			strResult = strCur + "+000000000000000000";
		} else if ( curWithThreeDec.indexOf(strCur) != -1 ) {
			strResult = strCur + "+000000000000000003";
		} else if ( curWithFiveDec.indexOf(strCur) != -1 ) {
			strResult = strCur + "+000000000000000005";
		} else if ( strtrim(strCur) == "") {
			strResult = "   +000000000000000000";
		} else {
			strResult = strCur + "+000000000000000002";
		}
		return 0;

	} else if (len > 15) {
		return -1;
	} else {
		strResult = "";
	}

	var decPoint	= ' ';
	var sign		= '+';

	if (strTmp.charAt(0) == '-') {
		if (! allowNegativeValue) {
			return -1;
		}

		sign = '-';
		strTmp = strtrim(strTmp.substring(1));
		len = strTmp.length;
	}

	for (i = len - 1; i >= 0; i--) {
		c = strTmp.charAt(i);

		if ((c == '.') || (c == ',')) {

			if ((decPoint == ' ') && (curWithoutDec.indexOf(strCur) == -1)) {

				decPoint	= c;
				strDec		= strInt;
				strInt		= "";

				if (strDec.length > 5)
					return -1

			} else {

				return -1;

			}

		} else if ((c >= '0') && (c <= '9')) {
			strInt = c + strInt;
		} else {
			return -1;
		}
	}

	if (curWithoutDec.indexOf(strCur) != -1) {

		strResult	= strCur + sign + formatnumber(strInt, 17) + "0";
		amountValue	= parseFloat(strInt);

	} else if (curWithThreeDec.indexOf(strCur) != -1) {

		strDec = strDec + "000";
		strResult	= strCur + sign + formatnumber(strInt, 14) + strDec.substring(0,3) + "3";
		amountValue	= parseFloat(strInt + "." + strDec);

	} else if (curWithFiveDec.indexOf(strCur) != -1) {

		strDec = strDec + "000";
		strResult	= strCur + sign + formatnumber(strInt, 12) + strDec.substring(0,5) + "5";
		amountValue	= parseFloat(strInt + "." + strDec);

	} else if ( strtrim(strCur) == ""){

		strResult	= "   " + sign + formatnumber(strInt, 17 - strDec.length) + strDec;
		strResult = strResult + strDec.length;
		amountValue	= parseFloat(strInt + "." + strDec);

	} else {

		strDec = strDec + "00";
		strResult	= strCur + sign + formatnumber(strInt, 15) + strDec.substring(0,2) + "2";
		amountValue	= parseFloat(strInt + "." + strDec);
	}

	if (sign == '-') {
		amountValue = (amountValue * -1);
	}

	return 1;
}

//-----------------------------------------------------------------------------

function BBLCheckAmountEx(strAmount, strCur) {
	return BBLCheckSignedAmountEx(strAmount, strCur, false);
}

function BBLCheckSignedAmountEx(strAmount, strCur, allowNegativeValue) {
	if (strCur == "   ")
		return BBLCheckSignedDecimalAmountEx(strAmount, strCur, allowNegativeValue, false);
	else
		return BBLCheckSignedDecimalAmountEx(strAmount, strCur, allowNegativeValue, true);
}

function BBLCheckSignedDecimalAmountEx(strAmount, strCur, allowNegativeValue, allowDecimalValue) {
	 var i, c;

	var strTmp	= strtrim(strAmount);
	var strInt	= "";
	var strDec	= "";
	var len		= strTmp.length;

	if (len == 0){

		if ( curWithoutDec.indexOf(strCur) != -1 || strCur == "   " ) {
			strResult = strCur + "+0000000000000000000000000000000000000000";
		} else if ( curWithThreeDec.indexOf(strCur) != -1 ) {
			strResult = strCur + "+0000000000000000000000000000000000000003";
		} else if ( curWithFiveDec.indexOf(strCur) != -1 ) {
			strResult = strCur + "+0000000000000000000000000000000000000005";
		} else {
			strResult = strCur + "+0000000000000000000000000000000000000002";
		}
		return 0;

	} else if (len > 36) {
		return -1;
	} else {
		strResult = "";
	}

	var decPoint = ' ';
	var sign		= '+';

	if (strTmp.charAt(0) == '-') {
		if (! allowNegativeValue) {
			return -1;
		}

		sign = '-';
		strTmp = strtrim(strTmp.substring(1));
		len = strTmp.length;
	}

	for (i = len - 1; i >= 0; i--) {
		c = strTmp.charAt(i);

		if ((c == '.') || (c == ',')) {

			if ((decPoint == ' ') && (curWithoutDec.indexOf(strCur) == -1) && allowDecimalValue) {
				decPoint	= c;
				strDec		= strInt;
				strInt		= "";

				if (strDec.length > 5)
					return -1

			} else {
				return -1;
			}

		} else if ((c >= '0') && (c <= '9')) {
			strInt = c + strInt;
		} else {
			return -1;
		}
	}

	if ( curWithoutDec.indexOf(strCur) != -1 ) {

		strResult	= strCur + sign + formatnumber(strInt, 38) + "00";
		amountValue	= parseFloat(strInt);

	} else if ( curWithThreeDec.indexOf(strCur) != -1) {

		strDec = strDec + "000";
		strResult	= strCur + sign + formatnumber(strInt, 35) + strDec.substring(0,3) + "03";
		amountValue	= parseFloat(strInt + "." + strDec);

	} else if ( curWithFiveDec.indexOf(strCur) != -1) {

		strDec = strDec + "00000";
		strResult	= strCur + sign + formatnumber(strInt, 33) + strDec.substring(0,5) + "05";
		amountValue	= parseFloat(strInt + "." + strDec);

	} else if ( strCur == "   "){

		strResult	= strCur + sign + formatnumber(strInt, 38 - strDec.length) + strDec;

		if (strDec.length < 10)
			strResult = strResult + "0" + strDec.length;
		else
			strResult = strResult + strDec.length;

		amountValue	= parseFloat(strInt + "." + strDec);

	} else {

		strDec = strDec + "00";
		strResult	= strCur + sign + formatnumber(strInt, 36) + strDec.substring(0,2) + "02";
		amountValue	= parseFloat(strInt + "." + strDec);
	}

	if (sign == '-') {
		amountValue = (amountValue * -1);
	}

	return 1;
}

//-----------------------------------------------------------------------------

function BBLCvtAmount(strAmount) { 
	var nDec       = parseInt(strAmount.charAt(21));
  	var strIntPart = strAmount.substring(5, 21 - nDec);
  	var strDecPart = strAmount.substring(21 - nDec, 21);

	var retVal;
	
  	if (strDecPart.length == 0)
    	retVal = (parseFloat(strIntPart));
	else
    	retVal = (parseFloat(strIntPart + '.' + strDecPart));
    	
    if ((strAmount.charAt(3) == '-') || (strAmount.charAt(3) == '1')) {
    	retVal = (retVal * -1);
    }
    	
    return retVal;
}

//-----------------------------------------------------------------------------
