var linktext=new Array()
linktext[0]="粗体: [b]文字[/b]"
linktext[1]="斜體: [i]文字[/i]"
linktext[2]="底線: [u]文字[/u]"
linktext[3]="插入網址: [url=http://url]網址或文字[/url]"
linktext[4]="插入電子郵件: [mail=mail@address]電子郵件名稱或是文字[/mail]"
linktext[5]="插入圖片連結: [img]http://圖檔連結位址[/img]"
linktext[6]="Insert code: [code]code text[/code]"
linktext[7]="插入引用: [quote]引用的文字[/quote]"
linktext[8]="字體顏色: [color=#000000]文字[/color]"
linktext[9]="字體大小: [size=]文字[/size]"
linktext[10]="閃亮文字: [glo=#a1f7a1]文字[/glo]"

 var ns6=document.getElementById&&!document.all
 var ie=document.all

function show_text(thetext, whichdiv){
 if (ie) eval("document.all."+whichdiv).innerHTML=linktext[thetext]
 else if (ns6) document.getElementById(whichdiv).innerHTML=linktext[thetext]
}

function resetit(whichdiv){
 if (ie) eval("document.all."+whichdiv).innerHTML=' '
 else if (ns6) document.getElementById(whichdiv).innerHTML=' '
}

function AddText(text) {
	if (document.input.message.createTextRange && document.input.message.caretPos) {      
		var caretPos = document.input.message.caretPos;      
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
		text + ' ' : text;
	}
	else document.input.message.value += text;
	document.input.message.focus(caretPos)
}

function showcolor(color) {
	AddTxt="[color="+color+"] [/color]";
	AddText(AddTxt);
}

function showsize(size) {
	AddTxt="[size="+size+"] [/size]";
	AddText(AddTxt);
}

function countlimit(maxlength,e,placeholder){
	var theform=eval(placeholder)
	var lengthleft=maxlength-theform.value.length
	var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
	if (window.event||e.target&&e.target==eval(placeholder)){
		if (lengthleft<0)
		theform.value=theform.value.substring(0,maxlength)
		placeholderobj.innerHTML=lengthleft
	}
}

function displaylimit(theform,thelimit){
	var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b>'
	if (document.all||ns6)
		document.write(limit_text)
	if (document.all){
		eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
		eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
	}
	else if (ns6){
		document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
	document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
	}
}

function storeCaret(text) { 
	if (text.createTextRange) {
		text.caretPos = document.selection.createRange().duplicate();
	}
}

function restrictinput(maxlength,e,placeholder){
	if (window.event&&event.srcElement.value.length>=maxlength)
		return false
	else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
		var pressedkey=/[a-zA-Z0-9\.\,\/]/ 
		if (pressedkey.test(String.fromCharCode(e.which)))
			e.stopPropagation()
		}
}