

function changeLanguage(lang)
{
	//alert(lang);
	// Set the language cookie
	var expires = new Date('1/1/2008');
	var path = '/';
	Set_Cookie('lang', lang, expires, path);
	
	var new_location = getScriptName();
	location.replace(new_location);

	// Call the current URL again, be careful to include the 'search' component if needed
	//var url = location.pathname;
	//var search = location.search;
	//if ( search != '' ) { url = url+search; }
	//location.replace(url);	
}

function gotoLocation(url, lang)
{
	// Set the language cookie
	var expires = new Date('1/1/2008');
	var path = '/';
	Set_Cookie('lang', lang, expires, path);
	
	// Hit the url
	location.replace(url);
}

function useLanguage(lang)
{
	// Set the language cookie
	var expires = new Date('1/1/2008');
	var path = '/';
	Set_Cookie('lang', lang, expires, path);
}

// Get the scriptname, we want the path (minus any languages folder) and the filename itself
function getScriptName()
{
	// Declare some constants
	// The beginning paths for translated pages
	var lang_fr   = '/languages/fr';
	var lang_de   = '/languages/de';
	var lang_jp   = '/languages/jp';
	var lang_gb   = '/languages/gb';
	var lang_big5 = '/languages/big5';
	

	var pathname = location.pathname;	// Get the full pathname
	var search = location.search;		// Get the search (querystring)

	var pathname_new = '';
	
	if ( pathname.indexOf(lang_fr) != -1 )
	{
		pathname_new = pathname.substr(lang_fr.length);
	}
	else if ( pathname.indexOf(lang_de) != -1 )
	{
		pathname_new = pathname.substr(lang_de.length);
	}
	else if ( pathname.indexOf(lang_jp) != -1 )
	{
		pathname_new = pathname.substr(lang_jp.length);
	}
	else if ( pathname.indexOf(lang_gb) != -1 )
	{
		pathname_new = pathname.substr(lang_gb.length);
	}
	else if ( pathname.indexOf(lang_big5) != -1 )
	{
		pathname_new = pathname.substr(lang_big5.length);
	}
	else
	{
		pathname_new = pathname;	// Default, English version
	}

	return pathname_new + search;	
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}


