// Build 9.00.7440.8
function ScrollBar(parent) {
    var o_scroll = document.createElement("div");
    parent.appendChild(o_scroll);
    o_scroll.style.position = "absolute";
    o_scroll.style.overflowX = "hidden";
    o_scroll.style.overflowY = "scroll";
    o_scroll.style.width = "18px";
    o_scroll.style.top = "0px";
    o_scroll.style.zIndex = 10;
    var i_scroll = document.createElement("div");
    o_scroll.appendChild(i_scroll);
    i_scroll.style.width = "1px";
    this.Parent = parent;
    this.o_Scroll = o_scroll;
    this.i_Scroll = i_scroll;
    
    this.UpdateSize(30, 16);
}
ScrollBar.prototype.UpdateSize = function (totalRows, visibleRows) {
    this.VisibleRows = Math.max(visibleRows, 1);
    this.TotalRows   = totalRows;
    this.UpdateHeight();
}
ScrollBar.prototype.UpdateHeight = function (height) {
//    var height = this.Height = height || this.Height || Math.max(1, this.Parent.offsetHeight - this.Parent.offsetTop);
//    this.o_Scroll.style.height = height + "px";
//    this.i_Scroll.style.height = Math.round (height * this.TotalRows / this.VisibleRows) + "px";
    this.o_Scroll.style.height = "100%";
    var h = Math.round (100 * this.TotalRows / this.VisibleRows)
    this.i_Scroll.style.height = h + "%";
    this.o_Scroll.style.display = h <= 100 ? 'none' : '';
    this.o_Scroll.style.left = (this.Parent.offsetWidth - 18) + "px";
}
ScrollBar.prototype.GetWidth = function () { 
    if (IS_MAC) {
        return 15;
    } else {
        return 17;
    }
}
ScrollBar.prototype.GetOffset = function () { // TODO: fix ? ('independent' of this.Height) ? (save offest ?)
    if(this.Height != undefined) {
        return Math.round(this.VisibleRows * this.o_Scroll.scrollTop / this.Height)
    } else {
        return 0;
    }
}

if (!Qva.Mgr) Qva.Mgr = {};

Qva.Mgr.table = function (owner, elem, name, prefix, condition) {
    
    this.Name = Qva.MgrMakeName ((name != null) ? name : '', prefix);
    owner.AddManager(this);
    this.LeftButton = owner.LeftButton;
    this.Element = elem;
    elem.AvqMgr = this;
    this.TableScan (owner, prefix);
    if (! this.AutoCol && this.Name != "") {
        owner.Append (this, this.Name, 'choice');
    }
    this.ScrollParent = this.Element.parentNode;
    this.Frame = this.ScrollParent.parentNode;
}

Qva.Mgr.table.prototype.CellObject = function (optval, value) {
    this.val = optval ? optval : "";
    var title = value.getAttribute ("title");
    this.title = title ? title : this.val;
    var index = value.getAttribute ("value");
    if (index) {
        this.intval = index;
        this.selected = value.getAttribute ("selected") == "yes";
        this.deselected = value.getAttribute ("deselected") == "yes";
        this.selectedexcluded = value.getAttribute ("selectedexcluded") == "yes";
        this.locked = value.getAttribute ("locked") == "yes";
        this.frequency = value.getAttribute ("frequency");
        this.level = value.getAttribute ("level");
        this.parts = value.getElementsByTagName ("range");
    } else {
        if (value.getAttribute ("locked")) {
            this.locked = value.getAttribute ("locked") == "yes";
            this.byval = true;
        }
        if (value.getAttribute ("selected")) {
            this.selected = value.getAttribute ("selected") == "yes";
            this.byval = true;
        }
    }
    this.mode = value.getAttribute ("mode");
    this.disabled = this.mode == "disabled";
    this.style = value.getAttribute ("style");
    this.isnum = value.getAttribute ("isnum") == "true";
    this.icons = value.getElementsByTagName ("icon");
    this.subcell = value.getAttribute ("subcell");
    this.first = value.getAttribute ("first");
    this.action = value.getAttribute ("action");
    this.url = value.getAttribute ("url");
    var selecttype = value.getAttribute ("selecttype");
    if (selecttype) {
        this.selecttype = selecttype;
        this.selectsource = value.getAttribute ("selectsource") == "true";
        if (this.action) debugger;
    }
    this.input = value.getAttribute ("input") == "true";
    var rowspan = value.getAttribute ("rowspan");
    if (rowspan) {
        this.rowspan = parseInt (rowspan);
    } else {
        this.rowspan = 1;
    }
}

Qva.Mgr.table.prototype.TableScan = function (owner, prefix) {
    var element = this.Element;
    this.Selected = new Array ();
    var groupname = element.getAttribute ('AvqGroup');
    if (groupname != null) {
        this.Group = Qva.MgrMakeName (groupname, prefix);
        owner.Append (this, this.Group);
    }
    this.PageName = this.Name;
    this.PageSize = 0; // unlimited
    this.TotalSize = 0;
    this.ColMgr = [];
    this.Fixed = false;
    this.RowHeight = -1;
    this.AllwaysFullWidth = false;
    this.Search = null;
    this.SearchName = this.Name;
    this.Searchable = false;
    this.IsAsync = false;
    this.IsTransient = false;
    this.TableLimit = owner.TableLimit;
    this.InlineStyle = owner.InlineStyle;
    if (element.getAttribute ('AvqStyle')) {
        this.InlineStyle = element.getAttribute ('AvqStyle') == "true";
    }
    var async = element.getAttribute ('AvqAsync');
    this.IsHeader = element.getAttribute ('avqheader') == "true";
    this.IsBody = element.getAttribute ('avqbody') == "true";
    this.HeaderRowCount = 0;
    if (async != null) {
        if (async != '') {
            var asyncs = async.split (':');
            if (asyncs.length > 2) {
                m_errors [m_errors.length] = 'Invalid AvqAsync: ' + async;
                return;
            }
            var pageSize = parseInt (asyncs [0]);
            if (isNaN (pageSize) || pageSize <= 0) {
                m_errors [m_errors.length] = 'Invalid page-size in AvqAsync: ' + pageSize;
                return;
            }
            this.PageSize = pageSize;
            if (asyncs.length >= 2) {
                this.PageName = Qva.MgrMakeName (asyncs [1], prefix);
            }
        } else {
            this.PageSize = 20;
        }
        this.IsAsync = true;
    }
    this.PageIncr = this.PageSize > 0 ? this.PageSize : 20;
    if (this.IsAsync) {
        owner.Append (this, this.PageName, 'pageoffset');
        owner.Append (this, this.PageName, 'pagesize');
        owner.Append (this, this.PageName, 'totalsize');
        owner.SetInitial (this.PageName, 'pagesize', this.PageSize);
    }
    if (this.IsHeader || this.IsBody) {
        owner.Append (this, this.PageName, 'fixedrows');
    }
    if (element.tagName == 'TABLE') {
        this.Body = element.tBodies [0];
        if (this.Body == null) {
            element.insertRow(-1);
            this.Body = element.tBodies [0];
        }
    } else {
        this.Body = element;
    }
    
    var body = this.Body;
    if (body.rows.length < 1) {
        body.appendChild(document.createElement("tr"));
        //m_errors [m_errors.length] = 'At least one row must exist: ' + this.Name;
    }
    
    if(IS_GECKO && GECKO_VERSION < 3.5) {
        element.style.borderCollapse = "separate";
        element.style.borderSpacing = "0px";
        //setTimeout(function() { element.style.borderCollapse = "collapse"; }, 1000);
    }
    
    var row = body.rows [0];
    row.rix = 0;
    this.Width = row.cells.length;
    
    this.AutoCol = this.Width === 0;
    
    var choice = null;
    if (this.Name != '') {
        choice = element.getAttribute ('AvqChoice');
        if (choice == null) choice = this.Name;
    }
    this.Lines = new Array ();
    this.Style = new Array ();
    this.BorderStyle = new Array ();
    this.IsPainted = new Array ();
    this.RowClassNames = new Array ();
    this.ColList = new Array ();
    this.ColDict = {};
    
    this.ChoiceIx = -1;
    
    var cix = 0;
    for (; cix < this.Width; ++cix) {
        var cell = row.cells[cix];
        
        var colfld = cell.getAttribute ('AvqCol');
        if (colfld == null) continue;
        if (colfld.indexOf (':') == -1 && colfld.indexOf ('.') >= 0) {
            // no separator specified but field specified -> assume 'edit'
            colfld = 'edit:' + colfld;
        }
        var parts = colfld.split (':');
        
        var cmd = parts[0];
        var name = (parts.length > 1) ? parts[1] : this.Name;
        var extra = (parts.length > 2) ? parts.slice(2).join (':') : null;
        if(this.ColMgr[cix]) {
            cmd = this.ColMgr[cix].cmd;
            extra = this.ColMgr[cix].extra;
        }
        
        var type = Qva.ColMgr[cmd] || Qva.ColMgr.basic;
        var colmgr = new type(this, cix, cell, name, prefix, extra);
        colmgr.Cmd = cmd;
        
        if (colmgr.Name == null) {
            m_errors [m_errors.length] = 'Invalid AvqCol "' + parts [1] + '": ' + this.Name;
            continue;
        }
        if (this.Group == null) owner.Append (this, colmgr.Name);
        this.ColDict[colmgr.Name] = colmgr;
        this.ColList [this.ColList.length] = colmgr;
    }
    this.RowClassNames [0] = body.rows [0].className;
    
    var stripes = element.getAttribute ('AvqStripeClasses');
    if (stripes != null) {
        this.RowClassNames = this.RowClassNames.concat(('' + stripes).split(/\s/));
    }
    if (choice != null) {
        var colmgr = this.ColDict[choice];
        if (colmgr == null) {
            colmgr = new Qva.ColMgr.basic(this, cix, null, choice, prefix);
            if (this.Group == null) owner.Append (this, colmgr.Name);
            this.ColDict[choice] = colmgr;
            ++cix;
        }
        this.ChoiceIx = colmgr.Index;
    }
    if (!this.IsHeader) {
        try {
            var pp = element.parentNode;
            pp.AvqMgrForScroll = this;
            pp.onscroll = this.ParentScroll;
        } catch (e) {
            alert ("Error: " + element.parentNode.tagName);
        }
    }
    
    var objectname = this.PageName.replace (this.PageBinder.DefaultScope + ".", "");
    if (element.id == "" && this.IsHeader) {
        element.id = objectname;
    }
    if (this.IsBody && ! element.Header) {
        var header = document.getElementById (objectname);
        if (header && header != element) {
            element.Header = header;
        } else if (element.id == "") {
            //Listboxes and multiboxes has no header
            element.id = objectname;
        }
    }
    
    if(element.getAttribute('AvqScrollBar') != null) {
        this.ScrollBar = new ScrollBar(element.parentNode);
        
        var _this = this;
        this.ScrollBar.o_Scroll.onscroll = Delay(function () {
            Qva.QueuePostPaintMessage(_this);
        }, 100);
        
        //element.parentNode.style.overflowY = "hidden";
        
        var parent = element.parentNode;
        parent.removeChild(element);
        var div = document.createElement("div");
        parent.appendChild(div);
        div.appendChild(element);
        this.Element = div;
        
        parent.style.overflowY = "hidden";
        div.style.overflowY = "hidden";
        div.style.overflowY = "hidden";
        div.style.overflowX = "auto";
        
        div.style.position = "relative"; // Fix IE bug
        
        div.AvqMgrForScroll = this;
        div.onscroll = function () {
            var mgr = this.AvqMgrForScroll;
            if (!mgr.Element.Header) return
            var header = mgr.Element.Header;
            if (header && header.parentNode.scrollLeft != this.scrollLeft) {
                header.parentNode.scrollLeft = this.scrollLeft;
            }
        };
    }
}

function Delay(func, time) {
    return function() {
        var _this = this;
        if(func._wait) clearTimeout(func._wait);
        func._wait = setTimeout(function() { func.apply(_this, arguments); func._wait = null; }, time);
    }
}

var busy = false;

Qva.Mgr.table.prototype.ParentScroll = function() {
    if (busy) return;
    var mgr = this.AvqMgrForScroll;
    if (mgr == null) mgr = element.document.body.AvqMgrForScroll; // daft workaround for daft design... (onscroll on body behaves strangely)
    if (mgr == null) return;
    if (mgr.Element.Header != null) {
        busy = true;
        var header = mgr.Element.Header;
        if (header.parentNode.scrollLeft != this.scrollLeft) {
            header.parentNode.scrollLeft = this.scrollLeft;
        }
        busy = false;
    }
    mgr.debugcounter = 0;
    Qva.QueuePostPaintMessage (mgr);
}

