0 && positions[j]<=value)
diff++;
print(diff);
return diff;
}
/** Merge given pages with current document.
* @param pages Array of pages to merge with.
* @param positions Array of positions for pages (see below).
*
* Inserts all pages from given array each to the position from given array.
* positions members are positions of pages in original document where to
* insert coresponding page. If positions array is shorter than pages, missing
* members are calculated as successors of the highest positions member.
* If pages array is shorther than positions array, positions's redundant
* (those without page) are ignored.
*
* Examples:
*
* // Current document has 3 pages (p1, p2, p3)
* // We want to merge pp1, pp2, pp3 with current document and
*
* // 1.)
* // pp1 should be inserted to the p1's position (currently 1st)
* // pp2 should be inserted to the p2's position (currently 2nd)
* // pp3 should be inserted to the p3's position (currently 3rd)
* mergeWithPages([pp1,pp2,pp3], [1,2,3])
* // or with skipped position parameters
* mergeWithPages([pp1,pp2,pp3], [1,2])
* // with same meaning as
* mergeWithPages([pp1,pp2,pp3], [1,2])
* // or
* mergeWithPages([pp1,pp2,pp3], [1])
* // or empty positions means from the begining of document
* mergeWithPages([pp1,pp2,pp3]. [])
*
* // As a result:
* // pp1, p1, pp2, p2, pp3, p3
*
* // 2.)
* // pp1 should be inserted to the p3's position (currently 1st)
* // pp2 should be inserted to the p2's position (currently 2nd)
* // pp3 should be inserted to the p1's position (currently 3rd)
* mergeWithPages([pp1,pp2,pp3], [3, 2, 1])
*
* // As a result:
* // pp3, p1, pp2, p2, pp1, p3
*
* // 3.)
* // merge pp1, pp2, pp3 behind current pages (join documents with
* // current in front part.
* mergeWithPages([pp1,pp2,pp3], [document.getPageCount()+1])
*
* // As a result:
* // p1, p2 ,p3, pp1, pp2, pp3
*
* // 4.)
* // merge pp1, pp2, pp3 before current pages (join documents with
* // current in back part.
* mergeWithPages([pp1,pp2,pp3], [1,1,1])
*
* // As a result:
* // pp1, pp2 ,pp3, p1, p2, p3
*
*/
function mergeWithPages(pages, positions)
{
var maxPos=0;
var pos;
// stores all pages which have their position
for(i=0;i