function bbcode(tArea, open, end){ 
    var isIE = (document.all)? true : false; 
    var open = (open)? open : ""; 
    var end = (end)? end : ""; 
if(isIE){ 
    tArea.focus(); 
    var curSelect = document.selection.createRange(); 
if(arguments[3]){ 
    curSelect.text = open + arguments[3] + "]" + curSelect.text + end; 
}else{ 
    curSelect.text = open + curSelect.text + end; 
} 
}else if(!isIE && typeof tArea.selectionStart != "undefined"){ 
    var selStart = tArea.value.substr(0, tArea.selectionStart); 
    var selEnd = tArea.value.substr(tArea.selectionEnd, tArea.value.length); 
    var curSelection = tArea.value.replace(selStart, '').replace(selEnd, ''); 
if(arguments[3]){ 
    tArea.value = selStart + open + arguments[3] + "]" + curSelection + end + selEnd; 
}else{ 
    tArea.value = selStart + open + curSelection + end + selEnd; 
} 
}else{ 
    tArea.value += (arguments[3])? open + arguments[3] + "]" + end : open + end; 
} 
}