// Build 9.00.7440.8

if (!Qva.Mgr) Qva.Mgr = {}

function onclick_action() {
    var binder = Qva.GetBinder(this.binderid);
    if (!binder.Enabled) return;
    if (this.Position != null) binder.Set (this.PositionName, 'position', this.Position, false);
    binder.Set (this.Name, "action", "", true);
}

function onclick_ContextClientAction(event) { 
    Qva.GetBinder(this.binderid).ContextClientAction (event, this); 
}

Qva.Mgr.show = function (owner, elem, name, prefix, condition) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    this.Condition = condition;
    owner.AddManager(this);
    this.Element = elem;
    owner.Append (this, this.Name, 'value');
}

Qva.Mgr.show.prototype.Paint = function(mode, node) {
    this.Touched = true;
    var show;
    if (mode == 'n') {
        show = (this.ModeIfNotEnabled == 'd');
    } else {
        show = (node.getAttribute (this.Attr) == this.Condition);
    }
    this.Element.style.display = show ? '' : 'none';
}

Qva.Mgr.hide = function (owner, elem, name, prefix, condition) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    this.Condition = condition;
    this.Element = elem;
    owner.AddManager(this);
    owner.Append (this, this.Name, 'value');
}

Qva.Mgr.hide.prototype.Paint = function(mode, node) {
    this.Touched = true;
    var hide;
    if (mode == 'n') {
        if (this.Condition == null) {
            hide = (this.ModeIfNotEnabled != 'd');
        } else {
            hide = false;
        }
    } else {
        hide = (node.getAttribute (this.Attr) == this.Condition);
    }
    this.Element.style.display = hide ? 'none' : '';
}

Qva.Mgr.disable = function (owner, elem, name, prefix) {
    this.Name = Qva.MgrMakeName (name, prefix);
    this.Element = elem;
    owner.AddManager(this);
}

Qva.Mgr.disable.prototype.Lock = Qva.LockDisabled;
Qva.Mgr.disable.prototype.Unlock = Qva.UnlockDisabled;
Qva.Mgr.disable.prototype.Paint = function(mode, node) {
    this.Touched = true;
    var element = this.Element;
    element.disabled = (mode != 'e');
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
}

Qva.Mgr.caption = function (owner, elem, name, prefix) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    this.Element = elem;
    elem.AvqMgr = this;
    owner.AddManager(this);
    this.PageBinder = owner;
    elem.moveObj = elem.parentNode.id;
    var bkgid = elem.parentNode.id.replace ("_frame", "_bkg");
    var bkgelem = window.document.getElementById (bkgid);
    if (bkgelem) {
        elem.moveObj += ":" + bkgid;
    }
    this.MiddleName = this.Name.split('.')[1];
    elem.Name = this.Name;
    elem.binderid = owner.ID;
    this.RowHeight = -1;
    this.InlineStyle = owner.InlineStyle;
    if (elem.getAttribute ('AvqStyle')) {
        this.InlineStyle = elem.getAttribute ('AvqStyle') == "true";
    }
}

Qva.Mgr.caption.prototype.SetPending = function (names) {
    for (var ix = 0; ix < names.length; ++ix) {
        if (this.MiddleName != names[ix]) continue;
        this.Element.parentNode.className += " QvPending";
        if (this.Element.BkgElem) this.Element.BkgElem.className += " QvPending";
        return;
    }
    var classname = this.Element.parentNode.className;
    this.Element.parentNode.className = classname.replace (" QvPending", "");
    if (this.Element.BkgElem) {
        classname = this.Element.BkgElem.className;
        this.Element.BkgElem.className = classname.replace (" QvPending", "");
    }
}

function setStyle (node, element) {
    if (node.getAttribute ('color')) element.style.color = node.getAttribute ('color');
    if (node.getAttribute ('fontfamily')) element.style.fontFamily = node.getAttribute ('fontfamily');
    if (node.getAttribute ('fontsize')) element.style.fontSize = node.getAttribute ('fontsize') + "pt";
    if (node.getAttribute ('fontstyle')) element.style.fontStyle = node.getAttribute ('fontstyle');
    if (node.getAttribute ('fontweight')) element.style.fontWeight = node.getAttribute ('fontweight');
    if (node.getAttribute ('textalign')) element.style.textAlign = node.getAttribute ('textalign');
    if (node.getAttribute ('verticalalign')) element.style.verticalAlign = node.getAttribute ('verticalalign');
    if (node.getAttribute ('textdecoration')) element.style.textDecoration = node.getAttribute ('textdecoration');
}

Qva.Mgr.caption.prototype.PostPaint = function () {
    var element = this.Element;
    if (this.RowHeight == -1 && this.RowSpan != 1) {
        this.RowHeight = element.clientHeight;
    }
    if (this.RowHeight != -1) {
        element.style.height = this.RowSpan == 1 ? "" : (this.RowHeight * this.RowSpan + "px");
    }
    if (this.NoText) {
        for (var ichild = 0; ichild < element.childNodes.length; ichild++) {
            var child = element.childNodes [ichild];
            if (child.tagName != "SPAN") continue;
            element.removeChild (child);
            break;
        }
    }
}

Qva.Mgr.caption.prototype.Paint = function(mode, node, name) {
    this.Touched = true;
    var element = this.Element;
    element.style.display = Qva.MgrGetDisplayFromMode(this, mode);
    if (element.style.display == "none") return;
    element.style.borderBottom = "solid 1pt Black";
    var IsContained = this.PageBinder.IsContained; //WB
    if (node.getAttribute("allowmove") == "true" && !IsContained) {
        element.onmousedown = Qva.Move.mouseDown;
    } else {
        element.onmousedown = null;
    }
    if (this.InlineStyle) {
        setStyle(node, element);
        element.activecolor = node.getElementsByTagName("activecolor")[0];
        element.color = node.getElementsByTagName("color")[0];
        var color = element.color.getAttribute('color');
        var bkgcolor = element.color.getAttribute('bkgcolor');
    }

    if (mode != 'n') {
        element.innerHTML = "";
        var icons = node.getElementsByTagName("action");
        if (icons.length >= 1) {
            for (var i = (icons.length - 1); i >= 0; i--) {
                var icon = icons[i];
                if (icon.getAttribute("type") == "divider") {
                    debugger;
                    continue;
                }
                if (IsContained && icon.getAttribute("name") == "MI") continue //WB
                var iconnodes = icon.getElementsByTagName("icon");
                var iconnode = null;
                for (var iIcon = 0; iIcon < iconnodes.length; iIcon++) {
                    iconnode = iconnodes[iIcon];
                }
                if (iconnode == null) {
                    debugger;
                    continue;
                }
                var img = document.createElement("img");
                img.alt = "";
                img.className = "CaptionIcon";
                img.title = icon.getAttribute("text");
                var style = iconnode.getAttribute("style");
                if (style) {
                    img.style.cssText = style;
                }
                var url = this.PageBinder.BuildBinaryUrl(iconnode.getAttribute("path"), iconnode.getAttribute("stamp"), iconnode.getAttribute("name"));
                if (!this.InlineStyle) {
                    url += "&color=" + escape(color);
                    url += "&bkgcolor=" + escape(bkgcolor);
                }
                img.src = url;
                var disabled = icon.getAttribute("mode") == "disabled";
                if (!disabled) {
                    var action = icon.getAttribute("name");
                    var clientaction = icon.getAttribute("clientaction");
                    img.binderid = element.binderid;
                    if (action) {
                        img.onclick = onclick_action;
                        img.Name = this.Name + "." + action;
                    }
                    if (clientaction) {
                        img.onclick = onclick_ContextClientAction;
                        img.Name = this.Name;
                        img.AvqMgr = this;
                        img.clientaction = clientaction;
                        img.param = icon.getAttribute('param');
                    }
                    if (icon.getAttribute("menu") == "true") {
                        img.targetname = this.Name.replace(".Caption", "").replace(this.PageBinder.DefaultScope + ".", "");
                        img.position = action;
                        img.oncontextmenu = function(event) { return Qva.GetBinder(this.binderid).OnContextMenu(event, this.Name); }
                    }
                }
                element.appendChild(img);
            }
        }
        var label = node.getAttribute('label');
        if (!label) {
            if (!this.InlineStyle)
                if (element.color.getAttribute('bkgcolor')) element.style.color = element.color.getAttribute('bkgcolor');
            label = "Gg";
            this.NoText = true;
        } else {
            this.NoText = false;
        }
        var span = document.createElement("span");
        span.innerText = label;
        element.appendChild(span);
    }
    if (this.InlineStyle) {
        this.RowSpan = node.getAttribute("rowspan");
        if (this.RowSpan) {
            Qva.QueuePostPaintMessage(this);
            this.Dirty = true;
        }
    }
}

Qva.Mgr.tabrow = function (owner, elem, name, prefix) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    owner.AddManager(this);
    this.Element = elem;
    elem.Name = this.Name;
    elem.binderid = owner.ID;
}

Qva.Mgr.tabrow.prototype.Paint = function (mode, node, name) {
    this.Touched = true;
    var element = this.Element;
    if (mode != 'n') {
        var tabs = node.getElementsByTagName ("value");
        var tabNodes = element.getElementsByTagName("a");
        for (var itab = 0; itab < Math.max(tabs.length, tabNodes.length); itab++) {
            var tabnode = tabs [itab];
            var tabelem = tabNodes[itab];
            if(!tabnode && !tabelem) continue;
            if (!tabelem) {
                tabelem = document.createElement ("a");
                tabelem.dir = "ltr";
                element.appendChild (tabelem);
            }
            if(!tabnode || tabnode.getAttribute ('mode') == "hidden") {
                tabelem.style.display = "none";
                continue;
            }
            tabelem.innerHTML = "";
            var id = tabnode.getAttribute ("name");
            tabelem.id = id;
            tabelem.style.display = "";
            
            var selected = tabnode.getAttribute ('selected') === "true";
            tabelem.className = selected ? "selected" : "";
            setStyle (tabnode, tabelem);
            setBackgroundStyle (tabnode, tabelem);
            var icons = tabnode.getElementsByTagName ("icon");
            var text;
            if (IS_IE) {
                text =  " " + tabnode.getAttribute ("text") + " ";
                if (icons.length >= 1) tabelem.style.paddingRight = "4pt";
            } else {
                text = tabnode.getAttribute ("text");
                if (icons.length >= 1) text += " ";
                if (selected) {
                    tabelem.style.padding = "1pt 4pt 1pt 4pt";
                } else {
                    tabelem.style.padding = "0pt 4pt 0pt 4pt";
                }
            }
            var textnode = document.createTextNode (text);
            tabelem.appendChild (textnode);
            if (icons.length >= 1) {
                var stamp = icons[0].getAttribute ("stamp");
                var name = icons[0].getAttribute ("name");
                var color = icons[0].getAttribute ("color");
                var url = this.PageBinder.BuildBinaryUrl (icons[0].getAttribute ("path"), stamp, name, color);
                var img = document.createElement ("img");
                img.alt = "";
                img.src = url;
                tabelem.appendChild (img);
            }
            if (tabnode.getAttribute ('action')) {
                tabelem.onclick = onclick_action;
                tabelem.Name = this.Name + "." + id;
            }
            if (IS_MAC) {
                if (IS_GECKO) {
                    tabelem.style.top = "2pt";
                }
            } else if (IS_GECKO) {
                tabelem.style.top = "0.5pt";
            } else if (IS_CHROME) {
                tabelem.style.top = "2pt";
            }
        }
    }
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
}

Qva.Mgr.background = function (owner, elem, name, prefix) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    owner.AddManager(this);
    this.Element = elem;
    elem.Name = this.Name;
    elem.binderid = owner.ID;
    this.AutoSize = false;
}

