var cPos,
    fObj,
    ieC = Boolean(document.selection && document.selection.createRange);

function smilie(str) {
    if (ieC) {
	if (typeof cPos != "undefined")
	    cPos.text = str;
	else
	    fObj.value = str;
    }

    else if (typeof window.HTMLTextAreaElement != "undefined")
	fObj.value = fObj.value.substring(0, fObj.selectionStart) + str + fObj.value.substring(fObj.selectionEnd);

    else fObj.value += str;
}

function sC() {
    cPos = document.selection.createRange().duplicate();
}

window.onload = function() {
    fObj = document.forms["postForm"].elements["meddelande"];

    if (ieC) {
	fObj.onclick  = function() { sC(); }
	fObj.onkeyup  = function() { sC(); }
	fObj.onselect = function() { sC(); }
    }
}
