
function setLang(xlang) {
	document.cookie = 'siteLang='+xlang+"; path=/";
	newL=location.href.replace(/_..\.html$/,'_'+xlang+'.html');
	if (location.href != newL) {
		location.href=newL;
	}
}	

// Function input: page= the full url of the destanation page, this should
//  always must end on _XX.html where XX is a language code
function goLangPage(page) {		
	// attempt to use the browser language (NOT the one set in options, but the actual language the
	// the browser is in). IndexOf==0 means the string starts with the substring. A cookie
	// will always override this if it is set
	var languageinfo=navigator.language? navigator.language : navigator.userLanguage;
	var xlang='uk' ; // this is your default language
	if (languageinfo.indexOf('de')==0) { xlang='de'; }
	if (languageinfo.indexOf('fr')==0) { xlang='fr'; }
	
	// search pattern: either at start of string OR preface with a semicolon
	//  followed by zero or more spaces, find the string 'siteLang=' and return all
	//  stuff following that up to but not inluding a semi-colon. 		
	var pattern = new RegExp ('(^|;)\\s*siteLang=([^;]+)', 'i') ;
	var matches = pattern.exec (document.cookie) ;
	if (matches) { xlang=unescape (matches[2]);	} 
	page=page.replace(/_..\.html$/,'_'+xlang+'.html');
	location.href=page;
	// this function never returns
}	

