if (typeof _htmlhead_start != "undefined" && document.getElementById && document.createElement)
{
  // new session gets new timer
  var tsess_new = sessid.substring(sessid.indexOf("=")+1, sessid.length);
  var tsess_old = __cookie__.get("tsess");
  if (nxValid(tsess_old) && tsess_old != tsess_new)
    __cookie__.set("ttime", 0);

  __cookie__.set("tsess", tsess_new);

  function gettcookie()
  {
    var ttime = __cookie__.get("ttime");
    ttime = nxValid(ttime) && ttime != 0 ? ttime : 0;
    __cookie__.set("ttime", 0);

    return parseInt(ttime);
  };

  function savetcookie(e)
  {
    var ttime = new Date().valueOf()
    __cookie__.set("ttime", ttime);
  };

  var dbgcount = 0;

  function evaldbg()
  {
    dbgcount++;
    //window.status = dbgcount;
    if (dbgcount>10)
      it.style.display = "block";
  };

  function dbgdown()
  {
    if (dbgcount>0)
      dbgcount--;
  };

  if (window.attachEvent)
  {
    window.attachEvent("onbeforeunload", savetcookie);
    document.body.attachEvent("onclick", evaldbg);
    window.setInterval("dbgdown()", 1000);
  }
  else if (window.addEventListener)
  {
    if (__client__.getEngine() == "gecko")
    {
      if (__client__.getBrowserMajorVersion() == 1)
      {
        if (__client__.getBrowserMinorVersion() >= 7)
        {
          window.addEventListener("beforeunload", savetcookie, false);
        }
        else
        {
          __cookie__.set("ttime", 0);
        };
      }
      else
      {
        __cookie__.set("ttime", 0);
      };
    }
    else
    {
      window.addEventListener("beforeunload", savetcookie, false);
    };

    window.addEventListener("click", evaldbg, false);
    window.setInterval("dbgdown()", 300);
  };

  var _lastload_start = gettcookie();
  var _postexec_stop = new Date().valueOf();
  var _fsize_post = document.body.innerHTML.length;
  var _complete = eval("_postexec_stop") - eval("_lastload_start");

  var it = document.createElement("table");
  it.cellPadding=2;
  it.cellSpacing=0;

  with(it.style)
  {
    display="none";
    border="1px solid #000000";
    backgroundColor="#fff";
    position="absolute";
    right="10px";
    top="120px";
    padding="4px";
    zIndex="1000000";
  }

  var itb = document.createElement("tbody");
  it.appendChild(itb);

  function _print(l, v)
  {
    var itr1 = document.createElement("tr");
    itb.appendChild(itr1);

    var ith1 = document.createElement("th");
    ith1.appendChild(document.createTextNode(l));
    itr1.appendChild(ith1);
    with(ith1.style)
    {
      fontSize="10px";
      textAlign="left";
    };

    var itd1 = document.createElement("td");
    itd1.appendChild(document.createTextNode(v));
    itr1.appendChild(itd1);
    with(itd1.style)
    {
      fontSize="10px";
      textAlign="left";
      color="#565656";
    };
  };

  function _printheader(l)
  {
    var itr1 = document.createElement("tr");
    itb.appendChild(itr1);

    var ith1 = document.createElement("th");
    ith1.appendChild(document.createTextNode(l));
    ith1.colSpan=2;
    itr1.appendChild(ith1);
    with(ith1.style)
    {
      fontSize="11px";
      textAlign="left";
      background="#565656";
      color="#fff";
      fontWeight="bold";
    };
  };

  function _printvalue(l, f, u)
  {
    _print(l, f + u);
  };

  function _printvar(f)
  {
    _print(f, eval("_" + f));
  };

  function _printdiff(t, f1, f2, u)
  {
    var mt = eval("_" + f2) - eval("_" + f1);
    var mc = Math.round(mt / _complete * 100)
    var ms = mc == 100 || _lastload_start==0 ? mt + u : mt + u + " (" + mc + "%)";
    _print(t, ms);
  };

  _printheader("Client");
  _printvalue("Engine", __client__.getEngine(), "");
  _printvalue("Version", __client__.getBrowserMajorVersion() + "." + __client__.getBrowserMinorVersion(), "");
  _printvalue("Platform", __client__.getPlatform(), "")
  _printvalue("System", __client__.getSystem(), "")
  _printvalue("Color", screen.colorDepth, "")
  _printvalue("Width", screen.width, "")
  _printvalue("Height", screen.height, "")
  _printvalue("Flash", __client__.getFlashVersion(), "")


  if (_lastload_start!=0)
  {
    _printheader("All");
    _printdiff("Request-Complete", "lastload_start", "postexec_stop", "ms");

    _printheader("Server");
    _printdiff("Server-Complete", "lastload_start", "htmlhead_start", "ms");
  };

  _printheader("HTML");
  _printdiff("HTML-Complete", "htmlhead_start", "postexec_stop", "ms");

  _printheader("HTML-Details");
  _printdiff("HTML-Head", "htmlhead_start", "htmlhead_stop", "ms");
  _printdiff("Page-Head", "pageheader_start", "pageheader_stop", "ms");
  _printdiff("Page-Body", "pagecontent_start", "pagecontent_stop", "ms");
  _printdiff("Post-Exec", "postexec_start", "postexec_stop", "ms");

  // final append
  document.body.appendChild(it);

  var timg = new Image();
  var tpath = "/common/img/loadtimer.gif";
  var tpara = "?";

  function _addpara(t, f1, f2)
  {
    var mt = eval("_" + f2) - eval("_" + f1);
    tpara += t + "=" + mt + "&";
  };

  tpara += "engine=" + __client__.getEngine() + "&";
  tpara += "version=" + __client__.getBrowserMajorVersion() + "." + __client__.getBrowserMinorVersion() + "&";
  tpara += "platform=" + __client__.getPlatform() + "&";
  tpara += "system=" + __client__.getSystem() + "&";
  tpara += "color=" + screen.colorDepth + "&";
  tpara += "width=" + screen.width + "&";
  tpara += "height=" + screen.height + "&";
  tpara += "flash=" + __client__.getFlashVersion() + "&";
  tpara += "page=" + page + "&";

  for (var i=0; i<_pagerdata.length; i++)
    tpara += "pager" + i + "=" + _pagerdata[i] + "&";

  if (_lastload_start!=0)
  {
    _addpara("reqcomplete", "lastload_start", "postexec_stop");
    _addpara("servercomplete", "lastload_start", "htmlhead_start");
  };

  _addpara("htmlcomplete", "htmlhead_start", "postexec_stop");
  _addpara("htmlhead", "htmlhead_start", "htmlhead_stop");
  _addpara("pagehead", "pageheader_start", "pageheader_stop");
  _addpara("pagebody", "pagecontent_start", "pagecontent_stop");
  _addpara("postexec", "postexec_start", "postexec_stop");

  timg.src = tpath + tpara;

  document.body.appendChild(timg);
};

