
function Numeric2Hex(num,digit)
{
    if (typeof num === 'undefined' || num === null || !IsNumeric(num))
        return '';
    if (typeof digit === 'undefined' || digit === null || !IsInt(digit) || digit <= 0)
        return '';
    var i,tmp = num,r,hex = '';
    for (i = 0;i < digit;i++)
    {
        r = tmp%16;
        tmp = Math.floor(tmp/16);
        switch(r)
        {
            case 10:
                r = 'A';
                break;
            case 11:
                r = 'B';
                break;
            case 12:
                r = 'C';
                break;
            case 13:
                r = 'D';
                break;
            case 14:
                r = 'E';
                break;
            case 15:
                r = 'F';
                break;
            default:
                r = r.toString();
        }
        hex = r + hex;
    }
    return hex;
}

function Hex2Numeric(hex)
{
    if (typeof hex === 'undefined' || hex === null)
        return null;
    var i,n = hex.length,pow = 1,result = 0;
    if (n <= 0)
        return null;
    for (i = n-1;i >= 0;i--)
    {
        if (IsInt(hex[i]))
            result = result + pow*hex[i];
        else
        {
            switch(hex[i])
            {
                case 'A':
                case 'a':
                    result = result + pow*10;
                    break;
                case 'B':
                case 'b':
                    result = result + pow*11;
                    break;
                case 'C':
                case 'c':
                    result = result + pow*12;
                    break;
                case 'D':
                case 'd':
                    result = result + pow*13;
                    break;
                case 'E':
                case 'e':
                    result = result + pow*14;
                    break;
                case 'F':
                case 'f':
                    result = result + pow*15;
                    break;
                default: 
                    return null;
            }
        }
        pow = pow*16;
    }
    return result;
}

function TableImageMonochrome2Binary(img)
{
    if (typeof img !== 'undefined' && img !== null)
    {
        var img2 = [];
        var i,j,k,n = img.length;
        for (i = 0;i < n;i++)
        {
            img2[i] = [];
            for(j = 0;j < img[i].length;j++)
            {
                if ((img[i][j] & 128) === 0)
                    img2[i][8*j] = 0;
                else
                    img2[i][8*j] = 1;
                if ((img[i][j] & 64) === 0)
                    img2[i][8*j + 1] = 0;
                else
                    img2[i][8*j + 1] = 1;
                if ((img[i][j] & 32) === 0)
                    img2[i][8*j + 2] = 0;
                else
                    img2[i][8*j + 2] = 1;
                if ((img[i][j] & 16) === 0)
                    img2[i][8*j + 3] = 0;
                else
                    img2[i][8*j + 3] = 1;
                if ((img[i][j] & 8) === 0)
                    img2[i][8*j + 4] = 0;
                else
                    img2[i][8*j + 4] = 1;
                if ((img[i][j] & 4) === 0)
                    img2[i][8*j + 5] = 0;
                else
                    img2[i][8*j + 5] = 1;
                if ((img[i][j] & 2) === 0)
                    img2[i][8*j + 6] = 0;
                else
                    img2[i][8*j + 6] = 1;
                if ((img[i][j] & 1) === 0)
                    img2[i][8*j + 7] = 0;
                else
                    img2[i][8*j + 7] = 1;
            }
        }
        return img2;
    }
    return img;
}

