The script works fine.

Anyhow, iam using these function with “insering smileys” too.. A better solution is to make a function for the smileys, that works almost equal to WrapTag function..

Function insertSmiley( ) {

}

That would insert some smiley codes, whitout highlighting any text..

I uses the wraptag function for that, with empty on right side, but that work in msie, cause i didn't highligh any text..

How can such function goes, if it should be build on this script.
.. I have a function like this I use now, but that only works for msie..

Is this something that can be done?





------ HTML -----------

<img src="/design/pictures/textstyles/boldbtn.gif" width="18" height="18"
title="Merk teksten du vil gjøre fet"
class="buttons" onmouseover="mouseover(this);" onmouseout="mouseout(this);" onmousedown="mousedown(this);" onmouseup="mouseup(this);"
onclick="wrapTag(elements['text'], '<b>', '</b>');">

<img src="/design/pictures/smileys/icon_cool.gif" title="Klikk for å sette inn smiley"
class="buttons" onmouseover="mouseover(this);" onmouseout="mouseout(this);" onmousedown="mousedown(this);" onmouseup="mouseup(this);"
onclick="wrapTag(elements['text'], ' :8)', ' ');">

-------- JavaScript ------------

<!--
function storeCaret (txtarea) {
if (txtarea.createTextRange) {
selectedRange = document.selection.createRange().duplicate();
selectedInputArea = txtarea;
}
}

function WrapIE(txtarea, lft, rgt) {
strSelection = document.selection.createRange().text;
if (strSelection!='') {
document.selection.createRange().text = lft + strSelection + rgt;
var range = document.selection.createRange();
range.collapse(true);
range.moveStart('character',
lft.length+strSelection.length+rgt.length);
range.select();
storeCaret(txtarea)
}
txtarea.focus();
}

function wrapMoz(txtarea, lft, rgt) {
var selLength = txtarea.textLength;
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
if (selEnd==1 || selEnd==2) selEnd=selLength;
var s1 = (txtarea.value).substring(0,selStart);
var s2 = (txtarea.value).substring(selStart, selEnd)
var s3 = (txtarea.value).substring(selEnd, selLength);
txtarea.value = s1 + lft + s2 + rgt + s3;
txtarea.focus();
var cPos=s1.length+(lft.length+s2.length+rgt.length);
txtarea.setSelectionRange(cPos,cPos);
}

function wrapTag(txtarea, lft, rgt) {
lft = unescape(lft);
rgt = unescape(rgt);
if (document.all) {
WrapIE(txtarea, lft, rgt);
}
else if (document.getElementById) {
wrapMoz(txtarea, lft, rgt);
}
}

function wrapWithLink(txtarea) {
var my_link = prompt('URL:','http://');
if (my_link != null) {
lft='<a href="' + my_link + '">';
rgt='</a>';
wrapTag(txtarea, lft, rgt);
}
return;
}

function insertIE (txtarea, text) {
if (txtarea.createTextRange && selectedRange) {
var caretPos = selectedRange;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text+caretPos.text + ' ' : text+caretPos.text;
} else {
txtarea.value = txtarea.value + text;
}
txtarea.focus();
return;
}

function insertMoz(txtarea , lft) {
var rgt='';
wrapTag(txtarea, lft, rgt);
return;
}

function insertTag(txtarea , lft) {
if (document.all) {
insertIE(txtarea, lft);
}
else if (document.getElementById) {
insertMoz(txtarea, lft);
}
}

function insertImage(txtarea) {
var my_link = prompt('IMG URL:','http://');
if (my_link != null) {
lft='[IMG]' + my_link + '[/IMG]';
insertTag(txtarea, lft);
}
return;
}
function mouseover(el) {
el.className = 'raise';
}

function mouseout(el) {
el.className = 'buttons';
}

function mousedown(el) {
el.className = 'press';
}

function mouseup(el) {
el.className = 'raise';
}


//-->
d