//var scserver = "http"+"://sc.info.gov.hk/gb/";
var scserver = "http"+"://";
var locapath = document.location.href

var atlang,domname,sitepath,atgb,atindex,org_part;
	//sc_path = "gb/";
	sc_path = "sc/";
	tc_path = "chi/";
	en_path = "eng/";
	tctext_path = "ctext/";
	gbtext_path = "sctext/";
	entext_path = "etext/";
	
    atgb = false;
	atindex = false;

if (locapath.toString().search('/sc/')!= -1){
	atgb = true;
	/*org_path_start = locapath.indexOf("/gb/") +4;
	org_path_end = locapath.length;
	sitepath = locapath.substring(org_path_start, org_path_end);*/
	sitepath = locapath.substring(7,locapath.length);
}else{
	atgb = false;
	sitepath = locapath.substring(7,locapath.length);
}

if (locapath.toString().search('/chi/')!= -1){
	atlang = "tc";
	org_part = tc_path;
}else
if (locapath.toString().search('/eng/')!= -1){
	atlang = "en";
	org_part = en_path;
}else
if (locapath.toString().search('/sc/')!= -1){
	atlang = "sc";
	org_part = sc_path;
}else
if (locapath.toString().search('/ctext/')!= -1){
	atlang = "tctext";
	org_part = tctext_path;
}else
if (locapath.toString().search('/etext/')!= -1){
	atlang = "entext";
	org_part = entext_path;
}else
if (locapath.toString().search('/sctext/')!= -1){
	atlang = "gbtext";
	org_part = gbtext_path;
}else
if (locapath.toString().search('/gb/')!= -1){
	atlang = "gb";
	org_part = sc_path;
}else
if (locapath.toString().search('index.htm')!= -1){
	atlang = "index";
	org_part = "index.htm";
	atindex = true;
}else
if (locapath.toString().search('index.htm')!= -1){
	atlang = "index";
	org_part = "index.htm";
	atindex = true;
}else

if (locapath.toString().search('index.htm')!= -1){
	atlang = "index";
	org_part = "index.htm";
	atindex = true;
}



function chglang(lang){

	switch(lang){
		case 'en':
			des_part = en_path;
			des_ind_part = "index.htm";
			base_path = "http"+"://";
			break;
		case 'tc':
			//des_part = tc_path;
			if (locapath.toString().search('/sctext/')!= -1)
			{
				des_part = "sc/";
			}
			else
			{
				des_part = tc_path;
			}
			des_ind_part = "index.htm";
			base_path = "http"+"://";
			break;
		case 'gb':
			//des_part = tc_path;
			if (locapath.toString().search('/sc/')!= -1)
			{
				des_part = "chi/";
			}
			else
			{
				des_part = "sc/";
			}
			des_ind_part = "index.htm";
			base_path = scserver;
			//base_path = "http"+"://";
			break;
		case 'entext':
			if (locapath.toString().search('/etext/')!= -1)
			{
				des_part = tctext_path;
			}
			else
			{
				des_part = entext_path;
			}
			des_ind_part = "index.htm";
			base_path = "http"+"://";
			break;
		case 'tctext':
			if (locapath.toString().search('/sc/')!= -1)
			{
				des_part = gbtext_path;
			}
			else
			{
				des_part = tctext_path;
			}
			des_ind_part = "index.htm";
			base_path = "http"+"://";
			break;
		case 'gbtext':
			if (locapath.toString().search('/sctext/')!= -1)
			{
				des_part = tctext_path;
			}
			else
			{
				des_part = gbtext_path;
			}
			des_ind_part = "index.htm";
			base_path = "http"+"://";
			break;
	}
//alert("org_part:"+org_part);
	if (atindex == true){
		tail = sitepath.replace(org_part, des_ind_part);
	}else{
		tail = sitepath.replace(org_part, des_part);
	}

//alert(base_path+tail)
	window.location =  base_path+tail;

}

function displaytcsc(){
	if (atgb){
		document.write("<a href=\"javascript:chglang('tc')\">");
		document.write("<img name=\"Image36\" border=\"0\" src=\"../gb/images/chibut.gif\" alt=\"Traditional Chinese\"></a>");	
	}else{
		document.write("<a href=\"javascript:chglang('gb')\">");
		document.write("<img name=\"Image36\" border=\"0\" src=\"../ctext/images/simbut.gif\" alt=\"Simplified Chinese\"></a>");
	}


}