Qva.Mgr.table.prototype.Lock = Qva.NoAction;
Qva.Mgr.table.prototype.Unlock = Qva.NoAction;

Qva.Mgr.table.prototype.getTableElement = function () {
    if (this.ScrollBar && this.IsBody) {
        return this.Element.getElementsByTagName("table")[0];
    } else {
        return this.Element;
    }
}

Qva.Mgr.table.prototype.FixCol = function (mode, node, name, partial) {
    var vals = new Array();
    for (var memb = node.firstChild; memb; memb = memb.nextSibling) {
        if (memb.nodeName != 'value') continue;
        if (memb.getAttributeNode ('width') == null) continue;
        vals [vals.length] = memb;
    }
    var element = this.Element;
    var objectisresized = this.Frame.maxclientheight == null || this.Frame.maxclientwidth == null;
    if (this.AllwaysFullWidth && ! this.IsTransient) {
        var Maximized = this.Frame.AvqMgr.Maximized;
        if (Maximized != this.Maximized) {
            objectisresized = true;
            this.Maximized = this.Frame.AvqMgr.Maximized;
        }
    }
    if (objectisresized && ! this.IsTransient) {
        setFrameWidth (this.Frame, 0);
        setFrameHeight (this.Frame, 0);
        if (this.Frame.maxclientwidth) {
            setContentWidth (this.Frame, this.Frame.maxclientwidth);
        }
    }
    
    if (this.Width == vals.length && this.Body.rows.length > 0) return;
    this.Fixed = false;

    this.Width = vals.length;
    
    var bodyParent = this.Body.parentNode;
    var body = this.Body.cloneNode (false);
    var row = document.createElement ("tr");
    body.appendChild(row);
    row.rix = 0;
    
    this.ColList = [];
    
    var cix = 0;
    var elem = vals [0] ? vals [0].childNodes [0] : null;
    var edit = elem && elem.getAttribute ('value');
    var tottablewidth = 0;

    this.UnmodifiedTableWidth = null;
    
    for (; cix < this.Width; ++cix) {
        var width = vals[cix].getAttribute ("width");
        var cell = row.cells[cix];
        if (cell == null) cell = row.appendChild (document.createElement("td"));
        if (width) {
            if (width == "auto") {
                cell.style.width = "" + 100 / this.Width + "%"
                this.AllwaysFullWidth = true;
            } else {
                var colwidth = parseInt (parseFloat (width) * 72 / 300);
                cell.style.width = colwidth + "pt";
                tottablewidth += colwidth;
                if (IS_GECKO) tottablewidth += 3;
                if (IS_CHROME || IS_SAFARI) tottablewidth += 2;
                if (cix == (this.Width - 1)) {
                    this.LastColWidth = colwidth + "pt"
                }
            }
            cell.innerText = "Gg";
        }
        if (this.InlineStyle) {
            var rowindex = 0;
            var val = null;
            while (! val) {
                val = vals[cix].getElementsByTagName('element') [rowindex];
                if (! val) break;
                if (this.IsHeader != (val.getAttribute ("position") == "top")) {
                    val = null;
                    rowindex++;
                }
            }
            if (val) {
                var data = new this.CellObject (val.getAttribute ("text"), val);
                cell.style.cssText += this.SetCellStyle (data, 0, cix, true, true);
            }
        }

        var extra = null;
        var cmd = edit ? (this.WindowsSelectionstyle ? 'windowsedit' : 'edit') : 'text';
        if (this.ColMgr[cix]) {
            cmd = this.ColMgr[cix].cmd;
            extra = this.ColMgr[cix].extra;
        }
        name = "." + vals[cix].getAttribute('name');
        var colmgr = new Qva.ColMgr[cmd] (this, cix, cell, name, this.PageName, extra);
                
        colmgr.Cmd = cmd;
        if (this.Group == null) this.PageBinder.Append (this, colmgr.Name, null, true);
        this.ColDict [colmgr.Name] = colmgr;
        this.ColList [this.ColList.length] = colmgr;
    }

    if (tottablewidth != 0) {
        this.getTableElement ().style.width = tottablewidth + "pt";
    }
    
    bodyParent.replaceChild (body, this.Body);
    this.Body = body;
    if (this.AllwaysFullWidth) {
        if ((IS_IE && IE_VERSION < 8) || IE_DOCMODE <= 7) {
            this.Element.style.width = "auto";
        } else {
            this.Element.style.width = "100%";
        }
    }
}

Qva.Mgr.table.prototype.AppendIfMissing = function(list, entry) {
    var len = list.length;
    for (var six = 0; six < len; ++six) {
        if (list [six] == entry) return;
    }
    list [len] = entry;
}

Qva.PageBinding.prototype.CreateTransientListBox = function (name) {

    var frame = document.createElement ("div");
    frame.style.cssText = "z-index: 100; display: none; left: 10pt; top: 10pt; width: 10pt; height: 800pt; position:absolute;";
    frame.className = "Frame DS";

    var body = document.createElement ("div");
    body.className = "body";

    var table = document.createElement ("table");
    table.style.cssText = "background-color: White;";
    table.setAttribute ("avqbody", "true");

    if (IS_GECKO || IS_SAFARI || IS_OPERA || IS_CHROME) {
        table.style.cssText += "width: 100%;";
    } else {
        table.style.cssText += "width: auto;";
    }
    table.setAttribute ("avqasync", "40:" + name);
    table.id = "DS";

    body.appendChild (table);
    frame.appendChild (body);
    document.body.appendChild (frame);

    new Qva.Mgr.label (this, frame, name);
    new Qva.Mgr.table (this, table);
}


Qva.Mgr.table.prototype.ModifyAltClasses = function (altclass, node) {
    var binder = this.PageBinder;
    for (var i = 0; i < document.styleSheets.length; i++) {
        var rules;
        try {
            rules = document.styleSheets[i].rules ? document.styleSheets[i].rules : document.styleSheets[i].cssRules;
        } catch (Error) { continue; }
        if (altclass == "LED") {
            for (var is = 0; is < rules.length; is++) {
                var style = rules[is];
                var state = null;
                var url = null;
                if (style.selectorText == (".AvqSelected_" + altclass)) {
                    if (!binder.Unicorn && binder.IsHosted) {
                        url = binder.BuildBinaryUrl (binder.ImageFolder + "HSI.png", "0", "HSI");
                    } else {
                        state = "AvqSelected";
                    }
                }
                if (style.selectorText == (".AvqDisabled_" + altclass)) {
                    if (!binder.Unicorn && binder.IsHosted) {
                        url = binder.BuildBinaryUrl (binder.ImageFolder + "IEI.png", "0", "IEI");
                    } else {
                        state = "AvqDisabled";
                    }
                }
                if (style.selectorText == (".AvqEnabled_" + altclass)) {
                    if (!binder.Unicorn && binder.IsHosted) {
                        url = binder.BuildBinaryUrl (binder.ImageFolder + "HOI.png", "0", "HOI");
                    } else {
                        state = "AvqEnabled";
                    }
                }
                if (style.selectorText == (".AvqLocked_" + altclass)) {
                    if (!binder.Unicorn && binder.IsHosted) {
                        url = binder.BuildBinaryUrl (binder.ImageFolder + "ILI.png", "0", "ILI");
                    } else {
                        state = "AvqLocked";
                    }
                }
                if (state != null) {
                    if (!binder.Unicorn && binder.IsHosted) debugger;
                    for (var memb = node.firstChild; memb; memb = memb.nextSibling) {
                        if (memb.getAttribute ("name") == state) {
                            url = binder.BuildBinaryUrl (binder.ImageFolder + altclass + ".png", null, altclass, memb.getAttribute ("color"));
                            break;
                        }
                    }
                }
                if (url == null) continue;
                style.style.backgroundImage = "url(" + url + ")";
            }
        } else {
            debugger;
        }
    }
}