function setBackgroundStyle (node, element) {
    if (node.getAttribute ('bkgcolor')) element.style.backgroundColor = node.getAttribute ('bkgcolor');
    element.style.backgroundPosition = node.getAttribute ('bkgposition') || "left top";
    if (node.getAttribute ('bkgrepeat')) element.style.backgroundRepeat = node.getAttribute ('bkgrepeat');
    if (node.getAttribute ('opacity')) {
        if (IS_CHROME || IS_OPERA || IS_SAFARI) {
            element.style.opacity = parseFloat (node.getAttribute ('opacity'));
        } else if (IS_GECKO) {
            element.style.MozOpacity = parseFloat (node.getAttribute ('opacity'));
        } else {
            element.style.filter = "alpha(opacity:" + parseFloat (node.getAttribute ('opacity')) * 100 + ")";
        }
    }
}

Qva.Mgr.background.prototype.PostPaint = function () {
    var element = this.Element;
    if (element.tagName == "DIV") {
        if (element.style.height == "auto" || this.AutoSize) {
            this.AutoSize = true;
            var newheight = parseInt (getContentMaxHeight (element));
            if (! isNaN (newheight)) {
                var frontid = element.parentNode.id.replace ("_bkg", "_frame");
                var frontelem = window.document.getElementById (frontid);
                if (frontelem) {
                    var froncaption = getSiblingByClassname (frontelem, "caption");
                    if (froncaption) {
                        var backgroundoffset = froncaption.offsetHeight;
                        var bkgcaption = getSiblingByClassname (element.parentNode, "caption");
                        if (bkgcaption && parseInt (bkgcaption.style.height) != backgroundoffset) {
                            if (bkgcaption.offsetHeight == 0) newheight -= backgroundoffset;
                            bkgcaption.style.height = backgroundoffset + "px";
                        }
                    }
                    else {
                        var backgroundoffset = 0;
                        var bkgcaption = getSiblingByClassname (element.parentNode, "caption");
                        if (bkgcaption && parseInt (bkgcaption.style.height) != backgroundoffset)
                            bkgcaption.style.height = backgroundoffset + "px";
                    }
                    var frontcontent = getSiblingByClassname (frontelem, "content");
                    if (frontcontent) {
                        var newheightfront = parseInt (getContentMaxHeight (frontcontent));
                        if (! isNaN (newheightfront))
                            frontcontent.style.height = newheightfront + "px";
                    }
                }
                element.style.height = newheight + "px";
            }
        }
        if (element.style.width == "auto" || this.AutoSize) {
            var objectframeNode = element.parentNode;
            setContentWidth (objectframeNode);
            if (frontelem) setContentWidth (frontelem);
        }
    }
    if (this.avq_url) { 
        var offset;
        if (element == document.body) {
            offset = Qva.GetAbsolutePageCoords(document.getElementById("PageContainer")).y;
        }
        var url = this.avq_url;
        if (this.AutoSize) {
            var width = parseInt (element.style.width);
            var height = parseInt (element.style.height);
            if (isNaN (width) || isNaN (height)) {
                if (element == document.body) {
                    width = parseInt (Qva.GetViewportWidth ());
                    height = parseInt (Qva.GetViewportHeight ());
                } else {
                    debugger;
                }
            }
            if (element == document.body) {
                height -= offset;
            }
            if (this.PageBinder.IsHosted) {
                this.PageBinder.Append (this, this.Name, 'w' + width + "px", false);
                this.PageBinder.Append (this, this.Name, 'w' + height + "px", false);
            } else {
                url += '&width=' + escape (width);
                url += '&height=' + escape (height);
            }
        }
        element.style.backgroundImage = "url(" + url + ")";
        if (element == document.body) {
            document.body.style.backgroundPosition = document.body.style.backgroundPosition.replace("top", offset + "px");
        }
    } else {
        element.style.backgroundImage = "";
    }
}

Qva.Mgr.background.prototype.Paint = function(mode, node, name) {
    this.Touched = true;
    var element = this.Element;
    var image = node.getAttribute ("bkgimage");
    if (image == "true") { 
        var stamp = node.getAttribute ("stamp");
        var url = this.PageBinder.BuildBinaryUrl (node.getAttribute ("path"), stamp, this.Name);
        this.avq_url = url;
    } else {
        this.avq_url = null;
        element.style.backgroundImage = "";
    }
    setBackgroundStyle (node, element);
    if (! node.getAttribute ('bkgposition') && node.getAttribute ('bkgrepeat') != "repeat" && element == document.body) {
        this.AutoSize = true
    }
    
    Qva.QueuePostPaintMessage (this);
}

Qva.Mgr.bind = function (owner, elem, name, prefix) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    owner.AddManager(this);
    this.Element = elem;
    elem.Name = this.Name;
    elem.binderid = owner.ID;
}

Qva.Mgr.bind.prototype.Paint = function(mode, node, name) {
    this.Touched = true;
    var element = this.Element;
    if (mode != 'n') {
        setStyle (node, element);
        var attrValue = '';
        if (mode != 'n') {
            attrValue = node.getAttribute (this.Attr);
        }
        if (attrValue == '' && this.TextIfNull) attrValue = this.TextIfNull;
        var text;
        if (this.Dec != null) {
            text = Qva.Trunc (attrValue, this.Dec);
        } else {
            text = attrValue;
        }
        var icons = node.getElementsByTagName ("icon");
        if (icons.length >= 1) {
            element.innerHTML = text;
            var url = this.PageBinder.BuildBinaryUrl (icons[0].getAttribute ("path"), icons[0].getAttribute ("stamp"), icons[0].getAttribute ("name"));
            var innerhtml = '&nbsp;<img alt="" src="' + url + '" />';
            element.innerHTML += innerhtml;
        } else {
            if (text) element.innerText = text;
        }
        if (node.getAttribute ('action')) {
            element.onclick = onclick_action;
        }
    }
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
}

Qva.Mgr.label = function (owner, elem, name, prefix) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    owner.AddManager(this);
    this.Element = elem;
    elem.Name = this.Name;
    elem.binderid = owner.ID;
    this.AutoSize = false;
	if (elem.style.width == 'auto' && elem.style.height == 'auto') this.AutoSize = true;
    this.InlineStyle = owner.InlineStyle;
    if (elem.getAttribute ('AvqStyle')) {
        this.InlineStyle = elem.getAttribute ('AvqStyle') == "true";
    }
}

Qva.Mgr.label.prototype.PostPaint = function () {
    if (this.AutoSize) {
        var element = this.Element;
        if (element.tagName == "DIV") {
            var newheight = parseInt (getContentMaxHeight (element, true));
            if (! isNaN (newheight)) {
                element.style.height = newheight + "px";
            }
            var objectframeNode = element.parentNode;
            setContentWidth (objectframeNode);
        }
    }
}

Qva.Mgr.label.prototype.Paint = function(mode, node) {
    this.Touched = true;
    var element = this.Element;
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
    if (this.InlineStyle) {
        setStyle (node, element);
    }
    if (element.style.display != "none" && this.AutoSize) Qva.QueuePostPaintMessage (this);
}

Qva.Mgr.frame = function (owner, elem, name, prefix, handleClick) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    owner.AddManager(this);
    this.Element = elem;
    elem.Name = this.Name;
    elem.binderid = owner.ID;
    elem.AvqMgr = this;
    if (! elem.Chart) {
        var chartid = elem.id.replace ("_frame", "_chart");
        elem.Chart = window.document.getElementById (chartid);
    }
    if (! elem.Caption) {
        var captionid = elem.id.replace ("_frame", "_caption");
        elem.Caption = window.document.getElementById (captionid);
    }
    var background = elem.getAttribute ('avqbackground');
    this.IsBackGround = false;
    if (background != null) {
        this.IsBackGround = background == "true";
    }
    
    this.BorderColor = null;
    this.BorderStyle = null;
    this.BorderWidth = null;
    if (!handleClick && Qva.LabelClick) {
        elem.onclick = function (event) { Qva.GetBinder(this.binderid).SetClick(event, this.Name); }
    }
    this.radiustopleft = -1;
    this.radiustopright = -1;
    this.radiusbottomleft = -1;
    this.radiusbottomright = -1;
    Qva.DragDrop.DropFrames[Qva.DragDrop.DropFrames.length] = this;
    var transientname = owner.DefaultScope + ".DS";
    if (Qva.LabelClick && owner.Members && ! owner.Members [transientname]) {
        this.PageBinder.CreateTransientListBox (transientname);
    }
}

Qva.Mgr.frame.prototype.Inside = function(pos, type) {
    var elem = this.Element;
    var cellPos = Qva.GetPageCoords(elem);
    var cellWidth = parseInt(elem.offsetWidth);
    var cellHeight = parseInt(elem.offsetHeight);
    if (pos.x > cellPos.x && pos.x < cellPos.x + cellWidth &&
            pos.y > cellPos.y && pos.y < cellPos.y + cellHeight) {
        return { 'Element': (this.DropType == type) ? elem : null };
    }
    return null;
}

Qva.Mgr.frame.prototype.PostPaint = function () {
    SetActiveStyle (this.Element, this.Element.IsActive);
}

Qva.Mgr.frame.prototype.PaintCorners = function (node) {
    if (! IS_IE) {
        var corners = node.getElementsByTagName("Corners");
        if (corners.length > 0 || this.radiustopleft != -1) {
            var element = this.Element;
            var firstchild = null;
            for (var ichild = 0; ichild < element.childNodes.length; ichild++) {
                var child = element.childNodes [ichild];
                if (! child.style) continue;
                if (child.style.display == 'none') continue;
                if (child.className == 'ResizeFrame') continue;
                if (child.className == 'MoveZone') continue;
                firstchild = child;
                break;
            }
            var anychanges = false;
            if (this.FirstChild != firstchild) {
                this.FirstChild = firstchild;
                anychanges = true;
            }
            var lastchild = null;
            for (var ichild = element.childNodes.length - 1; ichild >= 0; ichild--) {
                var child = element.childNodes [ichild];
                if (! child.style) continue;
                if (child.style.display == 'none') continue;
                lastchild = child;
                break;
            }
            if (this.LastChild != lastchild) {
                this.LastChild = lastchild;
                anychanges = true;
            }
            if (corners.length > 0) {
                var corner = corners[0];
                var radiustopleft = parseFloat (corner.getAttribute ('radiustopleft'));
                if (this.radiustopleft != radiustopleft) {
                    this.radiustopleft = radiustopleft;
                    anychanges = true;
                }
                var radiustopright = parseFloat (corner.getAttribute ('radiustopright'));
                if (this.radiustopright != radiustopright) {
                    this.radiustopright = radiustopright;
                    anychanges = true;
                }
                var radiusbottomleft = parseFloat (corner.getAttribute ('radiusbottomleft'));
                if (this.radiusbottomleft != radiusbottomleft) {
                    this.radiusbottomleft = radiusbottomleft;
                    anychanges = true;
                }
                var radiusbottomright = parseFloat (corner.getAttribute ('radiusbottomright'));
                if (this.radiusbottomright != radiusbottomright) {
                    this.radiusbottomright = radiusbottomright;
                    anychanges = true;
                }
            }
            if (anychanges == true) {
                element.style.MozBorderRadiusTopleft = this.radiustopleft + "pt";
                element.style.WebkitBorderTopLeftRadius = this.radiustopleft + "pt";
                if (this.FirstChild) {
                    this.FirstChild.style.MozBorderRadiusTopleft = this.radiustopleft + "pt";
                    this.FirstChild.style.WebkitBorderTopLeftRadius = this.radiustopleft + "pt";
                }
                element.style.MozBorderRadiusTopright = this.radiustopright + "pt";
                element.style.WebkitBorderTopRightRadius = this.radiustopright + "pt";
                if (this.FirstChild) {
                    this.FirstChild.style.MozBorderRadiusTopright = this.radiustopright + "pt";
                    this.FirstChild.style.WebkitBorderTopRightRadius = this.radiustopright + "pt";
                }
                element.style.MozBorderRadiusBottomleft = this.radiusbottomleft + "pt";
                element.style.WebkitBorderBottomLeftRadius = this.radiusbottomleft + "pt";
                if (this.LastChild) {
                    this.LastChild.style.MozBorderRadiusBottomleft = this.radiusbottomleft + "pt";
                    this.LastChild.style.WebkitBorderBottomLeftRadius = this.radiusbottomleft + "pt";
                }
                element.style.MozBorderRadiusBottomright = this.radiusbottomright + "pt";
                element.style.WebkitBorderBottomRightRadius = this.radiusbottomright + "pt";
                if (this.LastChild) {
                    this.LastChild.style.MozBorderRadiusBottomright = this.radiusbottomright + "pt";
                    this.LastChild.style.WebkitBorderBottomRightRadius = this.radiusbottomright + "pt";
                }
            }
        }
    }
}

