var bikky = document.cookie;

function getCookie(name)
{
  var value=null, search=name+"=";
  if (document.cookie.length > 0) {
    var offset = document.cookie.indexOf(search);
    if (offset != -1) {
      offset += search.length;
      var end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      value = unescape(document.cookie.substring(offset, end));
    }
  }
  return value;
}

var today = new Date();
var expire = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); // plus 365 days
var path = "/"

function setCookie(name, value) { // use: setCookie("name", value);
  document.cookie = name + "=" + escape(value) +
                    ((!expire) ? "" : ("; expires=" + expire.toGMTString())) +
                    "; path=" + ((!path) ? "/" : path);
}
    
function deleteCookie(name) { // use: setCookie("name", value);
  if (getCookie(name)) {
    document.cookie = name + "=" +
                    "; path=" + ((!path) ? "/" : path) +
                    "; expires=" + new Date(0).toGMTString();
  }
}
    

function FNArrayGetSearchLinearRowI( searchS, arraySA ) {
 var I = 0;
 var minI = 0;
 var maxI = arraySA.length - 1;
 //
 var s = "";
 //
 var foundB = false;
 //
 I = minI - 1;
 while ( ( I <= maxI ) && ( !( foundB ) ) ) {
  I = I + 1;
  s = arraySA[ I ];
  foundB = ( searchS == s );
  }
 if ( foundB ) {
  return( I );
 }
 else {
  return( -1000 ); // some negative number indicating not found
 }
}


function redirectLink() {
// test the cookie value and sets it into English if void
    if (getCookie('language')== null) { setCookie('language','en') }
    language = getCookie('language')

// check that the page is available in the array - if not, revert to English
    if(FNArrayGetSearchLinearRowI(language, languages_avail) == -1000) {language = 'en' ;}
    
//  create target address   
    currenturl = window.location.toString()
    lastocc = currenturl.lastIndexOf("/")
    pagename = currenturl.substr(lastocc)
    webpage = currenturl.substring(0, lastocc)
    
window.location = webpage + '/' + language + pagename
}

function page_reload() {

    currenturl = window.location.toString()
    lastocc = currenturl.lastIndexOf("/")
    pagename = currenturl.substr(lastocc)
    webpage = currenturl.substring(0, lastocc-3)
window.location = webpage + pagename
}