Make script more generic for use by other iframes

This PR makes the script a bit more generic so that I can make use of it for the formstack iframes and avoid having a lot of duplication of functionality.

Pinging @theefer who has helped me out a lot with this work.