// Build 9.00.7440.8

Qva.Collaboration = function (owner, elem) {
    this.Name = owner.DefaultScope + "." + owner.Autoview;
    this.Attr = 'collobj';
    this.Element = elem;
    this.PageBinder = owner;
    this.NewObjects = new Array();
    owner.AddManager(this);
}

Qva.Collaboration.prototype.Scale = function (node, attr, min) {
    var dim = parseFloat(node.getAttribute(attr));
    if (isNaN(dim) || dim < 0) dim = 100;
    if (dim < min) dim = min;
    return dim;
}

Qva.Collaboration.prototype.Paint = function(mode, rootnode) {
    this.Touched = true;
    if (this.Element == null) this.Element = document.getElementById("MainContainer");
    if (this.Element == null) return;
    this.NewObjects = new Array();
    var nodes = rootnode.getElementsByTagName('object');
    var count = nodes.length;
    for (var ix = 0; ix < count; ++ix) {
        var node = nodes[ix];
        var name = node.getAttribute('name');
        if (!name) continue;
        frame_toresize = name + '_frame';
        bkg_toresize = name + '_bkg';
        name = this.PageBinder.DefaultScope + "." + name;
        if (this.PageBinder.Members[name]) continue;
        var data = {}
        data.name = name;
        data.id = node.getAttribute('name');
        data.type = node.getAttribute('type');
        data.custom = node.getAttribute('custom-renderer');
        if (data.type == 'TW') {
            data.body = node.getAttribute('custom-body');
        }

        this.NewObjects.push(data);
    }
    if (this.NewObjects.length < 1) return;
    Qva.QueuePostPaintMessage(this);
}

Qva.CustomCreator = {}

Qva.WaitingForRequest = function() {}

Qva.LoadWhenReady = function(data) {
    if (data.Master.PageBinder.IsUpdating) {
        window.setTimeout (function () { Qva.LoadWhenReady(data) }, 10);	
    } else {
        window.setTimeout (function () { data.Master.PageBinder.LoadBegin() }, 10);	
    }
}

Qva.CheckForRequestedScript = function (data) {
    if (Qva.CustomCreator[data.custom] == Qva.WaitingForRequest) {
        window.setTimeout(function() { Qva.CheckForRequestedScript(data); }, 10);
    } else {
        var creator = Qva.CustomCreator[data.custom];
        creator(data.Master, data);
        data.Master.CreateMinimized(data);
        window.setTimeout (function () { Qva.LoadWhenReady(data) }, 10);	
    }
}

Qva.RequestScript = function (data) {
    var head = document.getElementsByTagName("head")[0];
    var script = document.createElement('script');
    script.id = data.custom;
    script.src = '/QvAjaxZfc/CustomRender/' + data.custom + '/script.js';
    script.type = 'text/javascript';
    head.appendChild(script);
    window.setTimeout(function() { Qva.CheckForRequestedScript(data); }, 10);
}

Qva.Collaboration.prototype.PostPaint = function () {
    var count = this.NewObjects.length;
    if (count < 1) return;
    for (var ix = 0; ix < count; ++ix) {
        var data = this.NewObjects[ix];
        var creator = null;
        if (data.custom) {
            creator = Qva.CustomCreator[data.custom];
            if (creator == Qva.WaitingForRequest) continue;
            if (creator == null) {
                Qva.CustomCreator[data.custom] = Qva.WaitingForRequest;
                data.Master = this;
                Qva.RequestScript(data);
                continue;
            }
        }
        if (creator) {
            creator(this, data);    
        } else {
            switch(data.type) {
            case 'BM':
                this.CreateBackground(data);
                this.CreateBookmark(data);
                break;
            case 'BU':
                this.CreateButton(data);
                break;
            case 'CH':
                this.CreateChart(data);
                break;
            case 'CS':
                this.CreateCurrentSelectionBox(data);
                break;
            case 'IB':
                this.CreateInputBox(data);
                break;
            case 'LA':
                this.CreateLineArrow(data);
                break;
            case 'LB':
                this.CreateListBox(data);
                break;
            case 'MB':
                this.CreateMultiBox(data);
                break;
            case 'SB':
                this.CreateStatisticsBox(data);
                break;
            case 'SL':
                this.CreateBackground(data);
                this.CreateSlider(data);
                break;
            case 'TB':
                this.CreateTableBox(data);
                break;
            case 'TX':
                this.CreateBackground(data);
                this.CreateTextObject(data);
                break;
            case 'TW':
                this.CreateToolWindow(data);
                break;
            case 'SO':
                this.CreateSearchObject(data);
                break;
            default:
                this.CreateBackground(data);
                break;
            }
        }
        if (data.type != 'TW') this.CreateMinimized(data);
    }
    var pb = this.PageBinder;
    window.setTimeout (function () { pb.LoadBegin() }, 50);	
}

