Not sure what part of this you are struggling with, the cookie or the event handler. Both can be done with the ClientAPI and the MSAJAX framework (which the ClientAPI will require in the next release).
MSAJAX allows you to attach events via the $addHandler global method. The clientapi has a dnn.dom.attachEvent method, which has the following defined in its intellisense for the next release.
/// <summary>
/// Attatches an event to an element. - you are encouraged to use the $addHandler method instead - kept only for backwards compatibility
/// </summary>
/// <param name="ctl" type="Object">
/// Control
/// </param>
/// <param name="type" type="String">
/// Event name to attach
/// </param>
/// <param name="fHandler" type="Function">
/// Reference to the function that will react to event
/// </param>
/// <returns type="Boolean" />
Accessing cookies is straight forward. you can either interact with the browser directly or I have helper methods in the ClientAPI.
dnn.dom.getCookie, dnn.dom.setCookie, dnn.dom.deleteCookie