home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 October / Chip_2000-10_cd1.bin / redakce / soutez / content / js / setEula.js < prev    next >
Text File  |  2000-08-24  |  4KB  |  165 lines

  1. // "Internal" function to return the decoded value of a cookie
  2.  
  3. //
  4.  
  5.  
  6.  
  7. function getCookieVal (offset) {
  8.  
  9.   var endstr = document.cookie.indexOf (";", offset);
  10.  
  11.   if (endstr == -1)
  12.  
  13.     endstr = document.cookie.length;
  14.  
  15.   return unescape(document.cookie.substring(offset, endstr));
  16.  
  17. }
  18.  
  19. //
  20.  
  21. //  Function to correct for 2.x Mac date bug.  Call this function to
  22.  
  23. //  fix a date object prior to passing it to SetCookie.
  24.  
  25. //  IMPORTANT:  This function should only be called *once* for
  26.  
  27. //  any given date object!  See example at the end of this document.
  28.  
  29. //
  30.  
  31.  
  32.  
  33. function FixCookieDate (date) {
  34.  
  35.   var base = new Date(0);
  36.  
  37.   var skew = base.getTime(); // dawn of (Unix) time - should be 0
  38.  
  39.   if (skew > 0)  // Except on the Mac - ahead of its time
  40.  
  41.     date.setTime (date.getTime() - skew);
  42.  
  43. }
  44.  
  45.  
  46.  
  47. var expdate = new Date ();
  48.  
  49. FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
  50.  
  51. expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now 
  52.  
  53.  
  54.  
  55. //
  56.  
  57. //  Function to create or update a cookie.
  58.  
  59. //    name - String object containing the cookie name.
  60.  
  61. //    value - String object containing the cookie value.  May contain
  62.  
  63. //      any valid string characters.
  64.  
  65. //    [expires] - Date object containing the expiration data of the cookie.  If
  66.  
  67. //      omitted or null, expires the cookie at the end of the current session.
  68.  
  69. //    [path] - String object indicating the path for which the cookie is valid.
  70.  
  71. //      If omitted or null, uses the path of the calling document.
  72.  
  73. //    [domain] - String object indicating the domain for which the cookie is
  74.  
  75. //      valid.  If omitted or null, uses the domain of the calling document.
  76.  
  77. //    [secure] - Boolean (true/false) value indicating whether cookie transmission
  78.  
  79. //      requires a secure channel (HTTPS).  
  80.  
  81. //
  82.  
  83. //  The first two parameters are required.  The others, if supplied, must
  84.  
  85. //  be passed in the order listed above.  To omit an unused optional field,
  86.  
  87. //  use null as a place holder.  For example, to call SetCookie using name,
  88.  
  89. //  value and path, you would code:
  90.  
  91. //
  92.  
  93. //      SetCookie ("myCookieName", "myCookieValue", null, "/");
  94.  
  95. //
  96.  
  97. //  Note that trailing omitted parameters do not require a placeholder.
  98.  
  99. //
  100.  
  101. //  To set a secure cookie for path "/myPath", that expires after the
  102.  
  103. //  current session, you might code:
  104.  
  105. //
  106.  
  107. //      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
  108.  
  109. //
  110.  
  111.  
  112.  
  113. function SetCookie (name,value,expires,path,domain,secure) {
  114.  
  115.   document.cookie = name + "=" + escape (value) +
  116.  
  117.     ((expires) ? "; expires=" + expires.toGMTString() : "") +
  118.  
  119.     ((path) ? "; path=" + path : "") +
  120.  
  121.     ((domain) ? "; domain=" + domain : "") +
  122.  
  123.     ((secure) ? "; secure" : "");
  124.  
  125. }
  126.  
  127.  
  128.  
  129. //
  130.  
  131. // Cookie Eula
  132.  
  133. //   In the top level directory will be a file called
  134.  
  135. //   start.htm, which contains the text of the End User
  136.  
  137. //   License Agreement and a button at the bottom of the
  138.  
  139. //   page for the user to click on to accept it.  The
  140.  
  141. //   button triggers a javascript call that sets a cookie
  142.  
  143. //   called 'eula' to remember their acceptance of the
  144.  
  145. //   agreement and then redirects them to the next page,
  146.  
  147. //   /content/main.htm.  We can (and will) check for
  148.  
  149. //   this cookie on the other pages and redirect them back
  150.  
  151. //   to the EULA page if it is not set.  The code for
  152.  
  153. //   checking the cookie on the other pages should appear
  154.  
  155. //   in a shared source file called /content/shared.js.
  156.  
  157.  
  158.  
  159. function eulaAccept () {
  160.  
  161.   SetCookie ("Eula", "accepted", expdate);
  162.  
  163.   window.location='content/soutez/maincz.html';
  164.  
  165. }