﻿function landingWhatson(firstloaded) {
	//try{
	var xml = "/xml/whatson.xml?"+ new Date().getTime();
	var xmlhttp = getXMLHTTP();	

	if (firstloaded == true)
	{
		if (xmlhttp!=null){
			xmlhttp.onreadystatechange=function (){

				if (xmlhttp.readyState==4){
					if (xmlhttp.status==200){ // 200 = "OK"
						var xmlDoc = null;
						if (window.XMLHttpRequest){ // code for IE7, Firefox, Opera, etc.
							parser = new DOMParser();
							xmlDoc = parser.parseFromString(xmlhttp.responseText, "text/xml");
						}else { // code for IE6, IE5
							xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
							xmlDoc.async = "false";
							xmlDoc.loadXML(xmlhttp.responseText);
						}
						landingWhatson2(xmlDoc);
					}
					else{
						alert("Problem retrieving XML data:" + xmlhttp.statusText);
					}
				}
			}
			xmlhttp.open("GET",xml,true);
			xmlhttp.send("");
		}else{
			alert("Your browser does not support XMLHTTP.");
		
		}
	}
	//}catch(err){alert("err:"+err)}
}


function landingWhatson2(xmlDoc){

        var objNodeType = xmlDoc.getElementsByTagName("type");
	    var objNodeDate = xmlDoc.getElementsByTagName("date");
	    var objNodeEngTitle = xmlDoc.getElementsByTagName("eng_title");
		var objNodeChiTitle = xmlDoc.getElementsByTagName("chi_title");
		var objNodeURL = xmlDoc.getElementsByTagName("url");
		var len = objNodeType.length;
		var type="Event";
		tmpStr = "";
		//highlights
		/*tmpStr +="<ul>\n";
		for (i = 0; i < 3; i++) {
			if(objNodeType[i].childNodes[0].nodeValue=="E"){
				type="Event: ";
			}else if(objNodeType[i].childNodes[0].nodeValue=="T"){
				type="Trainning: ";
			}
			tmpStr +="<li>"+type+objNodeDate[i].childNodes[0].nodeValue;
			tmpStr +="<p>"+objNodeEngTitle[i].childNodes[0].nodeValue+"</p></li>\n";
		}
		tmpStr +="</ul>\n";
		*/
		//event
		tmpStr +="<ul style=\"display: none;\">\n";
		var itemCount = 0;
		for (i = 0; i < len && itemCount<3; i++) {
/* 			alert("itemCount: " + itemCount);
			alert("objNodeType[i].childNodes[0].nodeValue: " + objNodeType[i].childNodes[0].nodeValue);
			alert("objNodeURL[i].childNodes[0].nodeValue: " + objNodeURL[i].childNodes[0].nodeValue);
			alert("objNodeDate[i].childNodes[0].nodeValue: " + objNodeDate[i].childNodes[0].nodeValue);
			alert("objNodeEngTitle[i].childNodes[0].nodeValue: " + objNodeEngTitle[i].childNodes[0].nodeValue); */
			if(objNodeType[i].childNodes[0].nodeValue=="E")
			{
				tmpStr +="<li>";
				tmpStr +="<p>";
				tmpStr += "<a ";
				if(objNodeURL[i].childNodes[0].nodeValue!="")
				{
					tmpStr += "target='_blank' href='";
					tmpStr += objNodeURL[i].childNodes[0].nodeValue;
					tmpStr += "'";
				}
				else
				{
					tmpStr += "#";
				}
				tmpStr += ">";
				tmpStr +=objNodeDate[i].childNodes[0].nodeValue + "<br/>";
				tmpStr +="<span>";
				tmpStr +=objNodeEngTitle[i].childNodes[0].nodeValue;
				tmpStr +="</span>";
				tmpStr += "</a>";

				tmpStr +="</p>";
				tmpStr +="</li>\n";
				itemCount++;
			}
		}

		tmpStr +="</ul>\n";
		//trainning
		tmpStr +="<ul style=\"display: none;\">\n";
		itemCount = 0;
		for (i = 0; i < len && itemCount<3; i++) {
			if(objNodeType[i].childNodes[0].nodeValue=="T")
			{
				tmpStr +="<li>";
				tmpStr +="<p>";
				tmpStr += "<a ";
				if(objNodeURL[i].childNodes[0].nodeValue!="")
				{
					tmpStr += "target='_blank' href='";
					tmpStr += objNodeURL[i].childNodes[0].nodeValue;
					tmpStr += "'";
				}
				else
				{
					tmpStr += "#";
				}
				tmpStr += ">";
				tmpStr +=objNodeDate[i].childNodes[0].nodeValue + "<br/>";
				tmpStr +="<span>";
				tmpStr +=objNodeEngTitle[i].childNodes[0].nodeValue;
				tmpStr +="</span>";
				tmpStr += "</a>";

				tmpStr +="</p>";
				tmpStr +="</li>\n";
				itemCount++;
			}
		}
		tmpStr +="</ul>\n";
		
/* 		alert(tmpStr);
		alert(document.getElementById("whatsonLanding").innerHTML); */
		document.getElementById("whatsonLanding").innerHTML+=tmpStr;

}
