var selectedSection;
var subSection;
var secondSubSection;
var exLevel;
var langID;
var langPath;
var locationPath;
var revisionDate;
var imagePath;
var	topButton;
var	backPage;
var	nextPage;
var	EngOnly;
var	vspace;
var isText;
var filePath='';
var folderPath='';
var textOnlyPath;
var graphicPath;
var isGICSearch=false;
var mainTopicNo = "";
var activeLeftMenuID = "";
var firstLayerTimerID;
var leftMenuFlag = false;
var firstLayerFlag = false;
var leftMenuWidth = 153;
var highestLeftMenuButton = 0;
var demo = false;
var govTestSite = false;
var govKanHan = true;
var http = "ht"+"tp://"
var sKanhanServer = "";
var hostAddress;
var z = "";

if(document.URL.toString().search('test2.westcomzivo.com') != -1){demo = true}
else if (document.URL.toString().search('www0.') != -1){demo = true}
else {demo = false}

if(document.URL.toString().search('westcomzivo') != -1){govTestSite = false}
else if (document.URL.toString().search('gov.hk') != -1){govTestSite = true}
//else {false = false}

//Java Script variable for global use
var locPath=location.href.toString();
var targetString;
var subPath;


var leftMenuCommonImageName = "nav_";
var leftMenuSectionImageOut = ".gif";
var leftMenuSectionImageOver = "_on.gif";


if(location.href.toString().search('westcomzivo')!=-1){
	hostAddress="test2.westcomzivo.com";
	locationPath='ht'+'tp://test2.westcomzivo.com/sfaa/';
	graphicPath=locationPath.substring(7,locationPath.length);
	gb_urlPath='common.westcomzivo.com/gb/';
	textOnlyPath="www0.sfaa.gov.hk/cgi-bin/sfaa/TextOnly.pl"
}else if(location.href.toString().indexOf('www0.sfaa.gov.hk')!=-1){
	hostAddress="www0.sfaa.gov.hk";
	locationPath='ht'+'tp://www0.sfaa.gov.hk/';
	graphicPath=locationPath.substring(7,locationPath.length);
	gb_urlPath='sc.info.gov.hk/gb/';
	textOnlyPath="www0.sfaa.gov.hk/cgi-bin/sfaa/TextOnly.pl"
}else if(location.href.toString().indexOf('www.sfaa.gov.hk')!=-1){
	hostAddress="www.sfaa.gov.hk";
	locationPath='ht'+'tp://www.sfaa.gov.hk/';
	graphicPath=locationPath.substring(7,locationPath.length);
	gb_urlPath='sc.info.gov.hk/gb/';
	textOnlyPath="www.sfaa.gov.hk/cgi-bin/sfaa/TextOnly.pl"
}else if(location.href.toString().indexOf('se.cgi')!=-1){
	/*locationPath='ht'+'tp://www.sfaa.gov.hk/';
	graphicPath=locationPath.substring(7,locationPath.length);
	gb_urlPath='sc.info.gov.hk/gb/';
	textOnlyPath="www.sfaa.gov.hk/cgi-bin/sfaa/TextOnly.pl"*/
	locationPath='ht'+'tp://www.sfaa.gov.hk/';
	graphicPath=locationPath.substring(7,locationPath.length);
	gb_urlPath='sc.info.gov.hk/gb/';
	textOnlyPath="www.sfaa.gov.hk/cgi-bin/sfaa/TextOnly.pl"
	isGICSearch=true;
} else if (location.href.toString().indexOf('ogciosfaa.arcotect.com')!=-1) {
	locationPath='ht'+'tp://ogciosfaa.arcotect.com/';
	graphicPath=locationPath.substring(7,locationPath.length);
	gb_urlPath='sc.info.gov.hk/gb/';
	textOnlyPath="www.sfaa.gov.hk/cgi-bin/sfaa/TextOnly.pl"
}else{
	hostAddress="www.sfaa.gov.hk";
	locationPath='ht'+'tp://www.sfaa.gov.hk/';
	graphicPath=locationPath.substring(7,locationPath.length);
	gb_urlPath='ht'+'tp://www.sfaa.gov.hk/gb/';
	textOnlyPath="www.sfaa.gov.hk/cgi-bin/sfaa/TextOnly.pl"
}


/* 
if(location.href.toString().search('/eng/')!=-1){
	targetString=location.href.search('/eng/')+1;
	subPath=locPath.substring(0, targetString);
}
if(location.href.toString().search('/tc/')!=-1){
	targetString=location.href.search('/tc/')+1;
	subPath=locPath.substring(0, targetString);
}
if(location.href.toString().search('/gb/')!=-1){
	targetString=location.href.search('/gb/')+4;
	locationPath=locPath.substring(targetString);
	targetString=locPath.search('/tc/');
	subPath=locPath.substring(0, targetString);
	subPath=subPath+'/';
}

locationPath=subPath;
graphicPath=locationPath.substring(7,locationPath.length);



if(location.href.toString().search('westcomzivo')!=-1){
	gb_urlPath='common.westcomzivo.com/gb/';
}else if(location.href.toString().indexOf('www0.info.gov.hk/sfaa/')!=-1){
	gb_urlPath='sc.info.gov.hk/gb/';
}else if(location.href.toString().indexOf('www.info.gov.hk/sfaa/')!=-1){
	gb_urlPath='sc.info.gov.hk/gb/';
}else if(location.href.toString().indexOf('se.cgi')!=-1){
	gb_urlPath='common.westcomzivo.com/gb/';
	isGICSearch=true;
}else{
	gb_urlPath='202.64.223.233/gb/';
}
*/



/*
if(location.href.toString().search('westcomzivo')!=-1){
	locationPath='ht'+'tp://test2.westcomzivo.com/sfaa/';
	graphicPath=locationPath.substring(7,locationPath.length);
	gb_urlPath='common.westcomzivo.com/gb/';
	//textOnlyPath="test.cedd.gov.hk/cgi-bin/cedd/TextOnly.pl"
}else if(location.href.toString().indexOf('www0.info.gov.hk/sfaa/')!=-1){
	locationPath='ht'+'tp://www0.info.gov.hk/sfaa/';
	graphicPath=locationPath.substring(7,locationPath.length);
	gb_urlPath='sc.info.gov.hk/gb/';
	//textOnlyPath="test.cedd.gov.hk/cgi-bin/cedd/TextOnly.pl"
}else if(location.href.toString().indexOf('www.info.gov.hk/sfaa/')!=-1){
	locationPath='ht'+'tp://www.info.gov.hk/sfaa/';
	graphicPath=locationPath.substring(7,locationPath.length);
	gb_urlPath='sc.info.gov.hk/gb/';
	//textOnlyPath="www.cedd.gov.hk/cgi-bin/cedd/TextOnly.pl"
}else if(location.href.toString().indexOf('se.cgi')!=-1){
	locationPath='ht'+'tp://test2.westcomzivo.com/sfaa';
	graphicPath=locationPath.substring(7,locationPath.length);
	gb_urlPath='common.westcomzivo.com/gb/';
	//textOnlyPath="test.cedd.gov.hk/cgi-bin/cedd/TextOnly.pl"
	isGICSearch=true;
}else{
	locationPath='ht'+'tp://127.0.0.1/sfaa/';
	graphicPath=locationPath.substring(7,locationPath.length);
	gb_urlPath='202.64.223.233/gb/';
//	textOnlyPath="test.cedd.gov.hk/cgi-bin/cedd/TextOnly.pl"


//	locationPath='ht'+'tp://202.64.223.171:8050/dev/';
//	graphicPath=locationPath.substring(7,locationPath.length);
//	gb_urlPath='202.64.223.233/gb/';
//	textOnlyPath="test.cedd.gov.hk/cgi-bin/cedd/TextOnly.pl"

}
*/

//change the locationPath for text only version
if(location.href.toString().indexOf('TextOnly.pl')!=-1|| location.search.toString().indexOf('isText=true')!=-1){
	isText=true;
	locationPath="ht"+"tp://"+textOnlyPath+"?search=";
}else{
	isText=false;
}

