﻿/// <reference name="MicrosoftAjax.js" />
/// <reference path="ITG.js" />
/// <reference path="ITG.Client.RadAjaxManager.js" />

ITG.Client.RadToolTipManager = function(clientID)
{
    /// <summary>
    /// Javascript class used to easily integrate with the RadToolTipManager control client-side functionality.
    /// </summary>

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // CONSTANTS
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // INSTANCE VARIABLES
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    this._id = clientID;
    this._toolTipManager = null;
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

ITG.Client.RadToolTipManager.prototype =
{
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // GETTERS / SETTERS
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    get_id: function()
    {
        /// <summary>
        /// Gets the client id for this instance.
        /// </summary>
        return this._id;
    },

    set_id: function(value)
    {
        /// <summary>
        /// Sets the client id for this instance.
        /// </summary>
        this._id = value;
    },
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // METHODS
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    show: function(element, title, message)
    {
        var manager = this.get();
        var tooltip = null;

        if (!manager) return;

        tooltip = manager.getToolTipByElement(element);

        if (!tooltip)
        {
            var outerspan = $("<span></span>");
            var div = $(String.format("<div>{0}</div>", message));

            div.css("text-align", "justify");
            div.css("padding", "8px");
            outerspan.append(div);

            tooltip = manager.createToolTip(element);
            tooltip.set_modal(true);
            tooltip.set_showCallout(true);
            tooltip.set_showDelay(2000);
            tooltip.set_text(outerspan.html());

            if (title) tooltip.set_title(title);
        }

        tooltip.show();
    },

    get: function()
    {
        /// <summary>
        /// Gets the RadToolTipManager for this instance.
        /// </summary>

        if (!this._toolTipManager)
        {
            this._toolTipManager = $find(this.get_id());
        }

        return this._toolTipManager;
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