Qva.Mgr.table.prototype.Paint = function (mode, node, name, partial) {
    this.debugcounter = 0;
    this.Touched = true;
    var NodeWithAttributes = (this.Name == name || this.PageName == name) ? node : node.parentNode;
    var WindowsSelectionstyle = NodeWithAttributes.getAttribute ("windowsselectionstyle") == "true";
    if (this.WindowsSelectionstyle != null && this.WindowsSelectionstyle != WindowsSelectionstyle) {
        this.Width = 0;
    }
    this.WindowsSelectionstyle = WindowsSelectionstyle;
    var owner = NodeWithAttributes.getAttribute ('owner');
    this.Height = -1;
    if (owner) {
        var row = parseInt (NodeWithAttributes.getAttribute ('row'));
        var col = parseInt (NodeWithAttributes.getAttribute ('col'));
        if (this.Owner && (this.Owner != owner || this.OwnerRow != row || this.OwnerCol != col)) {
            while (this.Body.rows.length > 0) {
                this.Body.deleteRow (this.Body.rows.length - 1);
            }
            this.ByValue = null;
            this.Fixed = false;
            this.getTableElement ().style.width = "";
        }
        this.Owner = owner;
        this.OwnerRow = row;
        this.OwnerCol = col;
        this.IsTransient = true;
        this.PageBinder.TransientObject = this.PageName;
        var ownerelement = document.getElementById (this.Owner);
        if (! ownerelement) {
            var legacyname = this.Owner + this.OwnerRow;
            ownerelement = document.getElementById (legacyname);
        }
        if (ownerelement && (ownerelement.nodeName == "TABLE" || ownerelement.nodeName == "TD")) {
            var left;
            var width;
            var top;
            if (ownerelement.nodeName == "TD") {
                left = ownerelement.offsetLeft;
                width = ownerelement.offsetWidth;
                top = ownerelement.offsetTop + ownerelement.offsetHeight;
                var offsetparent = ownerelement.offsetParent;
                while (offsetparent) {
                    left += offsetparent.offsetLeft;
                    top += offsetparent.offsetTop;
                    offsetparent = offsetparent.offsetParent;
                }
            } else if (ownerelement.nodeName == "TABLE") {
                if (this.OwnerRow == -1 && this.OwnerCol == -1) {
                    left = ownerelement.offsetLeft;
                    width = ownerelement.offsetWidth;
                    top = ownerelement.offsetTop + ownerelement.offsetHeight;
                    var offsetparent = ownerelement.offsetParent;
                    while (offsetparent) {
                        left += offsetparent.offsetLeft;
                        top += offsetparent.offsetTop;
                        offsetparent = offsetparent.offsetParent;
                    }
                } else {
                    if (ownerelement.rows.length > this.OwnerRow) {
                        var cell = ownerelement.rows[this.OwnerRow].cells [this.OwnerCol];
                        if (cell) {
                            if (cell.offsetWidth > 0) {
                                top = cell.offsetTop + cell.offsetHeight;
                                var ismultibox = false;
                                if (cell.offsetWidth < 23) {
                                    // Difference between multiboxes and otheer tables
                                    cell = ownerelement.rows[this.OwnerRow].cells [this.OwnerCol + 1];
                                    top = cell.offsetTop;
                                    ismultibox = true;
                                }
                                left = 2 + cell.offsetLeft;
                                width = cell.offsetWidth - 4;
                                var offsetparent = cell.offsetParent;
                                while (offsetparent) {
                                    left += offsetparent.offsetLeft;
                                    top += offsetparent.offsetTop;
                                    offsetparent = offsetparent.offsetParent;
                                }
                                top++;
                                if (! ismultibox) left -= 10;
                                width += 10;
                            }
                        }
                    }
                }
            }
            if (! isNaN (left)) {
                left -= (ownerelement.parentNode.scrollLeft - Qva.GetScrollLeft ());
                var height = 0;
                var offsetparent = ownerelement;
                while (offsetparent) {
                    height = offsetparent.offsetHeight;
                    offsetparent = offsetparent.offsetParent;
                }
                height -= (top - Qva.GetScrollTop ());
                // Take tabs into consideration
                if (height > 80) height -= 40;
                this.Frame.style.left = left + "px";
                this.Frame.style.top = top + "px";
                if (height > 0) {
                    if (this.Frame.maxclientheight != height) { 
                        this.Frame.maxclientheight = height;
                        setFrameHeight (this.Frame, 0);
                    }
                }
                if (this.Frame.maxclientwidth != width) { 
                    this.Frame.maxclientwidth = width;
                    setFrameWidth (this.Frame, 0);
                }
            }
        } else {
            debugger;
        }
    } else if (this.IsTransient) {
        this.Frame.maxclientwidth = null;
        this.Frame.maxclientheight = null;
        this.Element.parentNode.style.height = "";
        this.Element.parentNode.style.width = "";
        this.LastColWidth = null;
        this.PageBinder.TransientObject = "";
    }
    
    
    this.Searchable = NodeWithAttributes.getAttribute ("searchable") == "true";

    var element = this.Element;
    try {
        var newmode = Qva.MgrGetDisplayFromMode (this, mode);
        var colmgr = this.ColDict[name];
        if (colmgr == null) {
            if (newmode != element.style.display) {
                element.style.display = newmode;
            }
        } else if (newmode == 'none') {
            if (colmgr.Index != 0) {
                for (var rix = 0; rix < this.Lines.length && this.Lines [rix]; ++rix) {
                    this.Lines [rix][colmgr.Index] = null;
                }
            }
            return;
        }
    } catch (e) {
        debugger
    }
    element.disabled = (mode != 'e');
    if (this.InlineStyle) setStyle (node, element);
    var sortable = node.parentNode.getAttribute ('issortable');
    if (sortable && sortable == 'true') this.sortable = true;
    if (this.InlineStyle) {
        var stylenodes = node.getElementsByTagName ('style');
        if (stylenodes.length == 0) stylenodes = node.parentNode.getElementsByTagName ('style');
        if (stylenodes.length > 0) {
            stylenodes = stylenodes[0].getElementsByTagName ('style');
            for (var istyle = 0; istyle < stylenodes.length; istyle++) {
                this.Style [istyle] = new this.StyleObject (stylenodes [istyle]);
            }
        }
        stylenodes = node.getElementsByTagName ('borderstyle');
        if (stylenodes.length == 0) stylenodes = node.parentNode.getElementsByTagName ('borderstyle');
        if (stylenodes.length > 0) {
            stylenodes = stylenodes[0].getElementsByTagName ('borderstyle');
            for (istyle = 0; istyle < stylenodes.length; istyle++) {
                this.BorderStyle [istyle] = new this.BorderStyleObject (stylenodes [istyle]);
            }
        }
    }
    if (node.getAttribute ("menu") == "true") {
        this.Menu = true;
    }
    this.Dirty = true;
    if (this.Group == name) {
        var entries = node.childNodes;
        var height = entries.length;
        if (height > this.TableLimit) {
            TableTruncateAlert (this.Name, height);
            height = this.TableLimit;
        }
        var rowsskipped = 0;
        for (rix = 0; rix < height; ++ rix) {
            var entry = entries [rix];
            if (this.ByValue == null) {
                this.ByValue = (entry.getAttribute("value") != null);
            }
            var position = entry.getAttribute ('position');
            if (this.IsHeader) {
                if (! position == 'top') continue;
                if (! position) break;
            }
            if (this.IsBody) {
                if (position) {
                    rowsskipped++
                    continue;
                }
            }
            var actualrow = rix - rowsskipped;
            if (actualrow >= this.Lines.length) {
                this.Lines [actualrow] = new Array ();
            }
            var header = entry.getAttribute ('isheader');
            if (header && header == 'true') this.Lines [actualrow].IsHeader = true;
            this.IsPainted [actualrow] = false;
            var values = entry.childNodes;
            var width = values.length;
            for (var cix = 0; cix < width; ++ cix) {
                var value = values [cix];
                name = value.getAttribute ("name");
                for(var colix in this.ColList) {
                    var colmgr = this.ColList[colix];
                    if (colmgr.Name != name) continue;
                    var optval = value.getAttribute (colmgr.Attr);
                    if (colmgr.Dec != null) optval = Qva.Trunc (optval, colmgr.Dec);
                    this.Lines[actualrow][colmgr.Index] = new this.CellObject (optval, value);
                }
            }
        }
        this.Lines.length = height;
        this.TotalSize = height;
        return;
    }
    this.AndMode = NodeWithAttributes.getAttribute ("andmode") == "true";
    this.Semantic = NodeWithAttributes.getAttribute ("semantic") == "true";
    var AltClass = NodeWithAttributes.getAttribute ("altclass");
    if (AltClass != this.AltClass) {
        this.AltClass = AltClass;
        this.ModifyAltClasses (this.AltClass, NodeWithAttributes.getElementsByTagName (this.AltClass) [0]);
    }
    this.SizeTodata = NodeWithAttributes.getAttribute ("sizetodata") == "true" && this.AutoCol; 
    this.SupressHorizontalScroll = NodeWithAttributes.getAttribute ("suppresshorizontalscroll") == "true" && this.AutoCol;
    if (this.IsBody) {
        if (this.SupressHorizontalScroll && this.IsBody) {
            element.parentNode.style.overflowX = "hidden";
        } else {
            element.parentNode.style.overflowX = "auto";
        }
    }
    this.Fixed = false;
    if (this.PageName == "" || this.PageName == name) {
        this.ChunkOffset = parseInt (NodeWithAttributes.getAttribute ("pageoffset"));
        this.ChunkSize = parseInt (NodeWithAttributes.getAttribute ("pagesize"));
        this.TotalSize = parseInt (NodeWithAttributes.getAttribute ("totalsize"));
        var inflatesize = Math.max (500, this.ChunkSize);
        if (isNaN (this.EffectiveSize) || this.EffectiveSize < inflatesize) this.EffectiveSize = inflatesize;
        if (this.ChunkOffset + this.ChunkSize >= inflatesize) {
            this.EffectiveSize += inflatesize;
        }
        if (this.EffectiveSize > this.TotalSize) this.EffectiveSize = this.TotalSize;
        if (this.IsAsync) {
            if (! partial) {
                this.Lines.length = 0;
                for (var ix = 0; ix < this.IsPainted.length; ix ++) {
                    this.IsPainted [ix] = false;
                }
                if (this.ChunkOffset == 0) {
                    this.ScrollParent.scrollTop = 0;
                }
            }
            if (this.TotalSize == 0) return;
        }
    }
    if (this.Name == name) {
        this.Current = node.getAttribute ("text");
        if (this.Current != null) return;
        entries = node.getElementsByTagName ('choice');
        var checkSelected = entries.length >= 1;
        if (checkSelected) {
            entries = entries[0].getElementsByTagName ('element');
        } else {
            entries = node.getElementsByTagName ('element');
        }
        height = entries.length;

        if (this.IsAsync && partial) {
            for (rix = 0; rix < height; ++rix) {
                entry = entries [rix].getAttribute("text");
                if (!checkSelected || entries [rix].getAttribute("selected") == "yes") {
                    this.AppendIfMissing(this.Selected, entry);
                }
            }
        } else {
            var selix = 0;
            var disix = 0;
            var lckix = 0;
            for (rix = 0; rix < height; ++rix) {
                entry = entries [rix].getAttribute("text");
                if (!checkSelected || entries [rix].getAttribute("selected") == "yes") {
                    this.Selected [selix++] = entry;
                }
            }
            this.Selected.length = selix;
        }
        {
            entries = node.getElementsByTagName ("choice");
            if (entries.length >= 1) entries = entries[0].getElementsByTagName ("element");
            height = entries.length;
            
            if(0 < height && this.ByValue == null) {
                this.ByValue = (entries[0].getAttribute("value") != null);
            }
        }
        if (this.ByValue == true) {
            if (this.AllValues == null) this.AllValues = new Array ();
            var entries = node.getElementsByTagName ("choice");
            if (entries.length >= 1) entries = entries[0].getElementsByTagName ("element");
            var height = entries.length;
            if (this.IsAsync) {
                if (! partial) {
                    this.AllValues.length = this.EffectiveSize;
                }
                var ChunkOffset = this.ChunkOffset;
                for (var rix = 0; rix < height; ++rix) {
                    this.AllValues [rix + ChunkOffset] = entries [rix].getAttribute("value");
                }
            } else {
                this.AllValues.length = height;
                for (var rix = 0; rix < height; ++rix) {
                    this.AllValues [rix] = entries [rix].getAttribute("value");
                }
            }
        }
    }
    if (this.PageName == name && this.AutoCol && mode != 'h') {
        this.FixCol(mode, node, name, partial);
    }
    if (this.Name == "" && this.PageName == name) {
        // navigation has been updated, that is enough
        return;
    }
    var colmgr = this.ColDict[name];
    if (colmgr == null) {
        alert ('PaintTable unknown name:' + name);
        return;
    }
    var xIx = (this.Name == name && colmgr.Index != 0) ? 0 : -1;
    var entries;
    if(this.Name != name) {
        entries = node.getElementsByTagName('element');
    } else {
        entries = node.getElementsByTagName ("choice");
        if (entries.length >= 1) entries = entries[0].getElementsByTagName ("element");
    }
    var height = entries.length;
    if (height > this.TableLimit) {
        TableTruncateAlert (this.Name, height);
        height = this.TableLimit;
    }
    var rowsskipped = 0;
    var full_rix = 0;
    for (var rix = 0; rix < height; ++rix) {
        var entry = entries [rix];
        var optval = entry.getAttribute("text");
        var position = entry.getAttribute ('position');
        if (this.IsHeader) {
            if (! position == 'top') continue;
            if (! position) break;
        }
        if (this.IsBody) {
            if (position) {
                rowsskipped++
                continue;
            }
        }
        full_rix = rix - rowsskipped;
        if (this.IsAsync) {
            full_rix += this.ChunkOffset;
        }
        if (this.Lines [full_rix] == null) this.Lines [full_rix] = new Array ();
        var header = entry.getAttribute ('isheader');
        if (header && header == 'true') this.Lines [full_rix].IsHeader = true;
        this.IsPainted [full_rix] = false;
        this.Lines [full_rix][colmgr.Index] = new this.CellObject (optval, entry);
        if (xIx >= 0) this.Lines [full_rix][xIx] = new this.CellObject (optval, entry);
    }
    if (! this.IsAsync && height > 0) {
        this.Lines.length = full_rix + 1;
    }
    if (height == 0) {
        this.Lines.length = 0;
    }
}

Qva.Mgr.table.prototype.StyleObject = function (node) {
    this.BgColor = node.getAttribute ('bgcolor');
    this.Color = node.getAttribute ('color');
    this.NumAdjust = node.getAttribute ('numadjust');
    this.TextAdjust = node.getAttribute ('textadjust');
    this.BorderStyle = node.getAttribute ('borderstyle');
    var fontstyle = node.getAttribute ('fontstyle')
    this.FontStyle = fontstyle;
    this.FontWeight = node.getAttribute ('fontweight');
    this.TextDecoration = node.getAttribute ('textdecoration');
    this.SizeMod = node.getAttribute ('sizemod');
    var stretchmode = node.getAttribute ('stretchmode');
    if (stretchmode) this.StretchMode = stretchmode;
}

Qva.Mgr.table.prototype.BorderStyleObject = function (node) {
    this.Top = node.getAttribute ('top');
    this.Bottom = node.getAttribute ('bottom');
    this.Left = node.getAttribute ('left');
    this.Right = node.getAttribute ('right');
}

Qva.Mgr.table.prototype.GetIndex = function (line) {
    if (this.ChoiceIx < 0) return 0;
    var val = line [this.ChoiceIx].val;
    if (this.Current != null) {
        return (this.Current === val) ? 1 : 0;
    }
    for (var ix = 0; ix < this.Selected.length; ++ix) {
        if (this.Selected [ix] === val) return 1;
    }
    return 0;
}

Qva.Mgr.table.prototype.GetSelected = function (rix, cix) {
    var line = this.Lines [rix];
    return line[cix] ? line[cix].selected : false;
}

Qva.Mgr.table.prototype.GetDisabled = function (rix, cix) {
    var line = this.Lines [rix];
    return line [cix] ? line [cix].disabled : true;
}

function AvqAction_TableCheck () {
    var box = this;
    var row = box.parentNode.parentNode;
    if (row.tagName != 'TR') return;
    var mgr = row.parentNode.AvqMgr;
    if (mgr == null) mgr = row.parentNode.parentNode.AvqMgr;
    if (mgr == null) return;
    if (! mgr.PageBinder.Enabled) return;
    var selIx = row.rix;
    var SearchActive = (mgr.Search != null && mgr.Search.value != '');
    var valName = (mgr.Count != null) ? mgr.Count : mgr.Name;
    if (mgr.ByValue && mgr.PageBinder.Autoview != null) {
        // This code is not bw compat, check against AvqAutoView for "QlikView-only" activation
        // There is no other logical connection with AvqAutoView
        var ixVal = mgr.AllValues [selIx];
        mgr.PageBinder.Set (valName, 'count', (box.checked ? ' ' : '-') + ixVal, ! SearchActive);
    } else if (mgr.ChoiceIx != -1)  {
        var ixName = mgr.Lines [selIx][mgr.ChoiceIx].val;
        mgr.PageBinder.Set (valName, 'count', (box.checked ? ' ' : '-') + ixName, ! SearchActive);
    } else {
        var colname = mgr.ColList[box.parentNode.cellIndex].Name;
        mgr.PageBinder.Set (mgr.Group, 'cell', selIx + ':' + colname + ':' + (box.checked ? '1' : '0'), ! SearchActive);
    }
    if (SearchActive) {
        mgr.PageBinder.Set (mgr.SearchName, "closesearch", "abort", true);      // break out of search mode
        if (mgr.Search != null) mgr.Search.value = '';				// Allow for popup search being closed
    }
}