//change the locationPath for text only version
function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}
}
QueryString_Parse();

//function for document. e.g. doc, pdf
function documentPopUp(url){
	if(isText) url="ht"+"tp://"+graphicPath+updatePath(folderPath+url);
	eval("nw = window.open(url, 'document','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,pageXOffset=0,pageYOffset=0,top=0,left=0,width=700,height=500')");
	if ( nw.focus != null)
	{nw.focus();}
}

//function for text only version to get the real path of the HTML file
function updatePath(oldFilePath)
{
	var arFilePath = new Array();
	arFilePath = oldFilePath.split("/");
	var arFilePathTemp = new Array();
	for (i in arFilePath) 
	{
	   if (arFilePath[i] != "..") 
	   {arFilePathTemp.push(arFilePath[i]);}
	   else 
	   {arFilePathTemp.pop();}
	}
	var newFilePath = "";
	return newFilePath = arFilePathTemp.join("/");
}

//set the lang path and lang ID
if(isText)
{
	if(location.search.toString().indexOf('search=')!=-1)
	{
		filePath=updatePath(QueryString("search"))
		folderPath=filePath.substring(0,filePath.lastIndexOf("/")+1)
	}
	
	if(filePath.search('eng/')!=-1 || location.search.toString().indexOf('lang=eng')!=-1 || location.search.toString().indexOf('mode=261')!=-1){
		langPath = 'eng/';
		lang="eng";
		langID=1;
		vspace=0;
	}else{
		langPath = 'tc/';
		lang="chi";
		langID=2;
		vspace=3;
	}
}else{
	if(document.URL.toString().search('/eng/')!=-1 || location.search.toString().indexOf('lang=eng')!=-1 || location.search.toString().indexOf('mode=261')!=-1){
		langPath = 'eng/';
		lang="eng";
		langID=1;
		vspace=0;
	}else{
		langPath = 'tc/';
		lang="chi";
		langID=2;
		vspace=3;
	}
}

//change the location path and image path for Simplified Chinese version
if(document.URL.toString().search('/gb/')!=-1){
	imagePath = locationPath+'gb/';
	locationPath='ht'+'tp://'+gb_urlPath+locationPath.substring(7, locationPath.length);
}else{
	imagePath = locationPath+langPath;
}

//function for mouse over effect on left menu
function overTopMenu(obj)
{
        if (document.images){
				eval("document.images." + obj + ".src = '"+imagePath+"images/" + obj + "_f2.gif'");
        }
}

//function for mouse out effect on left menu
function outTopMenu(obj)
{
        if (document.images){
				eval("document.images." + obj + ".src = '"+imagePath+"images/" + obj + ".gif'");
        }
}

