Here’s the basic idea of one way to manage cookies with JavaScript. As always, there are more robust libraries available, but here’s the upshot:

POC: http://jsfiddle.net/moagrius/kwctsnyq/