function add_tag(txtstart,txtend) {
window.opener.document.getElementById('editor_field').focus();
if (window.opener.document.selection) {
// ie & may be opera 8
var rng = window.opener.document.selection.createRange();
if (rng.text) {
window.opener.document.selection.createRange().text = txtstart + rng.text + txtend;
} else {
window.opener.document.getElementById('editor_field').value += txtstart + txtend;
}
window.opener.document.getElementById('editor_field').focus();
}
else if (window.opener.document.getElementById('editor_field').selectionStart || window.opener.document.getElementById('editor_field').selectionStart == '0') {
// mozilla: intellegent bcodes support
var selStart = window.opener.document.getElementById('editor_field').selectionStart;
var selEnd = window.opener.document.getElementById('editor_field').selectionEnd;
var s = window.opener.document.getElementById('editor_field').value;
s = s.substring(0, selStart) + txtstart + s.substring(selStart, selEnd) + txtend + s.substring(selEnd, s.length);
window.opener.document.getElementById('editor_field').value = s;
if (selEnd != selStart) {
window.opener.document.getElementById('editor_field').selectionStart = selStart;
window.opener.document.getElementById('editor_field').selectionEnd = selEnd + txtstart.length + txtend.length;
} else {
window.opener.document.getElementById('editor_field').selectionStart = selStart + txtstart.length;
window.opener.document.getElementById('editor_field').selectionEnd = window.opener.document.getElementById('editor_field').selectionStart;
}
} else {
// other browsers
window.opener.document.getElementById('editor_field').value += txtstart + txtend;
}
} |