improved is_rtl javascript function