function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i>d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function simg(obj,src)
{
        if (document.images){
                obj.src = src;
        }
}

function topNav(upperPath, textPath, imgPath)
{
	var textOnlyPath = upperPath + "text/" + textPath

	var pageHref = location.href
	pageHref = pageHref.substr(7,pageHref.length-7) //cut the http://
	var charOffSet = pageHref.lastIndexOf("/eng/")
	var charOffSet2 = pageHref.lastIndexOf("/")
	var pagePath = pageHref.substr(0,charOffSet+1) //get the full path of the existing page
	var pageName = pageHref.substr(charOffSet+5,pageHref.length-charOffSet-1)
	var pageName2 = pageHref.substr(charOffSet2+1,pageHref.length-charOffSet2-1)
	var cPageName = upperPath + "chi/" + pageName //get the chinese page
	var scPageName = "chi/" + pageName //get the simplify chinese page

  document.write("<table width=\"760\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" height=\"50\">");
  document.write("<tr>"); 
  document.write("<td><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\"763\" height=\"78\">");
  document.write("<param name=movie value=\"../images/top.swf\">");
  document.write("<param name=quality value=high>");
  document.write("<param name=\"wmode\" value=\"opaque\">");
  document.write("<embed src=\"../images/top.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"763\" height=\"78\" wmode=\"opaque\"></embed>");
  document.write(""); 
  document.write("</object><br>");
  document.write("<img src=\"../images/line.gif\" width=\"763\" height=\"1\"></td>");
  document.write("</tr>");
  document.write("<tr>"); 
  document.write("<td background=\"../images/bg.jpg\">");
  document.write("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" height=\"12\">");
  document.write("<tr valign=\"top\">"); 
  document.write("<td width=\"54\" height=\"5\"> <a href=\"javascript:;\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('Image1','','../images/sitemap_2.jpg',1)\"><img src=\"../images/sitemap.jpg\" width=\"54\" height=\"20\" border=\"0\" name=\"Image1\" alt=\"SITE MAP\"></a></td>");
  document.write("<td width=\"12\" height=\"5\"> <img src=\"../images/vl.jpg\" width=\"12\" height=\"20\"></td>");
  document.write("<td width=\"63\" height=\"5\"> <a href=\"../other/disclaimer.html\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('Image2','','../images/disclaimer_2.jpg',1)\"><img src=\"../images/disclaimer.jpg\" width=\"63\" height=\"20\" border=\"0\" name=\"Image2\" alt=\"DISCLAIMER\"></a></td>");
  document.write("<td width=\"12\" height=\"5\"> <img src=\"../images/vl.jpg\" width=\"12\" height=\"20\"></td>");
  document.write("<td width=\"60\" height=\"5\"> <a href=\"../other/copyright.html\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('Image3','','../images/copyright_2.jpg',1)\"><img src=\"../images/copyright.jpg\" width=\"60\" height=\"20\" border=\"0\" name=\"Image3\" alt=\"COPYRIGHT\"></a></td>");
  document.write("<td width=\"183\" height=\"5\">&nbsp; </td>");
  document.write("<td width=\"74\" height=\"5\"> <a href=\"javascript:switchLang(0,1);\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('Image4','','../images/text_version_2.jpg',1)\"><img src=\""+imgPath+"images/text_version.jpg\" width=\"74\" height=\"20\" border=\"0\" name=\"Image4\" alt=\"TEXT VERSION\"></a></td>");
  document.write("<td width=\"11\" height=\"5\"> <img src=\"../images/vl.jpg\" width=\"12\" height=\"20\"></td>");
  document.write("<td width=\"38\" height=\"5\"> <kanhanbypass><a href=\"javascript:switchLang(1,3);\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('Image5','','../images/gb_2.jpg',1)\"><img src=\""+imgPath+"images/gb.jpg\" width=\"36\" height=\"20\" border=\"0\" name=\"Image5\" alt=\"SIMPLIFIED CHINESE\"></a></td>");
  document.write("<td width=\"12\" height=\"5\"> <img src=\"../images/vl.jpg\" width=\"12\" height=\"20\"></td>");
  document.write("<td width=\"39\" height=\"5\"> <kanhanbypass><a href=\"javascript:switchLang(1,2);\" onMouseOut=\"MM_swapImgRestore()\"  onMouseOver=\"MM_swapImage('Image6','','../images/big5_2.jpg',1)\"><img src=\""+imgPath+"images/big5.jpg\" width=\"39\" height=\"20\" border=\"0\" name=\"Image6\" alt=\"TRADITIONAL CHINESE\"></a></td>");
  document.write("<td width=\"12\" height=\"5\"> <img src=\"../images/vl.jpg\" width=\"12\" height=\"20\"></td>");
  document.write("<td width=\"193\" height=\"5\"><a href=\"javascript:;\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('Search','','../images/search_2.jpg',1)\"><img src=\"../images/search.jpg\" width=\"48\" height=\"20\" name=\"Search\" border=\"0\" onClick=\"javascript:document.search.submit()\" alt=\"SEARCH\"></a>");
  document.write("<input id=search style=\"WIDTH: 86pt\" size=9 name=qu maxlength=\"15\">");
  document.write("<a href=\"#\" ><img src=\"../images/search.gif\" width=\"14\" height=\"14\" name=\"Search_but\" onClick=\"javascript:document.search.submit()\" border=\"0\" alt=\"SEARCH\">"); 
  document.write("</td>");
  document.write("</tr>");
  document.write("</table>");
  document.write("</td>");
  document.write("</tr>");
  document.write("</table>");
}  
function switchLang(currLang, tarLang){

	var currPath = document.URL.toString();
	var lang = window.location.hostname;
	
	var head, toPath;
	toPath = "";
	
	
	if (currLang==0)
	{		
		if (tarLang==1)
		{
			currPath = currPath.replace("/eng/", "/text/eng/");
			toPath = currPath;
			location = toPath;
		}
		else if (tarLang==2)
		{
			currPath = currPath.replace("/chi/", "/text/chi/");
			//alert("Text Only Version is not available at the moment.");
			toPath = currPath;
			location = toPath;
		}
		else if (tarLang==3)
		{
			currPath = currPath.replace("/chi/", "/text/chi/");
			toPath = currPath;
			location = toPath;
		}
	}
	else if (currLang==1)
	{		
		if (tarLang==2)
		{
			currPath = currPath.replace("/eng/", "/chi/");
			toPath = currPath;
			location = toPath;
		}
		else if (tarLang==3)
		{
			currPath = currPath.replace("/eng/", "/chs/");
			toPath = currPath;
			location = toPath;
		}
	}
	else if (currLang==2)
	{		
		if (tarLang==1)
		{
			currPath = currPath.replace("/chi/", "/eng/");
			toPath = currPath;
			location = toPath;
		}
		else if (tarLang==3)
		{
			currPath = currPath.replace("/chi/", "/chs/");
			toPath = currPath;
			location = toPath;			
		}
	}
	else if (currLang==3)
	{
		if (tarLang==1)
		{
			currPath = currPath.replace("/chi/", "/eng/");
			currPath = currPath.replace("sc.info.gov.hk/TuniS/","");
			toPath = currPath;
			location = toPath;
		}
		else if (tarLang==2)
		{
			currPath = currPath.replace("sc.info.gov.hk/TuniS/","");
			toPath = currPath;
			location = toPath;
		}
	}
	
	//location = toPath;	
}