//function for switching image
function simg(obj,src)
{
        if (document.images){
                obj.src = src;
        }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  if(isText) theURL="ht"+"tp://"+graphicPath+updatePath(folderPath+theURL);
  window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  var tempPath = "";
  if(isText) {tempPath=locationPath+folderPath;}
  eval(targ+".location='"+tempPath+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//function for switching language
function changeLanguage(l){
	var lh = parent.location.href;
	if (l=="text") {
		if (isText) {
			lh = lh.replace("cgi-bin/sfaa/TextOnly.pl?search=", "");
		} else {
			if (lh.search("lang=")!=-1) {
				alert("Sorry, text version not available for this page. / 抱歉, 本頁不設純文字版 / 抱歉, 本页不设纯文字版");
			} else {
				lh = lh.replace("sfaa.gov.hk/", "sfaa.gov.hk/cgi-bin/sfaa/TextOnly.pl?search=");
			}
		}
	} else {
		if (isText) {
			lh = lh.replace("?search=tc/", "?search="+l+"/");
			lh = lh.replace("?search=chs/", "?search="+l+"/");
			lh = lh.replace("?search=eng/", "?search="+l+"/");
		} else {
			if (lh.search("lang=")!=-1) {
				if (l=="tc") l = "chi";
				if (lh.search("coursesearch.pl")!=-1) {
					courseSearchForm.action="coursesearch.pl?lang="+l;
					courseSearchForm.lang.value=l;
					courseSearchForm.submit();
					return;
				}
				if (lh.search("coursesearch_detail.pl")!=-1) {
					courseSearchDForm.action="coursesearch_detail.pl?lang="+l;
					courseSearchDForm.lang.value=l;
					courseSearchDForm.submit();
					return;
				}
				lh = lh.replace("lang=tc", "lang="+l);
				lh = lh.replace("lang=chi", "lang="+l);
				lh = lh.replace("lang=chs", "lang="+l);
				lh = lh.replace("lang=eng", "lang="+l);
			} else {
				lh = lh.replace("/tc/", "/"+l+"/");
				lh = lh.replace("/chs/", "/"+l+"/");
				lh = lh.replace("/eng/", "/"+l+"/");
			}
		}
	}
	parent.location.href = lh;
}
/*
function changeLanguage(switchLang){
	var locationPage;
	var currentPath=document.URL.toString();
	var slash="/";
	var tempSwitchLang=switchLang;
	var switchTc="/tc/";
	var ready = true;
	var modeTc = "mode=1";
	var modeEng = "mode=0";
	var currentMode = "";
	var targetMode = "";
//use for switch pl purpose (begin)
	var pathname = window.location.href.toLowerCase();
	var cgiFlag = false;
	var courseFormFlag = false;
//use for switch pl purpose (end)

	//use for special case 
	//Major Project
	if(location.href.toString().search('search.*cgi')!=-1){
	//if(location.search.toString().indexOf('isText=true')!=-1&&location.href.toString().indexOf('/cgi-bin/se.cgi')==-1){
		if(secondSubSection!="" && secondSubSection>0){
			currentPath=SecondSubSection[langID][selectedSection][subSection][secondSubSection];
		}else if(subSection!="" && subSection>0){
			currentPath=SubSection[langID][selectedSection][subSection];
		}else{
			currentPath=MainSection[langID][selectedSection];
		}
	}
	
	if(isText){
		currentPath=currentPath.replace(location.search,"?search="+filePath)
		slash="=";
		switchTc="=tc/";
		tempSwitchLang="="+switchLang.substring(1,switchLang.length);
	}
	
	if(isGICSearch){
		currentPath=document.URL.toString();

		if(langID==1){
			currentMode=modeEng
		}else{
			currentMode=modeTc
		}
		
		if(switchLang=='/tc/'){
			targetMode=modeTc;
			currentPath=currentPath.replace("mode=261", "mode=262");
		}else{
			targetMode=modeEng
			currentPath=currentPath.replace("mode=262", "mode=261");
		}
	}
	
	if(switchLang=='/text/'){
		if(isText){
			//locationPage=currentPath.replace(textOnlyPath+"?search=",graphicPath);
			locationPage=currentPath.replace(textOnlyPath,"");
			locationPage=locationPage.replace("?search=",graphicPath);
		}else{
			locationPage=currentPath.replace(graphicPath,textOnlyPath+"?search=")
			if(isGICSearch){
				if(langID==1){
					alert("Search function for text only version is not available")
				}else{
					alert("本網站並沒有提供純文字版本的搜尋功能")
				}
				ready=false
			}
		}
	}else if(switchLang=='/gb/'){
		locationPage=currentPath.substring(7, currentPath.length);
		if(langID==1){
			if(isGICSearch){
				locationPage='ht'+'tp://'+gb_urlPath+locationPage.replace(modeEng, modeTc);
			}else{
				locationPage='ht'+'tp://'+gb_urlPath+locationPage.replace(slash+langPath, switchTc);
			}
		}else{
			locationPage='ht'+'tp://'+gb_urlPath+locationPage;		
		}
	}else{
		if(currentPath.search('/gb/')!=-1){
			locationPage=currentPath.replace(gb_urlPath, "");
			if(isGICSearch){
				locationPage=locationPage.replace(currentMode, targetMode);
			}else{
				locationPage=locationPage.replace(slash+langPath, tempSwitchLang);
			}
		}else{
			if(isGICSearch){
				locationPage=currentPath.replace(currentMode, targetMode);
			}else{
				locationPage=currentPath.replace(slash+langPath, tempSwitchLang);
			}
		}
	}
	
//use for switch pl purpose (begin)

//	if (pathname.indexOf("/cgi-bin/")!=-1)
//	{
		if (pathname.indexOf("coursesearch.pl")!=-1 || pathname.indexOf("coursesearch_detail.pl")!=-1 || pathname.indexOf("course.pl")!=-1)
		{
//			if (switchLang.indexOf("/text/")!=-1)
			if (switchLang=='/text/')
			{
				alert('Text Only Version is not available at the moment.');
//				locationPage = "javascript:alert('Text Only Version is not available at the moment.')";
//				pathname = pathname.replace(".pl", "_t.pl");
//				switchLang = switchLang.replace("/text", "");
				ready = false;
			}
			cgiFlag = true
			courseFormFlag = true
		}
/*		
		else if (pathname.indexOf("coursesearch_t.pl")!=-1 || pathname.indexOf("coursesearch_detail_t.pl")!=-1 || pathname.indexOf("course_t.pl")!=-1)
		{
			if (curLang.indexOf("/text/")!=-1)
			{
				pathname = pathname.replace("_t.pl", ".pl");
			}
			cgiFlag = true
			courseFormFlag = true
		}

//	}
	
//	if (curLang == "/gb/"){pathname = pathname.replace(http+sKanhanServer, http);curLang="/tc/"}
//	if (switchLang == "/gb/"){pathname = pathname.replace(http, http+sKanhanServer);switchLang="/tc/"}
	if (cgiFlag)
//	{location = pathname.replace(curLang, tarLang);}
//	else
	{

		if (courseFormFlag)
		{locationPage=courseFormSwitchLang(pathname, switchLang);}
//		else if (gicSearchFlag)
//		{gicSearchSwitchLang(pathname, curLang, tarLang);}
	}	
//use for switch pl purpose (end)

//	alert(locationPage);
	if (ready){
		document.location=locationPage;
	}
}
*/
//function for generating the top menu
function getTopMenu(){

	if(langID==1){
		if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) <= 4))
		{
			var extarSpacer = '<td background="'+imagePath+'images/mainbar5.gif" bgcolor="#FAFAEB"><img name="mainbar5" src="'+imagePath+'images/spacer.gif" border="0" height=1 width=131 alt=""></td>';
		}
		else
		{
			var extarSpacer = '<td background="'+imagePath+'images/mainbar5.gif" bgcolor="#FAFAEB"><img name="mainbar5" src="'+imagePath+'images/spacer.gif" border="0" height=1 width=129 alt=""></td>';
		}
	}else{
		if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) <= 4))
		{
			var extarSpacer = '<td background="'+imagePath+'images/mainbar5.gif" bgcolor="#FAFAEB"><img name="mainbar5" src="'+imagePath+'images/spacer.gif" border="0" height=1 width=162 alt=""></td>';
		}
		else
		{
			var extarSpacer = '<td background="'+imagePath+'images/mainbar5.gif" bgcolor="#FAFAEB"><img name="mainbar5" src="'+imagePath+'images/spacer.gif" border="0" height=1 width=121 alt=""></td>';
		}
	}

	var gicSearchForm;
	
	gicSearchForm='<form name="frmSearch" action="'+arClfTopMenu[langID][1]+'" method="get">\n';
	gicSearchForm=gicSearchForm+'<input type="hidden" name="tpl_id" value="sfaa">\n';
	gicSearchForm=gicSearchForm+'<input type="hidden" name="ui_lang" value="'+arClfTopMenu[langID][24]+'">\n';
	gicSearchForm=gicSearchForm+'<input type="hidden" name="ui_charset" value="'+arClfTopMenu[langID][25]+'">\n';
	gicSearchForm=gicSearchForm+'<input type="hidden" name="gp0" value="sfaa_home">\n';
	gicSearchForm=gicSearchForm+'<input type="hidden" name="gp1" value="sfaa_home">\n';
	gicSearchForm=gicSearchForm+'<input type="hidden" name="web" value="this">\n';
	
	//graphic version
	if(!isText){
		document.writeln('	<tr>');
		document.writeln('	<td colspan="2">');
		document.writeln('		<table width="760" border="0" cellpadding="0" cellspacing="0">');
		document.writeln(gicSearchForm);
		document.writeln('		<tr align="left" valign="top">');
		document.writeln('			<td colspan="6" class="sidebar" background="'+imagePath+'images/bkgdtexture.gif" bgcolor="#FAFAEB"><a href="'+locationPath+'index.htm"><img src="'+imagePath+'images/branding.gif" border=0 alt="'+arClfTopMenu[langID][3]+'"></a></td>');
		document.writeln('			<td rowspan="2" valign="bottom" background="'+imagePath+'images/bkgdtexture.gif" align=center><input type="text" name="query" size="'+arClfTopMenu[langID][4]+'" class="search"></td>');
		document.writeln('			<td background="'+imagePath+'images/bkgdtexture.gif" colspan="3" valign="bottom" align=right bgcolor="#FAFAEB"><a href="'+arClfTopMenu[langID][5]+'" target="_top"><img name="BrandHK" src="'+imagePath+'images/hklogo.gif" border="0" alt="'+arClfTopMenu[langID][6]+'"></a></td>');
		document.writeln('		</tr>');
		document.writeln('		<tr align="left" valign="top">');
		document.writeln('			<td background="'+locationPath+langPath+'images/bkgdtexture.gif"><a href="'+arClfTopMenu[langID][26]+'" onMouseOut="outTopMenu(\'mainbar1\')" onMouseOver="overTopMenu(\'mainbar1\')"><img name="mainbar1" src="'+imagePath+'images/mainbar1.gif" border="0" alt="'+arClfTopMenu[langID][7]+'"></a></td>');
		document.writeln('			<td align="left" valign="top"><a href="javascript:changeLanguage(\''+arClfTopMenu[langID][9]+'\')" onMouseOut="outTopMenu(\'mainbar2\')" onMouseOver="overTopMenu(\'mainbar2\')"><img name="mainbar2" src="'+imagePath+'images/mainbar2.gif" border="0" alt="'+arClfTopMenu[langID][10]+'"></a></td>');
		document.writeln('			<td align="left" valign="top"><a href="javascript:changeLanguage(\''+arClfTopMenu[langID][12]+'\')" onMouseOut="outTopMenu(\'mainbar3\')" onMouseOver="overTopMenu(\'mainbar3\')"><img name="mainbar3" src="'+imagePath+'images/mainbar3.gif" border="0" alt="'+arClfTopMenu[langID][13]+'"></a></td>');
		document.writeln('			<td align="left" valign="top"><a href="javascript:changeLanguage(\''+arClfTopMenu[langID][15]+'\')" onMouseOut="outTopMenu(\'mainbar4\')" onMouseOver="overTopMenu(\'mainbar4\')"><img name="mainbar4" src="'+imagePath+'images/mainbar4.gif" border="0" alt="'+arClfTopMenu[langID][16]+'"></a></td>');
		document.writeln(extarSpacer);
	//	document.writeln('			<td background="'+imagePath+'images/mainbar5.gif" bgcolor="#FAFAEB"><img name="mainbar5" src="'+imagePath+'images/spacer.gif" border="0" height=1 width=64 alt=""></td>');
		document.writeln('			<td background="'+imagePath+'images/bkgdtexture.gif"><a href="javascript:document.frmSearch.submit();" onMouseOut="outTopMenu(\'mainbar6\')" onMouseOver="overTopMenu(\'mainbar6\')"><img name="mainbar6" src="'+imagePath+'images/mainbar6.gif" border="0" alt="'+arClfTopMenu[langID][17]+'"></a></td>');
		document.writeln('			<td background="'+imagePath+'images/bkgdtexture.gif"><a href="javascript:document.frmSearch.submit();" onMouseOut="outTopMenu(\'mainbar8\')" onMouseOver="overTopMenu(\'mainbar8\')"><img name="mainbar8" src="'+imagePath+'images/mainbar8.gif" border="0" alt="'+arClfTopMenu[langID][17]+'"></a></td>');
		document.writeln('			<td background="'+imagePath+'images/bkgdtexture.gif"><a href="'+locationPath+langPath+'sitemap/index.htm" onMouseOut="outTopMenu(\'mainbar9\')" onMouseOver="overTopMenu(\'mainbar9\')"><img name="mainbar9" src="'+imagePath+'images/mainbar9.gif" border="0" alt="'+arClfTopMenu[langID][18]+'"></a></td>');
		document.writeln('			<td background="'+imagePath+'images/bkgdtexture.gif" bgcolor="#FAFAEB"><a href="'+locationPath+langPath+'contact/index.htm" onMouseOut="outTopMenu(\'mainbar10\')" onMouseOver="overTopMenu(\'mainbar10\')"><img name="mainbar10" src="'+imagePath+'images/mainbar10.gif" border="0" alt="'+arClfTopMenu[langID][19]+'"></a></td>');
		document.writeln('		</tr>');
		document.writeln('		<tr align="left" valign="top">');
		document.writeln('			<td height=2 colspan="10"><img src="'+imagePath+'images/reddot.gif" width="760" height="2" alt="" border=0></td>');
		document.writeln('		</tr>');
		document.writeln('		</form>');
		document.writeln('		</table>');
		document.writeln('		</td>');
		document.writeln('	</tr>');
	}else{
	//text only version
		document.writeln('<tr valign=top>');
		document.writeln('<td>');
		document.writeln('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
		document.writeln('<tr>');
		document.writeln('	<td colspan="3"><p><span class="Heading"><b>'+arClfTopMenu[langID][20]+'</b></span></p>');
		document.writeln('</td></tr>');
		document.writeln('<tr>');
		document.writeln('	<td colspan="3">&nbsp;');
		document.writeln('</td>');
		document.writeln('</tr>');
		document.writeln(gicSearchForm);
		document.writeln('<input type="hidden" name="txtonly" value="1">\n');
		document.writeln('<tr valign="middle">');
		document.writeln('	<td colspan=3>');
		document.writeln('			[ <a href="'+arClfTopMenu[langID][26]+'">'+arClfTopMenu[langID][7]+'</a> ]&nbsp;');
		document.writeln('			[ <a href="javascript:changeLanguage(\''+arClfTopMenu[langID][9]+'\')">'+arClfTopMenu[langID][21]+'</a> ]&nbsp;');
		document.writeln('			[ <a href="javascript:changeLanguage(\''+arClfTopMenu[langID][12]+'\')">'+arClfTopMenu[langID][13]+'</a> ]&nbsp;');
		document.writeln('			[ <a href="javascript:changeLanguage(\''+arClfTopMenu[langID][15]+'\')">'+arClfTopMenu[langID][16]+'</a> ]&nbsp;');
		document.writeln('			&nbsp;[&nbsp;<a href="javascript:document.frmSearch.submit();">'+arClfTopMenu[langID][17]+'</a>&nbsp;]&nbsp;');
		document.writeln('			<input type="text" size="9" name="query">&nbsp;');
		document.writeln('			[ <a href="'+locationPath+langPath+'sitemap/index.htm">'+arClfTopMenu[langID][18]+'</a> ]');
		document.writeln('			 [ <a href="'+locationPath+langPath+'contact/index.htm">'+arClfTopMenu[langID][19]+'</a> ] ');
		document.writeln('	</td>');
		document.writeln('</tr>');
		document.writeln('		</form>');
		document.writeln('<tr>');
		document.writeln('	<td colspan="3"><hr></td>');
		document.writeln('</tr>');
		document.writeln('<tr>');
		document.writeln('	<td colspan="3">[ <a href="javascript:history.back();">'+arClfTopMenu[langID][22]+'</a> ]</td>');
		document.writeln('</tr>');
		document.writeln('<tr>');
		document.writeln('	<td colspan="3"><hr></td>');
		document.writeln('</tr>');
		document.writeln('</table>');
		document.writeln('</td>');
		document.writeln('</tr>');
	}
}

