<!--
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
if ((name + "=" + escape(value)).length <= 4000){
  document.cookie = curCookie;
 }
else{
  if (confirm("Cookie превышает 4KB и будет вырезан !"))
    document.cookie = curCookie;
 }
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
  date.setTime(date.getTime() - skew);
}

function saveLanguage(el,doc,_leng) {
  var reff = unescape(doc.location);
  var h_reff = reff.substring(0,reff.lastIndexOf('.'));
  var now = new Date();
  fixDate(now);
  now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000 * 10);
  if (_leng==1){
	setCookie("Lang","1",now,0,0,0);
	if (h_reff.lastIndexOf("_ukr")==-1){
	  el.href = h_reff+"_ukr.html";
	}else{
  	  el.href = h_reff+".html";
	}
  }
  else{
	setCookie("Lang","0",now,0,0,0);
    if (h_reff.lastIndexOf("_ukr")==-1){
	  el.href = h_reff+".html";
	}else{
      el.href = h_reff.substring(0,h_reff.lastIndexOf('_ukr'))+".html";
	}
  }
  return 1;
}
// -->