// JavaScript Document
var xmlWeather;
function loadWeather()
{
// code for IE
if (window.ActiveXObject)
  {
  xmlWeather=new ActiveXObject("Microsoft.XMLDOM");
  xmlWeather.async=false;
  xmlWeather.load("/en/js/yp_weather.xml");
  getweatherdata();
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation &&
document.implementation.createDocument)
  {
  xmlWeather=document.implementation.createDocument("","",null);
  xmlWeather.load("/en/js/yp_weather.xml");
  xmlWeather.onload=getweatherdata;
  }
else
  {
  alert('Your browser cannot handle this script');
  }
}

function getweatherdata()
{
var x=xmlWeather.documentElement;

//document.write(xmlWeather.documentElement.childNodes.length);
//for (i=0;i<x.childNodes.length;i++)
	//{
	//abc+=xmlWeather.getElementsByTagName("title")[i].childNodes[0].nodeValue;
	var dt=xmlWeather.getElementsByTagName("LastUpdateTime")[0].childNodes[0].nodeValue;
	var wf=xmlWeather.getElementsByTagName("URL")[0].childNodes[0].nodeValue;
	
	var atext;
	
	var curDate;
	var newDate;
	var tempHumid;
	var tempTemper;
	
	if (wf == "pic50"){ atext = "Sunny";
	}else if (wf == "pic51"){ atext = "Sunny Periods";
	}else if (wf == "pic52"){ atext = "Sunny Intervals";
	}else if (wf == "pic53"){ atext = "Sunny Periods with A Few Showers";
	}else if (wf == "pic54"){ atext = "Sunny Intervals with Showers";
	}else if (wf == "pic60"){ atext = "Cloudy";
	}else if (wf == "pic61"){ atext = "Overcast";
	}else if (wf == "pic62"){ atext = "Light Rain";
	}else if (wf == "pic63"){ atext = "Rain";
	}else if (wf == "pic64"){ atext = "Heavy Rain";
	}else if (wf == "pic65"){ atext = "Thunderstorms";
	}else if (wf == "pic70"){ atext = "Fine";
	}else if (wf == "pic71"){ atext = "Fine";
	}else if (wf == "pic72"){ atext = "Fine";
	}else if (wf == "pic73"){ atext = "Fine";
	}else if (wf == "pic74"){ atext = "Fine";
	}else if (wf == "pic75"){ atext = "Fine";	
	}else if (wf == "pic76"){ atext = "Mainly Cloudy";
	}else if (wf == "pic77"){ atext = "Mainly Fine";	
	}else if (wf == "pic80"){ atext = "Windy";
	}else if (wf == "pic81"){ atext = "Dry";
	}else if (wf == "pic82"){ atext = "Humid";
	}else if (wf == "pic83"){ atext = "Fog";
	}else if (wf == "pic84"){ atext = "Mist";
	}else if (wf == "pic85"){ atext = "Haze";
	}else if (wf == "pic90"){ atext = "Hot";	
	}else if (wf == "pic91"){ atext = "Warm";	
	}else if (wf == "pic92"){ atext = "Cool";	
	}else if (wf == "pic93"){ atext = "Cold";	
	}	
	
	curDate=dt.substring(0,10);
	newDate=curDate.substring(8,10)+"-"+curDate.substring(5,7)+"-"+curDate.substring(0,4);
	
	//document.getElementById("datentime").innerHTML=dt.substring(0,10);
	document.getElementById("datentime").innerHTML="<span class=\"weatherinfo\">" + newDate + "</span>";
	
	tempTemper = xmlWeather.getElementsByTagName("Measure")[0].childNodes[0].nodeValue ;
	tempHumid = xmlWeather.getElementsByTagName("Measure")[1].childNodes[0].nodeValue;
	
	if (tempTemper != null) {
		document.getElementById("temperature").innerHTML= "<span class=\"weatherinfo\">" + tempTemper + "<sup>o</sup>C</span>";
	}
	if (tempHumid != null) {
		document.getElementById("humidity").innerHTML= "<span class=\"weatherinfo\">Humidity " +  tempHumid  + "% </span>";
	}
	document.getElementById("weatherforecast").innerHTML="<a href=\"http://www.hko.gov.hk/contente.htm\" target=\"_blank\"><img src=\"/tc/images/home/weather_icon/" + wf + ".png\" title=\""+ atext +"\" width=\"18\" height=\"18\" border=\"0\"/></a>";

// Weather warning icon goes here
var wi;
var wiout='';
var wn;

for (var i=1;i<12;i++){
	//wn=xmlWeather.getElementsByTagName("Name")[i].childNodes[0].nodeValue;
	try
  {
	wi=xmlWeather.getElementsByTagName("URL")[i].childNodes[0].nodeValue;
	
	if (wi=="tc10"){ atext = "HURRICANE SIGNAL NO. 10";
	}else if (wi=="tc1"){ atext = "STANDBY SIGNAL NO. 1";
	}else if (wi=="tc3"){ atext = "STRONG WIND SIGNAL NO. 3";
	}else if (wi=="tc8ne"){ atext = "NO. 8 NORTHEAST GALE OR STORM SIGNAL";
	}else if (wi=="tc8nw"){ atext = "NO. 8 NORTHWEST GALE OR STORM SIGNAL";
	}else if (wi=="tc8se"){ atext = "NO. 8 SOUTHEAST GALE OR STORM SIGNAL";
	}else if (wi=="tc8sw"){ atext = "NO. 8 SOUTHWEST GALE OR STORM SIGNAL";
	}else if (wi=="tc9"){ atext = "INCREASING GALE OR STORM SIGNAL NO. 9 ";	
	}else if (wi=="raina"){ atext = "AMBER RAINSTORM WARNING SIGNAL";
	}else if (wi=="rainr"){ atext = "RED RAINSTORM WARNING SIGNAL";
	}else if (wi=="rainb"){ atext = "BLACK RAINSTORM WARNING SIGNAL";
	}else if (wi=="ts"){ atext = "THUNDERSTORM WARNING";
	}else if (wi=="ntfl"){ atext = "SPECIAL ANNOUNCEMENT ON FLOODING IN THE NORTHERN NEW TERRITORIES";
	}else if (wi=="landslip"){ atext = "LANDSLIP WARNING";
	}else if (wi=="sms"){ atext = "STRONG MONSOON SIGNAL";
	}else if (wi=="frost"){ atext = "FROST WARNING";
	}else if (wi=="firey"){ atext = "YELLOW FIRE DANGER WARNING";	
	}else if (wi=="firer"){ atext = "RED FIRE DANGER WARNING";
	}else if (wi=="cold"){ atext = "COLD WEATHER WARNING";
	}else if (wi=="vhot"){ atext = "VERY HOT WEATHER WARNING";
	}else if (wi=="tsunami-warn"){ atext = "TSUNAMI WARNING";
	}
	
	wiout+="<a href=\"http://www.hko.gov.hk/contente.htm\" target=\"_blank\"><img src=\"/tc/images/home/weather_icon/" + wi + ".gif\" title=\""+ atext +"\" width=\"18\" height=\"18\" border=\"0\"/></a>" + "&nbsp;";
  }catch(err){
  }
}

document.getElementById("warningicon").innerHTML=wiout;
//document.getElementById("temperature").innerHTML=xmlWeather.getElementsByTagName("Measure")[i].childNodes[0].nodeValue;
  //}
}