Fixed selection calculation in Firefox and copy/paste in IE