Qva.Mgr.frame.prototype.Paint = function(mode, node) {
    this.Touched = true;
    this.DropType = node.getAttribute("accept");
    var element = this.Element;
    var isContained = Qva.GetBinder(element.binderid).IsContained;
    element.style.display = Qva.MgrGetDisplayFromMode(this, mode);
    if (element.style.display == "none") return;
    if (node.getAttribute("menu") == "true") {
        element.oncontextmenu = function(event) { return Qva.GetBinder(this.binderid).OnContextMenu(event, this.Name); }
    }
    this.PaintCorners(node);
    if (isContained) {
        // do nothing, size and position is determined by the container unless there are borders
        if (!this.ContainerHeight) {
            this.ContainerHeight = getClientHeight(element);
            this.ContainerWidth = getClientWidth(element);
            if (node.getAttribute('borderwidth')) {
                bor = node.getAttribute('borderwidth');
                this.ContainerHeight -= 2 * bor;
                this.ContainerWidth -= 2 * bor;
                element.style.height = this.ContainerHeight + "px";
                element.style.width = this.ContainerWidth + "px";
            }
        }
    }
    else if (node.getAttribute("maximized") == "true") {
        if (!this.Maximized) {
            if (element.Chart) element.Chart.src = "";
            if (element.maxclientheight) {
                this.maxclientheight = element.maxclientheight;
                element.maxclientheight = null;
            }
            if (element.maxclientwidth) {
                this.maxclientwidth = element.maxclientwidth;
                element.maxclientwidth = null;
            }
            this.normalheight = element.style.height;
            this.normalwidth = element.style.width;
            this.normaltop = element.style.top;
            this.normalleft = element.style.left;
            var pagecontainer = document.getElementById("PageContainer");
            var offset = Qva.GetAbsolutePageCoords(pagecontainer).y;
            var windowtop = Qva.GetScrollTop();
            var height = Qva.GetViewportHeight();
            var width = Qva.GetViewportWidth();
            var left = Qva.GetScrollLeft();
            var top = Math.max(windowtop - offset, 0);
            element.style.top = top + "px";
            element.style.left = left + "px";
            if (windowtop < offset) height -= (offset - windowtop);
            height -= element.offsetHeight - getClientHeight(element);
            height -= 7;
            element.style.height = height + "px";
            width -= element.offsetWidth - getClientWidth(element);
            width -= 6;
            element.style.width = width + "px";
            window.scrollTo(left, windowtop);
        }
    } else if (this.Maximized) {
        if (element.Chart) element.Chart.src = "";
        element.style.top = this.normaltop;
        element.style.left = this.normalleft;
        element.style.height = this.normalheight;
        element.style.width = this.normalwidth;
        if (this.maxclientheight) {
            element.maxclientheight = this.maxclientheight;
            this.maxclientheight = null;
        }
        if (element.maxclientwidth) {
            element.maxclientwidth = this.maxclientwidth;
            this.maxclientwidth = null;
        }
        this.normalheight = null;
        this.normalwidth = null;
        this.normaltop = null;
        this.normalleft = null;
    } else {
        var rects = node.getElementsByTagName("rect");
        var rect = null;
        if (rects.length > 0) {
            rect = rects[0];
            if (this.rect == null) {
                // first run
                element.style.left = parseFloat(rect.getAttribute("left")) + "pt";
                element.style.top = parseFloat(rect.getAttribute("top")) + "pt";
                element.style.width = parseFloat(rect.getAttribute("width")) + "pt";
                element.style.height = parseFloat(rect.getAttribute("height")) + "pt";
            } else if (rect != this.rect) {
                // changed rect
                element.maxclientheight = null;
                element.maxclientwidth = null;
                if (rect.getAttribute("left") != this.rect.getAttribute("left"))
                    element.style.left = parseFloat(rect.getAttribute("left")) + "pt";
                if (rect.getAttribute("top") != this.rect.getAttribute("top"))
                    element.style.top = parseFloat(rect.getAttribute("top")) + "pt";
                if (rect.getAttribute("width") != this.rect.getAttribute("width"))
                    element.style.width = parseFloat(rect.getAttribute("width")) + "pt";
                if (rect.getAttribute("height") != this.rect.getAttribute("height"))
                    element.style.height = parseFloat(rect.getAttribute("height")) + "pt";
            }
            var zindex = parseInt(rect.getAttribute("zindex"));
            if (zindex) {
                element.style.zIndex = zindex;
            }
        }
        this.rect = rect;
    }
    this.Maximized = node.getAttribute("maximized") == "true" && document.getElementById("PageContainer") != null;
    this.Simplified = node.getAttribute('simple') == "true";
    if (node.getAttribute('bordercolor')) {
        element.BorderColor = node.getAttribute('bordercolor');
        if (this.Simplified) {
            element.ActiveBorderColor = node.getAttribute('activebordercolor');
        }
        if (node.getAttribute('borderstyle')) {
            element.BorderStyle = node.getAttribute('borderstyle');
            if (node.getAttribute('borderwidth')) {
                element.BorderWidth = node.getAttribute('borderwidth');
                this.Dirty = true;
                Qva.QueuePostPaintMessage(this);
            }
        }
    }
    if (!element.avqbackground && !isContained) {
        var resizer = element.firstChild;
        if (resizer && resizer.className != "ResizeFrame") resizer = null;
        if (node.getAttribute("allowresize") == "true") {
            Qva.Mgr.CreateAndUpdateResizeHandles(element);
        } else {
            if (resizer) element.removeChild(resizer);
        }
        Qva.Mgr.CreateOrDeleteMoveHandle(element, node.getAttribute("allowmove") == "true")
    }
}

Qva.Mgr.edit = function (owner, elem, name, prefix) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    owner.AddManager(this);
    this.Element = elem;
    owner.Append (this, this.Name, 'choice');
    this.InlineStyle = owner.InlineStyle;
    if (elem.getAttribute ('AvqStyle')) {
        this.InlineStyle = elem.getAttribute ('AvqStyle') == "true";
    }
}

Qva.Mgr.edit.prototype.Paint = function(mode, node, name) {
    this.Touched = true;
    var element = this.Element;
    if (name == this.ToolTip && node.getAttribute ('text')) {
        element.title = node.getAttribute ('text');
        return;
    }
    var attrValue = '';
    if (mode != 'n') {
        attrValue = node.getAttribute (this.Attr);
        switch (this.Attr) {
        case 'value':
            if (node.getAttribute ('text') == '') attrValue = '';
            break;
        case 'color':
            if (node.getAttribute ('color') && node.getAttribute ('bkgcolor')) {
                element.style.color = node.getAttribute ('color');
                element.style.backgroundColor = node.getAttribute ('bkgcolor');
                return;
            }
        }
    }
    if (attrValue == '' && this.TextIfNull) attrValue = this.TextIfNull;
    var text;
    if (this.Dec != null) {
        text = Qva.Trunc (attrValue, this.Dec);
    } else {
        text = attrValue;
    }
    element.innerText = text;
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
    if (node.getAttribute ('paddingTop')) element.style.paddingTop = node.getAttribute ('paddingTop') + "pt";
    if (node.getAttribute ('paddingLeft')) element.style.paddingLeft = node.getAttribute ('paddingLeft') + "pt";
    if (node.getAttribute ('paddingRight')) element.style.paddingRight = node.getAttribute ('paddingRight') + "pt";
    if (node.getAttribute ('paddingBottom')) element.style.paddingBottom = node.getAttribute ('paddingBottom') + "pt";
    if (this.InlineStyle) {
        setStyle (node, element);
    }
}

Qva.Mgr.inputcheckbox = function (owner, elem, name, prefix, condition) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    this.Element = elem;
    owner.AddManager(this);
    if (condition != null) {
        var sep = condition.substr(1,1);
        var parts = condition.split(sep);
        this.Conditional = (parts[0] == '-') ? -1 : 1;
        var alt1 = (parts.length > 1) ? parts[1] : '';
        var alt2 = (parts.length > 2) ? parts[2] : null;
        elem.True = (this.Conditional > 0) ? alt1 : alt2;
        elem.False = (this.Conditional < 0) ? alt1 : alt2;
    } else {
        this.Conditional = 0;
        elem.True = '1';
        elem.False = '0';
        this.Attr = 'value';
    }
    
    elem.Name = this.Name;
    elem.Attr = this.Attr;
    elem.binderid = owner.ID;
    
    elem.onclick = Qva.Mgr.inputcheckbox.OnClick;
    owner.Append (this, this.Name, 'choice');
}

Qva.Mgr.inputcheckbox.prototype.Lock = Qva.LockDisabled;
Qva.Mgr.inputcheckbox.prototype.Unlock = Qva.UnlockDisabled;
Qva.Mgr.inputcheckbox.prototype.Paint = function(mode, node) {
    this.Touched = true;
    var element = this.Element;
    var val = node.getAttribute (this.Attr);
    if (this.Conditional < 0) {
        element.checked = (val != element.False);
    } else {
        element.checked = (val == element.True);
    }
    var choices = node.getElementsByTagName ("choice");
    if (choices.length == 0) {
        element.disabled = (mode != 'e');
    } else {
        choices = choices[0].getElementsByTagName ("element");
        var range = choices.length;
        if (range > 1) {
            element.disabled = (mode != 'e');
        } else {
            element.disabled = true;
        }
    }
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
}

Qva.Mgr.inputcheckbox.OnClick = function() {
    var binder = Qva.GetBinder(this.binderid);
    if (!binder.Enabled) return;
    var newval = this.checked ? this.True : this.False;
    if (newval != null) {
        binder.Set (this.Name, this.Attr, newval, true);
    } else {
        newval = this.checked ? this.False : this.True;
        binder.Set (this.Name, 'count', '-' + newval, true);
    }
}

Qva.Mgr.inputradio = function (owner, elem, name, prefix) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    this.Element = elem;
    elem.Name = this.Name;
    elem.Attr = this.Attr;
    elem.binderid = owner.ID;
    owner.AddManager(this);
    
    elem.onclick = function () {
        if (!IS_GECKO && this.checked) return;
        var binder = Qva.GetBinder(this.binderid);
        if (!binder.Enabled) return;
        binder.Set (this.Name, this.Attr, this.value, true);
    };
    owner.Append (this, this.Name, 'choice');
}

