var ProductDetailsHandler =
{
    translations:
    {
        productAlreadyAddedAsMyProduct: "Det valgte produkt har du allerede tilføjet til dine produkter.",
        addProductError: "Der opstod desværre en fejl, prøv evt. igen.",
        productAdded: "Det valgte produkt blev tilføjet til dine produkter."
    },
    
    addUrl: "/",
    addButtonID: "",
    
    add: function()
    {
        $.getJSON(this.addUrl, this.callBack.bind(this));
    },
    
    callBack: function(data)
    {
        if (data)
        {
            if (data.error)
            {
                if (data.productAlreadyAddedAsMyProduct)
                    this.disableLinkButton();
            
                alert(data.errorMessage);
                return;
            }
            else
            {
                this.disableLinkButton();
                
                var span = $("#MyProductsCountSpan");
                
                if (span && span.length > 0)
                    span.html(data.productUserCount);
                
                alert(this.translations.productAdded);
            }
        }
        else
        {
            alert(this.translations.addProductError);
        }
    },
    
    disableLinkButton: function()
    {
        var button = $("#" + this.addButtonID + " a");
        button.attr("href", "javascript:alert('" + this.translations.productAlreadyAddedAsMyProduct + "')");
        button.attr("title", this.translations.productAlreadyAddedAsMyProduct);
    }
}
