<public:component>
<public:property name="selectionStart" get="getSelectionStart" />
<public:property name="selectionEnd" get="getSelectionEnd" />
<public:method name="setSelectionRange" />
<script language="javascript">

var selectionStart = 0;
var selectionEnd = 0;

function setSelectionRange(startPos, endPos) {
    var objRange = element.createTextRange();
    objRange.collapse(true);
    objRange.move("character", startPos);

    charLength = endPos - startPos;
    for (var i=1; i<=charLength; i++)
        objRange.expand("character");

    objRange.select();
}

function getSelectionStart() {
    getSelectionRange("start");
    return selectionStart;
}

function getSelectionEnd() {
    getSelectionRange("end");
    return selectionEnd;
}

function getSelectionRange(type) {
    var sRange = element.document.selection.createRange();
    // XXX this is wrong. there must be a way to know where
    // the cursor is and get info from that...thus far, though
    // a lengthless selection returns 0 for start and end, 
    // which breaks things badly
    if (sRange.text.length == 0) {
        selectionStart = null;
        selectionEnd = null;
        return;
    }
    var sRange2 = sRange.duplicate();
    var iRange = element.document.body.createTextRange();
    iRange.moveToElementText(element);
    var coord = 0;
    var fin = 0;

    while (fin == 0) {
        len = iRange.text.length;
        move = Math.floor(len / 2);
        _move = iRange.moveStart("character", move);
        where = iRange.compareEndPoints("StartToStart", sRange2);
        if (where == 1) {
            iRange.moveStart("character", -_move);
            iRange.moveEnd("character", -len+move);
        }
        else if (where == -1) {
            coord = coord + move;
        }
        else {
            coord = coord + move;
            fin = 1;
        }
        if (move == 0) {
            while (iRange.compareEndPoints("StartToStart", sRange2) < 0) {
                iRange.moveStart("character", 1);
                coord++;
            }
            fin = 2;
        }
    }
    selectionStart = coord;
    selectionEnd = coord + (sRange.text.replace(/\r/g, "")).length;
}

</script>
</public:component>
