function AddText(NewCode) 
	{
	if (document.frmMessageForm.message.createTextRange && document.frmMessageForm.message.caretPos) {
		var caretPos = document.frmMessageForm.message.caretPos;
		caretPos.text = NewCode;
	} else {
		document.frmMessageForm.message.value+=NewCode;
	}
	document.frmMessageForm.message.focus();
	}

function bold() 
	{
	var text = getText();
	if (text)
		{
		AddTxt="[b]" + text + "[/b]";
		AddText(AddTxt);
		}
	else 
		{
		txt=prompt("Nhap noi dung cho dong chu in dam:","");
		if ((txt==null) || (txt==""))
			{
				AddTxt="";
				AddText(AddTxt);
			}
		else
			{
				AddTxt="[b]" + txt + "[/b]";
				AddText(AddTxt);
			}
		}
	}

function italicize() 
	{
	var text = getText();
	if (text)
		{
		AddTxt="[i]" + text + "[/i]";
		AddText(AddTxt);
		}
	else 
		{
		txt=prompt("Nhap noi dung cho dong chu in nghieng:","");
		if ((txt==null) || (txt==""))
			{
				AddTxt="";
				AddText(AddTxt);
			}
		else
			{
				AddTxt="[i]" + txt + "[/i]";
				AddText(AddTxt);
			}
		}
	}

function underline()
	{
	var text = getText();
  	if (text)
		{
		AddTxt="[u]" + text + "[/u]";
		AddText(AddTxt);
		}
	else 
		{
		txt=prompt("Nhap noi dung cho dong chu co gach chan:","");
		if ((txt==null) || (txt==""))
			{
				AddTxt="";
				AddText(AddTxt);
			}
		else
			{
				AddTxt="[u]" + txt + "[/u]";
				AddText(AddTxt);
			}
		}
	}

function storeCaret(ftext)
	{
	if (ftext.createTextRange)
		{
		ftext.caretPos = document.selection.createRange().duplicate();
		}
	}

function hyperlink()
	{
	var text = getText();
	if (text)
		{
		txt=prompt("Hay Nhap duong dan cua lien ket:","http://");
		txt2=txt
		if ((txt2==null) || (txt2=="") || (txt2=="http://"))
			{
				AddTxt=text;
				AddText(AddTxt);
			}
		else
			{
				AddTxt="[url=" + txt2 + "]" + text + "[/url]";
				AddText(AddTxt);
			}
		} 
	else
		{ 
		txt3=prompt("Hay nhap noi dung cho link:","");
		txt4=prompt("Hay nhap duong dan cua lien ket:","http://");
		if ((txt3!=null) && (txt3!="") && (txt4!=null) && (txt4!="")&& (txt4!="http://"))
			{
				AddTxt="[url=" + txt4 + "]" + txt3 + "[/url]";
				AddText(AddTxt);
			}
		else
			{
				AddTxt="";
				AddText(AddTxt);
			}
		}
	}

function getText()
	{
	if (document.frmMessageForm.message.createTextRange && document.frmMessageForm.message.caretPos) 
		{
		return document.frmMessageForm.message.caretPos.text;
		}
	else 
		{
		return '';
		}
	}