function getCookie(cookieName) {
  var i, x, y, allCookies = document.cookie.split(';');
  for (i = 0; i < allCookies.length; i++) {
    x = allCookies[i].substr(0, allCookies[i].indexOf('='));
    y = allCookies[i].substr(allCookies[i].indexOf('=') + 1);
    x = x.replace(/^\s+|\s+$/g,'');
    if (x == cookieName) {
      return unescape(y);
    }
  }
}

// Actual redirect.
var destination = getCookie('lang_redirect');
// if there is a cookie and we the current lang is not the one in the cookie :
if (destination != null && destination != document.documentElement.lang) {
  // Redirect based on language.
  window.location = window.location.protocol + '//' + window.location.host + '/' + destination;
}