//function for get the main pic
function getTopPic(){
	if(!isText){
		document.write('<img src="'+imagePath+'images/top_bar2.jpg" alt="'+arClfTopMenu[langID][3]+'" border="0">');
	}else
	{}
}


//function for generating the left menu
function getLeftMenu(){
	var isOver = '';
	var iconNo = '';
	var mainOrder = 0;

	//graphic version
	if(!isText){
		document.writeln('	<td rowspan=2 valign="top" width="153" background="'+imagePath+'images/nav_bg.gif">');
	document.writeln('<table border="0" cellspacing="0" cellpadding="0">');
		document.writeln('		<tr><td><img src="'+imagePath+'images/top_bar1.jpg" alt="" border="0"></td></tr>');

		for (var i in MainSectionOrder[langID])
		{
			mainOrder=MainSectionOrder[langID][i];
			if (mainOrder == selectedSection)
			{
					document.writeln('<tr>');
					document.writeln('<td><a href="'+MainSection[langID][mainOrder]+'" onMouseOver="leftMenuMouseOver(\''+leftMenuCommonImageName+arMainTopicImage[mainOrder]+'\')" onMouseOut="leftMenuMouseOut(\''+leftMenuCommonImageName+arMainTopicImage[mainOrder]+'\')" target="'+MainSectionTarget[langID][mainOrder]+'"><img src="'+imagePath+'images/'+leftMenuCommonImageName+arMainTopicImage[mainOrder+1]+leftMenuSectionImageOver+'" border="0" name="'+leftMenuCommonImageName+arMainTopicImage[mainOrder]+'" alt="'+MainTitle[langID][mainOrder]+'"></a></td>');
					document.writeln('</tr>');
							}
			else
			{
			//alert(MainSection[langID][mainOrder]);

					document.writeln('<tr>');
					document.writeln('<td><a href="'+MainSection[langID][mainOrder]+'" onMouseOver="leftMenuMouseOver(\''+leftMenuCommonImageName+arMainTopicImage[mainOrder]+'\')" onMouseOut="leftMenuMouseOut(\''+leftMenuCommonImageName+arMainTopicImage[mainOrder]+'\')" target="'+MainSectionTarget[langID][mainOrder]+'"><img src="'+imagePath+'images/'+leftMenuCommonImageName+arMainTopicImage[mainOrder+1]+leftMenuSectionImageOut+'" border="0" name="'+leftMenuCommonImageName+arMainTopicImage[mainOrder]+'" alt="'+MainTitle[langID][mainOrder]+'"></a></td>');
					document.writeln('</tr>');

			}
		}
      	document.writeln('</table>');
		document.writeln('	</td>');
	}else{
	//text only version
		document.writeln('	<td valign=top>');
		document.writeln('	<table width="100%" border="0" cellspacing="0" cellpadding="0">');
		document.writeln('	<tr>');
		document.writeln('	<td>');
		for (var i in MainSectionOrder[langID]){
			mainOrder=MainSectionOrder[langID][i];
			if(parseInt(mainOrder) < 100){
				document.writeln('[ <a href="'+MainSection[langID][mainOrder]+'">'+MainTitle[langID][mainOrder]+'</a> ]');
			}
		}
		document.writeln('	</td>');
		document.writeln('	</tr>');
		document.writeln('	<tr>');
		document.writeln('	<td><hr>');
		document.writeln('	</td>');
		document.writeln('	</tr>');
		document.writeln('	</table>');
		document.writeln('	</td>');
		document.writeln('	</tr>');
		document.writeln('	<tr>');
	}
	mainOrder = 0;
}


