        function textCounter(field, countfield, maxlimit) {
                countfield.value = maxlimit - field.value.length;
        }
        function insertAtCursor(myField, myValue) {
                        myField.focus();

                //IE support
                if (document.selection) {
                        myField.focus();
                        sel = document.selection.createRange();
                        sel.text = myValue;
                }
                //MOZILLA/NETSCAPE support
                else if (myField.selectionStart || myField.selectionStart == '0') {
                        var startPos = myField.selectionStart;
                        var endPos = myField.selectionEnd;
                        myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
                } else {
                        myField.value += myValue;
                }
        }

        var i = 0;
        var j = 0;
        var k = 0;
        var l = 0;
        var f = 0;
        var g = 0;

        function insertQuote(form) {
                if (i % 2 == 0) {
                        insertAtCursor(form, '[q]');
                } else {
                        insertAtCursor(form, '[/q]');
                }
                i += 1;
        }
        function insertBold(form) {
                if (j % 2 == 0) {
                        insertAtCursor(form, '[b]');
                } else {
                        insertAtCursor(form, '[/b]');
                }
                j += 1;
        }
        function insertUnderline(form) {
                if (k % 2 == 0) {
                        insertAtCursor(form, '[u]');
                } else {
                        insertAtCursor(form, '[/u]');
                }
                k += 1;
        }
        function insertItalic(form) {
                if (l % 2 == 0) {
                        insertAtCursor(form, '[i]');
                } else {
                        insertAtCursor(form, '[/i]');
                }
                l += 1;
        }
       function insertLink(form) {
                if (f % 2 == 0) {
                        insertAtCursor(form, '[url=xxx]');
                } else {
                        insertAtCursor(form, '[/url]');
                }
                f += 1;
        }
       function insertColor(form) {
                if (g % 2 == 0) {
                        insertAtCursor(form, '[font=xxx]');
                } else {
                        insertAtCursor(form, '[/font]');
                }
                g += 1;
        }
       function insertImg1(form, url) {
                insertAtCursor(form, '[img='+url+' style=float:left; ]');
       }
       function insertImg2(form, url) {
                insertAtCursor(form, '[center][img='+url+' style=padding:3px; ][/center]');
       }
       function insertImg3(form, url) {
                insertAtCursor(form, '[img='+url+' style=float:right; ]');
       }
       function insertFlag(form, url) {
                insertAtCursor(form, ''+url+'');
       }

        function newImage(arg) {
                if (document.images) {
                        rslt = new Image();
                        rslt.src = arg;
                        return rslt;
                }
        }

        function changeImages() {
                if (document.images && (preloadFlag == true)) {
                        for (var i=0; i<changeImages.arguments.length; i+=2) {
                                document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
                        }
                }
        }
