/******************************************************
Javascript DOM function for change language url on load

Version	: 1.6b
Author	: irc@isd.gov.hk
Date	: 10 Oct 2006

******************************************************/


// Language directory
var b5_path	= "/chi/"
var eng_path= "/eng/"
var sim_path= "/sim/"


/* Stop Editing */



function kanhan(lang1ID, lang2ID) {
	loc1=location.href;
	loc2=location.href;
	alt="";

	if (isGB()) {
		loc1 = location.href.replace(sim_path, b5_path);
		loc2 = location.href.replace(sim_path, eng_path);
		alt = "繁體";
	}

	if (isB5()) {
		loc1 = location.href.replace(b5_path, sim_path);
		loc2 = location.href.replace(b5_path, eng_path);
		alt = "簡体";
	}

	if (isEng()) {
		loc1 = location.href.replace(eng_path, b5_path);
		loc2 = location.href.replace(eng_path, sim_path);
		alt = "Traditional Chinese";
	}

	if (document.getElementById) {
		if (document.getElementById(lang1ID)) {
			document.getElementById(lang1ID).setAttribute("href", loc1);
			if (document.getElementById(lang1ID).getElementsByTagName("IMG")[0]){
				document.getElementById(lang1ID).getElementsByTagName("IMG")[0].setAttribute("alt", alt);
				document.getElementById(lang1ID).getElementsByTagName("IMG")[0].setAttribute("title", alt);
			}
		}
		if (document.getElementById(lang2ID))
			document.getElementById(lang2ID).setAttribute("href", loc2);
	}
}



function isGB() {
	return (location.href.toString().indexOf(sim_path) != -1) ? true : false;

}

function isB5() {
	return (location.href.toString().indexOf(b5_path) != -1) ? true : false;
}
function isEng() {
	return (location.href.toString().indexOf(eng_path) != -1) ? true : false;
}




function init(e) {

	kanhan("lang1", "lang2");

}





if (window.addEventListener)
	window.addEventListener("load", init, false);
else if (window.attachEvent)
	window.attachEvent("onload", init);


//for IE/Mac
document.onreadystatechange = function(e) {
	if (document.readyState=="interactive")
	init();
}