//function for generating the path indicator
function getPath(){
	var strBuffer='<a href="'+MainSection[langID][0]+'" class="pathLink">'+MainTitle[langID][0]+'</a>';
	if(subSection>0){
		if(selectedSection>0) strBuffer+=' > <a href="'+MainSection[langID][selectedSection]+'" class="pathLink">'+MainTitle[langID][selectedSection]+'</a>';
	}else{
		if(exLevel){
			if(selectedSection>0) strBuffer+=' > <a href="'+MainSection[langID][selectedSection]+'" class="pathLink">'+MainTitle[langID][selectedSection]+'</a>';
		}else{
			if(selectedSection>0) strBuffer+=' > '+MainTitle[langID][selectedSection];
		}
	}
	if(secondSubSection>0){
		if(subSection>0) strBuffer+=' > <a href="'+SubSection[langID][selectedSection][subSection]+'" class="pathLink">'+SubSectionTitle[langID][selectedSection][subSection]+'</a>';
	}else{
		if(exLevel){
			if(subSection>0) strBuffer+=' > <a href="'+SubSection[langID][selectedSection][subSection]+'" class="pathLink">'+SubSectionTitle[langID][selectedSection][subSection]+'</a>';
		}else{
			if(subSection>0) strBuffer+=' > '+SubSectionTitle[langID][selectedSection][subSection];
		}
		
	}
	if(secondSubSection>0){
		if(exLevel){
			strBuffer+=' > <a href="'+SecondSubSection[langID][selectedSection][subSection][secondSubSection]+'" class="pathLink">'+SecondSubSectionTitle[langID][selectedSection][subSection][secondSubSection]+'</a>';
		}else{
			strBuffer+=' > '+SecondSubSectionTitle[langID][selectedSection][subSection][secondSubSection];		
		}
	}	
	
	if(exLevel){
		strBuffer+=' > '+exLevel;
	}
	
	//graphic version only
	if(!isText){
		document.writeln('<table border=0 cellpadding=0 cellspacing=0 background="'+imagePath+'images/spacer.gif">');
		document.writeln('<tr valign=top>');
		document.writeln('<td width=20><img src="'+imagePath+'images/spacer.gif" alt="" border="0" width=20 height=1></td>');
		document.writeln('<td class="path">'+strBuffer+'</td>');
		document.writeln('</tr>');
		document.writeln('<tr><td colspan=2><img src="'+imagePath+'images/spacer.gif" alt="" border="0" width=1 height=10></td></tr>');
		document.writeln('</table>');
	}
}

//function for generating the topic image
function getTopic(){
	var altText = '';
	var imgPath = '';
	altText = MainTitle[langID][selectedSection]; 
	
	if(!isText){
		document.write('<table border="0" cellpadding="0" cellspacing="0">');
		document.write('	<tr valign="top">');
		document.write('		<td align="left">');
		document.write('			<img src="'+imagePath+'images/spacer.gif" alt="" border="0" width="102" height="1">');
		document.write('		</td>');
		document.write('		<td align="left">');
		document.write('			<img src="'+imagePath+'images/hd/hd_'+(selectedSection+1)+'.gif" alt="'+altText+'" border="0">');
		document.write('		</td>');
		document.write('	</tr>');
		document.write('</table>');
	}else{
		document.write('<p class="title">'+altText+'</p>');
	}
}

//function for generating the top button
function getButton(){
	var altText='Top';
	if(langID!=1) altText='頁首';
	if(!isText){
		document.write('<p><a href="#"><img src="'+imagePath+'images/btn_top.gif" alt="'+altText+'" border="0" align="right"></a>&nbsp;</p>');
	}else{
		document.writeln('<p align=right><a href="#">'+altText+'</a></p>');
	}
	
	/*if(backPage!='' || nextPage!=''){
		document.writeln('<p><table border=0 cellspacing=0 cellpadding=0 width=100%><tr valign=top>');
	
		if(backPage!='')
			document.writeln('<td><a href="'+backPage+'"><img src="../images/btn_back.gif" alt="" border="0"></a></td>');
		if(nextPage!='')
			document.writeln('<td align=right><a href="'+nextPage+'"><img src="../images/btn_next.gif" alt="" border="0"></a></td>');
	
		document.writeln('</tr></table>');
	}*/
}

//function for generating the the text below
function otherLangOnly(){
	var TextStr='<p>We only provide <a href="javascript:changeLanguage(\'/tc/\');" class="text_link">Chinese Version</a>.</p>';
	if(langID==2) TextStr='<p>我們只提供<a href="javascript:changeLanguage(\'/eng/\');" class="text_link">英文版本</a>。</p>';
	document.writeln(TextStr);
}

//function for generating the the text for downloading acrobat reader
function getAcrobat(){
	var StrText='To view or download the following document, please download <a class="text_link" href="javascript:externalLink(\'http://www.adobe.com/prodindex/acrobat/readstep.html\');">Acrobat Reader</a>.';
	if(langID==2) StrText='如想觀看以上文件，請下載<a class="text_link" href="javascript:externalLink(\'http://www.adobe.com/prodindex/acrobat/readstep.html\');">Acrobat Reader</a> 。';
	var StrImg='<img src="'+locationPath+'images/acrobat.gif" border=0 align=top alt="Acrobat Reader">';
	if(isText) StrImg='Acrobat Reader';
	
	document.writeln('<p><table border=0 cellspacing=0 cellpadding=2 width=100%>');
	document.writeln('<tr valign=top><td width=1%><a href="javascript:externalLink(\'http://www.adobe.com/prodindex/acrobat/readstep.html\');">'+StrImg+'</a></td>');
	document.writeln('<td class="maincontent" width=99%>'+StrText+'</td></tr>');
	document.writeln('</table>');
}

var resizeFlag;
var footerY = 600;

function moveDivs(layerObj, inObj){
	layerObj.top  = inObj;
} 

function moveTopDivs(layerObj, inObjTop, inObjLeft){
	layerObj.top  = inObjTop;
	layerObj.left  = inObjLeft;
} 