Qva.Mgr.inputradio.prototype.PostScan = function(scanner) {
    var CheckIf = this.Element.getAttribute (scanner.Prefix + 'checkif');
    if (CheckIf) {
        this.CheckIf = new Function("value", "return " + CheckIf);
    }
}

Qva.Mgr.inputradio.prototype.Lock = Qva.LockDisabled;
Qva.Mgr.inputradio.prototype.Unlock = Qva.UnlockDisabled;
Qva.Mgr.inputradio.prototype.Paint = function(mode, node) {
    this.Touched = true;
    var element = this.Element;
    var value = node.getAttribute(this.Attr);
    if (this.CheckIf) {
        element.checked = this.CheckIf(value);
    } else {
        element.checked = (element.value == value);
    }
    element.disabled = (mode != 'e');
    if (mode == 'e' && !element.checked) {
        // check if should be disabled because not in choice
        var choices = node.getElementsByTagName ("choice");
        if (choices.length >= 1) {
            element.disabled = true;
            choices = choices[0].getElementsByTagName ("element");
            var cholen = choices.length;
            for (var ix = 0; ix < cholen; ++ix) {
                if (choices [ix].getAttribute(this.Attr) == element.value) {
                    element.disabled = false;
                    break;
                }
            }
        }
    }
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
}

Qva.Mgr.inputtext = function (owner, elem, name, prefix, condition) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    this.Element = elem;
    this.Condition = condition;
    elem.Name = this.Name;
    elem.binderid = owner.ID;
    elem.Attr = this.Attr;
    
    owner.AddManager(this);
    elem.onclick = function (event) {
        Qva.ActiveObject = null;
        if (!event) event = window.event;
        event.cancelBubble = true;
    };
    elem.onchange = function () {
        var binder = Qva.GetBinder(this.binderid);
        if (!binder.Enabled) return;
        if (this.value == '') {
            binder.Set(this.Name, 'text', '', true);
        } else {
            binder.Set(this.Name, this.Attr, this.value, true);
        }
    };
}
Qva.Mgr.inputtext.prototype.Lock = Qva.LockReadOnly;
Qva.Mgr.inputtext.prototype.Unlock = Qva.UnlockReadOnly;
Qva.Mgr.inputtext.prototype.Paint = function(mode, node) {
    this.Touched = true;
    var element = this.Element;
    element.readOnly = (mode != 'e');
    element.disabled = false;
    var attrValue = '';
    if (mode != 'n') {
        attrValue = node.getAttribute (this.Attr);
        if (this.Attr == 'value' && node.getAttribute ('text') == '') attrValue = '';
    }
    if (mode != 'n' && this.Condition != null) {
        var cval = node.getAttribute ('value');
        if (cval == this.Condition) {
            element.disabled = true;
            attrValue = '';
        }
    }
    if (attrValue == '' && this.TextIfNull) attrValue = this.TextIfNull;
    if (this.Dec != null) {
        element.value = Qva.Trunc (attrValue, this.Dec);
    } else {
        element.value = attrValue;
    }
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
    setStyle (node, element);
}

function Avq_Search_Focus (event) {
    var binder = this.AvqMgr.PageBinder;
    var name = this.AvqMgr.Name.replace (".Input", "");
    if (this.value == this.AvqMgr.DefaultText) {
        this.style.fontStyle = "";
        this.style.color = "";
        this.value = "**";
        Qva.SetCursor (this);
        binder.Set (name, "click", "", true);
    }
    binder.GlobaSearchObject = name;
}

function WebkitClickFix (event) {
    if (this.value == "**") {
        Qva.SetCursor (this);
    }
}

function Avq_Search_KeyDown(event) {
    if (! event) { 
        event = window.event; 
    }
    var mgr = this.AvqMgr;
    if (this.value == mgr.DefaultText) {
        this.value = "**";
        Qva.SetCursor (this);
        this.style.fontStyle = "";
        this.style.color = "";
    }
    var key = event.keyCode;
    var accept = false;
    switch (key) {
    case 13:    // <Enter>
        accept = true;
    case 27:    // <Escape>'
        var binder = mgr.PageBinder || Qva.GetBinder(mgr.binderid);
        if (binder.Enabled) {
	        if (accept) binder.Set (mgr.SearchName, "search", this.value, false);
	        var cmd = accept ? "accept" : "abort";
            binder.Set (mgr.SearchName, "closesearch", cmd, true);
        }
        this.value = mgr.DefaultText;
        this.style.fontStyle = mgr.DefaultFontStyle;
        this.style.color = mgr.DefaultColor;
        binder.GlobaSearchObject = "";
        break;
    }
}

Qva.Mgr.inputsearch = function (owner, elem, name, prefix, condition) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    this.Element = elem;
    this.Condition = condition;
    elem.Name = this.Name;
    elem.binderid = owner.ID;
    elem.Attr = this.Attr;
    elem.onkeydown = Avq_Search_KeyDown;
    elem.onkeyup = AvqAction_Search_KeyUp;
    elem.onfocus = Avq_Search_Focus;
    if (IS_SAFARI || IS_CHROME) {
        elem.onclick = WebkitClickFix;
    } else {
        elem.onclick = Qva.CancelAction;
    }
    elem.AvqMgr = this;
    this.SearchName = this.Name;
    owner.AddManager(this);
}

Qva.Mgr.inputsearch.prototype.PostPaint = function () {
    // A rather ugly way to get to the table parent
    var element = this.Element;
    var parentNode = element.parentNode.parentNode.parentNode.parentNode.parentNode;
    if (parentNode.tagName == "DIV" && parentNode.className == "content") {
        var newheight = parseInt (getContentMaxHeight (parentNode));
        if (! isNaN (newheight)) {
            parentNode.style.height = newheight + "px";
        }
        var objectframeNode = parentNode.parentNode;
        setContentWidth (objectframeNode);
    }
}

Qva.Mgr.inputsearch.prototype.Paint = function (mode, node) {
    this.Touched = true;
    var element = this.Element;
    element.readOnly = (mode != 'e');
    element.disabled = false;

    if (! this.DefaultText) {
        this.DefaultText = node.getAttribute ("defaulttext");
    }
    if (! this.DefaultFontStyle) {
        this.DefaultFontStyle = node.getAttribute ("fontstyle");
    }
    if (! this.DefaultColor) {
        this.DefaultColor = node.getAttribute ("color");
    }
    if (node.getAttribute ("searching") != "true") {
        element.value = this.DefaultText;
        this.DefaultFontStyle = node.getAttribute ("fontstyle");
        this.DefaultColor = node.getAttribute ("color");
    } else {
        this.PageBinder.GlobaSearchObject = this.Name.replace (".Input", "");
    }
    setStyle (node, element);
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
    
    if (node.parentNode.getAttribute ("allowmove") == "false") {
        element.onmousedown = null;
    }
    Qva.QueuePostPaintMessage (this);
}

Qva.Mgr.searchresults = function (owner, elem, name, prefix, condition) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    this.Element = elem;
    this.Condition = condition;
    elem.Name = this.Name;
    elem.binderid = owner.ID;
    elem.Attr = this.Attr;
    if (! elem.SO) {
        var parentid = elem.id.replace ("_results", "_frame");
        elem.SO = window.document.getElementById (parentid);
    }
    owner.AddManager(this);
}

Qva.Mgr.searchresults.prototype.Paint = function (mode, node) {
    this.Touched = true;
    var element = this.Element;
    var minheight = 100;
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
    element.style.left = element.SO.style.left;
    element.style.width = element.SO.style.width;
    var freespace = Qva.GetViewportHeight() + Qva.GetScrollTop () - (element.SO.offsetTop + element.SO.clientHeight) - 40;
    if (freespace > minheight) {
        element.style.top = (element.SO.offsetTop + element.SO.clientHeight) + "px";
//        element.style.height = Qva.GetViewportHeight () - (parseInt (element.style.top) - Qva.GetScrollTop ()) - 40 + "px";
        element.style.height = freespace + "px";
    } else {
        element.style.height = element.SO.offsetTop + "px";
        setTimeout(function() {element.style.top = (element.SO.offsetTop - element.clientHeight) + "px";},0);
    }
}

Qva.Mgr.textarea = Qva.Mgr.inputtext;
Qva.Mgr.inputpassword = Qva.Mgr.inputtext;

Qva.Mgr.text = function (owner, elem, name, prefix, tooltip) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    if (tooltip != null) {
        this.ToolTip = Qva.MgrMakeName (tooltip, prefix);
        owner.Append (this, this.ToolTip);
    }
    if (elem.tagName == 'SELECT') { debugger; }
    owner.AddManager(this);
    this.Element = elem;
    owner.Append (this, this.Name, 'value');
    this.InlineStyle = owner.InlineStyle;
    if (elem.getAttribute ('AvqStyle')) {
        this.InlineStyle = elem.getAttribute ('AvqStyle') == "true";
    }
}

Qva.Mgr.text.prototype.Paint = Qva.Mgr.edit.prototype.Paint;

Qva.Mgr.step = function (owner, elem, name, prefix, step) {
    switch (step) {
    case "next":
        this.Next = true;
        break;
    case "prev":
        this.Next = false;
        break;
    default:
        elem.Step = parseFloat (step);
        if (isNaN (elem.Step)) return;
        break;
    }
    if (!Qva.MgrSplit (this, name, prefix)) return;
    if (elem.Step == null) elem.Choice = new Array();
    owner.AddManager(this);
    this.Element = elem;
    
    elem.Name = this.Name;
    elem.binderid = owner.ID;
    elem.Attr = this.Attr;
    elem.onclick = Qva.Mgr.step.OnClick;
    owner.Append (this, this.Name, 'choice');
}

Qva.Mgr.step.prototype.Lock = Qva.LockDisabled;
Qva.Mgr.step.prototype.Unlock = Qva.UnlockDisabled;
Qva.Mgr.step.prototype.Paint = function(mode, node) {
    this.Touched = true;
    var element = this.Element;
    element.disabled = (mode != 'e');
    if (mode == 'n') {
        // no action
    } else if (element.Step != null) {
        element.Last = parseFloat (node.getAttribute (this.Attr));
    } else {
        var value = node.getAttribute (this.Attr);
        var choiceNodes = node.getElementsByTagName ("choice");
        element.Pending = -1;
        if (choiceNodes.length >= 1) {
            var choices = choiceNodes[0].getElementsByTagName ("element");
            var height = choices.length;
            for (var rix = 0; rix < height; ++rix) {
                element.Choice [rix] = choices[rix].getAttribute(this.Attr);
                if (choices[rix].getAttribute("selected") == "yes") {
                    if (this.Next) {
                        element.Pending = rix + 1;
                    } else {
                        element.Pending = rix - 1;
                    }
                }
            }
            element.Choice.length = height;
        }
        if (element.Pending < 0 || element.Pending >= element.Choice.length) element.disabled = true;
    }
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
}

Qva.Mgr.step.OnClick = function() {
    var binder = Qva.GetBinder(this.binderid);
    if (!binder.Enabled) return;
    var newval;
    if (this.Step != null) {
        newval = this.Last + this.Step;
    } else {
        if (this.Pending < 0 || this.Pending >= this.Choice.length) return;
        newval = this.Choice[this.Pending];
    }
    binder.Set (this.Name, this.Attr, '' + newval, true);
}

Qva.Mgr.actions = function (owner, elem, name, prefix) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    this.Attr = "mode";
    owner.AddManager(this);
    this.Element = elem;
    elem.Name = this.Name;
    elem.binderid = owner.ID;
}

