//cookies set & get methods
var cookieActivate = belenusHome.cookieActivate;

function cookieReset(name) {
  document.cookie = name+"=; expires=Fri, 02-Jan-1970 00:00:01 GMT;";
}

function getXCookie(name) { // use: getCookie("name");
  var cookieTmp = "";
  if(cookieActivate) {
  cookieTmp += document.cookie;
  var index = cookieTmp.indexOf(name + "=");
  if (index == -1) return null;
  index = cookieTmp.indexOf("=", index) + 1;
  var endstr = cookieTmp.indexOf(";", index);
  if (endstr == -1) endstr = cookieTmp.length;
  return unescape(cookieTmp.substring(index, endstr));
  }
}

function setXCookie(name, value, durationOfValidity) { 
  var cookieTmp = "";
  var today = new Date();
  try {
  	var expiry = (!isNaN(parseInt(durationOfValidity))) ? (new Date(today.getTime()+parseInt(durationOfValidity))) : (new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000)); // if durationOfValidity valid take it else 28days
  } catch(e) {
	var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000);
  }
  
  if(name == "Language") {
    if(cookieActivate) {
      if (value != null && value != "")
      document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString()+"; path=/";
      cookieTmp = document.cookie; // update cookieTmp
    }    
  } else {
    if(cookieActivate) {
      if (value != null && value != "")
      document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
      cookieTmp = document.cookie; // update cookieTmp
    }    
  }
}