Qva.Collaboration.prototype.CreateFrame = function (data, className, handleClick) {
    var frame = document.createElement("div");
    frame.className = className + " Frame";
    frame.id = data.id + "_frame";
    
    var caption = document.createElement("div");
    caption.className = "caption";
    caption.innerText = " ";
    frame.appendChild (caption);
    frame.Caption = caption;
    
    new Qva.Mgr.frame (this.PageBinder, frame, data.name, null, handleClick);
    new Qva.Mgr.caption(this.PageBinder, caption, data.name + ".Caption");
    
    return frame;
}

Qva.Collaboration.prototype.CreateBookmarkButton = function (row, name) {
    var cell = row.insertCell(-1);
    cell.style.cssText = "padding:0pt 2pt 0pt 2pt;";
    var button = document.createElement("button");
    var img = document.createElement("img");
    img.galleryimg = "no"
    img.style.cssText = "float:left;"
    button.appendChild(img);
    var textnode = document.createTextNode (" ");
    button.appendChild (textnode);
    var span = document.createElement("span");
    button.appendChild(span);
    button.PageBinder = this.PageBinder;
    button.onmouseover = function () { this.style.border = 'outset 1pt Gray'; }
    button.onmouseout = function () { this.style.border = 'outset 1pt Transparent'; }
    cell.appendChild(button);

    new Qva.Mgr.label (this.PageBinder, cell, name);
    new Qva.Mgr.action (this.PageBinder, button, name);
    new Qva.Mgr.binary (this.PageBinder, img, name);
    new Qva.Mgr.text (this.PageBinder, span, name);
}

Qva.Collaboration.prototype.CreateBookmark = function (data) {
    var frame = this.CreateFrame(data, "BookmarkObject");

    var content = document.createElement("div");
    content.className = "content";
    content.style.cssText = "width:auto; height:auto;";

    var table = document.createElement("table");

    var colgroup = document.createElement("colgroup");
    var col = document.createElement("col");
    col.style.cssText = "width:45%;";
    colgroup.appendChild(col);
    col = document.createElement("col");
    col.style.cssText = "width:55%;";
    colgroup.appendChild (col);
    table.appendChild (colgroup);
    
    var row1 = table.insertRow(-1);
    var cell1 = row1.insertCell(-1);
    cell1.style.cssText = "padding:2pt 4pt 10pt 4pt;";
    cell1.colSpan = 2;
    var select = document.createElement("select");
    select.style.cssText = "display:none";
    cell1.appendChild(select);
    
    var row2 = table.insertRow(-1);
    this.CreateBookmarkButton (row2, data.name + ".ADD");
    this.CreateBookmarkButton (row2, data.name + ".REM");

    content.appendChild (table);
    frame.appendChild (content);
    this.Element.appendChild(frame);
    
    new Qva.Mgr.label(this.PageBinder, content, data.name + ".Content");
    new Qva.Mgr.select(this.PageBinder, select, data.name + ".Content");
}

Qva.Collaboration.prototype.CreateButton = function (data) {
    var frame = this.CreateFrame(data, "Button");

    var content = document.createElement("div");
    content.className = "content";
    var button = document.createElement("button");
    button.style.cssText = "cursor: pointer; width: auto; height: auto;";
    content.appendChild(button);
    frame.appendChild(content);
    
    this.Element.appendChild(frame);
    
    new Qva.Mgr.label(this.PageBinder, content, data.name + ".Content");
    new Qva.Mgr.binaryaction(this.PageBinder, button, data.name + ".Content");
}

