/*
    recipe_search.js Recipe search
    Dependencies : Prototype JavaScript framework 1.6
                   utilities.js
*/

var SOSCuisine = SOSCuisine || {};

SOSCuisine.recipeSearch =
{
    toggleSelectAllItem: function(obj)
    {
        nodes = $$("form#form_recipe_search_action input[type='checkbox']");
        nodes.each(function(node)
        {
            node.checked = obj.checked;
        }.bind(this));
    },

    resetSelectAllCheckbox: function()
    {
        nodes = $$('input.search_action_select_all');
        nodes.each(function(node)
        {
            node.checked = false;
        }.bind(this));
    },

    reviewRecipe: function(obj, recipeId, forceRatingSelection)
    {
        this.recipeId = recipeId;

        if (Object.isUndefined(forceRatingSelection))
        {
            forceRatingSelection = true;
        }

        var callback =
        {
            success: function(args)
            {
                var div = Element.up(obj).up();
                new Ajax.Request(SOSCuisine.config.urlRoot + "recipe_search_ratings.php",
                {
                    method: "get",
                    encoding: 'iso-8859-1',
                    parameters: { recipe_id: recipeId },
                    onSuccess: function(transport)
                    {
                        var response = transport.responseText || "";
                        div.innerHTML = response;
                    } .bind(this)
                });
            },

            cancel: function() { }
        };

        SOSCuisine.windowRecipeReview.show({ source: obj, callback: callback, recipeId: recipeId, forceRatingSelection: forceRatingSelection });
    }
};
