/*
  - @author    Julien Visinand (VIJ)
  - @created   07 June 2005
  - @version   $Revision:   1.1  $ $Date:   Dec 02 2005 13:44:26  $
  - Description: A script that checks if the browser accepts the cookies.
*/

function getCookie(name)
{ var pos
  var token = name + "=";
  var tnlen = token.length;
  var cklen = document.cookie.length;
  var i = 0;
  var j;
  while (i < cklen)
  { j = i + tnlen;
    if (document.cookie.substring(i, j) == token)
    { pos = document.cookie.indexOf (";", j);
      if (pos == -1)
        pos = document.cookie.length;
      return unescape(document.cookie.substring(j, pos));
    }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

function setCookie(name, value, gCookiePath)
{ document.cookie = name + "=" + escape(value) + "; path="+ gCookiePath ;
}

function deleteCookie(name, gCookiePath)
{ var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = getCookie (name);
  document.cookie = name + "=" + cval + "; path="+ gCookiePath +"; expires=" + exp.toGMTString();
}

function browserCookieAcceptationTest(message)
{ var gCookieName;
  var gCookieValue;
  var gCookiePath;

  gCookieName = "IHB_TEST_COOKIE_NAME";
  gCookieValue = "IHB_TEST_COOKIE_VALUE";
  gCookiePath = "/";

  setCookie(gCookieName, gCookieValue, gCookiePath);
  gCookieValue = getCookie(gCookieName);
  deleteCookie(gCookieName, gCookiePath);

  if (gCookieValue == null) {
    alert(message);
  }
}