// Cookie Functions -- "Toss Your Cookies" Version (22-Mar-96) 
//
// Written by: Bill Dortch, hIdaho Design
// The following functions are released to the public domain.
//
// The fix code for DeleteCookie recalibrates the date prior to 
// deleting the cookie.
//
// ***** HERE IS THE FIX FUNCTION. DO NOT DELETE IT!!! ***** 

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);
}

// ***** END OF FIX FUNCTION *****

// The first two parameters are required. The others, if supplied, must 
// be passed in the order listed above. To omit an unused optional field, 
// use null as a place holder. For example, to call SetCookie using name, 
// value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null; var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null; var secure = (argc > 5) ? argv[5] : false;
    if      (expires!=null) FixCookieDate(expires);
    document.cookie = name + "=" + escape (value) + 
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : (";  path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

// "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 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;
}

