basepage: backtrack up the DOM from the first image to insert ajax results

The previous approach was to use a series of table cell offsets, which results in undefined
behaviour depending on the implementation of the DOM.  Instead, search for the first `<img>`
tag that is contained by a `<div>` and then backtrack upwards to the `<div>` in order to find the
proper insertion point.

Tested-on: IE 6, IE 10, Chrome, Firefox, Opera 12.
Signed-off-by: William Pitcock <kaniini@dereferenced.org>.