home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 October / Chip_2000-10_cd1.bin / redakce / soutez / content / js / shared.js < prev   
Text File  |  1999-12-08  |  3KB  |  97 lines

  1. // "Internal" function to return the decoded value of a cookie
  2. //
  3.  
  4. function getCookieVal (offset) {
  5.   var endstr = document.cookie.indexOf (";", offset);
  6.   if (endstr == -1)
  7.     endstr = document.cookie.length;
  8.   return unescape(document.cookie.substring(offset, endstr));
  9. }
  10. //
  11. //  Function to correct for 2.x Mac date bug.  Call this function to
  12. //  fix a date object prior to passing it to SetCookie.
  13. //  IMPORTANT:  This function should only be called *once* for
  14. //  any given date object!  See example at the end of this document.
  15. //
  16.  
  17. function FixCookieDate (date) {
  18.   var base = new Date(0);
  19.   var skew = base.getTime(); // dawn of (Unix) time - should be 0
  20.   if (skew > 0)  // Except on the Mac - ahead of its time
  21.     date.setTime (date.getTime() - skew);
  22. }
  23.  
  24. var expdate = new Date ();
  25. FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
  26. expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now 
  27.  
  28. //
  29. //  Function to return the value of the cookie specified by "name".
  30. //    name - String object containing the cookie name.
  31. //    returns - String object containing the cookie value, or null if
  32. //      the cookie does not exist.
  33. //
  34.  
  35. function GetCookie (name) {
  36.   var arg = name + "=";
  37.   var alen = arg.length;
  38.   var clen = document.cookie.length;
  39.   var i = 0;
  40.   while (i < clen) {
  41.     var j = i + alen;
  42.     if (document.cookie.substring(i, j) == arg)
  43.       return getCookieVal (j);
  44.     i = document.cookie.indexOf(" ", i) + 1;
  45.     if (i == 0) break; 
  46.   }
  47.   return null;
  48. }
  49.  
  50. //
  51. // Cookie Eula
  52. //   In the top level directory will be a file called
  53. //   start.htm, which contains the text of the End User
  54. //   License Agreement and a button at the bottom of the
  55. //   page for the user to click on to accept it.  The
  56. //   button triggers a javascript call that sets a cookie
  57. //   called 'eula' to remember their acceptance of the
  58. //   agreement and then redirects them to the next page,
  59. //   /content/main.htm.  We can (and will) check for
  60. //   this cookie on the other pages and redirect them back
  61. //   to the EULA page if it is not set.  The code for
  62. //   checking the cookie on the other pages should appear
  63. //   in a shared source file called /content/js/shared.js.
  64.  
  65. // Start of inline command to open a new home window if the Eula is not present.
  66.  
  67. i = GetCookie ("Eula");
  68. if (i != "accepted") {
  69.   window.location  = "/start.htm";
  70. }
  71.  
  72. //
  73. // Cookie Connected
  74. //
  75. //   Whenever there is a link to any external site, the
  76. //   url must be passed to a function that will check the
  77. //   'connected' cookie (this function should also appear
  78. //   in /content/shared.js).  If they are connected to the
  79. //   internet, a simple redirection occurs.  If not, a
  80. //   warning dialog comes up asking them if they want to
  81. //   continue. A yes answer to the dialog box redirects
  82. //   them to the URL.  A no answer simply makes the dialog
  83. //   go away leaving them on the original page.
  84.  
  85.  
  86. function externalLink(linker) {
  87.   i = GetCookie("Connected");
  88.   if (i != "1") {
  89.     if (window.confirm("You are currently not connected to the internet. Do you wish to connect to follow this link?")) {
  90.       window.location=linker;
  91.     }
  92.   }
  93.   else {
  94.      window.location=linker;
  95.   }
  96. }
  97.