// Code for IE
if (document.selection)
{
textarea.focus();
var sel = document.selection.createRange();
//alert(sel.text);
sel.text = tag1 + sel.text + tag2;
}
else
{ // Code for Mozilla Firefox
var len = textarea.value.length;
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
var sel = textarea.value.substring(start, end);
var rep = tag1 + sel + tag2;
textarea.value = textarea.value.substring(0,start) + rep + textarea.value.substring(end,len);
}
if (document.selection)
{
textarea.focus();
var sel = document.selection.createRange();
//alert(sel.text);
sel.text = tag1 + sel.text + tag2;
}
else
{ // Code for Mozilla Firefox
var len = textarea.value.length;
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
var sel = textarea.value.substring(start, end);
var rep = tag1 + sel + tag2;
textarea.value = textarea.value.substring(0,start) + rep + textarea.value.substring(end,len);
}