Qva.Collaboration.prototype.CreateChart = function (data) {
    var frame = this.CreateFrame(data, "Chart");
    
    var head = document.createElement("div");
    head.className = "header";
    var headTable = document.createElement("table");
    headTable.id = data.id;
    headTable.style.cssText = "width: auto; height: inherit;";
    headTable.className = "Chart";
    headTable.setAttribute("avqheader", "true");
    head.appendChild(headTable);
    frame.appendChild(head);
    
    var body = document.createElement("div");
    body.className = "body";
    var bodyTable = document.createElement("table");
    bodyTable.style.cssText = "width: auto;";
    bodyTable.className = "Chart";
    bodyTable.setAttribute("avqasync", "20:" + data.name);
    bodyTable.setAttribute("avqbody", "true");
    //bodyTable.setAttribute("AvqScrollBar", "true");
    bodyTable.Header = headTable;
    body.appendChild(bodyTable);
    frame.appendChild(body);
    
    var graph = document.createElement("div");
    graph.className = "graph";
    graph.style.cssText = "display:none;";
    var chart = document.createElement("img");
    chart.style.cssText = "width:auto;height:auto;";
    frame.Chart = chart;
    graph.appendChild(chart);
    frame.appendChild(graph);
    
    this.Element.appendChild(frame);

    new Qva.Mgr.label(this.PageBinder, head, data.name + ".Head");
    new Qva.Mgr.table(this.PageBinder, headTable, data.name);
    new Qva.Mgr.label(this.PageBinder, body, data.name + ".Body");
    new Qva.Mgr.table(this.PageBinder, bodyTable);
    new Qva.Mgr.label(this.PageBinder, graph, data.name + ".Graph");
    new Qva.Mgr.binary(this.PageBinder, chart, data.name + ".Graph");
    new Qva.Mgr.actions(this.PageBinder, chart, data.name + ".Graph");
}

Qva.Collaboration.prototype.CreateCurrentSelectionBox = function (data) {
    var frame = this.CreateFrame(data, "CurrentSelectionBox");

    var body = document.createElement("div");
    body.className = "body";

    var table = document.createElement("table");
    table.className = "CurrentSelectionBox";
    table.style.cssText = "width: auto;";
    table.setAttribute("avqbody", "true");
    body.appendChild(table);
    frame.appendChild(body);
    
    this.Element.appendChild(frame);
    
    new Qva.Mgr.table(this.PageBinder, table, data.name);
}

Qva.Collaboration.prototype.CreateInputBox = function (data) {
    var frame = this.CreateFrame(data, "InputBox");

    var content = document.createElement("div");
    content.className = "body";
    var table = document.createElement("table");
    table.className = "InputBox";
    table.style.cssText = "width: auto;";
    table.setAttribute("avqbody", "true");
    table.id = data.id;

    content.appendChild(table);
    frame.appendChild(content);
    
    this.Element.appendChild(frame);

    new Qva.Mgr.table(this.PageBinder, table, data.name);
}

Qva.Collaboration.prototype.CreateSearchObject = function (data) {
    var frame = this.CreateFrame(data, "SearchObject");

    var content = document.createElement("div");
    content.className = "content";
    content.style.cssText = "width:auto; height:auto;";

    var table = document.createElement("table");
    table.className = "SearchObject";
    table.style.cssText = "width: 100%;";
    table.id = data.id;

    //add "move" attributes
    frame.onmousedown = Qva.Move.mouseDown;
    frame.moveObj = frame.id;

    var colgroup = document.createElement("colgroup");
    var col = document.createElement("col");
    col.style.cssText = "width:15pt;";
    colgroup.appendChild(col);
    col = document.createElement("col");
    colgroup.appendChild (col);
    table.appendChild (colgroup);


    var row = table.insertRow (-1);
    var cell1 = row.insertCell (-1);
    cell1.style.cssText = "padding: 2pt 2pt 2pt 2pt";
    var img = document.createElement ("img");
    cell1.appendChild (img);
    var cell2 = row.insertCell (-1);
    var input = document.createElement ("input");
    input.style.cssText = "width: 95%; display:none";
    cell2.appendChild (input);

    content.appendChild (table);
    frame.appendChild (content);
    this.Element.appendChild (frame);
    new Qva.Mgr.binary (this.PageBinder, img, data.name + ".SEARCH");
    new Qva.Mgr.inputsearch (this.PageBinder, input, data.name + ".Input");
}

Qva.Collaboration.prototype.CreateLineArrow = function (data) {
    var frame = this.CreateFrame(data, "LineArrowObject");

    var content = document.createElement("div");
    content.className = "content";
    var img = document.createElement("img");
    img.style.cssText = "width: auto; height: auto;";
    content.appendChild(img);
    frame.appendChild(content);
    
    this.Element.appendChild(frame);
    
    new Qva.Mgr.label(this.PageBinder, content, data.name + ".Content");
    new Qva.Mgr.binary(this.PageBinder, img, data.name + ".Content");
    new Qva.Mgr.actions(this.PageBinder, img, data.name + ".Content");
}

