Turns out that code was in every single php file I had. I've gone though and manually edited it out of all php files, and things seem happy again.
That java script was coming from a redirect in a .htaccess file that was in the root directory. I thought I had checked it, but must have missed it somehow.
I think all is well again, and hopefully it will stay that way.