var req;
var theXML;
var pageName;
var xmlobject;

function loadEsrihkXMLDoc(url, pageName){
	this.pageName = pageName;
    new Ajax(url, {method: 'get', onComplete: createDom}).request()
	
	return false;
}

function createDom(request, flag){
	// code for IE
    var xmlDoc;
    if (window.ActiveXObject){
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(request);
        
	}
	// code for Mozilla, Firefox, Opera, etc.
	else{
		// convert string to XML object
		xmlDoc = (new DOMParser()).parseFromString(request, "text/xml");
	}
	
	if (flag){
        xmlobject = xmlDoc;
        chooseFunction();
    }
    else{
        coursesInfo =xmlDoc;
    }
}


function chooseFunction(){
    	switch(pageName){
		case "index":
			showIndex();
		break;
		case "aboutus":
			showAboutEsrihk();
		break;
		case "ceoplace":
			showCEOPlace();
		break;
		case "ceoHeadline":
			showHighlights();
		break;
		case "careers":
			showCareerTitles();
		break;
		case "jobdesc":
			showJobDesc();
		break;
		case "userlink":
			genUserLink();
		break;
		case "productoverview":
			showProductNews();
		break;
		case "community":
			showCommunity();
		break;
		case "communityArchive":
			showCommunityArchive();
		break;
		case "userlinkArchive":
			showUserlinkArchive();
		break;
		case "localArchive":
			showLocalArchive();
		break;
		case "localMonArchive":
			showLocalMonArchive();
		break;
		case "industrial":
			showIndustrial();
		break;
		case "schedule":
			showSchedule();
		break;		
		case "event":
			showEventArchive();
		break;
		case "comingevent":
			showComingEvent();
		break;
		case "eventinfo":
			showEventInfo();
		break;
		case "localmaps":
			showLocalMaps();
		break;
		case "localmap":
			showLocalMap();
		break;
		case "localcases":
			showLocalCases();
		break;
		case "localcase":
			showLocalCase();
		break;
		case "productArchive":
			showProductArchive();
		break;
		case "pressbk":
			showBookList();
		break;
    		case "bookdetails":
			showBookDetails();
		break;
        case "supportUtilities":
			showSupportUtilities();
		break;
        case "supportUtilitiesInfo":
			showSupportUtilitiesInfo();
		break;
        case "training":
			showTraining();
		break;
	}
}

