/******************************************************
Javascript DOM function for change language url on load

Version	: 1.7
Author	: irc@isd.gov.hk
Date	: 11 May 2009

******************************************************/


// Language directory
var b5_path	= "/chi/"
var eng_path= "/eng/"
var sim_path = "/sim/";

/* Stop Editing */
var Chi_Alt="繁體";
var Sim_Alt="簡体";
var Eng_Alt="English";

function kanhan(lang1ID, lang2ID) {
	loc1=location.href;
	loc2=location.href;
	alt1="";
	alt2="";

	if (isGB()) {
		loc1 = loc1.replace(sim_path, b5_path);
		loc2 = loc2.replace(sim_path, eng_path);
		alt1 = Chi_Alt;
		alt2 = Eng_Alt;
	}

	if (isB5()) {
		loc1 = loc1.replace(b5_path, sim_path);
		loc2 = loc2.replace(b5_path, eng_path);
		alt1 = Sim_Alt;
		alt2 = Eng_Alt;
	}

	if (isEng()) {
		loc1 = loc1.replace(eng_path, b5_path);
		loc2 = loc2.replace(eng_path, sim_path);
		alt1 = Chi_Alt;
		alt2 = Sim_Alt;
	}

	if (document.getElementById) {
		if (document.getElementById(lang1ID)!=null) {
			document.getElementById(lang1ID).setAttribute("href", loc1);
			if (document.getElementById(lang1ID).getElementsByTagName("IMG")[0]){
				document.getElementById(lang1ID).getElementsByTagName("IMG")[0].setAttribute("alt", alt1);
				document.getElementById(lang1ID).getElementsByTagName("IMG")[0].setAttribute("title", alt1);
			}
		}
		if (document.getElementById(lang2ID)!= null){
			document.getElementById(lang2ID).setAttribute("href", loc2);
			if (document.getElementById(lang2ID).getElementsByTagName("IMG")[0]){
				document.getElementById(lang2ID).getElementsByTagName("IMG")[0].setAttribute("alt", alt2);
				document.getElementById(lang2ID).getElementsByTagName("IMG")[0].setAttribute("title", alt2);
			}
		}
	}
}



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();
}
