dojo.provide("parus.proxy");

if (!parus) parus = {};

if (!parus.proxy) dojo.mixin(parus, {
  proxy: {}
});

dojo.mixin(parus.proxy, {

  Class_OCIProxyParusBalanceContentHandler: "{62F90CA0-67AA-41BC-8954-052FAE60056A}",
  //Balance ЦУД
  CLASS_PPCProxyBalanceContentHandler: "{B49A47C4-1FE1-4678-BBD2-F2EA86F4B514}",
  //Balance ЦУД
  CLASS_ParusRemoteAccessContentHandler: "{E9ACB1C3-3F97-4045-BDB3-B6944CA9D21B}",
  //ЦУД
  CLASS_PPCRemoteAccessContentHandler: "{73A6B080-08BA-4ED6-9E63-68B77BB60D25}",
  //ЦУД
  launcherFileName: "ParusClient.exe",

  installlerFileName: "ParusClientInstaller.exe",

  buildLaunchersList: function(handlerClasses, path) {
    dojo.xhrGet({
      handleAs: "xml",
      sync: true,
      headers: {
        "Disable-Basic-Auth": "yes"
      },
      url: "../.system/contents.xml",
      load: dojo.hitch(this, function(response) {
        var launchersNode = document.getElementById("launchers");

        var found = false;
        for (var i = 0; i < response.documentElement.childNodes.length; i++) {
          var node = response.documentElement.childNodes[i];
          if ((handlerClasses.indexOf(node.getAttribute("class").toString()) >= 0) && ((node.getAttribute("disabled") || 0).toString() != "1")) {

            if (!found) {

              var paraNode = launchersNode.appendChild(document.createElement("p"));
              var linkNode = paraNode.appendChild(document.createElement("a"));
              linkNode.style.fontWeight = "bold";
              linkNode.style.fontSize = "120%";

              var appName = this.launcherFileName.split(".")[0];

              var iconNode = paraNode.appendChild(document.createElement("img"));
              iconNode.src = path + appName + ".ico";
              iconNode.align = "middle";
              iconNode.width = 16;
              iconNode.height = 16;
              linkNode.appendChild(iconNode);


              linkNode.appendChild(document.createTextNode(String.fromCharCode(160) + "Единый агент для всех доступных организаций и приложений"));
              linkNode.setAttribute("href", path + this.launcherFileName);

              paraNode = launchersNode.appendChild(document.createElement("p"));
              linkNode = paraNode.appendChild(document.createElement("a"));
              linkNode.style.fontWeight = "bold";
              linkNode.style.fontSize = "120%";

              appName = this.launcherFileName.split(".")[0];

              iconNode = paraNode.appendChild(document.createElement("img"));
              iconNode.src = path + appName + ".ico";
              iconNode.align = "middle";
              iconNode.width = 16;
              iconNode.height = 16;
              linkNode.appendChild(iconNode);

              linkNode.appendChild(document.createTextNode(String.fromCharCode(160) + "Инсталлятор системных компонент"));
              linkNode.setAttribute("href", path + this.installlerFileName);

              launchersNode.appendChild(document.createElement("hr"));
            }

            found = true;
          }
        };

        ((found) ? document.getElementById("noLaunchers") : launchersNode).style.display = "none";

        dojo.fadeIn({
          node: document.getElementById("remoteAccessInfo")
        }).play();

        return (response);
      })
    });
  }
});