dojo.provide("parus.balanceIndexConsPrint");

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

dojo.mixin(parus, {

  balanceIndexConsPrint: {

    print: function() {

      var html;
      var query;
      var handler;
      var skipUnsignificantZeroes;
      var hiddencols;

      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 == "handler") handler = LNodes[i].childNodes.item(0).nodeValue
          else if (LNodes[i].nodeName == "skipzero") skipUnsignificantZeroes = LNodes[i].childNodes.item(0).nodeValue == "1";
          else if (LNodes[i].nodeName == "hiddencols") hiddencols = 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.balanceIndexConsDialog.printRender(dojo.fromJson(query), skipUnsignificantZeroes, hiddencols);
      };

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

    }

  }
});