


// Helper function. You can use it to create expiration date based on the current date and 
// an offset you specify. The offset is defined by days, hours, minutes.
// Pass three integer parameters for the number of days, hours,
// and minutes from now you want the cookie to expire (or negative
// values for a past date); all three parameters are required,
// so use zeros where appropriate
function make_exp_date(days, hours, minutes) {
    var expDate = new Date( );
    if (typeof days == "number" && typeof hours == "number" && 
        typeof hours == "number") {
        expDate.setDate(expDate.getDate( ) + parseInt(days));
        expDate.setHours(expDate.getHours( ) + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes( ) + parseInt(minutes));
        return expDate;
    }
}
   
// Internal function to extract the cookie value from the cookie string.
function get_cookie_val(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}
   
// get_cookie(name);
//Retrieve cookie value. Returns empty string if the cookie is not set.
function get_cookie(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 get_cookie_val(j);
        }

        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return "";
}
 

// set_cookie(name, value [,expires, path, domain, secure])
// Set cookie value.
function set_cookie (name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

// delete_cookie(name [,path,domain])
// Remove a cookie. Set it to an empty string and expiration date to a past date.
function delete_cookie (name,path,domain) {
	if (get_cookie(name)) {
		document.cookie = name + "=" +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

randnum = "abdef";

set_cookie("test_cookie", randnum, make_exp_date(0, 1, 1));

if(get_cookie("test_cookie") != randnum) {

	if(typeof(rootdir) == "undefined") rootdir = "./";
	window.location = rootdir+"nocookies.php";
} 