function showLocalCase(){
	var qId = getQueries('id');
	var localCases = xmlobject.getElementsByTagName('esrihkshowcase')[0].getElementsByTagName('case');
		
					
	for(i=0;i<localCases.length;i++){
		if (localCases[i].getAttribute('id')==qId){
			document.getElementById('title').innerHTML=localCases[i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
			document.getElementById('client').innerHTML+=localCases[i].getElementsByTagName('client')[0].childNodes[0].nodeValue;
			document.getElementById('clientLogo').src='../industries/images/'+localCases[i].getElementsByTagName('client')[0].getAttribute('logo');
			document.getElementById('clientLogo').alt=localCases[i].getElementsByTagName('client')[0].childNodes[0].nodeValue+' Logo';			
			var content = '';
			for (j=0;j<localCases[i].getElementsByTagName('desc').length;j++){
				content+='<p align="justify">'+localCases[i].getElementsByTagName('desc')[j].childNodes[0].nodeValue+'</p>';
			}
			document.getElementById('desc').innerHTML=content;
			if (localCases[i].getElementsByTagName('image').length>0){
				var table = document.createElement('table');
				var row, cell;
				for (j=0;j<localCases[i].getElementsByTagName('image').length;j++){
					if (j%2==0){
						row=table.insertRow(-1);
						cell=row.insertCell(-1);
						cell.style.padding="20px";
						cell.innerHTML='<image src="../industries/images/'+localCases[i].getElementsByTagName('image')[j].childNodes[0].nodeValue+'"/>';
					}
					else{
						cell=row.insertCell(-1);
						cell.innerHTML='<image width="200" height="150 "src="../industries/images/'+localCases[i].getElementsByTagName('image')[j].childNodes[0].nodeValue+'"/>';
					}
				}
				document.getElementById('image').appendChild(table);
			}
			
			break;
		}
	}
	
	
}

function showLocalCases(){
	var localCases = xmlobject.getElementsByTagName('esrihkshowcase')[0].getElementsByTagName('case');
	var localCasesTitle ='';
	//for(i=0;i<localCases.length;i++){
	for(i=0;i<localCases.length;i++){
		//alert(i);
		localCasesTitle+='<li><a href="../industries/localcase.html?id='+localCases[i].getAttribute('id')+'">'+localCases[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a></li>';
	}
	document.getElementById('lctitle').innerHTML=localCasesTitle;
}

function showLocalMap(){
	var qId = getQueries('id');
	var localMaps = xmlobject.getElementsByTagName('localmaps')[0].getElementsByTagName('map');
		
						
	for(i=0;i<localMaps.length;i++){
		if (localMaps[i].getAttribute('id')==qId){
			document.getElementById('title').innerHTML=localMaps[i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
			document.getElementById('shortdesc').innerHTML=localMaps[i].getElementsByTagName('shortdesc')[0].childNodes[0].nodeValue;
			document.getElementById('link').innerHTML=localMaps[i].getElementsByTagName('link')[0].getAttribute('url');
			document.getElementById('link').href=localMaps[i].getElementsByTagName('link')[0].getAttribute('url');
			document.getElementById('image').src='../industries/images/'+localMaps[i].getElementsByTagName('image')[0].childNodes[0].nodeValue;
			document.getElementById('image').alt=localMaps[i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
			break;
		}
	}
}

function showLocalMaps(){
	var localMaps = xmlobject.getElementsByTagName('localmaps')[0].getElementsByTagName('map');
	var localMapsTitle = new Array();
	for(i=0;i<localMaps.length;i++){
		localMapsTitle+='<li><a href="../industries/localmap.html?id='+localMaps[i].getAttribute('id')+'">'+localMaps[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a></li>';
	}
	document.getElementById('lmtitle').innerHTML=localMapsTitle
}

function showComingEvent(){
	
	var today = setDateObj(strToday);
	var news = xmlobject.getElementsByTagName('post');
	var comingEvent = new Array();
	/* requirement changed
		Get the comming event from the latest userlink only
		March 2008
	*/
	//for (i=0;i<news.length;i++){
		//alert(news[i].getAttribute('month'));
		i=0;
		if ((parseInt(news[i].getAttribute('month'))+parseInt(news[i].getAttribute('year'))*12)>=(today.getMonth()+today.getFullYear()*12)){
			
			for (j=0;j<news[i].getElementsByTagName('news').length;j++){
				if (news[i].getElementsByTagName('news')[j].getAttribute('type')=='comingevent'){
					//if (parseInt(news[i].getElementsByTagName('news')[j].getElementsByTagName('eventdate')[0].getElementsByTagName('start')[0].getAttribute('month'))+parseInt(news[i].getElementsByTagName('news')[j].getElementsByTagName('eventdate')[0].getElementsByTagName('start')[0].getAttribute('year')*12)>=(today.getMonth()+today.getFullYear()*12)){
						comingEvent.push(news[i].getElementsByTagName('news')[j]);
					//}
				}
			}
			if (comingEvent.length>0){
				/*var comingEventTable=document.createElement('table');
				comingEventTable.width="100%";
				//comingEventTable.className="content";
				comingEventTable.style.textAlign="left";
				var row = comingEventTable.insertRow(0);
				//row.style.fontWeight="bold";*/
				//var cell = row.insertCell(0);
				//cell.innerHTML=news[i].getAttribute('month')+' - '+ news[i].getAttribute('year')+'<br/>';
				//var cell = document.getElementById('comingEvent');
				//alert(cell);
				var list="<ul class='singleline'>";
				var target="";
				for (j=0;j<comingEvent.length;j++){
					target="_blank";
					if (comingEvent[j].getElementsByTagName('link').length==0){
						newEl=xmlobject.createElement('link');
						urlAtt=xmlobject.createAttribute('url');
						urlAtt.value='../events/comingeventinfo.html?year='+news[i].getAttribute('year')+'&month='+news[i].getAttribute('month')+'&id='+comingEvent[j].getAttribute('id');
						newEl.setAttributeNode(urlAtt);
						comingEvent[j].appendChild(newEl);
						target="";
					}
					link=comingEvent[j].getElementsByTagName('link')[0].getAttribute('url');
                    var duration=""
                    var location=""
                    
                    //if (comingEvent[j].getElementsByTagName('eventdate')[0].getElementsByTagName('start').length!=0){
                    if (comingEvent[j].getElementsByTagName('eventdate').length!=0){
                        duration=getEventDuration(comingEvent[j].getElementsByTagName('eventdate')[0])+'&nbsp;&middot;&nbsp;';
                        location=comingEvent[j].getElementsByTagName('location')[0].childNodes[0].nodeValue;
                    }
					else{
                        location=comingEvent[j].getElementsByTagName('shortdesc')[0].childNodes[0].nodeValue;
                    }
					list+='<li style="font-size: 12px; line-height: 15px; margin-bottom: 10px;"><a href="'+link+'" target="'+target+'">'+comingEvent[j].getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a><br>'+duration+location+'</li>';
				}
				list+='</ul>';
				
				
				//comingEventTable=genScheduleTable(comingEventTable,'Coming Event',true);
				//comingEventTable.width="100%";
				document.getElementById('comingEvent').innerHTML=list;
			}
		}
	//}
	
	
}

function showEventInfo(){
	var qYear = getQueries('year');
	var qMonth = getQueries('month');
	var qId = getQueries('id');
	var news = xmlobject.getElementsByTagName('esrihknews')[0].getElementsByTagName('news');
	var cePost = new Array();
	var year = new Array();
	var yearInList=false;
	var today = setDateObj(strToday);

	
	//update HTML, insert, style the row and cell in the table for coming event
	row = document.getElementById('ceTable').insertRow(-1);
	cell = row.insertCell(0);
	cell.className="content";
	
	//create array for ceInfo
	var ceInfo = new Array();
	
	//get coming event post
	for (i=news.length-1;i>=0;i--){
		
		//if(news[i].parentNode.getAttribute('month')<today.getMonth());
		if (news[i].getAttribute('type')=='comingevent'){
			ceInfo.push(news[i]);
		}
	}

	//gen Archived news if year and post index appeared in query string
	if ((qMonth!="") && (qId!="") && (qYear!="")){
		for (i=0;i<ceInfo.length;i++){
			if (ceInfo[i].getAttribute('id')==qId&&ceInfo[i].parentNode.getAttribute('month')==qMonth&&ceInfo[i].parentNode.getAttribute('year')==qYear){
				document.getElementById('subHeader').innerHTML=ceInfo[i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
				
				//cell.innerHTML=monthlyCsPost[qI][qJ].getElementsByTagName('desc')[0].childNodes[0].nodeValue;
				for (j=0;j<ceInfo[i].getElementsByTagName('desc').length;j++){
					cell.innerHTML+='<p align="justify">'+ceInfo[i].getElementsByTagName('desc')[j].childNodes[0].nodeValue+'</p>';
				}
				
				if (ceInfo[i].getElementsByTagName('image').length>0){
					var imageTable=document.createElement('table');
					for (j=0;j<ceInfo[i].getElementsByTagName('image').length;j++){
						imageTable.width="550";
						imageTable.className="content";
						var iTabRow = imageTable.insertRow(-1);
						var iTabCell = iTabRow.insertCell(0);
						var alt = "";
						var url= "";
						
						if (ceInfo[i].getElementsByTagName('image')[j].hasChildNodes()){
							alt=ceInfo[i].getElementsByTagName('image')[j].childNodes[0].nodeValue;
						}
						
						url=ceInfo[i].getElementsByTagName('image')[j].getAttribute('url');
						
						var folderName;
						if (ceInfo[i].parentNode.getAttribute('month')<10){
							folderName=ceInfo[i].parentNode.getAttribute('year')+"0"+ceInfo[i].parentNode.getAttribute('month');
						}
						else{
							folderName=ceInfo[i].parentNode.getAttribute('year')+ceInfo[i].parentNode.getAttribute('month');
						}
						
						if(url==null){
							iTabCell.innerHTML+='<img width="270" alt="'+alt+'" src="../news/images/'+folderName+'/'+ceInfo[i].getElementsByTagName('image')[j].getAttribute('file')+'">';
						}
						else{
							iTabCell.innerHTML+='<a href="'+url+'" target="_blank" ><img border="0" width="270" alt="'+alt+'" src="../news/images/'+folderName+'/'+ceInfo[i].getElementsByTagName('image')[j].getAttribute('file')+'"></a>';
						}
						iTabCell.width="270";
						iTabCell = iTabRow.insertCell(1);
						iTabCell.innerHTML+=alt;
						iTabCell.width="280";
						iTabCell.vAlign="bottom";
						iTabCell.style.textAlign="left";
						
					}
					cell.appendChild(imageTable);
				}
				cell.innerHTML+='<br/><a href="javascript:history.go(-1)">Back</a>'
				cell.style.textAlign='justify';
				break;
			}
		}
	}
	else{
		//update HTML, show selected year in Header
		document.getElementById('header').innerHTML=="Coming Event";
		//document.getElementById('subHeader').innerHTML+=qYear;
		//create layout of selected year grouped by year ordered desc
		for (i=ceInfo.length-1;i>=0;i--){
			/*if (ceInfo[i].parentNode.getAttribute('hidden')=='true'){
				continue;
			}*/
			var duration;
			if (ceInfo[i].getElementsByTagName('eventdate')[0].getElementsByTagName('end')[0]==null){
				var node = ceInfo[i].getElementsByTagName('eventdate')[0].getElementsByTagName('start')[0];
				duration= getShortMonthName(node.getAttribute('month'))+'&nbsp;'+node.getAttribute('day')+',&nbsp;'+node.getAttribute('year');
			}
			else{
				var node = ceInfo[i].getElementsByTagName('eventdate')[0];
				var startMonth = node.getElementsByTagName('start')[0].getAttribute('month');
				var endMonth = node.getElementsByTagName('end')[0].getAttribute('month');
				if (startMonth==endMonth){
					duration= getShortMonthName(node.getElementsByTagName('start')[0].getAttribute('month'))
					+'&nbsp;'+node.getElementsByTagName('start')[0].getAttribute('day')+'&nbsp;-&nbsp;'
					+node.getElementsByTagName('end')[0].getAttribute('day')+',&nbsp;'
					+node.getElementsByTagName('end')[0].getAttribute('year');
				}
				else{
					duration= getShortMonthName(node.getElementsByTagName('start')[0].getAttribute('month'))
					+'&nbsp;'+node.getElementsByTagName('start')[0].getAttribute('day')+'&nbsp;-&nbsp;'
					+getShortMonthName(node.getElementsByTagName('end')[0].getAttribute('month'))+'&nbsp;'
					+node.getElementsByTagName('end')[0].getAttribute('day')+',&nbsp;'
					+node.getElementsByTagName('end')[0].getAttribute('year');
				}
				
			}
			
			var content="";
			
			if (ceInfo[i].getElementsByTagName('link').length>0 && ceInfo[i].getElementsByTagName('desc').length==0){
				var target;
				//get url from xml if link is linked to another page
				//else
				//gen link included year and local post index in array format
				ceInfo[i].getElementsByTagName('link')[0].getAttribute('target')==null?target='':target='_blank';
				content+="<li><a href="+ceInfo[i].getElementsByTagName('link')[0].getAttribute('url')+" target="+target+">"
				+ceInfo[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+"</a><br/>";
				content+=duration+'&nbsp;&middot;&nbsp;'+ceInfo[i].getElementsByTagName('location')[0].childNodes[0].nodeValue;
				content+='</li>';
			}
			else{
				content+='<li><a href="'+location.pathname+'?year='+ceInfo[i].parentNode.getAttribute('year')+'&month='+ceInfo[i].parentNode.getAttribute('month')+'&id='+ceInfo[i].getAttribute('id')+'">'+ceInfo[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a><br/>';
				content+=duration+'&nbsp;&middot;&nbsp;'+ceInfo[i].getElementsByTagName('location')[0].childNodes[0].nodeValue;
				content+='</li>';
			}
			cell.innerHTML+="<ul class='singleline'>"+content+"</ul>";
			
		}
	}
}

function showEventArchive(){
	var qYear = getQueries('year');
	var qMonth = getQueries('month');
	var qId = getQueries('id');
	var news = xmlobject.getElementsByTagName('esrihknews')[0].getElementsByTagName('news');
	var comingEvent = new Array();
	var eventNews = new Array();
	var year = new Array();
	var yearInList=false;
	
	for (i=0;i<news.length;i++){
		if (news[i].getAttribute('type')=='eventnews' && news[i].parentNode.getAttribute('hidden')!='true'){
			for (j=0;j<year.length;j++){
				if (year[j]==news[i].parentNode.getAttribute('year')){
					yearInList=true;
					break;
				}
			}
			if (!yearInList){
				year.push(news[i].parentNode.getAttribute('year'));
			}
		}
		yearInList=false;
	}
	
	year.sort();
	//init qYear if no query string
	if (qYear==""){
		qYear=year[year.length-1];
	}
	
	//filter all news with (type = community || local) in qyear, store in lcPost[]
	for (i=0;i<news.length;i++){
		if (news[i].parentNode.getAttribute('year')==qYear){
			if (news[i].getAttribute('type')=='eventnews'){
				eventNews.push(news[i]);
			}
			else if(news[i].getAttribute('type')=='comingevent'){
				comingEvent.push(news[i]);
			}
		}
	}
	
	//create array for 12 month news
	var monthlyEventPost = new Array(12);
	//create array for each month news
	for (i=0;i<monthlyEventPost.length;i++){
		monthlyEventPost[i]=new Array();
	}
	
	//add post in arrary according its month
	for (i=eventNews.length-1;i>=0;i--){
		monthlyEventPost[eventNews[i].parentNode.getAttribute('month')-1].push(eventNews[i]);
	}
	
	
	//update HTML, add link under 'uId' object in HTML
	var list="";
	for (i=year.length-1;i>=0;i--){
		
		if (year[i]==qYear && ((qMonth=="") && (qId==""))){
			list+='<li class="selected">'+year[i]+'</li>';
		}
		else{
			list+='<li><a href="/events/events.html?year='+year[i]+'">'+year[i]+'</a></li>';
		}
	}
	document.getElementById('uId').innerHTML=list;
	
	//update HTML, insert, style the row and cell in the table for monthly news
	row = document.getElementById('eventNewsTable').insertRow(-1);
	cell = row.insertCell(0);
	cell.className="content";
	
	//gen Archived news if year and post index appeared in query string
	if ((qMonth!="") && (qId!="")){
		//change Header and subHeader
		document.getElementById('header').innerHTML+=' - <span style="font-size:x-small">'+getLongMonthName(qMonth)+' '+qYear+'</span>';
		for (i=0;i<monthlyEventPost[qMonth-1].length;i++){
			if (monthlyEventPost[qMonth-1][i].getAttribute('id')==qId){
				document.getElementById('subHeader').innerHTML=monthlyEventPost[qMonth-1][i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
				var content="";
				for (j=0;j<monthlyEventPost[qMonth-1][i].getElementsByTagName('desc').length;j++){
					content+='<p align="justify">'+monthlyEventPost[qMonth-1][i].getElementsByTagName('desc')[j].childNodes[0].nodeValue;+'</p>'
				}
				cell.innerHTML=content;
				if(monthlyEventPost[qMonth-1][i].getElementsByTagName('sub').length>0){
					//var list=document.createElement('ul');
					for (j=0;j<monthlyEventPost[qMonth-1][i].getElementsByTagName('sub').length;j++){
						cell.appendChild(getLink(monthlyEventPost[qMonth-1][i].getElementsByTagName('sub')[j]));
						cell.innerHTML+='<br/>';
					}
					
				}
				
				if (monthlyEventPost[qMonth-1][i].getElementsByTagName('other').length>0){
					for (j=0;j<monthlyEventPost[qMonth-1][i].getElementsByTagName('other').length;j++){
						
						if (monthlyEventPost[qMonth-1][i].getElementsByTagName('other')[j].getAttribute('target')==null){
							target="";
						}
						else{
							target=monthlyEventPost[qMonth-1][i].getElementsByTagName('other')[j].getAttribute('target');
						}
						var folderName;
						if (monthlyEventPost[qMonth-1][i].parentNode.getAttribute('month')<10){
							folderName=monthlyEventPost[qMonth-1][i].parentNode.getAttribute('year')+"0"+monthlyEventPost[qMonth-1][i].parentNode.getAttribute('month');
						}
						else{
							folderName=monthlyEventPost[qMonth-1][i].parentNode.getAttribute('year')+monthlyEventPost[qMonth-1][i].parentNode.getAttribute('month');
						}
						cell.innerHTML+='<a href=../news/others/'+monthlyEventPost[qMonth-1][i].parentNode.getAttribute('year')+monthlyEventPost[qMonth-1][i].parentNode.getAttribute('month')+'/'+monthlyEventPost[qMonth-1][i].getElementsByTagName('other')[j].getAttribute('file')+' target="'+target+'">'+monthlyEventPost[qMonth-1][i].getElementsByTagName('other')[j].childNodes[0].nodeValue+'</a><br/><br/>';
						
					}
					
				}
				
				if (monthlyEventPost[qMonth-1][i].getElementsByTagName('image').length>0){
					var imageTable=document.createElement('table');
					for (j=0;j<monthlyEventPost[qMonth-1][i].getElementsByTagName('image').length;j++){
						imageTable.width="550";
						imageTable.className="content";
						var iTabRow = imageTable.insertRow(-1);
						var iTabCell = iTabRow.insertCell(0);
						var alt ="";
                        var desc ="";
						var url="";
						
						if (monthlyEventPost[qMonth-1][i].getElementsByTagName('image')[j].hasChildNodes()){
							desc=monthlyEventPost[qMonth-1][i].getElementsByTagName('image')[j].childNodes[0].nodeValue;
                            //alt=desc.replace(/<br\/>/g,"&#013;");
						}
						url=monthlyEventPost[qMonth-1][i].getElementsByTagName('image')[j].getAttribute('url');
						var folderName;
						if (monthlyEventPost[qMonth-1][i].parentNode.getAttribute('month')<10){
							folderName=monthlyEventPost[qMonth-1][i].parentNode.getAttribute('year')+"0"+monthlyEventPost[qMonth-1][i].parentNode.getAttribute('month');
						}
						else{
							folderName=monthlyEventPost[qMonth-1][i].parentNode.getAttribute('year')+monthlyEventPost[qMonth-1][i].parentNode.getAttribute('month');
						}
						if(url==null){
							iTabCell.innerHTML+='<img width="270" alt="'+alt+' "src="../news/images/'+folderName+'/'+monthlyEventPost[qMonth-1][i].getElementsByTagName('image')[j].getAttribute('file')+'">';
						}
						else{
							iTabCell.innerHTML+='<a href="'+url+'" target="_blank" ><img border="0" width="270" alt="'+alt+' "src="../news/images/'+folderName+'/'+monthlyEventPost[qMonth-1][i].getElementsByTagName('image')[j].getAttribute('file')+'"></a>';
						}
						iTabCell.width="270";
						iTabCell = iTabRow.insertCell(1);
						iTabCell.innerHTML+=desc;
						iTabCell.width="280";
						iTabCell.vAlign="bottom";
						iTabCell.style.textAlign="left";
						
					}
					cell.appendChild(imageTable);
				}
				
				cell.innerHTML+='<br/><br/><a href="javascript:history.go(-1)">Back</a>'
				cell.style.textAlign='justify';
			}
		}
	}
	else{
		//update HTML, show selected year in Header
		document.getElementById('header').innerHTML='Event News';
		document.getElementById('subHeader').innerHTML+=qYear;
		//create layout of selected year grouped by year ordered desc
		for (i=monthlyEventPost.length-1;i>=0;i--){
			if (monthlyEventPost[i].length!=0){
				if (monthlyEventPost[i][0].parentNode.getAttribute('hidden')=='true'){
					continue;
				}
				var content="";
				for (j=monthlyEventPost[i].length-1;j>=0;j--){
					var target;
					//get url from xml if link is linked to another page
					//else
					//gen link included year and local post index in array format
					if (monthlyEventPost[i][j].getElementsByTagName('link').length>0){
						monthlyEventPost[i][j].getElementsByTagName('link')[0].getAttribute('target')==null?target='':target='_blank';
						content+="<li><a href="+monthlyEventPost[i][j].getElementsByTagName('link')[0].getAttribute('url')+" target="+target+">"
						+monthlyEventPost[i][j].getElementsByTagName('title')[0].childNodes[0].nodeValue+"</a></li>";
					}
					else{
						content+='<li><a href="'+location.pathname+'?year='+qYear+'&month='+monthlyEventPost[i][j].parentNode.getAttribute('month')+'&id='+monthlyEventPost[i][j].getAttribute('id')+'">'+monthlyEventPost[i][j].getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a></li>';
					}
				}
				cell.innerHTML+=getLongMonthName((i+1).toString())+"<ul class='singleline'>"+content+"</ul>";
			}
		}
	}
}

function getLink(node){
	var year,month,id,type;
	
	node.getAttribute('type')==null?type=node.parentNode.getAttribute('type'):type=node.getAttribute('type');
	node.getAttribute('year')==null?year=node.parentNode.parentNode.getAttribute('year'):year=node.getAttribute('year');
	node.getAttribute('month')==null?month=node.parentNode.parentNode.getAttribute('month'):month=node.getAttribute('month');
	
	if (year==null){
		year=node.parentNode.getAttribute('year');
	}
	if (month==null){
		month=node.parentNode.getAttribute('month');
	}
	id = node.getAttribute('id');
	
	var path='../';
	
	if (type=="eventnews"){
		path+='events/events.html?year='+year+'&month='+month+'&id='+id;
	}
	else if (type=="community"){
		path+='news/communityArchive.html?year='+year+'&month='+month+'&id='+id;
	}
	else if (type=="local"){
		path+='news/localNewsArchive.html?year='+year+'&month='+month+'&id='+id;
	}
	else if (type=="product"){
		path+='news/productsArchive.html?year='+year+'&month='+month+'&id='+id;
	}
				
	link=document.createElement('a');
	var href = document.createAttribute('href');
	href.value=path;
	link.setAttributeNode(href);
	post=xmlobject.getElementsByTagName('post');
		
	for (var i=0;i<post.length;i++){
		if (post[i].getAttribute('month')==month && post[i].getAttribute('year')==year){
			news = post[i].getElementsByTagName('news')
			for(var j=0;j<news.length;j++){
				if (news[j].getAttribute('id')==id){
					link.innerHTML=news[j].getElementsByTagName('title')[0].childNodes[0].nodeValue;
					break;
				}
			}
		}
	}
	return link;
}

function showSchedule(){
	var today = setDateObj(strToday);
	var duration;
	var courseInfoTab;
	var schedule = xmlobject.getElementsByTagName('training')[0].getElementsByTagName('schedule');
	var coursesDesc = xmlobject.getElementsByTagName('coursesDesc')[0];
    
	for (i=0;i<schedule.length;i++){
		
		if ((parseInt(schedule[i].getAttribute('month'))+parseInt(schedule[i].getAttribute('year'))*12)>(today.getMonth()+today.getFullYear()*12)){
			var courseInfoTab=document.createElement('table');
			courseInfoTab.width="100%";
			courseInfoTab.className="content";
			courseInfoTab.style.textAlign="left";
			var row = courseInfoTab.insertRow(0);
			row.style.fontWeight="bold";
			
			var cell = row.insertCell(0);
			cell.innerHTML+="Date";
			cell.width='20%';
			cell = row.insertCell(1);
			cell.width='50%';
			cell.innerHTML+="Topic";
			cell = row.insertCell(2);
			cell.innerHTML+="Fee(HKD)";
			cell.width='18%';
			cell = row.insertCell(3);
			cell.innerHTML+="&nbsp;";
			cell.width='12%';
			
            
			courses = schedule[i].getElementsByTagName('course');

                
			for (j=0;j<courses.length;j++){
                for (k=0; k<coursesDesc.childNodes.length; k++){
                    //alert(coursesDesc.childNodes[k+1].nodeName);
                    if (coursesDesc.childNodes[k].nodeName!="#text"){
                        if (courses[j].getAttribute('code')==coursesDesc.childNodes[k].getAttribute('code')){
                            //get the course date
                            var node = courses[j].getElementsByTagName('date')[0];
                            var startMonth = node.getElementsByTagName('start')[0].getAttribute('month');
                            var endMonth = node.getElementsByTagName('end')[0].getAttribute('month');
                            if (startMonth==endMonth){
                                courseDate= getShortMonthName(node.getElementsByTagName('start')[0].getAttribute('month'))
                                +' '+node.getElementsByTagName('start')[0].getAttribute('day')+' - '
                                +node.getElementsByTagName('end')[0].getAttribute('day');
                            }
                            else{
                                courseDate= getShortMonthName(node.getElementsByTagName('start')[0].getAttribute('month'))
                                +' '+node.getElementsByTagName('start')[0].getAttribute('day')+' - '
                                +getShortMonthName(node.getElementsByTagName('end')[0].getAttribute('month'))+' '
                                +node.getElementsByTagName('end')[0].getAttribute('day');
                            }
							if (coursesDesc.childNodes[k].getElementsByTagName('link')[0].getAttribute('url').substring(0, 4) == "http")
								coursePDF=coursesDesc.childNodes[k].getElementsByTagName('link')[0].getAttribute('url');		
							else
								coursePDF=coursesDesc.childNodes[k].nodeName+"/"+coursesDesc.childNodes[k].getElementsByTagName('link')[0].getAttribute('url');
                            
							
                            coursePDF=coursePDF.replace(/ /gi,'%20');
                            target=coursesDesc.childNodes[k].getElementsByTagName('link')[0].getAttribute('target');
                            courseName=coursesDesc.childNodes[k].getElementsByTagName('topic')[0].childNodes[0].nodeValue;
                            courseDuration=coursesDesc.childNodes[k].getElementsByTagName('duration')[0].childNodes[0].nodeValue;
                            
                    
                            courseLink="<a href="+coursePDF+" target='"+target+"'>"+courseName+"</a>";
                            
                            //framework of email
                            title='Email Registration';
                            body='Thank you for your interest in our training courses. Please provide the following information and we will contact you with further information.%0A%0A';
                            body+='Course: '+ coursesDesc.childNodes[k].getElementsByTagName('topic')[0].childNodes[0].nodeValue+' on '+ courseDate +'%0A%0A';
                            body+='Name:%0A';
                            body+='Organization:%0A';
                            body+='Contact Email:%0A';
                            body+='Telephone no.:%0A';
                            body+='%0A%0AShould you have any queries, feel free to contact us at 2730 6883.';
                            
                            title=title.replace(/ /gi,"%20");
                            body=body.replace(/ /gi,"%20");
                            
                            
                            //insert course to table row
                            row = courseInfoTab.insertRow(-1);
                            row.insertCell(0).innerHTML=courseDate;
                            row.insertCell(1).innerHTML=courseLink;
                            row.insertCell(2).innerHTML="$"+courseDuration*3000;
							if (courses[j].getElementsByTagName('status')[0].childNodes[0].nodeValue =="Registration"){
							//alert(parseInt(node.getElementsByTagName('start')[0].getAttribute('day'))+" "+parseInt(schedule[i].getAttribute('month'))+" "+parseInt(schedule[i].getAttribute('year')));
							//alert(today.getDay()+" "+today.getMonth()+" "+today.getFullYear());
									var trainingDay = new Date();
									trainingDay.setDate(parseInt(node.getElementsByTagName('start')[0].getAttribute('day')));
									trainingDay.setMonth(parseInt(schedule[i].getAttribute('month'))-1);
									trainingDay.setYear(parseInt(schedule[i].getAttribute('year')));
									

									//if ((parseInt(node.getElementsByTagName('start')[0].getAttribute('day'))+parseInt(schedule[i].getAttribute('month'))*30+parseInt(schedule[i].getAttribute('year'))*12)<=(today.getDay()+(today.getMonth()+1)*30+today.getFullYear()*12)){
									if (trainingDay.getTime()<=today.getTime()){
										row.insertCell(3).innerHTML="Closed";
									}
									else{

									row.insertCell(3).innerHTML='<a href="mailto:sales@esrichina-hk.com?subject='+title+'&body='+body+'">'+courses[j].getElementsByTagName('status')[0].childNodes[0].nodeValue+'</a>';
									}
									}

							else{
								row.insertCell(3).innerHTML=courses[j].getElementsByTagName('status')[0].childNodes[0].nodeValue;
							}
                            
//                            row.insertCell(3).innerHTML="registration"+j+i;
                        }
                    }
                }
				
				
               
                /*
				coursePDF=courses[j].getElementsByTagName('link')[0].getAttribute('url');
				coursePDF=coursePDF.replace(/ /gi,'%20');
				row = courseInfoTab.insertRow(-1);
				courseName="<a href="+coursePDF+
				" target='"+courses[j].getElementsByTagName('link')[0].getAttribute('target')+"'>"
				+courses[j].getElementsByTagName('topic')[0].childNodes[0].nodeValue+"</a>";
				row.insertCell(0).innerHTML=duration;
				row.insertCell(1).innerHTML=courseName;
				row.insertCell(2).innerHTML=courses[j].getElementsByTagName('fee')[0].childNodes[0].nodeValue;
				if (courses[j].getElementsByTagName('status')[0].childNodes[0].nodeValue =='Available'){
					title='Email Registration';
					//body='Applying training course '+courses[j].getElementsByTagName('topic')[0].childNodes[0].nodeValue+' dated on '+duration;
					body='Thank you for your interest in our training courses. Please provide the following information and we will contact you with further information.%0A%0A';
					body+='Course:'+ courses[j].getElementsByTagName('topic')[0].childNodes[0].nodeValue+' on '+ duration +'%0A';
					body+='Name:%0A';
					body+='Organization:%0A';
					body+='Contact Email:%0A';
					body+='Telephone no.:%0A';
					body+='%0A%0AShould you have any queries, feel free to contact us at 2730 6883.';
					//alert(body);
					title=title.replace(/ /gi,"%20");
					body=body.replace(/ /gi,"%20");
					row.insertCell(3).innerHTML='<a href="mailto:csd@esrichina-hk.com?subject='+title+'&body='+body+'">'+courses[j].getElementsByTagName('status')[0].childNodes[0].nodeValue+'</a>';
				}
				else{
					row.insertCell(3).innerHTML=courses[j].getElementsByTagName('status')[0].childNodes[0].nodeValue;
				}*/
			}
			courseTable=genScheduleTable(courseInfoTab,'Training Classes Schedule - '+getLongMonthName(schedule[i].getAttribute('month'))+' '+schedule[i].getAttribute('year'),true);
			courseTable.width="100%";
			document.getElementById('trainingSchedule').appendChild(courseTable);
		}

	}
}

function genScheduleTable(news, tableName, custom, rightHeaderLink){
	var content="<ul style='margin-left:10px'>";
	if (custom){
		content=news;
	}
	else{
		for (i=0;i<news.length;i++){
			content+='<li style=font-size:12px;line-height:15px><a href="'
			+news[i].getElementsByTagName('link')[0].getAttribute('url')+'">'
			+news[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+
			'</a><br/>'+news[i].getElementsByTagName('desc')[0].childNodes[0].nodeValue+'</li>';
		}
		content+="</ul>"
	}
	
	var table = document.createElement('table');
	table.width="560";
	table.cellSpacing="0";
	//font-size: 1em; border: 1px solid #D5CDB7; margin-top:10px;" >
	table.style.fontSize="13px";
	table.style.border="1px";
	table.style.borderStyle="solid";
	table.style.borderColor="#d5cdb7";
	table.style.marginTop="10px";
	//table.class="containerTable";
    row = table.insertRow(0);
	row.style.backgroundColor="#f4efe0";
	row.style.borderBottom="1px";
	row.style.borderBottomStyle="solid";
	row.style.borderBottomColor="#d5cdb7";
	row.style.color="#1f67a2";
	row.style.fontSize="12px";
	row.style.fontWeight="bold";
	row.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";
	
	cell = row.insertCell(0);
	cell.innerHTML+=tableName;
	cell.style.paddingLeft="10px";
	cell.style.paddingRight="10px";
	cell.style.paddingTop="5px";
	cell.style.paddingBottom="5px";

	
	cell = row.insertCell(1);
	if (rightHeaderLink!=null){
		cell.innerHTML+='<a href="'+rightHeaderLink+'">more</a>';
	}
	cell.style.textAlign="right";
	cell.style.paddingLeft="10px";
	cell.style.paddingRight="10px";
	cell.style.paddingTop="5px";
	cell.style.paddingBottom="5px";
	
	row = table.insertRow(1);
	cell = row.insertCell(0);
	cell.appendChild(content);
	cell.style.textAlign="justify";
	cell.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";
	cell.style.fontSize="1em";
	cell.style.paddingLeft="5px";
	cell.style.paddingRight="5px";
	cell.style.paddingTop="10px";
	cell.style.paddingBottom="5px";
	cell.colSpan="2";
	/*cell = row.insertCell(1);
	cell.width="150";
	cell.innerHTML="150 width jpeg";
	cell.align="right";
	cell.vAlign="top";*/
	
	return table
}

function showTraining(){
    var coursesDesc = xmlobject.getElementsByTagName('coursesDesc')[0];
    var course = new Array();
    
    for (i=0; i<coursesDesc.childNodes.length; i++){
        var haveCat=false;
        for (j=0; j<course.length;j++){
            if (course[j][0]==coursesDesc.childNodes[i].nodeName){
                course[j].push(coursesDesc.childNodes[i]);
                haveCat=true;
                break;
            }
        }
        if (!haveCat && coursesDesc.childNodes[i].nodeName!="#text"){
            course.push(new Array());
            course[course.length-1][0]=coursesDesc.childNodes[i].nodeName;
            course[course.length-1].push(coursesDesc.childNodes[i]);
        }
    }
    
    for (i=0; i<course.length; i++){
        var courseInfoTab=document.createElement('table');
		courseInfoTab.width="100%";
		courseInfoTab.className="content";
		courseInfoTab.style.textAlign="left";
			
        for (j=1; j<course[i].length; j++){
            //insert course to table row
            var row = courseInfoTab.insertRow(-1);
            
            var coursePDF = "";
            if (course[i][j].getElementsByTagName('link')[0].getAttribute('url').substring(0, 4) == "http")
                coursePDF=course[i][j].getElementsByTagName('link')[0].getAttribute('url');
            else
                coursePDF=course[i][j].nodeName+"/"+course[i][j].getElementsByTagName('link')[0].getAttribute('url');
            coursePDF=coursePDF.replace(/ /gi,'%20');
            
            var target=course[i][j].getElementsByTagName('link')[0].getAttribute('target');
            
            var courseName=course[i][j].getElementsByTagName('topic')[0].childNodes[0].nodeValue;
            
            var courseLink="<a href="+coursePDF+" target='"+target+"'>"+courseName+"</a>";
            
            row.insertCell(0).innerHTML=courseLink;
        }
        courseTable=genScheduleTable(courseInfoTab,course[i][0],true);
		courseTable.width="100%";
		document.getElementById('trainingCourses').appendChild(courseTable);
    }
}

function showIndustrial(){
	//var iNewsletters = xmlobject.getElementsByTagName('industrialnewsletter');
	var iNewsletters = new Array();
	iNewsletters.push(xmlobject.getElementsByTagName('industrialnewsletter')[0].getElementsByTagName('bustelecom'));
	iNewsletters.push(xmlobject.getElementsByTagName('industrialnewsletter')[0].getElementsByTagName('education'));
	iNewsletters.push(xmlobject.getElementsByTagName('industrialnewsletter')[0].getElementsByTagName('govsafteyhealth'));
	iNewsletters.push(xmlobject.getElementsByTagName('industrialnewsletter')[0].getElementsByTagName('environmentnaturalres'));
	iNewsletters.push(xmlobject.getElementsByTagName('industrialnewsletter')[0].getElementsByTagName('utilities'));
	var title= new Array();
	title.push('Business and Telecommunications');
	title.push('Education');
	title.push('Goverment, Saftey & Health Care');
	title.push('Environment & Natural Resources');
	title.push('Utilities');

	
	/*var business = new Array;
	var telecom = new Array;
	
	/*for (i=0;i<bustelecom.length;i++){
		if ((bustelecom[i].getAttribute('type')).toLowerCase()=='business'){
			business.push(bustelecom[i]);
		}
		else{
			telecom.push(bustelecom[i]);
		}
	}
	
	var businessContent = "<h3 style='margin:0px;font-size:x-small;font-weight:700'>Business</h3><ul style='margin-left:30px'>";
	for (i=0;i<business.length;i++){
		var link="<ul  class='singleline' style='margin-top:0px;list-style-type:circle'>";
		for (j=0;j<business[i].getElementsByTagName('link').length;j++){
			link +="<li><a href='"+business[i].getElementsByTagName('link')[j].getAttribute('url')+"'>"+
			business[i].getElementsByTagName('link')[j].childNodes[0].nodeValue+"</a></li>"
		}
		link+="</ul>";
		businessContent+="<li><h4 style='margin:0px;font-weight:600'>"+business[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+
		"</h4>"+business[i].getElementsByTagName('desc')[0].childNodes[0].nodeValue+"</li>"+link;
	}
	businessContent+='</ul>';*/
	
	/*var content = "";
	for (i=0;i<bustelecom.length;i++){
		var link="<ul  class='singleline' style='margin-top:0px;list-style-type:circle'>";
		for (j=0;j<bustelecom[i].getElementsByTagName('link').length;j++){
			link +="<li><a href='"+bustelecom[i].getElementsByTagName('link')[j].getAttribute('url')+"'>"+
			bustelecom[i].getElementsByTagName('link')[j].childNodes[0].nodeValue+"</a></li>"
		}
		link+="</ul>";
		content+="<li><span style='margin-left:0px;font-weight:600'>"+bustelecom[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+
		"</span><br/><div style='margin-left:15px'>"+bustelecom[i].getElementsByTagName('desc')[0].childNodes[0].nodeValue+"</div></li>"+link;
	}
	content+='</ul>';*/
	
	var content;
	
	for (i=0;i<iNewsletters.length;i++){
		content = ""
		for (j=0;j<iNewsletters[i].length;j++){
			var link="<ul  class='singleline' style='margin-top:0px;list-style-type:circle'>";
			for (k=0;k<iNewsletters[i][j].getElementsByTagName('link').length;k++){
				link +="<li><a href='"+iNewsletters[i][j].getElementsByTagName('link')[k].getAttribute('url')+"'>"+
				iNewsletters[i][j].getElementsByTagName('link')[k].childNodes[0].nodeValue+"</a></li>"
			}
			link+="</ul>";
			content+="<li><span style='margin-left:0px;font-weight:600'>"+iNewsletters[i][j].getElementsByTagName('title')[0].childNodes[0].nodeValue+
			"</span><br/><div style='margin-left:15px'>"+iNewsletters[i][j].getElementsByTagName('desc')[0].childNodes[0].nodeValue+"</div></li>"+link;
		}
		content+='</ul>';
		document.getElementById('industrialContent').appendChild(genNewsTable(content,title[i],true));
	}
	/*document.getElementById('industrialContent').appendChild(genNewsTable(education,'Education'));
	document.getElementById('industrialContent').appendChild(genNewsTable(govsafteyhealth,'Goverment, Saftey & Health Care'));
	document.getElementById('industrialContent').appendChild(genNewsTable(environmentnaturalres,'Environment & Natural Resources'));
	document.getElementById('industrialContent').appendChild(genNewsTable(utilities,'Utilities'));*/
	
}

function showLocal(){
	
	var lcPost = showCommunity(year);

	document.getElementById('year').innerHTML+=year;
	row = document.getElementById('csTable').insertRow(i);
	cell = row.insertCell(0);
	cell.className="content";
	
	var monthlyCsPost = new Array(12);
	for (i=0;i<monthlyCsPost.length;i++){
		monthlyCsPost[i]=new Array();
	}

	for (i=0;i<csPost.length;i++){
		monthlyCsPost[csPost[i].parentNode.getAttribute('month')-1].push(csPost[i]);
	}
	
	for (i=monthlyCsPost.length-1;i>=0;i--){
		if (monthlyCsPost[i].length!=0){
			var content="";
			for (j=0;j<monthlyCsPost[i].length;j++){
				var target;
				monthlyCsPost[i][j].getElementsByTagName('link')[0].getAttribute('target')==null?target='':target='_blank';
				content+="<li><a href="+monthlyCsPost[i][j].getElementsByTagName('link')[0].getAttribute('url')+" target="+target+">"
				+monthlyCsPost[i][j].getElementsByTagName('title')[0].childNodes[0].nodeValue+"</a></li>";
			}
			
			cell.innerHTML+=getLongMonthName((i+1).toString())+"<ul class='singleline'>"+content+"</ul>";
		}
	}
}

function showLocalArchive(){
	var qYear = getQueries('year');
	var qMonth = getQueries('month');
	var qId = getQueries('id');
	var news = xmlobject.getElementsByTagName('esrihknews')[0].getElementsByTagName('news');
	var lcPost = new Array();
	var year = new Array();
	var yearInList=false;
	
	//create entery for local news, get year of news in xml if not is hidden
	for (i=0;i<news.length;i++){
		//by requested,  hidden 2006 link, 23/4/2008
		if (news[i].parentNode.getAttribute('year')=="2006"){
			continue;;
		}
		if (news[i].getAttribute('type')=='local' && news[i].parentNode.getAttribute('hidden')!='true'){
			for (j=0;j<year.length;j++){
				if (year[j]==news[i].parentNode.getAttribute('year')){
					yearInList=true;
					break;
				}
			}
			if (!yearInList){
				year.push(news[i].parentNode.getAttribute('year'));
			}
		}
		yearInList=false;
	}
	
	year.sort();
	//init qYear if no query string
	if (qYear==""){
		qYear=year[year.length-1];
	}

	//filter all news with (type = community || local) in qyear, store in lcPost[]
	for (i=0;i<news.length;i++){
		if (news[i].getAttribute('type')=='local'&&news[i].parentNode.getAttribute('year')==qYear){
			lcPost.push(news[i]);
		}
	}
	

	//update HTML, insert, style the row and cell in the table for monthly news
	row = document.getElementById('localNewsTable').insertRow(-1);
	cell = row.insertCell(0);
	cell.className="content";
	
	//create array for 12 month news
	var monthlyLocalPost = new Array(12);
	//create array for each month news
	for (i=0;i<monthlyLocalPost.length;i++){
		monthlyLocalPost[i]=new Array();
	}
	
	//add post in arrary according its month
	for (i=lcPost.length-1;i>=0;i--){
		monthlyLocalPost[lcPost[i].parentNode.getAttribute('month')-1].push(lcPost[i]);
	}
	
	//update HTML, add link under 'uId' object in HTML
	var list="";
	for (i=year.length-1;i>=0;i--){
		if (year[i]==qYear){
			list+='<li class="selected">'+year[i]+'</li>';
		}
		else{
			list+='<li><a href="/news/localNewsArchive.html?year='+year[i]+'">'+year[i]+'</a></li>';
		}
		
		if (year[i]==qYear && ((qMonth!="") || (qId!=""))){
			//list+='<li><a href="/news/localNewsArchive.html?year='+year[i]+'">'+year[i]+'</a>';
			list+="<ul  class='singleline'>";
			for (j=monthlyLocalPost.length-1;j>=0;j--){
				if (monthlyLocalPost[j].length!=0){
					if (monthlyLocalPost[j][0].parentNode.getAttribute('hidden')=='true'){
						continue;
					}
					if (monthlyLocalPost[j][0].parentNode.getAttribute('month')==qMonth && qId==""){
						list+="<li class='selected'>"+getShortMonthName((j+1).toString())+"</li>";
					}
					else{
						list+="<li><a name='"+qYear+(j+1)+"' href='"+location.pathname+"?year="+qYear+"&month="+(j+1)+"'>"+getShortMonthName((j+1).toString())+"</a></li>";
					}
				}
			}
			list+="</ul></li>";
			//list+=newsTitle+"</li>";
		}
	}
	document.getElementById('uId').innerHTML=list;
	
	
	if ((qMonth=="") && (qId=="")){
		document.getElementById('subHeader').innerHTML+=qYear;
		var newsTitle="<ul  class='singleline'>";
		for (i=monthlyLocalPost.length-1;i>=0;i--){
			if (monthlyLocalPost[i].length!=0){
				if (monthlyLocalPost[i][0].parentNode.getAttribute('hidden')=='true'){
					continue;
				}
				newsTitle+='<li><a name="'+qYear+(i+1)+'" href="'+location.pathname+'?year='+qYear+'&month='+(i+1)+'">'+getLongMonthName((i+1).toString())+'</a></li>';			
			}
		}
		newsTitle+="</ul>";
		cell.innerHTML+=newsTitle;
	}
	else if ((qMonth!="") && (qId=="")){
		//update HTML, show selected year in Header
		document.getElementById('header').innerHTML='Local News';
		document.getElementById('subHeader').innerHTML+=qYear;
		//create layout of selected year grouped by year ordered desc
		/*for (i=monthlyLocalPost.length-1;i>=0;i--){
			if (monthlyLocalPost[i].length!=0){
				if (monthlyLocalPost[i][0].parentNode.getAttribute('hidden')=='true'){
					continue;
				}*/
				//show selected month local news only
				i=qMonth-1;
				var content="";
				//generate url for each month with selected year
				for (j=monthlyLocalPost[i].length-1;j>=0;j--){
					var target;
					//get url from xml if link is linked to another page
					//else
					//gen link included year and local post index in array format
					if (monthlyLocalPost[i][j].getElementsByTagName('link').length>0){
						monthlyLocalPost[i][j].getElementsByTagName('link')[0].getAttribute('target')==null?target='':target='_blank';
						content+="<li><a href="+monthlyLocalPost[i][j].getElementsByTagName('link')[0].getAttribute('url')+" target="+target+">"
						+monthlyLocalPost[i][j].getElementsByTagName('title')[0].childNodes[0].nodeValue+"</a></li>";
					}
					else{
						month=monthlyLocalPost[i][j].parentNode.getAttribute('month');
						id=monthlyLocalPost[i][j].getAttribute('id');
						content+='<li><a name="'+qYear+month+id+'" href="'+location.pathname+'?year='+qYear+'&month='+month+'&id='+id+'">'+monthlyLocalPost[i][j].getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a></li>';
					}
				}
				cell.innerHTML+=getLongMonthName((i+1).toString())+"<ul class='singleline'>"+content+"</ul>";
			//}
		//}
	}
	//gen Archived news if month and post index appeared in query string
	else if ((qMonth!="") && (qId!="")){
		var alt="";
		var previousNews=-1;
		var nextNews=-1;
		//change Header and subHeader
		document.getElementById('header').innerHTML+=' - <span style="font-size:x-small">'+getLongMonthName(qMonth)+' '+qYear+'</span>';
		
		for (i=0;i<monthlyLocalPost[qMonth-1].length;i++){
			if (monthlyLocalPost[qMonth-1][i].getAttribute('id')==qId){
				var folderName;
				
				//get next and prvious news for navigation
				if (i>0&&i<monthlyLocalPost[qMonth-1].length-1){
					previousNews = monthlyLocalPost[qMonth-1][i+1].getAttribute('id');
					nextNews = monthlyLocalPost[qMonth-1][i-1].getAttribute('id');
				}
				else if (i==0 && monthlyLocalPost[qMonth-1].length>1){
					previousNews = monthlyLocalPost[qMonth-1][i+1].getAttribute('id');
				}
				else if (i==monthlyLocalPost[qMonth-1].length-1 && monthlyLocalPost[qMonth-1].length>1){
					nextNews = monthlyLocalPost[qMonth-1][i-1].getAttribute('id');
				}
				
				//gen folder name for images / others
				if (monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('month')<10){
					folderName=monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('year')+"0"+monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('month');
				}
				else{
					folderName=monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('year')+monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('month');
				}
				//init subheader
				document.getElementById('subHeader').innerHTML=""
				
				// show press release if pressRelease node appear
				if (monthlyLocalPost[qMonth-1][i].getElementsByTagName('pressRelease').length>0){
					node=monthlyLocalPost[qMonth-1][i].getElementsByTagName('pressRelease')[0];
					alt=node.childNodes[0].nodeValue;
					width=node.getAttribute('width');
					document.getElementById('subHeader').innerHTML+="<div style='color:#106798;padding-bottom:10px;'>"+node.childNodes[0].nodeValue+"</div><div style='padding-bottom:30px;color:#000000;font-size:80%;'>"+node.getAttribute("date")+"</div>";
				}
				
				// show banner if banner node appear
				if (monthlyLocalPost[qMonth-1][i].getElementsByTagName('banner').length>0){
					node=monthlyLocalPost[qMonth-1][i].getElementsByTagName('banner')[0];
					alt=node.childNodes[0].nodeValue;
					width=node.getAttribute('width');
					document.getElementById('subHeader').innerHTML+="<img width='"+width+"' alt='"+alt+"' src='../news/images/"+folderName+"/"+node.getAttribute('file')+"'><br>";
				}
				
				document.getElementById('subHeader').innerHTML+=monthlyLocalPost[qMonth-1][i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
				
				for (j=0;j<monthlyLocalPost[qMonth-1][i].getElementsByTagName('desc').length;j++){
					cell.innerHTML+='<p style="text-align:justify;text-justify:inter-ideograph;">'+monthlyLocalPost[qMonth-1][i].getElementsByTagName('desc')[j].childNodes[0].nodeValue+'</p>';
				}     
          if (monthlyLocalPost[qMonth-1][i].getElementsByTagName('link').length>0){
              var filename =  monthlyLocalPost[qMonth-1][i].getElementsByTagName('link')[0].getAttribute('thumbnail');
              var interview =  monthlyLocalPost[qMonth-1][i].getElementsByTagName('link')[0].getAttribute('interview');
              var desc = '';
              
              if (interview != null)
                desc = 'Please click here to watch the interview';
              else
                desc = 'Please click here to view the article';
              
              if (filename != null){
              var folderName;
					if (monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('month')<10){
						folderName=monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('year')+"0"+monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('month');
					}
					else{
						folderName=monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('year')+monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('month');
					}
                    alt="Article thumbnail - "+monthlyLocalPost[qMonth-1][i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
                    cell.innerHTML+='<p><a href="'+monthlyLocalPost[qMonth-1][i].getElementsByTagName('link')[0].getAttribute('url')+'" target="_blank">'+'<img width="270" alt="'+alt+'"  border="0" src="../news/images/'+folderName+'/'+monthlyLocalPost[qMonth-1][i].getElementsByTagName('link')[0].getAttribute('thumbnail')+'"><br>' + desc + '</a></p>';
                    }
                    else{
                      cell.innerHTML+='<p><a href="'+monthlyLocalPost[qMonth-1][i].getElementsByTagName('link')[0].getAttribute('url')+'" target="_blank">'+monthlyLocalPost[qMonth-1][i].getElementsByTagName('link')[0].getAttribute('url')+'</a></p>';
                    }
                }
								
				//create link for file attachment
				if (monthlyLocalPost[qMonth-1][i].getElementsByTagName('other').length>0){
					for (j=0;j<monthlyLocalPost[qMonth-1][i].getElementsByTagName('other').length;j++){
						var folderName;
						if (monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('month')<10){
							folderName=monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('year')+"0"+monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('month');
						}
						else{
							folderName=monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('year')+monthlyLocalPost[qMonth-1][i].parentNode.getAttribute('month');
						}
						if (monthlyLocalPost[qMonth-1][i].getElementsByTagName('other')[j].getAttribute('target')==null){
							target="";
						}
						else{
							target=monthlyLocalPost[qMonth-1][i].getElementsByTagName('other')[j].getAttribute('target');
						}
						cell.innerHTML+='<a href=../news/others/'+folderName+'/'+monthlyLocalPost[qMonth-1][i].getElementsByTagName('other')[j].getAttribute('file')+' target="'+target+'">'+monthlyLocalPost[qMonth-1][i].getElementsByTagName('other')[j].childNodes[0].nodeValue+'</a><br/><br/>';
						
					}
					
				}
				
				//create table of image
				if (monthlyLocalPost[qMonth-1][i].getElementsByTagName('image').length>0){
					var imageTable=document.createElement('table');
					for (j=0;j<monthlyLocalPost[qMonth-1][i].getElementsByTagName('image').length;j++){
						imageTable.width="550";
						imageTable.className="content";
						var iTabRow = imageTable.insertRow(-1);
						var iTabCell = iTabRow.insertCell(0);
						var alt="";
                        var desc="";
						var url="";
						if (monthlyLocalPost[qMonth-1][i].getElementsByTagName('image')[j].hasChildNodes()){
                            desc=monthlyLocalPost[qMonth-1][i].getElementsByTagName('image')[j].childNodes[0].nodeValue;
                            alt=desc.replace(/<br\/>/g,"&#013;");
						}
						
						url=monthlyLocalPost[qMonth-1][i].getElementsByTagName('image')[j].getAttribute('url');

						if(url==null){
							iTabCell.innerHTML+='<img width="270" alt="'+alt+' "src="../news/images/'+folderName+'/'+monthlyLocalPost[qMonth-1][i].getElementsByTagName('image')[j].getAttribute('file')+'">';
						}
						else{
							iTabCell.innerHTML+='<a href="'+url+'" target="_blank" ><img border="0" width="270" alt="'+alt+' "src="../news/images/'+folderName+'/'+monthlyLocalPost[qMonth-1][i].getElementsByTagName('image')[j].getAttribute('file')+'"></a>';
						}
						iTabCell.width="270";
                        iTabCell.vAlign="top";
                        iTabCell.style.paddingTop="20px";
						iTabCell = iTabRow.insertCell(1);
						iTabCell.innerHTML+=desc;
						iTabCell.width="280";
						iTabCell.vAlign="bottom";
                        iTabCell.style.paddingTop="20px";
						iTabCell.style.textAlign="left";
						
					}
					cell.appendChild(imageTable);
				}
					//alert(getQueries('year'));
					//alert(location.hostname);
                var navTable=document.createElement('table');
                navTable.className="content";
                navTable.width="100%";
                var navTabRow = navTable.insertRow(-1);
                var navTabCell = navTabRow.insertCell(0);
                navTabCell.style.paddingTop="20px";
                if (previousNews==-1){
                    navTabCell.innerHTML+="&nbsp;";
                }
                else{
                    navTabCell.innerHTML+="<a href='"+location.pathname+"?year="+getQueries('year')+"&month="+getQueries('month')+"&id="+previousNews+"'>&lt;&lt;Previous News</a>";
                }
                navTabCell.style.textAlign="left";
                navTabCell = navTabRow.insertCell(1);
                
                // Add by Wilson 15072010 
                var post = xmlobject.getElementsByTagName('esrihknews')[0].getElementsByTagName('post');
                var latestYear = post[0].getAttribute('year');
                var latestMonth = post[0].getAttribute('month');
                
                if ((qMonth==latestMonth) && (qYear==latestYear))
                  navTabCell.innerHTML+="<a href='userlink.html'>Back to Userlink</a>";
                else
                  navTabCell.innerHTML+="<a href='userlinkArchive.html?year="+getQueries('year')+"&month="+getQueries('month')+"'>Back to Userlink</a>";
                navTabCell.style.paddingTop="20px";
                // END Add by Wilson 15072010 
                
                navTabCell = navTabRow.insertCell(2);
                //navTabCell = navTabRow.insertCell(1);
                
                if (nextNews==-1){
                    navTabCell.innerHTML+="&nbsp;";
                }
                else{
                    navTabCell.innerHTML+="<a href='"+location.pathname+"?year="+getQueries('year')+"&month="+getQueries('month')+"&id="+nextNews+"'>Next News>></a>";
                }
                navTabCell.style.textAlign="right";
                navTabCell.style.paddingTop="20px";
                navTabRow = navTable.insertRow(-1);
                navTabCell = navTabRow.insertCell(0);
                navTabCell.style.paddingTop="20px";
                navTabCell.innerHTML+='<a href="javascript:history.go(-1)">Back to Previous page</a>'
                cell.appendChild(navTable);
				//cell.innerHTML+='<br/><a href="'+location.pathname+'?year='+getQueries('year')+'#'+getQueries('year')+getQueries('month')+getQueries('id')+'">Back to Local News Archive</a>'
				//cell.style.textAlign='justify';
			}
		}
	}
	//if month and  news id are not appear in query strin
	//show title filter  by selected year

	else if (false){
		alert('2');
		//update HTML, show selected year in Header
		document.getElementById('header').innerHTML='Local News';
		document.getElementById('subHeader').innerHTML+=qYear;
		//create layout of selected year grouped by year ordered desc
		for (i=monthlyLocalPost.length-1;i>=0;i--){
			if (monthlyLocalPost[i].length!=0){
				if (monthlyLocalPost[i][0].parentNode.getAttribute('hidden')=='true'){
					continue;
				}
				var content="";
				//generate url for each month with selected year
				for (j=monthlyLocalPost[i].length-1;j>=0;j--){
					var target;
					//get url from xml if link is linked to another page
					//else
					//gen link included year and local post index in array format
					if (monthlyLocalPost[i][j].getElementsByTagName('link').length>0){
						monthlyLocalPost[i][j].getElementsByTagName('link')[0].getAttribute('target')==null?target='':target='_blank';
						content+="<li><a href="+monthlyLocalPost[i][j].getElementsByTagName('link')[0].getAttribute('url')+" target="+target+">"
						+monthlyLocalPost[i][j].getElementsByTagName('title')[0].childNodes[0].nodeValue+"</a></li>";
					}
					else{
						month=monthlyLocalPost[i][j].parentNode.getAttribute('month');
						id=monthlyLocalPost[i][j].getAttribute('id');
						content+='<li><a name="'+qYear+month+id+'" href="'+location.pathname+'?year='+qYear+'&month='+month+'&id='+id+'">'+monthlyLocalPost[i][j].getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a></li>';
					}
				}
				cell.innerHTML+=getLongMonthName((i+1).toString())+"<ul class='singleline'>"+content+"</ul>";
			}
		}
    // Go to the anchor position
    gotoAnchor();
	}
}

function getAuthInfo(anchor){

	table = document.getElementById('authInfo');
	if (anchor.innerHTML=="more"){
		anchor.innerHTML="close";
		var row = table.insertRow(1);
		row.id="authInfoContent";
		var cell = row.insertCell(0);
		cell.innerHTML="We have been offering a variety of instructor-led ESRI GIS training classes by our ESRI Authorized Instructors as well as GIS experts overseas since 1998. It is our pleasure and honor to announce that we are designated and authorized by ESRI Inc as one of the 500 <a href='/doc/ESRI_authorized_learning_centre_certificate_HK.pdf' target='_blank'>ESRI Authorized Learning Centers</a> nationwide. It is indeed great encouragement and endorsement from ESRI Inc. in recognition of our efforts to meet the growing demand for quality training of ESRI GIS technology. We will continue to refurbish the physical environment including equipment in our Authorized Learning Center and our accent on the qualification of instructors for training excellence.";
		cell.colSpan="2";
		cell.style.padding="10px,20px";
		cell.style.textAlign="justify";
		cell.style.lineHeight="130%";
	}
	else{
		anchor.innerHTML="more";
		table.deleteRow(1);
	}
}

function getServiceTeam(anchor){

	table = document.getElementById('serviceTeam');
	if (anchor.innerHTML=="more"){
		anchor.innerHTML="close";
		var row = table.insertRow(1);
		row.id="Content";
		var cell = row.insertCell(0);
		cell.innerHTML="Our professional services team of GIS and IT veterans in Hong Kong is amongst the finest in the region with project experience and hands-on expertise on cutting-edge technologies such as (Enterprise GIS, Wireless Location Services, Web Services), (ArcGISTM /ArcObjects TM/ArcGIS Server TM) implementation and so on. he Professional Services division includes the technical, management and customer support staff required in providing full project life-cycle services at competitive rates with rapid turnaround time. Typically, a solution team (of ESRI Project Managers, Consultants, Database and Technology Specialists, System Analysts, Programmers and Authorized Trainers) can be formed and deployed in a matter of days thus providing immediate services in enhancing your bottom line.";		
		cell.colSpan="2";
		cell.style.padding="10px,20px";
		cell.style.textAlign="justify";
		cell.style.lineHeight="130%";
	}
	else{
		anchor.innerHTML="more";
		table.deleteRow(1);
	}
}

function getOurMethods(anchor){

	table = document.getElementById('ourMethods');
	if (anchor.innerHTML=="more"){
		anchor.innerHTML="close";
		var row = table.insertRow(1);
		row.id="Content";
		var cell = row.insertCell(0);
		cell.innerHTML='<p>Our professional services team of GIS and IT veterans in Hong Kong is amongst the finest in the region with project experience and hands-on expertise on cutting-edge technologies such as (Enterprise GIS, Wireless Location Services, Web Services), (ArcGISTM /ArcObjects TM/ArcGIS Server TM) implementation and so on.</p>';
		cell.innerHTML+='<p>The Professional Services division includes the technical, management and customer support staff required in providing full project life-cycle services at competitive rates with rapid turnaround time. Typically, a solution team (of ESRI Project Managers, Consultants, Database and Technology Specialists, System Analysts, Programmers and Authorized Trainers) can be formed and deployed in a matter of days thus providing immediate services in enhancing your bottom line.</p>';		
		cell.colSpan="2";
		cell.style.padding="10px,20px";
		cell.style.textAlign="justify";
		cell.style.lineHeight="130%";
	}
	else{
		anchor.innerHTML="more";
		table.deleteRow(1);
	}
}

function getOurServices(anchor){

	table = document.getElementById('ourServices');
	if (anchor.innerHTML=="more"){
		anchor.innerHTML="close";
		var row = table.insertRow(1);
		row.id="Content";
		var cell = row.insertCell(0);
		if (navigator.appName=="Microsoft Internet Explorer"){
			cell.innerHTML+='<ul class="singleline" style="margin-left:10px">';
		}
		else{
			cell.innerHTML+='<ul class="singleline" style="margin-left:-25px">';
		}
		cell.innerHTML+='<li>Consulting and Project Planning </li><li>Project Management</li><li>System and Application Development</li><li>Data Modeling, Design and Development</li><li>Implementation Support</li><li>Feasibility Study</li><li>System Maintenance</li><li>Quality Assurance</li><li>Custom Training</li></ul>';
		//cell.style.padding="10px,20px";
		cell.style.textAlign="justify";
		cell.style.lineHeight="130%";
		cell = row.insertCell(1);
		if (navigator.appName=="Microsoft Internet Explorer"){
			cell.innerHTML+='<ul class="singleline" style="margin-left:10px">';
		}
		else{
			cell.innerHTML+='<ul class="singleline" style="margin-left:-25px">';
		}
		cell.innerHTML+='<li>Consulting and Project Planning </li><li>Project Management</li><li>System and Application Development</li><li>Data Modeling, Design and Development</li><li>Implementation Support</li><li>Feasibility Study</li><li>System Maintenance</li><li>Quality Assurance</li><li>Custom Training</li></ul>';
		//cell.style.padding="10px,20px";
		cell.style.textAlign="justify";
		cell.style.lineHeight="130%";

	}
	else{
		anchor.innerHTML="more";
		table.deleteRow(1);
	}
}

function getEquipInfo(anchor){

	table = document.getElementById('equipInfo');
	if (anchor.innerHTML=="more"){
		anchor.innerHTML="close";
		var row = table.insertRow(1);
		row.id="authInfoContent";
		var cell = row.insertCell(0);
		cell.innerHTML="The Facilities and Equipment of our Training Center include:"+
		"<ul class='singleline' style='margin-bottom:0px;'><li>Wireless LAN notebook</li>"+
		"<li>Electromagnetic LCD monitor with wireless pen mouse</li>"+
		"<!--li>Wireless LAN Internet access</li--><li>Overhead projector and screen</li>"+
		"<li>Dual wireless microphone</li><li>Ceiling speaker</li>"+
		"<li>Whiteboard</li><li>VCR and VCD player</li>"+
		"<li>ESRI software licenses</li></ul>";
		cell.colSpan="2";
		cell.style.padding="10px,20px";
		cell.style.textAlign="justify";
	}
	else{
		anchor.innerHTML="more";
		table.deleteRow(1);
	}
}

function showProductNews(){
	today = setDateObj(strToday);
	var news=xmlobject.getElementsByTagName('news');
	var productNews = new Array();
	for (i=0;i<news.length;i++){
		if (news[i].getAttribute('type')=='product' && news[i].parentNode.getAttribute('hidden')!='true'){
			//show only 2 months news
			if(((today.getMonth()+today.getFullYear()*12))-1<(parseInt(news[i].parentNode.getAttribute('month'))+parseInt(news[i].parentNode.getAttribute('year')*12))){
            	productNews.push(news[i]);
			}
		}
	}
	var productTable=genNewsTable(productNews,'Product News');
	//productTable.align="right";
	productTable.width="550px";
	document.getElementById('productNews').appendChild(productTable);
	//document.getElementById('productNews').innerHTML+=genUserlinkTable(productNews,'Product News');
}

function showCommunityArchive(){
	var qYear = getQueries('year');
	var qMonth = getQueries('month');
	var qId = getQueries('id');
	var news = xmlobject.getElementsByTagName('esrihknews')[0].getElementsByTagName('news');
	var csPost = new Array();
	var year = new Array();
	var yearInList=false;

	//create entery for local news, get year of news in xml	
	for (i=0;i<news.length;i++){
		if (news[i].getAttribute('type')=='community' && news[i].parentNode.getAttribute('hidden')!='true'){
			for (j=0;j<year.length;j++){
				if (year[j]==news[i].parentNode.getAttribute('year')){
					yearInList=true;
					break;
				}
			}
			if (!yearInList){
				year.push(news[i].parentNode.getAttribute('year'));
			}
		}
		yearInList=false;
	}
	
	year.sort();
	//init qYear if no query string
	if (qYear==""){
		qYear=year[year.length-1];
	}
	
	//filter all news with (type = community) in qyear, store in lcPost[]
	for (i=0;i<news.length;i++){
		if (news[i].parentNode.getAttribute('year')==qYear&&news[i].getAttribute('type')=='community'){
			csPost.push(news[i]);
		}
	}
	
	//update HTML, add link under 'uId' object in HTML
	var list="";
	for (i=year.length-1;i>=0;i--){
		if (year[i]==qYear && ((qMonth=="") && (qId==""))){
			list+='<li class="selected">'+year[i]+'</li>';
		}
		else{
			list+='<li><a href="/news/communityArchive.html?year='+year[i]+'">'+year[i]+'</a></li>';
		}
	}
	document.getElementById('csId').innerHTML=list;
	
	//update HTML, insert, style the row and cell in the table for monthly news
	row = document.getElementById('csTable').insertRow(-1);
	cell = row.insertCell(0);
	cell.className="content";
	
	//create array for 12 month news
	var monthlyCsPost = new Array(12);
	//create array for each month news
	for (i=0;i<monthlyCsPost.length;i++){
		monthlyCsPost[i]=new Array();
	}

	//add post in arrary according its month
	for (i=csPost.length-1;i>=0;i--){
		monthlyCsPost[csPost[i].parentNode.getAttribute('month')-1].push(csPost[i]);
	}

	//gen Archived news if year and post index appeared in query string
	if ((qMonth!="") && (qId!="")){
		
        var previousCs=-1;
        var nextCs=-1;
        
        document.getElementById('header').innerHTML+=' - <span style="font-size:x-small">'+getLongMonthName(qMonth)+' '+qYear+'</span>';
		for (i=0;i<monthlyCsPost[qMonth-1].length;i++){
			if (monthlyCsPost[qMonth-1][i].getAttribute('id')==qId){
				document.getElementById('subHeader').innerHTML=monthlyCsPost[qMonth-1][i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
				
                //get next and prvious news for navigation
                if (i>0&&i<monthlyCsPost[qMonth-1].length-1){
                    previousCs = monthlyCsPost[qMonth-1][i+1].getAttribute('id');
                    nextCs = monthlyCsPost[qMonth-1][i-1].getAttribute('id');
                }
                else if (i==0 && monthlyCsPost[qMonth-1].length>1){
                    previousCs = monthlyCsPost[qMonth-1][i+1].getAttribute('id');
                }
                else if (i==monthlyCsPost[qMonth-1].length-1 && monthlyCsPost[qMonth-1].length>1){
                    nextCs = monthlyCsPost[qMonth-1][i-1].getAttribute('id');
                }
                
				for (j=0;j<monthlyCsPost[qMonth-1][i].getElementsByTagName('desc').length;j++){
					cell.innerHTML+='<p style="text-align:justify;text-justify:inter-ideograph;">'+monthlyCsPost[qMonth-1][i].getElementsByTagName('desc')[j].childNodes[0].nodeValue+'</p>';
				}
                
          if (monthlyCsPost[qMonth-1][i].getElementsByTagName('link').length>0){
            var folderName;
            if (monthlyCsPost[qMonth-1][i].parentNode.getAttribute('month')<10){
              folderName=monthlyCsPost[qMonth-1][i].parentNode.getAttribute('year')+"0"+monthlyCsPost[qMonth-1][i].parentNode.getAttribute('month');
            }
            else{
              folderName=monthlyCsPost[qMonth-1][i].parentNode.getAttribute('year')+monthlyCsPost[qMonth-1][i].parentNode.getAttribute('month');
            }
              alt="Article thumbnail - "+monthlyCsPost[qMonth-1][i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
              cell.innerHTML+='<p><a href="'+monthlyCsPost[qMonth-1][i].getElementsByTagName('link')[0].getAttribute('url')+'" target="_blank">'+'<img width="270" alt="'+alt+'" border="0" src="../news/images/'+folderName+'/'+monthlyCsPost[qMonth-1][i].getElementsByTagName('link')[0].getAttribute('thumbnail')+'"><br>Please Click here to view the article'+'</a></p>';
          }
                
				if (monthlyCsPost[qMonth-1][i].getElementsByTagName('other').length>0){
					for (j=0;j<monthlyCsPost[qMonth-1][i].getElementsByTagName('other').length;j++){
						
						if (monthlyCsPost[qMonth-1][i].getElementsByTagName('other')[j].getAttribute('target')==null){
							target="";
						}
						else{
							target=monthlyCsPost[qMonth-1][i].getElementsByTagName('other')[j].getAttribute('target');
						}
		
                        var folderName;
						if (monthlyCsPost[qMonth-1][i].parentNode.getAttribute('month')<10){
							folderName=monthlyCsPost[qMonth-1][i].parentNode.getAttribute('year')+"0"+monthlyCsPost[qMonth-1][i].parentNode.getAttribute('month');
						}
						else{
							folderName=monthlyCsPost[qMonth-1][i].parentNode.getAttribute('year')+monthlyCsPost[qMonth-1][i].parentNode.getAttribute('month');
						}
						cell.innerHTML+='<a href=../news/others/'+folderName+'/'+monthlyCsPost[qMonth-1][i].getElementsByTagName('other')[j].getAttribute('file')+' target="'+target+'">'+monthlyCsPost[qMonth-1][i].getElementsByTagName('other')[j].childNodes[0].nodeValue+'</a><br/><br/>';
						
					}
					
				}
				
				if (monthlyCsPost[qMonth-1][i].getElementsByTagName('image').length>0){
					var imageTable=document.createElement('table');
					for (j=0;j<monthlyCsPost[qMonth-1][i].getElementsByTagName('image').length;j++){
						imageTable.width="550";
						imageTable.className="content";
						var iTabRow = imageTable.insertRow(-1);
						var iTabCell = iTabRow.insertCell(0);
						var alt="";
                        var desc="";
						var url="";
						if (monthlyCsPost[qMonth-1][i].getElementsByTagName('image')[j].hasChildNodes()){
							desc=monthlyCsPost[qMonth-1][i].getElementsByTagName('image')[j].childNodes[0].nodeValue;
                            alt=desc.replace(/<br\/>/g,"&#013;");
						}
						url=monthlyCsPost[qMonth-1][i].getElementsByTagName('image')[j].getAttribute('url');
						var folderName;
						if (monthlyCsPost[qMonth-1][i].parentNode.getAttribute('month')<10){
							folderName=monthlyCsPost[qMonth-1][i].parentNode.getAttribute('year')+"0"+monthlyCsPost[qMonth-1][i].parentNode.getAttribute('month');
						}
						else{
							folderName=monthlyCsPost[qMonth-1][i].parentNode.getAttribute('year')+monthlyCsPost[qMonth-1][i].parentNode.getAttribute('month');
						}
						if(url==null){
							iTabCell.innerHTML+='<img width="270" alt="'+alt+' "src="../news/images/'+folderName+'/'+monthlyCsPost[qMonth-1][i].getElementsByTagName('image')[j].getAttribute('file')+'">';
						}
						else{
							iTabCell.innerHTML+='<a href="'+url+'" target="_blank" ><img border="0" width="270" alt="'+alt+' "src="../news/images/'+folderName+'/'+monthlyCsPost[qMonth-1][i].getElementsByTagName('image')[j].getAttribute('file')+'"></a>';
						}
						iTabCell.width="270";
                        iTabCell.vAlign="top";
                        iTabCell.style.paddingTop="20px";
						iTabCell = iTabRow.insertCell(1);
						iTabCell.innerHTML+=desc;
						iTabCell.width="280";
						iTabCell.vAlign="bottom";
                        iTabCell.style.paddingTop="20px";
						iTabCell.style.textAlign="left";
						
					}
					cell.appendChild(imageTable);
				}
				
				var navTable=document.createElement('table');
                navTable.className="content";
                navTable.width="100%";
                var navTabRow = navTable.insertRow(-1);
                var navTabCell = navTabRow.insertCell(0);
                navTabCell.style.paddingTop="20px";
                if (previousCs==-1){
                    navTabCell.innerHTML+="&nbsp;";
                }
                else{
                    navTabCell.innerHTML+="<a href='"+location.pathname+"?year="+getQueries('year')+"&month="+getQueries('month')+"&id="+previousCs+"'>&lt;&lt;Previous Community Service</a>";
                }
                navTabCell.style.textAlign="left";
                navTabCell = navTabRow.insertCell(1);
                if (nextCs==-1){
                    navTabCell.innerHTML+="&nbsp;";
                }
                else{
                    navTabCell.innerHTML+="<a href='"+location.pathname+"?year="+getQueries('year')+"&month="+getQueries('month')+"&id="+nextCs+"'>Next Community Service>></a>";
                }
                navTabCell.style.textAlign="right";
                navTabCell.style.paddingTop="20px";
                navTabRow = navTable.insertRow(-1);
                navTabCell = navTabRow.insertCell(0);
                navTabCell.style.paddingTop="20px";
                navTabCell.innerHTML+='<a href="javascript:history.go(-1)">Back to Previous page</a>'
                cell.appendChild(navTable);
				//cell.innerHTML+='<br/><a href="'+location.pathname+'?year='+getQueries('year')+'#'+getQueries('year')+getQueries('month')+getQueries('id')+'">Back to Community Services Archive</a>'
				//alert(qYear);
				//cell.style.textAlign='justify';
			break;
			}
		}
	}
	else{
		//update HTML, show selected year in Header
		document.getElementById('header').innerHTML=="Community Services";
		document.getElementById('subHeader').innerHTML+=qYear;
		//create layout of selected year grouped by year ordered desc
		for (i=monthlyCsPost.length-1;i>=0;i--){
			if (monthlyCsPost[i].length!=0){
				if (monthlyCsPost[i][0].parentNode.getAttribute('hidden')=='true'){
					continue;
				}
				var content="";
				for (j=monthlyCsPost[i].length-1;j>=0;j--){
					if (monthlyCsPost[i][j].getElementsByTagName('link').length>0){
						var target;
						//get url from xml if link is linked to another page
						//else
						//gen link included year and local post index in array format
						monthlyCsPost[i][j].getElementsByTagName('link')[0].getAttribute('target')==null?target='':target='_blank';
						content+="<li><a href="+monthlyCsPost[i][j].getElementsByTagName('link')[0].getAttribute('url')+" target="+target+">"
						+monthlyCsPost[i][j].getElementsByTagName('title')[0].childNodes[0].nodeValue+"</a></li>";
					}
					else{
						month=monthlyCsPost[i][j].parentNode.getAttribute('month');
						id=monthlyCsPost[i][j].getAttribute('id');
						content+='<li><a name="'+qYear+month+id+'" href="'+location.pathname+'?year='+qYear+'&month='+monthlyCsPost[i][j].parentNode.getAttribute('month')+'&id='+monthlyCsPost[i][j].getAttribute('id')+'">'+monthlyCsPost[i][j].getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a></li>';
					}
				}
				cell.innerHTML+=getLongMonthName((i+1).toString())+"<ul class='singleline'>"+content+"</ul>";
			}
		}
	// Go to the anchor position
    //gotoAnchor();
	}
}

function showProductArchive(){
	var post = xmlobject.getElementsByTagName('esrihknews')[0].getElementsByTagName('post');
	//var news = xmlobject.getElementsByTagName('esrihknews')[0].getElementsByTagName('news');
	var qMonth = getQueries('month');
	var qYear = getQueries('year');
	var qId = getQueries('id');
	var year = new Array();
	var ptPost = new Array();
	var yearInList=false;
	//create entery for userlink, get year of news in xml	
	for (i=0;i<post.length;i++){
		if (post[i].getAttribute('hidden')!='true'){
			for (j=0;j<year.length;j++){
				if (year[j]==post[i].getAttribute('year')){
					yearInList=true;
					break;
				}
			}
			if (!yearInList){
				year.push(post[i].getAttribute('year'));
			}
		}
		yearInList=false;
	}
	
	year.sort();
	
	//update HTML, insert, style the row and cell in the table for monthly news
	row = document.getElementById('ptTable').insertRow(-1);
	cell = row.insertCell(0);
	cell.className="content";
	
	document.getElementById('ulId').innerHTML="";
	for (i=year.length-1;i>=0;i--){
		document.getElementById('ulId').innerHTML+='<li><a href="/news/userlinkArchive.html?year='+year[i]+'">'+year[i]+'</a></li>';
	}
	
	//filter all news with (type = product) in qyear, store in ptPost[]
	for (i=0;i<post.length;i++){
		if (post[i].getAttribute('year')==qYear && post[i].getAttribute('month')==qMonth){
			var monthlyPtPost = post[i].getElementsByTagName('news');
			for (j=0;j<monthlyPtPost.length;j++){
				if (monthlyPtPost[j].getAttribute('id')==qId){
					document.getElementById('subHeader').innerHTML=monthlyPtPost[j].getElementsByTagName('title')[0].childNodes[0].nodeValue;
					for (k=0;k<monthlyPtPost[j].getElementsByTagName('desc').length;k++){
						cell.innerHTML+='<p style="text-align:justify;text-justify:inter-ideograph;">'+monthlyPtPost[j].getElementsByTagName('desc')[k].childNodes[0].nodeValue+'</p>';
					}
					if(monthlyPtPost[j].getElementsByTagName('sub').length>0){
						var sub=monthlyPtPost[j].getElementsByTagName('sub');
						for (k=0;k<sub.length;k++){
							for (l=0;l<monthlyPtPost.length;l++){
								if (monthlyPtPost[l].getAttribute('id')==sub[k].getAttribute('id')){
									var subNews=monthlyPtPost[l];
									cell.innerHTML+='<ul style="margin-top:-8px;margin-bottom:-8px"><li><a href="'+subNews.getElementsByTagName('link')[0].getAttribute('url')+'">'+subNews.getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a></li></ul>';
									//cell.innerHTML+='<br/>';
								}
							}
						}
					}
					
				break;
				}
			}
			
		}
	}
	cell.innerHTML+='<br/><br/><a href="javascript:history.go(-1)">Back</a><br/>';
}

function showSupportArchive(){
	var post = xmlobject.getElementsByTagName('esrihknews')[0].getElementsByTagName('post');
	//var news = xmlobject.getElementsByTagName('esrihknews')[0].getElementsByTagName('news');
	var qMonth = getQueries('month');
	var qYear = getQueries('year');
	var qId = getQueries('id');
	var year = new Array();
	var ptPost = new Array();
	var yearInList=false;
	//create entery for userlink, get year of news in xml	
	for (i=0;i<post.length;i++){
		if (post[i].getAttribute('hidden')!='true'){
			for (j=0;j<year.length;j++){
				if (year[j]==post[i].getAttribute('year')){
					yearInList=true;
					break;
				}
			}
			if (!yearInList){
				year.push(post[i].getAttribute('year'));
			}
		}
		yearInList=false;
	}
	
	year.sort();
	
	//update HTML, insert, style the row and cell in the table for monthly news
	row = document.getElementById('ptTable').insertRow(-1);
	cell = row.insertCell(0);
	cell.className="content";
	
	document.getElementById('ulId').innerHTML="";
	for (i=year.length-1;i>=0;i--){
		document.getElementById('ulId').innerHTML+='<li><a href="/news/userlinkArchive.html?year='+year[i]+'">'+year[i]+'</a></li>';
	}
	
	//filter all news with (type = product) in qyear, store in ptPost[]
	for (i=0;i<post.length;i++){
		if (post[i].getAttribute('year')==qYear && post[i].getAttribute('month')==qMonth){
			var monthlyPtPost = post[i].getElementsByTagName('news');
			for (j=0;j<monthlyPtPost.length;j++){
				if (monthlyPtPost[j].getAttribute('id')==qId){
					document.getElementById('subHeader').innerHTML=monthlyPtPost[j].getElementsByTagName('title')[0].childNodes[0].nodeValue;
					for (k=0;k<monthlyPtPost[j].getElementsByTagName('desc').length;k++){
						cell.innerHTML+='<p style="text-align:justify;text-justify:inter-ideograph;">'+monthlyPtPost[j].getElementsByTagName('desc')[k].childNodes[0].nodeValue+'</p>';
					}
					if(monthlyPtPost[j].getElementsByTagName('sub').length>0){
						var sub=monthlyPtPost[j].getElementsByTagName('sub');
						for (k=0;k<sub.length;k++){
							for (l=0;l<monthlyPtPost.length;l++){
								if (monthlyPtPost[l].getAttribute('id')==sub[k].getAttribute('id')){
									var subNews=monthlyPtPost[l];
									cell.innerHTML+='<ul style="margin-top:-8px;margin-bottom:-8px"><li><a href="'+subNews.getElementsByTagName('link')[0].getAttribute('url')+'">'+subNews.getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a></li></ul>';
									//cell.innerHTML+='<br/>';
								}
							}
						}
					}
					
				break;
				}
			}
			
		}
	}
	cell.innerHTML+='<br/><br/><a href="javascript:history.go(-1)">Back</a><br/>';
}

function showUserlinkArchive(){
	var qYear = getQueries('year');
	var qMonth = getQueries('month');
	//var qId = getQueries('id');
	var post = xmlobject.getElementsByTagName('esrihknews')[0].getElementsByTagName('post');
	var ulPost = new Array();
	var year = new Array();
	var yearInList=false;

	//create entery for userlink, get year of news in xml	
	for (i=0;i<post.length;i++){
		//by requested,  hidden 2006 link, 23/4/2008
		if (post[i].getAttribute('year')=="2006"){
			continue;
		}
		if (post[i].getAttribute('hidden')!='true'){
			for (j=0;j<year.length;j++){
				if (year[j]==post[i].getAttribute('year')){
					yearInList=true;
					break;
				}
			}
			if (!yearInList){
				year.push(post[i].getAttribute('year'));
			}
		}
		yearInList=false;
	}
	
	year.sort();
	//init qYear if no query string
	if (qYear==""){
		qYear=year[year.length-1];
	}
	
	//update HTML, add link under 'ulId' object in HTML
	var list="";
	for (i=year.length-1;i>=0;i--){
		
		if (year[i]==qYear /*&& ((qMonth==""))*/){
			list+='<li class="selected">'+year[i]+'</li>';
		}
		else{
			list+='<li><a href="/news/userlinkArchive.html?year='+year[i]+'">'+year[i]+'</a></li>';
		}
	}
	document.getElementById('ulId').innerHTML=list;
	
	//update HTML, insert, style the row and cell in the table for monthly news
	row = document.getElementById('ulTable').insertRow(-1);
	cell = row.insertCell(0);
	cell.className="content";
	
	//create array for 12 month news
	var monthlyUlPost = new Array(12);


	//add post in arrary according its month
	for (i=post.length-1;i>=0;i--){
		if (post[i].getAttribute('year')==qYear && post[i].getAttribute('hidden')!='true'){
			monthlyUlPost[post[i].getAttribute('month')-1]=post[i];
		}
	}

	//gen Archived userlink entry if year and month index appeared in query string
	if ((qMonth!="") && (qYear!="")){
		genUserLink();
		document.getElementById('subHeader').innerHTML+= getLongMonthName(qMonth) +' '+qYear;
		document.getElementById('ulId').innerHTML="";
		for (i=year.length-1;i>=0;i--){
			document.getElementById('ulId').innerHTML+='<li><a href="/news/userlinkArchive.html?year='+year[i]+'">'+year[i]+'</a></li>';
		}
	

	}
	else{
		//update HTML, show selected year in Header
		document.getElementById('header').innerHTML=="Userlink";
		document.getElementById('subHeader').innerHTML+=qYear;
		//create entry for selected year's userlink month by month
		var content="";
		var currentpost=true;
		//show userlink entry of each month
		for (i=monthlyUlPost.length-1;i>=0;i--){
			if (monthlyUlPost[i]!=null){
				//skip currerent userlink show in archive
				if ((qYear==year[year.length-1])&&currentpost){
					
					currentpost=false;
					//continue;
                    content+='<li><a href="/news/userlink.html">'+getLongMonthName(monthlyUlPost[i].getAttribute('month'))+'</a></li>';
				}
				else{
                    content+='<li><a href="'+location.pathname+'?year='+qYear+'&month='+monthlyUlPost[i].getAttribute('month')+'">'+getLongMonthName(monthlyUlPost[i].getAttribute('month'))+'</a></li>';
                }
			}
		}
		cell.innerHTML+="<ul class='singleline'>"+content+"</ul>";
	}
}

function showCommunity(selectedYear){
	/*var news = xmlobject.getElementsByTagName('esrihknews')[0].getElementsByTagName('news');
	var csPost = new Array();
	var year = new Array();
	var yearInList=false;
			
	for (i=0;i<news.length;i++){
		if (news[i].getAttribute('type')=='community'){
			if (news[i].parentNode.getAttribute('year')==selectedYear){
				csPost.push(news[i]);
			}
			for (j=0;j<year.length;j++){
				if (year[j]==news[i].parentNode.getAttribute('year')){
					yearInList=true;
					break;
				}
			}
			if (!yearInList){
				year.push(news[i].parentNode.getAttribute('year'));
			}
		}
		yearInList=false;
	}
	
	year.sort();
	if (selectedYear==null){
		for (i=year.length-1;i>=0;i--){
			document.getElementById('csId').innerHTML+='<li><a href="/news/communityArchive.html?year='+year[i]+'">'+year[i]+'</a></li>';
		}
	}
	else {
		for (i=year.length-1;i>=0;i--){
			if (year[i]==selectedYear){
				
				document.getElementById('csId').innerHTML+='<li class="selected">'+year[i]+'</li>';
			}
			else{
				document.getElementById('csId').innerHTML+='<li><a href="/news/communityArchive.html?year='+year[i]+'">'+year[i]+'</a></li>';
			}
		}
	}
	return csPost;*/
	
}
	


/*function showProductNews(){
	var news=xmlobject.getElementsByTagName('news');
	var productNews = new Array();
	alert(today);
	for (i=0;i<news.length;i++){
		

		if (news[i].getAttribute('type')=='product'){
			productNews.push(news[i]);
		}
	}
	document.getElementById('productNews').appendChild(genNewsTable(productNews,'Product News'));
	//document.getElementById('productNews').innerHTML+=genUserlinkTable(productNews,'Product News');
}*/

function genUserLink(){
	var qYear = getQueries('year');
	var qMonth = getQueries('month');
	
	if (qMonth==""||qYear==""){
		var press = xmlobject.getElementsByTagName('post');
		var userlinkMonth;
		var userlinkYear;
		for (i=0;i<press.length;i++){
			if (press[i].getAttribute('hidden')==null || press[i].getAttribute('hidden')=='false'){
				userlinkMonth = press[i].getAttribute('month');
				userlinkYear = press[i].getAttribute('year');
				break;
			}
		}
		//var userlinkMonth = xmlobject.getElementsByTagName('press')[0].getAttribute('month');
		//var userlinkYear = xmlobject.getElementsByTagName('press')[0].getAttribute('year');
	}
	else{
		var userlinkMonth = qMonth;
		var userlinkYear = qYear;
	}
	
	//get all ceohighlights
	var highlightContent = xmlobject.getElementsByTagName('ceohighlights')[0].getElementsByTagName('highlight');
	
	//search highlight by month
	var content="";
	for (i=0;i<highlightContent.length;i++){
		if (highlightContent[i].getAttribute('month')==userlinkMonth){
			if (highlightContent[i].getAttribute('year')==userlinkYear){
				for (j=0;j<highlightContent[i].getElementsByTagName('p').length;j++){
					//alert(headlineContent[i].getElementsByTagName('p')[j].getAttribute('userlink'));
					if (highlightContent[i].getElementsByTagName('p')[j].getAttribute('userlink')=='true'){
						content+="<p>"+highlightContent[i].getElementsByTagName('p')[j].childNodes[0].nodeValue+"</p>";
						//content+=headlineContent[i].getElementsByTagName('p')[j].childNodes[0].nodeValue;
					}
					else{
						document.getElementById('userlinkContent').appendChild(createUserlinkCEOTable(content, userlinkMonth,userlinkYear));
						break;
					}
				}
			}
		}
	}
	//search all news in post by selected (month and year) or current news
	var news = xmlobject.getElementsByTagName('post');
	var userlinkNews = new Array();
	/*if (document.getElementById('date')!=null){
		alert('123');
		date.innerHTML+=getLongMonthName(userlinkMonth)+' '+userlinkYear
	}*/
	for (i=0;i<news.length;i++){
		if (news[i].getAttribute('month')==userlinkMonth && news[i].getAttribute('year')==userlinkYear){
			userlinkNews=news[i].getElementsByTagName('news');
			break;
		}
	}
	
	//type of news classification
	var headline = new Array();
	var local = new Array();
	var product = new Array();
	var comingevent = new Array();
	var innovative = new Array();
	var us = new Array();
	var smartips = new Array();
  var books = new Array();
	
	//generate URL for each news if the news is inside XML (is not linked to external site)
	for (i=userlinkNews.length-1;i>=0;i--){
		if (userlinkNews[i].getElementsByTagName('link').length==0){
			var type = userlinkNews[i].getAttribute('type');
			if (type == "community"){
				newEl=xmlobject.createElement('link');
				urlAtt=xmlobject.createAttribute('url');
				urlAtt.value='../news/communityArchive.html?year='+userlinkYear+'&month='+userlinkMonth+'&id='+userlinkNews[i].getAttribute('id');
				newEl.setAttributeNode(urlAtt);
				userlinkNews[i].appendChild(newEl);
			}
			if (type == "local"){
				newEl=xmlobject.createElement('link');
				urlAtt=xmlobject.createAttribute('url');
				urlAtt.value='../news/localNewsArchive.html?year='+userlinkYear+'&month='+userlinkMonth+'&id='+userlinkNews[i].getAttribute('id');
				newEl.setAttributeNode(urlAtt);
				userlinkNews[i].appendChild(newEl);
			}
			if (type == "comingevent"){
				newEl=xmlobject.createElement('link');
				urlAtt=xmlobject.createAttribute('url');
				urlAtt.value='../events/comingEventInfo.html?year='+userlinkYear+'&month='+userlinkMonth+'&id='+userlinkNews[i].getAttribute('id');
				newEl.setAttributeNode(urlAtt);
				userlinkNews[i].appendChild(newEl);
			} 
			if (type == "eventnews"){
				newEl=xmlobject.createElement('link');
				urlAtt=xmlobject.createAttribute('url');
				urlAtt.value='../events/events.html?year='+userlinkYear+'&month='+userlinkMonth+'&id='+userlinkNews[i].getAttribute('id');
				newEl.setAttributeNode(urlAtt);
				userlinkNews[i].appendChild(newEl);
			}
			if (type == "product"){
				newEl=xmlobject.createElement('link');
				urlAtt=xmlobject.createAttribute('url');
				urlAtt.value='../news/productsArchive.html?year='+userlinkYear+'&month='+userlinkMonth+'&id='+userlinkNews[i].getAttribute('id');
				newEl.setAttributeNode(urlAtt);
				userlinkNews[i].appendChild(newEl);
			}
			if (type == "smartips"){
				newEl=xmlobject.createElement('link');
				urlAtt=xmlobject.createAttribute('url');
				urlAtt.value='../news/smartips.html?year='+userlinkYear+'&month='+userlinkMonth+'&id='+userlinkNews[i].getAttribute('id');
				newEl.setAttributeNode(urlAtt);
				userlinkNews[i].appendChild(newEl);
			}
			if (type == "innovative") {
			    newEl = xmlobject.createElement('link');
			    urlAtt = xmlobject.createAttribute('url');
			    urlAtt.value = '../news/innovative.html?year=' + userlinkYear + '&month=' + userlinkMonth + '&id=' + userlinkNews[i].getAttribute('id');
			    newEl.setAttributeNode(urlAtt);
			    userlinkNews[i].appendChild(newEl);
			}}
	}
	
	for (i=0;i<userlinkNews.length;i++){
        if (userlinkNews[i].getAttribute('hideInUL')=="true"){
			continue;
		}
		if (userlinkNews[i].getAttribute('headline')=="true"){
			headline.push(userlinkNews[i]);
			continue;
		}
		if (userlinkNews[i].getAttribute('sub')=="true"){
			continue;
		}
        if (userlinkNews[i].getAttribute('subTitle')=="true"){
			continue;
		}
		switch (userlinkNews[i].getAttribute('type')){
		case "local":
			local.push(userlinkNews[i]);
			break;
		case "community":
			local.push(userlinkNews[i]);
			break;
		case "eventnews":
			local.push(userlinkNews[i]);
			break;
		case "comingevent" :
			comingevent.push(userlinkNews[i]);
			break;
		case "product" :
			product.push(userlinkNews[i]);
			break;
		case "innovative" :
			innovative.push(userlinkNews[i]);
			break;
		case "us" :
			us.push(userlinkNews[i]);
			break;
		case "smartips" :
			smartips.push(userlinkNews[i]);
			break;
        case "books" :
			books.push(userlinkNews[i]);
			break;
		}
	}
	
	//alert(headline.length+'\n'+local.length+'\n'+product.length+'\n'+innovative.length+'\n'+us.length);
	//generate userlink table
	if (headline.length>0){
		document.getElementById('userlinkContent').appendChild(genUserlinkTable(headline, 'Headlines'));
	}	
	if (comingevent.length>0){
		document.getElementById('userlinkContent').appendChild(genUserlinkTable(comingevent, 'Coming Event'));
	}
	if (smartips.length>0){
		document.getElementById('userlinkContent').appendChild(genUserlinkTable(smartips, 'Smart Tips on ArcGIS'));
	}
	if (local.length>0){
		document.getElementById('userlinkContent').appendChild(genUserlinkTable(local, 'Local News'));
	}
	if (product.length>0){
		document.getElementById('userlinkContent').appendChild(genUserlinkTable(product, 'Product News'));
	}
  if (books.length>0){
		document.getElementById('userlinkContent').appendChild(genUserlinkTable(books, 'New Books from Esri Press'));
	}
	if (innovative.length>0){
		document.getElementById('userlinkContent').appendChild(genUserlinkTable(innovative, 'Innovative GIS Application'));
	}
	if (us.length>0){
		document.getElementById('userlinkContent').appendChild(genUserlinkTable(us, 'Esri News'));
	}
}
	
function createUserlinkCEOTable(content,userlinkMonth,userlinkYear){
	var table = document.createElement('table');
	table.width="550";
	table.cellSpacing="0";
	//font-size: 1em; border: 1px solid #D5CDB7; margin-top:10px;" >
	table.style.fontSize="13px";
	table.style.border="1px";
	table.style.borderStyle="solid";
	table.style.borderColor="#d5cdb7";
	table.style.marginTop="10px";
	//table.class="containerTable";
    row = table.insertRow(0);
	row.style.backgroundColor="#f4efe0";
	row.style.borderBottom="1px";
	row.style.borderBottomStyle="solid";
	row.style.borderBottomColor="#d5cdb7";
	row.style.color="#1f67a2";
	row.style.fontSize="12px";
	row.style.fontWeight="bold";
	row.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";
	
	cell = row.insertCell(0);
	cell.innerHTML+='CEO Highlights';
	cell.style.paddingLeft="10px";
	cell.style.paddingRight="10px";
	cell.style.paddingTop="5px";
	cell.style.paddingBottom="5px";
	
	cell = row.insertCell(1);
	cell.innerHTML+='<a href="/ceo/ceohighlights.html?year='+userlinkYear+'&month='+userlinkMonth+'">more</a>';
	cell.style.textAlign="right";
	cell.style.paddingLeft="10px";
	cell.style.paddingRight="10px";
	cell.style.paddingTop="5px";
	cell.style.paddingBottom="5px";
	
	var innerTable=document.createElement('table');
	innerTable.cellSpacing="0";
	innerTable.cellPadding="0";
	innerTable.border="0";
	innerTable.align="right";
	innerRow=innerTable.insertRow(0);
	//<td width="92" height="106" valign="middle" align="center"style="padding: 2px 10px 2px 10px;">
	innerCell=innerRow.insertCell(0);
	innerCell.innerHTML='<a href="http://www.winnietang.hk" target="_blank"><img border="0" alt="Dr. Winnie Tang" src="/images/winnie_userlink.JPG"/ width="92" height="101"></a>'
	innerCell.style.paddingLeft="10px";
	innerCell.style.paddingRight="10px";
	innerCell.style.paddingBottom="5px";
	innerCell.style.paddingTop="5px";
	
	row = table.insertRow(1);
	cell = row.insertCell(0);
	cell.appendChild(innerTable);
	cell.innerHTML+=content;
	cell.style.textAlign="justify";
	cell.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";
	cell.style.fontSize="1em";
	cell.style.paddingLeft="10px";
	cell.style.paddingRight="10px";
	cell.style.paddingTop="10px";
	cell.style.paddingBottom="5px";
	cell.colSpan="2";
	
	return table
}
	
function genUserlinkTable(news, tableName){
	var content="";
	var target;
	for (i=0;i<news.length;i++){
    
		var target;
		news[i].getElementsByTagName('link')[0].getAttribute('target')==null?target='':target='_blank';
		content+='<li style="font-size:12px;line-height:15px;margin-bottom:15px;padding-bottom:0px;"><a href="'
		+news[i].getElementsByTagName('link')[0].getAttribute('url')+'" target="'+target+'">'
		+news[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+
		'</a>';
		
		if (news[i].getElementsByTagName('shortdesc').length>0&&(news[i].getAttribute('headline')=='true'||news[i].getAttribute('type')=='comingevent')){
			for (j=0;j<news[i].getElementsByTagName('shortdesc').length;j++){
                if((news[i].getElementsByTagName('shortdesc')[j].getElementsByTagName('title').length==0&&news[i].getElementsByTagName('shortdesc')[j].getElementsByTagName('link').length==0)&&news[i].getElementsByTagName('shortdesc')[j].childNodes.length>0){
                    content+='<br/>'+news[i].getElementsByTagName('shortdesc')[j].childNodes[0].nodeValue;
                }
                else if(news[i].getElementsByTagName('shortdesc')[j].getElementsByTagName('title').length>0&&news[i].getElementsByTagName('shortdesc')[j].getElementsByTagName('link').length>0){
                    if (news[i].getElementsByTagName('shortdesc')[j].getAttribute('start')!=null||news[i].getElementsByTagName('shortdesc').length==1){
                        content+='<ul class="singleline">';
                    }
                    link=news[i].getElementsByTagName('shortdesc')[j].getElementsByTagName('link')[0].getAttribute('url');
					title=news[i].getElementsByTagName('shortdesc')[j].getElementsByTagName('title')[0].childNodes[0].nodeValue;
					if (news[i].getElementsByTagName('shortdesc')[j].getElementsByTagName('link')[0].getAttribute('target')!=null){
						target="_blank";
					}
                    content+="<li><a href='"+link+"' target='"+target+"'>"+title+"</a></li>";
                    if (news[i].getElementsByTagName('shortdesc')[j].getAttribute('end')!=null||news[i].getElementsByTagName('shortdesc').length==1){
                        content+='</ul>';
                    }
                }
			}
		}
		if (news[i].getElementsByTagName('sub').length>0){
			content+='<p style="margin-bottom:0px;margin-top:0px;"><ul class="singleline" style="margin-left:15px;list-style-type:disc">';
			for (j=0;j<news[i].getElementsByTagName('sub').length;j++){
				//content+='&nbsp;&nbsp;&nbsp;- '+getLink(news[i].getElementsByTagName('sub')[j]).innerHTML+'<br/>';
				content+='<li>'+getLink(news[i].getElementsByTagName('sub')[j]).innerHTML+'</li>';
			}
			content+='</ul></p>';
			
		}
		content+='</li>';
		
	}
	var table = document.createElement('table');
	table.width="550";
	table.cellSpacing="0";
	//table.border="1";
	table.style.fontSize="13px";
	table.style.border="1px";
	table.style.borderStyle="solid";
	table.style.borderColor="#d5cdb7";
	table.style.marginTop="10px";
	//table.class="containerTable";
    row = table.insertRow(0);
	row.style.backgroundColor="#f4efe0";
	row.style.borderBottom="1px";
	row.style.borderBottomStyle="solid";
	row.style.borderBottomColor="#d5cdb7";
	row.style.color="#1f67a2";
	row.style.fontSize="12px";
	row.style.fontWeight="bold";
	row.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";
	
	cell = row.insertCell(0);
	cell.innerHTML+=tableName;
	cell.style.paddingLeft="10px";
	cell.style.paddingRight="10px";
	cell.style.paddingTop="5px";
	cell.style.paddingBottom="5px";

	
	cell = row.insertCell(1);
	//cell.innerHTML+='<a href="/ceo/ceohighlights.html?year='+currUserlinkYear+'&month='+currUserlinkMonth+'">more</a>';
	cell.style.textAlign="right";
	cell.style.paddingLeft="10px";
	cell.style.paddingRight="10px";
	cell.style.paddingTop="5px";
	cell.style.paddingBottom="5px";
	
	row = table.insertRow(1);
	cell = row.insertCell(0);
	//alert(navigator.appName);
	if (navigator.appName=="Microsoft Internet Explorer"){
		cell.innerHTML+='<ul style="margin-left:15px;margin-bottom:5px">'+content+'</ul>';
	}
	else{
		cell.innerHTML+='<ul style="margin-left:-25px;margin-bottom:5px">'+content+'</ul>';
	}
	cell.style.textAlign="justify";
	cell.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";
	cell.style.fontSize="1em";
	cell.style.paddingLeft="10px";
	cell.style.paddingRight="10px";
	cell.style.paddingTop="10px";
	//cell.style.paddingBottom="5px";
	//cell.colSpan="2";
	cell = row.insertCell(1);
	cell.width="50";
	//cell.innerHTML="150 width jpeg";
	cell.align="right";
	cell.vAlign="top";
	
	return table
}

function genNewsTable(news, tableName, custom, rightHeaderLink){
	
	var content;
	if (navigator.appName=="Microsoft Internet Explorer"){
		content='<ul style="margin-left:10px">';
	}
	else{
		content='<ul style="margin-left:-25px">';
	}
	if (custom){
		content=news;
	}
	else{
		var link,title;
		var target;
		for (i=0;i<news.length;i++){
			target="";
			if (news[i].getAttribute('sub')!="true" && news[i].getAttribute('subTitle')!="true"){
				if (news[i].getElementsByTagName('link').length>0){
					link=news[i].getElementsByTagName('link')[0].getAttribute('url');
					title=news[i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
					if (news[i].getElementsByTagName('link')[0].getAttribute('target')!=null){
						target="_blank";
					}
				}
				else{
					
					link=getLink(news[i]).getAttribute('href');
					//title=getLink(news[i]).childNode.nodeValue;
					title=getLink(news[i]).childNodes[0].nodeValue;
					
				}
				content+='<li style=font-size:12px;line-height:15px><a href="'+link+'" target="'+target+'">'+title+'</a><br/>';
				for (j=0;j<news[i].getElementsByTagName('shortdesc').length;j++){
					content+=news[i].getElementsByTagName('shortdesc')[j].childNodes[0].nodeValue;
				}
				//create sub content if sub.length > 0
				content+='<ul class="singleline">';
				for (j=0;j<news[i].getElementsByTagName('sub').length;j++){
					for (k=0;k<news.length;k++){
						if (news[k].getAttribute('id')==news[i].getElementsByTagName('sub')[j].getAttribute('id')){
							//check the sub news is under same month or not
							if (news[k].parentNode.getAttribute('month')==news[i].getElementsByTagName('sub')[j].parentNode.parentNode.getAttribute('month')){
								content+='<li style=font-size:12px;line-height:15px>';
								content+=news[k].getElementsByTagName('title')[0].childNodes[0].nodeValue;
								content+='</li>';
							}
						}
					}
				}
				content+='</ul>';
				content+='</li>';
			}
		}
		content+="</ul>"
	}
	
	var table = document.createElement('table');
	table.width="540";
	table.cellSpacing="0";
	//font-size: 1em; border: 1px solid #D5CDB7; margin-top:10px;" >
	table.style.fontSize="13px";
	table.style.border="1px";
	table.style.borderStyle="solid";
	table.style.borderColor="#d5cdb7";
	table.style.marginTop="10px";
	//table.class="containerTable";
    row = table.insertRow(0);
	row.style.backgroundColor="#f4efe0";
	row.style.borderBottom="1px";
	row.style.borderBottomStyle="solid";
	row.style.borderBottomColor="#d5cdb7";
	row.style.color="#1f67a2";
	row.style.fontSize="12px";
	row.style.fontWeight="bold";
	row.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";
	
	cell = row.insertCell(0);
	cell.innerHTML+=tableName;
	cell.style.paddingLeft="10px";
	cell.style.paddingRight="10px";
	cell.style.paddingTop="5px";
	cell.style.paddingBottom="5px";

	
	cell = row.insertCell(1);
	if (rightHeaderLink!=null){
		cell.innerHTML+='<a href="'+rightHeaderLink+'">more</a>';
	}
	cell.style.textAlign="right";
	cell.style.paddingLeft="10px";
	cell.style.paddingRight="10px";
	cell.style.paddingTop="5px";
	cell.style.paddingBottom="5px";
	
	row = table.insertRow(1);
	cell = row.insertCell(0);
	cell.innerHTML+=content;
	cell.style.textAlign="justify";
	cell.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";
	cell.style.fontSize="1em";
	cell.style.paddingLeft="10px";
	cell.style.paddingRight="30px";
	cell.style.paddingTop="10px";
	cell.style.paddingBottom="5px";
	cell.colSpan="2";
	/*cell = row.insertCell(1);
	cell.width="150";
	cell.innerHTML="150 width jpeg";
	cell.align="right";
	cell.vAlign="top";*/
	
	return table
}

function showJobDesc(){
	var ref = getQueries('ref');
	var jobs = xmlobject.getElementsByTagName('careers')[0].getElementsByTagName('job');
  var listIntro="";
	var listDescs="";
	var listReqs="";
  var listMore="";
  var jobemail="";
	for (i=0;i<jobs.length;i++){
		
		if (jobs[i].getAttribute('ref')==ref){
			//alert(jobs[i].getElementsByTagName('title')[0].childNodes[0].nodeValue);
      if (jobs[i].getAttribute('showMore')=="false"){
        document.getElementById('jobTitle').innerHTML+=jobs[i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
      }
      else
      {
        document.getElementById('jobTitle').innerHTML+=jobs[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+'('+jobs[i].getAttribute('ref')+')';
      }
      if(jobs[i].getElementsByTagName('intro').length > 0){
        document.getElementById('trIntro').style.display = 'block';
        for (j=0;j<jobs[i].getElementsByTagName('intro').length;j++){
          listIntro+='<p>'+jobs[i].getElementsByTagName('intro')[j].childNodes[0].nodeValue+'</p>';
        }
        document.getElementById('intros').innerHTML=listIntro;
      }
      else
        document.getElementById('trIntro').style.display = 'none';
      
			for (j=0;j<jobs[i].getElementsByTagName('desc').length;j++){
				listDescs+='<li>'+jobs[i].getElementsByTagName('desc')[j].childNodes[0].nodeValue+'</li>';
			}
			document.getElementById('descs').innerHTML=listDescs;
			for (j=0;j<jobs[i].getElementsByTagName('req').length;j++){
				listReqs+='<li>'+jobs[i].getElementsByTagName('req')[j].childNodes[0].nodeValue+'</li>';
			}
			document.getElementById('reqs').innerHTML=listReqs;
      
      if(jobs[i].getElementsByTagName('moreInfo').length > 0){
        document.getElementById('trMore').style.display = 'block';
        for (j=0;j<jobs[i].getElementsByTagName('moreInfo').length;j++){
          listMore+='<p>'+jobs[i].getElementsByTagName('moreInfo')[j].childNodes[0].nodeValue+'</p>';
        }
        document.getElementById('mores').innerHTML=listMore;
      }
      else
        document.getElementById('trMore').style.display = 'none';
      
      if (jobs[i].getAttribute('detail')=="false")
      {        
        document.getElementById('jobNeed').innerHTML = '<br>Please send your detailed resume and date of availability to the:';
      }
      else
      {
        document.getElementById('jobNeed').innerHTML = '<br>Please send your detailed resume with current &amp; expected salary and date of availability to the:';
      }
      
      if (jobs[i].getAttribute('otherEmail')=="true")
      {
        for (j=0;j<jobs[i].getElementsByTagName('email').length;j++){
          jobemail+=jobs[i].getElementsByTagName('email')[j].childNodes[0].nodeValue;
        }
        
        document.getElementById('details3').innerHTML = 'or via e-mail to&nbsp;<a href="mailto:' + jobemail + '">' + jobemail + '</a>';
      }
      else
      {
        document.getElementById('details3').innerHTML = 'or via e-mail to&nbsp;<a href="mailto:recruit@esrichina-hk.com">recruit@esrichina-hk.com</a>';
      }
      
      if (jobs[i].getAttribute('showMore')=="false"){
        document.getElementById('details1').style.display = 'none';
        document.getElementById('details2').style.display = 'none';
        document.getElementById('details3').style.display = 'none';
        document.getElementById('details4').style.display = 'none';
      }
      else
      {
        document.getElementById('details1').style.display = 'block';
        document.getElementById('details2').style.display = 'block';
        document.getElementById('details3').style.display = 'block';
        document.getElementById('details4').style.display = 'block';
      }
			break;
		}
	}
	
}

function showCareerTitles(){

	var jobs = xmlobject.getElementsByTagName('careers')[0].getElementsByTagName('job');
	var list="";
	for (i=0;i<jobs.length;i++){
		if (jobs[i].getAttribute('post')=="true"){
			var ref=jobs[i].getAttribute('ref');
			var title=jobs[i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
			
			var date = jobs[i].getElementsByTagName('date')[0].getAttribute('day')+'&nbsp;'+
				getLongMonthName(jobs[i].getElementsByTagName('date')[0].getAttribute('month'))+',&nbsp;'+
				jobs[i].getElementsByTagName('date')[0].getAttribute('year');
			list+='<li><a href="jobDESC.html?ref='+ref+'">'+title+
			'</a><br/>Posting Date:&nbsp;'+date+'</li>';
		}
	}
	document.getElementById('careersJobsTitle').innerHTML=list;
}

function showHighlights(){
	var year = getQueries('year');
	var month = getQueries('month');
	var monthName = getLongMonthName(month);
	document.getElementById('date').innerHTML+=monthName+'&nbsp;'+year;
	var headlineContent = xmlobject.getElementsByTagName('ceohighlights')[0].getElementsByTagName('highlight');
	//var flag=true;
	var content="";
	for (i=0;i<headlineContent.length;i++){
		if (headlineContent[i].getAttribute('month')==month){
			if (headlineContent[i].getAttribute('year')==year){
				for (j=0;j<headlineContent[i].getElementsByTagName('p').length;j++){
					//alert(headlineContent[i].getElementsByTagName('p').length);
					content+="<p>"+headlineContent[i].getElementsByTagName('p')[j].childNodes[0].nodeValue+"</p>";
				}
				break;
			}
		}
	}
	document.getElementById('ceoHighlight').innerHTML+=content;
	document.getElementById('ceoHighlight').innerHTML+='<a href="javascript:history.go(-1)">Back</a><br/><br/>';
}

function getQueries(name){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else    
		return results[1];
	}
// Roy
function gotoAnchor() {
  var hash=window.location.hash;
  if (hash.length>0) location.href=hash;
}

function showCEOPlace(){
	var ceoHeadLine = xmlobject.getElementsByTagName('ceohighlights')[0].getElementsByTagName('highlight');
	//var post = xmlobject.getElementsByTagName('esrihknews')[0].getElementsByTagName('post');
	var list="";
    
	for (i=0;i<ceoHeadLine.length;i++){
            if (i>12){
                break;
            }
			hlMonth = ceoHeadLine[i].getAttribute('month');
			hlYear = ceoHeadLine[i].getAttribute('year');
			//compare with userlink, vertify that is hidden or not
			//for (j=0;j<post.length;j++){
				//var userLinkMonth=post[j].getAttribute('month');
				//var userLinkYear=post[j].getAttribute('year');
				//if (userLinkMonth==month && userLinkYear==year){
					//if (post[j].getAttribute('hidden')!='true'){
						monthName = getLongMonthName(hlMonth);
						list+='<li><a href="/ceo/ceohighlights.html?year='+hlYear+'&month='+hlMonth+'">'
						+monthName+' '+hlYear+'</a></li>';
					//}
				//}
			//}
	}
	document.getElementById('ceohighlights').innerHTML=list;
	
}

function showAboutEsrihk(){
	var aboutEsrihk = xmlobject.getElementsByTagName('about');
	
	for (i=0;i<aboutEsrihk[0].getElementsByTagName('esrihk').length;i++){
		document.getElementById('aboutEsrihk').innerHTML+=aboutEsrihk[0].getElementsByTagName('esrihk')[i].childNodes[0].nodeValue+'<br/><br/>';
	}
	
	/*for (i=0;i<aboutEsrihk[0].getElementsByTagName('visionmission').length;i++){
		document.getElementById('visionMission').innerHTML+=aboutEsrihk[0].getElementsByTagName('visionmission')[i].childNodes[0].nodeValue+'<br/><br/>';
	}
	
	for (i=0;i<aboutEsrihk[0].getElementsByTagName('offer').length;i++){
		document.getElementById('offer').innerHTML+=aboutEsrihk[0].getElementsByTagName('offer')[i].childNodes[0].nodeValue+'<br/><br/>';
	}*/
}

function showVisionMission(){
	var aboutEsrihk = xmlobject.getElementsByTagName('about');
	if (document.getElementById('visionMission').innerHTML==""){
		for (i=0;i<aboutEsrihk[0].getElementsByTagName('visionmission').length;i++){
			document.getElementById('visionMission').innerHTML+=aboutEsrihk[0].getElementsByTagName('visionmission')[i].childNodes[0].nodeValue+'<br/><br/>';
		}
		document.getElementById('visionMission').innerHTML+='<a href="javascript:clearInnerHTML(\'visionMission\')">close</a>';
	}
}

function showOffer(){
	var aboutEsrihk = xmlobject.getElementsByTagName('about');
	if (document.getElementById('offer').innerHTML==""){
		for (i=0;i<aboutEsrihk[0].getElementsByTagName('offer').length;i++){
			document.getElementById('offer').innerHTML+=aboutEsrihk[0].getElementsByTagName('offer')[i].childNodes[0].nodeValue+'<br/><br/>';
		}
		document.getElementById('offer').innerHTML+='<a href="javascript:clearInnerHTML(\'offer\')">close</a>';
	}
}

function clearInnerHTML(object){
	document.getElementById(object).innerHTML="";
}

function showIndex(){
	//get	event node
	var news = xmlobject.getElementsByTagName('news');
	var eventNews = new Array();
	//var esriNews = new Array();
	//var localNews = new Array();
	//var productNews = new Array();
	var indexNews = new Array();
	var hasComingEvent=false;
	var noOfUserlink = xmlobject.getElementsByTagName('post');
	var latestUserlink;
	for (i=0;i<noOfUserlink.length;i++){
		if (noOfUserlink[i].getAttribute('hidden')!="true"){
			latestUserlink=noOfUserlink[i].getAttribute('month');
			break;
		}
	}
	for (i=0;i<news.length&&news[i].parentNode.getAttribute('month')==latestUserlink;i++){
		// if (xmlobject.getElementsByTagName('news')[i].getAttribute('index')){
			//indexNews.push(xmlobject.getElementsByTagName('news')[i]);
		 // }
		 // else if (xmlobject.getElementsByTagName('news')[i].getAttribute('type')=="event"){
			 // eventNews.push(xmlobject.getElementsByTagName('news')[i]);
		// }
		if (xmlobject.getElementsByTagName('news')[i].getAttribute('showInIndex')=="true"){
			if (xmlobject.getElementsByTagName('news')[i].getAttribute('type')=="comingevent"){
				eventNews.push(xmlobject.getElementsByTagName('news')[i]);
			}
			else{
				if (xmlobject.getElementsByTagName('news')[i].parentNode.getAttribute('hidden')!="true"){
					indexNews.push(xmlobject.getElementsByTagName('news')[i]);
				}
			}
		}
		/*else if (xmlobject.getElementsByTagName('news')[i].getAttribute('type')=='us'){
			esriNews.push(xmlobject.getElementsByTagName('news')[i]);
		}
		/*else if (xmlobject.getElementsByTagName('news')[i].getAttribute('type')=='local'){
			//alert(xmlobject.getElementsByTagName('news')[i].getAttribute('type'));
			localNews.push(xmlobject.getElementsByTagName('news')[i]);
		}
		/*else if (xmlobject.getElementsByTagName('news')[i].getAttribute('type')=='product'){
			esriNews.push(xmlobject.getElementsByTagName('news')[i]);
		}
		/*else if (xmlobject.getElementsByTagName('news')[i].getAttribute('type')=='innovative'){
			esriNews.push(xmlobject.getElementsByTagName('news')[i]);
		}*/
		
	}
	
	//for (i=0;i<eventNews.length;i++){
	for (i=0;i<eventNews.length;i++){
		/*requirement changed
			only show news in the latest userlink
			march 2008
		*/
		var today = setDateObj(strToday);
		var duration;
        if (eventNews[i].getElementsByTagName('eventdate').length!=0){
        
        if (eventNews[i].getElementsByTagName('eventdate')[0].getElementsByTagName('start').length!=0){
            var node = eventNews[i].getElementsByTagName('eventdate')[0].getElementsByTagName('start')[0];
            var eventDate =setDateObj(node.getAttribute('day')+"/"+node.getAttribute('month')+"/"+node.getAttribute('year'));
            //if ((parseInt(node.getAttribute('month'))+parseInt(node.getAttribute('year'))*12)>(today.getMonth()+today.getFullYear()*12)){
            
            if (eventDate>today){
                //alert(today+"\n"+eventDate);
    			hasComingEvent=true;
    			duration = getEventDuration(eventNews[i].getElementsByTagName('eventdate')[0]);
    			
    			if (eventNews[i].getElementsByTagName('link').length>0){
    				var target;
    				//get url from xml if link is linked to another page
    				//else
    				//gen link included year and local post index in array format
    				eventNews[i].getElementsByTagName('link')[0].getAttribute('target')==null?target='':target='_blank';
    				document.getElementById('eventList').innerHTML+='<dt><a href="'
    				+eventNews[i].getElementsByTagName('link')[0].getAttribute('url')+'" target="'+target+'">'
    				+eventNews[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+
    				'</a></dt><dd>'+duration+'&nbsp;&middot;&nbsp;'
    				+eventNews[i].getElementsByTagName('location')[0].childNodes[0].nodeValue+'<br></dd>';
    			}
    			else{
    				document.getElementById('eventList').innerHTML+='<dt><a href="../events/comingEventInfo.html?year='+eventNews[i].parentNode.getAttribute('year')+'&month='+eventNews[i].parentNode.getAttribute('month')+'&id='+eventNews[i].getAttribute('id')+'">'+eventNews[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a></dt>'+
    				'<dd>'+duration+'&nbsp;&middot;&nbsp;'+eventNews[i].getElementsByTagName('location')[0].childNodes[0].nodeValue+'<br></dd>';
    			}
    		}
        }
        else{
            var node = eventNews[i].getElementsByTagName('eventdate')[0].getElementsByTagName('end')[0];
           
            if ((parseInt(node.getAttribute('month'))+parseInt(node.getAttribute('year'))*12)>(today.getMonth()+today.getFullYear()*12)){
            
                hasComingEvent=true;
                if (eventNews[i].getElementsByTagName('link').length>0){
    				var target;
    				//get url from xml if link is linked to another page
    				//else
    				//gen link included year and local post index in array format
    				eventNews[i].getElementsByTagName('link')[0].getAttribute('target')==null?target='':target='_blank';
    				document.getElementById('eventList').innerHTML+='<dt><a href="'
    				+eventNews[i].getElementsByTagName('link')[0].getAttribute('url')+'" target="'+target+'">'
    				+eventNews[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+
    				'</a></dt><dd>'
    				+eventNews[i].getElementsByTagName('shortdesc')[0].childNodes[0].nodeValue+'<br></dd>';
    			}
    			else{
    				document.getElementById('eventList').innerHTML+='<dt><a href="../events/comingEventInfo.html?year='+eventNews[i].parentNode.getAttribute('year')+'&month='+eventNews[i].parentNode.getAttribute('month')+'&id='+eventNews[i].getAttribute('id')+'">'+eventNews[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a></dt>'+
    				'<dd>'+eventNews[i].getElementsByTagName('shortdesc')[0].childNodes[0].nodeValue+'<br></dd>';
    			}
            }
        }
        }
        else{
            if ((parseInt(node.getAttribute('month'))+parseInt(node.getAttribute('year'))*12)>(today.getMonth()+today.getFullYear()*12)){
    			hasComingEvent=true;
    			//duration = getEventDuration(eventNews[i].getElementsByTagName('eventdate')[0]);
    			loc=eventNews[i].getElementsByTagName('shortdesc')[0].childNodes[0].nodeValue;
    			if (eventNews[i].getElementsByTagName('link').length>0){
    				var target;
    				//get url from xml if link is linked to another page
    				//else
    				//gen link included year and local post index in array format
    				eventNews[i].getElementsByTagName('link')[0].getAttribute('target')==null?target='':target='_blank';
    				document.getElementById('eventList').innerHTML+='<dt><a href="'
    				+eventNews[i].getElementsByTagName('link')[0].getAttribute('url')+'" target="'+target+'">'
    				+eventNews[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+
    				'</a></dt><dd>'+loc+'<br></dd>';
    			}
    			else{
    				document.getElementById('eventList').innerHTML+='<dt><a href="../events/comingEventInfo.html?year='+eventNews[i].parentNode.getAttribute('year')+'&month='+eventNews[i].parentNode.getAttribute('month')+'&id='+eventNews[i].getAttribute('id')+'">'+eventNews[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a></dt>'+
    				'<dd>'+loc+'<br></dd>';
    			}
    		}
        }
        
	}
	if (!hasComingEvent){
		document.getElementById('comingEventHeader').innerHTML="No Scheduled";
	}
	

	for (i=0;(i<indexNews.length && i<=3);i++){
		//alert(i);
		row = document.getElementById('esrihknews').insertRow(i);
		cell = row.insertCell(0);
		//var link;
		if (indexNews[i].getElementsByTagName('link').length==0){
			
			newEl=xmlobject.createElement('link');
			urlAtt=xmlobject.createAttribute('url');
			urlAtt.value=getLink(indexNews[i]).getAttribute('href');
			newEl.setAttributeNode(urlAtt);
			indexNews[i].appendChild(newEl);
			
		}
		if (indexNews[i].getElementsByTagName('shortdesc').length>0){
			
			var target;
			indexNews[i].getElementsByTagName('link')[0].getAttribute('target')==null?target='':target='_blank';
			cell.innerHTML+='<h4><a target="'+target+'" href="'
			+indexNews[i].getElementsByTagName('link')[0].getAttribute('url')+'">'
			+indexNews[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a></h4>'
            
            for (j=0; j<indexNews[i].getElementsByTagName('shortdesc').length; j++){
                if (j==0){
                    cell.innerHTML+="<dl style='line-height:10px;font-size:x-small;margin:0px 0px 5px 5px'>"
                }
                if((indexNews[i].getElementsByTagName('shortdesc')[j].getElementsByTagName('title').length==0&&indexNews[i].getElementsByTagName('shortdesc')[j].getElementsByTagName('link').length==0)&&indexNews[i].getElementsByTagName('shortdesc')[j].childNodes.length>0){
                    cell.innerHTML+='<dt>'+indexNews[i].getElementsByTagName('shortdesc')[j].childNodes[0].nodeValue;+'</dt>'
                }
                else if(indexNews[i].getElementsByTagName('shortdesc')[j].getElementsByTagName('title').length>0&&indexNews[i].getElementsByTagName('shortdesc')[j].getElementsByTagName('link').length>0){
                    link=indexNews[i].getElementsByTagName('shortdesc')[j].getElementsByTagName('link')[0].getAttribute('url');
					title=indexNews[i].getElementsByTagName('shortdesc')[j].getElementsByTagName('title')[0].childNodes[0].nodeValue;
					if (indexNews[i].getElementsByTagName('shortdesc')[j].getElementsByTagName('link')[0].getAttribute('target')!=null){
						target="_blank";
					}
                    cell.innerHTML+="<dt style='line-height:12px;font-size:x-small;margin:0px 0px 5px 5px'><a href='"+link+"' target='"+target+"'>"+title+"</a></dt>";
                }
                if (j==0){
                    cell.innerHTML+='</dl>'
                }

            }
            /*+'<dl style="line-height:10px;font-size:xx-small;margin:0px 0px 5px 5px"><dt>123</dt><dt>123</dt></dl>'
            +'<ul class="singleline" style="font-size:xx-small;padding-left:15px;margin-left:0px"><li>123</li></ul>'
			+indexNews[i].getElementsByTagName('shortdesc')[0].childNodes[0].nodeValue;*/
		}
		else{
			indexNews[i].getElementsByTagName('link')[0].getAttribute('target')==null?target='':target='_blank';
			cell.innerHTML+='<h4><a target="'+target+'" href="'
			+indexNews[i].getElementsByTagName('link')[0].getAttribute('url')+'">'
			+indexNews[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a></h4></p>';
		}
	}
	
	var cases = xmlobject.getElementsByTagName('esrihkshowcase')[0].getElementsByTagName('case');
	
	/*var index = new Array();
	var inArray=false;
	var num;
	while (index.length<3){
		num=getRandom(cases.length);
		for (j=0;j<index.length;j++){
			if (num==index[j]){
				inArray=true;
			}
		}
		if (!inArray){
			index.push(num);
			//alert(num);
		}
		inArray-false;
		
	}*/
	
	for (i=0;i<cases.length && i<3;i++){
		row = document.getElementById('esrihkshowcase').insertRow(i);
		cell = row.insertCell(0);
		
		link='http://'+location.hostname+'/industries/localcase.html?id='+cases[i].getAttribute('id');
		cell.innerHTML+='<h4><a target="'+target+'" href="'+link+'">'
		+cases[i].getElementsByTagName('title')[0].childNodes[0].nodeValue+'</a></h4><p>'
		+cases[i].getElementsByTagName('client')[0].childNodes[0].nodeValue+'</p>';
	}
	
	
}

function getNPLink(){
}

function getRandom(length)
{
    var ranNum= Math.floor(Math.random()*length);
    return ranNum;
}


function getShortMonthName(month){
	if (typeof(month)!="number"){
		month=parseInt(month);
	}
	var monthName;
	switch(month){
		case 1:
			monthName="Jan";
			break;
		case 2:
			monthName="Feb";
			break;
		case 3:
			monthName="Mar";
			break;
		case 4:
			monthName="Apr";
			break;
		case 5:
			monthName="May";
			break;
		case 6:
			monthName="Jun";
			break;
		case 7:
			monthName="Jul";
			break;
		case 8:
			monthName="Aug";
			break;
		case 9:
			monthName="Sep";
			break;
		case 10:
			monthName="Oct";
			break;
		case 11:
			monthName="Nov";
			break;
		case 12:
			monthName="Dec";
			break;
	}
	return monthName;
}

function daysInMonth(iMonth, iYear)
{
	return 32 - new Date(iYear, iMonth, 32).getDate();
}


function getLongMonthName(month){
	if (typeof(month)!="number"){
		month=parseInt(month);
	}
	var monthName;
	switch(month){
		case 1:
			monthName="January";
			break;
		case 2:
			monthName="February";
			break;
		case 3:
			monthName="March";
			break;
		case 4:
			monthName="April";
			break;
		case 5:
			monthName="May";
			break;
		case 6:
			monthName="June";
			break;
		case 7:
			monthName="July";
			break;
		case 8:
			monthName="August";
			break;
		case 9:
			monthName="September";
			break;
		case 10:
			monthName="October";
			break;
		case 11:
			monthName="November";
			break;
		case 12:
			monthName="December";
			break;
	}
	return monthName;
}

function setDateObj(date){
	today =new Date();
    today.setYear(date.substring(date.lastIndexOf("/")+1));
	today.setMonth((date.substring(date.indexOf("/")+1,date.lastIndexOf("/")))-1);
	today.setDate(date.substring(0,date.indexOf("/")));
    return today;
}

function getEventDuration(node){
	if (node.getElementsByTagName('end')[0]==null){
        node=node.getElementsByTagName('start')[0]
		duration= getShortMonthName(node.getAttribute('month'))+'&nbsp;'+node.getAttribute('day')+',&nbsp;'+node.getAttribute('year');
	}
	else{
		var startMonth = node.getElementsByTagName('start')[0].getAttribute('month');
		var endMonth = node.getElementsByTagName('end')[0].getAttribute('month');
		if (startMonth==endMonth){
			duration= getShortMonthName(node.getElementsByTagName('start')[0].getAttribute('month'))
			+'&nbsp;'+node.getElementsByTagName('start')[0].getAttribute('day')+'&nbsp;-&nbsp;'
			+node.getElementsByTagName('end')[0].getAttribute('day')+',&nbsp;'
			+node.getElementsByTagName('end')[0].getAttribute('year');
		}
		else{
			duration= getShortMonthName(node.getElementsByTagName('start')[0].getAttribute('month'))
			+'&nbsp;'+node.getElementsByTagName('start')[0].getAttribute('day')+'&nbsp;-&nbsp;'
			+getShortMonthName(node.getElementsByTagName('end')[0].getAttribute('month'))+'&nbsp;'
			+node.getElementsByTagName('end')[0].getAttribute('day')+',&nbsp;'
			+node.getElementsByTagName('end')[0].getAttribute('year');
		}
		
	}
	return duration;
}


function convertLink(url,text){
	return "<a href='url'>"+text+"</a>"
}

function showBookList(){
	var localCases = xmlobject.getElementsByTagName('esripress')[0].getElementsByTagName('pressbook');
	var localCasesTitle ='';
  
	for(i=0;i<localCases.length;i++){
		row = document.getElementById('lctitle').insertRow(i);
		
    if (localCases[i].getAttribute('disable') != "true"){
      cell = row.insertCell(0);    
      cell.innerHTML+='<a href="bookdetails.html?id=' + localCases[i].getAttribute('id') + '">' + localCases[i].getElementsByTagName('name')[0].childNodes[0].nodeValue+'</a>';
      pricecell = row.insertCell(1);
      pricecell.innerHTML+='HK$' + localCases[i].getElementsByTagName('price')[0].childNodes[0].nodeValue;
    }
	}
}

function showBookDetails(){
	var qId = getQueries('id');
  
	var localCases = xmlobject.getElementsByTagName('esripress')[0].getElementsByTagName('pressbook');
	var localCasesTitle ='';
  
	for(i=0;i<localCases.length;i++){
    if (localCases[i].getAttribute('id') == qId){
    
      //Title
      document.getElementById('bookTitle').innerHTML=localCases[i].getElementsByTagName('name')[0].childNodes[0].nodeValue;
      if (localCases[i].getElementsByTagName('slogan').length != 0){
        document.getElementById('bookSubTitle').innerHTML='<br>' +localCases[i].getElementsByTagName('slogan')[0].childNodes[0].nodeValue;
    }
      
      //Description
  		row = document.getElementById('bkdetails'); 
      
      if (localCases[i].getElementsByTagName('slogan').length != 0){
      row.innerHTML+='<img alt="'+localCases[i].getElementsByTagName('name')[0].childNodes[0].nodeValue + ': ' + localCases[i].getElementsByTagName('slogan')[0].childNodes[0].nodeValue +'" align="right" hspace="10" vspace="10" src="images/'+localCases[i].getElementsByTagName('image')[0].getAttribute('file')+'">';
    }
    else{
      row.innerHTML+='<img alt="'+localCases[i].getElementsByTagName('name')[0].childNodes[0].nodeValue +'" align="right" hspace="10" vspace="10" src="images/'+localCases[i].getElementsByTagName('image')[0].getAttribute('file')+'">';
    }
      
      for (j=0;j<localCases[i].getElementsByTagName('description').length;j++){
        row.innerHTML+='<p>' + localCases[i].getElementsByTagName('description')[j].childNodes[0].nodeValue + '</p>';
      }
      
      if (localCases[i].getElementsByTagName('aboutauther').length != 0){
        row.innerHTML+='<p><b>About the editors:</b></p>';
        
        for (k=0;k<localCases[i].getElementsByTagName('aboutauther').length;k++){
          row.innerHTML+='<p>' + localCases[i].getElementsByTagName('aboutauther')[k].childNodes[0].nodeValue + '</p>';
        }
      }
      
      row.innerHTML+='<p>';
      if (localCases[i].getElementsByTagName('ISBN').length != 0){
        row.innerHTML+='ISBN: ' + localCases[i].getElementsByTagName('ISBN')[0].childNodes[0].nodeValue;
      }
      
      if (localCases[i].getElementsByTagName('year').length != 0){
        row.innerHTML+='&nbsp;&nbsp;&nbsp;&nbsp;' + localCases[i].getElementsByTagName('year')[0].childNodes[0].nodeValue;
      }
      
      if (localCases[i].getElementsByTagName('page').length != 0){
        if (localCases[i].getElementsByTagName('page')[0].childNodes[0].nodeValue != "-")
          row.innerHTML+='&nbsp;&nbsp;&nbsp;&nbsp;' + localCases[i].getElementsByTagName('page')[0].childNodes[0].nodeValue + ' pages';
      }
      
      if (localCases[i].getElementsByTagName('price').length != 0){
        row.innerHTML+='&nbsp;&nbsp;&nbsp;&nbsp;HK$' + localCases[i].getElementsByTagName('price')[0].childNodes[0].nodeValue;
      }
      row.innerHTML+='</p>';
      row.innerHTML+='<a href="press2.html">Back</a>'
      
      break;
    }
    
	}
}

function showSupportUtilities(){
	var utilities = xmlobject.getElementsByTagName('download')[0].getElementsByTagName('utilities');
    var list= document.getElementById('utilitiesList');
    list.innerHTML="";
    for(i=0;i<utilities.length;i++){
        var listItem= document.createElement("li")
        var anchor = document.createElement("a");
        anchor.setAttribute("href", "utilitiesInfo.html?id="+ utilities[i].getAttribute('id'));
        anchor.innerHTML=utilities[i].getAttribute('name') +"<span class='detail' style='text-decoration:none;'> "//+utilities[i].getElementsByTagName('release')[0].getAttribute('day')+" "+getShortMonthName(utilities[i].getElementsByTagName('release')[0].getAttribute('month'))+" ,"+utilities[i].getElementsByTagName('release')[0].getAttribute('year')+"</span>";
        listItem.appendChild(anchor);
        list.appendChild(listItem);
    }
    
}
function showSupportUtilitiesInfo(){
	var utilities = xmlobject.getElementsByTagName('download')[0].getElementsByTagName('utilities');
	var qId = getQueries('id');
    
    for(i=0;i<utilities.length;i++){
        if (utilities[i].getAttribute('id') == qId){
            document.getElementById('utilities').innerHTML=utilities[i].getAttribute('name');
            for (j=0;j<utilities[i].getElementsByTagName('desc').length;j++){
                document.getElementById('desc').innerHTML+="<p style='text-align:justify;'>"+utilities[i].getElementsByTagName('desc')[j].childNodes[0].nodeValue + "</p>";
            }
            document.getElementById('version').innerHTML=utilities[i].getElementsByTagName('version')[0].childNodes[0].nodeValue;
            document.getElementById('release').innerHTML=utilities[i].getElementsByTagName('release')[0].getAttribute('day')+" "+getLongMonthName(utilities[i].getElementsByTagName('release')[0].getAttribute('month'))+", "+utilities[i].getElementsByTagName('release')[0].getAttribute('year');
            document.getElementById('program').innerHTML=utilities[i].getElementsByTagName('program')[0].childNodes[0].nodeValue;
            document.getElementById('dependency').innerHTML=utilities[i].getElementsByTagName('dependency')[0].childNodes[0].nodeValue;
            document.getElementById('language').innerHTML=utilities[i].getElementsByTagName('language')[0].childNodes[0].nodeValue;
            document.getElementById('platform').innerHTML=utilities[i].getElementsByTagName('platform')[0].childNodes[0].nodeValue;
            //document.getElementById('filename').innerHTML=utilities[i].getElementsByTagName('filename')[0].childNodes[0].nodeValue;
            //document.getElementById('filesize').innerHTML=utilities[i].getElementsByTagName('filesize')[0].childNodes[0].nodeValue;
            var download = document.getElementById("download");
            var anchor = document.createElement("a");
            anchor.setAttribute("href", "download.aspx?filename="+utilities[i].getElementsByTagName('filename')[0].childNodes[0].nodeValue+"."+utilities[i].getElementsByTagName('filename')[0].getAttribute('extension'));
            anchor.innerHTML=utilities[i].getElementsByTagName('filename')[0].childNodes[0].nodeValue;
            download.appendChild(anchor);
            download.innerHTML+=" <span class='detail'>"+utilities[i].getElementsByTagName('filename')[0].getAttribute('extension')+" - "+utilities[i].getElementsByTagName('filesize')[0].childNodes[0].nodeValue;+"</span>";
            
            //document.getElementByID('download').href="2345";
            break;
        }
    }
}
