This is probably not the answer you want to hear, but I'd suggest editing your Javascript in a separate editor. I'd recommend the free Komodo Edit, which is what I use for editing HTML and CSS as well. I own Adobe CS4 Web Premium, which includes Dreamweaver, but frankly speaking, I never use Dreamweaver at all. It is not designed for intense Javascript, but expects that you will adopt its model of adding "behaviors" to your page through a dumbed-down interface.
If you need to rely on a WYSIWYG HTML editor to get layout done, you can still edit your Javascript separately. Use Dreamweaver and your JS editor side-by-side. But let me warn you that certain layout options and dynamic HTML creation will be either very difficult or simply closed to you. This failing is not unique to Dreamweaver, but exists for all WYSIWYG editors. As soon as you surrender your markup and CSS generation to one of them, not to mention your Javascript coding, you lose certain abilities.