cross-browser function to return the selection position