function setCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}

function getCookie(search_name) {
  // note: document.cookie only returns name=value, not the other components
  var tab_cookies = document.cookie.split( ';' );
  for ( i = 0; i < tab_cookies.length; i++ ) {
    // now we'll split apart each name=value pair
    var cookie_tmp = tab_cookies[i].split('=');
    // and trim left/right whitespace while we're at it
    var cookie_name = cookie_tmp[0].replace(/^\s+|\s+$/g, '');
    // if the extracted name matches passed search_name
    if (cookie_name==search_name) {
      // we need to handle case where cookie has no value but exists (no = sign, that is):
      if (cookie_tmp.length>1) {
        return unescape( cookie_tmp[1].replace(/^\s+|\s+$/g, '') );
      }
      // cookie is initialized but no value => result = null
      return null;
    }
  }
  return null;
} 

function changeSiteLanguage() {
	setCookie("site_language", document.getElementById('site_language').value, 999);
	window.location="/";
}

function showSiteLanguage() {
	var currentLanguageOption = document.getElementById(getCookie('site_language'));
	currentLanguageOption.selected = true;
}

function getBrowserLanguage() {
	var userLang = (navigator.language) ? navigator.language : navigator.userLanguage;
	alert ("The language is: " + userLang);
}
