if ( app.documents.length > 0 ) {
    if ( app.activeDocument.stories.length > 0 ) {
        var
            myDocument = app.activeDocument,
            docStories = myDocument.stories.everyItem(),
            docCharacters = docStories.characters.length,
            docWords = docStories.words.length,
            docFootnotesCharacters = docStories.footnotes.everyItem().characters.length,
            docFootnotesWords = docStories.footnotes.everyItem().words.length,
            docTablesCharacters = docStories.tables.everyItem().cells.everyItem().characters.length,
            docTablesWords = docStories.tables.everyItem().cells.everyItem().words.length
            statReport = [];
            
            statReport.push ( "Document text statistic:" );
            statReport.push ( "===================" );
            statReport.push ( "" );
            statReport.push ( "[Stories]");
            statReport.push ( "------------------------------" );
            statReport.push ( "Characters: " + docCharacters );
            statReport.push ( "Words: " + docWords );
            statReport.push ( "" );
            statReport.push ( "[Footnotes]");
            statReport.push ( "------------------------------" );
            statReport.push ( "Characters: " + docFootnotesCharacters );
            statReport.push ( "Words: " + docFootnotesWords );
            statReport.push ( "" );
            statReport.push ( "[Tables]");
            statReport.push ( "------------------------------" );
            statReport.push ( "Characters: " + docTablesCharacters );
            statReport.push ( "Words: " + docTablesWords );
            statReport.push ( "" );
            statReport.push ( "[TOTAL]");
            statReport.push ( "===================" );
            statReport.push ( "Characters: " + ( docCharacters + docFootnotesCharacters + docTablesCharacters ) );
            statReport.push ( "Words: " + ( docWords + docFootnotesWords + docTablesWords ) );
            
            alert ( statReport.join ( "\r" ), "Document Text Statistic" );
    } else {
        alert ( "No stories found in the document!", "Document Text Statistic" );
    }
} else {
    alert ( "No opened document!", "Document Text Statistic" );
}