/* $Header */

/* This implements the C24 site's memory of what section you're in.
 * (Some hyperlinks would ordinarily take the user to a new section of
 * the site, but for usability reasons we want to give the illusion
 * that the user stays in the same section.)
 *
 * Any hyperlink which keeps the user within the current section is
 * given a CSS class of 'c24-remember-section'.
 *
 * Once the page has loaded, we find all such hyperlinks and set their
 * onclick handler. The handler function sets a cookie before the page
 * navigates off to the new page. The server will see this cookie, and
 * act on it to retain the navigation section last entered.
 *
 * Unless the user clicks on such a hyperlink, on page unload we clear
 * the cookie, so that by default hyperlinks 'forget' (do not remember).
 */


/* run this as soon as possible (i.e. not onload) */
eraseCookie('remember-section');

var C24Remember = {};

C24Remember.onclick = function () {
    /* we pass the actual section id (rather than just 'true', and
     * relying on the server to remember what section the user's in)
     * to avoid issues caused by the user using the back button
     */
    createCookie('remember-section', CURRENT_SECTION_ID, 0);

    return true;
}


/*
 * I've commented this out because adding the onclick events only
 * when the page has loaded means that the user could click on an item
 * while the page is loading (which can be slow, e.g. because of the ads)

C24Remember.onload = function () {
    eraseCookie('remember-section');

    // links
    var links = getElementsByClass('a', 'remember-section');
    for (var i = 0; i < links.length; i++) {
        addEventHandler(links[i], 'onclick', C24Remember.onclick);
    }

    // forms
    var forms = getElementsByClass('form', 'remember-section');
    for (var i = 0; i < forms.length; i++) {
        addEventHandler(forms[i], 'onsubmit', C24Remember.onclick);
    }
}


addLoadEvent(C24Remember.onload);

*/

