Fixed Javascript replacing strings only once.

Pull request for bugfix of issue #1 , see issue #2

merged.