  var MediusKeepAliveLocalCount = 0;
  
  var MediusKeepAliveCount    = 0;
  var MediusKeepAliveTimeOut  = 60;
  var MediusKeepAlivePing     = 2;
  var MediusKeepAliveMsgTime  = 40;
  var MediusKeepAliveURLCount = 0;

  var MediusRestartFormMouseIsDown = false;
  var MediusRestartFormLastClientX = 0;
  var MediusRestartFormLastClientY = 0;
  
  var MediusRestartFormPosX = 350;
  var MediusRestartFormPosY = 250;
  
  function HandleUnLoad()
  {
    if (window.screenTop > 9999) 
    {
      var MKAF = document.getElementById("MediusKeepAliveFrame");
      MKAF.src = "/KeepAlive.Medius.axd?Closing=yes" 
    }
    MediusKeepAliveCount = 0;
  }
    
  function Minuut_en(x)
  {
    if (x==1) return "1 minuut";
         else return x+" minuten";
  }
  
  function MediusRestartFormMouseDown(event)
  {
    var event = (!event) ? window.event : event;
    
    var newX = 0;
    var newY = 0;

    if (document.all) {
      MediusRestartFormLastClientX = event.clientX;
      MediusRestartFormLastClientY = event.clientY;
    } else {
      MediusRestartFormLastClientX = event.pageX;
      MediusRestartFormLastClientY = event.pageY;
    }      
    
    MediusRestartFormMouseIsDown = true;
  }
  
  function MediusRestartFormMouseUp()
  {
    MediusRestartFormMouseIsDown = false;
  }
  
  function MediusRestartFormMouseMove(event)
  {
    var event = (!event) ? window.event : event;
    var newX = 0;
    var newY = 0;

    if (MediusRestartFormMouseIsDown)
    {
      if (document.all) {
        newX = event.clientX;
        newY = event.clientY;
      } else {
        newX = event.pageX;
        newY = event.pageY;
      }      
    
      MediusRestartFormPosX += newX-MediusRestartFormLastClientX;
      MediusRestartFormPosY += newY-MediusRestartFormLastClientY;
      
      MediusRestartFormLastClientX = newX;
      MediusRestartFormLastClientY = newY;

      document.getElementById("KeepAliveCounterWindow").style.left = MediusRestartFormPosX+"px";
      document.getElementById("KeepAliveCounterWindow").style.top  = MediusRestartFormPosY+"px";
    }
  }
  
  function MediusRestartAlive()
  {
    MediusKeepAliveLocalCount = 0;
    MediusKeepAliveCount = 0;
    MediusKeepAliveURLCount = 1;
    var MKAF = document.getElementById("MediusKeepAliveFrame");
    MKAF.src = "/KeepAlive.Medius.axd?URLCount=1";
    document.getElementById("KeepAliveCounterWindow").style.visibility = "hidden";
  }
  
  function MediusKeepAliveFunc() 
  {
    if (MediusKeepAliveCount==(-1)) 
      return;
          
    MediusKeepAliveLocalCount++;
    MediusKeepAliveCount++;
    if (MediusKeepAliveCount<MediusKeepAliveTimeOut)
    {
      
      var MKAF = document.getElementById("MediusKeepAliveFrame");
      if ((MediusKeepAliveLocalCount % MediusKeepAlivePing)==0)
      {
        MKAF.src = "/KeepAlive.Medius.axd?URLCount="+ ++MediusKeepAliveURLCount; 
      }
              
      if ((MediusKeepAliveLocalCount % MediusKeepAlivePing)==1)
      {
        //debugger;
        if (MediusKeepAliveFrame.document.getElementById("KeepAliveMsgTime")           != null) 
          if (MediusKeepAliveFrame.document.getElementById("KeepAliveMsgTime").innerHTML != ""  )
          {
            MediusKeepAliveCount   = MediusKeepAliveFrame.document.getElementById("KeepAliveCount").innerHTML;
            MediusKeepAliveTimeOut = MediusKeepAliveFrame.document.getElementById("KeepAliveTimeOut").innerHTML;
            MediusKeepAlivePing    = MediusKeepAliveFrame.document.getElementById("KeepAlivePing").innerHTML;
            MediusKeepAliveMsgTime = MediusKeepAliveFrame.document.getElementById("KeepAliveMsgTime").innerHTML;
            MediusKeepAliveFrame.document.getElementById("KeepAliveMsgTime").innerHTML = "";
          }  
      }
        
      if (Number(MediusKeepAliveCount)>=Number(MediusKeepAliveMsgTime))
      {
        document.getElementById("KeepAliveCounterWindow").style.visibility = "visible";
        if (!MediusRestartFormMouseIsDown)
          document.getElementById("KeepAliveCounterLabel").innerHTML = "<center>Uw connectie is al "+Minuut_en(MediusKeepAliveCount)+" niet actief en wordt over "+Minuut_en(MediusKeepAliveTimeOut-MediusKeepAliveCount)+" verbroken</center>";
      }
      else
      {
        document.getElementById("KeepAliveCounterWindow").style.visibility = "hidden";
      }
    }
    else
      document.location = "/Admin/Security/Logoff.aspx";
  }

  setInterval('MediusKeepAliveFunc()', 60000);
  if (document.all)
  {
    document.body.onunload    = HandleUnLoad;
    document.body.onmousemove = MediusRestartFormMouseMove;
    document.body.onmouseup   = MediusRestartFormMouseUp;
    KeepAliveCounterWindowHeader.onmousedown = MediusRestartFormMouseDown;
  }

