function Folder(a, b) {
  this.desc = a;
  this.hreference = b;
  this.id = -1;
  this.navObj = 0;
  this.children = new Array();
  this.nChildren = 0;
  this.level = 0;
  this.leftSideCoded = "";
  this.isOpen = false;
  this.isRendered = 0;
  this.initialize = initializeFolder;
  this.setState = setStateFolder;
  this.addChild = addChild;
  this.createIndex = createEntryIndex;
  this.escondeBlock = escondeBlock;
  this.esconde = escondeFolder;
  this.mostra = mostra;
  this.renderOb = drawFolder;
  this.totalHeight = totalHeight;
  this.subEntries = folderSubEntries;
  this.blockStartHTML = blockStartHTML;
  this.blockEndHTML = blockEndHTML;
}
function initializeFolder(d, c) {
  var a = 0;
  var b = 0;
  nc = this.nChildren;
  this.createIndex();
  this.level = d;
  this.leftSideCoded = c;
  if (browserVersion == 0) {
    this.isOpen = true;
  }
  if (d > 0) {
    c = c + "0";
  }
  if (nc > 0) {
    d = d + 1;
    for (b = 0; b < this.nChildren; b++) {
      this.children[b].initialize(d, c);
    }
  }
}
function gonextURL(a) {
  window.sessionStorage.id = a;
  window.sessionStorage.historyFolderURL = indexOfEntries[a].hreference;
  window.sessionStorage.removeItem("historyItemURL");
  top.window.frames.basefrm.location = indexOfEntries[a].hreference;
//  top.document.title = indexOfEntries[a].desc;
  if (indexOfEntries[a].hreference.indexOf("logout.html") != -1) {
    window.sessionStorage.removeItem("historyFolderURL");
    window.sessionStorage.removeItem("id");
  }
}
function drawFolder() {
  var a = "";
  var b = leftSideHTML(this.leftSideCoded);
  this.isRendered = 1;
  if (browserVersion == 2) {
    if (!doc.yPos) {
      doc.yPos = 10;
    }
  }
  a = this.blockStartHTML("folder");
  if (this.level > 0) {
    a = a + "<tr>";
    a = a + "<td class='menuCell' valign=middle nowrap width=100%>";
    a =
      a +
      "<a class='menuLink' href='javascript:gonextURL(\"" +
      this.id +
      "\")'";
    if (browserVersion > 0) {
      a = a + "onClick='javascript:clickOnFolder(" + this.id + ")'";
    }
    a = a + ">" + b + this.desc + "&nbsp;&nbsp;</a>";
    a = a + "</td>";
  }
  a = a + this.blockEndHTML();
  doc.write(a);
  if (browserVersion == 1) {
    this.navObj = getElById("folder" + this.id);
  } else {
    if (browserVersion == 2) {
      this.navObj = doc.layers["folder" + this.id];
      doc.yPos = doc.yPos + this.navObj.clip.height;
    }
  }
}
function setStateFolder(d) {
  var f;
  var c;
  var e = 0;
  var b = 0;
  var a;
  if (d == this.isOpen) {
    return;
  }
  if (browserVersion == 2) {
    c = 0;
    for (b = 0; b < this.nChildren; b++) {
      c = c + this.children[b].navObj.clip.height;
    }
    f = this.subEntries();
    if (this.isOpen) {
      c = 0 - c;
    }
    for (e = this.id + f + 1; e < nEntries; e++) {
      indexOfEntries[e].navObj.moveBy(0, c);
    }
  }
  this.isOpen = d;
  propagateChangesInState(this);
}
function propagateChangesInState(b) {
  var a = 0;
  for (a = b.nChildren - 1; a >= 0; a--) {
    if (b.isOpen) {
      b.children[a].mostra();
    } else {
      b.children[a].esconde();
    }
  }
}
function escondeFolder() {
  this.escondeBlock();
  this.setState(0);
}
function addChild(a) {
  this.children[this.nChildren] = a;
  this.nChildren++;
  return a;
}
function folderSubEntries() {
  var a = 0;
  var b = this.nChildren;
  for (a = 0; a < this.nChildren; a++) {
    if (this.children[a].children) {
      b = b + this.children[a].subEntries();
    }
  }
  return b;
}
function Item(a, b) {
  this.desc = a;
  this.link = b;
  this.id = -1;
  this.navObj = 0;
  this.isRendered = 0;
  this.level = 0;
  this.leftSideCoded = "";
  this.nChildren = 0;
  this.initialize = initializeItem;
  this.createIndex = createEntryIndex;
  this.escondeBlock = escondeBlock;
  this.esconde = escondeBlock;
  this.mostra = mostra;
  this.renderOb = drawItem;
  this.totalHeight = totalHeight;
  this.blockStartHTML = blockStartHTML;
  this.blockEndHTML = blockEndHTML;
}
function initializeItem(b, a) {
  this.createIndex();
  this.level = b;
  this.leftSideCoded = a;
}
function gonextItemURL(a) {
  window.sessionStorage.id = a;
  window.sessionStorage.historyItemURL = indexOfEntries[a].link;
  window.sessionStorage.removeItem("historyFolderURL");
  top.window.frames.basefrm.location = indexOfEntries[a].link;
//  top.document.title = indexOfEntries[a].desc;
}
function drawItem() {
  var b = leftSideHTML(this.leftSideCoded);
  var a = "";
  this.isRendered = 1;
  a = this.blockStartHTML("item");
  a = a + "<tr>";
  a = a + "<td class='menuCell' valign=middle nowrap width=100%>";
  a =
    a +
    "<a class='menuLink' href='javascript:gonextItemURL(\"" +
    this.id +
    "\")' >" +
    b +
    this.desc +
    "&nbsp;&nbsp;</a>";
  a = a + "</td>";
  a = a + this.blockEndHTML();
  doc.write(a);
  if (browserVersion == 2) {
    this.navObj = doc.layers["item" + this.id];
    doc.yPos = doc.yPos + this.navObj.clip.height;
  } else {
    if (browserVersion != 0) {
      this.navObj = getElById("item" + this.id);
    }
  }
}
function escondeBlock() {
  if (browserVersion == 1) {
    this.navObj.style.display = "none";
  } else {
    this.navObj.visibility = "hiden";
  }
}
function mostra() {
  if (!this.isRendered) {
    this.renderOb();
  } else {
    if (browserVersion == 1) {
      this.navObj.style.display = "block";
    } else {
      this.navObj.visibility = "show";
    }
  }
}
function blockStartHTML(c) {
  var b = "id='" + c + this.id + "'";
  var a = "";
  if (browserVersion == 2) {
    a = "<layer " + b + " top=" + doc.yPos + " >";
  } else {
    if (browserVersion == 1) {
      a = "<div " + b + " >";
    }
  }
  a = a + "<table border=0 cellspacing=2 cellpadding=0 width=100%>";
  return a;
}
function blockEndHTML() {
  var a = "";
  a = "</table>";
  if (browserVersion == 2) {
    a = a + "</layer>";
  } else {
    if (browserVersion == 1) {
      a = a + "</div>";
    }
  }
  return a;
}
function createEntryIndex() {
  this.id = nEntries;
  indexOfEntries[nEntries] = this;
  nEntries++;
}
function totalHeight() {
  var b = this.navObj.clip.height;
  var a = 0;
  if (this.isOpen) {
    for (a = 0; a < this.nChildren; a++) {
      b = b + this.children[a].totalHeight();
    }
  }
  return b;
}
function leftSideHTML(b) {
  var a;
  var c = "";
  for (a = 0; a < b.length; a++) {
    if (b.charAt(a) == "0") {
      c = c + "&nbsp;&nbsp;&nbsp;";
    }
  }
  return c;
}
function clickOnFolder(a) {
  var b = indexOfEntries[a];
  var c;
  for (i = 1; i < nEntries; i++) {
    c = indexOfEntries[i];
    if (b.level == c.level && c.isOpen == true) {
      c.setState(false);
      break;
    }
  }
  b.setState(true);
}
function gFld(a, b) {
  folder = new Folder(a, b);
  return folder;
}
function gLnk(d, e, b) {
  var a = "";
  var c = "";
  var f = "";
  var g = "";
  c = d.charAt(0);
  if (c == "R") {
    f = "basefrm";
  }
  if (c == "S") {
    f = "_self";
  }
  if (c == "P") {
    f = "_parent";
  }
  a = "" + b + "";
  linkItem = new Item(e, a);
  return linkItem;
}
function insFld(b, a) {
  return b.addChild(a);
}
function insDoc(b, a) {
  return b.addChild(a);
}
function renderAllTree(b) {
  var a = 0;
  b.renderOb();
  for (a = 0; a < b.nChildren; a++) {
    renderAllTree(b.children[a]);
  }
}
function hideWholeTree(e, f, b) {
  var d = 0;
  var a = 0;
  var c = b;
  if (f) {
    e.escondeBlock();
  }
  if (browserVersion == 2) {
    e.navObj.moveBy(0, 0 - b);
  }
  for (d = 0; d < e.nChildren; d++) {
    heightContainedInChild = hideWholeTree(e.children[d], true, c);
    if (browserVersion == 2) {
      a = a + heightContainedInChild + e.children[d].navObj.clip.height;
      c = c + heightContainedInChild;
    }
  }
  return a;
}
function getElById(a) {
  if (document.getElementById != null) {
    return document.getElementById(a);
  }
  if (document.all != null) {
    return document.all[a];
  }
  alert("Problem getting element by id");
  return null;
}
indexOfEntries = new Array();
nEntries = 0;
browserVersion = 0;
doc = document;
doc.yPos = 0;
function initializeDocument() {
  xbDetectBrowser();
  foldersTree.initialize(0, "0");
  renderAllTree(foldersTree);
  if (browserVersion != 0) {
    hideWholeTree(foldersTree, false, 0);
  }
  if (browserVersion == 2) {
    doc.write(
      "<layer top=" +
        indexOfEntries[nEntries - 1].navObj.top +
        ">&nbsp;</layer>"
    );
  }
  if (browserVersion != 0) {
    var a;
    a = indexOfEntries[0];
    a.setState(true);
  }
}
function xbDetectBrowser() {
  var b = window.onerror;
  window.onerror = null;
  window.saveNavigator = window.navigator;
  var a = window.navigator.userAgent.toLowerCase();
  if (
    a.indexOf("msie") != -1 ||
    a.indexOf("konqueror") != -1 ||
    a.indexOf("gecko") != -1
  ) {
    browserVersion = 1;
  } else {
    if (
      a.indexOf("mozilla") != -1 &&
      a.indexOf("spoofer") == -1 &&
      a.indexOf("compatible") == -1 &&
      a.indexOf("opera") == -1 &&
      a.indexOf("webtv") == -1 &&
      a.indexOf("hotjava") == -1
    ) {
      browserVersion = 2;
    } else {
      browserVersion = 0;
    }
  }
  window.onerror = b;
}
var timeoutInt;
var timeouttimer = -1;
var checkinterval = 0;
var realtimeout = 0;
//var displaytime = window.parent.frames[0].document.createElement("div");
function createdisplaydiv(c) {
  displaytime.id = "displayhttptimeout";
  displaytime.innerText = c;
  displaytime.className = "timeout_div";
  displaytime.style.position = "absolute";
  (displaytime.style.top = 20), (displaytime.style.right = 20);
  displaytime.style.fontSize = "20px";
  var a = window.parent.frames[0].document.querySelector("body");
  a.appendChild(displaytime);
}
function starttimeout() {
  checkinterval = checkinterval + 1;
  timeoutInt = timeoutInt - 1;
  window.parent.frames[0].document.getElementById(
    "displayhttptimeout"
  ).innerText = timeoutInt;
  if (timeoutInt == 0) {
    if (timeouttimer != -1) {
      window.clearInterval(timeouttimer);
    }
    with (top.frames.basefrm) {
      location.href = "logout.html";
    }
    return;
  }
  if (checkinterval == 60) {
    $.ajax({
      url: "gethttptimeout.html",
      success: function (result) {
        realtimeout = parseInt(result);
        if (realtimeout > 1 && realtimeout < 86400) {
          timeoutInt = realtimeout;
        }
        checkinterval = 0;
      },
    });
  }
}
function sethttptimeout(httptimeout) {
  if (httptimeout == "") {
    return;
  }
  timeoutInt = parseInt(httptimeout);
  if (timeoutInt < 60) {
    return;
  }
  if (timeoutInt > 86400) {
    timeoutInt = 86400;
  }
  createdisplaydiv(httptimeout);
  with (top) {
    var frm = document.querySelector("frame[name=basefrm]");
    if (frm) {
      $(frm).on("load", function () {
        $.get("gethttptimeout.html", function (data, status) {
          realtimeout = parseInt(data);
          if (realtimeout > 0 && realtimeout < 86400) {
            timeoutInt = realtimeout;
            checkinterval = 0;
          }
        });
      });
    }
  }
  timeouttimer = setInterval(function () {
    starttimeout();
  }, 1000);
}
