/*	PrintPopUp version 1.00.2 - Allows the user to select a page number from a popup and have it 'silently' printed.
  	Copyright David Wraight / PlanetPDF © 2000		
	
	Credits:	Carl Othlieb[Adobe] - Supplying original popUpMenu code
				George Johnson		- Supplied advice and code for arrays and loops	

	Bug:		Acrobat 4.00 contains a return value bug, after running script three
				times popUp.Menu returns 'null' - restarting application solves the problem	
				Bug has been fixed in 4.05		*/

//  Create an Array to store the Popup menu items
var popupArray = new Array();

// How many pages are in the PDF file.
var numPDFPages = this.numPages;

// ArrayIndex is used to count the number of items in the array
var arrayIndex = 0;
var pageLoop;
var pageLoop2;

//  Fill the array with Menu Headers:
//	(["Page 1- 20","Page 1","Page 2...."],["Page 21 - 40","Page 21","Page 22..."],)
for (pageLoop = 1; pageLoop < numPDFPages; pageLoop += 20) 
{

     popupArray[arrayIndex] = "['Page " + pageLoop + " - " + (pageLoop + 19);

     for (j = pageLoop; j < pageLoop + 20; j++) 
	 {
          popupArray[arrayIndex] += "','" + j;
     }
     
	 popupArray[arrayIndex] += "'],";
     arrayIndex = arrayIndex + 1;
}

var completeString = "";
//  Create one long string with all of the array elements
for (pageLoop = 0; pageLoop < arrayIndex; pageLoop++) 
{
     completeString += popupArray[pageLoop];
}

// Capture the selected item
var returnValue = eval("app.popUpMenu(" + completeString + "'Print Window')"); 

// Process the return value
if (returnValue == 'Print Window')
{
	// Show Print Dialog Only
	this.print(true,1,1,false);
}

else if (returnValue == null)
{
	//You either selected nothing, or your using Acrobat 4.0
}

else
{
	//  Print Document using page range - Silently
	this.print(false,returnValue,returnValue,true);

	//  Output complete message
	app.alert("Page " + returnValue + " printed.");
}

