

var cart_mini = {
    qtd_input: null,
    span: null,
    current: null,
    add: function (product_id, product_version) {
        this.qtd_input = app.get('cart_quantity_' + product_id + '_' + product_version);
        var product_quantity = this.qtd_input.value;
        if (isNaN(product_quantity)) {
            this.qtd_input.value = 0;
            return alert('Please enter a number!');
        } else if (product_quantity == 0) {
            this.qtd_input.value = 1;
            return alert('Please enter a product quantity!');
        }
        this.span = app.get('product_button_' + product_id);
        this.current = this.span.innerHTML;
        this.span.innerHTML = '<img src="/public/styles/images/checkout/loading.gif" alt="wait a moment ..." />';
        var ret = ajax.exec('POST', '/application/api/cart.add.php', 'product_id=' + product_id + '&product_version=' + product_version + '&qtd=' + product_quantity);
        this.span.innerHTML = '<b>Added to <a href="/cart/">shopping cart</a></b>';
        var t = setTimeout('cart_mini.update_message()', 2000);
        var msg = app.get('cart_message');
        msg.innerHTML = ret;
    },
    update_message: function() {
        this.span.innerHTML = this.current;
        this.qtd_input.value = 1;
    }
}

