/***********************************************************************/
/*                                                                     */
/*      UnFoot ::    Convert InDesign footnote(s) to story texts       */
/*                                                                     */
/*      [Ver: 1.01]    [Author: Marc Autret]    [Modif: 08/26/09]      */
/*      [Lang: EN]     [Req: InDesign CS4]      [Creat: 08/24/09]      */
/*                                                                     */
/*      Installation:                                                  */
/*                                                                     */
/*      1) Place the current file into Scripts/Scripts Panel/          */
/*                                                                     */
/*      2) Run InDesign, open a document                               */
/*      [opt] place the insertion point in a footnote to 'unfoot'      */
/*            only this one                                            */
/*      [opt] select a textframe (or place the insertion point inside) */
/*            to 'unfoot' all the story's footnotes                    */
/*      By default, the script converts all the document's footnotes   */
/*                                                                     */
/*      3) Exec script from Window > Automatisation > Scripts          */
/*         (double-click on the script name)                           */
/*                                                                     */
/*      Bugs & Feedback : marc{at}indiscripts{dot}com                  */
/*                        www.indiscripts.com                          */
/*                                                                     */
/***********************************************************************/

var UNFOOT_MARKS = ["<",">"];

/*arr*/	Object.prototype.getFootnotes = function()
//----------------------------------------------------------
{
if ( this.constructor.name == 'Footnote' )
	return([this]);
if ( 'footnotes' in this )
	return(this.footnotes.everyItem().getElements());
if ( 'stories' in this )
	return(this.stories.everyItem().
	footnotes.everyItem().getElements());
return([]);
}

/*void*/	Footnote.prototype.unFoot = function()
//----------------------------------------------------------
{
var txt = this.convertToText();
var p = txt.parent;
var iEnd = txt.insertionPoints.item(-1).index +
	UNFOOT_MARKS[0].length;
txt.insertionPoints.item(0).contents = UNFOOT_MARKS[0];
p.insertionPoints.item(iEnd).contents = UNFOOT_MARKS[1];
}

/*void*/	Application.prototype.main = function()
//----------------------------------------------------------
{
if ( this.documents.length <= 0 ) return;
var tg = this.selection[0] || this.activeDocument;

if ( 'appliedFont' in tg ) tg = tg.parent;
tg = tg.getFootnotes();

for ( var i = tg.length-1 ; i>=0 ; i-- )
	{
	tg[i].unFoot();
	}
}

app.doScript('app.main();', ScriptLanguage.javascript,
undefined, UndoModes.entireScript, app.activeScript.displayName);