well that bbstyle is fairly simple, it is just taking care of whatever you clicked, and checking to see if you have selected anything before you clicked, whatever you click on, say the bold button, it passes a number to the function, thats why it is bbstyle(number), it then uses if's etc... to look for the number and process it
for example when clicking on the bold button, it says this:
onClick="bbstyle(0)"
in the button tag, and that sends the 0 back to the function to process it
get the idea now, if not you may want to look into something else