Qva.Collaboration.prototype.CreateListBox = function (data) {
    var frame = this.CreateFrame(data, "ListBox");

    var body = document.createElement ("div");
    body.className = "body";

    var table = document.createElement ("table");
    table.className = "ListBox";
    table.style.cssText = "width: 100%;";
    table.setAttribute ("avqasync", "20:" + data.name);
    table.setAttribute ("avqbody", "true");
    table.id = data.id;
    body.appendChild (table);
    frame.appendChild (body);
    
    this.Element.appendChild (frame);
    
    new Qva.Mgr.table(this.PageBinder, table);
}

Qva.Collaboration.prototype.CreateMultiBox = function (data) {
    var frame = this.CreateFrame(data, "MultiBox");

    var body = document.createElement("div");
    body.className = "body";

    var table = document.createElement("table");
    table.className = "MultiBox";
    table.style.cssText = "width: auto;";
    table.setAttribute("avqbody", "true");
    table.id = data.id;
    body.appendChild(table);
    frame.appendChild(body);
    
    this.Element.appendChild(frame);
    
    new Qva.Mgr.table(this.PageBinder, table, data.name);
}

Qva.Collaboration.prototype.CreateStatisticsBox = function (data) {
    var frame = this.CreateFrame(data, "StatisticsBox");

    var body = document.createElement("div");
    body.className = "body";

    var table = document.createElement("table");
    table.className = "StatisticsBox";
    table.style.cssText = "width: auto;";
    table.setAttribute("avqbody", "true");
    body.appendChild(table);
    frame.appendChild(body);
    
    this.Element.appendChild(frame);
    
    new Qva.Mgr.table(this.PageBinder, table, data.name);
}

Qva.Collaboration.prototype.CreateSlider = function (data) {
    var frame = this.CreateFrame(data, "SliderObject");

    var slider = document.createElement("div");
    slider.className = "content";
    slider.style.cssText = "display:none; width: auto; height: auto;";
    frame.appendChild(slider);
    
    var calendar = document.createElement("div");
    calendar.className = "content";
    calendar.style.cssText = "display:none; width: auto; height: auto;";

    var table = document.createElement("table");
    table.style.cssText = "margin: 2pt 2pt 2pt 2pt; width:95%;";
    var colgroup = document.createElement("colgroup");
    var col = document.createElement("col");
    col.style.cssText = "width: 80%;";
    colgroup.appendChild(col);
    col = document.createElement("col");
    col.style.cssText = "width: 20%;";
    colgroup.appendChild(col);
    table.appendChild(colgroup);
    var row = table.insertRow(-1);
    var cell1 = row.insertCell(-1);
    cell1.style.cssText = "display:none; background-color: White;";
    
    var cell2 = row.insertCell(-1);
    cell2.style.cssText = "padding: 2pt 2pt 2pt 2pt;";
    var img = document.createElement ("img");
    img.src = this.PageBinder.BuildBinaryUrl (null, null, "Calendar_img");

    img.title = "Date selector";
    img.style.cssText = "display:none; cursor: pointer; border: 1px solid red;";
    cell2.appendChild (img);

    calendar.appendChild(table);
    frame.appendChild(calendar);
    
    this.Element.appendChild(frame);
    
    new Qva.Mgr.slider (this.PageBinder, slider, data.name + ".Slider");
    new Qva.Mgr.label (this.PageBinder, calendar, data.name + ".Calendar");
    new Qva.Mgr.text (this.PageBinder, cell1, data.name + ".Calendar");
    new Qva.Mgr.date (this.PageBinder, img, data.name + ".Calendar");
}

Qva.Collaboration.prototype.CreateTableBox = function (data) {
    var frame = this.CreateFrame(data, "TableBox");

    var head = document.createElement("div");
    head.className = "header";
    var headTable = document.createElement("table");
    headTable.id = data.id;
    headTable.style.cssText = "width: auto; height: inherit;";
    headTable.className = "TableBox";
    headTable.setAttribute("avqheader", "true");
    head.appendChild(headTable);
    frame.appendChild(head);
    
    var body = document.createElement("div");
    body.className = "body";

    var bodyTable = document.createElement("table");
    bodyTable.style.cssText = "width: auto;";
    bodyTable.className = "TableBox";
    bodyTable.setAttribute("avqasync", "20:" + data.name);
    bodyTable.setAttribute("avqbody", "true");
    bodyTable.Header = headTable;
    body.appendChild(bodyTable);
    frame.appendChild(body);
    
    this.Element.appendChild(frame);
    
    new Qva.Mgr.label(this.PageBinder, head, data.name + ".Head");
    new Qva.Mgr.table(this.PageBinder, headTable, data.name);
    new Qva.Mgr.table(this.PageBinder, bodyTable);
}