function TTableShow(){
    var type = 'TTableShow';
    TTableShow.prototype.InitConstructor = function(){
        TPageElement.prototype.InitConstructor.call(this);
        this.SetType(type);
        this.lineStyle = 'noLine';
        this.tableTXT = null;
        this.varTable = null;
        this.colourProfile = null;
        this.minColourTXT = null;
        this.maxColourTXT = null;
        this.minColourTextTXT = null;
        this.maxColourTextTXT = null;
        this.colourBand = 1;
        this.colourBandType = null;
        this.widthCell = null;
        this.heightCell = null;
        this.widthTeXCell = null;
        this.heightTeXCell = null;
        this.alignTextX = 'center';
        this.alignTextY = 'center';
        this.minValue = null;
        this.maxValue = null;
        this.lineWidth = null;
        this.hex = false;
        this.hexDigit = 2;
        this.colourMap = [];
        this.colourMapMin = [];
        this.colourMapMax = [];
        this.alignX = 'center';
        this.alignY = 'center';
        this.textSize = null;
        this.fontStyle = null;
        this.font = null;
    };
    this.InitConstructor();

    TTableShow.prototype.Init = function(_object){
        TPageElement.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TTableShow'))
        {
            var i;
            if (typeof _object.lineStyle !== 'undefined' && _object.lineStyle !== null)
            {
                this.lineStyle = new String(_object.lineStyle);
                if (this.lineStyle !== null)
                    this.lineStyle = this.lineStyle.toString();
            }
            if (typeof _object.tableTXT !== 'undefined' && _object.tableTXT !== null)
            {
                this.tableTXT = new String(_object.tableTXT);
                if (this.tableTXT !== null)
                    this.tableTXT = this.tableTXT.toString();
            }
            if (typeof _object.varTable !== 'undefined' && _object.varTable !== null && _object.varTable.IsType('TVariableVoidTXT'))
                this.varTable = objM.copy(_object.varTable);
            if (typeof _object.colourProfile !== 'undefined' && _object.colourProfile !== null)
            {
                this.colourProfile = new String(_object.colourProfile);
                if (this.colourProfile !== null)
                    this.colourProfile = this.colourProfile.toString();
            }
            if (typeof _object.minColourTXT !== 'undefined' && _object.minColourTXT !== null && _object.minColourTXT.IsType('TColourTXT'))
                this.minColourTXT = objM.copy(_object.minColourTXT);
            if (typeof _object.maxColourTXT !== 'undefined' && _object.maxColourTXT !== null && _object.maxColourTXT.IsType('TColourTXT'))
                this.maxColourTXT = objM.copy(_object.maxColourTXT);
            if (typeof _object.minColourTextTXT !== 'undefined' && _object.minColourTextTXT !== null && _object.minColourTextTXT.IsType('TColourTXT'))
                this.minColourTextTXT = objM.copy(_object.minColourTextTXT);
            if (typeof _object.maxColourTextTXT !== 'undefined' && _object.maxColourTextTXT !== null && _object.maxColourTextTXT.IsType('TColourTXT'))
                this.maxColourTextTXT = objM.copy(_object.maxColourTextTXT);
            if (typeof _object.colourBand !== 'undefined' && _object.colourBand !== null && IsInt(_object.colourBand))
                this.colourBand = _object.colourBand;
            if (typeof _object.colourBandType !== 'undefined' && _object.colourBandType !== null)
            {
                this.colourBandType = new String(_object.colourBandType);
                if (this.colourBandType !== null)
                    this.colourBandType = this.colourBandType.toString();
            }
            if (typeof _object.widthCell !== 'undefined' && _object.widthCell !== null && IsNumeric(_object.widthCell))
                this.widthCell = _object.widthCell;
            if (typeof _object.heightCell !== 'undefined' && _object.heightCell !== null && IsNumeric(_object.heightCell))
                this.heightCell = _object.heightCell;
            if (typeof _object.widthTeXCell !== 'undefined' && _object.widthTeXCell !== null && IsNumeric(_object.widthTeXCell))
                this.widthTeXCell = _object.widthTeXCell;
            if (typeof _object.heightTeXCell !== 'undefined' && _object.heightTeXCell !== null && IsNumeric(_object.heightTeXCell))
                this.heightTeXCell = _object.heightTeXCell;
            if (typeof _object.alignTextX !== 'undefined' && _object.alignTextX !== null)
            {
                this.alignTextX = new String(_object.alignTextX);
                if (this.alignTextX !== null)
                    this.alignTextX = this.alignTextX.toString();
            }
            if (typeof _object.alignTextY !== 'undefined' && _object.alignTextY !== null)
            {
                this.alignTextY = new String(_object.alignTextY);
                if (this.alignTextY !== null)
                    this.alignTextY = this.alignTextY.toString();
            }
            if (typeof _object.minValue !== 'undefined' && _object.minValue !== null && IsNumeric(_object.minValue))
                this.minValue = _object.minValue;
            if (typeof _object.maxValue !== 'undefined' && _object.maxValue !== null && IsNumeric(_object.maxValue))
                this.maxValue = _object.maxValue;
            if (typeof _object.lineWidth !== 'undefined' && _object.lineWidth !== null && IsNumeric(_object.lineWidth))
                this.lineWidth = _object.lineWidth;
            if (typeof _object.hex !== 'undefined' && _object.hex !== null)
                this.hex = _object.hex;
            if (typeof _object.hexDigit !== 'undefined' && _object.hexDigit !== null && IsInt(_object.hexDigit))
                this.hexDigit = _object.hexDigit;
            if (typeof _object.colourMap !== 'undefined' && _object.colourMap !== null)
            {
                for (i = 0;i < _object.colourMap.length;i++)
                    this.colourMap[i] = objM.copy(_object.colourMap[i]);
            }
            if (typeof _object.colourMapMin !== 'undefined' && _object.colourMapMin !== null)
            {
                for (i = 0;i < _object.colourMapMin.length;i++)
                    this.colourMapMin[i] = _object.colourMapMin[i];
            }
            if (typeof _object.colourMapMax !== 'undefined' && _object.colourMapMax !== null)
            {
                for (i = 0;i < _object.colourMapMax.length;i++)
                    this.colourMapMax[i] = _object.colourMapMax[i];
            }
            if (typeof _object.alignX !== 'undefined' && _object.alignX !== null)
            {
                this.alignX = new String(_object.alignX);
                if (this.alignX !== null)
                    this.alignX = this.alignX.toString();
            }
            if (typeof _object.alignY !== 'undefined' && _object.alignY !== null)
            {
                this.alignY = new String(_object.alignY);
                if (this.alignY !== null)
                    this.alignY = this.alignY.toString();
            }
            if (typeof _object.textSize !== 'undefined' && _object.textSize !== null && IsNumeric(_object.textSize))
                this.textSize = _object.textSize;
            if (typeof _object.fontStyle !== 'undefined' && _object.fontStyle !== null)
            {
                this.fontStyle = new String(_object.fontStyle);
                if (this.fontStyle !== null)
                    this.fontStyle = this.fontStyle.toString();
            }
            if (typeof _object.font !== 'undefined' && _object.font !== null)
            {
                this.font = new String(_object.font);
                if (this.font !== null)
                    this.font = this.font.toString();
            }
        }
    };

    TTableShow.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TPageElement.prototype.IsType.call(this,_type);
    };
    

    TTableShow.prototype.ReadXML = function(tag,fun){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof tag !== 'undefined' && tag !== null)
        {
            var attr = null;
            this.ReadXMLInit(tag);
            this.SetLineStyle(tag.getAttribute('lineStyle'));
            this.SetTableTXT(tag.getAttribute('table'));
            this.SetWidthCell(tag.getAttribute('widthCell'));
            this.SetHeightCell(tag.getAttribute('heightCell'));
            this.SetWidthTeXCell(tag.getAttribute('widthTeXCell'));
            this.SetHeightTeXCell(tag.getAttribute('heightTeXCell'));
            this.SetMinValue(tag.getAttribute('min'));
            this.SetMaxValue(tag.getAttribute('max'));
            this.SetAlignTextX(tag.getAttribute('alignTextX'));
            this.SetAlignTextY(tag.getAttribute('alignTextY'));
            this.SetAlignX(tag.getAttribute('alignX'));
            this.SetAlignY(tag.getAttribute('alignY'));
            this.SetLineWidth(tag.getAttribute('lineWidth'));
            this.SetColourProfile(tag.getAttribute('colourProfile'));
            this.SetTextSize(tag.getAttribute('sizeText'));
            this.SetFontStyle(tag.getAttribute('fontStyle'));
            this.SetFont(tag.getAttribute('font'));
            attr = tag.getAttribute('hex');
            if (attr !== 'undefined' && attr !== null)
                if (attr === 'Yes' || attr === 'yes')
                    this.SetHex(true);
            this.SetHexDigit(tag.getAttribute('hexDigit'));
            attr = tag.getAttribute('name');
            if (attr !== 'undefined' && attr !== null)
            {
                var data = null,tmp = this.FindVariable(attr);
                if (typeof tmp !== 'undefined' && tmp !== null && tmp.IsType('TVariableVoidTXT'))
                    data = tmp.GetValue();
                if (tmp !== null && data !== null)
                {
                    this.varTable = tmp;
//                    this.varTable.SetValue(this.CalculateValue(data));
//                    this.varTable.SetEquation(data);
                    this.varTable.ReadXML(tag);
                } 

                
/*                this.varTable = objM.newObject('TVariableVoidTXT');
                if (this.varTable !== null)
                {
                    this.varTable.ReadXML(tag,fun);
                    this.SetVariable(this.varTable);
                }*/
                
            }
            var x = tag.childNodes,i;
            var j = 0;
            this.colourMap = [];this.colourMapMax = [];this.colourMapMin = [];
            for (i = 0;i < x.length;i++)
            {
                if (x[i].nodeType === 1)
                {
                    if (x[i].nodeName === 'ColourMin')
                    {
                        if (this.minColourTXT === null)
                            this.minColourTXT = objM.newObject('TColourTXT');
                        if (this.minColourTXT !== null)
                            this.minColourTXT.ReadXML(x[i]);
                    }
                    if (x[i].nodeName === 'ColourMax')
                    {
                        if (this.maxColourTXT === null)
                            this.maxColourTXT = objM.newObject('TColourTXT');
                        if (this.maxColourTXT !== null)
                            this.maxColourTXT.ReadXML(x[i]);
                    }
                    if (x[i].nodeName === 'ColourMinText')
                    {
                        if (this.minColourTextTXT === null)
                            this.minColourTextTXT = objM.newObject('TColourTXT');
                        if (this.minColourTextTXT !== null)
                            this.minColourTextTXT.ReadXML(x[i]);
                    }
                    if (x[i].nodeName === 'ColourMaxText')
                    {
                        if (this.maxColourTextTXT === null)
                            this.maxColourTextTXT = objM.newObject('TColourTXT');
                        if (this.maxColourTextTXT !== null)
                            this.maxColourTextTXT.ReadXML(x[i]);
                    }
                    if (x[i].nodeName === 'Colour')
                    {
                        this.colourMap[j] = objM.newObject('TColourTXT');
                        if (this.colourMap[j] !== null)
                            this.colourMap[j].ReadXML(x[i]);
                        this.SetColourMapMin(j,x[i].getAttribute('min'));
                        this.SetColourMapMax(j++,x[i].getAttribute('max'));
                    }
                    
                }   
            }
        }
    };

    TTableShow.prototype.SetLineStyle = function(style){
        if (typeof style !== 'undefined' && style !== null)
        {
            this.lineStyle = new String(style);
            if (this.lineStyle !== null)
                this.lineStyle = this.lineStyle.toString();
        }
    };

    TTableShow.prototype.GetLineStyle = function(){
        if (typeof this.lineStyle !== 'undefined' && this.lineStyle !== null)
        {
            var tmp = new String(this.lineStyle);
            if (tmp !== null)
                return tmp.toString();
            return tmp;
        }
        return null;
    };

    TTableShow.prototype.SetTableTXT = function(txt){
        if (typeof txt !== 'undefined' && txt !== null)
        {
            this.tableTXT = new String(txt);
            if (this.tableTXT !== null)
                this.tableTXT = this.tableTXT.toString();
        }
    };

    TTableShow.prototype.GetTableTXT = function(){
        if (typeof this.tableTXT !== 'undefined' && this.tableTXT !== null)
        {
            var tmp = new String(this.tableTXT);
            if (tmp !== null)
                return tmp.toString();
            return tmp;
        }
        return null;
    };

    TTableShow.prototype.SetWidthCell = function(w){
        if (typeof w !== 'undefined' && w !== null && IsNumeric(w))
            this.widthCell = w;
        if (w === null)
            this.widthCell = null;
    };

    TTableShow.prototype.GetWidthCell = function(){
        return this.widthCell;
    };

    TTableShow.prototype.SetHeightCell = function(h){
        if (typeof h !== 'undefined' && h !== null && IsNumeric(h))
            this.heightCell = h;
        if (h === null)
            this.heightCell = null;
    };

    TTableShow.prototype.GetHeightCell = function(){
        return this.heightCell;
    };

    TTableShow.prototype.SetWidthTeXCell = function(w){
        if (typeof w !== 'undefined' && w !== null && IsNumeric(w))
            this.widthTeXCell = w;
        if (w === null)
            this.widthTeXCell = null;
    };

    TTableShow.prototype.GetWidthTeXCell = function(){
        return this.widthTeXCell;
    };

    TTableShow.prototype.SetHeightTeXCell = function(h){
        if (typeof h !== 'undefined' && h !== null && IsNumeric(h))
            this.heightTeXCell = h;
        if (h === null)
            this.heightTeXCell = null;
    };

    TTableShow.prototype.GetHeightTeXCell = function(){
        return this.heightTeXCell;
    };

    TTableShow.prototype.Draw = function(_object){
        if (typeof _object !== 'undefined' && _object !== null && _object.IsType('TGenerateObject'))
        {
            var tmp2 = [],id = this.GetId();
            if (id !== null)
            {
                tmp2[0] = id;
                var tab;
                if (this.varTable === null)
                {
                    tab = this.CalculateValue(this.tableTXT);
                }else
                {
                    tab = this.CalculateValue(this.varTable.GetValue());                    
                }
                if (this.hex === true && tab !== 'undefined' && tab !== null)
                {
                    var i, j,tab_tmp = [];
                    for (i = 0;i < tab.length;i++)
                    {
                        tab_tmp[i] = [];
                        for (j = 0;j < tab[i].length;j++)
                            tab_tmp[i][j] = Numeric2Hex(tab[i][j],this.hexDigit);
                    }
                    tmp2[1] = tab_tmp;
                }else
                    tmp2[1] = tab;
                tmp2[2] = this.GetClassStyle();
                tmp2[3] = this.lineStyle;
                tmp2[4] = this.widthCell;
                tmp2[5] = this.heightCell;
                if (this.minColourTXT === null)
                    tmp2[6] = null;
                else
                    tmp2[6] = this.minColourTXT.GetColour(this.GetObjectVariables());
                if (this.maxColourTXT === null)
                    tmp2[7] = null;
                else
                    tmp2[7] = this.maxColourTXT.GetColour(this.GetObjectVariables());
                tmp2[8] = this.minValue;
                tmp2[9] = this.maxValue;
                if (this.minColourTextTXT === null)
                    tmp2[10] = null;
                else
                    tmp2[10] = this.minColourTextTXT.GetColour(this.GetObjectVariables());
                if (this.maxColourTextTXT === null)
                    tmp2[11] = null;
                else
                    tmp2[11] = this.maxColourTextTXT.GetColour(this.GetObjectVariables());
                tmp2[12] = this.alignTextX;
                tmp2[13] = this.alignTextY;
                tmp2[14] = this.lineWidth;
                tmp2[15] = this.hex;
                tmp2[16] = this.colourProfile;
                tmp2[17] = this.GetColourMap();
                tmp2[18] = this.colourMapMin;
                tmp2[19] = this.colourMapMax;
                tmp2[20] = this.widthTeXCell;
                tmp2[21] = this.heightTeXCell;
                tmp2[22] = this.GetTextSize();
                tmp2[23] = this.GetFontStyle();
                tmp2[24] = this.GetFont();

/*                tmp2[0] = this.GetWidth();
                tmp2[1] = this.GetHeight();
                tmp2[2] = this.GetFigures();
                tmp2[3] = this.GetXMax()-this.GetXMin();
                tmp2[4] = this.GetYMax()-this.GetYMin();
                tmp2[5] = 1;
                tmp2[6] = this.GetXMin();
                tmp2[7] = this.GetYMin();
                tmp2[8] = 0;
                tmp2[9] = this.generate;
                tmp2[10] = this.scaleTikZ;
                tmp2[11] = this.scale;
                tmp2[12] = this.GetAlignX();*/
                _object.Add('TableShow','',tmp2);
            }
        }
    };

    TTableShow.prototype.SetMinValue = function(v){
        if (typeof v !== 'undefined' && v !== null && IsNumeric(v))
            this.minValue = v;
        if (v === null)
            this.minValue = null;
    };

    TTableShow.prototype.GetMinValue = function(){
        return this.minValue;
    };

    TTableShow.prototype.SetMaxValue = function(v){
        if (typeof v !== 'undefined' && v !== null && IsNumeric(v))
            this.maxValue = v;
        if (v === null)
            this.maxValue = null;
    };

    TTableShow.prototype.GetMaxValue = function(){
        return this.maxValue;
    };

    TTableShow.prototype.SetAlignTextX = function(align){
        if (typeof align !== 'undefined' && align !== null)
        {
            this.alignTextX = new String(align);
            if (this.alignTextX !== null)
                this.alignTextX = this.alignTextX.toString();
        }
    };

    TTableShow.prototype.GetAlignTextX = function(){
        if (typeof this.alignTextX !== 'undefined' && this.alignTextX !== null)
        {
            var tmp = new String(this.alignTextX);
            if (tmp !== null)
                return tmp.toString();
            return tmp;
        }
        return null;
    };

    TTableShow.prototype.SetAlignTextY = function(align){
        if (typeof align !== 'undefined' && align !== null)
        {
            this.alignTextY = new String(align);
            if (this.alignTextY !== null)
                this.alignTextY = this.alignTextY.toString();
        }
    };

    TTableShow.prototype.GetAlignTextY = function(){
        if (typeof this.alignTextY !== 'undefined' && this.alignTextY !== null)
        {
            var tmp = new String(this.alignTextY);
            if (tmp !== null)
                return tmp.toString();
            return tmp;
        }
        return null;
    };

    TTableShow.prototype.SetLineWidth = function(width){
        if (typeof width !== 'undefined' && width !== null && IsNumeric(width))
            this.lineWidth = width;
        if (width === null)
            this.lineWidth = null;
    };

    TTableShow.prototype.GetLineWidth = function(){
        return this.lineWidth;
    };

    TTableShow.prototype.SetHex = function(h){
        if (typeof h !== 'undefined' && h !== null)
            this.hex = h;
    };

    TTableShow.prototype.GetHex = function(){
        return this.hex;
    };

    TTableShow.prototype.SetHexDigit = function(d){
        if (typeof d !== 'undefined' && d !== null && IsInt(d))
            this.hexDigit = d;
    };

    TTableShow.prototype.GetHexDigit = function(){
        return this.hexDigit;
    };

    TTableShow.prototype.GetColourText = function(weight){
        if (typeof weight !== 'undefined' && weight !== null && IsNumeric(weight))
        {
            if (this.minColourTextTXT !== null && this.maxColourTextTXT !== null)
            {
                var col1 = this.minColourTextTXT.GetColour(this.GetObjectVariables());
                var col2 = this.maxColourTextTXT.GetColour(this.GetObjectVariables());
                if (col1 !== null && col2 !== null)
                {
                    if (weight >= 0.5)
                        return col2;
                    else
                        return col1;
                }
            }
        }
        return null;
    };

    TTableShow.prototype.GetColourBackground = function(weight){
        if (typeof weight !== 'undefined' && weight !== null && IsNumeric(weight))
        {
            if (this.minColourTXT !== null && this.maxColourTXT !== null)
            {
                var col1 = this.minColourTXT.GetColour(this.GetObjectVariables());
                var col2 = this.maxColourTXT.GetColour(this.GetObjectVariables());
                if (col1 !== null && col2 !== null)
                {
                    return col2.MeanColour(weight,col1);
                }
            }
        }
        return null;
    };

    TTableShow.prototype.GetVarTable = function(){
        return this.varTable;
    };
    
    TTableShow.prototype.Refresh = function(){
        var id_ = this.GetId();
        var tmp_tab = null;
        if (typeof id_ !== 'undefined' && id_ !== null)
        {
            if (this.varTable  !== null)
            {
                var txt = this.varTable.GetValue();
                tmp_tab = this.CalculateValue(txt);
            }else
            {
                if (this.tableTXT !== null)
                {
                    tmp_tab = this.CalculateValue(this.tableTXT);
                }
                if (typeof tmp_tab !== 'undefined' && tmp_tab !== null)
                {
                    var i,j, n = tmp_tab.length;
                    var id2,obj;
                    var tmpValue,colourTmp2;
                    var mincolour = null,maxcolour = null,colourTmp;
                    if (this.minColourTXT !== null)
                        mincolour = this.minColourTXT.GetColour(this.GetObjectVariables());
                    if (this.maxColourTXT !== null)
                        maxcolour = this.maxColourTXT.GetColour(this.GetObjectVariables());
                    var minTextcolour = null,maxTextcolour = null;
                    if (this.minColourTextTXT !== null)
                        minTextcolour = this.minColourTextTXT.GetColour(this.GetObjectVariables());
                    if (this.maxColourTextTXT !== null)
                        maxTextcolour = this.maxColourTextTXT.GetColour(this.GetObjectVariables());
                    for (i = 0;i < n;i++)
                    {
                        for (j = 0;j < tmp_tab[i].length;j++)
                        {
                            id2 = id_ + '_' + i + '_' + j;
                            obj = document.getElementById(id2);
                            colourTmp = null;
                            if (typeof obj !== 'undefined' && obj !== null)
                            {
                                obj.innerHTML = tmp_tab[i][j];
                                var k,colourMap = this.GetColourMap();
                                var tmp_tab_val;
//                                    if (this.GetHex())
//                                        tmp_tab_val = Hex2Numeric(tmp_tab[i][j]);
//                                    else
                                    tmp_tab_val = tmp_tab[i][j];
                                if (this.minValue !== null && this.maxValue !== null)
                                {
                                    tmpValue = (tmp_tab_val - this.minValue)/(this.maxValue - this.minValue);
                                    if (mincolour !== null && maxcolour !== null)
                                    {
                                        colourTmp = maxcolour.MeanColour(tmpValue,mincolour);
                                    }
                                }
                                if (colourMap !== null)
                                {
                                    for (k = 0;k < colourMap.length;k++)
                                    {
                                        if (tmp_tab_val >= this.GetColourMapMin(k) && tmp_tab_val <= this.GetColourMapMax(k))
                                        {
                                            colourTmp = colourMap[k];
                                            break;
                                        }
                                    }
                                }
                                if (colourTmp !== null)
                                    obj.style.backgroundColor = '#' + colourTmp.Get24bitColourHex();
                                if (minTextcolour !== null && maxTextcolour !== null)
                                {
                                    if (tmpValue >= 0.5)
                                        colourTmp2 = maxTextcolour;
                                    else
                                        colourTmp2 = minTextcolour;
                                    if (colourTmp2 !== null)
                                        obj.style.color = '#' + colourTmp2.Get24bitColourHex();
                                }
                                
                            }
                        }
                    }
                }
            }
        }
    };    

    TTableShow.prototype.SetColourProfile = function(profile){
        if (typeof profile !== 'undefined' && profile !== null)
        {
            this.colourProfile = profile;
            switch(profile)
            {
                case 'colour24bit':
                    this.SetHex(true);
                    this.SetHexDigit(6);
                    break;
            }
        }
        if (profile === null)
            this.colourProfile = null;
    };

    TTableShow.prototype.GetColourProfile = function(){
        return this.colourProfile;
    };

    
    TTableShow.prototype.SetColourMapElement = function(position,colour){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof position !== 'undefined' && position !== null && IsInt(position) && position >= 0)
        {
            if (colour !== null && colour !== null && colour.IsType('TColourTXT'))
            {
                this.colourMap[position] = objM.copy(colour);
            }
            if (colour === null)
                this.colourMap[position] = null;
        }
    };

    TTableShow.prototype.GetColourMapElement = function(position){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof position !== 'undefined' && position !== null && IsInt(position) && position >= 0 && position < this.colourMap.length)
        {
            if (typeof this.colourMap[position] !== 'undefined' && this.colourMap[position] !== null)
            {
                return this.colourMap[position].GetColour(this.GetObjectVariables());
            }
        }
        return null;
    };

    TTableShow.prototype.SetColourMapMin = function(position,min_){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof position !== 'undefined' && position !== null && IsInt(position) && position >= 0)
        {
            if (typeof min_ !== 'undefined' && min_ !== null && IsNumeric(min_))
            {
                this.colourMapMin[position] = min_;
            }
            if (min_ === null)
                this.colourMapMin[position] = null;
        }
    };

    TTableShow.prototype.GetColourMapMin = function(position){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof position !== 'undefined' && position !== null && IsInt(position) && position >= 0 && position < this.colourMapMin.length)
        {
            if (typeof this.colourMapMin[position] !== 'undefined' && this.colourMapMin[position] !== null)
            {
                return this.colourMapMin[position];
            }
        }
        return null;
    };

    TTableShow.prototype.SetColourMapMax = function(position,max_){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof position !== 'undefined' && position !== null && IsInt(position) && position >= 0)
        {
            if (typeof max_ !== 'undefined' && max_ !== null && IsNumeric(max_))
            {
                this.colourMapMax[position] = max_;
            }
            if (max_ === null)
                this.colourMapMax[position] = null;
        }
    };

    TTableShow.prototype.GetColourMapMax = function(position){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof position !== 'undefined' && position !== null && IsInt(position) && position >= 0 && position < this.colourMapMax.length)
        {
            if (typeof this.colourMapMax[position] !== 'undefined' && this.colourMapMax[position] !== null)
            {
                return this.colourMapMax[position];
            }
        }
        return null;
    };

    TTableShow.prototype.GetColourMap = function(){
        var i,tmp = [];
        for (i = 0;i < this.colourMap.length;i++)
        {
            if (typeof this.colourMap[i] !== 'undefined' && this.colourMap[i] !== null)
                tmp[i] = this.colourMap[i].GetColour(this.GetObjectVariables());
            else
                tmp[i] = null;
        }
        return tmp;
    };

    TTableShow.prototype.GetTable = function(){
        if (this.varTable === null)
        {
            return this.CalculateValue(this.tableTXT);
        }else
        {
            return this.CalculateValue(this.varTable.GetValue());                    
        }
    };

    TTableShow.prototype.SetAlignX = function(align){
        if (typeof align !== 'undefined' && align !== null)
        {
            this.alignX = new String(align);
            if (this.alignX !== null)
                this.alignX = this.alignX.toString();
        }
    };

    TTableShow.prototype.GetAlignX = function(){
        if (typeof this.alignX !== 'undefined' && this.alignX !== null)
        {
            var tmp = new String(this.alignX);
            if (tmp !== null)
                return tmp.toString();
            return tmp;
        }
        return null;
    };

    TTableShow.prototype.SetAlignY = function(align){
        if (typeof align !== 'undefined' && align !== null)
        {
            this.alignY = new String(align);
            if (this.alignY !== null)
                this.alignY = this.alignY.toString();
        }
    };

    TTableShow.prototype.GetAlignY = function(){
        if (typeof this.alignY !== 'undefined' && this.alignY !== null)
        {
            var tmp = new String(this.alignY);
            if (tmp !== null)
                return tmp.toString();
            return tmp;
        }
        return null;
    };

    TTableShow.prototype.SetTextSize = function(size){
        if (typeof size !== 'undefined' && size !== null)
            this.textSize = size;
    };

    TTableShow.prototype.GetTextSize = function(){
        return this.textSize;
    };

    TTableShow.prototype.SetFontStyle = function(style){
        if (typeof style !== 'undefined' && style !== null)
        {
            this.fontStyle = new String(style);
            if (this.fontStyle !== null)
                this.fontStyle = this.fontStyle.toString();
        }
    };

    TTableShow.prototype.GetFontStyle = function(){
        if (typeof this.fontStyle !== 'undefined' && this.fontStyle !== null)
        {
            var tmp = new String(this.fontStyle);
            if (tmp !== null)
                return tmp.toString();
            return tmp;
        }
        return null;
    };

    TTableShow.prototype.SetFont = function(font){
        if (typeof font !== 'undefined' && font !== null)
        {
            this.font = new String(font);
            if (this.font !== null)
                this.font = this.font.toString();
        }
    };

    TTableShow.prototype.GetFont = function(){
        if (typeof this.font !== 'undefined' && this.font !== null)
        {
            var tmp = new String(this.font);
            if (tmp !== null)
                return tmp.toString();
            return tmp;
        }
        return null;
    };

};

