dojo.provide("parus.balanceReportCheckProtocolTabPage");

dojo.require("dojo.date.locale");

dojo.require("dijit.form.Button");

dojo.require("parus.parus8");
dojo.require("parus.gridData");
dojo.require("parus.dictEdit");

dojo.require("parus.tabPage");

dojo.require("parus.balanceCheckReportCheckDialog");

dojo.declare("parus.balanceReportCheckProtocolTabPage", [parus.tabPage], {

  _refreshChecksDetailGridTimeoutID: null,
  _refreshCheckResultsGridTimeoutID: null,
  _refreshCheckResultsDetailGridTimeoutID: null,

  _onSelectedChecksMasterGridEventHandler: null,
  _onSelectedChecksDetailGridEventHandler: null,

  rn: null,

  subRn: null,

  checklist: null,

  showResultReportOnly: false,

  autonomousMode: false,

  _initialized: false,
  _checkResultsGridInitialized: false,

  postCreate: function() {
    this.inherited(arguments);

    this._checksMasterAttrDescriptors = parus.parus8._attrDescriptors ? parus.parus8.rowNodes(parus.database.execute("attrDescriptors", {
      "UNITCODE": "BalanceCheckReports"
    }).documentElement.childNodes[0].childNodes[0].childNodes[0]) || [] : [];

    this._checksDetailAttrDescriptors = parus.parus8._attrDescriptors ? parus.parus8.rowNodes(parus.database.execute("attrDescriptors", {
      "UNITCODE": "BalanceCheckReportsSpecs"
    }).documentElement.childNodes[0].childNodes[0].childNodes[0]) || [] : [];

    this._onSelectedChecksMasterGridEventHandler =
    dojo.connect(this.checksMasterGrid, "onSelected", this, this.checksMasterGridChange, true);
    this._onSelectedChecksDetailGridEventHandler =
    dojo.connect(this.checksDetailGrid, "onSelected", this, this.checksDetailGridChange, true);

    dojo.connect(this.detailsPane, "onShow", this, this.pageChanged, true);

  },

  settingsAdditions: function() {
    return [{
      widget: this.detailsPane,
      title: "Скрыть проверки и результаты",
      id: "detailsPaneHiddenMode"
    }]

  },

  onShow: function() {


    var structure = [];

    dojo.forEach(this._checksMasterAttrDescriptors, function(descriptor) {

      structure.push({
        colSpan: 1,
        attrRN: parus.parus8.nodeField(descriptor, "RN"),
        dataType: parus.parus8.nodeField(descriptor, "DATATYPE"),
        dataSubType: 0,
        field: "attr" + parus.parus8.nodeField(descriptor, "RN"),
        name: parus.parus8.nodeField(descriptor, "NAME"),
        formatter: parus.balance.formatAttrValue,
        width: (parus.parus8.nodeField(descriptor, "ACTIVE") == "1") ? "121px" : "0px",
        hidden: (parus.parus8.nodeField(descriptor, "ACTIVE") != "1"),
        styles: "text-align:" + ((parus.parus8.nodeField(descriptor, "DATATYPE") == 0) ? "left" : "right") + ";",
        sortField: (parus.parus8.nodeField(descriptor, "PARAMCOUNT") == "2") ? (parus.parus8.nodeField(descriptor, "STOREDPROC") + "(T.COMPANY, T.RN)") : (parus.parus8.nodeField(descriptor, "STOREDPROC") + "(T.RN)")
      })

    });


    if (structure.length) {
      var str = dojo.clone(this.checksMasterGrid.structure);
      str[0].cells[0] = str[0].cells[0].concat(structure);
      this.checksMasterGrid.setStructure(str);
    };


    var structure = [];

    dojo.forEach(this._checksDetailAttrDescriptors, function(descriptor) {

      structure.push({
        colSpan: 1,
        attrRN: parus.parus8.nodeField(descriptor, "RN"),
        dataType: parus.parus8.nodeField(descriptor, "DATATYPE"),
        dataSubType: 0,
        field: "attr" + parus.parus8.nodeField(descriptor, "RN"),
        name: parus.parus8.nodeField(descriptor, "NAME"),
        formatter: parus.balance.formatAttrValue,
        width: (parus.parus8.nodeField(descriptor, "ACTIVE") == "1") ? "121px" : "0px",
        hidden: (parus.parus8.nodeField(descriptor, "ACTIVE") != "1"),
        styles: "text-align:" + ((parus.parus8.nodeField(descriptor, "DATATYPE") == 0) ? "left" : "right") + ";",
        sortField: (parus.parus8.nodeField(descriptor, "PARAMCOUNT") == "2") ? (parus.parus8.nodeField(descriptor, "STOREDPROC") + "(T.COMPANY, T.RN)") : (parus.parus8.nodeField(descriptor, "STOREDPROC") + "(T.RN)")
      })

    });


    if (structure.length) {
      var str = dojo.clone(this.checkResultsGrid.structure);
      str[0].cells[0] = str[0].cells[0].concat(structure);
      this.checkResultsGrid.setStructure(str);

      var str = dojo.clone(this.checkResultsDetailGrid.structure);
      str[0].cells[0] = str[0].cells[0].concat(structure);
      this.checkResultsDetailGrid.setStructure(str);
    };


    this.checksMasterGrid.attr("store", this.checksMasterGridStore());
    this.checksDetailGrid.attr("store", this.checksDetailGridStore());
    this.checkResultsGrid.attr("store", this.checkResultsGridStore());
    this.checkResultsDetailGrid.attr("store", this.checkResultsDetailGridStore());

    parus.balance._createActionsButton(this.checksMasterGridPopupMenu, this.headingPane);
    this.checksMasterGridPopupMenu.bindDomNode(this.checksMasterGrid.viewsNode);

    var settings = parus.userdata.get(this.declaredClass + "-checksMasterGrid");
    if (settings) {
      parus.gridSettingsDialog.mergeGridSettings(this.checksMasterGrid, settings.gridSettings);
      parus.gridSettingsDialog.mergeColorConditions(this.checksMasterGrid, settings.colorConditions);
      parus.gridSettingsDialog.mergeMenuSettings(this.checksMasterGridPopupMenu, settings.actionSettings, settings.userProcsActions, settings.userReportsActions, settings.userAppsActions);
      parus.gridSettingsDialog.mergeFilterBar(this.checksMasterGrid, settings.showFilterBar, settings.filterValues, settings.sortInfo);
      parus.gridSettingsDialog.mergeAdditions(this.settingsAdditions(), settings.additions);
    };


    parus.balance._createActionsButton(this.checksDetailGridPopupMenu, this.checksDetailHeaderPane);
    this.checksDetailGridPopupMenu.bindDomNode(this.checksDetailGrid.viewsNode);

    var settings = parus.userdata.get(this.declaredClass + "-checksDetailGrid");
    if (settings) {
      parus.gridSettingsDialog.mergeGridSettings(this.checksDetailGrid, settings.gridSettings);
      parus.gridSettingsDialog.mergeColorConditions(this.checksDetailGrid, settings.colorConditions);
      parus.gridSettingsDialog.mergeFilterBar(this.checksDetailGrid, settings.showFilterBar, settings.filterValues, settings.sortInfo);
    };


    parus.balance._createActionsButton(this.checkResultsDetailGridPopupMenu, this.checkResultsDetailHeaderPane);
    this.checkResultsDetailGridPopupMenu.bindDomNode(this.checkResultsDetailGrid.viewsNode);

    var settings = parus.userdata.get(this.declaredClass + "-checkResultsDetailGrid");
    if (settings) {
      parus.gridSettingsDialog.mergeGridSettings(this.checkResultsDetailGrid, settings.gridSettings);
      parus.gridSettingsDialog.mergeColorConditions(this.checkResultsDetailGrid, settings.colorConditions);
      parus.gridSettingsDialog.mergeFilterBar(this.checkResultsDetailGrid, settings.showFilterBar, settings.filterValues, settings.sortInfo);
    };

    parus.balance._createActionsButton(this.checkResultsGridPopupMenu, this.checkResultsHeaderPane);
    this.checkResultsGridPopupMenu.bindDomNode(this.checkResultsGrid.viewsNode);

    setTimeout(dojo.hitch(this, function() {
      this.checksMasterGrid.setQuery(this.checksMasterGrid.query);
      this._initialized = true;
    }), 100);

    if (this.autonomousMode) {
      dojo.place("<span>" + this.title + "<span>", this.headingPane.getChildren()[0].containerNode, "only");
      document.title = this.title;
    }

  },

  destroy: function() {
    dojo.disconnect(this._onSelectedChecksMasterGridEventHandler);
    dojo.disconnect(this._onSelectedChecksDetailGridEventHandler);
    this.inherited(arguments);
  },

  getGridFieldValue: function(grid, fieldName) {
    var store = grid.store;
    var index = grid.selection.getSelectedIndex();
    var item = grid.getItem(index);
    return store.getValue(item, fieldName);
  },

  checksMasterGridStore: function() {
    return parus.gridData({
      queryid: "ReportCheckProtocols",

      onGetConditions: dojo.hitch(this, function(store) {
        var conditions = {};
        conditions.REPORT = this.rn.join(";");
        if (this.checklist) conditions.CHECKLIST = this.checklist;
        if (this.subRn) conditions.BLSUBREPORT = this.subRn.join(";");
        if (this.showResultReportOnly) conditions.BALSECTION = "!*";
        return conditions;
      }),

      onComplete: dojo.hitch(this, function(store, items) {
        if ((items.length > 0) && !this.checksMasterGrid.selection.getSelectedCount()) {
          this.checksMasterGrid.selection.select(0);
          this.checksMasterGrid.autoSelected = true;
        }

        dojo.forEach(this.checksMasterGridPopupMenu.getChildren(), dojo.hitch(this, function(menuItem) {
          menuItem.userObjectsGrid = this.checksMasterGrid;
          if (menuItem.itemAction) if (menuItem.declaredClass != "dijit.MenuSeparator")

          menuItem.attr("disabled", items.length == 0);
        }));

        parus.parus8.checkMenuSeparators(this.checksMasterGridPopupMenu);

      })
    });
  },

  checksDetailGridStore: function() {
    return parus.gridData({
      queryid: "ReportChecks",

      onGetConditions: dojo.hitch(this, function(store) {
        return {
          PRN: this.getGridFieldValue(this.checksMasterGrid, "RN") || "!*"
        };
      }),

      onComplete: dojo.hitch(this, function(store, items) {
        if ((items.length > 0) && !this.checksDetailGrid.selection.getSelectedCount()) {
          this.checksDetailGrid.selection.select(0);
          this.checksDetailGrid.autoSelected = true;

        }
        this.checksDetailGridChange();
      })
    });
  },

  checkResultsDetailGridStore: function() {
    return parus.gridData({
      queryid: "ReportCheckResults",

      onGetConditions: dojo.hitch(this, function(store) {
        return {
          PRN: this.getGridFieldValue(this.checksDetailGrid, "PRN") || "!*",
          BLCHECK: this.getGridFieldValue(this.checksDetailGrid, "BLCHECK") || "!*"
        };
      }),

      onComplete: dojo.hitch(this, function(store, items) {
        if ((items.length > 0) && !this.checkResultsDetailGrid.selection.getSelectedCount()) {
          this.checkResultsDetailGrid.selection.select(0);
          this.checkResultsDetailGrid.autoSelected = true;
        }
      })
    });
  },

  checkResultsGridStore: function() {
    return parus.gridData({
      queryid: "ReportCheckResults",

      onGetConditions: dojo.hitch(this, function(store) {
        return {
          PRN: this.getGridFieldValue(this.checksMasterGrid, "RN") || "!*"
        };
      }),

      onComplete: dojo.hitch(this, function(store, items) {
        if ((items.length > 0) && !this.checkResultsGrid.selection.getSelectedCount()) {
          this.checkResultsGrid.selection.select(0);
          this.checkResultsGrid.autoSelected = true;
        }
      })
    });
  },

  pageChanged: function() {
    if (!this.detailsPages.selectedChildWidget.isFirstChild && !this._checkResultsGridInitialized) {
      var settings = parus.userdata.get(this.declaredClass + "-checkResultsGrid");
      if (settings) {
        parus.gridSettingsDialog.mergeGridSettings(this.checkResultsGrid, settings.gridSettings);
        parus.gridSettingsDialog.mergeColorConditions(this.checkResultsGrid, settings.colorConditions);
        parus.gridSettingsDialog.mergeFilterBar(this.checkResultsGrid, settings.showFilterBar, settings.filterValues);
      };
      this._checkResultsGridInitialized = true;
    };
    setTimeout(dojo.hitch(this, function() {
      this.checksMasterGridChange();
    }), 100);

  },

  checksMasterGridChange: function() {
    if (this._refreshChecksDetailGridTimeoutID) clearTimeout(this._refreshChecksDetailGridTimeoutID);
    this._refreshChecksDetailGridTimeoutID = null;
    if (this._refreshCheckResultsGridTimeoutID) clearTimeout(this._refreshCheckResultsGridTimeoutID);
    this._refreshCheckResultsGridTimeoutID = null;

    if (!this._initialized) return;

    if (this.detailsPages.selectedChildWidget.isFirstChild) this._refreshChecksDetailGridTimeoutID = setTimeout(dojo.hitch(this, this._refreshChecksDetailGrid), 300);
    else this._refreshCheckResultsGridTimeoutID = setTimeout(dojo.hitch(this, this._refreshCheckResultsGrid), 300);
  },

  checksDetailGridChange: function() {
    if (this._refreshCheckResultsDetailGridTimeoutID) clearTimeout(this._refreshCheckResultsDetailGridTimeoutID);
    this._refreshCheckResultsDetailGridTimeoutID = setTimeout(dojo.hitch(this, this._refreshCheckResultsDetailGrid), 300);
  },

  _onQueryComplete: null,

  _refreshChecksDetailGrid: function() {
    if (this._refreshChecksDetailGridTimeoutID) clearTimeout(this._refreshChecksDetailGridTimeoutID);
    this._refreshChecksDetailGridTimeoutID = null;

    if (this._refreshCheckResultsDetailGridTimeoutID) clearTimeout(this._refreshCheckResultsDetailGridTimeoutID);
    this._refreshCheckResultsDetailGridTimeoutID = null;

    parus.balance.refreshGrid(this.checksDetailGrid);
  },

  _refreshCheckResultsDetailGrid: function() {
    if (this._refreshCheckResultsDetailGridTimeoutID) clearTimeout(this._refreshCheckResultsDetailGridTimeoutID);
    this._refreshCheckResultsDetailGridTimeoutID = null;

    parus.balance.refreshGrid(this.checkResultsDetailGrid);
  },

  _refreshCheckResultsGrid: function() {
    if (this._refreshCheckResultsGridTimeoutID) clearTimeout(this._refreshCheckResultsGridTimeoutID);
    this._refreshCheckResultsGridTimeoutID = null;
    parus.balance.refreshGrid(this.checkResultsGrid);
  },

  editValues: function() {

    var store = this.checksMasterGrid.store;
    var index = this.checksMasterGrid.selection.getSelectedIndex();
    var item = this.checksMasterGrid.getItem(index);

    if (this.autonomousMode && !parus.parus8._embeddedMode) {

      parus.database.query("BalanceReportTemplates", {
        "REPORT": store.getValue(item, "REPORT")
      }, dojo.hitch(this, function(response) {

        var templates = parus.parus8.rowNodes(response);
        if (templates.length == 0) {
          parus.parus8.errorMessage("Трафареты для редактирования значений отсутствуют или недоступны.");
          return;
        };

        var template;
        var direction;


        if (templates.length == 1) {
          template = parus.parus8.nodeField(templates[0], "RN");
          direction = parus.parus8.nodeField(templates[0], "DIRECT_TABLE");
        }
        else dojo.forEach(templates, function(templateNode) {
          if (parus.parus8.nodeField(templateNode, "EDIT_DEFAULT") == "1") {
            template = parus.parus8.nodeField(templateNode, "RN");
            direction = parus.parus8.nodeField(templateNode, "DIRECT_TABLE");
          }
        });


        parus.parus8.registerAction();

        if (template) window.open(dojo.moduleUrl("parus", "report.html").toString() + "?loggedUserHandler=" + parus.database.connected + "&params=" + parus.parus8.hexEncodeParams([store.getValue(item, "REPORT"), store.getValue(item, "BALSECTION") ? store.getValue(item, "BLSUBREPORT") : null, template]))
        else {

          var dialog = new parus.balanceTemplatesDialog({

            templates: templates,

            onApply: dojo.hitch(this, function() {

              dojo.forEach(dialog.templatesGrid.selection.getSelected(), function(item) {
                template = dialog.templatesGrid.store.getValue(item, "RN", "");
                direction = dialog.templatesGrid.store.getValue(item, "DIRECT_TABLE", "")
              });

              if (!template) return false;

              window.open(dojo.moduleUrl("parus", "report.html").toString() + "?loggedUserHandler=" + parus.database.connected + "&params=" + parus.parus8.hexEncodeParams([store.getValue(item, "REPORT"), store.getValue(item, "BALSECTION") ? store.getValue(item, "BLSUBREPORT") : null, template]))

              return true;
            })


          });
          dialog.show();
        }

      }));



    }
    else parus.balance.executeEditValues(store.getValue(item, "REPORT"), store.getValue(item, "BALSECTION") ? store.getValue(item, "BLSUBREPORT") : null, store.getValue(item, "REPDATE"), store.getValue(item, "REPFORMCODE"), store.getValue(item, "AGNABBR"), store.getValue(item, "BALSECTIONCODE"), store.getValue(item, "REPKIND"), store.getValue(item, "AGENT"));

  },

  print: function(fullVersion) {
    var conditions = {};
    conditions.REPORT = this.rn.join(";");
    if (this.checklist) conditions.CHECKLIST = this.checklist;
    if (this.subRn) conditions.BLSUBREPORT = this.subRn.join(";");
    if (this.showResultReportOnly) conditions.BALSECTION = "!*";

    orders = [];

    dojo.forEach(this.checksMasterGrid.getSortProps() || [], function(sortProp) {
      var idx = dojo.indexOf(["REPDATE", "REPFORMCODE", "BALSECTIONCODE", "AGNABBR", "CHECKDATE", "BLCHECKLISTCODE", "BLCHECKLISTNAME", "TYPE", "ERRORSCOUNT", "WARNINGSCOUNT"], sortProp.field);
      var order = (idx >= 0) ? [3, 1, 2, 4, null, 5, 5, null, null, null][idx] : null;
      if (order) orders.push(order + (sortProp.descending ? " desc" : ""));
    });

    dojo.forEach(this.checkResultsDetailGrid.getSortProps() || [], function(sortProp) {
      var idx = dojo.indexOf(["RESULT", "MAIN_DESC", "LEFT_DESC", "LEFT_RESULT", "REL_OPERATOR", "RIGHT_DESC", "RIGHT_RESULT", "SUBTRACTION", "MESSAGE"], sortProp.field);
      var order = (idx >= 0) ? [6, 8, 9, 12, 11, 10, 13, 14, 7][idx] : null;
      if (order) orders.push(order + (sortProp.descending ? " desc" : ""));
    });


    dojo.forEach(this.checkResultsGrid.getSortProps() || [], function(sortProp) {

      var idx = dojo.indexOf(["FORMULACODE", "FORMULANAME", "RESULT", "MAIN_DESC", "LEFT_DESC", "LEFT_RESULT", "REL_OPERATOR", "RIGHT_DESC", "RIGHT_RESULT", "SUBTRACTION", "MESSAGE"], sortProp.field);
      var order = (idx >= 0) ? [null, null, 6, 8, 9, 12, 11, 10, 13, 14, 7][idx] : null;
      if (order) orders.push(order + (sortProp.descending ? " desc" : ""));

    });

    conditions.order = orders.length ? orders.join(",") : "1,2,3,4,5,6,7";

    if (parus.parus8._embeddedMode) {
      this.printForm["htmldata"].value = parus.balanceReportCheckProtocolTabPage.printRender(
      conditions, fullVersion ? 1 : 0, this.title);
    } else {
      this.printForm["querydata"].value = dojo.toJson(conditions);
      this.printForm["full"].value = fullVersion ? 1 : 0;
      this.printForm["handler"].value = parus.database.connected;
    };

    this.printForm["title"].value = this.title;

    document.body.appendChild(this.printForm);
    this.printForm.submit();
    document.body.removeChild(this.printForm);

  },

  checksDetailGridRecheck: function() {

    var store = this.checksDetailGrid.store;
    var item = this.checksDetailGrid.selection.getFirstSelected();

    for (var i = 0; i < this.checksDetailGrid.selection.getSelectedCount(); i++) {
      parus.database.execute("ReCheck", {
        PRN: store.getValue(item, "PRN"),
        CHECK: store.getValue(item, "BLCHECK")
      });
      item = this.checksDetailGrid.selection.getNextSelected(item);
    };

    parus.balance.refreshGrid(this.checksDetailGrid);

  },

  checkResultsGridRecheck: function() {

    var store = this.checkResultsGrid.store;
    var item = this.checkResultsGrid.selection.getFirstSelected();

    for (var i = 0; i < this.checkResultsGrid.selection.getSelectedCount(); i++) {
      parus.database.execute("ReCheck", {
        RN: store.getValue(item, "RN"),
        PRN: store.getValue(item, "PRN"),
        CHECK: store.getValue(item, "BLCHECK")
      });
      item = this.checkResultsGrid.selection.getNextSelected(item);
    };

    parus.balance.refreshGrid(this.checkResultsGrid);
  },

  checkReport: function() {

    var rnValues = [];
    var formedRnValues = [];
    var reportValues = [];

    var grid = this.checksMasterGrid;

    var kind = 0;

    var store = grid.store;
    var item = grid.selection.getFirstSelected();

    for (var i = 0; i < grid.selection.getSelectedCount(); i++) {
      rnValues.push(store.getValue(item, "BLSUBREPORT"));
      formedRnValues.push(store.getValue(item, "BLREPFORMED"));
      kind = store.getValue(item, "REPKIND") || 0;
      reportValues.push(store.getValue(item, "REPORT"));
      item = grid.selection.getNextSelected(item);
    };
    var dialog = new parus.balanceCheckReportCheckDialog({
      grid: grid,
      kind: kind,
      isSubReport: true,
      rn: rnValues,
      formedRn: formedRnValues,
      reportRn: reportValues,
      title: ((kind == 0) ? "Первичные" : "Сводные") + " отчеты: Параметры проверки"
    });

    dialog.show();



  }


});

