/**
 * Adds css hover ability to LI list items for IE
 *
 * from http://alistapart.com/articles/dropdowns/
 */
startList = function()
{
    if (document.all && document.getElementById)
    {
        if (document.getElementById("topnav"))
        {
            navRoot = document.getElementById("topnav").firstChild;

            for (i=0; i < navRoot.childNodes.length; i++)
            {
                node = navRoot.childNodes[i];
                if (node.nodeName == "LI") {
                    node.onmouseover = function() {
                        this.className += " hover";
                    };

                    node.onmouseout = function() {
                        this.className=this.className.replace(" hover", "");
                    };
                }
            }
        }

        /*
        if (document.getElementById("leftnav")) {
            listItems = document.getElementById("leftnav").getElementsByTagName("LI");
            for (i=0; i < listItems.length; i++)
            {
                node = listItems[i];
                if (node.nodeName=="LI")
                {
                    node.onmouseover=function()
                    {
                        this.className += " hover";
                    }

                    node.onmouseout=function()
                    {
                        this.className=this.className.replace(" hover", "");
                    }
                }
            }

        }
        */
    }
};

/**
 * Allows any <div> element with the class "clickable" to become a link.
 * The link will be whatever the first <a> element links to.
 */
linkableDivs = function()
{
    var divs = document.getElementsByClassName("clickable", "div");

    for (var i = 0; i < divs.length; i++)
    {
        var anchor, anchor_href, anchor_target;
        anchor = divs[i].getElementsByTagName("a")[0];

        if (typeof anchor == "undefined") {
            continue;
        }

        anchor_href = anchor.getAttribute("href") || "";
        anchor_target = anchor.getAttribute("target") || "";

        if (anchor_href === "") {
            continue;
        }
        else {
            divs[i].onclick = (function() {
                                   var href = anchor_href;
                                   var target = anchor_target;
                                   return function() { link_to(href, target); return false; };
                               })();

        }
    }
    
    return true;
};

link_to = function(url, window)
{
    if (window === "") {
        location.href = url;
    }
    else if (window == "_blank") {
        top.window.open(url);
    }
    else if (window[0] != "_") {
        top.window.open(url, window);
    }
    else {
        location.href = url;
    }
};


/* Run onload scripts */

Event.observe(window, 'load', function() {
                                   try { startList(); } catch (err) {}
                                   try { linkableDivs(); } catch (err2) {}
                               });


/*
 * Functions to open popup windows from footer links
 */

function MM_openBrWindow(theURL, winName, features) {
    window.open(theURL,winName,features);
}

function openLanguages_e(object) {
    MM_openBrWindow('/en/languages_e.asp', 'languages','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=525,height=357');
}

function openLanguages_f(object) {
    MM_openBrWindow('/fr/languages_f.asp', 'languages','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=525,height=357');
}

function openSecurity_e(object) {
    MM_openBrWindow('/en/security_e.asp', 'security','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=525,height=357');
}

function openSecurity_f(object) {
    MM_openBrWindow('/fr/security_f.asp', 'security','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=525,height=357');
}

function openPrivacy_e(object) {
    MM_openBrWindow('/en/privacy_e.asp', 'privacy','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=525,height=357');
}

function openPrivacy_f(object) {
    MM_openBrWindow('/fr/privacy_f.asp', 'privacy','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=525,height=357');
}

function openLegalAgreement_e(object) {
    MM_openBrWindow('/en/legal_agreement_e.asp', 'legal_agreement','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=525,height=357');
}

function openLegalAgreement_f(object) {
    MM_openBrWindow('/fr/legal_agreement_f.asp', 'legal_agreement','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=525,height=357');
}

function open_rep_map(url) {
    window.open(url, 'repmap', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600');
}
