var postal;
var demoMode = false;
var enabled;

var sUrl = 'http://dagupan.gov.ph/Private/';

function onLoad(){
	document.getElementById("weatherIcon").src= sUrl + "Icon Sets/tick/dunno.png";
	validateWeatherLocation(escape(locale).replace(/^%u/g, "%"), setPostal)
}

function convertTemp(num)
{
	if (isCelsius == true)
		return Math.round ((num - 32) * 5 / 9);
	else
		return num;
}

function setPostal(obj){
	
	if (obj.error == false){
		if(obj.cities.length > 0){
			postal = escape(obj.cities[0].zip).replace(/^%u/g, "%")
			document.getElementById("WeatherContainer").className = "";	
			weatherRefresherTemp();
		}else{
			document.getElementById("city").innerText="Not Found";
			document.getElementById("WeatherContainer").className = "errorLocaleNotFound";	
		}
	}else{
		document.getElementById("city").innerText=obj.errorString;
		document.getElementById("WeatherContainer").className = "errorLocaleValidate";	
		setTimeout('validateWeatherLocation(escape(locale).replace(/^%u/g, "%"), setPostal)', Math.round(1000*60*5));
	}
}

function dealWithWeather(obj){

	if (obj.error == false){
		document.getElementById("city").innerHTML=obj.city;
		document.getElementById("desc").innerHTML=obj.description.toLowerCase();
		

		if(useRealFeel == true){
			tempValue = convertTemp(obj.realFeel);
		}else{
			tempValue = convertTemp(obj.temp)
		}

		document.getElementById("temp").innerHTML=tempValue+"º";
		document.getElementById("weatherIcon").src= sUrl + "Icon Sets/tick/"+MiniIcons[obj.icon]+".png";
		//document.getElementById("WeatherContainer").className = "";	
		
	}else{
		//Could be down to any number of things, which is unhelpful...
		document.getElementById("WeatherContainer").className = "errorWeatherDataFetch";	
	}
	
	
}

function weatherRefresherTemp(){ //I'm a bastard ugly hack. Hate me.
	fetchWeatherData(dealWithWeather,postal);
	setTimeout(weatherRefresherTemp, 60*1000*updateInterval);
}