TTableShow.prototype = new TPageElement();

function TTableEdit(){
    var type = 'TTableEdit';
    TTableEdit.prototype.InitConstructor = function(){
        TTableShow.prototype.InitConstructor.call(this);
        this.SetType(type);
        this.minValue = 0;
        this.maxValue = 255;
        this.colourErrorBackground = null;
        this.colourErrorText = null;
        this.table = null;
        this.nonZero = false;
        this.typeVariable = 'double';
    };
    this.InitConstructor();

    TTableEdit.prototype.Init = function(_object){
        TTableShow.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        var i,j;
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TTableEdit'))
        {
            if (typeof _object.minValue !== 'undefined' && _object.minValue !== null && IsNumeric(_object.minValue))
                this.minValue = _object.minValue;
            if (typeof _object.maxValue !== 'undefined' && _object.maxValue !== null && IsNumeric(_object.maxValue))
                this.maxValue = _object.maxValue;
            if (typeof _object.colourErrorBackground !== 'undefined' && _object.colourErrorBackground !== null && _object.colourErrorBackground.IsType('TColourRGBA'))
                this.colourErrorBackground = objM.copy(_object.colourErrorBackground);
            if (typeof _object.colourErrorText !== 'undefined' && _object.colourErrorText !== null && _object.colourErrorText.IsType('TColourRGBA'))
                this.colourErrorText = objM.copy(_object.colourErrorText);
            if (typeof _object.table !== 'undefined' && _object.table !== null)
            {
                for (i = 0;i < _object.table.length;i++)
                    for (j = 0;j < _object.table.length;j++)
                        if (typeof _object.table[i][j] !== 'undefined' && _object.table[i][j] !== null)
                        {
                            if (IsNumeric(_object.table[i][j]))
                                this.table[i][j] = _object.table[i][j];
                            else
                            {
                                this.table[i][j] = new String(_object.table[i][j]);
                                if (this.table[i][j] !== null)
                                    this.table[i][j] = this.table[i][j].toString();
                            }
                        }
            }
            if (typeof _object.nonZero !== 'undefined' && _object.nonZero !== null)
                this.nonZero = _object.nonZero;
            if (typeof _object.typeVariable !== 'undefined' && _object.typeVariable !== null)
            {
                this.typeVariable = new String(_object.typeVariable);
                if (this.typeVariable !== null)
                    this.typeVariable = this.typeVariable.toString();
            }
        }
    };

    TTableEdit.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TTableShow.prototype.IsType.call(this,_type);
    };
    

    TTableEdit.prototype.ReadXML = function(tag,fun){
        TTableShow.prototype.ReadXML.call(this,tag,fun);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof tag !== 'undefined' && tag !== null)
        {
            var tmp = tag.getAttribute('nonzero');
            if (typeof tmp !== 'undefined' && tmp !== null && (tmp==='Yes' || tmp ==='yes'))
                this.nonZero = true;
            var attr = tag.getAttribute('typeVar');
            this.SetTypeVariable(attr);
            var j=0,x = tag.childNodes;
            var x = tag.childNodes,i;
            for (i = 0;i < x.length;i++)
            {
                if (x[i].nodeType === 1)
                {
                    if (x[i].nodeName === 'ColourErrorBackground')
                    {
                        if (this.colourErrorBackground === null)
                            this.colourErrorBackground = objM.newObject('TColourTXT');
                        if (this.colourErrorBackground !== null)
                            this.colourErrorBackground.ReadXML(x[i]);
                    }
                    if (x[i].nodeName === 'ColourErrorText')
                    {
                        if (this.colourErrorText === null)
                            this.colourErrorText = objM.newObject('TColourTXT');
                        if (this.colourErrorText !== null)
                            this.colourErrorText.ReadXML(x[i]);
                    }
                    
                }   
            }

            var x2,k;
            this.actions[j] = objM.newObject('TActionTableEditError');
            if (this.actions[j] !== null)
            {
                this.actions[j].SetId(this.GetId());
                this.actions[j++].SetObject(this);
            }
            for (i = 0,k = 0;i < x.length;i++)
            {
                if (x[i].nodeType === 1)
                {
                    if(x[i].nodeName === 'Id')
                    {
                        x2 = x[i].childNodes;
                        attr = x[i].getAttribute('id');
                        if (attr !== null)
                        {
                            if (k === 0)
                                this.actions[j] = objM.newObject('TActionTableEditRecalculate');
                            if (this.actions[j] !== null)
                            {
                                if (k === 0)
                                    this.actions[j].SetId(this.GetId());
                                this.actions[j].SetId(attr,k++);
                            }
                        }
                        
                    }
                }
            }
        }
    };

    TTableEdit.prototype.Draw = function(_object){
        if (typeof _object !== 'undefined' && _object !== null && _object.IsType('TGenerateObject'))
        {
            var tmp2 = [],id = this.GetId();
            if (id !== null)
            {
                var tab = null;
                if (this.varTable === null)
                {
                    if (this.table === null)
                        tab = this.CalculateValue(this.tableTXT);
                    else
                        tab = this.table;
                }else
                {
                    var tmpTab = this.GetVarTable();
                    if (tmpTab !== null)
                        tab = this.CalculateValue(tmpTab.GetValue());                    
                }
                this.table = tab;
                tmp2[0] = id;
                if (this.hex === true && tab !== 'undefined' && tab !== null)
                {
                    var i, j,tab_tmp = [];
                    for (i = 0;i < tab.length;i++)
                    {
                        tab_tmp[i] = [];
                        for (j = 0;j < tab[i].length;j++)
                            tab_tmp[i][j] = Numeric2Hex(tab[i][j],this.hexDigit);
                    }
                    tmp2[1] = tab_tmp;
                }else
                    tmp2[1] = tab;
                tmp2[2] = this.GetClassStyle();
                tmp2[3] = this.lineStyle;
                tmp2[4] = this.widthCell;
                tmp2[5] = this.heightCell;
                if (this.minColourTXT === null)
                    tmp2[6] = null;
                else
                    tmp2[6] = this.minColourTXT.GetColour(this.GetObjectVariables());
                if (this.maxColourTXT === null)
                    tmp2[7] = null;
                else
                    tmp2[7] = this.maxColourTXT.GetColour(this.GetObjectVariables());
                tmp2[8] = this.minValue;
                tmp2[9] = this.maxValue;
                if (this.minColourTextTXT === null)
                    tmp2[10] = null;
                else
                    tmp2[10] = this.minColourTextTXT.GetColour(this.GetObjectVariables());
                if (this.maxColourTextTXT === null)
                    tmp2[11] = null;
                else
                    tmp2[11] = this.maxColourTextTXT.GetColour(this.GetObjectVariables());
                tmp2[12] = this.alignTextX;
                tmp2[13] = this.alignTextY;
                tmp2[14] = this.lineWidth;
                tmp2[15] = this.hex;
                tmp2[16] = this.colourProfile;
                tmp2[17] = this.GetColourMap();
                tmp2[18] = this.colourMapMin;
                tmp2[19] = this.colourMapMax;
                tmp2[20] = this.widthTeXCell;
                tmp2[21] = this.heightTeXCell;
                tmp2[22] = this.GetTextSize();
                tmp2[23] = this.GetFontStyle();
                tmp2[24] = this.GetFont();

/*                tmp2[0] = this.GetWidth();
                tmp2[1] = this.GetHeight();
                tmp2[2] = this.GetFigures();
                tmp2[3] = this.GetXMax()-this.GetXMin();
                tmp2[4] = this.GetYMax()-this.GetYMin();
                tmp2[5] = 1;
                tmp2[6] = this.GetXMin();
                tmp2[7] = this.GetYMin();
                tmp2[8] = 0;
                tmp2[9] = this.generate;
                tmp2[10] = this.scaleTikZ;
                tmp2[11] = this.scale;
                tmp2[12] = this.GetAlignX();*/
                _object.Add('TableEdit','',tmp2);
            }
        }
    };

    TTableEdit.prototype.GetN = function(){
        if (this.table !== null)
            return this.table.length;
        return 0;
    };

    TTableEdit.prototype.GetM = function(){
        if (this.table !== null && this.table.length > 0 && this.table[0] !== null)
            return this.table[0].length;
        return 0;
    };

    TTableEdit.prototype.GetData = function(x,y){
        return this.table[x][y];
    };

    TTableEdit.prototype.SetData = function(x,y,data){
        this.table[x][y] = data;
    };

    TTableEdit.prototype.GetColourTextError = function(){
        if (this.colourErrorText)
        return this.colourErrorText.GetColour(this.GetObjectVariables());
    };

    TTableEdit.prototype.GetColourBackgroundError = function(){
        if (this.colourErrorBackground)
            return this.colourErrorBackground.GetColour(this.GetObjectVariables());
        return null;
    };

    TTableEdit.prototype.GetNonZero= function(){
        return this.nonZero;
    };

    TTableEdit.prototype.SetTypeVariable = function(type){
        if (typeof type !== 'undefined' && type !== null)
        {
            this.typeVariable = new String(type);
            if (this.typeVariable !== null)
                this.typeVariable = this.typeVariable.toString();
        }
//        if (type === null)
//            this.typeVariable = null;
    };

    TTableEdit.prototype.GetTypeVariable = function(){
        if (this.typeVariable !== null)
        {
            var tmp = new String(this.typeVariable);
            if (tmp !== null)
                return tmp.toString();
        }
        return null;
    };

    TTableEdit.prototype.RefreshTable = function(){
        if (this.table !== null)
        {
            var i,j, n = this.table.length;
            var txt = '[';
            for (i = 0;i < n;i++)
            {
                if (i !== 0)
                    txt = txt + ',';
                txt = txt + '[';
                for (j = 0;j < this.table[i].length;j++)
                {
                    if (j !== 0)
                        txt = txt + ',';
                    txt = txt + this.table[i][j];
                }
                txt = txt + ']';
            }
            txt = txt + ']';
            this.tableTXT = txt;
            var tmp = this.GetVarTable();
            if (tmp !== null)
                tmp.SetValue(txt);
        }
    };

};

