The W3Schools JavaScript Cookies code has a bug in it. In the function setCookie this line:
exdate.setDate(exdate.getDate()+expiredays);
JavaScript Date Object Properties:
getDate() - Returns the day of the month (from 1-31)
...
getTime() - Returns the number of milliseconds since midnight Jan 1, 1970
...
getDate() plus the number of days is not going to work. I think it should be something like this:
expire = expiredays * 1000 * 60 * 60 * 24; // convert to milliseconds
var exdate = new Date( today.getTime() + (expire) );
The cookie libraries at TechPatterns.com Javascript Cookie Script Get Cookie, Set Cookie, Delete Cookie Functions work better (#1 in Google results isn't always the best).
I tested code from both pages in IE8 and the first one caused my cookie to have an expire date of 1/1/2038 1:00 AM. The code from the second example set my cookie expire date to exactly 1 day from the time I tested it, just as expected.