﻿var link_normal = "请输入显示的文字，如果留空则直接显示链接。";
var link_normal_input = "请输入链接地址，注意不能输入空格、引号、方括号等特殊字符。";


function AddText(NewCode) {
        if(document.all){
        	insertAtCaret(document.form1.txtDetail, NewCode);
        	setfocus();
        } else{
        	document.form1.txtDetail.value += NewCode;
        	setfocus();
        }
}

function setfocus() {
        document.form1.txtDetail.focus();
}


function insertAtCaret (textEl, text){
        if (textEl.createTextRange && textEl.caretPos){
                var caretPos = textEl.caretPos;
                caretPos.text += caretPos.text.charAt(caretPos.text.length - 2) == ' ' ? text + ' ' : text;
        } else if(textEl) {
                textEl.value += text;
        } else {
        	textEl.value = text;
        }
}

function hyperlink() {
        txt2=prompt(link_normal,""); 
        if (txt2!=null) {
                txt=prompt(link_normal_input,"http://");      
                if (txt!=null) {
                        if (txt2=="") {
                                AddTxt="[url]"+txt;
                                AddText(AddTxt);
                                AddText("[/url]");
                        } else {
                                AddTxt="[url="+txt+"]"+txt2;
                                AddText(AddTxt);
                                AddText("[/url]");
                        }         
                } 
        }
}