function AvqAction_TableInput () {
    var box = this;
    var row = box.parentNode.parentNode;
    if (row.tagName != 'TR') return;
    var mgr = row.parentNode.AvqMgr;
    if (mgr == null) mgr = row.parentNode.parentNode.AvqMgr;
    if (mgr == null) return;
    if (! mgr.PageBinder.Enabled) return;
    var selIx = row.rix;
    var colname = mgr.ColList[box.parentNode.cellIndex].Name;
    mgr.PageBinder.Set (mgr.Group, 'cell', selIx + ':' + colname + ':' + box.value, true);
}

Qva.Mgr.table.prototype.appendCellIcon = function (icon, cix, rix, stretchmode, adjust, colmgr) {
    var img = document.createElement ("img");
    var style = 'cursor: pointer;';
    var iconstyle = icon.getAttribute ("iconstyle");
    var alttext = icon.getAttribute ("alttext");
    img.alt = alttext ? alttext : "";
    if (iconstyle != null) {
        style += ' left:0px; top:0px; ' + iconstyle;
    } else {
        style += ' float:right; top:2px; right:1px; position:relative;';
    }
    var stamp = icon.getAttribute ("stamp");
    var sendsizetoserver = icon.getAttribute ("sendsize") == "true";
    if (sendsizetoserver) {
        if (colmgr.CellHeight == -1 || colmgr.CellWidth == -1) debugger;
        style += "height:" + colmgr.CellHeight + "px; width:" + colmgr.CellWidth + "px; ";
    }
    img.style.cssText = style;
    
    var url = icon.getAttribute ("url");
    if (url) {
        img.src = url;
    } else {
        var name = icon.getAttribute ("name");
        var stamp = icon.getAttribute ("stamp");
        var color = icon.getAttribute ("color");
        var url = this.PageBinder.BuildBinaryUrl (icon.getAttribute ("path"), stamp, name, color);
        if (! this.PageBinder.IsHosted && sendsizetoserver) {
            url += "&width=" + colmgr.CellWidth + "&height=" + colmgr.CellHeight + "&stretchmode=" + stretchmode + "&adjust=" + adjust;
        }
        img.src = url;
        
        var action       = icon.getAttribute ("action");
        var clientaction = icon.getAttribute ("clientaction");
        var drag         = icon.getAttribute ("drag");
        if (action || clientaction) {
            var binder = this.PageBinder;
            img.binderid = this.PageBinder.ID;
            if (action) {
                img.onmousedown = avq_action_md;
                img.onmouseup = avq_action_mu;
                img.pressed = false;
                img.action = action;
            } else if (clientaction) {
                img.onmousedown = Qva.CancelAction;
                img.onmouseup = Qva.CancelAction;
                img.onclick = onclick_ContextClientAction;
                img.AvqMgr = this;
                img.clientaction = clientaction;
                img.param = icon.getAttribute ("param");
            }
            var targetname = colmgr.Name.split ('.') [1];
            img.targetname = targetname;
            img.xx = cix;
            img.yy = rix;
            if (icon.getAttribute ("menu") == "true") {
                img.position = action + ":" + cix + ":" + rix;
                img.oncontextmenu = function (event) { 
                    this.pressed = false;
                    return Qva.GetBinder(this.binderid).OnContextMenu(event, this.Name); 
                }
            }
        } else if(drag) {
            img.dragObj = { 'Name': this.PageName, 'type': "col" };
        } else {
            img.ondrag = function () { return false; };
            img.onmousedown = Qva.NoAction;
            img.onmouseup = Qva.NoAction;
            img.onclick = Qva.NoAction;
        }
    }
    return img;
}

Qva.Mgr.table.prototype.appendCellContent = function (cell, data, text, cix, rix, colmgr) {
    if (! this.ByValue) rix += this.HeaderRowCount + this.PageOffsetForPainting ();
    var level = parseInt (data.level);
    if (! isNaN (level)) {
        var level = parseInt (data.level);
        var paddingleft = cell.origpadding;
        if (isNaN (cell.origpadding)) {
            if (IS_GECKO || IS_SAFARI || IS_OPERA || IS_CHROME) {
                var gs = document.defaultView.getComputedStyle (cell, "");
                paddingleft = parseInt (gs.getPropertyValue ("padding-left"));
            } else {
                paddingleft = parseInt (cell.currentStyle.paddingLeft);
            }
            cell.origpadding = paddingleft;
        } else {
            paddingleft = cell.origpadding;
        }
        for (var i = 0; i < parseInt (data.level); i++) paddingleft += 10;
        cell.style.paddingLeft = paddingleft + "px";
    }
    cell.innerHTML = "";
    var textalign = "left";
    var style = this.Style [data.style];
    var stretchmode = null;
    if (style) {
        textalign = data.isnum ? style.NumAdjust : style.TextAdjust;
        stretchmode = style.StretchMode;
    }
    if (data.frequency) {
        if (textalign != "right") {
            var span = document.createElement ("span");
            span.innerText = data.frequency;
            span.style.position = "absolute";
            span.style.textAlign = "right";
            cell.appendChild  (span);
            var left = cell.offsetLeft - span.offsetWidth - 1;
            if (colmgr.CellWidth != -1) {
                left += colmgr.CellWidth;
            } else {
                left += cell.offsetWidth;
                debugger;
            }
            if (IS_GECKO || IS_OPERA) {
                left -= 3;
            }
            span.style.left = left + "px";
        } else {
            text += "  " + data.frequency;
        }
    }
    for (var iicons = 0; iicons < data.icons.length; iicons++) {
        var icon = data.icons [iicons];
        var iconelem = this.appendCellIcon (icon, cix, rix, stretchmode, textalign, colmgr);
        cell.appendChild (iconelem);
    }
    if (data.parts && data.parts.length > 0) {
        var currentpos = 0;
        var currentpart = 0;
        while (text != "") {
            var part = data.parts [currentpart++];
            if (part) {
                var partpos = parseInt (part.getAttribute ("pos"));
                var partcount = parseInt (part.getAttribute ("count"));
                if (partpos > currentpos) {
                    var span = document.createElement ("span");
                    span.innerText = text.substr (0, partpos - currentpos);
                    text = text.substr (partpos - currentpos)
                    currentpos = partpos;
                    cell.appendChild (span);
                } 
                var span = document.createElement ("span");
                span.innerText = text.substr (0, partcount);
                text = text.substr (partcount)
                currentpos += partcount;
                span.className = "qvHighLighted";
                cell.appendChild (span);
            } else {
                var span = document.createElement ("span");
                span.innerText = text;
                cell.appendChild (span);
                text = "";
            }
        }
    } else {
        var textnode = document.createTextNode (text);
        cell.appendChild (textnode);
    }
}

Qva.Mgr.table.prototype.GetScrollWidth = function () {
    if (IS_MAC) {
        return 15;
    } else {
        return 17;
    }
}

Qva.Mgr.table.prototype.GetScrollHeight = function () {
    if (IS_MAC) {
        return 15;
    } else {
        return 17;
    }
}

Qva.Mgr.table.prototype.HasHorizontalScrollbar = function () {
    return getClientWidth (this.Frame) < this.Element.offsetWidth && ! this.SupressHorizontalScroll;
}

Qva.Mgr.table.prototype.HasVerticalScrollbar = function (maxheight, scrollheight) {
    var numberofrows = isNaN (this.TotalSize) ? this.Lines.length : this.TotalSize;
    var calculatedscrollheight = this.RowHeight * numberofrows;
    var HasVerticalScrollbar = (maxheight - scrollheight) < calculatedscrollheight;
    HasVerticalScrollbar = HasVerticalScrollbar || this.Element.offsetHeight > (maxheight - scrollheight);
    return HasVerticalScrollbar;
}

Qva.Mgr.table.prototype.FixTableWidth = function (header) {
    if (this.Lines.length > 0 && this.getTableElement ().offsetWidth < 10) debugger;
    var scrollheight = 0;
    if (this.HasHorizontalScrollbar ()) {
        scrollheight = this.GetScrollHeight ();
    }
    var HasVerticalScrollbar = this.HasVerticalScrollbar (parseInt (getContentMaxHeight (this.ScrollParent)), scrollheight);
    var scrollwidth = 0;
    if (HasVerticalScrollbar) {
        scrollwidth = this.GetScrollWidth ();
    }

    var maxwidth = getMaxClientWidth (this.Frame);
    var delta = maxwidth - this.UnmodifiedTableWidth;
    var modifylastcolumn = this.SupressHorizontalScroll && delta < 0 || (delta > 0 && delta < scrollwidth);

    var lastheadercells = new Array ();
    if (header) {
        for (var i = 0; i < header.rows.length; i ++) {
            if (header.rows [i].cells [this.Width - 1]) {
                lastheadercells [lastheadercells.length] = header.rows [i].cells [this.Width - 1];
            }
        }
    }
    var newscrollwidth = maxwidth;
    var newheaderwidth = newscrollwidth;
    var lastheadercellfixed = false;
    if (this.Body.rows.length > 0) {
        var cell = this.Body.rows[0].cells [this.Width - 1];
        if (modifylastcolumn) {
            cell.style.width = "";
            for (var i = 0; i < lastheadercells.length; i ++) {
                lastheadercells [i].style.width = "";
            }
            if (this.SupressHorizontalScroll) {
                this.getTableElement ().style.width = (newscrollwidth - scrollwidth) + "px";
            } else {
                debugger;
            }
        } else {
            cell.style.width = this.LastColWidth;
            if (this.m_HasVerticalScrollbar != HasVerticalScrollbar) {
                this.getTableElement ().style.width = this.UnmodifiedTableWidth + "px";
            }
            if (! HasVerticalScrollbar) {
                for (var i = 0; i < lastheadercells.length; i ++) {
                    lastheadercells [i].style.width = this.LastColWidth;
                }
            }
            if (! this.SizeTodata && this.getTableElement ().offsetWidth < newscrollwidth) {
                newheaderwidth = this.getTableElement ().offsetWidth;
                if ((IS_CHROME || IS_GECKO || IS_SAFARI) && lastheadercells.length > 0) {
                    if (parseInt (lastheadercells [0].style.width) != parseInt (this.LastColWidth)) {
                        for (var i = 0; i < lastheadercells.length; i ++) {
                            lastheadercells [i].style.width = this.LastColWidth;
                        }
                    }
                    lastheadercellfixed = true;
                }
                scrollwidth = 0;
            } else if (this.SupressHorizontalScroll) {
                newheaderwidth = this.UnmodifiedTableWidth;
                this.getTableElement ().style.width = this.UnmodifiedTableWidth + "px";
                if (this.SizeTodata) {
                    newheaderwidth += scrollwidth;
                    newscrollwidth = newheaderwidth;
                }
                if (scrollwidth != 0) {
                    scrollwidth++
                }
            } else if (this.getTableElement ().offsetWidth < newscrollwidth) {
                if (this.SizeTodata) {
                    newscrollwidth = this.getTableElement ().offsetWidth;
                    newscrollwidth += scrollwidth;
                    newheaderwidth = newscrollwidth;
                } else {
                    debugger;
                }
            } else {
                // Horizontal scrollbar
                newheaderwidth = Math.max (this.getTableElement ().offsetWidth, 1);
                newheaderwidth += scrollwidth;
                if (scrollwidth != 0) {
                    scrollwidth++
                }
            }
        } 
    } else {
        // No data cells
        if (modifylastcolumn) {
            for (var i = 0; i < lastheadercells.length; i ++) {
                lastheadercells [i].style.width = "";
            }
        } else {
            newscrollwidth = this.UnmodifiedTableWidth;
            newheaderwidth = this.UnmodifiedTableWidth;
        }
    }
    if (header) {
        header.style.width = newheaderwidth + "px";
        if (lastheadercells.length > 0) {
            if (IS_GECKO || IS_SAFARI || IS_CHROME) {
                var bodycell = this.Body.rows [0] ? this.Body.rows [0].cells [this.Width - 1] : null;
                if (bodycell) {
                    if (HasVerticalScrollbar && ! (this.SupressHorizontalScroll && modifylastcolumn) && ! lastheadercellfixed) {
                        var cellwidth = getClientWidth (bodycell);
                        if (parseInt (lastheadercells [0].style.width) != cellwidth) {
                            for (var i = 0; i < lastheadercells.length; i ++) {
                                lastheadercells [i].style.width = cellwidth + "px";
                            }
                        }
                    }
                } else {
                    debugger;
                }
            }
            var rightpadding = scrollwidth != 0 ? scrollwidth + "px" : "";
            if (parseInt (lastheadercells [0].style.paddingRight) != parseInt (rightpadding)) {
                for (var i = 0; i < lastheadercells.length; i ++) {
                    lastheadercells [i].style.paddingRight = scrollwidth != 0 ? scrollwidth + "px" : "";
                }
            }
        }
    }
    
    var deltaframeX = maxwidth - newscrollwidth;
    setFrameWidth (this.Frame, deltaframeX);
    var resetpaint = this.m_HasVerticalScrollbar != null && ! this.m_HasVerticalScrollbar && HasVerticalScrollbar;
    setContentWidth (this.Frame, newscrollwidth);
    if (this.ScrollBar && this.SizeTodata) { 
        this.getTableElement ().style.width = (newscrollwidth - scrollwidth) + "px";
        var table = this.getTableElement();
        var element = this.Element;
        setTimeout(function() {
            element.style.width = table.offsetWidth + "px"; 
            //alert("x: " + table.offsetWidth);
        }, 1);
    }
    this.m_HasVerticalScrollbar = HasVerticalScrollbar;
    return resetpaint;
}


