//
//	lang.js
//
//	Language handling functions
//
//	cookies: lang ("en", "ch")
//
//	Author: pky
//
//	Copyright (c) ZePortal.com Ltd, 2001-2002. All Rights Reserved.
//

var langCookie = "lang";
var lang = "";
var b5 = "b5";
var en = "en";

// file names suffix
var enSuffix = "_en.gif";
var b5Suffix = "_b5.gif";

function setLang(l) {	// setup lang cookie
	//don't set cookie with date such that it will become machine wide, just keep cookie session only is fine
	var nextyear=new Date();
	nextyear.setFullYear(nextyear.getFullYear() +1);

	lang = l;
	setCookie(langCookie,l, nextyear);
}

function getLang() {	// get the language code
	return lang;
}

function ckLang() {	// check system/browser language being supported
	var l="en-";	// default to English
	lang = getCookie(langCookie);
	if (lang == "" || lang == "\"\"") {	// tomcat5 return junk at times
		if (navigator["language"] != null)
			l = navigator["language"];
		else if (navigator["userLanguage"] != null)
			l = navigator["userLanguage"];
		if (l.match("zh-")) setLang(b5);	// traditional Chinese (Big5)
		else setLang(en);	// default to English
	}
	else setLang(lang);	// to refresh exp date
}

function writeIf(l,str) {	// write only if language l being supported
	if (lang == l) document.write(str);
}

function isLang(l) {	// if language l being supported
	return (lang == l);
}

function setIf(l,obj,val) {	// set obj to val if language l being supported
	if (lang == l) obj = val;
}

function fileSuffix() {
	return (lang == en)?enSuffix:b5Suffix;
}

ckLang();	// call to setup the cookie

