﻿// genernal function
function Website_Init(page){
	var tempObject=new Object();
	var tempTagObject=new Object();
	
	// header
	tempObject=new Object();
	tempTagObject=new Object();
	this.TempXML=this.loadXML("resources/xml/common/header.xml");
	tempTagObject["items"]="items";
	tempTagObject["item"]="item";
	tempTagObject["title"]="title";
	tempTagObject["link"]="link";
	tempTagObject["image"]="image";
	tempTagObject["url"]="url";
	for(var i=0;i<this.TempXML.getElementsByTagName(tempTagObject["items"]).length;i++){
		if(this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getAttribute("name")=="socialmedia"){
			try{
				for(var j=0;j<this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"]).length;j++){
					tempObject["title"]=this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getElementsByTagName(tempTagObject["title"])[0].getAttribute(this.define_lang_code["en"]);
					tempObject["link"]=this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getElementsByTagName(tempTagObject["link"])[0].getAttribute(this.define_lang_code["en"]);
					tempObject["image_url"]=this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getElementsByTagName(tempTagObject["image"])[0].getElementsByTagName(tempTagObject["url"])[0].childNodes[0].nodeValue;
				document.getElementById("socialmedia"+(j+1)).innerHTML=" <img src=\"" + tempObject["image_url"] + "\" class=\"topicon\" alt=\"" + tempObject["title"] + "\"> " + this.setURL(tempObject["title"],tempObject["link"]) + " ";
				}
			}catch(error){
			}
		} else if(this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getAttribute("name")=="navigation"){
			try{
				for(var j=0;j<this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"]).length;j++){
					tempObject["title"]=this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getElementsByTagName(tempTagObject["title"])[0].getAttribute(this.define_lang_code[this.lang]);
					tempObject["link"]=this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getElementsByTagName(tempTagObject["link"])[0].getAttribute(this.define_lang_code[this.lang]);
					document.getElementById("header_navigation"+(j+1)).innerHTML=this.setURL(tempObject["title"],tempObject["link"]);
				}
			}catch(error){
			}
		} else if(this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getAttribute("name")=="lang_select"){
			try{
				for(var j=0;j<this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"]).length;j++){
					tempObject["title"]=this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getAttribute("text");
					tempObject["link"]=this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getAttribute("code");
					document.getElementById("lang_select").options[document.getElementById("lang_select").length]=new Option(tempObject["title"],tempObject["link"]);
					}
				//}
			}catch(error){}
		}
	}
	this.TempXML=this.loadXML("/resources/xml/sitemap.xml",true);
	try{
		var root=this.TempXML.getElementsByTagName("root")[0],c=1;//counter
		for(var j=0;j<root.childNodes.length;j++){
			if(root.childNodes[j].nodeType==3||root.childNodes[j].nodeType==8)continue;
			if(root.childNodes[j].getAttribute("hidden").indexOf(1)>=0||root.childNodes[j].getAttribute("hidden").indexOf("true")>=0)continue;
			var mapping,rows=new Array();
			switch(c){case 1:mapping=1;break;case 2:mapping=2;break;case 3:mapping=7;break;case 4:mapping=3;break;case 5:mapping=6;break;}
			rows.push("<li><h2><!--img src=\"../../resources/images/common/icon_0"+mapping+".gif\" class=\"icon\" /-->"+root.childNodes[j].getAttribute(this.define_lang_code[this.lang])+"</h2>");
			var items=root.childNodes[j].childNodes;
			if(items.length>0)rows.push("<ul>");
			this.loadMenuBarItems(items, rows);
			if(items.length>0)rows.push("</ul>");rows.push("</li>");
			document.getElementById("header_banner"+mapping).innerHTML=rows.join("");
			c++;
		}
	}catch(error){}
	// start of index page initial
	if(page=="index"){
		// index content
		tempObject=new Object();
		tempTagObject=new Object();
		tempTagObject["component"]="component";
		tempTagObject["title"]="title";
		tempTagObject["item"]="item";
		tempTagObject["description"]="description";
		tempTagObject["link"]="link";
		tempTagObject["image"]="image";
		tempTagObject["url"]="url";
		
		this.TempXML=this.loadXML("resources/xml/common/"+this.lang+"_index.xml");
		// website title
		try{
			document.title=this.TempXML.getElementsByTagName(tempTagObject["title"])[0].childNodes[0].nodeValue;
		}catch(error){}
			
		for(var j=0;j<this.TempXML.getElementsByTagName(tempTagObject["component"]).length;j++){
			
			// content 1 or 9 or 10 or 11
			if(this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id")=="1" || this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id")=="9" || this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id")=="10" || this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id")=="11"){
				var temp_id=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id");
				
				tempObject=new Object();
				
				try{
					tempObject["section_title"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["title"])[0].childNodes[0].nodeValue;
				}catch(error){
				}
				try{
					tempObject["title"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"])[0].getElementsByTagName(tempTagObject["title"])[0].childNodes[0].nodeValue;					}catch(error){
				}
				try{
					tempObject["description"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"])[0].getElementsByTagName(tempTagObject["description"])[0].childNodes[0].nodeValue;
				}catch(error){
				}
				try{
					tempObject["link"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"])[0].getElementsByTagName(tempTagObject["link"])[0].childNodes[0].nodeValue;
				}catch(error){
				}
				try{
					tempObject["image_link"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"])[0].getElementsByTagName(tempTagObject["image"])[0].getElementsByTagName(tempTagObject["link"])[0].childNodes[0].nodeValue;
				}catch(error){
				}
				try{
					tempObject["image_url"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"])[0].getElementsByTagName(tempTagObject["image"])[0].getElementsByTagName(tempTagObject["url"])[0].childNodes[0].nodeValue;
				}catch(error){
				}
				document.getElementById("channel"+temp_id+"_title").innerHTML=tempObject["section_title"];
				document.getElementById("channel"+temp_id+"_description").innerHTML=tempObject["description"];
				//document.getElementById("channel"+temp_id+"_button").innerHTML=this.setURL('<img src="../../resources/images/common/btn_01_bullet.gif"  class="btnbullet"/> ' + tempObject["title"],tempObject["link"]);
			}
			
			// content 2
			else if(this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id")=="2"){
				var temp_id=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id");
				
				tempObject=new Object();
				
				try{
					tempObject["section_title"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["title"])[0].childNodes[0].nodeValue;
				}catch(error){
				}
				try{
					tempObject["title"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"])[0].getElementsByTagName(tempTagObject["title"])[0].childNodes[0].nodeValue;
				}catch(error){
				}
				try{
					tempObject["description"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"])[0].getElementsByTagName(tempTagObject["description"])[0].childNodes[0].nodeValue;
				}catch(error){
				}
				try{
					tempObject["link"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"])[0].getElementsByTagName(tempTagObject["link"])[0].childNodes[0].nodeValue;
				}catch(error){
				}
				try{
					tempObject["image_link"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"])[0].getElementsByTagName(tempTagObject["image"])[0].getElementsByTagName(tempTagObject["link"])[0].childNodes[0].nodeValue;
				}catch(error){
				}
				try{
					tempObject["image_url"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"])[0].getElementsByTagName(tempTagObject["image"])[0].getElementsByTagName(tempTagObject["url"])[0].childNodes[0].nodeValue;
				}catch(error){
				}
				document.getElementById("channel"+temp_id+"_title").innerHTML=tempObject["section_title"];
				document.getElementById("channel"+temp_id+"_description").innerHTML=tempObject["description"];
				//document.getElementById("channel"+temp_id+"_button").innerHTML=this.setURL('<img src="../../resources/images/common/btn_02_bullet.gif"  class="btnbullet"/> ' + tempObject["title"],tempObject["link"]);
				//document.getElementById("channel"+temp_id+"_button").innerHTML=this.setURL(tempObject["title"],tempObject["link"]);
			}
			
			// content 3, 12,13,14
			else if(this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id")=="3" ||
					this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id")=="12" ||
					this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id")=="13" ||
					this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id")=="14"){
				tempObject=new Object();
				var temp_id=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id");
				
				try{
					tempObject["section_title"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["title"])[0].childNodes[0].nodeValue;
				}catch(error){}
				document.getElementById("channel"+temp_id+"_section_title").innerHTML=tempObject["section_title"];
					
				for(var k=0;k<this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"]).length;k++){
					tempObject=new Object();
					try{
						tempObject["title"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"])[k].getElementsByTagName(tempTagObject["title"])[0].childNodes[0].nodeValue;
					}catch(error){}
					try{
						tempObject["description"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"])[k].getElementsByTagName(tempTagObject["description"])[0].childNodes[0].nodeValue;
					}catch(error){}
					try{
						tempObject["link"]=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"])[k].getElementsByTagName(tempTagObject["link"])[0].childNodes[0].nodeValue;
					}catch(error){}
					var img=this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getElementsByTagName(tempTagObject["item"])[k].getElementsByTagName(tempTagObject["image"]);
					if(img.length>0){
						try{
						tempObject["image_link"]=img[0].getElementsByTagName(tempTagObject["link"])[0].childNodes[0].nodeValue;
						}catch(error){}
						try{
						tempObject["image_url"]=img[0].getElementsByTagName(tempTagObject["url"])[0].childNodes[0].nodeValue;
						}catch(error){}
						document.getElementById("channel"+temp_id+"_button"+(k+1)).innerHTML=this.setURL("<img  src=\""+tempObject["image_url"]+"\"/>",tempObject["link"]);
					}else
						document.getElementById("channel"+temp_id+"_button"+(k+1)).innerHTML=this.setURL(tempObject["title"],tempObject["link"]);
				}
			/*}else if(this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id")=="6"){
				var c=this.TempXML.getElementsByTagName(tempTagObject["component"])[j];
				document.getElementById("channel6_section_title").innerHTML=c.getElementsByTagName("title")[0].firstChild.nodeValue;
				document.getElementById("channel6_content").innerHTML=c.getElementsByTagName("description")[0].firstChild.nodeValue;
			}else if(this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id")=="7"){
				var c=this.TempXML.getElementsByTagName(tempTagObject["component"])[j];
				document.getElementById("channel7_section_title").innerHTML=c.getElementsByTagName("title")[0].firstChild.nodeValue;
				document.getElementById("channel7_content").innerHTML=c.getElementsByTagName("description")[0].firstChild.nodeValue;*/
			}else if(this.TempXML.getElementsByTagName(tempTagObject["component"])[j].getAttribute("id")=="8"){
				var rows=new Array();
				var c=this.TempXML.getElementsByTagName(tempTagObject["component"])[j];
				rows.push("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td class=\"conthdframe\"><h4><span class=\"conthd\">"+c.getElementsByTagName("title")[0].childNodes[0].nodeValue+"</span></h4></td></tr>");
				var items=c.getElementsByTagName("item");
				for(var k=0;k<items.length;k++){
					rows.push("<tr><td><span class=\"btnlight\"><a href=\""+items[k].getAttribute("link")+"\" target=\"_blank\">"+items[k].getAttribute("description")+"</a></span></td></tr>");}rows.push("</table>");
				document.getElementById("show_sponsoredlink").innerHTML=rows.join("\n");
			}
		}
		
		// index content's ihk news
		this.TempXML=this.loadXML("resources/xml/common/"+this.lang+"_hottopic.xml");
		var rows=new Array();
		//var mths=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		var mths=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
		rows.push("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");var items=this.TempXML.getElementsByTagName("item");
		rows.push("<tr><td class=\"alitop\" colspan=\"3\"><table><tr><td class=\"alitop\">");
		if(items[0].getElementsByTagName("image")[0]==null) rows.push("<img  src=\"../../resources/images/news/default.jpg\" style=\"width:115px;\"/>");
		else {rows.push("<img style=\"width:115px;\" src=\""+items[0].getElementsByTagName("image")[0].getElementsByTagName("url")[0].childNodes[0].nodeValue);
		alt_text=items[0].getElementsByTagName("title")[0].childNodes[0].nodeValue.replace(/"/g,"&quot;");
		rows.push("\" alt=\""+ alt_text +"\" />")}
		rows.push("</td><td class=\"colminmid\">&nbsp;</td><td class=\"alitop\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><h6><span class=\"newstext\">");
			var d=items[0].getElementsByTagName("newsDate")[0];
			rows.push("<a href=\""+items[0].getElementsByTagName("link")[0].childNodes[0].nodeValue+"\">"+items[0].getElementsByTagName("title")[0].childNodes[0].nodeValue+"</a><br/><span class=\"date\">");
			if (this.lang=="sc" || this.lang=="tc"){
				rows.push(d.getElementsByTagName("year")[0].childNodes[0].nodeValue+"年");				
				rows.push(d.getElementsByTagName("month")[0].childNodes[0].nodeValue+"月");
				rows.push(d.getElementsByTagName("day")[0].childNodes[0].nodeValue+"日");
			}
			else {
				rows.push(d.getElementsByTagName("day")[0].childNodes[0].nodeValue+" ");
				rows.push(mths[d.getElementsByTagName("month")[0].childNodes[0].nodeValue-1]);
				rows.push(" "+d.getElementsByTagName("year")[0].childNodes[0].nodeValue);
			}
			rows.push("</span><br /></span></h6></td></tr></table></td></tr></table></td></tr><table>");
		for(var i=1;i<5&&i<items.length;i++){
			rows.push("<tr><td class=\"alitop hottopicframe\">");
			if(items[i].getElementsByTagName("image")[0]==null) rows.push("<img  src=\"../../resources/images/news/default.jpg\" style=\"width:70px;\"/>");
			else 
			{rows.push("<img style=\"width:70px;\" src=\""+items[i].getElementsByTagName("image")[0].getElementsByTagName("url")[0].childNodes[0].nodeValue);
			alt_text=items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue.replace(/"/g,"&quot;");
			rows.push("\" alt=\""+alt_text+ " \"/>");
			}
			rows.push("</td><td class=\"colminmid hottopicframe\">&nbsp;</td><td class=\"alitop hottopicframe\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><h6><span class=\"newstext\">");
			var d=items[i].getElementsByTagName("newsDate")[0];
			rows.push("<a href=\""+items[i].getElementsByTagName("link")[0].childNodes[0].nodeValue+"\">"+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+"</a><br/><span class=\"date\">");
			if (this.lang=="sc" || this.lang=="tc"){
				rows.push(d.getElementsByTagName("year")[0].childNodes[0].nodeValue+"年");				
				rows.push(d.getElementsByTagName("month")[0].childNodes[0].nodeValue+"月");
				rows.push(d.getElementsByTagName("day")[0].childNodes[0].nodeValue+"日");
			}
			else {
				rows.push(d.getElementsByTagName("day")[0].childNodes[0].nodeValue+" ");
				rows.push(mths[d.getElementsByTagName("month")[0].childNodes[0].nodeValue-1]);
				rows.push(" "+d.getElementsByTagName("year")[0].childNodes[0].nodeValue);
			}
			rows.push("</span><br /></span></h6></td></tr></table></td></tr>");}
		rows.push("</table>");
		if(this.lang=="tc")document.getElementById("channel4_section_title").innerHTML="投資推廣署新聞";
		else if (this.lang=="sc") document.getElementById("channel4_section_title").innerHTML="投资推广署新闻";
		else document.getElementById("channel4_section_title").innerHTML="InvestHK News";
		document.getElementById("channel4_content").innerHTML=rows.join("");

		// index content's news
		if(this.lang=="tc"){document.getElementById("channel5_section_title").innerHTML=" 最新商業新聞 ";
			document.getElementById("channel5_content").innerHTML="<iframe src=\"http://www.meltwaternews.com/magenta/xml/html/74/1/124656.html\" style=\"height:1.2em; width:850px;scrolling:no;vertical-align:bottom;margin-left:10px;margin-top:2px;background-color:#c9d6ed;\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\"><a href=\"http://www.meltwaternews.com/magenta/xml/html/74/1/112905.html\">InvestHK News</a></iframe>";
		}else if(this.lang=="sc"){
			document.getElementById("channel5_section_title").innerHTML=" 最新商业新闻 ";
			document.getElementById("channel5_content").innerHTML="<iframe src=\"http://www.meltwaternews.com/magenta/xml/html/74/1/102705.html\" style=\"height:1.2em; width:850px;scrolling:no;vertical-align:bottom;margin-left:10px;margin-top:2px;background-color:#c9d6ed;\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\"><a href=\"http://www.meltwaternews.com/magenta/xml/html/74/1/112905.html\">InvestHK News</a></iframe>";
			} else {
			document.getElementById("channel5_section_title").innerHTML=" Hong Kong Business News Update";//Latest Hong Kong Business News";
			document.getElementById("channel5_content").innerHTML="<iframe src=\"http://www.meltwaternews.com/magenta/xml/html/74/1/112905.html\" style=\"height:1.2em; width:670px;scrolling:no;vertical-align:bottom;margin-left:10px;margin-top:2px;background-color:#c9d6ed;\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\"><a href=\"http://www.meltwaternews.com/magenta/xml/html/74/1/112905.html\">InvestHK News</a></iframe>";
		}

		// index content's events
		this.TempXML=this.loadXML("resources/xml/common/"+this.lang+"_events.xml");
//		this.TempXML=this.loadXML("resources/xml/common/"+this.lang+"_calendar.xml");
		var items=this.TempXML.getElementsByTagName("item");
		if (items.length > 0) {
			var rows=new Array();
			rows.push("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
			rows.push("<tr><td class=\"conthdframe\"><h4><span class=\"conthd\"><span id=\"ihk_event_title\"></span></span></h4></td></tr>");
            rows.push("<tr><td><span id=\"ihk_event_content\"></span></td></tr>");
			rows.push("</table>");
			document.getElementById("show_event").innerHTML=rows.join("\n");
			if(this.lang=="tc")document.getElementById("ihk_event_title").innerHTML="投資推廣署相關活動";
			else if(this.lang=="sc") document.getElementById("ihk_event_title").innerHTML="投资推广署相关活动";
			else document.getElementById("ihk_event_title").innerHTML="Events with InvestHK";
			var rows=new Array();
			rows.push("<table>");
			for(var i=0;i<items.length;i++){
				rows.push("<tr><td class=\"alitop aliright\"><h6><span class=\"newstext eventdate\">");
				var d=items[i].getElementsByTagName("newsDate")[0];
				if (this.lang=="sc" || this.lang=="tc"){
					rows.push(d.getElementsByTagName("year")[0].childNodes[0].nodeValue+"年");				
					rows.push(d.getElementsByTagName("month")[0].childNodes[0].nodeValue+"月");
					rows.push(d.getElementsByTagName("day")[0].childNodes[0].nodeValue+"日");
				}
				else {
					rows.push(d.getElementsByTagName("day")[0].childNodes[0].nodeValue+" ");
					//if(d.getElementsByTagName("month")[0].childNodes[0].nodeValue<10)rows.push("0"+d.getElementsByTagName("month")[0].childNodes[0].nodeValue);
					//else rows.push(d.getElementsByTagName("month")[0].childNodes[0].nodeValue);
					rows.push(mths[d.getElementsByTagName("month")[0].childNodes[0].nodeValue-1]);
					rows.push(" "+d.getElementsByTagName("year")[0].childNodes[0].nodeValue);
				}	
				rows.push("</span></h6></td><td class=\"alitop\"><h6><span class=\"newstext\"><a href=\""+items[i].getElementsByTagName("link")[0].childNodes[0].nodeValue+"\" target=\"_blank\">"+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue)+"</a></span></h6></td></tr>";
				}
			rows.push("</table>");
			document.getElementById("ihk_event_content").innerHTML=rows.join("");
		}
	// end of index page initial
	}
	
	// footer
	this.TempXML=this.loadXML("resources/xml/common/footer.xml");
	tempObject=new Object();
	tempTagObject=new Object();
	
	tempTagObject["items"]="items";
	tempTagObject["item"]="item";
	tempTagObject["title"]="title";
	tempTagObject["link"]="link";
	tempTagObject["description"]="description";
	
	for(var i=0;i<this.TempXML.getElementsByTagName(tempTagObject["items"]).length;i++){
		if(this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getAttribute("name")=="banner"){
			try{
				var rows=new Array();
				for(var j=0;j<this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"]).length;j++){
					tempObject["title"]=this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getElementsByTagName(tempTagObject["title"])[0].getAttribute(this.define_lang_code[this.lang]);
					tempObject["link"]=this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getElementsByTagName(tempTagObject["link"])[0].getAttribute(this.define_lang_code[this.lang]);
					tempObject["description"]=this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getElementsByTagName(tempTagObject["description"])[0].getAttribute(this.define_lang_code[this.lang]);
					rows.push(this.setURL(tempObject["title"],tempObject["link"],"",tempObject["description"]));
				}
				document.getElementById("footer_banner1").innerHTML=rows.join("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
			}catch(error){}
		}else if(this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getAttribute("name")=="info"){
			try{// Handle other languages into English if null
				var rows=new Array();
				for(var j=0;j<this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"]).length;j++){
					if(this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getElementsByTagName(tempTagObject["title"])[0].getAttribute(this.define_lang_code[this.lang])!=null)tempObject["title"]=this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getElementsByTagName(tempTagObject["title"])[0].getAttribute(this.define_lang_code[this.lang]);
					else tempObject["title"]=this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getElementsByTagName(tempTagObject["title"])[0].getAttribute("eng");
					if(this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getElementsByTagName(tempTagObject["link"])[0].getAttribute(this.define_lang_code[this.lang])!=null)tempObject["link"]=this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getElementsByTagName(tempTagObject["link"])[0].getAttribute(this.define_lang_code[this.lang]);
					else tempObject["link"]=this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"])[j].getElementsByTagName(tempTagObject["link"])[0].getAttribute("eng");
					if(j<5)
						document.getElementById("footer_info"+(j+1)).innerHTML=this.setURL(tempObject["title"],tempObject["link"]);
					else if ((j+1)==this.TempXML.getElementsByTagName(tempTagObject["items"])[i].getElementsByTagName(tempTagObject["item"]).length){
						document.getElementById("footer_info6").innerHTML=rows.join(" | ");
						document.getElementById("footer_info7").innerHTML=this.setURL(tempObject["title"],tempObject["link"]);}
					else {
						rows.push(this.setURL(tempObject["title"],tempObject["link"]));
					}
				}
			}catch(error){}
		}
	}
	
	//AddRoundBorder();
}

function loadMenuBarItems(items, rows){
for (var k=0;k<items.length;k++){
	if(items[k].nodeType==3||items[k].nodeType==8)continue;
	var itemhidden = items[k].getAttribute("hidden") == null ? "" : items[k].getAttribute("hidden");
	if(itemhidden.indexOf("1")>=0||itemhidden.indexOf("true")>=0||itemhidden.search(eval("/" + this.define_lang_code[this.lang] + "/i"))>=0)continue;
		rows.push("<li><a href=\"/default_bodies/"+items[k].getAttribute("url").replace(/\/en_/,"/"+this.lang+"_")+"\">"+items[k].getAttribute(this.define_lang_code[this.lang])+"</a>");
		if(items[k].childNodes.length>0){
			rows.push("<ul>");this.loadMenuBarItems(items[k].childNodes,rows);rows.push("</ul></li>");
		}else rows.push("</li>");
		var t=location.href.replace(/\/(sc|tc)_/,"/en_"),par;
		if(t.search(new RegExp(items[k].getAttribute("url")))>0){
			if(items[k].parentNode.nodeName=="root")return;
			//(t.search("_sectors_")<0)?par=items[k].parentNode.childNodes:par=items[k].childNodes;
			(items[k].childNodes.length==0)?par=items[k].parentNode.childNodes:par=items[k].childNodes;
			this.submenu["item"]=new Array();this.submenu["exist_content"]="";
			for(var m=0;m<par.length;m++){
				if(par[m].nodeType==3||par[m].nodeType==8)continue;
				var submenuitemhidden = par[m].getAttribute("hidden") == null ? "" : par[m].getAttribute("hidden");
				if(submenuitemhidden.indexOf("1")>=0 ||submenuitemhidden.indexOf("true")>=0 ||submenuitemhidden.search(eval("/" + this.define_lang_code[this.lang] + "/i"))>=0)continue;
				(par[m].getAttribute("eng")==items[k].getAttribute("eng"))?this.submenu["selected"]=true:this.submenu["selected"]=false;
				this.submenu["item"][this.submenu["item"].length]=(par[m].getAttribute("eng")==items[k].getAttribute("eng"))?this.setURL(par[m].getAttribute(this.define_lang_code[this.lang]),par[m].getAttribute("url").replace(/\/en_/,"/"+this.lang+"_"),"selected"):this.setURL(par[m].getAttribute(this.define_lang_code[this.lang]),par[m].getAttribute("url").replace(/\/en_/,"/"+this.lang+"_"));
				this.submenu["content"]+=this.submenu["item"][this.submenu["item"].length-1];
				if(this.submenu["item"].length>this.submenu["display_length"])
					this.submenu["display_record"]=this.submenu["display_length"];
				else{
					this.submenu["display_record"]=this.submenu["item"].length;
					this.submenu["exist_content"]+=this.submenu["item"][this.submenu["item"].length-1];
				}
			}
			if(this.submenu["item"].length>this.submenu["display_length"]) this.submenu["exist_content"]+='<span class="extend" onMouseOver="html.toggleMenu(\'menu\');"><a href="#"></a></span>';
			document.getElementById("menu").innerHTML=this.submenu["exist_content"];
		}
	}
}

function ShowImageButton(span_name,tag_name,item_no,style){
	var rows=new Array();
	var topimage;
	var bottomimage;
	var framestyle;
	var linkstyle;
	var linktitle;
	
	if(document.getElementById(span_name)!=undefined){
		try {
			linktitle = this.tempObject[tag_name][item_no-1]["title"];
		}
		catch (error) {
			linktitle = "";
		}
		
		if(style=="light"){
			topimage="btn_05_top.gif";
			bottomimage="btn_05_bottom.gif";
			framestyle="btnlight2frame";
			linkstyle="btnlight2";
		}
		else {
			topimage="btn_06_top.gif";
			bottomimage="btn_06_bottom.gif";
			framestyle="btndark2frame";
			linkstyle="btndark2";
		}
		
		if (!(linktitle == null || linktitle == "")){
/*			rows.push("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"" + framestyle + "\">");
			rows.push("<tr><td><img src=\"../../resources/images/common/" + topimage + "\" /></td></tr>");
			rows.push("<tr><td><h5><span class=\"" + linkstyle + "\">");
			rows.push(this.setURL(linktitle,this.tempObject[tag_name][item_no-1]["link"]));
			rows.push("</span></h5></td></tr>");
			rows.push("<tr><td><img src=\"../../resources/images/common/" + bottomimage + "\" /></td></tr>");
			rows.push("</table>");
*/			
			rows.push("<table cellspacing=\"0\" cellpadding=\"0\" class=\"" + framestyle + "\">");
			rows.push("<tr><td><h5><span class=\"" + linkstyle + "\">");
			rows.push(this.setURL(linktitle,this.tempObject[tag_name][item_no-1]["link"]));
			rows.push("</span></h5></td></tr>");
			rows.push("</table>");
			document.getElementById(span_name).innerHTML=rows.join("\n");
		}
	}
}


function CaseStudy(span_name,index){
	var rows=new Array();
	var haveCS = false;
	
	rows.push("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"csframe\"><tr><td colspan=\"2\" class=\"casestudieshdframe\"><h4><span class=\"casestudieshd\">");
	if (/rhq/.test(index)){
		if(this.lang=="tc")rows.push("個案研究</span></h4><td></tr>");
		else if(this.lang=="sc")rows.push("个案研究</span></h4><td></tr>");
		else rows.push("RHQ Case Studies</span></h4><td></tr>");
	}else{
		if(this.lang=="tc")rows.push("個案研究</span></h4><td></tr>");
		else if(this.lang=="sc")rows.push("个案研究</span></h4><td></tr>");
		else if(this.lang=="jp")rows.push("ケーススタディー</span></h4><td></tr>");
		else rows.push("Investor Case Studies</span></h4><td></tr>");
	}
	var dir=new Array("business","consumer","creative","financial","information","innovation","tourism","transportation");

	if (/all/.test(index)) {
		if(this.lang=="tc") l=1;
		else if (this.lang=="sc") l=2;
		else if (this.lang=="jp") l=3;		
		else l=0;
		for (var d=0;d<dir.length;d++){
			this.TempXML=this.loadXML("../../resources/xml/casestudies/"+dir[d]+"/0.xml",true);
			if (this.TempXML.getElementsByTagName("languages")[l] != null){
				var items=this.TempXML.getElementsByTagName("languages")[l].getElementsByTagName("item");
				for(var i=0;i<items.length;i++){
					if(items[i].getAttribute("active")==0||items[i].getAttribute("active")=="false")continue;
					rows.push("<tr><td class=\"csimgframe\"><img style=\"width:70px;\" src=\""+items[i].getElementsByTagName("photo")[0].		getAttribute("url")+"\" alt=\""+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+ "\"/></td><td class=\"cstextframne\"><h6><span class=\"cstext\"><a href=\"");
					rows.push("../sectors/" + this.lang + "_sectors_"  + dir[d] + "99.html?"+items[i].getAttribute("id"));
					rows.push("\">"+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+"</a></span></h6></td></tr>");
					haveCS = true;
				}
			}
		}
	}	
	else if (/index/.test(index)){
		var s=new Array();
		var d=0;
		for(var i=0;i<5;i++){
			d++;
			if (d > dir.length) break;
			var r=true;
			while(r){r=false;
				s[i]=Math.round(Math.random()*(dir.length-2))+1;
				for(var j=0;j<s.length-1;j++){if(s[i]==s[j])r=true;}
				if(!r)break;}
			//this.TempXML=this.loadXML("/xml/S"+s[i]+"/0.xml",true);
			this.TempXML=this.loadXML("../../resources/xml/casestudies/"+dir[s[i]]+"/0.xml",true);
			if(this.lang=="tc") l=1;
			else if (this.lang=="sc") l=2;
			else if (this.lang=="jp") l=3;		
			else l=0;
			var item;
			if (this.TempXML.getElementsByTagName("languages")[l] != null)
				item=this.TempXML.getElementsByTagName("languages")[l].getElementsByTagName("item")[0];	
			else {i--;continue;}

			if(item.getAttribute("active")==0||item.getAttribute("active")=="false"){i--;continue};
			rows.push("<tr><td class=\"csimgframe\"><img style=\"width:70px;\" src=\""+item.getElementsByTagName("photo")[0].getAttribute("url")+"\" alt=\""+item.getElementsByTagName("title")[0].childNodes[0].nodeValue+"\" /></td><td class=\"cstextframne\"><h6><span class=\"cstext\"><a href=\"");
			rows.push("../sectors/" + this.lang + "_sectors_"  + dir[s[i]] + "99.html?"+item.getAttribute("id"));
			rows.push("\">"+item.getElementsByTagName("title")[0].childNodes[0].nodeValue+"</a></span></h6></td></tr>");
			haveCS = true;
		}
	}
	else if (/rhq/.test(index)){
		var l;
		if(this.lang=="tc") l=1;
		else if (this.lang=="sc") l=2;
		else l=0;
		this.TempXML=this.loadXML("../../resources/xml/casestudies/rhq/0.xml",true);
		if (this.TempXML.getElementsByTagName("languages")[l] != null){
			var items=this.TempXML.getElementsByTagName("languages")[l].getElementsByTagName("item");
			for(var i=0;i<items.length;i++){
				if(items[i].getAttribute("active")==0||items[i].getAttribute("active")=="false")continue;
				rows.push("<tr><td class=\"csimgframe\"><img style=\"width:70px;\" src=\""+items[i].getElementsByTagName("photo")[0].		getAttribute("url")+"\" alt=\""+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+ "\"/></td><td class=\"cstextframne\"><h6><span class=\"cstext\"><a href=\"");
				rows.push("../sectors/" + this.lang + "_sectors_"  + items[i].getAttribute("sector") + "99.html?"+items[i].getAttribute("sectorid"));
				rows.push("\">"+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+"</a></span></h6></td></tr>");
				haveCS = true;
			}
		}
	}
	else{
		var s;
		if(/business/.test(index)) s="business";
		else if(/consumer/.test(index)) s="consumer";
		else if(/creative/.test(index)) s="creative";
		else if(/financial/.test(index)) s="financial";
		else if(/information/.test(index)) s="information";
		else if(/innovation/.test(index)) s="innovation";
		else if(/tourism/.test(index)) s="tourism";
		else if(/transportation/.test(index)) s="transportation";
/*		else if(/industrial/.test(index)) s="industrial";*/
		else return;
		var l;
		if(this.lang=="tc") l=1;
		else if (this.lang=="sc") l=2;
		else if (this.lang=="jp") l=3;
		else l=0;
		this.TempXML=this.loadXML("../../resources/xml/casestudies/"+s+"/0.xml",true);
		
		if (this.TempXML.getElementsByTagName("languages")[l] != null){
			var items=this.TempXML.getElementsByTagName("languages")[l].getElementsByTagName("item");
			var filename = location.pathname;
			var codepos = filename.search(/.html/) - 2;
			var filecode = filename.substr(codepos, 2);
			var code = new RegExp(filecode);
			var flag = 0;
			for(var i=0;i<items.length;i++){
				if(!/99/.test(index)) {
					if(!/97/.test(index)){
						try{
							if(!code.test(items[i].getAttribute("show")))
								continue;
						}catch(err){	
							continue;
						}
					}
					else if(items[i].getAttribute("active")==0||items[i].getAttribute("active")=="false")continue;
				}
				rows.push("<tr><td class=\"csimgframe\"><img style=\"width:70px;\" src=\""+items[i].getElementsByTagName("photo")[0].getAttribute("url")+"\" alt=\""+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+"\" /></td><td class=\"cstextframne\"><h6><span class=\"cstext\"><a href=\"");
				if(/99/.test(index)||/97/.test(index)) rows.push("?"+items[i].getAttribute("id")+"\" onclick=\"loadCase()");					else rows.push(index.replace(/\d\d/,97)+".html?"+items[i].getAttribute("id"));
				rows.push("\">"+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+"</a></span></h6></td></tr>");
				haveCS = true;
				flag = flag + 1;
			}
			if(flag ==0){ //if non-97 and non-99 xml does not have the "show" attribute, show the "active" ones.
				for(var i=0;i<items.length;i++){
					if(items[i].getAttribute("active")==0||items[i].getAttribute("active")=="false")continue;
				rows.push("<tr><td class=\"csimgframe\"><img style=\"width:70px;\" src=\""+items[i].getElementsByTagName("photo")[0].getAttribute("url")+"\" /></td><td class=\"cstextframne\"><h6><span class=\"cstext\"><a href=\"");
				if(/99/.test(index)||/97/.test(index)) rows.push("?"+items[i].getAttribute("id")+"\" onclick=\"loadCase()");					else rows.push(index.replace(/\d\d/,97)+".html?"+items[i].getAttribute("id"));
				rows.push("\">"+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+"</a></span></h6></td></tr>");
				haveCS = true;
				}
			}
		}
	}rows.push("</table>");
	
	if (haveCS){
		document.getElementById(span_name).innerHTML=rows.join("");
	}
}
/*
function CaseStudy(span_name,index){
	var rows=new Array();
	var haveCS = false;
	
	rows.push("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"csframe\"><tr><td colspan=\"2\" class=\"casestudieshdframe\"><h4><span class=\"casestudieshd\">");
	if (/rhq/.test(index)){
		if(this.lang=="tc")rows.push("個案研究</span></h4><td></tr>");
		else if(this.lang=="sc")rows.push("个案研究</span></h4><td></tr>");
		else rows.push("RHQ Case Studies</span></h4><td></tr>");
	}else{
		if(this.lang=="tc")rows.push("個案研究</span></h4><td></tr>");
		else if(this.lang=="sc")rows.push("个案研究</span></h4><td></tr>");
		else if(this.lang=="jp")rows.push("ケーススタディー</span></h4><td></tr>");
		else rows.push("Investor Case Studies</span></h4><td></tr>");
	}
	var dir=new Array("business","consumer","creative","financial","information","innovation","tourism","transportation");

	if (/all/.test(index)) {
		if(this.lang=="tc") l=1;
		else if (this.lang=="sc") l=2;
		else if (this.lang=="jp") l=3;		
		else l=0;
		for (var d=0;d<dir.length;d++){
			this.TempXML=this.loadXML("../../resources/xml/casestudies/"+dir[d]+"/0.xml",true);
			if (this.TempXML.getElementsByTagName("languages")[l] != null){
				var items=this.TempXML.getElementsByTagName("languages")[l].getElementsByTagName("item");
				for(var i=0;i<items.length;i++){
					if(items[i].getAttribute("active")==0||items[i].getAttribute("active")=="false")continue;
					rows.push("<tr><td class=\"csimgframe\"><img style=\"width:70px;\" src=\""+items[i].getElementsByTagName("photo")[0].		getAttribute("url")+"\" alt=\""+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+ "\"/></td><td class=\"cstextframne\"><h6><span class=\"cstext\"><a href=\"");
					rows.push("../sectors/" + this.lang + "_sectors_"  + dir[d] + "99.html#"+items[i].getAttribute("id"));
					rows.push("\">"+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+"</a></span></h6></td></tr>");
					haveCS = true;
				}
			}
		}
	}	
	else if (/index/.test(index)){
		var s=new Array();
		var d=0;
		for(var i=0;i<5;i++){
			d++;
			if (d > dir.length) break;
			var r=true;
			while(r){r=false;
				s[i]=Math.round(Math.random()*(dir.length-2))+1;
				for(var j=0;j<s.length-1;j++){if(s[i]==s[j])r=true;}
				if(!r)break;}
			//this.TempXML=this.loadXML("/xml/S"+s[i]+"/0.xml",true);
			this.TempXML=this.loadXML("../../resources/xml/casestudies/"+dir[s[i]]+"/0.xml",true);
			if(this.lang=="tc") l=1;
			else if (this.lang=="sc") l=2;
			else if (this.lang=="jp") l=3;		
			else l=0;
			var item;
			if (this.TempXML.getElementsByTagName("languages")[l] != null)
				item=this.TempXML.getElementsByTagName("languages")[l].getElementsByTagName("item")[0];	
			else {i--;continue;}

			if(item.getAttribute("active")==0||item.getAttribute("active")=="false"){i--;continue};
			rows.push("<tr><td class=\"csimgframe\"><img style=\"width:70px;\" src=\""+item.getElementsByTagName("photo")[0].getAttribute("url")+"\" alt=\""+item.getElementsByTagName("title")[0].childNodes[0].nodeValue+"\" /></td><td class=\"cstextframne\"><h6><span class=\"cstext\"><a href=\"");
			rows.push("../sectors/" + this.lang + "_sectors_"  + dir[s[i]] + "99.html#"+item.getAttribute("id"));
			rows.push("\">"+item.getElementsByTagName("title")[0].childNodes[0].nodeValue+"</a></span></h6></td></tr>");
			haveCS = true;
		}
	}
	else if (/rhq/.test(index)){
		var l;
		if(this.lang=="tc") l=1;
		else if (this.lang=="sc") l=2;
		else l=0;
		this.TempXML=this.loadXML("../../resources/xml/casestudies/rhq/0.xml",true);
		if (this.TempXML.getElementsByTagName("languages")[l] != null){
			var items=this.TempXML.getElementsByTagName("languages")[l].getElementsByTagName("item");
			for(var i=0;i<items.length;i++){
				if(items[i].getAttribute("active")==0||items[i].getAttribute("active")=="false")continue;
				rows.push("<tr><td class=\"csimgframe\"><img style=\"width:70px;\" src=\""+items[i].getElementsByTagName("photo")[0].		getAttribute("url")+"\" alt=\""+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+ "\"/></td><td class=\"cstextframne\"><h6><span class=\"cstext\"><a href=\"");
				rows.push("../sectors/" + this.lang + "_sectors_"  + items[i].getAttribute("sector") + "99.html#"+items[i].getAttribute("sectorid"));
				rows.push("\">"+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+"</a></span></h6></td></tr>");
				haveCS = true;
			}
		}
	}
	else{
		var s;
		if(/business/.test(index)) s="business";
		else if(/consumer/.test(index)) s="consumer";
		else if(/creative/.test(index)) s="creative";
		else if(/financial/.test(index)) s="financial";
		else if(/information/.test(index)) s="information";
		else if(/innovation/.test(index)) s="innovation";
		else if(/tourism/.test(index)) s="tourism";
		else if(/transportation/.test(index)) s="transportation";
//		else if(/industrial/.test(index)) s="industrial";
		else return;
		var l;
		if(this.lang=="tc") l=1;
		else if (this.lang=="sc") l=2;
		else if (this.lang=="jp") l=3;
		else l=0;
		this.TempXML=this.loadXML("../../resources/xml/casestudies/"+s+"/0.xml",true);
		
		if (this.TempXML.getElementsByTagName("languages")[l] != null){
			var items=this.TempXML.getElementsByTagName("languages")[l].getElementsByTagName("item");
			var filename = location.pathname;
			var codepos = filename.search(/.html/) - 2;
			var filecode = filename.substr(codepos, 2);
			var code = new RegExp(filecode);
			var flag = 0;
			for(var i=0;i<items.length;i++){
				if(!/99/.test(index)) {
					if(!/97/.test(index)){
						try{
							if(!code.test(items[i].getAttribute("show")))
								continue;
						}catch(err){	
							continue;
						}
					}
					else if(items[i].getAttribute("active")==0||items[i].getAttribute("active")=="false")continue;
				}
				rows.push("<tr><td class=\"csimgframe\"><img style=\"width:70px;\" src=\""+items[i].getElementsByTagName("photo")[0].getAttribute("url")+"\" alt=\""+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+"\" /></td><td class=\"cstextframne\"><h6><span class=\"cstext\"><a href=\"");
				if(/99/.test(index)||/97/.test(index)) rows.push("#\" onclick=\"loadCase(null,"+items[i].getAttribute("id")+")");					else rows.push(index.replace(/\d\d/,97)+".html#"+items[i].getAttribute("id"));
				rows.push("\">"+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+"</a></span></h6></td></tr>");
				haveCS = true;
				flag = flag + 1;
			}
			if(flag ==0){ //if non-97 and non-99 xml does not have the "show" attribute, show the "active" ones.
				for(var i=0;i<items.length;i++){
					if(items[i].getAttribute("active")==0||items[i].getAttribute("active")=="false")continue;
				rows.push("<tr><td class=\"csimgframe\"><img style=\"width:70px;\" src=\""+items[i].getElementsByTagName("photo")[0].getAttribute("url")+"\" /></td><td class=\"cstextframne\"><h6><span class=\"cstext\"><a href=\"");
				if(/99/.test(index)||/97/.test(index)) rows.push("#\" onclick=\"loadCase(null,"+items[i].getAttribute("id")+")");					else rows.push(index.replace(/\d\d/,97)+".html#"+items[i].getAttribute("id"));
				rows.push("\">"+items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+"</a></span></h6></td></tr>");
				haveCS = true;
				}
			}
		}
	}rows.push("</table>");
	
	if (haveCS){
		document.getElementById(span_name).innerHTML=rows.join("");
	}
}

*/
function MostPopular(span_name,with_title,filename){
	if(document.getElementById(span_name)==null)return;
	if(with_title!=false)with_title=true;
	
	// temporary content start
	this.echo('<span id="temp_' + span_name + '" style="display:none">');
	
	// template
	this.echo('<table border="0" cellspacing="0" cellpadding="0">');
	if(with_title){
		this.echo('	<!--tr>');
		this.echo('		<td class="conthdframe"><h4><span class="conthd"><span id="channel6' + span_name + '_section_title"></span></span></h4></td>');
		this.echo('	</tr-->');
	}
	this.echo('	<tr>');
	this.echo('		<td>');
	this.echo('			<table border="0" cellspacing="0" cellpadding="0" class="rollingframe">');
	this.echo('				<tr>');
	if(/tc_/.test(location.pathname)||/sc_/.test(location.pathname))
		this.echo('					<td class="rollingtext"><h5><span id="channel6' + span_name + '_content"></span><br/><div id="quotepause" class="btnquote" onclick="html.stopQuote()">■ 停止</div></h5></td>');
	else
		this.echo('					<td class="rollingtext"><h5><span id="channel6' + span_name + '_content"></span><br/><div id="quotepause" class="btnquote" onclick="html.stopQuote()">■ Stop</div></h5></td>');
	this.echo('				</tr>');
	this.echo('			</table>');
	this.echo('		</td>');
	this.echo('	</tr>');
	this.echo('</table>');
	// temporary content end
	this.echo('</span>');
	
	if(filename==undefined){
		var ss=new Array("business","consumer","creative","financial","information","innovation","tourism","transportation");
		for(var i=0;i<ss.length;i++){
			try{this.TempXML=this.loadXML("resources/xml/sectors/"+this.lang+"_sectors_"+ss[i]+"01_quote.xml",false);
			if(this.TempXML==null)continue;}
			catch(e){continue;}
			var items=this.TempXML.getElementsByTagName("item");
			for(var j=0;j<items.length;j++) quotes.push(items[j].getElementsByTagName("description")[0].childNodes[0].nodeValue);
		}
	}else{this.TempXML=this.loadXML(filename,false);
		var items=this.TempXML.getElementsByTagName("item");
		for(var i=0;i<items.length;i++) quotes.push(items[i].getElementsByTagName("description")[0].childNodes[0].nodeValue);
	}
	
	try{
		if (quotes.length > 0){
			document.getElementById(span_name).innerHTML=document.getElementById("temp_" + span_name).innerHTML;
		}
		else {
			document.getElementById("temp_" + span_name).innerHTML = "";
		}
	}catch(error){}
/*	try{
		if(this.lang=="tc")document.getElementById("channel6show_mostpopular_section_title").innerHTML="亞洲國際商業城市";
		else document.getElementById("channel6show_mostpopular_section_title").innerHTML="Asia's Most Popular City";
	}catch(error){}*/
	this.loadQuote();
}

var quotes=new Array();
var t;
function loadQuote(){
	if (quotes.length > 0){
		var i=Math.round(Math.random()*(quotes.length-1));
		document.getElementById("channel6show_mostpopular_content").innerHTML=quotes[i];
		t = setTimeout("loadQuote();",10000);
	}
}

function stopQuote(){
	if(/tc_/.test(location.pathname)||/sc_/.test(location.pathname)){btn_stop_txt = "停止"; btn_play_txt = "播放";}
	else {btn_stop_txt = "Stop"; btn_play_txt = "Play";}

	if(document.getElementById('quotepause').innerHTML=="■ "+btn_stop_txt){
		clearTimeout(t);
		document.getElementById('quotepause').innerHTML="► "+btn_play_txt;
		/*document.getElementById('quotepause').title="Click to Play";*/		
	} else{
		document.getElementById('quotepause').innerHTML="■ "+btn_stop_txt;
		/*document.getElementById('quotepause').title="Click to Stop";	*/
		this.loadQuote();
		}
}

function LoadContent(xmlfile,change_browser_title){

	try{
		// generate content
		this.tempObject=new Object();
		this.tempObject["item"]=new Array();
		this.TempXML=this.loadXML("../../"+xmlfile,true);
		/*if (this.TempXML.text.length==0){
			throw 'Empty XML Content';
		}*/
		tempTagObject=new Object();
		
		tempTagObject["channel"]="channel";
		tempTagObject["title"]="title";
		tempTagObject["item"]="item";
		tempTagObject["description"]="description";
		tempTagObject["link"]="link";
		tempTagObject["image"]="image";
		tempTagObject["url"]="url";
		
		// load page title
/*		try{
			if(change_browser_title!=false)
				document.title=this.TempXML.getElementsByTagName(tempTagObject["title"])[0].childNodes[0].nodeValue;
		}catch(error){}
		*/
		//LastUpdate
		try{
//			var x=this.TempXML.lastModified;
//			if(navigator.appName=="Microsoft Internet Explorer") 
			var x=this.fileLastModified;
			if(Date.parse(x)>this.lastModified){
				if(this.lang=="tc")document.getElementById("lastUpdate").innerHTML="<span class=\" lastupdtext\">最後更新日期︰"+x+"</span>";
				else if(this.lang=="sc")document.getElementById("lastUpdate").innerHTML="<span class=\" lastupdtext\">最后更新日期︰"+x+"</span>";
				else document.getElementById("lastUpdate").innerHTML="<span class=\" lastupdtext\">Last updated on: "+x+"</span>";
				this.lastModified=Date.parse(x);
			}
		}catch(e){}

		// retrieve XML content
		for(var i=0;i<this.TempXML.getElementsByTagName(tempTagObject["channel"]).length;i++){
			if(this.TempXML.getElementsByTagName(tempTagObject["channel"])[i].tagName=="channel"){
				for(var j=0;j<this.TempXML.getElementsByTagName(tempTagObject["channel"])[i].getElementsByTagName(tempTagObject["title"]).length;j++){
					tempObject=new Object();
					var temp_id=this.TempXML.getElementsByTagName(tempTagObject["channel"])[i].getAttribute("id");
					
					try{
						this.tempObject["title"]=this.TempXML.getElementsByTagName(tempTagObject["channel"])[i].getElementsByTagName(tempTagObject["title"])[0].childNodes[0].nodeValue;
					}catch(error){
					}
					
					var content_length=content_length=this.TempXML.getElementsByTagName(tempTagObject["channel"])[i].getElementsByTagName(tempTagObject["item"]).length;
					
					for(var k=0;k<content_length;k++){
						this.tempObject["item_length"]=this.tempObject["item"].length;
						this.tempObject["item"][this.tempObject["item_length"]]=new Object();
						
						try{
							this.tempObject["item"][this.tempObject["item_length"]]["title"]=this.TempXML.getElementsByTagName(tempTagObject["channel"])[i].getElementsByTagName(tempTagObject["item"])[k].getElementsByTagName(tempTagObject["title"])[0].childNodes[0].nodeValue;
						}catch(error){
							this.tempObject["item"][this.tempObject["item_length"]]["title"]="";
						}
						
						try{
							this.tempObject["item"][this.tempObject["item_length"]]["description"]=this.TempXML.getElementsByTagName(tempTagObject["channel"])[i].getElementsByTagName(tempTagObject["item"])[k].getElementsByTagName(tempTagObject["description"])[0].childNodes[0].nodeValue;
						}catch(error){
							this.tempObject["item"][this.tempObject["item_length"]]["description"]="";
						}
						
						try{
							this.tempObject["item"][this.tempObject["item_length"]]["link"]=this.TempXML.getElementsByTagName(tempTagObject["channel"])[i].getElementsByTagName(tempTagObject["item"])[k].getElementsByTagName(tempTagObject["link"])[0].childNodes[0].nodeValue;
						}catch(error){
							this.tempObject["item"][this.tempObject["item_length"]]["link"]="";
						}
						
						try{
							this.tempObject["item"][this.tempObject["item_length"]]["image_link"]=this.TempXML.getElementsByTagName(tempTagObject["channel"])[i].getElementsByTagName(tempTagObject["item"])[k].getElementsByTagName(tempTagObject["image"])[0].getElementsByTagName(tempTagObject["link"])[0].childNodes[0].nodeValue;
						}catch(error){
							this.tempObject["item"][this.tempObject["item_length"]]["image_link"]="";
						}
						
						try{
							this.tempObject["item"][this.tempObject["item_length"]]["image_url"]=this.TempXML.getElementsByTagName(tempTagObject["channel"])[i].getElementsByTagName(tempTagObject["item"])[k].getElementsByTagName(tempTagObject["image"])[0].getElementsByTagName(tempTagObject["url"])[0].childNodes[0].nodeValue;
						}catch(error){
							this.tempObject["item"][this.tempObject["item_length"]]["image_url"]="";
						}
							
					}
					break;
					
				}
			}
		}
		
		this.loadXMLStatus=true;
	}catch(error){
		this.showError("There have a problem in XML file \"" + xmlfile + "\". Please check XML content and try again.");
		this.loadXMLStatus=false;
	}
		
}

function ShowContent(span_name,tag_name,item_no,item_tag,link){
	if(this.loadXMLStatus==false){
		return;
	}else if(item_no==undefined){
		try{
			if(document.getElementById(span_name)==undefined){
				this.showError("There is no this span name \"" + span_name +"\" in this content.");
			}else{
				document.getElementById(span_name).innerHTML=this.tempObject[tag_name];
			}
		}catch(error){
			this.showError("There is no this tag name \"" + tag_name +"\"  in this content.");
		}
	}else{
		try{
			if(document.getElementById(span_name)==undefined){
				this.showError("There is no this span name \"" + span_name +"\" in this content.");
			}else if(this.tempObject[tag_name][item_no-1][item_tag]==undefined && item_tag!="image"){
				this.showError("There is no this item's tag \"" + item_tag +"\" in this content.");
			}else{
				if(item_tag=="image"){
					if (this.tempObject[tag_name][item_no-1]["image_url"].length > 0){
						if(link==true){
							document.getElementById(span_name).innerHTML=this.setURL("<img src=\"" + this.url_location + this.tempObject[tag_name][item_no-1]["image_url"] + "\" border=\"0\" alt=\""+this.tempObject[tag_name][item_no-1]["title"]+ "\">",this.tempObject[tag_name][item_no-1]["image_link"]);
						}else{
							document.getElementById(span_name).innerHTML="<img src=\"" + this.url_location + this.tempObject[tag_name][item_no-1]["image_url"] + "\" border=\"0\" alt=\""+ this.tempObject[tag_name][item_no-1]["title"]+"\">";
						}
					}
				}else{
					if(link==true){
						document.getElementById(span_name).innerHTML=this.setURL(this.tempObject[tag_name][item_no-1][item_tag],this.tempObject[tag_name][item_no-1]["link"]);
					}else{
						document.getElementById(span_name).innerHTML=this.tempObject[tag_name][item_no-1][item_tag];
					}
				}
			}
		}catch(error){
			if(item_tag==undefined){
				this.showError("Item's tag is missing.");
			}else{
				this.showError("ShowContent Error: There have " + this.tempObject["item"].length + " item(s) only. Item no \"" + item_no + "\" doesn't exist in this content.");
			}
		}
	}
	
}

function loadcontact(span_name, tag_id,lang, country){
if(/tc_/.test(location.pathname))	lang="cht";
	else if (/sc_/.test(location.pathname))	lang="chs";
	//else if (/fr/.test(location.pathname)) lang="fra";
if(lang=="en") lang="eng";	

if(/lifestyle/.test(location.pathname)||/index/.test(location.pathname)||/services/.test(location.pathname)){

	//var country;
	//r paras=/\/(en|tc|sc)_community.html?(\w*)/;
	var region=location.search;

	if (/australia/.test(region)) country= "au";
	else if(/canada/.test(region)) country="ca";
	else if(/france/.test(region)) country="fr";
	else if(/germany/.test(region)) country="de";
	else if(/netherlands/.test(region)) country="nl";
	else if(/india/.test(region)) country="in";
	else if(/israel/.test(region)) country="il";
	else if(/italy/.test(region)) country="it";
	else if(/japan/.test(region)) country="jp";
	else if(/korea/.test(region)) country="kr";
	else if(/latinamerica/.test(region)) country="sa";
	else if(/nordic/.test(region)) country="se";
	else if(/russia/.test(region)) country="ru";
	else if(/singapore/.test(region)) country="sg";
	else if(/spain/.test(region)) country="be";
	else if(/switzerland/.test(region)) country="ch";
	else if(/taiwan/.test(region)) country="tw";
	else if(/uk/.test(region)) country="gb";
	else if(/us/.test(region)) country="us";
	
	ShowContact(span_name,lang,country);
}
else{
	ShowHQ(span_name,tag_id,lang);
}
}

function ShowContact(span_name,lang,country){
	var rg=new RegExp(country);
	var tel,fax,areaR;
	if(lang=="cht"){tel="電話︰";fax="傳真︰";}
	else if(lang=="chs"){tel="电话︰";fax="传真︰";}
	else{tel="T: ";fax="F: ";}
	if (lang=="cht"){areaR="負責區域:";}
	else if (lang=="chs"){areaR="负责区域:";}
	else if (lang=="jpn"){areaR="担当地域";}
	else if (lang=="kor"){areaR="담당 지역: 대한민국";}
	else if (lang=="deu"){areaR="Verantwortungsbereich:"}
	else if (lang=="fra"){areaR="Zone géographique couverte:";}
	else if (lang=="ita"){areaR="Area di responsabilità:";}
	else if (lang=="spn"){areaR="Áreas de responsabilidad:";}
	else if (lang=="por"){areaR="Área de Responsabilidade:";}
	else if (lang=="rus"){areaR="Страны и регионы";}
	else areaR="Area of Responsibility:";

	if (country=="hk"){
		var x=loadXML("/xml/hq.xml",true);
	}
	else{
		var x=loadXML("/xml/contact.xml",true);
	}
	var c=x.getElementsByTagName("office");
	var temp=new Array(); 
	for(i=0;i<c.length;i++){
		if(rg.test(c[i].getAttribute("region"))){ 
			if(c[i].getElementsByTagName("name")[0].getAttribute(lang)==null)
				temp.push("<b><u>"+c[i].getElementsByTagName("name")[0].getAttribute("eng")+"</u></b><br/><br/>");
			else temp.push("<b><u>"+c[i].getElementsByTagName("name")[0].getAttribute(lang)+"</u></b><br/><br/>");
			for(j=0;j<c[i].getElementsByTagName("contact").length;j++){
				var b=c[i].getElementsByTagName("contact")[j];
				temp.push("<!--img src=\""+b.getElementsByTagName("image")[0].getAttribute("url")+"\"><br-->");
				if(b.getElementsByTagName("name")[0].getAttribute(lang)==null)
					temp.push("<b>"+b.getElementsByTagName("name")[0].getAttribute("eng")+"</b><br>");
				else temp.push("<b>"+b.getElementsByTagName("name")[0].getAttribute(lang)+"</b><br>");
				if (b.getElementsByTagName("title")[0].getAttribute(lang) == null)
					temp.push(b.getElementsByTagName("title")[0].getAttribute("eng")+"<br/>");
				else
					temp.push(b.getElementsByTagName("title")[0].getAttribute(lang)+"<br/>");
			temp.push(tel+b.getElementsByTagName("tel")[0].childNodes[0].nodeValue+"<br>");
			if(c[i].getElementsByTagName("fax")[0].childNodes[0].nodeValue !=null)
				temp.push(fax+c[i].getElementsByTagName("fax")[0].childNodes[0].nodeValue+"<br>"); 
			//r cctitle = c[i].getElementsByTagName("title")[0].getAttribute(lang);
			temp.push("<a href=\"mailto:"+b.getElementsByTagName("email")[0].childNodes[0].nodeValue+"?cc=enq@investhk.gov.hk&subject=Enquiry from InvestHK website&body=To efficiently respond to your enquiry, please provide contact details, company name, nature of business, sector and country of origin.\">");
			temp.push(b.getElementsByTagName("email")[0].childNodes[0].nodeValue+"</a><br><br>");
			if (country=="hk") break;
		}
		if(c[i].getElementsByTagName("address")[0].getAttribute(lang)==null)
			temp.push(c[i].getElementsByTagName("address")[0].getAttribute("eng")+"<br>");
		else temp.push(c[i].getElementsByTagName("address")[0].getAttribute(lang)+"<br>");
		if(c[i].getElementsByTagName("responsibility").length>0)
			temp.push("<br/><b>"+areaR+"</b><br/>"+c[i].getElementsByTagName("responsibility")[0].getAttribute(lang)+"<br/><br/><br/>");
		else
			temp.push("<br/><br/><br/>");
		}
	;}
	document.getElementById(span_name).innerHTML=temp.join("");
}

function ShowHQ(span_name, tag_id, lang){
var x=loadXML("/xml/hq.xml",true);
var c=x.getElementsByTagName("contact");
var tel,fax;
if(lang=="cht"){tel="電話︰";fax="傳真︰";}
else if(lang=="chs"){tel="电话︰";fax="传真︰";}
else{tel="T: ";fax="F: ";}
var temp=new Array(); 
// push all information into an array, then join them by space
for(i=0;i<c.length;i++){
		if(c[i].getAttribute("id")==tag_id){ 
		temp.push("<div class=\"conttextphoto\"><img src=\"");
		temp.push(c[i].getElementsByTagName("image")[0].getAttribute("url")+"\" alt=\""+c[i].getElementsByTagName("name")[0].getAttribute(lang)+"\"><br>");
		temp.push("<b>"+c[i].getElementsByTagName("name")[0].getAttribute(lang)+"</b><br>");
		temp.push(c[i].getElementsByTagName("title")[0].getAttribute(lang)+"<br>");
		temp.push(tel+c[i].getElementsByTagName("tel")[0].childNodes[0].nodeValue+"<br>");
		temp.push(fax+c[i].getElementsByTagName("fax")[0].childNodes[0].nodeValue+"<br>"); 
//		var cctitle = c[i].getElementsByTagName("title")[0].getAttribute(lang);
		temp.push("<a href=\"mailto:"+c[i].getElementsByTagName("email")[0].childNodes[0].nodeValue+"?cc=enq@investhk.gov.hk&subject=Enquiry from InvestHK website&body=To efficiently respond to your enquiry, please provide contact details, company name, nature of business, sector and country of origin.\">");
		temp.push(c[i].getElementsByTagName("email")[0].childNodes[0].nodeValue+"</a></div>");
	break;}
	}
//	temp 
document.getElementById(span_name).innerHTML=temp.join("");
}

function AddOptions(span_name, without_value){
	var item_no = 1;
	var MAX_NO = 50;
	if(this.loadXMLStatus==false){
		return;
	}
	else{
		if(document.getElementById(span_name)==undefined){
			this.showError("There is no this span name \"" + span_name +"\" in this content.");
		}
		else if(document.getElementById(span_name).length==undefined){
			this.showError("Please use <SELECT> tag for span name \"" + span_name +"\" and try again.");
		}
		else{
			while(true && item_no <= MAX_NO){
				try{
					if(without_value){
						document.getElementById(span_name).options[document.getElementById(span_name).length]=new Option(this.tempObject["item"][item_no-1]["title"],"#");
					}else{
						document.getElementById(span_name).options[document.getElementById(span_name).length]=new Option(this.tempObject["item"][item_no-1]["title"],this.tempObject["item"][item_no-1]["link"]);
					}
					item_no ++;
				}
				catch (error){
					break;
				}
			}
		}
	}
}

function AddOption(span_name,item_no,without_value){
	if(this.loadXMLStatus==false){
		return;
	}else if(item_no==undefined){
		this.showError("Item number is missing.");
	}else{
		try{
			if(document.getElementById(span_name)==undefined){
				this.showError("There is no this span name \"" + span_name +"\" in this content.");
			}else if(document.getElementById(span_name).length==undefined){
				this.showError("Please use <SELECT> tag for span name \"" + span_name +"\" and try again.");
			}else{		
				if(without_value!=false){
					document.getElementById(span_name).options[document.getElementById(span_name).length]=new Option(this.tempObject["item"][item_no-1]["title"],this.tempObject["item"][item_no-1]["link"]);
				}else{
					document.getElementById(span_name).options[document.getElementById(span_name).length]=new Option(this.tempObject["item"][item_no-1]["title"]);
				}
			}
		}catch(error){
			this.showError("AddOption Error: There have " + this.tempObject["item"].length + " item(s) only. Item no \"" + item_no + "\" doesn't exist in this content.");
		}
	}
}

function AddMenu(span_name,item_no,selected){
	if(this.loadXMLStatus==false){
		return;
	}else if(item_no==undefined){
		this.showError("Item number is missing.");
	}else{
		if(this.submenu["item"]==undefined){
			this.submenu["item"]=new Array();
		}
		
		if(selected===true){
			this.submenu["selected"]=true;
		}else{
			this.submenu["selected"]=false;
		}
		
		try{
			if(document.getElementById(span_name)==undefined){
				this.showError("There is no this span name \"" + span_name +"\" in this content.");
			}else{
				
				this.submenu["content"]="";
				this.submenu["item"][this.submenu["item"].length]=this.setURL(this.tempObject["item"][item_no-1]["title"],this.tempObject["item"][item_no-1]["link"],"selected");
				
				if(this.submenu["item"].length>this.submenu["display_length"]){
					this.submenu["display_record"]=this.submenu["display_length"];
				}else{
					this.submenu["display_record"]=this.submenu["item"].length;
				}
				
				for(i=0;i<this.submenu["display_record"];i++){
					this.submenu["content"]+=this.submenu["item"][i];
				}
				if(this.submenu["item"].length>this.submenu["display_length"]){
					this.submenu["content"]+='<span class="extend" onMouseOver="html.toggleMenu(\'' + span_name + '\');"><a href="#"></a></span>';
					this.submenu["exist_content"]=this.submenu["content"];
				}
				
				document.getElementById(span_name).innerHTML=this.submenu["content"];
			}
		}catch(error){
			this.showError("AddMenu Error: There have " + this.tempObject["item"].length + " item(s) only. Item no \"" + item_no + "\" doesn't exist in this content.");
		}
	}
	
}

function ToggleMenu(span_name,onMouseOver){
	this.submenu["span_name"]=span_name;
 	document.getElementById(span_name).position="absolute";
 	//document.getElementById(span_name).style.background=this.submenu["background_color"];
	
	if(onMouseOver!="false"){
		document.getElementById("menu_block").style.height=document.body.clientHeight + "px";
		document.getElementById("menu_block").style.width=document.body.clientWidth + "px";
		document.getElementById("menu_block").style.display="";
		this.submenu["content"]="";
		for(i=0;i<this.submenu["item"].length;i++){
			this.submenu["content"]+=this.submenu["item"][i];
		}
		document.getElementById(span_name).innerHTML=this.submenu["content"];
		document.getElementById(span_name).style.zIndex="500";
		document.getElementById(span_name).innerHTML='<span style="z-index: 500; background-color:'+this.submenu["background_color"]+';">' + document.getElementById(span_name).innerHTML + '</span>';
	}else if(onMouseOver=="false"){
		document.getElementById("menu_block").style.display="none";
	 	document.getElementById(span_name).style.border="0px";
		document.getElementById(span_name).style.height="105px";
		document.getElementById(span_name).innerHTML=this.submenu["exist_content"];
	}
}

function ShowError(error){
	if(this.debug_mode===true){
		alert(error);
	}
}

function echo(str){
	document.writeln(str);
}

function setURL(str,url,cssclass,description){
	if(url==null || url==""){
		if(cssclass!=null){
			return "<span class=\"" + cssclass + "\">" + str+ "</span>";
		}else{
			return str;
		}
	}else{
		if(cssclass==null || cssclass==""){
			if(url==""){
				return str;
			}else if(url=="#"){
				url=window.location;
			}else if(/javascript:/.test(url)){
				return "<a href=\"" + url + "\">"+str+"</a>";
			}else if(url.search(/\.pdf/)>-1||url.search(/\.doc/)>-1||/http:/.test(url)){
				if (description==null || description=="") {
					return "<a href=\"" + url + "\" target=_blank>" + str+ "</a>";
				}else{
					return "<a href=\"" + url + "\" title=\"" + description + "\" target=_blank>" + str+ "</a>";
				}
			}else if(url.search(/http:/)==-1&&url.search(/mailto:/)==-1){
				url=this.url_location + this.start_path + "/" + url;
			}						
			if (description==null || description=="") {
				return "<a href=\"" + url + "\">" + str+ "</a>";
			}else{
				return "<a href=\"" + url + "\" title=\"" + description + "\">" + str+ "</a>";
			}
		}else{
			if(this.submenu["selected"]==true){
				return "<a href=\"" + this.url_location + this.start_path + "/" + url + "\" class=\"" + cssclass + "\">" + str+ "</a>";
			}else{
			if(/http:/.test(url))
			return "<a href=\""+url+ "\" target=_blank><span class=\"" + cssclass + "\">" + str+ "</span></a>";
			else {
				return "<a href=\""+ url + "\"><span class=\"" + cssclass + "\">" + str+ "</span></a>";}
			//return "<a href=\"" + this.url_location + this.start_path + "/" + url + "\"><span class=\"" + cssclass + "\">" + str+ "</span></a>";}
			}
		}
	}
}

function SwitchLang(lang){
	if(/en/.test(lang)||/tc/.test(lang)||/sc/.test(lang))location.href=document.URL.replace("/" + this.lang + "_", "/" + lang +"_");
	else location.href="../common/" + lang + "_index.html";
}
function loadItems(item,rows,l){
	rows.push("<li><a href=\"/default_bodies/"+item.getAttribute("url")+"\">"+item.getAttribute(l)+"</a></li>");
	for(var i=0;i<item.childNodes.length;i++){
		if(item.childNodes[i].nodeType==3)continue;
		rows.push("<ul>");loadItems(item.childNodes[i],rows,l);rows.push("</ul>");
	}
}

function loadXML(fname,ext){
	var xmlhttp = false;
	var xmlDoc = null;
	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest && !(window.ActiveXObject)){
	 	try{
			xmlhttp = new XMLHttpRequest();
    	}catch(e){
			xmlhttp = false;
	    }
	    // branch for IE/Windows ActiveX version
	}else if(window.ActiveXObject){
	    try{
	       	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	    }catch(e) {
	    	try{
	        	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	        }catch(e){
	        	xmlhttp = false;
	        }
		}
	}
	
	if(xmlhttp&&!ext)xmlhttp.open("GET", this.url_location + fname, false);
	else if(xmlhttp&&ext)xmlhttp.open("GET", fname, false);
	if(xmlhttp){
		xmlhttp.send("");
		xmlDoc=xmlhttp.responseXML;
		this.fileLastModified=xmlhttp.getResponseHeader("Last-Modified");
	}
	return(xmlDoc);
}

function createBookmark(){
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(document.title,location.href,"");
	}else if( window.external ) { // IE Favorite
		window.external.AddFavorite(location.href,document.title);
	}else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}

var notice_left_margin=20;   // change the # on the left to adjuct the X co-ordinate
var notice_top_margin=130;   // change the # on the left to adjuct the Y co-ordinate

function Close_Notice() {
  document.getElementById("noticepopup").style.visibility='hidden';
}

function Show_Notice() {
  document.getElementById("noticepopup").style.visibility='visible';
}

function Move_Notice() {
  if (document.getElementById("noticepopup").style.visibility=='visible') {
	  if (document.body) {
	    document.getElementById("noticepopup").style.top = (document.body.scrollTop + notice_top_margin) + "px";
		document.getElementById("noticepopup").style.left = (document.body.scrollLeft + notice_left_margin) + "px";
		}
	  else {
	    document.getElementById("noticepopup").style.top = window.pageYOffset + (window.innerHeight - (window.innerHeight-notice_top_margin)) + "px";
	    document.getElementById("noticepopup").style.left = window.pageXOffset + (window.innerWidth - (window.innerWidth-notice_left_margin)) + "px";
		}
	  window.setTimeout("Show_Notice()", 10); 
  }
}

function Load_Notice(notice,delay) {
	var items = notice.getElementsByTagName("item");
	if (items.length > 0) {
		document.getElementById("noticepopup").innerHTML=items[0].getElementsByTagName("description")[0].childNodes[0].nodeValue;
		window.setTimeout("Show_Notice()",delay);
	}
}

function Contact_Us(lang,to_addr)
{ 
var enq_addr = "enq@investhk.gov.hk";
var mailto_url = "mailto:";
if (to_addr == enq_addr ) {
	mailto_url = mailto_url + to_addr;
}
else {
	mailto_url = mailto_url + to_addr + "?cc=" + enq_addr;
}
/*switch(lang) {
case "tc":
	email_subject="投資推廣署網站查詢";
	email_body="請提供您的公司名稱、國家、聯絡資料及業務性質，以便將您的查詢給予合適的同事跟進。";
	break;
case "sc":
	email_subject="投資推廣署網站查詢";
	email_body="請提供您的公司名稱、國家、聯絡資料及業務性質，以便將您的查詢給予合適的同事跟進。";
	break;
case "en":
	email_subject="Enquiry from InvestHK Website";
	email_body="Please kindly provide company name, contact details, country of origin, business nature and sector.";
	break;
}*/
email_subject="Enquiry from InvestHK Website";
email_body="To efficiently respond to your enquiry, please provide contact details, company name, nature of business, sector and country of origin.";
mailto_url = mailto_url + "?subject=" + email_subject + "&body=" + email_body;
/*mailto_win = window.open(mailto_url,'InvestHK');
if (mailto_win && mailto_win.open &&!mailto_win.closed) mailto_win.close(); */
window.location.href=mailto_url;
} 

function AddRoundBorder(){
	var render = false;
	// border for boxes
	if (document.getElementById("pinkbox") != null || document.getElementById("bluebox") != null || document.getElementById("redbox") != null){
		
		if (document.getElementById("redbox") != null){
			try{
				if (document.getElementById("show_mostpopular")!=null && document.getElementById("show_mostpopular").innerHTML !=""){
					render=true;
				}
				if (document.getElementById("show_casestudy")!=null && document.getElementById("show_casestudy").innerHTML !=""){
					render=true;
				}
				if (document.getElementById("redbox").innerText.length>0){
					render=true;
				}
			}catch (e){}
			
			if (!render){
				document.getElementById("redbox").parentNode.innerHTML = "";
			}
			else {
				document.getElementById("redbox").style.background = "#c50202";
				document.getElementById("redbox").style.border = "2px solid #c50202";
			}
		}
		
		if (render){
			head=document.getElementsByTagName("head")[0];
			
			var js = document.createElement('script');
			js.setAttribute('type', 'text/javascript');
			js.setAttribute('src', "../../resources/js/cssquery2-p.js");
			head.appendChild(js);
			var js1 = document.createElement('script');
			js1.setAttribute('type', 'text/javascript');
			js1.setAttribute('src', "../../resources/js/ruzeeborders.js");
				
			if (js1.readyState){  //IE
				js1.onreadystatechange = function(){
					if (js1.readyState == "loaded" ||	js1.readyState == "complete"){
						js1.onreadystatechange = null;
						RUZEE.Borders.add({
						  '#pinkbox': { borderType:'shadow', cornerRadius:5, shadowWidth:5 },
						  '#bluebox': { borderType:'shadow', cornerRadius:5, shadowWidth:5 },
						  '#redbox': { borderType:'shadow', cornerRadius:5, shadowWidth:5 }
						});
						RUZEE.Borders.render();
					}
				};
			} else {  //Others
				js1.onload = function(){
						RUZEE.Borders.add({
						  '#pinkbox': { borderType:'shadow', cornerRadius:5, shadowWidth:5 },
						  '#bluebox': { borderType:'shadow', cornerRadius:5, shadowWidth:5 },
						  '#redbox': { borderType:'shadow', cornerRadius:5, shadowWidth:5 }
						});
						RUZEE.Borders.render();
				};
			}
			head.appendChild(js1);	
		}
	}
}

function HTML(start_path){
	this.start_path=start_path;
	
	// graphic mode function
	this.echo=echo;
	this.init=Website_Init;
	this.setURL=setURL;
	this.loadXML=loadXML;
	this.casestudy=CaseStudy;
	this.mostpopular=MostPopular;
	this.loadQuote=loadQuote;
	this.stopQuote=stopQuote;
	this.loadContent=LoadContent;
	this.showContent=ShowContent;
	this.addOption=AddOption;
	this.addOptions=AddOptions;
	this.addMenu=AddMenu;
	this.toggleMenu=ToggleMenu;
	this.showError=ShowError;
	this.showImageButton=ShowImageButton;
	this.loadMenuBarItems=loadMenuBarItems
	this.lastModified=new Date(1970,1,1);
	this.fileLastModified;
	this.close_notice=Close_Notice;
	this.show_notice=Show_Notice;
	this.move_notice=Move_Notice;
	this.load_notice=Load_Notice;
	this.loadcontact=loadcontact;
	this.showContact=ShowContact;
	this.showHQ=ShowHQ;
	this.contact_us=Contact_Us;
	this.addRoundBorder=AddRoundBorder;
	
	// define lang
	if(window.location.toString().indexOf("/tc_")!==-1){
		this.lang="tc";
	}else if(window.location.toString().indexOf("/sc_")!==-1){
		this.lang="sc";
	}else if(window.location.toString().indexOf("/fr_")!==-1){
		this.lang="fr";
	}else if(window.location.toString().indexOf("/de_")!==-1){
		this.lang="de";
	}else if(window.location.toString().indexOf("/it_")!==-1){
		this.lang="it";
	}else if(window.location.toString().indexOf("/jp_")!==-1){
		this.lang="jp";
	}else if(window.location.toString().indexOf("/ko_")!==-1){
		this.lang="ko";
	}else if(window.location.toString().indexOf("/pt_")!==-1){
		this.lang="pt";
	}else if(window.location.toString().indexOf("/ru_")!==-1){
		this.lang="ru";
	}else if(window.location.toString().indexOf("/es_")!==-1){
		this.lang="es";
	}else{
		this.lang="en";
	}
	
	// private variable
	var path_array=window.location.toString().split("/");
	var i;
	var start_path=false;
	var temp_path="";
	if(path_array[path_array.length-1]==undefined || path_array[path_array.length-1]==""){
		this.filename="index.html";
	}else{
		this.filename=path_array[path_array.length-1];
	}
	
	for(i=0;i<path_array.length;i++){
		if(start_path==true){
			temp_path+="../";
		}
		
		if(path_array[i]==this.start_path){
			start_path=true;
			try{
				this.sub_category=path_array[i+1];
			}catch(err){
			}
		}
	}
	this.url_location=temp_path;
	this.SwitchLang=SwitchLang;
	this.language=new Object();
	this.submenu=new Object();
	this.quote=new Array();
	this.define_lang=new Array();
	this.define_lang[this.define_lang.length]="en";
	this.define_lang[this.define_lang.length]="tc";
	this.define_lang[this.define_lang.length]="sc";
	this.define_lang[this.define_lang.length]="fr";
	this.define_lang[this.define_lang.length]="de";
	this.define_lang[this.define_lang.length]="it";
	this.define_lang[this.define_lang.length]="jp";
	this.define_lang[this.define_lang.length]="ko";
	this.define_lang[this.define_lang.length]="pt";
	this.define_lang[this.define_lang.length]="ru";
	this.define_lang[this.define_lang.length]="es";
	
	this.define_lang_code=new Object();
	this.define_lang_code["en"]="eng";
	this.define_lang_code["tc"]="cht";
	this.define_lang_code["sc"]="chs";
	this.define_lang_code["fr"]="fra";
	this.define_lang_code["de"]="deu";
	this.define_lang_code["it"]="ita";
	this.define_lang_code["jp"]="jpn";
	this.define_lang_code["ko"]="kor";
	this.define_lang_code["pt"]="por";
	this.define_lang_code["ru"]="rus";
	this.define_lang_code["es"]="spn";
	
	
	// custom define value
	this.debug_mode=true; // true or false
	this.submenu["display_length"]=4;
	this.submenu["border_color"]="#FFFFFF";
	this.submenu["border_width"]=1;
	this.submenu["background_color"]="";	
}

html=new HTML("default_bodies");


// sub menu background
html.echo('<div id="menu_block" style="display: ; background-color: gray; ');
html.echo('        position: absolute; left: 0px; top: 0px; margin-right: 0px; z-index: 300; filter:alpha(opacity=0);-moz-opacity:0;opacity:0;"');
html.echo('        onclick="return false" onmouseover="');
html.echo('html.toggleMenu(html.submenu[\'span_name\'],\'false\');');
html.echo('" onmousedown="return false;" onmousemove="return false;" ');
html.echo('        onmouseup="return false" ondblclick="return false">');
html.echo('</div>');
if (document.location.href.indexOf("_sectors_")>0){
	html.echo('<div class="sector1subMenuBtn" style="position:absolute; left:685px; top:150px; z-index:300"><h5><span id="menu"></span></h5></div>');
}
else {
	html.echo('<div class="subMenuBtn" style="position:absolute; left:685px; top:150px; z-index:300"><h5><span id="menu"></span></h5></div>');
}