var ResultOptionsHandler =
{
    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: "/?pid=",

    addProduct: function(id, buttonId)
    {
        $.getJSON(this.addUrl + id, this.callBack.bind(this, buttonId));
    },

    callBack: function(buttonId, data)
    {
        if (data)
        {
            if (data.error)
            {
                if (data.productAlreadyAddedAsMyProduct)
                    this.disableLinkButton(buttonId);
            
                alert(data.errorMessage);
                return;
            }
            else
            {
                this.disableLinkButton(buttonId);
                
                var span = $("#MyProductsCountSpan");
                
                if (span && span.length > 0)
                    span.html(data.productUserCount);
                
                alert(this.translations.productAdded);
            }
        }
        else
        {
            alert(this.translations.addProductError);
        }
    },

    disableLinkButton: function(buttonId)
    {
        var button = $("#" + buttonId + " a");
        button.attr("href", "javascript:alert('" + this.translations.productAlreadyAddedAsMyProduct + "')");
        button.attr("title", this.translations.productAlreadyAddedAsMyProduct);
    }
}
