// JavaScript Document
// start of speedtest & redirect code
  var iFileSize = 27263; 		// size of image (speedtest.jpg) in bytes
  var objImage = new Image();
  objImage.onload = StopWatch;
  var objDate = new Date();
  var objStartTime = objDate.getTime();
  var objStopTime = objDate.getTime();
  var objTimerHandle = 0;
  var iIterations = 0;
     
  function Working()
  {
    //$("#speedtest").append(".");
    iIterations++;
    if (iIterations < 3600)
      {
      objTimerHandle = setTimeout("Working();", 500);
      }  
    else 
      {
      //$("#speedtest").append("\nERROR:  Either the test 'load test' file could not be found, or your network is too slow or not functioning properly. (Took more than 30 minutes to complete.)");
      }
  }
  function StartWatch()
  {
    //$("#speedtest").html("Testing bandwidth speed...");
    objDate = new Date()
    objStartTime = objDate.getTime();
    objImage.src = "speedtest.jpg?Epoch=" + objStartTime ;
    objTimerHandle = setTimeout("Working();", 500);
  }
  function StopWatch()
  {
    objDate = new Date()
    objStopTime = objDate.getTime();
    if (objTimerHandle) 
      {
      clearTimeout(objTimerHandle);
      objTimerHandle=0;
      }
    var iDuration = (objStopTime - objStartTime) / 1000;  // the number of seconds it took
    var iThroughPut = (iFileSize / iDuration) / 1024;
    var iThroughPutBits = ((iFileSize * 8) / iDuration) / 1024;
    iThroughPut = (Math.round(iThroughPut * 100)) / 100
    iThroughPutBits = (Math.round(iThroughPutBits * 100)) / 100
    //$("#speedtest").append("\nTest completed...");
    //$("#speedtest").append("\nNetwork throughput is " + iThroughPut + " kilobytes per second. \n(" + iThroughPutBits + " kilobits per second)");
    iIterations = 0;    
   if (iThroughPut<20)
   {
    window.location="index_lowband.php";
   }
   }
   // end speedtest/redirect code 
 
