//Generate HTML for the weather section on the branding
//inserts HTML code into a hardcoded div id "xmlfeed_branding_weather"
function generateHTMLWeather(req, num) {
	/***** Feed to parse - http://weather.yahooapis.com/forecastrss?p=SNXX0006&u=c *****/
	/***** XML response object - /common/php/curl_proxy.php?url=http%3A//weather.yahooapis.com/forecastrss?p=SNXX0006&u=c *****/
	/***** HTML to generate *****
	chday <span class="en">Monday, 14 May 2007 <img src="/common/imgs/cloud1.gif" width="40" height="27" alt="" title="" border="0" />26C  (25C to 32C)</span>
	*****************************/
	
	var xmlDoc = req.responseXML;
	//if (!xmlDoc) return;
	//alert("lastBuildDate: "+xmlDoc.getElementsByTagName('lastBuildDate').length);
	
	if (window.ActiveXObject) tagPrefix = "yweather:"; //IE needs prefix
	else if (document.implementation && document.implementation.createDocument) tagPrefix = ""; //Mozilla, Firefox, Opera, etc.
	
	if (!xmlDoc.getElementsByTagName(tagPrefix+"condition")[0]) return;
	var weatherDescription = xmlDoc.getElementsByTagName(tagPrefix+"condition")[0].attributes[0].nodeValue; //'text', eg. "Light Showers"
	var weatherCode = xmlDoc.getElementsByTagName(tagPrefix+"condition")[0].attributes[1].nodeValue; //'code', eg. "11".gif
	var currentTemp = xmlDoc.getElementsByTagName(tagPrefix+"condition")[0].attributes[2].nodeValue; //'temp', eg. "26" (deg C)
	var currentDateTime = xmlDoc.getElementsByTagName(tagPrefix+"condition")[0].attributes[3].nodeValue; //'date', eg. "Thu, 14 Jun 2007 12:00 pm SGT"
	
	var customIcons = new Array("4", "9", "11", "21", "24", "26", "27", "27", "28", "29", "30", "31", "32", "33", "34", "36", "45");
	for (var i=0; i<customIcons.length; i++) {
		if (customIcons[i] == weatherCode) { //if custom icon found
			var path = "/common/imgs/weather/";
			break;
		}
		var path = "http://l.yimg.com/us.yimg.com/i/us/we/52/";
	}
	
	var weatherImage = new Image();
	weatherImage.src = path + weatherCode +".gif";
	weatherImage.alt = weatherDescription; // + " - weather forecast for " + currentDateTime;
	
	var minTemp = xmlDoc.getElementsByTagName(tagPrefix+"forecast")[0].attributes[2].nodeValue; //'low', eg. "26" (deg C)
	var maxTemp = xmlDoc.getElementsByTagName(tagPrefix+"forecast")[0].attributes[3].nodeValue; //'high', eg. "26" (deg C)
	
	var str = '';
	str += '<img src="'+weatherImage.src+'" width="32" height="23" alt="'+weatherImage.alt+'" title="'+weatherImage.alt+'" border="0" />\n';
	str += '&nbsp;'+currentTemp+'&deg;C';
	str += '&nbsp;&nbsp;('+minTemp+'&deg;C to '+maxTemp+'&deg;C)</span>\n';
	
	//append the item to the DOM
	document.getElementById("xmlfeed_branding_weather").innerHTML = str;
}

function getCnDay(id) {
	var cnDay;
	var enDay = document.getElementById(id).innerHTML.toLowerCase().substr(0,3);
	switch (enDay) {
		case "mon":
			cnDay = "%u661F%u671F%u4E00"; break;
		case "tue":
			cnDay = "%u661F%u671F%u4E8C"; break;
		case "wed":
			cnDay = "%u661F%u671F%u4E09"; break;
		case "thu":
			cnDay = "%u661F%u671F%u56DB"; break;
		case "fri":
			cnDay = "%u661F%u671F%u4E94"; break;
		case "sat":
			cnDay = "%u661F%u671F%u516D"; break;
		case "sun":
			cnDay = "%u661F%u671F%u65E5"; break;
		default:
			break;
	}	
	document.getElementById(id).innerHTML = unescape(cnDay);
}
