home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 October
/
Chip_2000-10_cd1.bin
/
redakce
/
soutez
/
content
/
js
/
shared.js
< prev
Wrap
Text File
|
1999-12-08
|
3KB
|
97 lines
// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
//
// Function to correct for 2.x Mac date bug. Call this function to
// fix a date object prior to passing it to SetCookie.
// IMPORTANT: This function should only be called *once* for
// any given date object! See example at the end of this document.
//
function FixCookieDate (date) {
var base = new Date(0);
var skew = base.getTime(); // dawn of (Unix) time - should be 0
if (skew > 0) // Except on the Mac - ahead of its time
date.setTime (date.getTime() - skew);
}
var expdate = new Date ();
FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now
//
// Function to return the value of the cookie specified by "name".
// name - String object containing the cookie name.
// returns - String object containing the cookie value, or null if
// the cookie does not exist.
//
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
//
// Cookie Eula
// In the top level directory will be a file called
// start.htm, which contains the text of the End User
// License Agreement and a button at the bottom of the
// page for the user to click on to accept it. The
// button triggers a javascript call that sets a cookie
// called 'eula' to remember their acceptance of the
// agreement and then redirects them to the next page,
// /content/main.htm. We can (and will) check for
// this cookie on the other pages and redirect them back
// to the EULA page if it is not set. The code for
// checking the cookie on the other pages should appear
// in a shared source file called /content/js/shared.js.
// Start of inline command to open a new home window if the Eula is not present.
i = GetCookie ("Eula");
if (i != "accepted") {
window.location = "/start.htm";
}
//
// Cookie Connected
//
// Whenever there is a link to any external site, the
// url must be passed to a function that will check the
// 'connected' cookie (this function should also appear
// in /content/shared.js). If they are connected to the
// internet, a simple redirection occurs. If not, a
// warning dialog comes up asking them if they want to
// continue. A yes answer to the dialog box redirects
// them to the URL. A no answer simply makes the dialog
// go away leaving them on the original page.
function externalLink(linker) {
i = GetCookie("Connected");
if (i != "1") {
if (window.confirm("You are currently not connected to the internet. Do you wish to connect to follow this link?")) {
window.location=linker;
}
}
else {
window.location=linker;
}
}