﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("AtlasArena.ClientCollection");

AtlasArena.ClientCollection.ShoppingCart = function() {
    AtlasArena.ClientCollection.ShoppingCart.initializeBase(this);
    this.collection = new Array();
}

AtlasArena.ClientCollection.ShoppingCart.prototype = {
    initialize: function() {
        AtlasArena.ClientCollection.ShoppingCart.callBaseMethod(this, 'initialize');

        // Add custom initialization here
    },
    dispose: function() {
        //Add custom dispose actions here
        AtlasArena.ClientCollection.ShoppingCart.callBaseMethod(this, 'dispose');
    },

    Fill: function(data) {
        this.collection = data;
    },
    Remove: function(id) {
        for (var i = 0; i < this.collection.length; i++) {
            if (this.collection[i].id == id) {
                this.collection.splice(i, 1);
                break;
            }
        }
    },
    RemoveAll: function() {
        while (this.collection.length > 0)
            this.collection.pop();
    },

    Update: function(item) {
        if (item != null) {
            var isNewItem = true;
            for (var i = 0; i < this.collection.length; i++) {
                if (this.collection[i].id == item.id) {
                    this.collection[i].quantity = item.quantity;
                    this.collection[i].quantityUnit = item.quantityUnit;
                    this.collection[i].amount = item.amount;
                    isNewItem = false;
                    break;
                }
            }
            if (isNewItem)
                this.collection.push(item);
        }
    }
}

