/* Usage: setCookie('name', 'value'[, days, 'path', 'domain', secure]); where name, value, and path are strings, and secure is either true or null. Only name and value are required. Note: days can be either a number of days until the cookie expires or a GMT-formatted date string such as 'Fri, 13-Apr-1970 00:00:00 GMT'. readCookie('name'); Returns the value associated with name. delCookie('name'[, 'path', 'domain']); Remember that path and domain must be supplied if they were set with the cookie. */ function setCookie(cookieName, value, days, path, domain, secure){ if(days) { if ((typeof(days) == 'string') && Date.parse(days) ) { // already a Date string var expdate = days; } else if (typeof(days) == 'number') { // calculate Date from number of hours var expdate = (new Date((new Date()).getTime() + (days * 24 * 3600 * 1000))).toGMTString(); } } document.cookie = cookieName + '=' + escape(value) + ((expdate)?(';expires=' + expdate):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified. } function getCookie(cookieName){ if (document.cookie.length > 0){ begin = document.cookie.indexOf(cookieName+"="); if (begin != -1){ begin += cookieName.length+1; end = document.cookie.indexOf(";", begin); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(begin, end)); } } return null; } function delCookie(name, path, domain) { var theValue = getCookie(name); // We need the value to delete the cookie if(theValue) { document.cookie = name + '=' + '; expires=Thu, 01-Jan-70 00:00:01 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie } } // delCookie