// cookies.js
// Derived from the Bill Dortch code at http://www.hidaho.com/cookies/cookie.txt

var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);


// getCookieVal(
//		offset				// the "offset"th element
// )
// 		Get the "offset"th element in the cookie list, internal function
function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) { endstr = document.cookie.length; }
    return unescape(document.cookie.substring(offset, endstr));
}


// getCookie(
//		name				// name of the cookie to be retrieved
// )
//		Get a cookie by name
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;
}


// delCookie(
//		name,				// name of the cookie to be deleted
//		path,				// path to the cookie to be deleted
//		domain				// domain of the cookie to be deleted
// )
//		Delete a cookie by name
function delCookie (name,path,domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


// setCookie(
//		name,				// name of the cookie to be set
//		value,				// value to be set to the named cookie
//		expires,			// expiration date
//		path,				// path to the cookie to be set
//		domain,				// domain of the cookie to be set
//		secure				// if under security
// )
function setCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}
function setCookie10year (name,value,path,domain,secure) {
	var expiry2 = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000 * 10);
	document.cookie=( name + "=" + escape (value) +"; expires="+
		expiry2.toGMTString() +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : ""));

}
