<!--
// global flag
var isIE = false;

// global request and XML document objects
var req, lastupdateday;
var DayArray = new Array();
var MonthArray = new Array();
var YearArray = new Array();
var LinkArray = new Array();
var TitleArray = new Array();
var issueDateArray = new Array();
var bgArray =new Array();

function change_c1(input){
 var result;
 switch(input){
	case '1':
	  result = '一';
	  break;
	case '2':
	  result = '二';
	  break;
	case '3':
	  result = '三';
	  break;
	case '4':
	  result = '四';
	  break;
	case '5':
	  result = '五';
	  break;
	case '6':
	  result = '六';
	  break;
	case '7':
	  result = '七';
	  break;
	case '8':
	  result = '八';
	  break;
	case '9':
	  result = '九';
	  break;
	case '0':
	  result = '零';
	  break;
	default:
	  result = '零';
	  break;
 } 
	return result;
	
}

function change_c2(input){
 var result;
 switch(input){
	case '1':
	  result = '十';
	  break;
	case '2':
	  result = '二十';
	  break;
	case '3':
	  result = '三十';
	  break;
	case '0':
	  result = '';
	  break;
	default:
	  result = '';
	  break;
 } 
	return result;
	
}




function showlastupdate(){
var lasty, lastm, lastd;
var yyyy, mm, dd;

yyyy = YearArray[0].split("");
mm = MonthArray[0].split("");
dd = DayArray[0].split("");

lasty = change_c1(yyyy[0]) + change_c1(yyyy[1]) + change_c1(yyyy[2]) + change_c1(yyyy[3]) + '年';
lastm = (mm.length>1) ? change_c2(mm[0]) + change_c1(mm[1]) + '月' : change_c1(mm[0]) + '月';
lastd = (dd.length>1) ? change_c2(dd[0]) + change_c1(dd[1]) + '日' : change_c1(dd[0]) + '日';
lastm = (lastm=='十零月') ? '十月' : lastm;
lastd = (lastd=='十零日') ? '十日' : lastd;
lastd = (lastd=='二十零日') ? '二十日' : lastd;
lastd = (lastd=='三十零日') ? '三十日' : lastd;
lastupdateday = lasty + lastm + lastd;
//lastupdateday = lasty + mm[0]+mm[1] + lastd;
return lastupdateday;
}


function external_link(hyperlink){
	var result;
	if (hyperlink.toString().search('www.epd.gov.hk')!= -1){
		result = '&nbsp;&nbsp;';
	}else{
		result = '&nbsp;*&nbsp;';
	}
	return result;
}


function loadXMLDoc(url) {
    // branch for native XMLHttpRequest object
    //Simple way for refresh xml
	var d = new Date();
	var t = d.getTime();
	url=url+'?date='+d+'&time='+t;
	
	
	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
		
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

// handle onreadystatechange event of req object
function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            buildContent();
         } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
         }
    }
}


// retrieve text of an XML document element, including
// elements using namespaces
function getElementTextNS(prefix, local, parentElem, index) {
    var result = "";
    if (prefix && isIE) {
        // IE/Windows way of handling namespaces
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {
        result = parentElem.getElementsByTagName(local)[index];
    }
    if (result) {
        // get text, accounting for possible
        // whitespace (carriage return) text nodes 
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
            return result.firstChild.nodeValue;    		
        }
    } else {
        return "n/a";
    }
}

// fill Topics select list with items from
// the current XML document
function buildContent() {
    //var select = document.getElementById("highlights");
    var items = req.responseXML.getElementsByTagName("chiitem");
	var pubDate = '';
	var pubDateArray = '';
	var div, divupdate;
	var content = '';
	var j=0;
    //alert(items.length);
    // loop through <item> elements, and add each nested
    // <title> element to Topics select element
    for (var i = 0; i < items.length; i++) {
        //pubDate = getElementTextNS("", "pubDate", items[i], 0);
		//pubDateArray = pubDate.split(" ");
		pubDate = getElementTextNS("", "issueDate", items[i], 0);
		pubDateArray = pubDate.split(".");
		DayArray[i] = pubDateArray[0];
		MonthArray[i] = pubDateArray[1];
		YearArray[i] = pubDateArray[2];	
		issueDateArray[i] = getElementTextNS("", "issueDate", items[i], 0);
		LinkArray[i] = getElementTextNS("", "link", items[i], 0);
		TitleArray[i] = getElementTextNS("", "title", items[i], 0);
		if(i==0){
		lastupdateday = DayArray[i] + MonthArray[i] + YearArray[i];
		}
    }
    
    div = document.getElementById("pressrelease");
    divupdate = document.getElementById("lastupdate");
	div.innerHTML = ""; 
	divupdate.innerHTML = "";
	
	bgArray[0]="#ffffff";
	bgArray[1]="#fafad9";
	
		content += '<table cellspacing="0" cellpadding="5" width="557" border="0">';
	    content += '<tr valign="top">';
		content += ' <td width="100" bgcolor="#3182DE" align="center"><strong><font face="細明體" color="#ffffff" size="3">日期</font></strong></td>';
		content += '<td width="457" bgcolor="#3182DE"><strong><font face="細明體" color="#ffffff" size="3">題目</font></strong></td>';
		content += '</tr>';
     for(var i=0; i<TitleArray.length; i++){
		content += '<tr>';
		if ((TitleArray.length-i-1) % 2 == 0)
			{j=1;}
		else
			{j=0;}
		
		content += '<td nowrap="nowrap" bgcolor='+bgArray[j]+' height="29"><font face="細明體" size="3">'+issueDateArray[i]+'</font></td>';
		content += ' <td bgcolor='+bgArray[j]+' height="29"><a href="'+LinkArray[i]+'" target="_blank"><font face="細明體" size="3">'+TitleArray[i]+'</font></td>';
		content += '</tr>';
		//content +='<tr><td>&nbsp;</td><td>&nbsp;</td></tr>'
	 }	
		content += '</table>';	

	div.innerHTML = content;
	divupdate.innerHTML = '修訂日期 : ' + showlastupdate();
	
}

//-->
