Get Listview SelectedItem from JavaScript

Hi,

How do I get the current ListView item in JavaScript?

I have a listview and wish to do validation and and additional data lookup when a user exits various fields contained within the listview item. But I cannot figure out how to determine which listview item is the current one being edited. The code sample below illustrates what I am attempting to accomplish, however the javascript only works for inserts or if the item being edited is the last item in the listview. Of course the problem is when a user attempts to edit an item other than the last one this code will not work properly.