//textarea="";
function setSelect(text) {
        if (typeof(text.createTextRange) != 'undefined')
                text.selectPos = document.selection.createRange().duplicate();
        textarea=text;
}
function insertText(text1,text2,promptext) {
         var tagtext = prompt(promptext,"");
         if (tagtext) {
         replaceText(text1+tagtext+"'"+">", text2, textarea);
         }
}
function replaceText(text1,text2) {
        if (typeof(textarea) != 'undefined') {
        if (typeof(textarea.selectPos) != "undefined" && textarea.createTextRange)
        {
                var selectPos = textarea.selectPos;

                selectPos.text = selectPos.text.charAt(selectPos.text.length - 1) == ' ' ? text1 + selectPos.text + text2 + ' ' : text1 + selectPos.text + text2;
                selectPos.select();
        }
        else if (typeof(textarea.selectionStart) != "undefined")
        {
                var begin = textarea.value.substr(0, textarea.selectionStart);
                var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
                var end = textarea.value.substr(textarea.selectionEnd);
                var newCursorPos = textarea.selectionStart;
                var scrollPos = textarea.scrollTop;

                textarea.value = begin + text1 + selection + text2 + end;

                if (textarea.setSelectionRange)
                {
                        if (selection.length == 0)
                                textarea.setSelectionRange(newCursorPos + text1.length, newCursorPos + text1.length);
                        else
                                textarea.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length);
                        textarea.focus();
                }
                textarea.scrollTop = scrollPos;
        }
        else
        {
                textarea.value += text1 + text2;
                textarea.focus(textarea.value.length - 1);
        }
        }
}