Qva.Mgr.table.prototype.FixTableHeight = function () {
    var objectframeclientheight = getMaxClientHeight (this.Frame);
    var maxscrollheight = getContentMaxHeight (this.ScrollParent);
    var newscrollheight = maxscrollheight;
    if (this.ScrollParent.clientHeight == 0 && this.Element.offsetHeight == 0) {
        return;
    }
            
    if (this.SizeTodata) {
        var realHeight, sParent;
        if(this.ScrollBar && this.Body.rows.length > 0) {
            realHeight = this.RowHeight * this.ScrollBar.TotalRows;
            realWidth = this.Element.getElementsByTagName("table")[0].offsetWidth;
            sParent = this.Element;
        } else {
            realHeight = this.Element.offsetHeight;
            realWidth = this.Element.offsetWidth
            sParent = this.ScrollParent;
        }
        if (realHeight < newscrollheight) {
            var hashorizontalscrollbar = getClientWidth (this.Frame) < realWidth && ! this.SupressHorizontalScroll;
            newscrollheight = realHeight;
            if (hashorizontalscrollbar) {
                var scrollheight = sParent.offsetHeight - sParent.clientHeight;
                newscrollheight += scrollheight;
            }
        }
    } else {
//                debugger;
    }
    var deltaframeY = maxscrollheight - newscrollheight;
    if (parseInt (this.ScrollParent.style.height) != newscrollheight) {
        if (isNaN(newscrollheight)) {
            this.ScrollParent.style.height = "1px";
        } else {
            this.ScrollParent.style.height = Math.max (newscrollheight, 1) + "px";
        }
    }
    setFrameHeight (this.Frame, deltaframeY);
    if (this.ScrollBar) {
        var cellheight = this.RowHeight == -1 ? this.Body.rows [0].cells [0].offsetHeight : this.RowHeight;
        
        var scrollBar = this.ScrollBar;
        setTimeout(function() {
            scrollBar.Height = getClientHeight(this.ScrollParent);
        }, 1);
        this.Element.style.height = "auto";
        this.Element.parentNode.style.height = "auto";
        var maxRows = Math.max(1, Math.min(this.TotalSize, Math.floor(getContentMaxHeight(this.ScrollParent) / cellheight)));
        if(this.ScrollBar.VisibleRows != maxRows || this.ScrollBar.TotalRows != this.TotalSize) {
            this.ScrollBar.UpdateSize(this.TotalSize, maxRows);
            postpaintposted = true;
            Qva.QueuePostPaintMessage (this);
            return;
        }
    }
}


Qva.Mgr.table.prototype.PostPaint = function () {
    this.debugcounter++;
    if (this.debugcounter > 50) {
        debugger;
        this.debugcounter = 0;
        return;
    }
    
    if (this.Lines == null) return;
    if (!this.ScrollParent || (this.ScrollParent.style && this.ScrollParent.style.display == 'none')) {
        this.Fixed = true;
        return;
    }
    
    if (this.RowHeight <= 0 && this.Body.rows [0] && this.Body.rows [0].cells [0]) {
        if (this.Lines.length > 0 && this.Lines [0].length > 0) {
            if (this.Body.rows [0].cells [0].offsetHeight > 0) {
                if (IS_GECKO || IS_OPERA) {
                    this.RowHeight = this.Body.rows [0].offsetHeight;
                } else {
                    this.RowHeight = getClientHeight (this.Body.rows [0].cells [0]);
                }
                if (this.IsBody && this.ScrollBar) {
                    //this.ScrollBar.UpdateSize(this.TotalSize, getContentMaxHeight (scrollParent) / this.RowHeight);
                    //this.ScrollBar.UpdateHeight (getContentMaxHeight (scrollParent));
                    this.ScrollBar.UpdateSize(this.TotalSize, 1); 
                }
            }
        }
    }
    if (this.Frame.style && this.Frame.style.display == 'none') return;
    var WantedChunkNumber = null;
    var postpaintposted = false;
    var header = this.Element.Header;
    var lastheadercell = null;
    if (header != null) {
        if (header != this.Element) {
            if (! header.AvqMgr.Fixed) {
                Qva.QueuePostPaintMessage (this);
                return;
            }
            lastheadercell = header.rows [0] ? header.rows [0].cells [this.Width - 1] : null;
        } else {
            debugger;
        }
    }
    var frame = Qva.GetFrame (this.Element);
    if (frame) {
        if (frame.AvqMgr && frame.AvqMgr.Dirty) {
            Qva.QueuePostPaintMessage (this);
            return;
        }
        if (frame.Caption) {
            if (frame.Caption.AvqMgr && frame.Caption.AvqMgr.Dirty) {
                Qva.QueuePostPaintMessage (this);
                return;
            }
        }
    }
    if (frame && this.InlineStyle && ! this.IsTransient && ! (IS_GECKO || IS_SAFARI || IS_OPERA || IS_CHROME)) {
        // In IE "medium" means that the element is not yet attached to the DOM
        if (this.Frame.currentStyle.borderLeftWidth == "medium") {
            Qva.QueuePostPaintMessage (this);
            return;
        }
    }
    if (this.IsBody && this.LastColWidth) {
        if (! this.UnmodifiedTableWidth) {
            this.UnmodifiedTableWidth = this.getTableElement ().offsetWidth;
            if (header) this.UnmodifiedTableWidth = Math.max (this.UnmodifiedTableWidth, header.offsetWidth);
        }
    }
    var height;
    if (!this.IsHeader) {
        if (this.TotalSize == 0 || this.Lines.length == 0) {
            height = 0;
        } else if (this.ScrollBar && this.RowHeight > 1) {
            height = this.ScrollBar.VisibleRows;
        } else if (this.IsAsync) {
            height = this.EffectiveSize;
        } else {
            height = this.Lines.length;
        }
    } else {
        height = this.Lines.length;
    }
    var rowlen = this.Body.rows.length;
    if (height != rowlen) {
        if (!this.ScrollBar && this.IsAsync && height < rowlen && rowlen <= this.TotalSize) {
            // special case: new table data is shorter for Mozilla
            this.EffectiveSize = rowlen;
            height = this.EffectiveSize;
        } else {
            this.Inflate (height, rowlen);	// make sure table is right size
        }
    }

    if (this.IsBody && this.LastColWidth) {
        if (this.FixTableWidth (header)) {
            Qva.QueuePostPaintMessage (this);
            return;
        }
    }

    if (! this.Fixed) {
        if (this.IsBody) {
            this.FixTableHeight ();
        } else {
            this.Fixed = true;
        }
    }

    var newscrollheight;
    if (this.InlineStyle && this.IsBody) {
        newscrollheight = getContentMaxHeight (this.ScrollParent);
    } else {
        newscrollheight = getClientHeight (this.ScrollParent);
    }
    var rix_start = 0;
    var rix_stop = height;
    if (! this.ScrollBar && this.IsAsync) {
        if (this.TotalSize < this.PageSize) {
            rix_start = 0;
            rix_stop = this.TotalSize;
        } else {
            var scrollpos = this.ScrollParent.scrollTop;
            rix_start = this.RowForPos (this.Body.rows, scrollpos);
            if (this.ChunkOffset == 0 && scrollpos == 0 && rix_start != 0) {
                rix_start = 0;
                rix_stop = this.PageSize;
            } else {
                rix_stop = this.RowForPos (this.Body.rows, scrollpos + newscrollheight) + 1;
                var visibleScrollRowsDiv2 = Math.ceil ((rix_stop - rix_start) / 2);
                rix_start -= visibleScrollRowsDiv2;
                rix_stop += visibleScrollRowsDiv2;
            }
            if (rix_start < 0) rix_start = 0;
            if (rix_stop > height) rix_stop = height;
            if (rix_stop > this.TotalSize) rix_stop = this.TotalSize;
        }
    }

    var rows = this.Body.rows;
    var PaintedLines = 0;
    var LastRowAdjusted = false;
    this.HeaderRowCount = header ? header.rows.length : 0;
    this.Height = this.IsBody ? this.TotalSize : rows.length;
    for (var rix = rix_start; rix < rix_stop; ++ rix) {
        if (!this.ScrollBar && this.IsPainted [rix]) continue;
        var lix = rix + this.PageOffsetForPainting ();
        var line = this.Lines[lix];
        var row = this.Body.rows[rix];
        if (line == null) {
            if (WantedChunkNumber == null && lix < this.TotalSize) {
                WantedChunkNumber = Math.floor (lix / this.ChunkSize);
            }
            if (row != null) {
                for (var cix = 0; cix < row.cells.length; ++ cix) {
                    row.cells [cix].innerText = '|';
                }
            }
            break;
        }
        var IsSelected = this.GetIndex(line);
        var rcix = rix % this.RowClassNames.length;
        if (row.className != this.RowClassNames [rcix]) {
            row.className = this.RowClassNames [rcix];
        }
        if (row.rix == null) row.rix = rix;
        for (var cix = 0; cix < this.Width; ++ cix) {
            var colmgr = this.ColList [cix];
            if (! colmgr) continue;
            if (this.ByValue == null) {
                this.ByValue = colmgr.Cmd == 'edit' || colmgr.Cmd == 'windowsedit';
            }
            var cell = row.cells [cix];
            if (cell == null) {
                cell = document.createElement ("td");
                row.appendChild (cell);
            }
            if (!colmgr.IsLocal && line [cix] == null) {
                cell.style.display = "none";
            } else {
                if (this.RowHeight > 1) {
                    var rowheight = this.RowHeight * line[cix].rowspan;
                    if (this.WindowsSelectionstyle) {
                        rowheight = Math.max (rowheight, 20);
                    }
                    cell.style.height = rowheight + "px";
                    if (colmgr.CellWidth == -1) colmgr.CellWidth = getClientWidth (cell);
                    colmgr.CellHeight = rowheight;
                }
                cell.style.display = "";
                var IsDisabled = this.GetDisabled (lix, cix);
                colmgr.PaintCell (line, cell, rix, IsDisabled || IsSelected);
                cell.oncontextmenu = function (event) { this.pressed = false ; return Qva.GetBinder(this.binderid).OnContextMenu(event); }
                cell.binderid = this.PageBinder.ID;
                cell.position = cix + ":" + rix + ":";
                cell.position += this.IsHeader ? "Head" : "Body";
                var targetname = colmgr.Name.split ('.') [1];
                if (targetname == "Fields") targetname += "." + colmgr.Name.split ('.') [2]
                cell.targetname = targetname;
            }
        }

        this.IsPainted [rix] = true;
        PaintedLines ++;
        if (!this.ScrollBar && PaintedLines >= this.PageIncr && this.IsAsync) {
            postpaintposted = true;
            Qva.QueuePostPaintMessage (this);
            break;
        }
    }
    if (this.IsBody && this.LastColWidth && ! this.AllwaysFullWidth) {
        var scrollheight = 0;
        if (this.HasHorizontalScrollbar ()) {
            scrollheight = this.GetScrollHeight ();
        }
        var HasVerticalScrollbar = this.HasVerticalScrollbar (parseInt (getContentMaxHeight (this.ScrollParent)), scrollheight);
        if (this.m_HasVerticalScrollbar != HasVerticalScrollbar) {
            Qva.QueuePostPaintMessage (this);
            return;
        }
    }
    
    this.Unlock ();
    this.Element.style.display = "";
    if (WantedChunkNumber != null) {
        var newChunkOffset = WantedChunkNumber * this.ChunkSize;
        if (this.ChunkOffset != newChunkOffset) {
            this.ChunkOffset = newChunkOffset;
            this.PageBinder.PartialLoad (this.PageName, this.ChunkOffset);
        }
    }
    if (! this.Fixed && this.IsBody) {
        this.FixTableHeight ();
        this.Fixed = true;
    }
}

Qva.Mgr.table.prototype.Inflate = function (height, rowlen) {
    var mgr = this;
    var body = mgr.Body;
    var bodyParent = body.parentNode;
    var onerow = document.createElement ("tr");
    for(var i = 0; i < this.Width; ++i) {
        var cell = document.createElement ("td");
        var colmgr = mgr.ColList [i];
        cell.className = colmgr.ClassName;
        cell.align = colmgr.Align;
//        switch (colmgr.Cmd) {
//        case 'check':
//            cell.innerHTML = '<input class="avqCheckbox" type=checkbox >';
//            break;
//        default:
            cell.innerHTML = "|";
//        }
        onerow.appendChild (cell);
    }
    var height_to_inflate = height;
    var chunksize = mgr.ChunkSize;
    if (chunksize == null || chunksize <= 0) chunksize = 20;
    for (var rix = 0; rix < rowlen && rix < height_to_inflate; ++ rix) {
        mgr.IsPainted [rix] = false;
        var row = body.rows [rix];
        row.rix = rix;
        row.style.position = "static";
    }
    for (var rix = rowlen; rix < height_to_inflate; ++ rix) {
        mgr.IsPainted [rix] = false;
        var row = null;
        if (rix == 0 && mgr.Body.rows [0]) {
            row = mgr.Body.rows [0].cloneNode (true);
        } else {
            row = onerow.cloneNode (true);
        }
        row.rix = rix;
        var rcix = rix % mgr.RowClassNames.length;
        row.className = mgr.RowClassNames [rcix];
        body.appendChild (row);
    }
    if (height_to_inflate < height) {
        var last_rix = height - 1;
        var rcix = last_rix % mgr.RowClassNames.length;
        var row = null;
        if (body.rows.length <= height_to_inflate) {
            row = onerow.cloneNode (true);
            row.className = mgr.RowClassNames [rcix];
            row.style.position = "absolute";
            row.style.left = body.rows [1].offsetLeft + "px";
            row.style.top = body.rows [1].offsetHeight * last_rix + "px";
            body.appendChild (row);
        } else {
            while (body.rows.length > height_to_inflate + 1) {
                body.deleteRow (height_to_inflate + 1);
            }
            row = body.rows [height_to_inflate];
            row.className = mgr.RowClassNames [rcix];
            row.style.position = "absolute";
            row.style.left = body.rows [1].offsetLeft + "px";
            row.style.top = body.rows [1].offsetHeight * last_rix + "px";
        }
        row.rix = last_rix;
    }
    
//var fillTime = new Date ().valueOf () - Time;
    if (height_to_inflate == height) {
        while (mgr.Body.rows.length > height_to_inflate) {
            mgr.Body.deleteRow (height_to_inflate);
        }
    }
//Time = new Date ().valueOf () - Time;
//if (timeIt) alert ("Time: " + Time + " cloneTime: " + cloneTime + " fillTime: " + fillTime + " swapBody: " + swapBody + " height: " + height);
}

Qva.Mgr.table.prototype.RowForPos = function (rows, pos) {
    var lo = 0;
    var hi = rows.length;
    while (hi - lo > 1) {
        var m = Math.floor ((hi + lo) / 2);
        if (rows [m].offsetTop > pos) {
            hi = m;
        } else {
            lo = m;
        }
    }
    return lo;
}


Qva.Mgr.table.prototype.PageOffsetForPainting = function () {
    if(this.ScrollBar) {
        return this.ScrollBar.GetOffset();
    } else {
        return 0;
    }
}

Qva.Mgr.table.prototype.GetSelectionStateClassName = function (is_selected, is_enabled, is_disabled, is_locked, is_deselected) {
    if (is_selected == true) {
        return this.SelectedClassName;
    } else if (is_deselected == true) {
        return this.DeselectedClassName;
    } else if (is_enabled == true) {
        return this.EnabledClassName;
    } else if (is_disabled == true) {
        return this.DisabledClassName;
    } else if (is_locked == true) {
        return this.LockedClassName;
    } else {
        return "";
    }
}

Qva.Mgr.table.prototype.ClearSelection = function () {
    if (window.getSelection) {
        window.getSelection().removeAllRanges();
    } else {
        window.document.selection.empty ();
    }
}

Qva.Mgr.table.prototype.IndicateCellsToSelect = function (ctrl, clearselection) {
    if (this.SelectionStartRow == null) return;
    if (this.Element.id != Qva.SearchableObject) {
        SetActiveAndSearchable (this.Element.id, this.IsTransient ? Qva.ActiveObject : this.Element.id);
    }
    if (! ctrl) {
        ctrl = this.ctrl;
    }
    var rix_start = this.SelectionStartRow.rix;
    var rix_end = this.SelectionEndRow.rix;
    if (rix_start > rix_end) {
        var tmp = rix_end;
        rix_end = rix_start;
        rix_start = tmp;
    }
    var cix_start = this.SelectionStartCol;
    var cix_end = this.SelectionEndCol;
    if (cix_start > cix_end) {
        var tmp = cix_end;
        cix_end = cix_start;
        cix_start = tmp;
    }
    if (this.prev_cix_start == null) this.prev_cix_start = new Array ();
    if (this.prev_cix_end == null) this.prev_cix_end = new Array ();
    var row_loop_start = this.prev_rix_start != null && this.prev_rix_start < rix_start ? this.prev_rix_start : rix_start;
    var row_loop_end = this.prev_rix_end != null && this.prev_rix_end > rix_end ? this.prev_rix_end : rix_end;
    if (this.AndMode) {
        if (this.CurrentPhase != null && ! clearselection && m_MgrWithPendingAndMode == null) this.CurrentPhase = (this.CurrentPhase + 1) % 3;
    }
    for (var rix = row_loop_start; rix <= row_loop_end; rix ++) {
        var row = this.Body.rows[rix];
        var selIx = rix + this.PageOffsetForPainting ();
        var col_loop_start = this.prev_cix_start [rix] != null && this.prev_cix_start [rix] < cix_start ? this.prev_cix_start [rix] : cix_start;
        var col_loop_end = this.prev_cix_end [rix] != null && this.prev_cix_end [rix] > cix_end ? this.prev_cix_end [rix] : cix_end;
        var actualcixstart = (this.ByValue && rix != row_loop_start) ? 0 : cix_start;
        var actualcixend = (this.ByValue && rix < row_loop_end) ? (row.cells.length - 1) : cix_end;
        col_loop_start = Math.min (col_loop_start, actualcixstart);
        col_loop_end = Math.max (col_loop_end, actualcixend);
        this.prev_cix_start [rix] = actualcixstart;
        this.prev_cix_end [rix] = actualcixend;
        for (var cix = col_loop_start; cix <= col_loop_end; ++ cix) {
            var StateClassName = null;
            var cell = row.cells [cix];
            var IsDisabled = this.GetDisabled (selIx, cix);
            if (rix < rix_start || rix > rix_end || cix < actualcixstart || cix > actualcixend) {
                // restore state
                var IsSelected = (ctrl || cell.windowsselectionstyle) ? this.GetSelected(selIx, cix) : false;
                StateClassName = this.GetSelectionStateClassName (IsSelected, IsDisabled == false, IsDisabled == true);
            } else {
                // change to selected state or toggle if ctrl pressed
                if (this.AndMode) {
                    if (this.CurrentPhase == null) {
                        this.CurrentPhase = 0;
                    }
                    switch (this.CurrentPhase) {
                        case 0:
                            if (ctrl) {
                                StateClassName = IsDisabled ? this.DeselectedClassName : this.SelectedClassName;
                            } else {
                                StateClassName = this.SelectedClassName;
                            }
                            break;
                        case 1:
                            if (ctrl) {
                                StateClassName = IsDisabled ? this.SelectedClassName : this.DeselectedClassName;
                            } else {
                                StateClassName = this.DeselectedClassName;
                            }
                            break;
                        case 2:
                            StateClassName = IsDisabled ? this.DisabledClassName: this.EnabledClassName;
                            break;
                        default:
                            debugger;
                            break;
                    }
                } else {
                    var IsEnabled = !IsDisabled;
                    var IsSelected = (ctrl || cell.windowsselectionstyle) ? !this.GetSelected(selIx, cix) : true;
                    StateClassName = this.GetSelectionStateClassName (IsSelected, IsEnabled, IsDisabled, false);
                }
            }
            var rcix = rix % this.RowClassNames.length;
            if (row.className != this.RowClassNames [rcix]) {
                row.className = this.RowClassNames [rcix];
            }
            var colmgr = this.ColList [cix];
            if (this.ByValue && cell.value == -1) continue;
            var cellClassName = colmgr.ClassName;
            var deselect = clearselection || (StateClassName == this.EnabledClassName);
            if (this.Semantic) {
                if (StateClassName != '') {
                    StateClassName += "_Semantic";
                    if (! deselect) StateClassName += "_Pressed";
                    cellClassName += " " + StateClassName;
                } else {
                    debugger;
                }
            } else if (this.AltClass) {
                if (StateClassName != '') {
                    StateClassName += "_" + this.AltClass;
                    cellClassName += " " + StateClassName;
                } else {
                    debugger;
                }
            } else {
                if (StateClassName != '') {
                    cellClassName += " " + StateClassName;
                }
            }
            if (cell.className != cellClassName) {
                this.IndicateSingleSelect (rix, cix, deselect, StateClassName);
            }
        }
    }
    this.prev_rix_start = rix_start;
    this.prev_rix_end = rix_end;
    if (this.AndMode) {
        this.ctrl = ctrl;
        DelayAndModeToogle (this);
    }
}

var m_MgrWithPendingAndMode = null;

function DelayAndModeToogle (mgr) {
    if (m_MgrWithPendingAndMode != null) return;
    m_MgrWithPendingAndMode = mgr;
    window.setTimeout (AndModeToogle, 1000);
}

function AndModeToogle () {
    var mgr = m_MgrWithPendingAndMode;
    m_MgrWithPendingAndMode = null;
    mgr.IndicateCellsToSelect ();
}

Qva.Mgr.table.prototype.SetCellSelected = function (cell, newclassName, deselect, colmgr) {
    if (cell.windowsselectionstyle) {
        var input = null;
        for (var iElem = 0; iElem < cell.childNodes.length; iElem++) {
            if (cell.childNodes [iElem].tagName == "INPUT") {
                input = cell.childNodes [iElem];
                break;
            }
        }
        if (input == null) debugger;
        var checked = this.SelectedClassName == newclassName;
        input.checked = checked;
    } else {
        if (deselect) {
            if (cell.origcolor != "") {
                cell.style.color = cell.origcolor;
                cell.origcolor = "";
            }
            if (cell.origbackgroundColor != "") {
                cell.style.backgroundColor = cell.origbackgroundColor;
                cell.origbackgroundColor = "";
            }
        } else {
            if (cell.style.color != "") {
                cell.origcolor = cell.style.color;
                cell.style.color = "";
            }
            if (cell.style.backgroundColor != "") {
                cell.origbackgroundColor = cell.style.backgroundColor;
                cell.style.backgroundColor = "";
            }
        }
        var cellClassName = colmgr.ClassName;
        if (newclassName != '') {
            cellClassName += " " + newclassName;
        }
        if (cell.className != cellClassName) {
            cell.className = cellClassName;
        }
    }
}

Qva.Mgr.table.prototype.IndicateSingleSelect = function (rowindex, colindex, deselect, newclassname) {
    var rows = this.Body.rows;
    var row = rows[rowindex];
    var cell = row.cells [colindex];
    var colmgr = this.ColList [colindex];
    if (cell.selectsource) {
        var selectedclassName = this.GetSelectionStateClassName (true, false, false);
        for (var cix = 0; cix < row.cells.length ; cix ++) {
            var cell = row.cells [cix];
            if (! cell.selectsource && (cell.singleselect || cell.multiselect)) {
                this.SetCellSelected (cell, selectedclassName, deselect, colmgr);
            }
        }
        for (var rix = 0; rix < rowindex; rix ++) {
            var cell = rows[rix].cells [colindex];
            if (! cell.selectsource && (cell.singleselect || cell.multiselect)) {
                this.SetCellSelected (cell, selectedclassName, deselect, colmgr);
            }
        }
    } else {
        this.SetCellSelected (cell, newclassname, deselect, colmgr);
    }
}

