dojo.provide("parus.balanceReportCheckProtocolPrint");

dojo.require("parus.parus8");
dojo.require("parus.database");
dojo.require("parus.balanceReportCheckProtocolTabPage");

dojo.mixin(parus, {

  balanceReportCheckProtocolPrint: {

    print: function() {

      var query;
      var full;
      var handler;
      var title;
      var html;

      dojo.xhrGet({

        url: "../.system/session.xml",
        handleAs: "xml",
        sync: true,
        preventCache: true,

        load: function(response) {

          if (!dojo.isIE) response.normalize();

          var LNodes = response.documentElement.getElementsByTagName("*");

          for (var i = 0; i != LNodes.length; i++)
          if (LNodes[i].nodeName == "querydata") query = LNodes[i].childNodes.item(0).nodeValue
          else if (LNodes[i].nodeName == "full") full = (LNodes[i].childNodes.item(0).nodeValue == "1")
          else if (LNodes[i].nodeName == "handler") handler = LNodes[i].childNodes.item(0).nodeValue
          else if (LNodes[i].nodeName == "title") title = LNodes[i].childNodes.item(0).nodeValue;
          else if (LNodes[i].nodeName == "htmldata") html = LNodes[i].childNodes.item(0).nodeValue;

          return (response);

        }
      });

      if (query) {
        parus.database.connected = handler;
        html = parus.balanceReportCheckProtocolTabPage.printRender(dojo.fromJson(query), full, title);
      };

      if (html) document.body.insertAdjacentHTML("afterBegin", html);

      var titleNode = document.body.firstChild;

      document.title = (!dojo.isIE || dojo.isIE >= 10) ? titleNode.textContent : titleNode.innerText;

    }

  }

});