How do I code it so when someone clicks a smilie it automatically inputs the code into the text box?

Also how would I do the same for the http://, e-mail and img buttons exactly like a vbb forum?