﻿if (!SIGI) throw ("SIGI.ComboBox depends on the following scripts. Please make sure these are included.\nSIGI.js");

// === SIGI.RadioButton === //
SIGI.RadioButton = function() {
    this._initialDisplay = "";
};
SIGI.RadioButton.inherits(SIGI.UI.Control);

SIGI.RadioButton.prototype.get_text = function() {
    return this.get_element()._label.innerHTML;
};
SIGI.RadioButton.prototype.set_text = function(pValue) {
    this.get_element()._label.innerHTML = pValue;
};
SIGI.RadioButton.prototype.get_value = function() {
    return this.get_element().value;
};
SIGI.RadioButton.prototype.set_value = function(pValue) {
    return this.get_element().value = pValue;
};
SIGI.RadioButton.prototype.get_checked = function() {
    return this.get_element().checked;
};
SIGI.RadioButton.prototype.set_checked = function(pValue) {
    this.get_element().checked = pValue;
};
SIGI.RadioButton.prototype.get_groupName = function() {
    return this.get_element().getAttribute("name");
};
SIGI.RadioButton.prototype.get_group = function() {
    return this._group;
};
SIGI.RadioButton.prototype.get_enabled = function() {
    return !this.get_element().disabled;
};
SIGI.RadioButton.prototype.set_enabled = function(pValue) {
    SIGI.changeState(this.get_element(), !pValue);
    if (this.get_element()._label != null)
        this.get_element()._label.disabled = !pValue;
    if (this.get_element().simpleValidator) {
        //document.getElementById(this.get_element().simpleValidator).style.display = this.get_element().style.display;
        document.getElementById(this.get_element().simpleValidator).style.display = "none";
    }
};
SIGI.RadioButton.prototype.get_toolTip = function() {
    return this.get_element().getAttribute("tooltip");
};
SIGI.RadioButton.prototype.set_toolTip = function(pValue) {
    this.get_element().setAttribute("tooltip", pValue);
};
SIGI.RadioButton.prototype.get_statusText = function() {
    return this.get_element().getAttribute("statustext");
};
SIGI.RadioButton.prototype.set_statusText = function(pValue) {
    this.get_element().setAttribute("statustext", pValue);
};
SIGI.RadioButton.prototype.get_visible = function() {
    if (this.get_element().style.display == "none")
        return false;
    else
        return true;
};
SIGI.RadioButton.prototype.set_visible = function(pValue) {
    if (pValue) {
        if (this._initialDisplay.toLowerCase() == "none") {
            this.get_element().style.display = "block";
        }
        else {
            this.get_element().style.display = this._initialDisplay;
        }
    }
    else {
        this.get_element().style.display = "none";
    }
    if (this.get_element().simpleValidator) {
        //document.getElementById(this.get_element().simpleValidator).style.display = this.get_element().style.display;
        document.getElementById(this.get_element().simpleValidator).style.display = "none";
    }
    if (this.get_element().label) {
        if (SIGI.Validation.hideLabelWithElement(this.get_element())) {
            try {
                this.get_element().label.style.display = this.get_element().style.display;
                this.get_element().label.className = "FormLabel";
            }
            catch (e) {
                document.getElementById(this.get_element().label).style.display = this.get_element().style.display;
                document.getElementById(this.get_element().label).className = "FormLabel";
            } 
        }
    }
};
SIGI.RadioButton.prototype.focus = function() {
    SIGI.setFocus(this.get_element());
};


// === SIGI.RadioButtonGroup === //
SIGI.RadioButtonGroup = function(id) {
    this.id = id;
    this._initialDisplay = "";
    this._items = new SIGI.CollectionObject();
};
SIGI.RadioButtonGroup.inherits(SIGI.UI.Control);

SIGI.RadioButtonGroup.prototype.get_value = function() {
    for (var i = 0; i < this._items.count(); i++) {
        if (this._items[i].get_checked())
            return this._items[i].get_value();
    }
};
SIGI.RadioButtonGroup.prototype.set_value = function(pValue) {
    for (var i = 0; i < this._items.count(); i++) {
        if (this._items[i].get_value().toLowerCase() == pValue.toLowerCase())
            this._items[i].set_checked(true);
         else
             this._items[i].set_checked(false);
    }
};

SIGI.RadioButtonGroup.prototype.set_enabled = function(pValue) {
    for (var i = 0; i < this._items.count(); i++) {
        this._items[i].set_enabled(pValue);
    }
};
SIGI.RadioButtonGroup.prototype.set_visible = function(pValue) {
    for (var i = 0; i < this._items.count(); i++) {
        this._items[i].set_visible(pValue);
    }
};
SIGI.RadioButtonGroup.prototype.initialize = function() {
    this.id = this.get_element().id;
};

SIGI.RadioButton.prototype.initialize = function() {
    this._initialDisplay = this.get_element().style.display;
    this.get_element()._label = document.getElementById(this._id + "_Label")
    if (!$SIGIfind(this.get_groupName()))
        $SIGIcreate(SIGI.RadioButtonGroup, null, null, null, new SIGI.RadioButtonGroup(this.get_groupName()));
    this._group = $SIGIfind(this.get_groupName());
    this._group._items.add(this);
};
