How to get the start and end points of selection in text area?

i want to get the cursor start and end position of a selected range in a text-field or text-area. i tried lot of functions in various forums. but when the last character of the selection is a new line character JavaScript ignore it in IE6. any one having idea ?

thank you
Nayana Adassuriya

Have you seen this one? http://www.quirksmode.org/dom/range_intro.html