moved some JS code out of HTM into JS file

moved all JS code to single JS file as per rules.