﻿function hideDocumentElement(id) 
{
    var el = document.getElementById(id);
    if (el) el.style.display = 'none';
}

function showDocumentElement(id) 
{
    var el = document.getElementById(id);
    if (el) el.style.display = 'block';
}

function switchVisibility(id)
{
	if(document.getElementById(id).style.display == 'block')
	{
		hideDocumentElement(id);	
	}
	else
	{
		showDocumentElement(id);
	}
}

/******************************************************************* 
  Timer
/*******************************************************************/

var secs
var timerID = null
var timerRunning = false
var delay = 2000

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 1
    StopTheClock()
    StartTheTimer()

    
    showDocumentElement('feedback');
    hideDocumentElement('gatherInfo');

}

function StopTheClock()
{
    if(timerRunning)
    clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        
        document.getElementById("ctl00_AREA_BODY_AREA_CONTENT_btNext").click();

    }
    else
    {
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
   
}

function setResult(latency, pipeSpeed) 
{
    var result;
    
	if (pipeSpeed < 0)
	{
	    result = "Bandwidth is too fast to measure";
	}
	else 
	{
	    result = "Pipe speed " + pipeSpeed + " kilobytes / sec" + " HTTP Latency: " + latency + "ms ";
	}
	
	document.getElementById("ctl00_AREA_BODY_AREA_CONTENT_hfSpeedResults").value = result;
	
	getComputerInfo("ctl00_AREA_BODY_AREA_CONTENT_hfComputer");
	InitializeTimer();
	
}