function getDim(el){
	for (var lx=0,ly=0;el!=null;
		lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
	return {x:lx,y:ly}
}

//function for setting the top button
function setTopLayerPosition(resizeFlag){
	if(topButton=='Y'){
		if (document.all && document.all["footer_layer"]!=null)
		{
	//		footerY = getDim(document.images.leftMenuLineBottom).y;
			moveTopDivs(document.all["footer_layer"].style, getDim(document.images.backtotopspacer).y, getDim(document.images.backtotopspacer).x)
			if (getDim(document.images.backtotopspacer).y > footerY)
			{
				if (resizeFlag)
				{document.all["footer_layer"].style.visibility = "visible"}
			}
		}
		if (document.layers && document.layers["footer_layer"])
		{
	//		footerY = document.images["leftMenuLineBottom"].y;
			moveTopDivs(document.layers["footer_layer"], document.images["backtotopspacer"].y, document.images["backtotopspacer"].x);
			if (document.images["backtotopspacer"].y > footerY)
			{
				if (resizeFlag)
				{document.layers["footer_layer"].visibility = "show"}
			}
		}
		if (!document.all && document.getElementById && document.getElementById("footer_layer")!=null)
		{
	//		footerY = document.images["leftMenuLineBottom"].y;
			moveTopDivs(document.getElementById("footer_layer").style, document.images["backtotopspacer"].y, document.images["backtotopspacer"].x);
			if (document.images["backtotopspacer"].y > footerY)
			{
				if (resizeFlag)
				{document.getElementById("footer_layer").style.visibility = "visible"}
			}
		}
	}
}

if(!isText){
	onresize=setTopLayerPosition;
}

//function for generating the layer for top button
function genfooterLayer(){
	var altText='Top';
	
	if(langID!=1) altText='頁首';

	if(!isText){
		if (document.layers)
			{document.writeln('<layer name=footer_layer top=0 left=0 width=602 height=26 visibility="hide" >');}
		else
			{document.writeln('<div id="footer_layer" style="position:absolute; left:0; top:0; width:26; height:26; z-index:1; visibility: hidden">');}
		document.writeln('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
		document.writeln('<tr valign=top>');
		document.writeln('	<td align="right"><a href="#top"><img src="'+imagePath+'images/btn_top.gif" alt="'+altText+'" border="0"></a></td>');
		document.writeln('</tr>');
		document.writeln('</table>');
		if (document.layers)
			{document.writeln('</layer>');}
		else
			{document.writeln('</div>');}			
	}
}

//function for generating the footer
function getFooter(){
	var altText='Top';
	if(langID!=1) altText='頁首';
	var copyYear='2005';
	var noticesLink=locationPath+langPath+'notices/index.htm';
	var privacyLink=locationPath+langPath+'notices/privacy.htm';
	var noticeText='Important notices';
	var privacyText='Privacy Policy';
	var revisionText='Last revision date: ';	
	var copyrightText = 'Copyright ';
	if (revisionDate==''||revisionDate=='MM/DD/YYYY') revisionDate='5/26/2009';
	if (langID==2){
		noticeText='重要告示';
		privacyText='私隱政策';
		revisionText='修訂日期： ';	
		copyrightText = '版權所有 ';
	}
	var monthArray=new Array();
	monthArray[0]='January';
	monthArray[1]='February';
	monthArray[2]='March';
	monthArray[3]='April';
	monthArray[4]='May';
	monthArray[5]='June';
	monthArray[6]='July';
	monthArray[7]='August';
	monthArray[8]='September';
	monthArray[9]='October';
	monthArray[10]='November';
	monthArray[11]='December';
	var reDate=new Date(Date.parse(revisionDate))
	var showDate=reDate.getDate()+' '+monthArray[reDate.getMonth()]+' '+reDate.getFullYear();
	if (langID==2) showDate=reDate.getFullYear()+'年'+(reDate.getMonth()+1)+'月'+reDate.getDate()+'日';
	//generate the topic image to the buffer variable
	if(!isText){
		document.writeln('<p>');
		document.writeln('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
		if(topButton=='Y')
			document.writeln('	<tr valign=top><td colspan=2 align=right><img src="'+imagePath+'images/spacer.gif" name="backtotopspacer" width=50 height=25 border="0" align="right"></td></tr>');
		document.writeln('	<tr>');
		document.writeln('		<td><img src="'+imagePath+'images/spacer.gif" alt="" border="0" width=5 height=1></td>');
		document.writeln('		<td valign="top" align="center"> ');
		document.writeln('		<table width="100%" border="0" cellspacing="0" cellpadding="0">');
		document.writeln('		<tr bgcolor="#FFFFFF">');
		document.writeln('			<td colspan="2"><img src="'+imagePath+'images/botdot.jpg" alt="" width="600" height="3" border=0></td>');
		document.writeln('		</tr>');
		document.writeln('		<tr bgcolor="#FFFFFF">');
		document.writeln('			<td width="300" height="15" bgcolor="#FFFFFF" class="footer" nowrap><b>'+copyYear+'</b> <img src="'+imagePath+'images/copy.gif" alt="" width="12" height="11"> | <b><a href="'+noticesLink+'" class="footer_link">'+noticeText+'</a></b> | <b><a href="'+privacyLink+'" class="footer_link">'+privacyText+'</a></b></td>');
		document.writeln('			<td height="15" bgcolor="#FFFFFF" class="footer" align="right" nowrap>'+revisionText+showDate+'</td>');
		document.writeln('		</tr>');
		document.writeln('		</table>');
		document.writeln('		</td>');
		document.writeln('	</tr>');
		document.writeln('</table><br>');
	}else{
		document.writeln('	</td>');
		document.writeln('	</tr>');
		document.writeln('	<tr>');
		document.writeln('	<td>');
		document.writeln('<p><table width="100%" border="0" cellspacing="0" cellpadding="0">');
		document.writeln('<tr>');
		document.writeln('	<td colspan=2><hr></td>');
		document.writeln('</tr>');
		document.writeln('<tr>');
		document.writeln('	<td>[ <a href="#">'+altText+'</a> ]</td>');
		document.writeln('</tr>');
		document.writeln('<tr>');
		document.writeln('	<td colspan=2><hr></td>');
		document.writeln('</tr>');
		document.writeln('<tr>');
		document.writeln('	<td>'+copyrightText+' 2004 | <a href="'+noticesLink+'">'+noticeText+'</a> | <a href="'+privacyLink+'">'+privacyText+'</a><br></td>');
		document.writeln('	<td align="right">'+revisionText+showDate+'</td>');
		document.writeln('</tr>');
		document.writeln('</table></p>');
	}
}

//function for generating the sitemap
function getSiteMap(){
	var mainOrder = 0;
	var subOrder = 0;
	var secondSubOrder = 0;
	var LineBroken='<br>';
	var bullet1='<img src="'+locationPath+langPath+'images/bullet_1.gif" alt="*" vspace='+vspace+' border="0" hspace=3>';
	var bullet2='<img src="'+locationPath+langPath+'images/bullet_2.gif" alt="*" vspace='+vspace+' border="0" hspace=3>';
	var bullet3='<img src="'+locationPath+langPath+'images/bullet_3.gif" alt="*" vspace='+vspace+' border="0" hspace=3>';
	if(isText){
		bullet1="*";
		bullet2="*";
		bullet3="*";
	}
	document.write('<table border=0 cellspacing=0 cellpadding=0 width=100%>');	
	for(var i in MainSectionOrder[langID]){
		mainOrder=MainSectionOrder[langID][i];
		if (MainTitle[langID][mainOrder] != ''){
			checkLinkLang(MainSection[langID][mainOrder]);
			document.writeln('<tr valign=top><td width=1%>'+bullet1+'</td>');
			document.writeln('<td class="maincontent" width=99%><a href="'+MainSection[langID][mainOrder]+'" class="text_link">'+MainTitle[langID][mainOrder]+'</a>'+EngOnly);
			if((SubSectionTitle[langID][mainOrder] != null) && (SubSectionTitle[langID][mainOrder].length > 0)){
				document.write(LineBroken+LineBroken+'<table border=0 cellspacing=0 cellpadding=0 width=100%>');	
				for(var j in SubSectionOrder[langID][mainOrder]){
					subOrder=SubSectionOrder[langID][mainOrder][j];
					if (SubSectionTitle[langID][mainOrder][subOrder] != ''){
						checkLinkLang(SubSection[langID][mainOrder][subOrder]);
						document.writeln('<tr valign=top><td width=1%>'+bullet2+'</td>');
						document.writeln('<td class="maincontent" width=99%><a href="'+SubSection[langID][mainOrder][subOrder]+'" class="text_link">'+SubSectionTitle[langID][mainOrder][subOrder]+'</a>'+EngOnly);
						if((SecondSubSectionTitle[langID][mainOrder][subOrder] != null) && (SecondSubSectionTitle[langID][mainOrder][subOrder].length > 0)){
							document.write(LineBroken+LineBroken+'<table border=0 cellspacing=0 cellpadding=0 width=100%>');	
								for(var k in SecondSubSectionOrder[langID][mainOrder][subOrder]){
									secondSubOrder=SecondSubSectionOrder[langID][mainOrder][subOrder][k];
									if (SecondSubSectionTitle[langID][mainOrder][subOrder][secondSubOrder] != ''){
										checkLinkLang(SecondSubSection[langID][mainOrder][subOrder][secondSubOrder]);
										document.writeln('<tr valign=top><td width=1%>'+bullet3+'</td>');
										document.writeln('<td class="maincontent" width=99%><a href="'+SecondSubSection[langID][mainOrder][subOrder][secondSubOrder]+'" class="text_link">'+SecondSubSectionTitle[langID][mainOrder][subOrder][secondSubOrder]+'</a>'+EngOnly);
										if((SecondSubSectionTitle[langID][mainOrder][subOrder][secondSubOrder+1] != null) && (SecondSubSectionTitle[langID][mainOrder][subOrder][secondSubOrder+1].length > 0)){
											document.writeln(LineBroken+LineBroken+'</td></tr>');
										}else{
											document.writeln('</td></tr>');
										}
									}
								}
							document.write('</table>');
						}
						if((SecondSubSectionTitle[langID][mainOrder][subOrder] != null) && (SecondSubSectionTitle[langID][mainOrder][subOrder].length > 0)){
							document.write(LineBroken);					
						}else{
							document.write(LineBroken+LineBroken);
						}
						document.writeln('</td></tr>');
					}
				}
				document.write('</table>');
			}else{
				if((SubSectionTitle[langID][mainOrder] != null) && (SubSectionTitle[langID][mainOrder].length > 0)){
					document.write(LineBroken);
				}else{
					document.write(LineBroken+LineBroken);
				}
			}
			document.writeln('</td></tr>');
		}
		mainOrder = 0;
		subOrder = 0;
		secondSubOrder = 0;
	}
	
	document.write('</table>');
}

//function for generating the sub-section list. Up to level 3 only
function getSectionList(){
	var sectionOrder=0;
	var strSectionOrder='';
	var strBuffer='';
 	var textLink='';
	var bullet1='<img src="'+locationPath+langPath+'images/bullet_1.gif" alt="*" border="0" vspace='+vspace+' hspace=3 align=absMiddle>';
	if(isText) bullet1='*';
	if(selectedSection>0) strBuffer+='['+selectedSection+']';
	if(subSection>0) strBuffer+='['+subSection+']';
	if(subSection>0){
		textLink='SecondSubSection['+langID+']'+strBuffer;
		strSectionOrder='SecondSubSectionOrder['+langID+']'+strBuffer;
		strBuffer='SecondSubSectionTitle['+langID+']'+strBuffer;
	}else{
		textLink='SubSection['+langID+']'+strBuffer;
		strSectionOrder='SubSectionOrder['+langID+']'+strBuffer;
		strBuffer='SubSectionTitle['+langID+']'+strBuffer;
	}
	var count = eval(strSectionOrder+".length");
	if(count != 0){
		document.write('<table border=0 cellspacing=0 cellpadding=0 width=100%>');
		for(var j in eval(strSectionOrder)){
			sectionOrder=eval(strSectionOrder+"["+j+"]")
			if (eval(strBuffer+"["+sectionOrder+"]") != ""){
				checkLinkLang(eval(textLink+"["+sectionOrder+"]"));
				document.writeln('<tr valign=top><td width=1%>'+bullet1+'</td>');
				document.writeln('<td class="maincontent" width=99%><a href="'+eval(textLink+"["+sectionOrder+"]")+'" class="TLink">'+eval(strBuffer+"["+sectionOrder+"]")+'</a>'+EngOnly+'<br><br></td></tr>');
			}
		}
		document.write('</table>');
	}
	sectionOrder=0
}

function checkLinkLang(inputLink){
	if((eval(inputLink.search('/eng/')!=-1))&&(eval(inputLink.search('javascript:')==-1))&&(langID!=1)){
		EngOnly='&nbsp;<img src="'+locationPath+langPath+'images/btn_tc_eng.gif" align=absMiddle border=0 alt="只有英文版">';
		if(isText) EngOnly='&nbsp;只有英文版';
		vspace=3;
	}else{
		EngOnly='';
		vspace=0;
	}
}

//function for index page
function textOnlyLink(textLang){
	var tempLocation = 'ht'+'tp://'+textOnlyPath+'?search=';
	var tempGbUrl = 'sc.info.gov.hk/gb/';
	
	if(textLang=='eng'){
		tempLocation=tempLocation+'eng/index.htm';
	}else if(textLang=='tc'){
		tempLocation=tempLocation+'tc/index.htm';
	}else if(textLang=='gb'){
		tempLocation=tempLocation+'tc/index.htm';
		tempLocation=tempLocation.substring(0,7)+tempGbUrl+tempLocation.substring(7,tempLocation.length);
	}
	location=tempLocation;
}

//function for index page
function graphicLink(graphicLang){
	var tempLocation = 'ht'+'tp://'+graphicPath;
	
	if(graphicLang=='eng'){
		tempLocation=tempLocation+'eng/index.htm';
	}else if(graphicLang=='tc'){
		tempLocation=tempLocation+'tc/index.htm';
	}else if(graphicLang=='gb'){
		tempLocation=tempLocation+'tc/index.htm';
		tempLocation=tempLocation.substring(0,7)+gb_urlPath+tempLocation.substring(7,tempLocation.length);
	}
	location=tempLocation;
}

//function for external link
function externalLink(url)
{eval("nw = window.open(url, 'external','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,pageXOffset=0,pageYOffset=0,top=0,left=0,width=700,height=500')");
	if ( nw.focus != null)
	{nw.focus();}
}

//function for setting the CSS for different browser and language
function checkStyle(){
	var cssLevel = "";
	var cssExtension = ".css"
	var cssLang = "";
	/*if(secondSubSection!="" && secondSubSection>0){
		cssLevel="../../../../";
	}else if(subSection!="" && subSection>0){
		cssLevel="../../../";
	}else if(selectedSection!="" && selectedSection>0){
		cssLevel="../../";
	}else{
		cssLevel="ht"+"tp://"+graphicPath;
	}
	
	if(location.href.toString().indexOf('/cgi-bin/')!=-1){
		cssLevel="ht"+"tp://"+graphicPath;
	}*/
	cssLevel="ht"+"tp://"+graphicPath;
	
	if(isText){
		cssExtension = "_text.css"
	}
	
	if(langID==2) {cssLang = "_tc";}
	
	if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) <= 4)) {
		document.writeln('<link href="'+cssLevel+'css/style_nt'+cssLang+cssExtension+'" rel="STYLESHEET" type="text/css">');
	}else{
		document.writeln('<link href="'+cssLevel+'css/style'+cssLang+cssExtension+'" rel="STYLESHEET" type="text/css">');
	}
}

