﻿/**
 * Контрол для показа Индикатора БР на главной странице
 * (Использует паттерн MS Ajax Component. Будет доступен через $find)
 */
function IndicatorBR()
{
	//Стандартный интерфейс для компонента
	IndicatorBR.initializeBase(this);
	//ID элемента, в котором находится данный контрол
	this._containerElementID = null;
	this.tooltip = null;
};
IndicatorBR.prototype =
{
    get_containerElementID: function()
    {
        return this._containerElementID;
    },
    set_containerElementID: function(value)
    {
        this._containerElementID = value;
    },
    /**
    * Устанавливает значение частоты
    * @param {Object} value Значение цены
    */
    set_value: function(value)
    {
        var container = $("#" + this._containerElementID);
        if (value == null)
        {
            container.text("-");
            return;
        }

        value = value.toFixed(2);
        var stringValue = value + "";
        //Для удобного показа
        stringValue = stringValue.replace(".", ",");
        container.text(stringValue);
    },
    get_value: function()
    {
        //Сделано специально, чтобы value было свойством (тогда его можно инициализировать через Asp.net ajax)
        return null;
    },

    set_tooltip: function(value)
    {
        this.tooltip = value;
        var container = $("#" + this._containerElementID);
        container.attr("title", value);
    },
    get_tooltip: function() { return this.tooltip; },
    
    set_isSelected: function(value)
    {
        var container = $("#" + this._containerElementID);
        if (value) container.addClass("sel");
        else container.removeClass("sel");
    },
    get_isSelected: function()
    {
        var container = $("#" + this._containerElementID);
        return container.hasClass("sel");
    }
};

// JSON object that describes all properties, events, and methods of this component that should
// be addressable through the Sys.TypeDescriptor methods, and addressable via xml-script.
IndicatorBR.descriptor = {
properties: [
    { name: 'containerElementID', type: String },
    { name: 'tooltip', type: String },
    { name: 'value', type: Object }, 
    { name: 'isSelected', type:Boolean}]
};
IndicatorBR.registerClass('IndicatorBR', Sys.Component);

// Since this script is not loaded by System.Web.Handlers.ScriptResourceHandler
// invoke Sys.Application.notifyScriptLoaded to notify ScriptManager 
// that this is the end of the script.
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