Qva.Collaboration.prototype.CreateTextObject = function (data) {
    var frame = this.CreateFrame(data, "TextObject");
    
    var content = document.createElement("div");
    content.className = "content";
    content.style.cssText = "height:auto; width:auto;";
    var table = document.createElement("table");
    table.className = "TextObject";
    table.style.cssText = "height:100%; width:100%;";
    var row = table.insertRow(-1);
    var cell = row.insertCell(-1);
    content.appendChild(table);
    frame.appendChild(content);
    
    this.Element.appendChild(frame);
    
    new Qva.Mgr.label (this.PageBinder, content, data.name + ".Content");
    new Qva.Mgr.actions (this.PageBinder, content, data.name + ".Content");
    new Qva.Mgr.text (this.PageBinder, cell, data.name + ".Content");
    new Qva.Mgr.scroll (this.PageBinder, content, data.name + ".Content");
}

Qva.Collaboration.prototype.CreateToolWindow = function(data) {
    var frame = this.CreateFrame(data, "ToolWindow", true);
    frame.style.cssText += "display:none;";

    var content = document.createElement("div");
    content.className = "content";
    content.style.cssText = "height:auto; width:auto;";
    var table = document.createElement("table");
    table.className = "ToolWindow";
    table.style.cssText = "height:100%; width:100%;";
    // non scrolling region at the top
    var rowHeader = table.insertRow(-1);
    var cellHeader = rowHeader.insertCell(-1);
    cellHeader.vAlign = "top";
    cellHeader.innerHTML = "<div class='ToolWindow-Navigation'></div>";
    // scrolling region
    var row = table.insertRow(-1);
    var cell3 = row.insertCell(-1);
    cell3.vAlign = "top";

    if (data.body) {
        cell3.innerHTML = data.body;
    } else {
        cell3.innerHTML = "<div class='ToolWindow-Body'></div>";
    }
    content.appendChild(table);
    frame.appendChild(content);
    frame.oncontextmenu = function(event) { return Qva.GetBinder(this.binderid).OnContextMenu(event, this.Name); }

    this.Element.appendChild(frame);

    new Qva.Mgr.label(this.PageBinder, content, data.name + ".Content");
    new Qva.Mgr.toolwindownavigation(this.PageBinder, cellHeader.firstChild, data.name + ".Navigation");
    var bmgr = new Qva.Mgr.toolwindowbody(this.PageBinder, cell3.firstChild, data.name + ".Body");
    if (data.body) bmgr.Scan();
}

Qva.Collaboration.prototype.CreateBackground = function (data) {
    var frame = document.createElement("div");
    frame.setAttribute("avqbackground", "true");
    frame.className = "Frame";
    frame.id = data.id + "_bkg";
    
    var caption = document.createElement("div");
    caption.className = "caption";
    caption.style.cssText = "height:0px;";
    frame.appendChild (caption);

    var content = document.createElement("div");
    content.className = "QvBackground";
    content.style.cssText = "height:auto; width:auto;";
    frame.appendChild(content);
    
    this.Element.appendChild(frame);

    new Qva.Mgr.frame (this.PageBinder, frame, data.name);
    new Qva.Mgr.background (this.PageBinder, content, data.name);
}

Qva.Collaboration.prototype.CreateMinimized = function (data) {
    var frame = document.createElement("div");
    frame.className = "Frame";
    frame.style.cssText = "vertical-align:middle;text-align:left; display:none;";
    //move attributes
    frame.id = data.id + "_minimized";
    
    var div = document.createElement("div");
    frame.appendChild(div);
    
    var innerdiv = document.createElement("div");
    innerdiv.style.cssText = "width:auto; height:auto;";
    div.appendChild(innerdiv);
    
    var imageelem = document.createElement ("img");
    innerdiv.appendChild (imageelem);

    
    this.Element.appendChild(frame);
    
    new Qva.Mgr.restore (this.PageBinder, frame, data.name + ".RE");
    new Qva.Mgr.binaryaction (this.PageBinder, innerdiv, data.name + ".RE");
}