dojo.mixin(parus.balanceReportCheckProtocolTabPage, {

  printRender: function(query, full, title) {

    var body = document.createElement("body");

    body.style.width = full ? "260mm" : "190mm";

    if (title.charAt(0) != "<") title = "<div align=\"center\">" + title + "</div>";

    body.insertAdjacentHTML("afterBegin", title);

    var titleNode = body.firstChild;

    titleNode.style.height = "auto";
    titleNode.style.fontWeight = "bold";
    titleNode.style.fontFamily = "Tahoma, Verdana, sans-serif";
    titleNode.style.margin = "10px";

    var table = body.appendChild(document.createElement("table"));

    table.width = "100%";
    table.border = "1";
    table.cellSpacing = "0";

    var row = table.insertRow(-1);
    row.style.fontWeight = "bold";
    row.insertCell(-1).appendChild(document.createTextNode("№№ п/п"));
    row.insertCell(-1).appendChild(document.createTextNode("Форма отчета"));
    row.insertCell(-1).appendChild(document.createTextNode("Разрез"));
    row.insertCell(-1).appendChild(document.createTextNode("Дата отчета"));
    row.insertCell(-1).appendChild(document.createTextNode("Контрагент"));
    row.insertCell(-1).appendChild(document.createTextNode("Перечень"));
    row.insertCell(-1).appendChild(document.createTextNode("Тип"));
    row.insertCell(-1).appendChild(document.createTextNode("Сообщение"));

    if (full) {
      row.insertCell(-1).appendChild(document.createTextNode("Описание левой части"));
      row.insertCell(-1).appendChild(document.createTextNode("Значение левой части"));
      row.insertCell(-1).appendChild(document.createTextNode("Оператор"));
      row.insertCell(-1).appendChild(document.createTextNode("Описание правой части"));
      row.insertCell(-1).appendChild(document.createTextNode("Значение правой части"));
      row.insertCell(-1).appendChild(document.createTextNode("Разность"));
    };

    var n = 1;

    var rows = parus.parus8.rowNodes(parus.database.query("ReportCheckResultsPrint", query));

    dojo.forEach(rows, function(dataRow) {
      var row = table.insertRow(-1);
      row.style.fontSize = "smaller";

      row.insertCell(-1).appendChild(document.createTextNode(n++));
      row.insertCell(-1).appendChild(document.createTextNode(parus.parus8.nodeField(dataRow, "FORM_CODE") || String.fromCharCode(160)));
      row.insertCell(-1).appendChild(document.createTextNode(parus.parus8.nodeField(dataRow, "SECTION_CODE") || String.fromCharCode(160)));
      row.insertCell(-1).appendChild(document.createTextNode(parus.parus8.nodeField(dataRow, "BDATE") || String.fromCharCode(160)));
      row.insertCell(-1).appendChild(document.createTextNode(parus.parus8.nodeField(dataRow, "AGENT_CODE") || String.fromCharCode(160)));
      row.insertCell(-1).appendChild(document.createTextNode(parus.parus8.nodeField(dataRow, "CHECKLIST_CODE") || String.fromCharCode(160)));
      row.insertCell(-1).appendChild(document.createTextNode(parus.parus8.nodeField(dataRow, "RESULT") || String.fromCharCode(160)));
      row.insertCell(-1).innerHTML = (parus.parus8.nodeField(dataRow, "MESSAGE") || String.fromCharCode(160)).split("\n").join("<br/>");
      if (full) {
        row.insertCell(-1).appendChild(document.createTextNode(parus.parus8.nodeField(dataRow, "LEFT_DESC") || String.fromCharCode(160)));
        row.insertCell(-1).appendChild(document.createTextNode(parus.parus8.nodeField(dataRow, "LEFT_RESULT") || String.fromCharCode(160)));
        row.insertCell(-1).appendChild(document.createTextNode(parus.parus8.nodeField(dataRow, "REL_OPERATOR") || String.fromCharCode(160)));
        row.insertCell(-1).appendChild(document.createTextNode(parus.parus8.nodeField(dataRow, "RIGHT_DESC") || String.fromCharCode(160)));
        row.insertCell(-1).appendChild(document.createTextNode(parus.parus8.nodeField(dataRow, "RIGHT_RESULT") || String.fromCharCode(160)));
        row.insertCell(-1).appendChild(document.createTextNode(parus.parus8.nodeField(dataRow, "SUBTRACTION") || String.fromCharCode(160)));
      }

    });

    if (n == 1) dojo.place("<div>Нет ошибок и предупреждений.</div>", table, "replace");

    return body.innerHTML;

  }



});