/*
  To the extent possible under law, Niels Serup has waived all copyright and
  related or neighboring rights to this file. This file is available under the
  Creative Commons Zero 1.0 license, see
  http://creativecommons.org/publicdomain/zero/1.0/

  This JavaScript file contains misc. code snippets designed to add extra
  features to a website. Not loading it will not make a website depending on it
  stop working.
*/

add_external_document_writing_script = function(url, elem) {
    var orig_write, content, done, ns;
    orig_write = document.write;
    content = ''
    document.write = function(msg) {
        content += msg + '\n';
    };

    done = function() {
        document.write = orig_write;
        elem.innerHTML = content;
    };

    ns = document.createElement('script');
    ns.type = 'text/javascript';
    ns.src = url;
    ns.onload = function() {
        done();
    };
    ns.onreadystatechange = function() {
        if (this.readyState == 'complete')
            done();
    };
    document.body.appendChild(ns);
};

add_fsf_widget = function(associate_id) {
    fsf_widget_size = 'normal';
    fsf_associate_id = associate_id + '';
    add_external_document_writing_script(
        'http://www.fsf.org/graphics/widget/global/widget.js',
        document.getElementById('fsfextern'));
};