Qva.Mgr.actions.prototype.Lock = Qva.LockDisabled;
Qva.Mgr.actions.prototype.Unlock = Qva.UnlockDisabled;
Qva.Mgr.actions.prototype.Paint = function (mode, node) {
    this.Touched = true;
    var element = this.Element;
    element.disabled = (mode != 'e');
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
    if (node.getAttribute ('actions') == "true") {
        element.style.cursor = 'hand';
        element.onclick = onclick_action;
    }
}

Qva.Mgr.scroll = function (owner, elem, name, prefix) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    owner.AddManager(this);
    this.Element = elem;
}

Qva.Mgr.scroll.prototype.Paint = function (mode, node) {
    this.Touched = true;
    var element = this.Element;
    if (node.getAttribute ('overflowx')) {
        element.style.overflowX = node.getAttribute ('overflowx');
    }
    if (node.getAttribute ('overflowy')) {
        element.style.overflowY = node.getAttribute ('overflowy');
    }
}

Qva.Mgr.action = function (owner, elem, name, prefix) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    this.Attr = "mode";
    owner.AddManager(this);
    this.Element = elem;
    elem.Name = this.Name;
    elem.binderid = owner.ID;
    elem.onclick = onclick_action;
    owner.Append (this, this.Name, 'action');
}

Qva.Mgr.action.prototype.Lock = Qva.LockDisabled;
Qva.Mgr.action.prototype.Unlock = Qva.UnlockDisabled;
Qva.Mgr.action.prototype.Paint = function (mode, node) {
    this.Touched = true;
    var element = this.Element;
    element.disabled = (mode != 'e');
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
    if (node.getAttribute ('clientaction')) {
        element.onclick = onclick_ContextClientAction;
        element.Name = this.Name;
        element.AvqMgr = this;
        element.clientaction = node.getAttribute ('clientaction');
        element.param = node.getAttribute ("param");
    }
    setStyle (node, element);
}

Qva.Mgr.restore = function (owner, elem, name, prefix) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    this.Attr = "mode";
    owner.AddManager(this);
    this.Element = elem;
    elem.Name = this.Name;
    elem.binderid = owner.ID;
    elem.moveObj = elem.id;
    owner.Append (this, this.Name, 'action');
}

Qva.Mgr.restore.prototype.Lock = Qva.LockDisabled;
Qva.Mgr.restore.prototype.Unlock = Qva.UnlockDisabled;
Qva.Mgr.restore.prototype.Paint = function (mode, node) {
    this.Touched = true;
    var element = this.Element;
    element.disabled = (mode != 'e');
    element.style.display = node.getAttribute ("stamp") ? Qva.MgrGetDisplayFromMode (this, mode) : "none";
    if (node.getAttribute("left")) element.style.left = parseFloat(node.getAttribute("left")) + "pt";
    if (node.getAttribute("top")) element.style.top = parseFloat(node.getAttribute("top")) + "pt";
    if (node.getAttribute("width")) element.style.width = parseFloat(node.getAttribute("width")) + "pt";
    if (node.getAttribute("height")) element.style.height = parseFloat(node.getAttribute("height")) + "pt";

    element.oncontextmenu = function (event) { return Qva.GetBinder(this.binderid).OnContextMenu(event, this.Name.replace (".RE", "")); }
    if (node.getAttribute ("allowmove") == "true") {
        element.onmousedown = Qva.Move.mouseDown;
    } else {
        element.onmousedown = null;
    }
}

Qva.Mgr.select = function (owner, elem, name, prefix, condition) {
    if (elem.multiple) { debugger; return; }
    //if (elem.size > 1) { debugger; return; }
    if (!Qva.MgrSplit (this, name, prefix)) return;
    owner.AddManager(this);
    this.Element = elem;
    this.Condition = condition;
    this.Texts = new Array ();
    this.Values = new Array ();
    this.Disabled = new Array ();
    this.Locked = new Array ();
    
    elem.binderid = owner.ID;
    elem.Name = this.Name;
    
    elem.onchange = Qva.Mgr.select.OnChange;
    elem.onclick = Qva.CancelBubble;
}

Qva.Mgr.select.prototype.Lock = Qva.LockDisabled;
Qva.Mgr.select.prototype.Unlock = Qva.UnlockDisabled;
Qva.Mgr.select.prototype.Paint = function(mode, node) {
    this.Touched = true;
    var element = this.Element;
    if (mode != 'n' && element.ByValue == null) {
        element.ByValue = (node.getAttribute('value') != null);
    }
    setStyle (node, element);
    var currentValue = node.getAttribute("text");
    if (this.Dec != null) currentValue = Qva.Trunc (currentValue, this.Dec);
    if (currentValue == null) currentValue = "";
    if (this.TextIfNull && currentValue == "") currentValue = this.TextIfNull;
    var optlen = element.options.length;
    if (mode == 'e' && (this.Condition == null || currentValue != '')) {
        var choices = node.getElementsByTagName ("choice");
        if (choices.length >= 1) choices = choices[0].getElementsByTagName ("element");
        var first = (this.Condition == null) ? 0 : 1;
        var cholen = choices.length - first;
        element.options.length = cholen;
        if (cholen >= 1) {
            this.SelectedIndex = -1;
            for (var ix = 0; ix < cholen; ++ix) {
                var cho = choices [ix + first];
                var optval = cho.getAttribute("text");
                if (this.TextIfNull && optval == "") optval = this.TextIfNull;
                if (this.Dec != null) optval = Qva.Trunc (optval, this.Dec);
                var opt = element.options [ix];
                opt.text = optval.replace (/\t/g, ' ');
                opt.value = element.ByValue ? cho.getAttribute('value') : optval;
                var selected = false;
                if (optval == currentValue) {
                    this.SelectedIndex = ix;
                    selected = true;
                }
                if (selected) opt.selected = true;
            }
            if (this.SelectedIndex == -1) {
                element.options [cholen-1].selected = true;
            }
        }
        element.disabled = false;
    } else {
        element.disabled = true;
        if (optlen < 1 || this.Condition != null) {
            element.options.length = 1;
            var opt0 = element.options [0];
            opt0.text = (currentValue != null) ? currentValue.replace (/\t/g, ' ') : '';
            opt0.value = element.ByValue ? node.getAttribute('value') : currentValue;
            opt0.selected = true;
        }
    }
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
}

Qva.Mgr.select.OnChange = function() {
    var binder = Qva.GetBinder(this.binderid);
    if (!binder.Enabled) return;
    if (this.selectedIndex < 0) return;
    var opt = this.options [this.selectedIndex];
    if (this.ByValue === true) {
        binder.Set (this.Name, 'value', opt.value, true);
    } else {
        binder.Set (this.Name, "text", opt.text, true);
    }
}

Qva.Mgr.binary = function (owner, elem, name, prefix) {
    elem.Name = this.Name = Qva.MgrMakeName (name, prefix);
    elem.binderid = owner.ID;
	if (elem.style.width == 'auto' && elem.style.height == 'auto') elem.autosize = true;
    this.Attr = "mode";
    owner.AddManager(this);
    this.Element = elem;
    var hover = Qva.GetBinder(elem.binderid).GetHoverDiv();
    hover.style.display = "none";
    elem.style.display = "none";
    
    elem.SelectStart = Qva.Mgr.binary.SelectStart;
    elem.Select      = Qva.Mgr.binary.Select;
    elem.SelectEnd   = Qva.Mgr.binary.SelectEnd;
    elem.onclick = function (event) { Qva.GetBinder(this.binderid).SetClick(event, this.Name, this); }
    elem.onmousedown = function (event) { Qva.MouseDown(event, this); }
    elem.onmousemove = function (event) {
        Qva.MouseMove(event, this);
        this.onmouseover(event);
    }
    elem.onmouseover = function (event) {
        if(!this.hover) return;
        if(!event) event = window.event;
        var binder = Qva.GetBinder(this.binderid);
        var name   = this.Name;
        
        var hover = binder.GetHoverDiv();
        hover.style.left = (event.clientX + Qva.GetScrollLeft() + 5) + "px";
        hover.style.top  = (event.clientY + Qva.GetScrollTop() + 5)  + "px";
        hover.style.display = "none";
        
        var pos = Qva.GetPageCoords(this);
        var click = (event.clientX - pos.x) + ':' + (event.clientY - pos.y);
        var objectframeNode = Qva.GetFrame(this);
        var graphwidth = parseInt (imagewidth (objectframeNode, this));
        var graphheight = parseInt (imageheight (objectframeNode, this));
        click += ':' + graphwidth + ':' + graphheight;
        
        if (this.hoverTimout) { this.hoverTimout = clearTimeout(this.hoverTimout); }
        this.hoverTimout = setTimeout(function () {
            if (!binder.Enabled) return;
            if (Qva.ContextMenu != null && Qva.ContextMenu.style.display != 'none') return;
            binder.Set(name, "hover", click, true);
        }, 1000 );
    };
    elem.onmouseout  = function (event) {
        if (this.hoverTimout) { this.hoverTimout = clearTimeout(this.hoverTimout); }
    }
    
    elem.style.cursor = 'crosshair';
    if (owner.IsHosted && ! elem.sizefixed) {
        var objectframeNode = elem.parentNode.parentNode;
        if (elem.style.height != '') {
            var height = imageheight (objectframeNode, elem);
            owner.Append (this, this.Name, 'h' + height + "px");
        }
        if (elem.style.width != '') {
            var width = imagewidth (objectframeNode, elem);
            owner.Append (this, this.Name, 'w' + width + "px", true);
        }
    }
}

Qva.Mgr.binary.prototype.Unlock = function () {
    this.Touched = true;
    if (this.Element.style.display != 'none') {
        this.PostPaint ();
    }
}

GraphScrollBar.prototype.Step = function (pos) {
    var binder = Qva.GetBinder (this.binderid);
    var name   = this.Name;
    var step = pos - this.Pos;
    this.Pos = pos;
    binder.Set(name, "scrollstep", step, true);
}

GraphScrollBar.prototype.createScrollEnd = function (top, left, height, width, color, firstbutton) {
    var div = document.createElement("div");
    if (this.IsXScroll) {
        div.style.top = (top + 1) + "px";
        left++;
        if (! firstbutton) left += (width - height);
        div.style.left = left + "px";
        height -= 2;
        div.style.height = height + "px";
        div.style.width = height + "px";
    } else {
        div.style.left = (left + 1) + "px";
        top++;
        if (! firstbutton) top += (height - width);
        div.style.top = top + "px";
        width -= 2;
        div.style.height = width + "px";
        div.style.width = width + "px";
    }
    div.style.backgroundColor = color;
    div.style.cursor = "pointer";
    div.style.position = "absolute";
    div.firstbutton = firstbutton;

    var position, points;
    if (this.IsXScroll) {
        position = [parseInt (height / 2) - 1, parseInt (height / 2) - 3];
        points = firstbutton ? [[2,0], [0,3], [2,6]] : [[0,0], [2,3], [0,6]];
    } else {
        position = [parseInt (width / 2) - 3, parseInt (width / 2)];
        points = firstbutton ? [[0,2], [3,0], [6,2]] : [[0, 0], [3,2], [6, 0]];
    }
    var size = [9, 9];
    this.G.CreatePolygonObj (points, "#000000", div, position, size);
    var _this = this;
    div.onmousedown = function (event) {
        if (!event) event = window.event;
        event.cancelBubble = true;
        var pos = this.firstbutton ? _this.Pos - 1 : _this.Pos + 1;
        if (pos >= 0) {
            _this.Step (pos);
        }
        return false;
    };
    return div;
}

