/***********************************************************************
Javascript DOM function for change language url on load (UTF-8 version)

Version	: 2.0b
Author	: irc@isd.gov.hk
Date		: 7 July 2006

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


// Language directory
var en_path= "/eng/"
var tc_path= "/chi/"
var sc_path= "/sim/"



/* Stop Editing */

function changeLang() {
	loc1=location.href;
	loc2=location.href;
	id1="";
	id2="";
	
	if (isEn()) {
		loc1 = loc1.replace(en_path, tc_path);
		loc2 = loc2.replace(en_path, sc_path);
		id1 = "tc"
		id2 = "sc"
	}

	if (isTc()) {
		loc1 = loc1.replace(tc_path, en_path);
		loc2 = loc2.replace(tc_path, sc_path);
		id1 = "en"
		id2 = "sc"
	}

	if (isSc()) {
		loc1 = loc1.replace(sc_path, en_path);
		loc2 = loc2.replace(sc_path, tc_path);
		id1 = "en"
		id2 = "tc"
	}

	if (document.getElementById) {
		if (document.getElementById(id1)) {
			document.getElementById(id1).setAttribute("href", loc1);
		}
		if (document.getElementById(id2))
			document.getElementById(id2).setAttribute("href", loc2);
	}
}


function isEn() {
	return (location.href.toString().indexOf(en_path) != -1) ? true : false;
}
function isTc() {
	return (location.href.toString().indexOf(tc_path) != -1) ? true : false;
}
function isSc() {
	return (location.href.toString().indexOf(sc_path) != -1) ? true : false;
}


function init(e) {
	changeLang();
}





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