define("money", ["moneyApi"],
    function(moneyApi) {
        "use strict";

        function $iterator(o) {
            if (o instanceof Array) return function() {
                return {
                    cur: 0,
                    arr: o,
                    hasNext: function() {
                        return this.cur < this.arr.length;
                    },
                    next: function() {
                        return this.arr[this.cur++];
                    }
                };
            };
            return typeof(o.iterator) == 'function' ? $bind(o, o.iterator) : o.iterator;
        };;
        var $fid = 0;

        function $bind(o, m) {
            if (m == null) return null;
            if (m.__id__ == null) m.__id__ = $fid++;
            var f;
            if (o.hx__closures__ == null) o.hx__closures__ = {};
            else f = o.hx__closures__[m.__id__];
            if (f == null) {
                f = function() {
                    return f.method.apply(f.scope, arguments);
                };
                f.scope = o;
                f.method = m;
                o.hx__closures__[m.__id__] = f;
            }
            return f;
        };
        var $_;
        var $estr = function() {
            return _hcmn_.js_Boot.__string_rec(this, '');
        };
        if (typeof money == 'undefined') {
            var money = {};
        };
        money.DecimalNumber = function(value) {
            this.isNegative = false;
            this.wholePart = "";
            this.decimalPart = "";
            if (value == null || value == "") return;
            var truncValue = value.split(" ").join("");
            var first = _hcmn_.HxOverrides.substr(truncValue, 0, 1);
            if (first == "+") truncValue = _hcmn_.HxOverrides.substr(truncValue, 1, null);
            if (first == "-") {
                truncValue = _hcmn_.HxOverrides.substr(truncValue, 1, null);
                this.isNegative = true;
            }
            var truncArray = truncValue.split(money.DecimalNumber.decimalPoint);
            this.wholePart = truncArray[0];
            if (truncArray.length > 1) this.decimalPart = truncArray[1];
            this.clean();
        };
        money.DecimalNumber.__name__ = ["money", "DecimalNumber"];
        money.DecimalNumber.prototype.isNegative = null;
        money.DecimalNumber.prototype.wholePart = null;
        money.DecimalNumber.prototype.decimalPart = null;
        money.DecimalNumber.prototype.toString = function() {
            this.clean();
            var result_b = "";
            if (this.isNegative) result_b += "-";
            if (this.isEmpty(this.wholePart)) result_b += "0";
            else result_b += _hcmn_.Std.string(this.wholePart);
            if (!this.isEmpty(this.decimalPart)) {
                result_b += _hcmn_.Std.string(money.DecimalNumber.decimalPoint);
                result_b += _hcmn_.Std.string(this.decimalPart);
            }
            return result_b;
        };
        money.DecimalNumber.prototype.add = function(number) {
            if (this.isCleanZero()) return number.clone();
            if (number.isCleanZero()) return this.clone();
            var absValue1 = this.abs();
            var absValue2 = number.abs();
            var resultStr = null;
            var changeSign = false;
            if (this.isNegative) {
                if (number.isNegative) {
                    resultStr = this.addPositiveNumbers(absValue1, absValue2);
                    changeSign = true;
                } else resultStr = this.subPositiveNumbers(absValue2, absValue1);
            } else if (number.isNegative) resultStr = this.subPositiveNumbers(absValue1, absValue2);
            else resultStr = this.addPositiveNumbers(absValue1, absValue2);
            var result = new money.DecimalNumber(resultStr);
            if (changeSign) result.changeSign();
            return result;
        };
        money.DecimalNumber.prototype.sub = function(number) {
            if (this.isCleanZero()) return number.neg();
            if (number.isCleanZero()) return this.clone();
            var absValue1 = this.abs();
            var absValue2 = number.abs();
            var resultStr = null;
            var changeSign = false;
            if (this.isNegative) {
                if (number.isNegative) resultStr = this.subPositiveNumbers(absValue2, absValue1);
                else {
                    resultStr = this.addPositiveNumbers(absValue1, absValue2);
                    changeSign = true;
                }
            } else if (number.isNegative) resultStr = this.addPositiveNumbers(absValue1, absValue2);
            else resultStr = this.subPositiveNumbers(absValue1, absValue2);
            var result = new money.DecimalNumber(resultStr);
            if (changeSign) result.changeSign();
            return result;
        };
        money.DecimalNumber.prototype.mul = function(number) {
            if (this.isCleanZero()) return this.getZero();
            if (number.isCleanZero()) return this.getZero();
            if (this.isCleanOne() && !this.isNegative) return number.clone();
            if (number.isCleanOne() && !number.isNegative) return this.clone();
            var absValue1 = this.abs();
            var absValue2 = number.abs();
            var resultStr = null;
            var result = new money.DecimalNumber(this.mulPositiveNumbers(absValue1, absValue2));
            if (this.isNegative && !number.isNegative || !this.isNegative && number.isNegative) result.changeSign();
            return result;
        };
        money.DecimalNumber.prototype.mulInt = function(number) {
            if (this.isCleanZero()) return this.getZero();
            if (this.isCleanOne() && !this.isNegative) return new money.DecimalNumber(number == null ? "null" : "" + number);
            if (number == 0) return this.getZero();
            if (number == 1) return this.clone();
            var absValue1 = this.abs();
            var absNumber = number;
            if (number < 0) absNumber = -number;
            var resultStr = null;
            var result = new money.DecimalNumber(this.mulIntPositiveNumbers(absValue1, absNumber));
            if (this.isNegative && number >= 0 || !this.isNegative && number < 0) result.changeSign();
            return result;
        };
        money.DecimalNumber.prototype.neg = function() {
            var result = this.clone();
            result.changeSign();
            return result;
        };
        money.DecimalNumber.prototype.abs = function() {
            if (this.isNegative) return this.neg();
            else return this.clone();
        };
        money.DecimalNumber.prototype.clone = function() {
            return new money.DecimalNumber(this.toString());
        };
        money.DecimalNumber.prototype.isZero = function() {
            this.clean();
            return this.isCleanZero();
        };
        money.DecimalNumber.prototype.clean = function() {
            this.wholePart = this.truncLeftZeros(this.wholePart);
            this.decimalPart = this.truncRightZeros(this.decimalPart);
            if (this.isCleanZero()) this.isNegative = false;
        };
        money.DecimalNumber.prototype.isCleanZero = function() {
            return this.isEmpty(this.wholePart) && this.isEmpty(this.decimalPart);
        };
        money.DecimalNumber.prototype.isCleanOne = function() {
            return this.wholePart == "1" && this.isEmpty(this.decimalPart);
        };
        money.DecimalNumber.prototype.getZero = function() {
            return new money.DecimalNumber("0");
        };
        money.DecimalNumber.prototype.getOne = function() {
            return new money.DecimalNumber("1");
        };
        money.DecimalNumber.prototype.changeSign = function() {
            if (!this.isCleanZero()) this.isNegative = !this.isNegative;
        };
        money.DecimalNumber.prototype.addPositiveNumbers = function(value1, value2) {
            if (value1.isCleanZero()) return value2.toString();
            if (value2.isCleanZero()) return value1.toString();
            var decimalCount = this.maxInt(value1.decimalCount(), value2.decimalCount());
            var digits1 = value1.getDigits(decimalCount);
            var digits2 = value2.getDigits(decimalCount);
            var result = this.addPositiveIntegers(digits1, digits2);
            result = this.positiveIntToDecimalString(result, decimalCount);
            return result;
        };
        money.DecimalNumber.prototype.subPositiveNumbers = function(value1, value2) {
            if (value1.isCleanZero()) return value2.neg().toString();
            if (value2.isCleanZero()) return value1.toString();
            var decimalCount = this.maxInt(value1.decimalCount(), value2.decimalCount());
            var digits1 = value1.getDigits(decimalCount);
            var digits2 = value2.getDigits(decimalCount);
            var result = this.subPositiveIntegers(digits1, digits2);
            result = this.positiveIntToDecimalString(result, decimalCount);
            return result;
        };
        money.DecimalNumber.prototype.mulPositiveNumbers = function(value1, value2) {
            if (value1.isCleanZero()) return "0";
            if (value2.isCleanZero()) return "0";
            if (value1.isCleanOne()) return value2.toString();
            if (value2.isCleanOne()) return value1.toString();
            var decimalCount = value1.decimalCount() + value2.decimalCount();
            var digits1 = value1.getDigits(0);
            var digits2 = value2.getDigits(0);
            var result = this.mulPositiveIntegers(digits1, digits2);
            result = this.positiveIntToDecimalString(result, decimalCount);
            return result;
        };
        money.DecimalNumber.prototype.mulIntPositiveNumbers = function(value1, number) {
            if (value1.isCleanZero()) return "0";
            if (value1.isCleanOne())
                if (number == null) return "null";
                else return "" + number;
            if (number == 0) return "0";
            if (number == 1) return value1.toString();
            var decimalCount = value1.decimalCount();
            var digits1 = value1.getDigits(0);
            var result = this.mulIntPositiveIntegersImpl(digits1, number).join("");
            result = this.positiveIntToDecimalString(result, decimalCount);
            return result;
        };
        money.DecimalNumber.prototype.decimalCount = function() {
            if (this.isEmpty(this.decimalPart)) return 0;
            return this.decimalPart.length;
        };
        money.DecimalNumber.prototype.addPositiveIntegers = function(int1, int2) {
            return this.addPositiveIntegersImpl(int1, int2).join("");
        };
        money.DecimalNumber.prototype.addPositiveIntegersImpl = function(int1, int2) {
            var resultReverse = [];
            var overflow = 0;
            var numberOfDigits = this.maxInt(int1.length, int2.length);
            var revertIndex;
            var _g = 0;
            while (_g < numberOfDigits) {
                var revertIndex1 = _g++;
                var sum = overflow;
                var index1 = int1.length - 1 - revertIndex1;
                if (index1 >= 0) sum += int1[index1];
                var index2 = int2.length - 1 - revertIndex1;
                if (index2 >= 0) sum += int2[index2];
                if (sum > 9) {
                    overflow = 1;
                    sum = sum - 10;
                } else overflow = 0;
                resultReverse.push(sum);
            }
            if (overflow > 0) resultReverse.push(overflow);
            resultReverse.reverse();
            return resultReverse;
        };
        money.DecimalNumber.prototype.subPositiveIntegers = function(int1, int2) {
            var resultReverse = [];
            var borrow = 0;
            var numberOfDigits = this.maxInt(int1.length, int2.length);
            var revertIndex;
            var _g = 0;
            while (_g < numberOfDigits) {
                var revertIndex1 = _g++;
                var diff = -borrow;
                var index1 = int1.length - 1 - revertIndex1;
                if (index1 >= 0) diff += int1[index1];
                var index2 = int2.length - 1 - revertIndex1;
                if (index2 >= 0) diff -= int2[index2];
                if (diff < 0) {
                    borrow = 1;
                    diff = diff + 10;
                } else borrow = 0;
                resultReverse.push(diff);
            }
            resultReverse.reverse();
            var result = resultReverse.join("");
            if (borrow > 0) {
                var borrowedInt = [];
                borrowedInt.push(1);
                var index;
                var _g1 = 0;
                while (_g1 < numberOfDigits) {
                    var index3 = _g1++;
                    borrowedInt.push(0);
                }
                result = "-" + this.subPositiveIntegers(borrowedInt, resultReverse);
            }
            return result;
        };
        money.DecimalNumber.prototype.mulPositiveIntegers = function(int1, int2) {
            var result = [];
            result.push(0);
            var multiplier = [];
            var revertIndex;
            var _g1 = 0;
            var _g = int2.length;
            while (_g1 < _g) {
                var revertIndex1 = _g1++;
                var index2 = int2.length - 1 - revertIndex1;
                var mul = null;
                var n = int2[index2];
                if (n > 0) {
                    mul = this.mulIntPositiveIntegersImpl(int1, n);
                    if (revertIndex1 > 0) {
                        var zeroIndex;
                        var _g2 = 0;
                        while (_g2 < revertIndex1) {
                            var zeroIndex1 = _g2++;
                            mul.push(0);
                        }
                    }
                    result = this.addPositiveIntegersImpl(result, mul);
                }
            }
            return result.join("");
        };
        money.DecimalNumber.prototype.mulIntPositiveIntegersImpl = function(int1, n) {
            if (n == 1) return this.copyIntArray(int1);
            var resultReverse = [];
            if (n == 0) {
                resultReverse.push(0);
                return resultReverse;
            }
            var overflow = 0;
            var revertIndex;
            var _g1 = 0;
            var _g = int1.length;
            while (_g1 < _g) {
                var revertIndex1 = _g1++;
                var mul = overflow;
                overflow = 0;
                var index1 = int1.length - 1 - revertIndex1;
                mul = mul + int1[index1] * n;
                if (mul > 9)
                    while (mul > 9) {
                        overflow = overflow + 1;
                        mul = mul - 10;
                    }
                resultReverse.push(mul);
            }
            if (overflow > 0) resultReverse.push(overflow);
            resultReverse.reverse();
            return resultReverse;
        };
        money.DecimalNumber.prototype.getDigits = function(minDecimalCount) {
            var result = [];
            if (!this.isEmpty(this.wholePart)) {
                var digitS;
                var _g = 0;
                var _g1 = this.wholePart.split("");
                while (_g < _g1.length) {
                    var digitS1 = _g1[_g];
                    ++_g;
                    result.push(_hcmn_.Std.parseInt(digitS1));
                }
            }
            if (!this.isEmpty(this.decimalPart)) {
                var digitS2;
                var _g2 = 0;
                var _g11 = this.decimalPart.split("");
                while (_g2 < _g11.length) {
                    var digitS3 = _g11[_g2];
                    ++_g2;
                    result.push(_hcmn_.Std.parseInt(digitS3));
                }
            }
            if (minDecimalCount > 0) {
                if (this.decimalCount() < minDecimalCount) {
                    var index;
                    var _g3 = this.decimalCount();
                    while (_g3 < minDecimalCount) {
                        var index1 = _g3++;
                        result.push(0);
                    }
                }
            }
            return result;
        };
        money.DecimalNumber.prototype.addRightZeros = function(value, count) {
            var result_b = "";
            if (value == null) result_b += "null";
            else result_b += "" + value;
            var i;
            var _g = 0;
            while (_g < count) {
                var i1 = _g++;
                result_b += "0";
            }
            return result_b;
        };
        money.DecimalNumber.prototype.getZeros = function(count) {
            var result_b = "";
            var i;
            var _g = 0;
            while (_g < count) {
                var i1 = _g++;
                result_b += "0";
            }
            return result_b;
        };
        money.DecimalNumber.prototype.truncLeftZeros = function(value) {
            if (this.isEmpty(value)) return value;
            var truncValue = value;
            while (_hcmn_.HxOverrides.substr(truncValue, 0, 1) == "0") {
                truncValue = _hcmn_.HxOverrides.substr(truncValue, 1, null);
                if (this.isEmpty(truncValue)) break;
            }
            return truncValue;
        };
        money.DecimalNumber.prototype.truncRightZeros = function(value) {
            if (this.isEmpty(value)) return value;
            var truncValue = value;
            while (_hcmn_.HxOverrides.substr(truncValue, truncValue.length - 1, 1) == "0") {
                truncValue = _hcmn_.HxOverrides.substr(truncValue, 0, truncValue.length - 1);
                if (this.isEmpty(truncValue)) break;
            }
            return truncValue;
        };
        money.DecimalNumber.prototype.isEmpty = function(value) {
            if (value == null) return true;
            if (value == "") return true;
            return false;
        };
        money.DecimalNumber.prototype.maxInt = function(a, b) {
            if (a == null) return b;
            if (b == null) return a;
            if (a > b) return a;
            return b;
        };
        money.DecimalNumber.prototype.positiveIntToDecimalString = function(number, decimalCount) {
            var result = "";
            if (decimalCount > 0) {
                if (number.length <= decimalCount) {
                    var resultBuff = new _hcmn_.StringBuf();
                    resultBuff.b += "0";
                    resultBuff.b += _hcmn_.Std.string(money.DecimalNumber.decimalPoint);
                    if (decimalCount - number.length > 0) resultBuff.add(this.getZeros(decimalCount - number.length));
                    if (number == null) resultBuff.b += "null";
                    else resultBuff.b += "" + number;
                    result = resultBuff.b;
                } else {
                    var resultBuff1 = new _hcmn_.StringBuf();
                    resultBuff1.add(_hcmn_.HxOverrides.substr(number, 0, number.length - decimalCount));
                    resultBuff1.b += _hcmn_.Std.string(money.DecimalNumber.decimalPoint);
                    resultBuff1.add(_hcmn_.HxOverrides.substr(number, number.length - decimalCount, null));
                    result = resultBuff1.b;
                }
            } else result = number;
            return result;
        };
        money.DecimalNumber.prototype.copyIntArray = function(value) {
            if (value == null) return null;
            var element;
            var result = [];
            var _g = 0;
            while (_g < value.length) {
                var element1 = value[_g];
                ++_g;
                result.push(element1);
            }
            return result;
        };
        money.DecimalNumber.prototype.__class__ = money.DecimalNumber;
        money.Money = function(value) {
            this.value = value;
        };
        money.Money.__name__ = ["money", "Money"];
        money.Money.prototype.value = null;
        money.Money.prototype.add = function(money1) {
            var value1 = new money.DecimalNumber(this.value);
            var value2 = new money.DecimalNumber(money1.value);
            return new money.Money(value1.add(value2).toString());
        };
        money.Money.prototype.sub = function(money1) {
            var value1 = new money.DecimalNumber(this.value);
            var value2 = new money.DecimalNumber(money1.value);
            return new money.Money(value1.sub(value2).toString());
        };
        money.Money.prototype.mul = function(money1) {
            var value1 = new money.DecimalNumber(this.value);
            var value2 = new money.DecimalNumber(money1.value);
            return new money.Money(value1.mul(value2).toString());
        };
        money.Money.prototype.mulInt = function(value) {
            var value1 = new money.DecimalNumber(this.value);
            return new money.Money(value1.mulInt(value).toString());
        };
        money.Money.prototype.compare = function(money1) {
            var value1 = new money.DecimalNumber(this.value);
            var value2 = new money.DecimalNumber(money1.value);
            var sub = value1.sub(value2);
            if (sub.isNegative) return -1;
            else if (sub.isZero()) return 0;
            return 1;
        };
        money.Money.prototype.__class__ = money.Money;
        money.DecimalNumber.decimalPoint = ".";;
        return {
            exports: money
        };
    });
//# sourceURL=money.js