function GraphScrollBar (mgr, parent, top, left, width, height, color, bkgcolor, max, page, isxscroll) {
    var o_scroll = document.createElement("div");
    o_scroll.style.backgroundColor = bkgcolor;
    o_scroll.style.cursor = "pointer";
    o_scroll.style.position = "absolute";

//    this.binderid = mgr.binderid;
    this.binderid = mgr.Element.binderid;
    this.Name = mgr.Name;
    this.IsXScroll = isxscroll;
    var _this = this;

    this.G = SelectInitGraphics();

    o_scroll.onmousedown = function (event) {
        if (!event) event = window.event;
        event.cancelBubble = true;
        var relpos = Qva.GetPageCoords(this);
        var px;
        var scrollpos;
        if (_this.IsXScroll) {
            px = event.clientX - relpos.x;
            scrollpos = parseInt(_this.i_Scroll.style.left);
        } else {
            px = event.clientY - relpos.y;
            scrollpos = parseInt(_this.i_Scroll.style.top);
       }
        var pos = px < scrollpos ? _this.Pos -_this.Page : _this.Pos +_this.Page;
        if (pos >= 0) {
            _this.Step (pos);
        }
        return false;
    };

    var i_scroll = document.createElement("div");
    i_scroll.style.backgroundColor = color;
    i_scroll.style.border = "solid 1px white";
    i_scroll.style.cursor = "pointer";
    i_scroll.style.position = "absolute";

    i_scroll.onmousedown = function(event) {
        if (!event) event = window.event;
        event.cancelBubble = true;
        if (_this.IsXScroll) {
            i_scroll.mouseZero = event.clientX;
            i_scroll.scrollZero = i_scroll.offsetLeft;
        } else {
            i_scroll.mouseZero = event.clientY;
            i_scroll.scrollZero = i_scroll.offsetTop;
        }

        function Update (event, mouseup) {
            if (!event) event = window.event;
            var px, pos;
            if (_this.IsXScroll) {
                px = i_scroll.scrollZero + event.clientX - i_scroll.mouseZero;
            } else {
                px = i_scroll.scrollZero + event.clientY - i_scroll.mouseZero;
            }
            if (px < _this.ScrollStart) {
                px = _this.ScrollStart;
                pos = 0;
            } else if (px > _this.ScrollStop) {
                px = _this.ScrollStop;
                pos = _this.Max - _this.Page;
            } else {
                pos = Math.round ((px - _this.ScrollStart) * _this.Page / _this.ScrollLength);
            }
            if (_this.IsXScroll) {
                i_scroll.style.left = px + "px";
            } else {
                i_scroll.style.top = px + "px";
            }
            if (_this.Pos != pos) {
                _this.Step (pos);
            } else if (mouseup) {
                _this.UpdateScrollPos ();
            }
        }
        
        function SlideEnd(event) {
            Qva.removeEvent(document,"mousemove",SlideDrag);
            Qva.removeEvent(document,"mouseup",SlideEnd);
            Update (event, true);
            _this.i_Scroll.mouseZero = null;
            Qva.Select.Active = true;
        }
        function SlideDrag(event) {
            Update (event, false);
            
            event = event || window.event;
            if (event.preventDefault) 
                event.preventDefault();
            else
                event.returnValue = false;
            return false;
        }
        Qva.Select.Active = false;
        Qva.addEvent(document,"mousemove",SlideDrag);
        Qva.addEvent(document,"mouseup",SlideEnd);
        return false;
    }

    this.o_Scroll = o_scroll;
    this.i_Scroll = i_scroll;
    parent.appendChild (o_scroll);
    parent.appendChild (i_scroll);

    this.UpdateScrollSize (top, left, width, height, max, page, 0, color, bkgcolor);
}

GraphScrollBar.prototype.UpdateScrollPos = function (pos) {
    if (! isNaN (pos)) this.Pos = pos;
    var newstart = parseInt (this.Pos * this.ScrollLength / this.Page) + this.ScrollStart;
    if (newstart > this.ScrollStop) newstart = this.ScrollStop; 
    if (this.IsXScroll) {
        this.i_Scroll.style.left = newstart + "px";
    } else {
        this.i_Scroll.style.top = newstart + "px";
    }
}

GraphScrollBar.prototype.UpdateScrollSize = function (top, left, width, height, max, page, pos, color, bgColor) {
    if (this.Top != top || this.Left != left || this.Height != height || this.Width != width) {
        this.Height = height;
        this.Top = top;
        this.Left = left;
        this.Width = width;
        this.o_Scroll.style.height = height + "px";
        this.o_Scroll.style.top = top + "px";
        this.o_Scroll.style.left = left + "px";
        this.o_Scroll.style.width = Math.max(0, width) + "px";
        if (this.IsXScroll) {
            this.i_Scroll.style.height = Math.max (1, height - 4) + "px";
            this.i_Scroll.style.top = top + 1 + "px";
            this.i_Scroll.style.left = (height + left) + "px";
        } else {
            this.i_Scroll.style.top = (width + top) + "px";
            this.i_Scroll.style.left = (left + 1) + "px";
            this.i_Scroll.style.width = Math.max (1, width - 4) + "px";
        }
        var parent = this.o_Scroll.parentNode;
        if (this.firstbutton) {
            parent.removeChild (this.firstbutton);
            parent.removeChild (this.lastbutton);
        }
        var firstbutton = this.createScrollEnd (top, left, height, width, color , true);
        var lastbutton = this.createScrollEnd (top, left, height, width, color, false);
        this.firstbutton = firstbutton;
        this.lastbutton = lastbutton;
        parent.appendChild (firstbutton);
        parent.appendChild (lastbutton);
    }

    this.Page = page;
    this.Max = max;
    var maxpos = this.Max - this.Page;
    if (this.IsXScroll) {
        this.ScrollStart = this.o_Scroll.offsetLeft + parseInt (this.Height);
        this.ScrollLength = parseFloat ((this.Width - 2 * (this.Height)) * this.Page / this.Max);
        this.ScrollLengthVisible = (this.ScrollLength > 5) ? parseInt(this.ScrollLength) : 5
        this.ScrollStop = parseInt (maxpos * this.ScrollLength / this.Page) + this.ScrollStart - (this.ScrollLengthVisible - parseInt(this.ScrollLength));
        this.i_Scroll.style.width = this.ScrollLengthVisible + "px";
    } else {
        this.ScrollStart = this.o_Scroll.offsetTop + parseInt (this.Width);
        this.ScrollLength = parseFloat ((this.Height - 2 * (this.Width)) * this.Page / this.Max);
        this.ScrollLengthVisible = (this.ScrollLength > 5) ? parseInt(this.ScrollLength) : 5
        this.ScrollStop = parseInt (maxpos * this.ScrollLength / this.Page) + this.ScrollStart - (this.ScrollLengthVisible - parseInt(this.ScrollLength));
        this.i_Scroll.style.height = this.ScrollLengthVisible + "px";
    }
    if (bgColor) this.o_Scroll.style.backgroundColor = bgColor;
    this.i_Scroll.style.backgroundColor = color;
    this.firstbutton.style.backgroundColor = color;
    this.lastbutton.style.backgroundColor = color;
    this.UpdateScrollPos (pos);
}

GraphScrollBar.prototype.GetOffset = function (px) {
    var totlength;
    if (this.IsXScroll) {
        totlength = this.o_Scroll.offsetWidth - 2 * this.Height;
    } else {
        totlength = this.o_Scroll.offsetHeight - 2 * this.Width;
    }
    return Math.round(this.Page * px / totlength);
}

Qva.Mgr.binary.prototype.Paint = function (mode, node) {
    this.Touched = true;
    var element = this.Element;
    var disabled = (mode != 'e');
    element.disabled = disabled;
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
    if (element.style.display == 'none') {
        return;
    }
    if (element.autosize) {
        var objectframeNode = element.parentNode.parentNode;
        setFrameWidth (objectframeNode, 0);
        setFrameHeight (objectframeNode, 0);
    }
    if (node.getAttribute ("selectable") == "false") { 
        element.style.cursor = '';
        element.SelectStart = null;
        element.Select      = null;
        element.SelectEnd   = null;
        element.onmousedown = null;
        element.onmousemove = null;
    } 
    if (node.getAttribute ('clientaction')) {
        element.onclick = onclick_ContextClientAction;
        element.Name = this.Name;
        element.AvqMgr = this;
        element.clientaction = node.getAttribute ('clientaction');
        element.param = node.getAttribute ("param");
    }
    
    element.hover = node.getAttribute ('hover') === "true";
    var scrollnode = node.getElementsByTagName("xscroll") [0];
    var isxscroll = true;
    if (! scrollnode) {
        scrollnode = node.getElementsByTagName("yscroll") [0];
        isxscroll = false;
    }
    if (scrollnode) {
        if (this.ScrollBar && this.ScrollBar.IsXScroll != isxscroll) {
            element.parentNode.removeChild (this.ScrollBar.o_Scroll);
            element.parentNode.removeChild (this.ScrollBar.i_Scroll);
            element.parentNode.removeChild (this.ScrollBar.firstbutton);
            element.parentNode.removeChild (this.ScrollBar.lastbutton);
            this.ScrollBar = null
        } 
        var max = parseInt (scrollnode.getAttribute ("max"));
        var page = parseInt (scrollnode.getAttribute ("page"));
        var top = parseInt (scrollnode.getAttribute ("top"));
        var left = parseInt (scrollnode.getAttribute ("left"));
        var height = parseInt (scrollnode.getAttribute ("height"));
        var width = parseInt (scrollnode.getAttribute ("width"));
        var color = scrollnode.getAttribute ("color");
        var bkgcolor = scrollnode.getAttribute ("bkgcolor");
        if (! this.ScrollBar) {
            if (width > 2 && height > 2) {
                this.ScrollBar = new GraphScrollBar (this, element.parentNode, top, left, width, height, color, bkgcolor, max, page, isxscroll);
            }
        } else {
            if (! this.ScrollBar.i_Scroll.mouseZero) {
                this.ScrollBar.UpdateScrollSize (top, left, width, height, max, page, parseInt (scrollnode.getAttribute ("pos")), color, bkgcolor)
            }
        }
    } else {
        if (this.ScrollBar) {
            element.parentNode.removeChild (this.ScrollBar.o_Scroll);
            element.parentNode.removeChild (this.ScrollBar.i_Scroll);
            element.parentNode.removeChild (this.ScrollBar.firstbutton);
            element.parentNode.removeChild (this.ScrollBar.lastbutton);
        }
        this.ScrollBar = null
    }
    var stamp = node.getAttribute ('stamp');
    if (stamp != "0") {
        var name = stamp ? this.Name : node.getAttribute ('name');
        if (element.disabled ) name += ".DISABLED";
        var url = this.PageBinder.BuildBinaryUrl (node.getAttribute ('path'), stamp, name);
        this.avq_url = url;
    }
    Qva.QueuePostPaintMessage (this);
}

