Insert Into Textarea, Javascript maybe?

How would I do this:

I want to make a series of buttons like Bold, Italic and Underline… Using javascript how would I let the user press the button and a little code like was placed into the text box or around a word or sentence highlighted?

so if i had the word Hello highlighted then the user clicked Bold

it would appear like : [noparse] Hello [/noparse]

Any Ideas?