Qva.Mgr.table.prototype.SetCellStyle = function (data, rix, cix, ignorecolor, hidetext) {
    if (! this.InlineStyle) return "";
    if (! data.style) return "";
    var style = this.Style [data.style];
    if (! style) return ""
    var firstrow = rix == 0;
    var lastrow = this.Height != -1 ? rix == (this.Height - 1) : this.IsHeader;
    var firstcol = cix == 0;
    var lastcol = cix == (this.Width - 1)
    
    var csstext = "";
    if (hidetext) {
        csstext += "; background-color:" + style.BgColor;
        csstext += "; color:" + style.BgColor;
    } else if (! ignorecolor) {
        csstext += "; background-color:" + style.BgColor;
        csstext += "; color:" + style.Color;
    } else {
        csstext += "; background-color:";
        csstext += "; color:";
    }
    csstext += "; text-align:" + (data.isnum ? style.NumAdjust : style.TextAdjust);

    csstext += "; font-style:" + style.FontStyle;
    csstext += "; font-weight:" + style.FontWeight;
    csstext += "; text-decoration:" + style.TextDecoration;
    switch (style.SizeMod) {
        case "2":
            csstext += "; font-size:large";
            break;
        case "1":
            csstext += "; font-size:larger";
            break;
        case "-1":
            csstext += "; font-size:smaller";
            break;
        case "-2":
            csstext += "; font-size:small";
            break;
    }
    if (! this.Semantic) {
        var borderstyle = this.BorderStyle [style.BorderStyle];
        if (borderstyle) {
            var hastopborder = false;
            var hasbottomborder = false;
            if (! (data.subcell == "y")) {
                hastopborder = true;
                if (! (data.first == "y")) {
                    hasbottomborder = true;
                }
            }
            csstext += "; border-bottom:";
            if (lastrow && this.SizeTodata && ! this.IsHeader || ! hasbottomborder) {
                var hiddenborder = borderstyle.Bottom.substr (0, borderstyle.Bottom.indexOf ("#")) + style.BgColor;
                csstext += hiddenborder;
            } else {
                csstext += borderstyle.Bottom;
            }
            csstext += "; border-top:";
            if ((IS_GECKO && GECKO_VERSION < 3.5) || firstrow || ! hastopborder) {
                var hiddenborder = borderstyle.Top.substr (0, borderstyle.Top.indexOf ("#")) + style.BgColor;
                csstext += hiddenborder;
            } else {
                csstext += borderstyle.Top;
            }
            var hasleftborder = false;
            var hasrightborder = false;
            if (! (data.subcell == "x")) {
                hasleftborder = true;
                if (! (data.first == "x")) {
                    hasrightborder = true;
                }
            }
            if ((IS_GECKO && GECKO_VERSION < 3.5) || firstcol || ! hasleftborder) {
                csstext += "; border-left:none";
            } else {
                csstext += "; border-left:" + borderstyle.Left;
            }
            if (lastcol && this.SizeTodata || ! hasrightborder) {
                csstext += "; border-right:none";
            } else {
                csstext += "; border-right:" + borderstyle.Right;
            }
        }
    }
    return csstext;
}

Qva.Mgr.table.prototype.SelectRows = function (ctrl) {
    var rix_start = this.SelectionStartRow.rix;
    var rix_end = this.SelectionEndRow.rix;
    if (rix_start > rix_end) {
        var tmp = rix_end;
        rix_end = rix_start;
        rix_start = tmp;
    }
    var cix_start = this.SelectionStartCol;
    var cix_end = this.SelectionEndCol;
    if (cix_start > cix_end) {
        var tmp = cix_end;
        cix_end = cix_start;
        cix_start = tmp;
    }
    this.IndicateCellsToSelect (ctrl, true);
    this.SelectionStartRow = null;
    this.SelectionEndRow = null;
    this.SelectionStartCol = null;
    this.SelectionEndCol = null;
    if (this.AndMode && this.CurrentPhase == 2) {
        this.CurrentPhase = null;
        return;
    }
    
    var SearchActive = (this.Search != null && this.Search.value != '');
    if (this.ByValue) {
        var sendtext = this.Body.rows[0].cells [0].value == null;
        var singlecellselection = (rix_start == rix_end && cix_start == cix_end);
        var windowsselectionstyleandradio = false;
        if (singlecellselection) {
            if (this.Body.rows[rix_start].cells [cix_start].value == -1) return;
            windowsselectionstyleandradio = this.WindowsSelectionstyle && this.Body.rows[rix_start].cells [cix_start].singleselect == true;
        }
        var selIx = rix_start + this.PageOffsetForPainting ();
        var IsSelected = this.GetIndex(this.Lines[selIx]);
        var valName = this.PageName;
        if (valName == "") {
            valName = this.ColList [0].Name.split ('.') [1];
        }
        if (! ctrl && ! sendtext && (! this.WindowsSelectionstyle || windowsselectionstyleandradio) && ! (IS_SAFARI && IS_MOBILE)) {	// Not toggle mode
            this.PageBinder.Set (valName, 'clear', '', false);
            if (IsSelected && this.Selected.length == 1 && singlecellselection) {
                rix_start ++; // nothing more to do
            }
        }
        var phasesent = false;
        for (var rix = rix_start; rix <= rix_end; rix ++) {
            var row = this.Body.rows[rix];
            var actualcixstart = (rix != rix_start) ? 0 : cix_start;
            var actualcixend = (rix < rix_end) ? (row.cells.length - 1) : cix_end;
            for (var cix = actualcixstart; cix <= actualcixend; cix ++) {
                var cell = row.cells [cix];
                var valValue = cell.value;
                if (ctrl) { // Toggle mode
                    if (! this.AndMode) {
                        this.Lines [rix] [cix].selected = ! this.Lines [rix] [cix].selected;
                    }
                    if (this.AndMode && ! phasesent) {
                        this.PageBinder.TogglePhase = this.CurrentPhase;
                        phasesent = true;
                    }
                    this.PageBinder.ToggleSelect = valName;
                    Qva.ActiveObject = this.Element.id;
                    if (this.PageBinder.ToggleSelects == null) {
                        this.PageBinder.ToggleSelects = new Array ();
                    }
                    this.PageBinder.ToggleSelects [this.PageBinder.ToggleSelects.length] = valValue;
                } else {
                    if (sendtext) {
                        this.PageBinder.Set (valName, 'text', cell.innerText, false);
                    } else {
                        if (this.AndMode && ! phasesent) {
                            this.PageBinder.Set (valName, 'phase', this.CurrentPhase, false);
                            phasesent = true;
                        }
                        this.PageBinder.Set (valName, 'value', valValue, false);
                    }
                }
            }
        }
    } else {
        var valName = this.PageName;
        if (valName == "") {
            valName = this.ColList [0].Name.split ('.') [1];
        }
        var rectstring = '' + cix_start + ':' + (rix_start + this.PageOffsetForPainting ()) + ':' + (cix_end - cix_start + 1) + ':' + (rix_end - rix_start + 1);
        if (this.IsHeader) rectstring += ':Head';
        this.PageBinder.Set (valName, "rect", rectstring, true);
    }
    if (! ctrl) {
        if (SearchActive) {
            this.PageBinder.Set (this.SearchName, "closesearch", "abort", true);      // break out of search mode
            if (this.Search != null) this.Search.value = '';				// Allow for popup search being closed
        } else {
            this.PageBinder.LoadBegin ();
        }
    }
    this.CurrentPhase = null;
}

var m_MgrWithSelectStart  = null;

function AvqAction_TableEditMouseMove (event) {
    if (! event) event = window.event;
    
    var row = this.parentNode;
    if (row.tagName != 'TR') return;
    var mgr = row.parentNode.AvqMgr;
    if (mgr == null) mgr = row.parentNode.parentNode.AvqMgr;
    if (mgr == null) return;
    if (mgr.SelectionStartRow == null) return;
    if (m_MgrWithSelectStart != null && m_MgrWithSelectStart != mgr) {
        return;
    }
    if (mgr.SelectSource != this.selectsource) return;
    mgr.ClearSelection ();
    if (! mgr.PageBinder.Enabled) return;
    mgr.SelectionEndRow = row;
    mgr.SelectionEndCol = this.cellIndex;
    if (this.singleselect) {
        mgr.SelectionStartRow = mgr.SelectionEndRow;
        mgr.SelectionStartCol = mgr.SelectionEndCol;
    }
    mgr.IndicateCellsToSelect (ctrlKeyPressed (event));
}

function AvqAction_TableEditMouseDown (event) {
    if (! event) event = window.event;
    
    var row = this.parentNode;
    if (row.tagName != 'TR') return;
    var mgr = row.parentNode.AvqMgr;
    if (mgr == null) mgr = row.parentNode.parentNode.AvqMgr;
    if (mgr == null) return;
    if (event.button != mgr.LeftButton) return;
    if (! mgr.PageBinder.Enabled) return;
    mgr.prev_rix_start = null;
    mgr.prev_rix_end = null;
    mgr.SelectionStartRow = row;
    mgr.SelectionEndRow = row;
    mgr.prev_cix_start = null;
    mgr.prev_cix_end = null;
    mgr.SelectionStartCol = this.cellIndex;
    mgr.SelectionEndCol = this.cellIndex;
    mgr.SelectSource = this.selectsource;
    mgr.CurrentPhase = null;
    mgr.IndicateCellsToSelect (ctrlKeyPressed (event));
    m_MgrWithSelectStart = mgr;
    Qva.addEvent(document,"mouseup",AvqAction_TableEditMouseUp);
    Qva.Select.Active = false;

}

function AvqAction_TableEditMouseUp (event) {
    if (! event) event = window.event;
    var mgr = m_MgrWithSelectStart;
//    
//    var row = this.parentNode;
//    if (row.tagName != 'TR') return;
//    var mgr = row.parentNode.AvqMgr;
//    if (mgr == null) mgr = row.parentNode.parentNode.AvqMgr;
    if (mgr == null) return;
//    if (event.button != mgr.LeftButton) return;
    if (mgr.SelectionStartRow == null) return;
//    if (m_MgrWithSelectStart != null && m_MgrWithSelectStart != mgr) {
//        return;
//    }
    mgr.ClearSelection ();
    if (! mgr.PageBinder.Enabled) return;
//    if (mgr.SelectionStartRow == null) {
//        mgr.SelectionStartRow = row;
//        mgr.SelectionStartCol = this.cellIndex;
//    }
//    if (mgr.SelectSource == this.selectsource) {
//        mgr.SelectionEndRow = row;
//        mgr.SelectionEndCol = this.cellIndex;
//    }
    mgr.SelectRows (ctrlKeyPressed (event));
    Qva.removeEvent(document,"mouseup",AvqAction_TableEditMouseUp);
    Qva.Select.Active = true;
    m_MgrWithSelectStart = null;
}

function TableHeaderDblClick (event) {
    if (! event) { event = window.event; }
    var row = this.parentNode;
    if (row.tagName != 'TR') return;
    var mgr = row.parentNode.AvqMgr;
    if (mgr == null) mgr = row.parentNode.parentNode.AvqMgr;
    if (mgr == null) return;
    this.pressed = false;
    var name = mgr.ColList [this.cellIndex].Name;
    if (mgr.PageBinder.Enabled) {
        mgr.PageBinder.Set (name, "click", name, true);
    } else {
        mgr.PageBinder.PendingDblClickName = name;
    }
}

function avq_action_md (event) {
    if (! event) event = window.event;
    event.cancelBubble = true;
    this.pressed = true;
}

function action_mu (elem) {
    if (! elem.pressed) return;
    elem.pressed = false;
    var action = elem.action;
    if (elem.targetname != null) {
        var binder = Qva.GetBinder (elem.binderid);
        var target = binder.DefaultScope + "." + elem.targetname;
        binder.Set (target, 'position', elem.xx + ":" + elem.yy, false);
        binder.Set (target + "." + action, "action", "", true);
    }
}

function avq_action_mu (event) {
    if (! event) event = window.event;
    if (! this.pressed) return;
    event.cancelBubble = true;
    var _this = this; 
    window.setTimeout (function() { action_mu (_this); }, 200);
}


Qva.ColMgr = { };
Qva.ColMgr.Init = function (parent, cix, cell, name, prefix) {
    this.IsLocal = false;
    this.Index = cix;
    if (cell != null) {
        this.ClassName = cell.className;
        this.Align = cell.align;
        this.Html = cell.innerHTML;
    }
    this.Parent = parent;
    this.CellHeight = -1;
    this.CellWidth = -1;
    Qva.MgrSplit (this, name, prefix)
}

Qva.ColMgr.basic = function (parent, cix, cell, name, prefix) {
    Qva.ColMgr.Init.apply(this, arguments);
    this.IsLocal = true;
}

Qva.ColMgr.basic.prototype.PaintCell = function (line, cell, rix) {
    cell.innerHTML = this.Html;
}

Qva.ColMgr.edit = function (parent, cix, cell, name, prefix) {
    Qva.ColMgr.Init.apply(this, arguments);
}

