﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="../Wcf/SDProxy.svc" />
/// <reference path="Lib/jquery-1.2.6-vsdoc.js" />
/// <reference path="beetservices-0.0.js" />
/// <reference path="carousel-0.0.js" />
/// <reference path="common.js" />
/// <reference path="cookiegram-0.0.js" />
/// <reference path="eventmanager-0.0.js" />
/// <reference path="lunchcartservices-0.0.js" />
/// <reference path="popupwindow-0.0.js" />
/// <reference path="productservices-0.0.js" />
/// <reference path="userservices-0.0.js" />

///
/// Written by CC ~ 06/04/2009
/// Revised RR ~ 06/18/2009
///
Type.registerNamespace('Specialtys.SpecialtysDirect.Client.ProductGallery');

Specialtys.SpecialtysDirect.Client.ProductGallery = function(clientId) {
    // constructor
    this._clientId = clientId;
}
Specialtys.SpecialtysDirect.Client.ProductGallery.prototype = {
    generateQtyId: function(product) {
        return this._clientId + '_qty_' + product.ProductId;
    },
    generateLinePriceId: function(product) {
        return this._clientId + '_linePrice_' + product.ProductId;
    },
    generatePriceId: function(product) {
        return this._clientId + '_itemPrice_' + product.ProductId;
    },
    addToCart: function(product) {
        var qty = $("#" + this.generateQtyId(product));
        if (qty.length == 0)
            qtyToAdd = 1;
        else
            qtyToAdd = qty.val();
        if (qtyToAdd <= 0) {
            alert("Your quantity must be greater than zero");
        } else {
            lunchcartMgr.addToCart(product.ProductId, qtyToAdd);
        }
    },
    decreaseQty: function(product) {
        var currentQty = parseInt($("#" + this.generateQtyId(product)).val());
        var basePrice = parseFloat($("#" + this.generatePriceId(product)).val());
        if ((currentQty - 1) > 0) {
            $("#" + this.generateQtyId(product)).val(currentQty - 1);
            $("#" + this.generateLinePriceId(product)).val((parseFloat(currentQty - 1) * basePrice).toFixed(2));
        } else {
            $("#" + this.generateQtyId(product)).val("0");
            $("#" + this.generateLinePriceId(product)).val("0.00");
        }

    },
    increaseQty: function(product) {
        var currentQty = parseInt($("#" + this.generateQtyId(product)).val());
        var basePrice = parseFloat($("#" + this.generatePriceId(product)).val());
        $("#" + this.generateQtyId(product)).val(currentQty + 1);
        $("#" + this.generateLinePriceId(product)).val(((parseFloat(currentQty + 1) * basePrice)).toFixed(2));
    }
}
