function format(tag) {
                var el = document.getElementById('text');
                if (el.setSelectionRange) {
                    el.value = el.value.substring(0,el.selectionStart) + '[' + tag + ']' + el.value.substring(el.selectionStart,el.selectionEnd) + '[e' + tag + ']' + el.value.substring(el.selectionEnd,el.value.length)
                } else {    
                    if (selectedText != '') {
                        var selectedText = document.selection.createRange().text;
                        var newText = '[' + tag + ']' + selectedText + '[e' + tag + ']';
                        document.selection.createRange().text = newText;
                    } 
                }
            }
            
            function bold() {
                format('b');
            }
            function italic() {
                format('i');
            }
            function underline() {
                format('u');
            }
            function hyperlink() {
                format('l');
            }
			function firstbullet() {
                format('fbl');
            }
			function bullet() {
                format('bl');
            }
			function lastbullet() {
                format('lbl');
            }
			function firstlist() {
                format('fn');
            }
			function list() {
                format('n');
            }
			function lastlist() {
                format('ln');
            }