/// class ProspectDirector.Web.UI.Utilities.Kendo.Grid

ProspectDirector.Web.UI.Utilities.Kendo.Grid = Class.extend({
});

//==============================
// STATIC METHODS
//==============================

ProspectDirector.Web.UI.Utilities.Kendo.Grid.addMessage = function (grid, text, callback) {

    var container = $("<table style=\"height:99%;background-color:#FFFFFF;border:0px;\" data-role=\"message-container\"><tr><td style=\"border-width:0px;text-align:center;vertical-align:middle;\"></td></tr></table>"),
        message = $("<span style=\"font-size:13px;color:#999999;\" data-role=\"message\">" + text + "</span>");

    ProspectDirector.Web.UI.Utilities.Kendo.Grid.removeMessage(grid);

    if ($.isFunction(callback)) {

        message.css({
            textDecoration: "underline",
            color: "#0000FF",
            cursor: "pointer"
        });

        grid.on("click.gridmessage", "[data-role=message-container] [data-role=message]", callback);

    }

    message.appendTo(container.find("TR > TD"));

    grid.find(".k-grid-content > TABLE[role=grid]").hide();
    grid.find(".k-grid-content").prepend(container);

}

ProspectDirector.Web.UI.Utilities.Kendo.Grid.removeMessage = function (grid) {
    grid.find(".k-grid-content > TABLE[role=grid]").show();
    grid.find(".k-grid-content [data-role=message-container]").remove();
    grid.off("click.gridmessage");
};

ProspectDirector.Web.UI.Utilities.Kendo.Grid.setHeight = function (grid, height) {

    var nonContentHeight = 0;

    grid.children().not(".k-grid-content").each(function () {
        nonContentHeight += $(this).outerHeight(true);
    });

    grid.find(".k-grid-content").height(height - nonContentHeight);

};

ProspectDirector.Web.UI.Utilities.Kendo.Grid.fill = function (options) {

    var height = ProspectDirector.Web.UI.Utilities.Kendo.Grid.getAvailableSpace(options),
        grid = options.grid,
        nonContentHeight = 0;

        grid.children().not(".k-grid-content").each(function () {
            nonContentHeight += $(this).outerHeight(true);
        });

        grid.find(".k-grid-content").height(height - nonContentHeight);

};

ProspectDirector.Web.UI.Utilities.Kendo.Grid.getAvailableSpace = function (options) {

    var height = 0,
        grid = options.grid;

    if (options.useAvailableSpace) {

        height = grid.parent().outerHeight(true);

        grid.children().each(function (index, element) {
            if (!$(element).is(grid)) {
                height = height - $(element).outerHeight(true);
            }
        });

    }
    else {
        height = grid.innerHeight();
    }

    return (height < 0) ? 0 : height;

}