Replace filename. From http://stackoverflow.com/questions/5953239/how-do-i-change-file-extension-with-javascript
file = file.substr(0, file.lastIndexOf(".")) + ".htm";