/*
Folder Javascript Created by Joel Geraci - Acrobat Technical Evangelist - geraci@adobe.com.
 
This JavaScript was designed to convert Highligh annotations to Redaction Marks abd back"

This example demonstrates
* 	Adding SubMenus and Menu Items
*   Querying Annotation Types
*   Adding Annotations
*	Deleting annotations
*	Use of the thermometer object

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

* 	Convert Redaction Marks to Highlights
    This menu item will convert all Redaction Marks to Highlights
	The Highlight color will be the same color as your default (usually Yellow).
	 
* 	Convert Redaction Marks to Highlights
	This menu item will convert all Highlights to Redaction Marks - The Redactions will not be applied by this script though it can be easily modified to do so.

*/

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

app.addMenuItem({
	cName: "ADBE_JFG_R2H",
	cUser: "Convert Redaction Marks to Highlights",
	cParent: "ADBE_JFG_RedactionUtilities",
	cExec:"redact2Highlight()",
	cEnable: "event.rc = (event.target != null);"
	});


app.addMenuItem({
	cName: "ADBE_JFG_DeleteSimilarAnnots",
	cUser: "Convert Highlights to Redaction Marks",
	cParent: "ADBE_JFG_RedactionUtilities",
	cExec:"highlight2Redact()",
	cEnable: "event.rc = (event.target != null);"
	});


function redact2Highlight()
{
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 == "Redact")
				{
					q = annots[i].quads
					p = annots[i].page
					annots[i].destroy();
					this.addAnnot({type: "Highlight", page: p, quads: q})
				}
		}	
	}
t.end();
}

function highlight2Redact()
{
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")
				{
					q = annots[i].quads
					p = annots[i].page
					annots[i].destroy();
					this.addAnnot({type: "Redact", page: p, quads: q})
				}
		}	
	}
t.end();
}