Qva.Mgr.binary.prototype.PostPaint = function () {
    var elem = this.Element;
    if (elem.style.display == 'none') return;
    var imageelem = null;
    var isbutton = false;
    if (elem.tagName == "BUTTON" || elem.tagName == "DIV") {
        for (var i = 0; i < elem.childNodes.length; i++) {
            if (elem.childNodes [i].tagName == "IMG") {
                imageelem = elem.childNodes [i];
                break;
            }
        }
        isbutton = true;
        elem.style.cursor = elem.disabled ? "default" : "";
    } else {
        imageelem = elem;
    }
    elem.isgraph = ! isbutton;
    var parentNode = elem.parentNode;
    var objectframeNode = parentNode.parentNode;
    if (elem.autosize) {
        if (parentNode.tagName == "DIV") {
            var newheight = parseInt (getContentMaxHeight (parentNode));
            if (! isNaN (newheight)) {
                parentNode.style.height = newheight + "px";
            }
        }
        setContentWidth (objectframeNode, getMaxClientWidth (objectframeNode));
    }
    if (imageelem) {
        var url = this.avq_url;
        var sizeupdated = false;
        var sendsizetoserver = this.PageBinder.IsHosted || ! isbutton;
        if (elem.style.width != '') {
            var graphwidth = imagewidth (objectframeNode, elem);
            if ((IS_GECKO || IS_CHROME) && isbutton) {
                graphwidth -= 3;
            }
            if (sendsizetoserver && this.GraphWidth != graphwidth) {
                this.GraphWidth = graphwidth;
                sizeupdated = true;
            }
            if (! this.PageBinder.IsHosted) {
                url += '&width=' + escape (graphwidth);
            } else {
                imageelem.style.width = graphwidth + "px";
                elem.sizefixed = true;
            }
        }
        if (elem.style.height != '') {
            var graphheight = imageheight (objectframeNode, elem);
            if ((IS_GECKO || IS_CHROME) && isbutton) {
                graphheight -= 1;
            }
            if (sendsizetoserver && this.GraphHeight != graphheight) {
                this.GraphHeight = graphheight;
                sizeupdated = true;
            }
            if (! this.PageBinder.IsHosted) {
                url += '&height=' + escape (graphheight);
            } else {
                imageelem.style.height = graphheight + "px";
                elem.sizefixed = true;
            }
        }
        if (this.avq_url) {
            imageelem.src = url;
        }
        if (sizeupdated) {
            this.PageBinder.Set (this.Name, 'size', this.GraphWidth + ":" + this.GraphHeight, true);
        }
    } else {
        debugger;
    }
    if (imageelem) imageelem.style.display = "block";
}

Qva.Mgr.binary.SelectStart = function (X, Y) { Qva.OpenDragRect(X, Y); }
Qva.Mgr.binary.Select      = function (X, Y) { Qva.SizeDragRect(X, Y); }
Qva.Mgr.binary.SelectEnd   = function (X, Y) { Qva.CloseDragRect(X, Y, this.Name, this.binderid, this); }


Qva.Mgr.binaryaction = function (owner, elem, name, prefix) {
    elem.Name = this.Name = Qva.MgrMakeName (name, prefix);
    elem.binderid = owner.ID;
    this.Attr = "mode";
    owner.AddManager(this);
    this.Element = elem;
    var imageelem = null;
    if (elem.tagName == "BUTTON") {
        for (var i = 0; i < elem.childNodes.length; i++) {
            if (elem.childNodes [i].tagName == "IMG") {
                imageelem = elem.childNodes [i];
                break;
            }
        }
        if (! imageelem) {
            imageelem = document.createElement ("img");
            elem.appendChild (imageelem);
        }
    } else {
        imageelem = elem;
    }
	if (elem.style.width == 'auto' && elem.style.height == 'auto') elem.autosize = true;
    if (owner.IsHosted && ! elem.sizefixed) {
        var objectframeNode = elem.parentNode.parentNode;
        if (elem.style.width != '') {
            var width = imagewidth (objectframeNode, elem);
            imageelem.style.width = elem.style.width;
        }
        if (elem.style.height != '') {
            var height = imageheight (objectframeNode, elem);
            imageelem.style.height = elem.style.height;
        }
    }
    //prevent "mising image" icon to show in IE, image is displayed in the previous function: Qva.Mgr.binary.prototype.PostPaint
    if (imageelem) imageelem.style.display = "none";
    
    if (elem.Name.substring(elem.Name.length-3)==".RE")
        elem.ondblclick = onclick_action;
    else
        elem.onclick = onclick_action;
    owner.Append (this, this.Name, 'action');
}

Qva.Mgr.binaryaction.prototype.Lock = Qva.LockDisabled;
Qva.Mgr.binaryaction.prototype.Unlock = Qva.UnlockDisabled;
Qva.Mgr.binaryaction.prototype.Paint = Qva.Mgr.binary.prototype.Paint;
Qva.Mgr.binaryaction.prototype.PostPaint = Qva.Mgr.binary.prototype.PostPaint;


Qva.Mgr.menu = function (owner, elem, name, prefix) {
    this.Name = Qva.MgrMakeName ((name != null) ? name : '', prefix);
    owner.AddManager(this);
    this.Element = elem;
    owner.Append (this, this.Name, 'menu');
}

function ShowSubMenu (elem) {
    var row = elem.parentNode;
    if (row.AvqMgr.SubMenuRow != null && row.AvqMgr.SubMenuRow != row && row.AvqMgr.SubMenuRow.SubMenu) {
        row.AvqMgr.SubMenuRow.SubMenu.style.display = 'none';
    }
    row.AvqMgr.SubMenuRow = row;
    if (! row.SubMenu) {
        row.SubMenu = document.createElement ('table');
        row.SubMenu.className = "contextsubmenu";
        var at = Qva.GetPageCoords (row);
        row.SubMenu.style.top = at.y - 1 + "px";
        row.SubMenu.style.left = at.x + row.offsetWidth + "px";
        document.body.appendChild(row.SubMenu);
        row.AvqMgr.AppendMenuItems (row.submenunode.getElementsByTagName ("action"), row.SubMenu, 1);
    }
    row.AvqMgr.SubMenuRow.SubMenu.style.display = '';
}

function HighLightRow (elem) {
    var row = elem.parentNode;
    row.className = "ContextHighlightedRow"; 
}

function LeaveRow (elem) {
    var row = elem.parentNode;
    row.className = ""; 
}

function HideSubMenu (elem) {
    var row = elem.parentNode;
    if (row.AvqMgr.SubMenuRow != null && row.AvqMgr.SubMenuRow.SubMenu) {
        row.AvqMgr.SubMenuRow.SubMenu.style.display = 'none';
    }
}

Qva.Mgr.menu.prototype.AppendMenuItems = function (itemnodes, element, level) {
    var currentrow = 0;
    var icononly = true;
    var numberofactions = 0;
    for (var i = 0; i < itemnodes.length; i++) {
        if (this.PageBinder.IsContained && itemnodes[i].getAttribute("name") == "MI") continue; //WB
        var text = itemnodes [i].getAttribute ("text");
        var isdivider = itemnodes [i].getAttribute ("type") == "divider";
        var iconnodes = itemnodes [i].getElementsByTagName("icon");
        var nodelevel = parseInt (itemnodes [i].getAttribute ("level"));
        if (nodelevel != level) continue;
        if (! text && ! isdivider && iconnodes.length == 0) {
            debugger;
            continue;
        }
        if (isdivider && i == (itemnodes.length -1)) break;
        numberofactions++;
        var row;
        var cell1;
        var cell2;
        if (icononly) {
            icononly = (! text && ! isdivider)
        }
        if (element.rows [currentrow] && element.rows [currentrow].cells [0]) {
            row = element.rows [currentrow];
            cell1 = row.cells [0];
            if (! icononly) cell2 = row.cells [1];
        } else {
            row = element.insertRow (-1);
            cell1 = row.insertCell (-1);
            if (! icononly) cell2 = row.insertCell (-1);
        }
        row.className = "ContextRow";
        currentrow++;
        cell1.style.width = "16px";
        if (! icononly) { 
            if (row.cells [1]) {
                cell2 = row.cells [1];
            } else {
                cell2 = row.insertCell (-1);
            }
            cell2.className = "ContextTextCell";
            element.style.width = "";
        } else {
            element.style.width = "20pt";
        }

        if (itemnodes [i].getAttribute ("type") == "divider")  {
            var div = document.createElement ('div');
            div.className = "ContextDivider";
            div.style.width = "100%";
	        div.style.height = "1px";
            cell2.appendChild(div);
            cell2.style.padding = "0px 0px 0px 10px";
	        cell2.style.height = "1px";
            cell1.style.padding = "0px";
	        cell1.style.height = "1px";
        }  else {
            for (var iIcon = 0; iIcon < iconnodes.length; iIcon++) {
                if (level != parseInt (iconnodes[iIcon].getAttribute ("level"))) continue;
                var url = this.PageBinder.BuildBinaryUrl (iconnodes[iIcon].getAttribute ("path"), iconnodes[iIcon].getAttribute ("stamp"), iconnodes[iIcon].getAttribute ("name"));
                cell1.innerHTML = '<img alt="" src="' + url + '" style="' + iconnodes[iIcon].getAttribute ("style") + '" />';
            }
            if (! isdivider) {
                if (! icononly) cell2.innerText = text ? text : " ";
                var disabled = itemnodes [i].getAttribute ("mode") == "disabled";
                row.disabled = disabled;
                row.binderid = this.PageBinder.ID;
                if (! disabled) {
                    var submenu = itemnodes [i].getAttribute ("submenu") == "true";
                    row.AvqMgr = this;
                    if (submenu) {
                        row.submenunode = itemnodes [i];
                        cell1.onmouseover = function () { 
                            ShowSubMenu (this);
                            HighLightRow (this);
                        }
                        cell2.onmouseover = function () { 
                            ShowSubMenu (this);
                            HighLightRow (this);
                        }
                    } else {
                        var action = itemnodes [i].getAttribute ("name");
                        var clientaction = itemnodes [i].getAttribute ("clientaction");
                        if (action) {
                            row.onclick = onclick_action;
                            row.Name = this.Context + "." + action;
                            var index = itemnodes [i].getAttribute ("index");
                            if (index) {
                                row.PositionName = this.Context;
                                row.Position = index;
                            } else if (this.Position) {
                                row.PositionName = this.Context;
                                row.Position = this.Position;
                            }
                        } else if (clientaction) {
                            row.onclick = onclick_ContextClientAction;
                            row.Name = this.Context;
                            row.clientaction = clientaction;
                            row.param = itemnodes [i].getAttribute ("param");
                        }
                        if (nodelevel == 0) {
                            cell1.onmouseover = function () { 
                                HideSubMenu (this);
                                HighLightRow (this);
                            }
                            if (! icononly)  {
                                cell2.onmouseover = function () { 
                                    HideSubMenu (this);
                                    HighLightRow (this);
                                }
                            }
                        } else {
                            cell1.onmouseover = function () { 
                                HighLightRow (this);
                            }
                            if (! icononly)  {
                                cell2.onmouseover = function () { 
                                    HighLightRow (this);
                                }
                            }
                        }
                    }
                    cell1.onmouseout = function () { LeaveRow (this); }
                    if (! icononly)  {
                        cell2.onmouseout = function () { LeaveRow (this); }
                    }
                } else {
                    cell1.style.color = "InactiveCaptionText";
                    if (! icononly) cell2.style.color = "InactiveCaptionText";
                }
            } else {
                debugger;
            }
        }
    }
    return numberofactions;
}

Qva.Mgr.menu.prototype.Paint = function (mode, node) {
    var itemnodes = node.getElementsByTagName ("action");
    if (itemnodes.length == 0) {
        Qva.HideContextMenu ();
        return;
    }
    this.Touched = true;
    this.Context = this.PageBinder.DefaultScope + "." + node.getAttribute ("context");
    this.Position = node.getAttribute ("position");  
    var numberofactions = this.AppendMenuItems (itemnodes, this.Element, 0);
    Qva.KeepContextMenuAlive = false;
    if (numberofactions == 0) {
        Qva.HideContextMenu ();
    } else {
        if (this.Element.offsetHeight + this.Element.offsetTop - Qva.GetScrollTop () >  Qva.GetViewportHeight ()) {
            var top = Math.max (0, this.Element.offsetTop - this.Element.offsetHeight);
            this.Element.style.top = top + "px";
        }
        if (this.Element.offsetWidth + this.Element.offsetLeft - Qva.GetScrollLeft () >  Qva.GetViewportWidth ()) {
            var left = Math.max (0, this.Element.offsetLeft - this.Element.offsetWidth);
            this.Element.style.left = left + "px";
        }
    }
}