TTableEdit.prototype = new TTableShow();


function TActionTableEdit(){
    var type = 'TActionEdit';
    TActionTableEdit.prototype.InitConstructor = function(){
        TAction.prototype.InitConstructor.call(this);
        this.SetType(type);
        this.SetTagName('input');
    };
    this.InitConstructor();

    TActionTableEdit.prototype.Init = function(_object){
        TAction.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TActionTableEdit'))
        {
        }
    };
    
    TActionTableEdit.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TAction.prototype.IsType.call(this,_type);
    };

}

TActionTableEdit.prototype = new TAction();


function TActionTableEditError(){
    var type = 'TActionTableEditError';
    TActionTableEditError.prototype.InitConstructor = function(){
        TActionTableEdit.prototype.InitConstructor.call(this);
        this.SetType(type);
    };
    this.InitConstructor();

    TActionTableEditError.prototype.Init = function(_object){
        TActionTableEdit.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TActionTableEditError'))
        {
        }
    };
    
    TActionTableEditError.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TActionTableEdit.prototype.IsType.call(this,_type);
    };

    TActionTableEditError.prototype.Interaction = function(object){
        var id = this.GetId();
        var obj = document.getElementById(id);
        var objM = this.GetObjectManager();
        if (objM !== null)
//        if (this.actionObject !== null)
        {
            var objTableEdit = this.GetObject();
            if (typeof obj !== 'undefined' && obj !== null && typeof objTableEdit !== 'undefined' && objTableEdit !== null && objTableEdit.IsType('TTableEdit'))
            {
                var weight,minValue = objTableEdit.GetMinValue(),maxValue = objTableEdit.GetMaxValue();
                var colBackground;
                var colText;
                var colBackgroundError = objTableEdit.GetColourBackgroundError();
                var colTextError = objTableEdit.GetColourTextError();
                var n = objTableEdit.GetN(),m = objTableEdit.GetM();
                if (n !== null && m !== null && n > 0 && m > 0)
                {
                    var i,j,data,id2,objTmp;
                    for (i = 0;i < n;i++)
                        for (j = 0;j < m;j++)
                        {
                            id2 = id + '_' + i + '_' + j;
                            objTmp = document.getElementById(id2);
                            if (objTmp !== null)
                            {
                                if (objTableEdit.GetColourProfile() === 'colour24bit')
                                {
                                    if (objTmp.innerText.length > 6)
                                    {
//                                        data = objTmp.innerText.substring(0,6);
//                                        objTmp.innerHTML = data;
                                        data = objTmp.innerText;
                                    }
                                    else
                                        data = objTmp.innerText;
                                    if (objTableEdit.GetHex())
                                        data = Hex2Numeric(data);
                                    else
                                        data = parseFloat(data);
/*                                    var txt = '',data2=objTmp.innerText;
                                    txt = txt + '<span style="color: red">' + data2.substring(0,2) + '</span>';
                                    txt = txt + '<span style="color: green">' + data2.substring(2,4) + '</span>';
                                    txt = txt + '<span style="color: blue">' + data2.substring(4,6) + '</span>';
                                    objTmp.innerHTML = txt;*/
                                }else
                                {
                                    if (objTableEdit.GetHex())
                                        data = Hex2Numeric(objTmp.value);
                                    else
                                        data = parseFloat(objTmp.value);
                                }    
                                if (objTableEdit.GetColourProfile() === 'colour24bit')
                                {
//                                    objTableEdit.SetData(i,j,data);
                                    if (colTextError !== null || colBackgroundError !== null)
                                    {
                                        if (!IsNumeric(data))
                                        {
                                            if (colText !== null)
                                                objTmp.style.color = '#' + colTextError.Get24bitColourHex();
                                            if (colBackground !== null)
                                                objTmp.style.background = '#' + colBackgroundError.Get24bitColourHex();
                                        }else
                                        {
//                                            if ((objTableEdit.GetMinValue() === null || data >= objTableEdit.GetMinValue()) && (objTableEdit.GetMaxValue() === null || data <= objTableEdit.GetMaxValue()))
                                            if (data >= 0 && data <= 16777215)
                                            {
    //                                            if (colText !== null)
    //                                                objTmp.style.color = '#' + colText.Get24bitColourHex();
                                                colBackground = objM.newObject('TColourRGBA');
                                                if (colBackground !== null)
                                                {
                                                    colBackground.SetColourRGBA(Math.floor(data/(256*256))/255,Math.floor((data & (255*256))/256)/255,Math.floor(data & 255)/255,1);
                                                    objTmp.style.background = '#' + colBackground.Get24bitColourHex();
                                                }
                                                objTableEdit.SetData(i,j,data);
                                                YN = true;
                                            }else
                                                YN = false;
                                            if (!YN) 
                                            {

                                                if (colText !== null)
                                                    objTmp.style.color = '#' + colTextError.Get24bitColourHex();
                                                if (colBackground !== null)
                                                    objTmp.style.background = '#' + colBackgroundError.Get24bitColourHex();                                    
                                            }

                                        }
                                    }
                                }else
                                {
                                    weight = (data - minValue)/(maxValue - minValue);
                                    colText = objTableEdit.GetColourText(weight);
                                    colBackground = objTableEdit.GetColourBackground(weight);
                                    var k,colourMap = objTableEdit.GetColourMap();
                                    if (colourMap !== null)
                                    {
                                        for (k = 0;k < colourMap.length;k++)
                                        {
                                            if (data >= objTableEdit.GetColourMapMin(k) && data <= objTableEdit.GetColourMapMax(k))
                                            {
                                                colBackground = colourMap[k];
                                                break;
                                            }
                                        }
                                    }

                                    if (colText !== null && colBackground !== null)
                                    {

                                        if ((colTextError !== null && colText !== null) || (colBackgroundError !== null && colBackground !== null))
                                        {
                                            if (!IsNumeric(data))
                                            {
                                                if (colTextError !== null)
                                                    objTmp.style.color = '#' + colTextError.Get24bitColourHex();
                                                if (colBackgroundError !== null)
                                                    objTmp.style.background = '#' + colBackgroundError.Get24bitColourHex();
                                            }else
                                            {
                                                if (objTableEdit.GetNonZero() && data === 0)
                                                {
                                                    if (colTextError !== null)
                                                        objTmp.style.color = '#' + colTextError.Get24bitColourHex();
                                                    if (colBackgroundError !== null)
                                                        objTmp.style.background = '#' + colBackgroundError.Get24bitColourHex();                                
                                                }else
                                                {
                                                    var YN = false,YN2 = false,var_ = objTableEdit.GetTypeVariable();
                                                    if (typeof var_ !== 'undefined' && var_ !== null && var_ === 'int')
                                                    {
                                                        YN2 = true;
                                                        if (IsInt(data))
                                                            YN = true;
                                                    }

                                                    if (!YN || YN2)
                                                    {
                                                        if ((objTableEdit.GetMinValue() === null || data >= objTableEdit.GetMinValue()) && (objTableEdit.GetMaxValue() === null || data <= objTableEdit.GetMaxValue()))
                                                        {
                                                            if (colText !== null)
                                                                objTmp.style.color = '#' + colText.Get24bitColourHex();
                                                            if (colBackground !== null)
                                                                objTmp.style.background = '#' + colBackground.Get24bitColourHex();
                                                            objTableEdit.SetData(i,j,data);
                                                            YN = true;
                                                        }else
                                                            YN = false;
                                                    }
                                                    if (!YN) 
                                                    {

                                                        if (colText !== null)
                                                            objTmp.style.color = '#' + colTextError.Get24bitColourHex();
                                                        if (colBackground !== null)
                                                            objTmp.style.background = '#' + colBackgroundError.Get24bitColourHex();                                    
                                                    }
                                                }
                                            }
                                        }
                                    }
                                
                                }
                            }
                        }
                    objTableEdit.RefreshTable();
                }
                
            }
        }
    };

}

