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

Version	: 0.5
Author	: irc@isd.gov.hk
Date	: 14 May 2009

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


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

var Chi_Alt = "繁體版";
var Sim_Alt = "簡体版";
var Eng_Alt = "English";

/* Stop Editing */


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

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

	//Update the href and Alt-text
	e1=document.getElementById(lang1ID);
	e2=document.getElementById(lang2ID);

	if (e1) {
		e1.setAttribute("href", loc1);
		e1.getElementsByTagName("IMG")[0].setAttribute("alt", alt1);
	}
	if (e2) {
		e2.setAttribute("href", loc2);
		e2.getElementsByTagName("IMG")[0].setAttribute("alt", 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();
}