function genCourseRedirectForm()
{
	var tempGovKanHan = ""
	if(document.URL.toString().search('/gb/') != -1){tempGovKanHan = "sc.info.gov.hk/gb/";}
	
	if (demo)
	{
		document.writeln('<form name="courseRedirectForm" method="POST" action="ht'+'tp://'+tempGovKanHan+'www0.sfaa.gov.hk/cgi-bin/sfaa/course.pl?lang='+lang+'">');
	}
	else
	{document.writeln('<form name="courseRedirectForm" method="POST" action="ht'+'tp://'+tempGovKanHan+'www.sfaa.gov.hk/cgi-bin/sfaa/course.pl?lang='+lang+'">');}
/*	if(filePath.search('eng/')!=-1)
	{
		document.writeln('<input type="hidden" name="lang" value="eng">');
	}
	else
	{
		document.writeln('<input type="hidden" name="lang" value="tc">');
	}*/
	document.writeln('<input type="hidden" name="lang" value="'+lang+'">');
//	document.writeln('<input type="hidden" name="demo" value="'+demo+'">');
//	document.writeln('<input type="hidden" name="govTestSite" value="'+govTestSite+'">');
	document.writeln('</form>');
}

function genCourseForm()
{
	var tempGovKanHan = ""
	if(document.URL.toString().search('/gb/') != -1){tempGovKanHan = "sc.info.gov.hk/gb/";}
	if (demo)
	{
		document.writeln('<form name="courseForm" method="POST" action="ht'+'tp://'+tempGovKanHan+'www0.sfaa.gov.hk/cgi-bin/sfaa/coursesearch.pl?lang='+lang+'" onsubmit="return checkValidation();">');
	}
	else
	{
		document.writeln('<form name="courseForm" method="POST" action="ht'+'tp://'+tempGovKanHan+'www.sfaa.gov.hk/cgi-bin/sfaa/coursesearch.pl?lang='+lang+'" onsubmit="return checkValidation();">');
	}

	document.writeln('<input type="hidden" name="lang" value="'+lang+'">');
	document.writeln('<input type="hidden" name="CategoryType" value="'+z+'">');
}

