//loads the data from the rest server
function showForecast_Type1(location){
	SimcoeWeatherAPI.localforecast_get({
		parameters: {
	        apikey: "94351bc971eb5aab6a0cdc84227a6af3",
			secretkey: "c77cfd5563c8ec4bfcde94c09098ba84",
			callback: "getResults",
			location: location,
			dayname: "local"
	    }
	});
	
	//beta - refreshes every 2 minutes automatically
	setTimeout("showForecast_Type1(\""+ location+ "\")",120000);
}

//the callback function specified above in the "callback" parameter
function getResults(obj){

	if (obj.sw.status == "error") {
		var error_code = obj.sw.code;
		var error_message = obj.sw.message;
		
		document.getElementById("localforecast_error").innerHTML = "Error Code: " + error_code + "<br />Message: " + error_message;
	}
	else {
		var output = '<table width="100%" cellspacing="0" cellpading="0" style="font-size:small;text-align:center;">';
		output += '<tr>';
		output += '<td colspan="2" align="left" style="background-color:#3F5F9C;color:#ffffff;font-size:medium;">Forecast for '+obj.sw.forecastinfo.location.place+'</td>';
		output += '</tr>';
		output += '<tr align="center">';
		output += '<td style="border-right:1px solid #dddddd;" width="50%" valign="top"><b>Currently</b></td>';
		var dayname = obj.sw.forecastinfo.forecast.day[0].dayname;		
		output += '<td valign="top"><b>'+dayname+'</b></td>';
		output += '</tr>';
		output += '<tr>';
		output += '<td style="border-right:1px solid #dddddd;" valign="top"><div style="font-size:medium;margin-bottom:5px;">'+obj.sw.forecastinfo.observation.temperature+'&deg;C</div>Humi: '+obj.sw.forecastinfo.observation.humidity+'%<br />Pressure:<br />'+obj.sw.forecastinfo.observation.pressure+' mb<br />Wind: '+obj.sw.forecastinfo.observation.winddir+'<br />'+obj.sw.forecastinfo.observation.windspeed+' km/h</td>';
		output += '<td valign="top"><img src="http://www.simcoe-weather.com/images/wx_icons/60/'+obj.sw.forecastinfo.forecast.day[0].weathericon+'.gif" alt="'+obj.sw.forecastinfo.forecast.day[0].condition+'" title="'+obj.sw.forecastinfo.forecast.day[0].condition+'" /><div style="font-size:medium;margin-top:5px;">'+obj.sw.forecastinfo.forecast.day[0].temperature+'&deg;C</div></td>';
		output += '<tr>';
		output += '<td colspan="2" align="right"><a href="http://www.simcoe-weather.com/forecast/'+obj.sw.forecastinfo.location.place.toLowerCase()+'" target="_blank"><img src="http://www.simcoe-weather.com/badge/logo.png" alt="Click for Full Forecast" title="Click for Full Forecast" border="0" /></a></td>';
		output += '</tr>';
		output += '</table>';
		
		document.getElementById("localforecast_output").innerHTML = output;
	}
}