Qva.Mgr.toolbar = function (owner, elem, name, prefix) {
    this.Name = Qva.MgrMakeName ((name != null) ? name : '', prefix);
    owner.AddManager(this);
    this.Element = elem;
    owner.Append (this, this.Name, 'toolbar');
}

Qva.Mgr.toolbar.prototype.Paint = function (mode, node) {
    this.Touched = true;
    var element = this.Element;
    
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
    if (element.style.display == 'none') return;
    
    var itemnodes = node.getElementsByTagName ("action");
    
    var table = element.tagName == "TABLE" ? element : element.getElementsByTagName("table")[0];
    if (! table) {
        table = document.createElement("table");
        element.appendChild(table);
    }
    var row;
    if (table.rows[0]) {
        row = table.rows[0];
    } else {
        row = table.insertRow (-1);
    }
    
    if (row.cells.length > itemnodes.length) {
        // TODO: fix ?
    }
    
    var cellcount = 0;
    for (var i = 0; i < itemnodes.length; i++) {
        var action = itemnodes [i].getAttribute ("name");
        var clientaction = itemnodes [i].getAttribute ("clientaction");
        var iconnodes = itemnodes [i].getElementsByTagName ("icon");
        
        var cell;
        if (row.cells[cellcount]) {
            cell = row.cells[cellcount];
        } else {
            cell = row.insertCell(-1);
            
        }
        cellcount++;
        
        cell.style.width = "18pt";
        cell.align = "center";
        cell.className = ""
        cell.binderid = this.PageBinder.ID;
        
        var text = itemnodes [i].getAttribute ("text");
        cell.title = text;
        
        if(iconnodes.length == 0) {
            cell.innerText = text;
            cell.style.width = itemnodes[i].getAttribute("width") || "";
        }
        
        for (var iIcon = 0; iIcon < iconnodes.length; iIcon++) {
            if (iconnodes[iIcon].getAttribute ("usage") != null && iconnodes[iIcon].getAttribute ("usage") != "caption") continue;
            var url = this.PageBinder.BuildBinaryUrl (iconnodes[iIcon].getAttribute ("path"), iconnodes[iIcon].getAttribute ("stamp"), iconnodes[iIcon].getAttribute ("name"));
            cell.innerHTML = '<img title="' + text + '" style="height:16px; width:16px;" alt="&nbsp;" src="' + url + '" />';
        }
        if (action || clientaction) {
            if (action) {
                cell.onclick = onclick_action;
                cell.Name = this.Name + "." + action;
            }
            if (clientaction) {
                cell.onclick = onclick_ContextClientAction;
                cell.Name = this.Name;
                cell.AvqMgr = this;
                cell.clientaction = clientaction;
                cell.param = itemnodes [i].getAttribute ("param");
            }
            cell.disabled = itemnodes [i].getAttribute ("mode") == "disabled";
            cell.onmouseover = function () { this.className = "ToolBarHighlightedButton"; }
            cell.onmouseout = function () { this.className = "ToolBarButton"; }
            cell.className = "ToolBarButton";
        } else {
            cell.style.padding = "0px";
            cell.style.backgroundColor = "#cccccc";
            cell.style.width = "1px";
        }
    }
    var selects = node.getElementsByTagName ("value");
    for (var iSelect = 0; iSelect < selects.length; iSelect++) {
        var name = this.Name + "." + selects [iSelect].getAttribute ("name");
        var cell;
        if (row.cells[cellcount]) {
            cell = row.cells[cellcount];
        } else {
            cell = row.insertCell(-1);
        }
        cellcount++;
        if (cell.Name == name) continue;
        cell.Name = name;
        cell.className = "QvToolbarDropdownCell";
        var select = window.document.createElement ("SELECT");
        cell.appendChild (select);
        new Qva.Mgr.select (this.PageBinder, select, name);
    }
}


Qva.MgrLinkScan = function (mgr, owner, lnkname, namePrefix) {
    mgr.LinkParts = lnkname.split ('$');
    var plen = mgr.LinkParts.length;
    mgr.LinkArgs = lnkname.split ('$');
    if (plen >= 2) {
        for (var lix = 1; lix < plen; lix += 2) {
            var name = namePrefix + mgr.LinkParts [lix];
            owner.Append (mgr, name);
            mgr.LinkParts [lix] = name;
        }
    }
};

function onclick_link () { 
    window.open (this.link);
}

Qva.Mgr.link = function (owner, elem, name, prefix, path) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    Qva.MgrLinkScan (this, owner, path, prefix);
    owner.AddManager(this);
    this.Element = elem;
    elem.Name = this.Name;
    elem.binderid = owner.ID;
    elem.onclick = onclick_link;
}

Qva.Mgr.link.prototype.Paint = function (mode, node, name) {
    this.Touched = true;
    var element = this.Element;
    if (element.Name == name) {
        element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
    }
    for (var lix = 1; lix < this.LinkParts.length; lix += 2) {
        if (this.LinkParts [lix] == name) {
            this.LinkArgs [lix] = node.getAttribute ("text");
        }
    }
    element.link = "";
    for (var lix = 0; lix < this.LinkArgs.length; lix ++) {
        element.link += this.LinkArgs [lix];
    }
}

Qva.Mgr.hover = function (owner, elem, name, prefix) {
    if (!Qva.MgrSplit (this, name, prefix)) return;
    owner.AddManager(this);
    this.Element = elem;
}

Qva.Mgr.hover.prototype.Paint = function(mode, node, name) {
    var element = this.Element;
    element.style.display = Qva.MgrGetDisplayFromMode (this, mode);
    element.innerHTML = "";
    var lines = node.getElementsByTagName ("line");
    for (var i = 0; i < lines.length; i++) {
        var p = document.createElement ("span");
        p.innerText = lines [i].getAttribute ("text");
        element.appendChild (p);
        var br = document.createElement ("br");
        element.appendChild (br);
    }
}

Qva.ZIndex = function (owner) {
    this.Name = owner.DefaultScope + ".ZIndex";
    this.Attr = 'zindex';
    this.PageBinder = owner;
    owner.AddManager(this);
    this.Names = new Array ();
    this.ZIndexes = new Array ();
}

function SetRelatedElementsZindex (objectname, zindex) {
    var frame = window.document.getElementById (objectname + "_frame");
    if (frame) {
        var oldzindex = frame.style.zIndex;
        if (zindex == oldzindex) return;
        frame.style.zIndex = zindex;
    }
    var ids = [objectname + "_bkg", objectname + "_frame_resize", objectname + "_frame_move", objectname + "_minimized"];
    for (var i = 0; i < ids.length; i++) {
        var elem = window.document.getElementById (ids[i]);
        if (elem) elem.style.zIndex = zindex;
    }
}

Qva.ZIndex.prototype.PostPaint = function () {
    for (var i = 0; i < this.Names.length; i++) {
        SetRelatedElementsZindex (this.Names [i], this.ZIndexes [i]); 
    }
}

Qva.ZIndex.prototype.Paint = function (mode, node) {
    this.Touched = true;
    var objects = node.getElementsByTagName("object");
    this.Names.length = 0;
    this.ZIndexes.length = 0;
    for (var i = 0; i < objects.length; i++) {
        this.ZIndexes [this.ZIndexes.length] = parseInt (objects [i].getAttribute ("zindex"));
        this.Names [this.Names.length] = objects [i].getAttribute ("name");
    }
    Qva.QueuePostPaintMessage (this);
}

Qva.Mgr.CreateAndUpdateResizeHandles = function (frame) {
        // create resize-div
        var sizeIn = 4; //pixels inside frame
        var sizeOut = 4;//pixels outside frame
        var cellWidth  = parseInt(frame.offsetWidth);
        var cellHeight = parseInt(frame.offsetHeight);
        var resizeParentId = frame.id + '_resize';
        var handleParent = document.getElementById(resizeParentId)
        if (!handleParent) {
            var handleParent = document.createElement("div");
            handleParent.id = resizeParentId;
            handleParent.className = "ResizeFrame";
            handleParent.ResizeType = "Parent";
            frame.insertBefore (handleParent, frame.firstChild);
        }
        handleParent.style.left = "-1px";
        handleParent.style.top = "-1px";
        handleParent.style.height = "1px";
        handleParent.style.width = "1px";
        
        var handles = ["br","r","b","bl","l","tl","t","tr"];
        for (var i = 0; i < handles.length;i++) {
            var resizeId = frame.id + '_resize_' + handles[i];
            var handle = document.getElementById(resizeId)
            if (!handle) {
                var handle = document.createElement("div");
                handle.id = resizeId;
                handle.ResizeType = handles[i];
                handleParent.appendChild(handle);
                handle.className = "ResizeZone";
            }
            var offsetX = 0; 
            var offsetY = 0; 
            // left
            if (handles[i].indexOf("r")!=-1) {
                var left = offsetX + cellWidth - sizeIn;
            } else if (handles[i].indexOf("l")!=-1) {
                var left = offsetX - sizeOut;
            } else {
                var left = offsetX + sizeIn;
            }
            // top
            if (handles[i].indexOf("b")!=-1) {
                var top = offsetY + cellHeight - sizeIn;
            } else if (handles[i].indexOf("t")!=-1) {
                var top = offsetY - sizeOut;
            } else {
                var top = offsetY + sizeIn;
            }
            // width
            if (handles[i].indexOf("r")!=-1 || handles[i].indexOf("l")!=-1) {
                var width = sizeIn + sizeOut;
            } else {
                var width = cellWidth - 2 * sizeIn;
            }
            // hight
            if (handles[i].indexOf("t")!=-1 || handles[i].indexOf("b")!=-1) {
                var height = sizeIn + sizeOut;
            } else {
                var height = cellHeight - 2 * sizeIn;
            }
            // cursor
            var cu = "";
            if (handles[i].indexOf("t")!=-1) 
                cu = "n";
            else if (handles[i].indexOf("b")!=-1) 
                cu = "s";
            if (handles[i].indexOf("l")!=-1) 
                cu += "w";
            else if (handles[i].indexOf("r")!=-1) 
                cu += "e";
            handle.style.cssText = 'width: ' + width + 'px; height: ' + height + 'px; cursor: ' + cu + '-resize; left: ' + left + 'px; top: ' + top + 'px;';
            handle.onmousedown = function (event) { Qva.Resize.mouseDown (event, frame); }
        }
}

Qva.Mgr.CreateOrDeleteMoveHandle = function (frame, allowmove) {
    var moveElementId = frame.id + '_move';
    var moveElement = document.getElementById(moveElementId)
    if (allowmove) {
        // just above the resize handle
        var height = 4;
        var top = -8;
        var cellWidth  = parseInt(frame.offsetWidth);
        if (!moveElement) {
            moveElement = document.createElement("div");
            moveElement.id = moveElementId;
            moveElement.className = "MoveZone";
            moveElement.style.cssText = 'width: ' + cellWidth + 'px; height: ' + height + 'px; left: ' + 0 + 'px; top: ' + top + 'px;';
            moveElement.Name = frame.Name;
            moveElement.moveObj = frame.id;
            var bkgid = frame.id.replace ("_frame", "_bkg");
            var bkgelem = window.document.getElementById (bkgid);
            if (bkgelem) {
                moveElement.moveObj += ":" + bkgid;
            }
            moveElement.onmousedown = Qva.Move.mouseDown;
            frame.appendChild (moveElement);
        }
    } else {
        if (moveElement) {
            frame.removeChild(moveElement);
        }
    }
}

