Hi,
I think the main problem is index of textFrames (x) on your pages. Your code assumes top frame has index 0 and it grows going down...
This is often false, cause frame's index is applied while creation (last frame has index 0; not first)
So comparing textFrame[x].label to "captionY" is mostly false.
Check this one line code with your doc:
alert(myDocument.pages[0].textFrames[0].label)
It supposed to be 'caption1' but I am pretty sure it is not.
Jarek