
/*
Download links tracking
version FR 1.2.2
*/

function track_link() {
    trackFile(this, ( /_trial/.test(document.location) ? 'Trial ' : '' ) + this.getAttribute('file'));
}

function track_trial_link() {
    t = this.href.split('/');
    trackFile(this, 'Trial '+ t[t.length-1]);
}

if ( /chapter=(186498691|186498689)/.test(document.location.search) && document.getElementById("download_link") ) {
    document.getElementById("download_link").onclick = track_trial_link;
}

function link_init() {
    var el = document.getElementsByTagName("a");
    for(var i = 0; i < el.length; i++) {
        if( el[i].getAttribute('file') ) {
                el[i].onclick = track_link;
        }
    }
}

if(typeof window.addEventListener != 'undefined') {
    window.addEventListener('load', link_init, false);
}
else if(typeof document.addEventListener != 'undefined') {
    //.. opera 7
    document.addEventListener('load', link_init, false);
}
else if(typeof window.attachEvent != 'undefined') {
    //.. win/ie
    window.attachEvent('onload', link_init);
}
//** remove this condition to degrade older browsers
else {
    //.. mac/ie5 and anything else that gets this far
    //if there's an existing onload function
    if(typeof window.onload == 'function') {
        //store it
        var existing = onload;

        //add new onload handler
        window.onload = function() {
            //call existing onload function
            existing();

            //call link_init onload function
            link_init();
        };
    }
    else {
        //setup onload function
        window.onload = link_init;
    }
}
