Fixed issue in page-moving code.

A for loop was checking the page count of the new, pageless document
instead of the (hopefully) pageful unlocked document.