I would like to know how to load an external Javascript into my document from a function.
This is one way:
function loadDaFun() {
var script = document.createElement('script');
script.src = '/path/to/your/script.js';
var head = document.getElementsByTagName("head")[0];
head.appendChild(script);
}