function highLight() {
document.courseForm.InstitutionName.disabled = false;
document.courseForm.InstitutionCName.disabled = false;
document.courseForm.CourseName.disabled = false;
document.courseForm.CourseCName.disabled = false;

	if (document.courseForm.InstitutionName.value != "" || document.courseForm.CourseName.value != "" )
	{
		document.courseForm.InstitutionCName.disabled = true;
		document.courseForm.CourseCName.disabled = true;
	}
	else if (document.courseForm.InstitutionCName.value != "" || document.courseForm.CourseCName.value != "" )
	{
		document.courseForm.InstitutionName.disabled = true;
		document.courseForm.CourseName.disabled = true;
	}
}

function checkAll() {
var e = document.courseForm.CategoryTypeOption;
for (i=0; i < e.length; i++) {
if (e[i].checked == false) e[i].checked = true;
   }
}

function uncheckAll() {
var e = document.courseForm.CategoryTypeOption;
for (i=0; i < e.length; i++) {
if (e[i].checked == true) e[i].checked = false;
   }
}

function checkValidation()
{
	var x = 0;
//	var z = "";
	var e = document.courseForm.CategoryTypeOption;
	
//        if (location.search.toString().indexOf('lang=eng')!=-1)
//        {
//                if((document.courseForm.InstitutionName.value == "") && (document.courseForm.CourseName.value == "") && (document.courseForm.InstitutionCName.value == "") && (document.courseForm.CourseCName.value == ""))
//                {
//                        alert("Please input either of one")
//                        return false;
//                }
//        }
//        else
//        {
//                if((document.courseForm.InstitutionName.value == "") && (document.courseForm.CourseName.value == "") && (document.courseForm.InstitutionCName.value == "") && (document.courseForm.CourseCName.value == ""))
//                {
//                        alert("請輸入其中一項")
//                        return false;
//                }
//        }

	for (i=0; i < e.length; i++)
	{
		if (e[i].checked)
		{
			if (z != ""){
				z += "|" + e[i].value;
			}else{
				z = e[i].value; 		
			}
		}
		else
		{
			x++;
		}
	}
	
	if (x == e.length)
	{
		if (location.search.toString().indexOf('lang=eng')!=-1)
		{
			alert("Please choose at least one category!");
			return false;
		}
		else
		{
			alert("請選擇最少一種類別!");
			return false;
		}
	}
	else
	{
		document.courseForm.CategoryType.value = z;
                if((document.courseForm.InstitutionName.value == "") && (document.courseForm.CourseName.value == "") && (document.courseForm.InstitutionCName.value == "") && (document.courseForm.CourseCName.value == ""))
                {
                        document.courseForm.CourseName.value = "*";
                }
	}
	return true;
}

//function for course form's next, back button
function courseFormListNextBack(startPage)
{
	var pathname = window.location.href.toLowerCase();
	document.courseSearchForm.start.value = startPage;
	document.courseSearchForm.submit();
}

function courseDFormListNextBack(startPage)
{
	var pathname = window.location.href.toLowerCase();
	document.courseSearchDForm.sstart.value = startPage;
	document.courseSearchDForm.submit();
}

function courseDLFormListNextBack(startPage)
{
	var pathname = window.location.href.toLowerCase();
	document.courseSearchDLForm.sstart.value = startPage;
	document.courseSearchDLForm.submit();
}

//function for view the form detail
function courseFormDetail(p_courseNumber,p_noie,p_noic)
{
	var pathname = window.location.href.toLowerCase();
	document.courseSearchForm.courseNumber.value = p_courseNumber;
	document.courseSearchForm.noie.value = p_noie;
	document.courseSearchForm.noic.value = p_noic;
	if (pathname.indexOf("coursesearch.pl?lang=eng")!=-1)
	{document.courseSearchForm.action = document.courseSearchForm.action.replace("coursesearch.pl?lang=eng", "coursesearch_detail.pl?lang=eng");}
	else if (pathname.indexOf("coursesearch_t.pl?lang=eng")!=-1)
	{document.courseSearchForm.action = document.courseSearchForm.action.replace("coursesearch_t.pl?lang=eng", "coursesearch_detail_t.pl?lang=eng");}
	else if (pathname.indexOf("coursesearch.pl?lang=chi")!=-1)
	{document.courseSearchForm.action = document.courseSearchForm.action.replace("coursesearch.pl?lang=chi", "coursesearch_detail.pl?lang=chi");}
	else if (pathname.indexOf("coursesearch_t.pl?lang=chi")!=-1)
	{document.courseSearchForm.action = document.courseSearchForm.action.replace("coursesearch_t.pl?lang=chi", "coursesearch_detail_t.pl?lang=chi");}
	document.courseSearchForm.submit();
}

//function for back to search list button
function courseFormDetailBackToList()
{
	var pathname = window.location.href.toLowerCase();
	if (pathname.indexOf("coursesearch_detail.pl?lang=eng")!=-1)
	{document.courseSearchDForm.action = document.courseSearchDForm.action.replace("coursesearch_detail.pl?lang=eng", "coursesearch.pl?lang=eng");}
	else if (pathname.indexOf("coursesearch_detail_t.pl?lang=eng")!=-1)
	{document.courseSearchDForm.action = document.courseSearchDForm.action.replace("coursesearch_detail_t.pl?lang=eng", "coursesearch_t.pl?lang=eng");}
	else if (pathname.indexOf("coursesearch_detail.pl?lang=chi")!=-1)
	{document.courseSearchDForm.action = document.courseSearchDForm.action.replace("coursesearch_detail.pl?lang=chi", "coursesearch.pl?lang=chi");}
	else if (pathname.indexOf("coursesearch_detail_t.pl?lang=chi")!=-1)
	{document.courseSearchDForm.action = document.courseSearchDForm.action.replace("coursesearch_detail_t.pl?lang=chi", "coursesearch_t.pl?lang=chi");}
	document.courseSearchDForm.submit();
}

//function for course form switch language
function courseFormSwitchLang(pathname, switchLang)
{
//locPath = locationPath + "tc/schemes/search.htm";
if (switchLang == "/tc/")
{
//	if(location.href.toString().search('/gb/') != -1)
		locPath = http + hostAddress + "/tc/schemes/search.htm";
//	else
//		locPath = locPath.replace("eng", "chi");
}
else if (switchLang == "/eng/")
{
//	if(location.href.toString().search('/gb/') != -1)
		locPath = http + hostAddress + "/eng/schemes/search.htm";
//	else
//		locPath = locPath.replace("chi", "eng");
}
else if (switchLang == "/gb/")
{
	locPath = http + gb_urlPath + hostAddress + "/tc/schemes/search.htm";
}
//location.href = locPath;
return locPath;
/*
if (switchLang == '/eng/')
{var tarLang2 = 'eng'}
else if  (switchLang == '/tc/')
{var tarLang2 = 'chi'}
else if  (switchLang == '/gb/')
{var tarLang2 = 'chi'}
*/
//	switchLang = switchLang.substring(1,switchLang.length-1);
/*
	if (pathname.indexOf("coursesearch_detail.pl")!=-1)
	{
		document.courseSearchDForm.action = pathname;
		document.courseSearchDForm.lang.value = tarLang2;
		document.courseSearchForm.demo.value = demo;
		document.courseSearchForm.govTestSite.value = govTestSite;
		document.courseSearchDForm.submit();
	}
	else
	{
		document.courseSearchForm.action = pathname;
		document.courseSearchForm.lang.value = tarLang2;
		document.courseSearchForm.demo.value = demo;
		document.courseSearchForm.govTestSite.value = govTestSite;
		document.courseSearchForm.submit();
	}
*/
}

function PopWin(url,page,x,y,z){
	eval("nw = window.open(url, page,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,pageXOffset=0,pageYOffset=0,top=0,left=" + z + ",width=" + x + ",height=" + y + "')");
	if ( nw.focus != null)
	{nw.focus();}
}

checkStyle();
