﻿if (!SIGI) throw ("SIGI.ComboBox depends on the following scripts. Please make sure these are included.\nSIGI.js");

// === classes ===
SIGI.TextArea = function() {
    this._initialDisplay = "";
};
SIGI.TextArea.inherits(SIGI.UI.Control);

SIGI.TextArea.prototype.get_text = function() {
    return this.get_element().value;
};
SIGI.TextArea.prototype.set_text = function(pValue) {
    this.get_element().value = pValue;
};
SIGI.TextArea.prototype.get_maxLength = function() {
    var iReturn = this.get_element().getAttribute("maxlength");
    if (!iReturn)
        iReturn = -1;
    return SIGI.Convert.toInteger(iReturn);
};
SIGI.TextArea.prototype.set_maxLength = function(pValue) {
    if (SIGI.Convert.toInteger(pValue) > 0) {
        pValue = SIGI.Convert.toInteger(pValue) + 1;
    }
    this.get_element().setAttribute("maxlength", pValue)
    this.get_element().setAttribute("maxlen", pValue)
};
SIGI.TextArea.prototype.get_enabled = function() {
    return !this.get_element().disabled;
};
SIGI.TextArea.prototype.set_enabled = function(pValue) {
    SIGI.changeState(this.get_element(), !pValue);
};
SIGI.TextArea.prototype.get_allowKeys = function() {
    return this.get_element().getAttribute("allowKeys");
};
SIGI.TextArea.prototype.set_allowKeys = function(pValue) {
    this.get_element().setAttribute("allowKeys", pValue)
};
SIGI.TextArea.prototype.get_toolTip = function() {
    return this.get_element().getAttribute("tooltip");
};
SIGI.TextArea.prototype.set_toolTip = function(pValue) {
    this.get_element().setAttribute("tooltip", pValue);
};
SIGI.TextArea.prototype.get_statusText = function() {
    return this.get_element().getAttribute("statustext");
};
SIGI.TextArea.prototype.set_statusText = function(pValue) {
    this.get_element().setAttribute("statustext", pValue);
};
SIGI.TextArea.prototype.get_visible = function() {
    return this.get_element().getAttribute("helpID");
};
SIGI.TextArea.prototype.set_visible = function(pValue) {
    if (pValue)
        this.get_element().style.display = this._initialDisplay;
    else
        this.get_element().style.display = "none";
};
SIGI.TextArea.prototype._enforceMaxLength = function(e) {
    if ((ie) && (document)) document.execCommand("OverWrite", false, true);
    var keychar

    if (e.keyCode)
        keychar = e.keyCode;
    else
        keychar = e.which;
    //debugger;
    if ((this.get_maxLength() > 0) && (this.get_element().value.length > (this.get_maxLength() - 1)) && (keychar != 8) && (keychar != 46)) {

        if (e.preventDefault) e.preventDefault();
        if (e.stopPropagation) e.stopPropagation();

        if (ie) e.keyCode = 0;
        e.returnValue = false;
        e.cancelBubble = true;
    }

};
SIGI.TextArea.prototype.focus = function() {
    SIGI.setFocus(this.get_element());
};
SIGI.TextArea.prototype.initialize = function() {
    this._initialDisplay = this.get_element().style.display;
    this.set_maxLength(this.get_maxLength());

    SIGI.attachEvent(this.get_element(), "onkeypress", this.context(this._enforceMaxLength));

};
