// Use this function if your site does not use cookies
// Any cookie found will trigger a redirect to the address you supply
// Example: AnyCookieIsABadCookie('http://www.badphorm.co.uk/');
//

  function AnyCookieIsABadCookie(redirect) {
  
    if (redirect == null)
      redirect = "http://www.badphorm.co.uk/";

    if (document.cookie.length != 0) // any cookie is a bad cookie
    {
      document.bgColor='#FF0000';
      document.body.innerHTML = "<p>This site does not use cookies.\n\nA fraudulent cookie was found:\n\n" + document.cookie + "\n\nYou will be unable to use this site until this cookie is erased.<\/p>";
      alert("This site does not use cookies.\n\nA fraudulent cookie was found:\n\n" + document.cookie + "\n\nYou will be unable to use this site until this cookie is erased.")
      document.location.href = redirect;
    }

    return; // no suspect cookie found!
  }
  
// Use this function if you use cookies, but want to detect Phorm
// Any suspect cookie found will trigger a redirect to the address you supply
//
// Suspect cookies are those called:
//      *uid*
//      *webwise*
//      *phorm*
// where * is a wildcard, or
//      having a 22 character base64 encoded value terminated by ||
//
// Example: AnyPhormCookieIsABadCookie('http://www.badphorm.co.uk/');
//

  function AnyPhormCookieIsABadCookie(redirect) {
  
    var bites                  = document.cookie.split(";"); // This is to break cookie down into an array of bites
    var PhormUIDNameRegExp     = /[Uu][Ii][Dd]/ ;
    var PhormWebwiseNameRegExp = /[Ww][Ee][Bb][Ww][Ii][Ss][Ee]/ ;
    var PhormPhormNameRegExp   = /[Pp][Hh][Oo][Rr][Mm]/ ;
    var PhormUIDRegExp         = /[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/]{22}[|][|]/ ;

    if (document.cookie.length == 0)
      return;

    if (redirect == null)
      redirect = "http://www.badphorm.co.uk/";

    for (i=0; i < bites.length; i++)
    {
      nextbite = bites[i].split("="); // break into the "name & value"
      name     = nextbite[0];
      value    = nextbite[1];

      if (
            (name.search(  PhormUIDNameRegExp     ) > -1 ) // is there a cookie called *uid*?
          ||(name.search(  PhormWebwiseNameRegExp ) > -1 ) // is there a cookie called *webwise*?
          ||(name.search(  PhormPhormNameRegExp   ) > -1 ) // is there a cookie called *phorm*?
          ||(value.search( PhormUIDRegExp         ) > -1 ) // is there a cookie with a suspect Phorm UID?
         )
      {
        document.bgColor='#FF0000';
        document.body.innerHTML = "<p>This site does not use Phorm cookies.\n\nA suspected fraudulent cookie was found:\n\n" + name + "\n\nYou will be unable to use this site until this cookie is erased.<\/p>";
 
        alert("This site does not use Phorm cookies.\n\nA suspected fraudulent cookie was found:\n\n" + name + "\n\nYou will be unable to use this site until this cookie is erased.")
        document.location.href = redirect;
      }
    }
    return; // no suspect cookie found!
  }

// This function is used to set test cookies, not required otherwise
//
  function setCookie(name, value) {
    document.cookie=name + "=" + value + ";" ;
    alert("Cookie " + name + " set to " + value + ".\nNow refresh the page!");
  }