Doing a WYSIWYG with Javascript is a complicated undertaking, its not possible to explain everything involved in a few posts to a forum. Furthermore, everyone has projects of their own, why should we spend hours doing your work?? What you have in mind requires an array of regular expressions, and as far as opening and modifying files I don't think that's possible without a server-side technology of some kind. If it is possible, it would require very low security settings on the client computer.
I would suggest looking at already built solutions. I found this one and after looking over the demo I quite like it. It's a cross-platform, client-side WYSIWYG that produces XHTML compliant markup.
http://www.fckeditor.net/
If you're determined to do BBCode, then download a server-side solution like the one I suggested and write a javascript version of it! As always, Google is your friend!
http://www.google.com/search?q=WYSIWYG+Javascript
Of course none of these create or have any part in managing the files generated! You still need a server-side technology for that.
Regards,
Rich
--
[
http://www.smilingsouls.net]
[
http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail