
var reimbursementModel = function (data) {

    var self = this;
    ko.mapping.fromJS(data, {}, self);
    self.options = ko.observable(data.ExpressShipping ? "ExpressShipping" : "RegularShipping");

    self.options.subscribe(function (newValue) {

        if (self.options() === "RegularShipping") {

            self.RegularShipping(true);
            self.ExpressShipping(false);
            self.WaiveShippingFee(false);

            var url = "GetReimbursementData";

            $.ajax({
                dataType: "json",
                method: "post",
                url: url,
                cache: false,
                data: {
                        regularShipping: self.RegularShipping(),
                        expressShipping: self.ExpressShipping(),
                        waiveShippingFee: self.WaiveShippingFee()
                    }
            }).done(function (returnObject) {
                self.ShippingFeeInString(returnObject.ShippingFeeInString);
                self.RegularShipping(true);
                self.ExpressShipping(false);
                self.WaiveShippingFee(false);
                loadPaymentSummary();
            });
        }

        if (self.options() === "ExpressShipping") {

            self.RegularShipping(false);
            self.ExpressShipping(true);

            var url = "GetReimbursementData";

            $.ajax({
                dataType: "json",
                method: "post",
                url: url,
                cache: false,
                data: {
                    regularShipping: self.RegularShipping(),
                    expressShipping: self.ExpressShipping(),
                    waiveShippingFee: self.WaiveShippingFee()
                }
            }).done(function (returnObject) {
                self.ShippingFeeInString(returnObject.ShippingFeeInString);
                self.RegularShipping(false);
                self.ExpressShipping(true);
                loadPaymentSummary();
            });
        }

    }, self);

    self.WaiveShippingFee.subscribe(function (newValue) {

        if (self.options() === "ExpressShipping") {

            self.RegularShipping(false);
            self.ExpressShipping(true);

            var url = "GetReimbursementData";

            $.ajax({
                dataType: "json",
                method: "post",
                url: url,
                cache: false,
                data: {
                    regularShipping: self.RegularShipping(),
                    expressShipping: self.ExpressShipping(),
                    waiveShippingFee: self.WaiveShippingFee()
                }
            }).done(function (returnObject) {
                self.ShippingFeeInString(returnObject.ShippingFeeInString);
                self.RegularShipping(false);
                self.ExpressShipping(true);
                loadPaymentSummary();
            });
        }

    }, self);

    self.isDisplayWaiveShippingFee = ko.computed(function () {
        return self.DisplayWaiveShippingFee() && self.DisplayExpressShipping();
    });

    self.isEnableWaiveShippingFee = ko.computed(function () {
        return !self.RegularShipping();
    });

};

