var cookieName = "_Huktra01";

function getCookie (name) {
var dcookie = document.cookie; 
var cname = name + "=";
var clen = dcookie.length;
var cbegin = 0;
   while (cbegin < clen) {
   var vbegin = cbegin + cname.length;
     if (dcookie.substring(cbegin, vbegin) == cname) { 
     var vend = dcookie.indexOf (";", vbegin);
        if (vend == -1) vend = clen;
     return unescape(dcookie.substring(vbegin, vend));
     }
   cbegin = dcookie.indexOf(" ", cbegin) + 1;
     if (cbegin == 0) break;
   }
return null;
}

function setCookie (name, value, expires) {
  if (!expires) expires = new Date();
  document.cookie = name + "=" + escape (value) + "; expires=" + expires.toGMTString() +  "; path=/";
}

function delCookie (name) {
  var expireNow = new Date();
  document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
  window.history.go(0);
}

function show_name() {
  if(getCookie(cookieName) != null)
  document.write("Cookie =" + getCookie(cookieName) + ". ");
  else document.write("No Cookie currently enabled");
}

function goSite(langVersion) {
		window.location.href=langVersion + "index.htm";
        var expdate = new Date ();
        expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
		var wotLang = langVersion;
        if (wotLang != '') {setCookie (cookieName, wotLang, expdate);}
	return false;
}

function switchSite(langVersion) {
		window.location.href="../"+langVersion + "index.htm";
        var expdate = new Date ();
        expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
		var wotLang = langVersion;
        if (wotLang != '') {setCookie (cookieName, wotLang, expdate);}
	return false;
}

function set_lang(form) {
  var expdate = new Date ();
  expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
  var wotLang = form.languagelist.value
    if (wotLang != '') {
       setCookie (cookieName, wotLang, expdate);          
    }
}

function set_name(form) {
  var expdate = new Date ();
  expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
  var username = form.nameinput.value
    if (username != '') {
       setCookie (cookieName, username, expdate);
       window.history.go(0);                        
    }
}

function checkSite() {
   if(getCookie(cookieName) != null)
   location.href=getCookie(cookieName) + "index.htm";
}
