/*
Folder Javascript Created by Joel Geraci - Acrobat Technical Evangelist - geraci@adobe.com.
 
This JavaScript was designed to assist the user when the Acrobat Compare Function finds "too much"

This example demonstrates
* 	Adding SubMenus and Menu Items
*	Detecting which annotation is selected
*	Detecting annotation properties
*	Deleting annotations
*	Use of the thermometer object

This JavaScript code will add a menu item "Joel's Comment Utilities" under "Comments" menu. 
Under that menu, you will find three additional menu items.

* 	Delete "Matching graphic not found" Annotations
    This menu item will delete all "Highligh" annotations with content "Matching graphic not found"
	 
* 	Delete Annotations of the Same Type and with the Same Content as the one Selected
	To use this menu item, select one of a kind of comment that occurs frequently and you want to remove all of then select the menu item.
	All comments of the same type and same content will be deleted.
	
* 	Count Annotations of the Same Type and with the Same Content as the one Selected
	Same as above except that comments are not deleted, they are simply counted.	

*/

app.addSubMenu({
	cName: "ADBE_JFG_CommentUtilities",
	cUser: "Joel's Comment Utilities",
	cParent: "Annots:TopLevelMenuComments",
	nPos: 0
	});

app.addMenuItem({
	cName: "ADBE_JFG_HideGNF",
	cUser: 'Delete "Matching graphic not found" Annotations',
	cParent: "ADBE_JFG_CommentUtilities",
	cExec:"deleteGNF()",
	cEnable: "event.rc = (event.target != null);"
	});


app.addMenuItem({
	cName: "ADBE_JFG_DeleteSimilarAnnots",
	cUser: "Delete Annotations of the Same Type and with the Same Content as the one Selected",
	cParent: "ADBE_JFG_CommentUtilities",
	cExec:"deleteSimilarAnnots()",
	cEnable: "event.rc = this.selectedAnnots"
	});

app.addMenuItem({
	cName: "ADBE_JFG_CountSimilarAnnots",
	cUser: "Count Annotations of the Same Type and with the Same Content as the one Selected",
	cParent: "ADBE_JFG_CommentUtilities",
	cExec:"countSimilarAnnots()",
	cEnable: "event.rc = this.selectedAnnots"
	});



function deleteGNF()
{
t = app.thermometer
annots = this.getAnnots(); 
t.duration = annots.length
t.text = "Processing";
t.begin();
	if (annots)
	{
	for (i = 0; i < annots.length; i++)
		{
			t.value = i;
			if (annots[i].type == "Highlight" && annots[i].contents == "Matching graphic not found")
				{
					annots[i].destroy();
				}	
		}	
	}
t.end();
}


function deleteSimilarAnnots()
{
t = app.thermometer
t.text = "Processing";
annContents = this.selectedAnnots[0].contents;
annType =  this.selectedAnnots[0].type
annots = this.getAnnots(); 
t.duration = annots.length
t.begin();
	if (annots)
	{
	for (i = 0; i < annots.length; i++)
		{
			t.value = i;
			if (annots[i].type == annType && annots[i].contents == annContents)
				{
					annots[i].destroy();
				}	
		}	
	}
t.end();	
}

function countSimilarAnnots()
{
t = app.thermometer
t.text = "Processing";
annContents = this.selectedAnnots[0].contents;
annType =  this.selectedAnnots[0].type
annots = this.getAnnots(); 
t.duration = annots.length
t.begin();
c=0
	if (annots)
	{
	for (i = 0; i < annots.length; i++)
		{
			t.value = i;
			if (annots[i].type == annType && annots[i].contents == annContents)
				{
					c++;
				}	
		}	
	}
t.end();
app.alert(c+" Annotations are like the one selected")
}





	