NULL_VALUE = "#NULL#"

function removeBlanks(s) {
  var temp = ""
  for (var i=0;i<s.length;++i) {
    var c=s.charAt(i)
    if (c != " ") temp += c
  }
  return temp
}

function getCookieValue(n) {
  s = removeBlanks(document.cookie)
  var pairs = s.split(";")
  for (var i=0;i<pairs.length;++i) {
    var pairSplit=pairs[i].split("=")
    if (pairSplit[0] == n) {
      if (pairSplit[0].length > 1) return pairSplit[1]
      else return NULL_VALUE
    }
  }
  return NULL_VALUE
}

function SetCookie (name, value) {
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) +
                ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
                ((path == null) ? "" : ("; path=" + path)) +
                ((domain == null) ? "" : ("; domain=" + domain)) +
                ((secure == true) ? "; secure" : "");
}

//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//    path -   String object containing the path of the cookie to delete.  This MUST
//             be the same as the path used to create the cookie, or null/omitted if
//             no path was specified when creating the cookie.
//    domain - String object containing the domain of the cookie to delete.  This MUST
//             be the same as the domain used to create the cookie, or null/omitted if
//             no domain was specified when creating the cookie.
//
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

