function storeCaret (textEl) {
        if (textEl.createTextRange)
                textEl.caretPos = document.selection.createRange().duplicate();
}

function insertAtCaret (textEl, text) {
        if (textEl.createTextRange && textEl.caretPos) {
                var caretPos = textEl.caretPos;
                caretPos.text =
                        caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
                        text + ' ' : text;
        } else {
                textEl.value  = textEl.value + text; // for non MSIE browsers just append it
        }

        return true;
}
        function DoPrompt(action) {
                var currentMessage = document.blog.VAL_BLOG_TEXT.value;

                if (action == "url") {
                        var thisURL = prompt("Enter the complete URL for the link you wish to add.", "http://");
                        if (thisURL == null){return;}

                        var thisTitle = prompt("Now enter the title of the webpage you wish to reference.  For instance, if you are linking to the URL for TwoRags.com, you might use the title 'TwoRags'.", "web page");
                        if (thisTitle == null){return;}

                        insertAtCaret(document.blog.VAL_BLOG_TEXT, ' ' + "[url=" + thisURL + "]" + thisTitle + "[/url]" + ' ');
                        document.blog.VAL_BLOG_TEXT.focus();
                        return;
                }

                if (action == "bold") {
                        var thisBold = prompt("Enter the text that you wish to make bold.", "");
                        if (thisBold == null){return;}

                        insertAtCaret(document.blog.VAL_BLOG_TEXT, ' ' + "[b]" + thisBold + "[/b]" + ' ' );
                        document.blog.VAL_BLOG_TEXT.focus();
                        return;
                }

                if (action == "italics") {
                        var thisItal = prompt("Enter the text that you wish to italicize.", "");
                        if (thisItal == null){return;}

                        insertAtCaret(document.blog.VAL_BLOG_TEXT, ' ' + "[i]" + thisItal + "[/i]" + ' ' );
                        document.blog.VAL_BLOG_TEXT.focus();
                        return;
                }

                if (action == "image") {
                        var thisImage = prompt("Enter the complete URL for the image you wish to display.", "http://");
                        if (thisImage == null){return;}

                        insertAtCaret(document.blog.VAL_BLOG_TEXT, ' ' + "[img]" + thisImage + "[/img]" + ' ' );
                        document.blog.VAL_BLOG_TEXT.focus();
                        return;
                }

                if (action == "color") {
                        var thisURL = prompt("Enter the font color you want to use.  May be a color code such as #ff1123 or something like blue", "");
                        if (thisURL == null){return;}

                        var thisTitle = prompt("Now enter the text you want to be colored.", "");
                        if (thisTitle == null){return;}

                        insertAtCaret(document.blog.VAL_BLOG_TEXT, ' ' + "[color:" + thisURL + "]" + thisTitle + "[/color]" + ' ');
                        document.blog.VAL_BLOG_TEXT.focus();
                        return;
                }

                if (action == "club") {
                        insertAtCaret(document.blog.VAL_BLOG_TEXT, '' + "[c]" + ' ' );
                        document.blog.VAL_BLOG_TEXT.focus();
                        return;
                }

                if (action == "heart") {
                        insertAtCaret(document.blog.VAL_BLOG_TEXT, '' + "[h]" + ' ' );
                        document.blog.VAL_BLOG_TEXT.focus();
                        return;
                }

                if (action == "diamond") {
                        insertAtCaret(document.blog.VAL_BLOG_TEXT, '' + "[d]" + ' ' );
                        document.blog.VAL_BLOG_TEXT.focus();
                        return;
                }

                if (action == "spade") {
                        insertAtCaret(document.blog.VAL_BLOG_TEXT, '' + "[s]" + ' ' );
                        document.blog.VAL_BLOG_TEXT.focus();
                        return;
                }
        }
