function setCookie(name, value, expires, path, domain){
  value = escape(value);
  if (expires == ""){
    var nowDate = new Date();
    nowDate.setMonth(nowDate.getMonth() + 6);
    expires = nowDate.toGMTString();
  }
  if (path != ""){
    path = "; path=" + path;
  }
  if (domain != ""){
    domain = "; domain=" + domain;
  }
  document.cookie=name+"="+value+"; expires="+expires+domain+path+";";
}

function getCookieValue(name){
  var value = document.cookie;
  var cookieStartsAt = value.indexOf(" " + name + "=");
  if (cookieStartsAt == -1){
    cookieStartsAt = value.indexOf(name + "=");
  }
  if (cookieStartsAt == -1){
    value = null;
  }
  else{
    cookieStartsAt = value.indexOf("=", cookieStartsAt) + 1;
    var cookieEndsAt = value.indexOf(";", cookieStartsAt);
    if (cookieEndsAt == -1){
      cookieEndsAt = value.length;
    }
    value = unescape( value.substring(cookieStartsAt, cookieEndsAt) );
  }
  return value;
}

function removeCookie(name){
  var nowDate = new Date();
  nowDate.setMonth(nowDate.getMonth() - 1);
  expires = nowDate.toGMTString();
  setCookie("page", "", expires, "", "");
}
