Adding a javascript to all pages in OpenCart
save your script to a file, say 'catalog/view/javascript/myscript.js'
Then add
$this->document->addScript('catalog/view/javascript/myscript.js');
to the catalog/controller/common/header.php some place before this line:
$this->data['scripts'] = $this->document->getScripts();
You could also just place your script inline into catalog/view/theme/{theme name}/template/common/header.tpl using normal html markup.