
var timerID = 0;

function loadWeather()
{

		if(timerID)
		{
				clearTimeout(timerID);
				clockID  = 0;
		}

		dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "/weatherjson?nocache"+timerID,
		handleAs: "json",
		load: function(response, ioArgs)
		{
				var o = document.getElementById("weatherimg");
				o.src = response.imagelocation;
				o.title = response.description;
				document.getElementById("globallocation").innerHTML = response.location;
				document.getElementById("globalweather").innerHTML = response.degreefahrenheit+"&#176;F  "+response.degreecelsius+"&#176;C" ;

				timerID = setTimeout("loadWeather();", 5000);

				return response;
		},

		//// The ERROR function will be called in an error case.
		error: function(response, ioArgs)
		{
				// alert("ERROR");
				console.error("HTTP status code: ", ioArgs.xhr.status);
				return response;
		}
});
}

function Start()
{
		loadWeather();

		timerID  = setTimeout("loadWeather();", 5000);
}

function Stop()
{
		if(timerID)
		{
				clearTimeout(timerID);
				timerID  = 0;
		}
}