TActionTableEditError.prototype = new TActionTableEdit();

function TActionTableEditRecalculate(){
    var type = 'TActionTableEditRecalculate';
    TActionTableEditRecalculate.prototype.InitConstructor = function(){
        TActionTableEdit.prototype.InitConstructor.call(this);
        this.SetType(type);
    };
    this.InitConstructor();

    TActionTableEditRecalculate.prototype.Init = function(_object){
        TActionTableEdit.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TActionTableEditRecalculate'))
        {
        }
    };
    
    TActionTableEditRecalculate.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TActionTableEdit.prototype.IsType.call(this,_type);
    };

    TActionTableEditRecalculate.prototype.Interaction = function(object){
        var obj = document.getElementById(this.GetId()),scene,context;
        var objM = this.GetObjectManager();
        if (objM !== null && this.actionObject !== null)
        {
            var i,n = this.GetNId(),id_,obj2,scene_,k,tabObj,obj3;
            for(i = 0;i < n;i++)
            {
                id_ = this.GetId(i);
                if (typeof id_ !== 'undefined' && id_ !== null)
                {
                    obj2 = document.getElementById(id_);
                    if (typeof obj2 !== 'undefined' && obj2 !== null)
                    {
                        if (typeof obj2.typeDraw === 'undefined' || obj2.typeDraw === null)
                        {
                            if (typeof obj2.thisObject !== 'undefined' && obj2.thisObject !== null && obj2.thisObject.IsType('TPageElement'))
                            {
                                obj2.thisObject.Refresh();
                            }
                            if (typeof obj2.thisObject !== 'undefined' && obj2.thisObject !== null && obj2.thisObject.IsType('TParagraphElement'))
                            {
                                obj2.thisObject.Refresh();
                            }
                        }
                        if (obj2.typeDraw === 'three')
                        {
                            if (typeof obj2.camera !== 'undefined' && obj2.camera !== null && typeof obj2.renderer !== 'undefined' && obj2.renderer !== null && typeof obj2.scene !== 'undefined' && obj2.scene !== null)
                            {
                                scene = obj2.scene;
                                scene_ = scene.GetScene();
                                if (scene_ !== null)
                                {
                                    for (k = scene_.children.length - 1;k >= 0;k--)
                                    {
                                        obj3 = scene_.children[k];
                                        scene_.remove(obj3);
                                    }
                                }
                                tabObj = obj2.tabObj;
                                if (typeof tabObj !== 'undefined' && tabObj !== null)
                                {
                                    for (k = 0;k < tabObj.length;k++)
                                    {
                                        obj = tabObj[k];
                                        if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TObjectFigure'))
                                        {
                                            obj.DrawFigure(scene);
                                        }
                                    }
                                }
                                obj2.renderer.render(scene_, obj2.camera.GetCamera());                         
                            }
                        }
                        if (obj2.typeDraw === 'canvas')
                        {
                            tabObj = obj2.tabObj;
                            var ctx_ = obj2.getContext('2d');
                            scene = objM.newObject('TCanvasScene');
                            scene.SetScale(1);
//                            var matrix = objM.newObject('TMatrixTransformation3D');
//                            matrix.SetTranslationMatrix(0,0,0);

//                            scene.SetTransformation(matrix);
//                            scene.SetContext(ctx_);
                            if (typeof obj2.scene !== 'undefined' && obj2.scene !== null)
                            {
                                scene.SetContext(ctx_);
                                scene.SetTransformation(obj2.transformationMatrix);
//                                scene.SetTransformationMatrix(obj2.scene.GetTransformationMatrix());
//                                obj2.scene.context.fillText('aaaaaa',0,0)
                                if (typeof tabObj !== 'undefined' && tabObj !== null)
                                {
 //                                   context = scene.GetContext();
                                    context = ctx_;
                                    if (typeof context !== 'undefined' && context !== null)
                                    {
                                        context.clearRect(0, 0, context.canvas.width, context.canvas.height);
                                        for (k = 0;k < tabObj.length;k++)
                                        {
                                            obj = tabObj[k];
                                            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TObjectFigure'))
                                            {
                                                obj.DrawFigure(scene);
                                            }
                                        }
                                    }
                                }
                            }                            
                        }
                        
                    }
                }
            }

        }
    };

}

TActionTableEditRecalculate.prototype = new TActionTableEdit();
