

webserver_path = "cd.edb.gov.hk";
kanserver_path = "cd.edb.gov.hk";

div_path = "/";
cv_sc_base_path = "http:" + "//" + kanserver_path + webserver_path;
cv_nonsc_base_path = "http:" + "//" + webserver_path;

sc_path = cv_sc_base_path + div_path;
tc_path = cv_nonsc_base_path + div_path;

if (location.href.toString().search('/gb/') != -1) {
	atgb = 1
} else {
	atgb = 0;
}

function changelang(lang)
{

 if (document.length > 0)
  {
	for (i=0; i<document.length; i++)
	{
		org_path=document.location.pathname;
		//org_path_start=org_path.indexOf(div_path);
		org_path_start=org_path.indexOf(webserver_path);
		if (org_path_start>-1)
		{
			org_path_end=webserver_path.length;
			//add=org_path.substring(org_path_start, org_path_end);
			add = org_path.substring(org_path_start+org_path_end, org_path.length);
		}
		else
		{
			org_path_end=org_path.length;
			add=org_path.substring(org_path_start, org_path_end);
		}
		
		if (lang == "b5")
		{
			tempPath = add.replace("/en/", "/b5/");
			tempPath = tempPath.replace("/gb/", "/b5/");
		}
		else if (lang == "gb")
		{
			tempPath = add.replace("/b5/", "/gb/");		
			tempPath = tempPath.replace("/en/", "/gb/");
		}
		else if (lang == "en")
		{
			tempPath = add.replace("/b5/", "/en/");
			tempPath = tempPath.replace("/gb/", "/en/");
		}
		path = tempPath;

		if (lang == 'sc') {
			base_path = cv_sc_base_path;
		} else {
			base_path = cv_nonsc_base_path;
		}	
	
		document.location.href = base_path + path;

	}
  }
  else
  {
	  	org_path=parent.location.pathname;
		org_path_start=org_path.indexOf(webserver_path);
		if (org_path_start>-1)
		{
			org_path_end=webserver_path.length;
			//add=org_path.substring(org_path_start, org_path_end);
			add = org_path.substring(org_path_start+org_path_end, org_path.length);
		}
		else
		{
			org_path_start=org_path.indexOf(div_path);
			org_path_end=org_path.length;
			add=org_path.substring(org_path_start, org_path_end);
		}
		if (lang == "b5")
		{
			tempPath = add.replace("/en/", "/b5/");
			tempPath = tempPath.replace("/gb/", "/b5/");
		}
		else if (lang == "gb")
		{
			tempPath = add.replace("/b5/", "/gb/");		
			tempPath = tempPath.replace("/en/", "/gb/");
		}
		else if (lang == "en")
		{
			tempPath = add.replace("/b5/", "/en/");
			tempPath = tempPath.replace("/gb/", "/en/");
		}
		path = tempPath;

		if (lang == 'sc') {
			base_path = cv_sc_base_path;
		} else {
			base_path = cv_nonsc_base_path;
		}	
  	parent.location.href = base_path + path;;
  }

}

function show_link() {

	if (atgb)  // show traditional chinese link
	{
		document.write("<a href=\"javascript:changelang('tc');\" onMouseOver=\"MM_swapImage('b5','','../images/b5_over.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src=\"../images/b5.gif\" alt=\"Traditional Chinese\" name=\"b5\" width=\"27\" height=\"14\" hspace=\"5\" vspace=\"5\" border=\"0\" id=\"b5\"></a>");	
	} else // show simplified chinese link
	{
		document.write("<a href=\"javascript:changelang('sc');\" onMouseOver=\"MM_swapImage('gb','','../images/gb_over.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src=\"../images/gb.gif\" alt=\"Simplified Chinese\" name=\"gb\" width=\"27\" height=\"14\" hspace=\"5\" vspace=\"5\" border=\"0\" id=\"gb\"></a>");
	}
}