Qva.ColMgr.edit.prototype.PaintCell = function (line, cell, rix, ignorecolor) {
    cell.style.color = "";
    var cix = this.Index;
    cell.value = line [cix].intval;
    var text = "";
    if (this.Parent.AndMode) {
        if (line [cix].selected) {
            text = "&  ";
            cell.style.paddingLeft = "";
        } else if (line [cix].deselected) {
            text = "!  ";
            cell.style.paddingLeft = "";
        } else {
            cell.style.paddingLeft = "12px";
        }
    }
    text += (line [cix].val != '') ? line [cix].val : ' ';
    var StateClassName = this.Parent.GetSelectionStateClassName (line [cix].selected, ! line [cix].disabled && ! line [cix].locked, line [cix].disabled, line [cix].locked, line [cix].deselected);
    if (this.Parent.Semantic) {
        StateClassName += "_Semantic";
    } else if (this.Parent.AltClass) {
        StateClassName += "_" + this.Parent.AltClass;
    }
    var cellClassName = this.ClassName;
    if (StateClassName != '') cellClassName += " " + StateClassName;
    if (cell.className != cellClassName) cell.className = cellClassName;
    this.Parent.appendCellContent (cell, line [cix], text, cix, cell.value, this);
    cell.title = line [cix].title;
    if (line [cix].selecttype == null) {
        cell.onmousedown = Qva.NoAction;
        cell.onmousemove = Qva.NoAction;
    } else {
        cell.onmousedown = AvqAction_TableEditMouseDown;
        cell.onmousemove = AvqAction_TableEditMouseMove;
        if (line [cix].selecttype == "single") {
             cell.singleselect = true;
        }
        cell.onclick = Qva.CancelAction;
    }
    cell.style.cssText += this.Parent.SetCellStyle (line [cix], rix, cix, ignorecolor && this.Parent.ByValue);
}

Qva.ColMgr.text = function (parent, cix, cell, name, prefix) {
    Qva.ColMgr.Init.apply(this, arguments);
}

Qva.ColMgr.text.prototype.PaintCell = function (line, cell, rix, ignorecolor) {
    var cix = this.Index;
    
    if (line.IsHeader && line.IsHeader == true) {
        if (this.Parent.sortable && this.Parent.sortable == true) {
            cell.ondblclick = TableHeaderDblClick;
        }
    }
    var innertext = (line [cix].val != '') ? line [cix].val : ' ';
    var showstateclass = false;
    if (line [cix].byval) {
        var StateClassName = this.Parent.GetSelectionStateClassName (line [cix].selected, ! line [cix].disabled && ! line [cix].locked, line [cix].disabled, line [cix].locked, line [cix].deselected);
        var cellClassName = this.ClassName;
        if (StateClassName != '') cellClassName += " " + StateClassName;
        if (cell.className != cellClassName) cell.className = cellClassName;
        showstateclass = true;
        cell.style.color = "";
        cell.style.backgroundColor = "";
    }
    ignorecolor = (ignorecolor && this.Parent.ByValue) || showstateclass;
    cell.style.cssText += this.Parent.SetCellStyle (line [cix], rix, cix, ignorecolor);
    if (cell.className && cell.className != "" && ! showstateclass) cell.className = "";
    var ulr = line [cix].url;
    if (ulr) {
        cell.innerText = "";
        var link = document.createElement ("a");
        link.innerText = innertext;
        link.href = ulr;
        link.target = "_blank";
        cell.appendChild (link);
        cell.onclick = Qva.CancelAction;
        cell.onmousedown = Qva.CancelAction;
        cell.onmousemove = Qva.CancelAction;
        cell.style.cursor = "Default";
    } else {
        cell.style.cursor = "";
        if (line [cix].subcell) {
            cell.innerText = "";
        } else {
            cell.innerText = innertext;
        }
        cell.title = line [cix].title;
        if (line [cix].icons.length > 0 && ! line [cix].subcell) {
            this.Parent.appendCellContent (cell, line [cix], line [cix].val, cix, rix, this);
        }
        var selecttype = line [cix].selecttype;
        if (selecttype == null) {
            var action = line [cix].action;
            if (action) {
                cell.binderid = this.Parent.PageBinder.ID;
                cell.onmousedown = avq_action_md;
                cell.onmouseup = avq_action_mu;
                cell.pressed = false;
                cell.action = action;
                cell.targetname = this.Parent.Name;
                cell.xx = cix;
                cell.yy = rix;
                cell.onclick = Qva.CancelAction;
            } else {
                cell.onclick = Qva.NoAction;
                cell.onmousedown = Qva.NoAction;
                cell.onmousemove = Qva.NoAction;
            }
            cell.selectsource = null;
            cell.multiselect = null;
            cell.singleselect = null;
        } else if (selecttype == "input") {
            cell.innerText = "";
            var input = document.createElement ("input");
            input.value = innertext;
            var style = "border:none; height:"
            style += cell.clientHeight;
            style += "px; width:";
            style += cell.clientWidth;
            style += "px; ";
            if (this.Parent.Element.style.fontFamily) {
                style += "font-family:" + this.Parent.Element.style.fontFamily + "; ";
            }
            if (this.Parent.Element.style.fontSize) {
                style += "font-size:" + this.Parent.Element.style.fontSize + "; ";
            }
            input.style.cssText = style;
            input.onmousedown = Qva.CancelAction;
            input.onmouseup = Qva.CancelAction;
            input.onclick = Qva.CancelAction;
            new Qva.Mgr.inputtext (this.Parent.PageBinder, input, this.Parent.Name + ".V" + rix);
            cell.appendChild (input);
        } else {
            cell.onmousedown = AvqAction_TableEditMouseDown;
            cell.onmousemove = AvqAction_TableEditMouseMove;
//            cell.onmouseup = AvqAction_TableEditMouseUp;
            if (selecttype == "multi") {
                cell.multiselect = true;
            } else {
                cell.singleselect = true;
            }
            cell.selectsource = line [cix].selectsource;
        }
    }
}

Qva.ColMgr.check = function (parent, cix, cell, name, prefix) {
    Qva.ColMgr.Init.apply(this, arguments);
}
Qva.ColMgr.check.prototype.PaintCell = function (line, cell, rix) {
    var cix = this.Index;
    
    if (cell.firstChild == null || cell.firstChild.tagName != 'INPUT' || cell.firstChild.type != 'checkbox') {
        cell.innerHTML = '<input class="avqCheckbox" type=checkbox >';
    }
    cell.firstChild.onclick = AvqAction_TableCheck;
    if (this.Parent.ChoiceIx != -1) {
        var lix = rix + this.Parent.PageOffsetForPainting();
        var IsSelected = this.Parent.GetIndex(line) != 0;
        cell.firstChild.checked = IsSelected;
    } else {
        cell.firstChild.checked = line[cix].val != 0;
        cell.firstChild.disabled = line[cix].disabled;
    }
}

Qva.ColMgr.input = function (parent, cix, cell, name, prefix) {
    Qva.ColMgr.Init.apply(this, arguments);
}
Qva.ColMgr.input.prototype.PaintCell = function (line, cell, rix) {
    var cix = this.Index;
    
    if (cell.firstChild == null || cell.firstChild.tagName != 'INPUT' || cell.firstChild.type != 'text') {
        cell.innerHTML = '<input class="avqEdit" style="width:100%" value="" >';
        cell.firstChild.onchange = AvqAction_TableInput;
    }
    cell.firstChild.value = line[cix].val;
    cell.firstChild.disabled = line[cix].disabled;
}

Qva.ColMgr.windowsedit = function (parent, cix, cell, name, prefix) {
    Qva.ColMgr.Init.apply (this, arguments);
}

Qva.ColMgr.windowsedit.prototype.PaintCell = function (line, cell, rix, ignorecolor) {
    cell.style.color = "";
    var cix = this.Index;
    if (line [cix].intval == "-1") {
        cell.innerHTML = "";
        return;
    }
    cell.value = line [cix].intval;
    var text = ""
    if (this.Parent.AndMode) {
        if (line [cix].selected) {
            text = "&  ";
        } else if (line [cix].deselected) {
            text = "!  ";
        }
    }
    text += (line [cix].val != '') ? line [cix].val : ' ';

    var style = this.Parent.Style [line [cix].style];
    var textalignright = (line [cix].isnum ? style.NumAdjust : style.TextAdjust) == "right";
    var radio = line [cix].selecttype == "single";
    var input = null;
    for (var iElem = 0; iElem < cell.childNodes.length; iElem++) {
        if (cell.childNodes [iElem].tagName == "INPUT") {
            input = cell.childNodes [iElem];
        } else {
            cell.removeChild (cell.childNodes [iElem]);
        }
    }
    if (! input) {
        input = document.createElement ("INPUT");
        input.type = radio ? "radio" : "checkbox";
        cell.appendChild (input);
    }
    input.checked = line [cix].selected || line [cix].locked || line [cix].selectedexcluded;
    input.disabled = line [cix].disabled;

    if (textalignright) {
        var span = document.createElement ("span");
        span.innerText = text;
        span.style.position = "absolute";
        span.style.textAlign = "right";
        cell.appendChild  (span);
        var left = cell.offsetLeft - span.offsetWidth - 1;
        if (this.CellWidth != -1) {
            left += this.CellWidth;
        } else {
            left += cell.offsetWidth;
            debugger;
        }
        if (IS_GECKO || IS_OPERA) {
            left -= 3;
        }
        span.style.left = left + "px";
    } else {
        var textnode = document.createTextNode (text);
        cell.appendChild (textnode);
    }
    cell.windowsselectionstyle = true;
    if (this.Parent.Element.disabled || line [cix].locked) {
        cell.onmousedown = Qva.NoAction;
        cell.onmousemove = Qva.NoAction;
    } else {
        cell.onmousedown = AvqAction_TableEditMouseDown;
        cell.onmousemove = AvqAction_TableEditMouseMove;
    }
    if (line [cix].selecttype == "single") {
         cell.singleselect = true;
    }
    ignorecolor = ignorecolor && this.Parent.ByValue;
    var csstext = this.Parent.SetCellStyle (line [cix], rix, cix, ignorecolor);
    if (textalignright) csstext = csstext.replace ("right", "left"); 
    cell.style.cssText += csstext;
}

Qva.ColMgr.action = function (parent, cix, cell, name, prefix, action) {
    Qva.ColMgr.Init.apply(this, arguments);
    this.Action = action;
}
Qva.ColMgr.action.prototype.PaintCell = function (line, cell, rix, ignorecolor) {
    var cix = this.Index;
    if(!cell.firstChild || cell.firstChild.tagName != 'INPUT') {
        cell.innerHTML = '<input type="button" />';
    }
    var button = cell.firstChild;
    if(!button) { debugger; return; }
    button.innerText = (line[cix].val != '') ? line[cix].val : ' ';
    button.Action = this.Action;
    button.onclick = function(event) { eval(this.Action); };
    
    if (this.Parent.InlineStyle) {
        ignorecolor = ignorecolor && this.Parent.ByValue;
        cell.style.cssText += this.Parent.SetCellStyle (line [cix], rix, cix, ignorecolor);
        if (cell.className && cell.className != "") cell.className = "";
    }
}

function AvqAction_TableAction () {
    var box = this;
    var row = box.parentNode;
    if (row.tagName != 'TR') return;
    var mgr = row.parentNode.AvqMgr;
    if (mgr == null) mgr = row.parentNode.parentNode.AvqMgr;
    if (mgr == null) return;
    if (! mgr.PageBinder.Enabled) return;
    var selIx = row.rix;
    var colname = mgr.ColList[box.cellIndex].Name;
    mgr.PageBinder.Set (mgr.Group, 'cell', selIx + ':' + colname, true);
}

Qva.ColMgr.imgaction = function (parent, cix, cell, name, prefix, action) {
    Qva.ColMgr.Init.apply(this, arguments);
}
Qva.ColMgr.imgaction.prototype.PaintCell = function (line, cell, rix, ignorecolor) {
    cell.style.display = (line[this.Index].mode === "hidden") ? 'none' : '';
	cell.innerHTML = this.Html;
    cell.onclick = AvqAction_TableAction;
}

Qva.ColMgr.hidden = function (parent, cix, cell, name, prefix) {
    Qva.ColMgr.Init.apply(this, arguments);
}
Qva.ColMgr.hidden.prototype.PaintCell = function (line, cell, rix) {
    cell.style.display = "none";
    var cix = this.Index;
    cell.innerText = (line[cix].val != '') ? line[cix].val : ' ';
}

Qva.ColMgr.error = function (parent, cix, cell, name, prefix, action) {
    Qva.ColMgr.Init.apply(this, arguments);
    this.IsLocal = true;
}
Qva.ColMgr.error.prototype.PaintCell = function (line, cell, rix, ignorecolor) {
    var col = line[this.Index];
    var msg = col.val;
    cell.style.visibility = (msg && msg != '') ? 'visible' : 'hidden';
    cell.innerHTML = this.Html;
    cell.title = msg;
}
