{"version":3,"sources":["../js/Text/GreenlightTextCompare_FullDocumentSelection.js"],"names":["g_oTextCompare_FullDocumentSelection","TextCompareFullDocumentSelection","this","SHORT_TIMEOUT","LONG_PAGE_CHANGED_TIMEOUT","prototype","processFullDocumentSelection","oCompareCanvas","oArtworkCanvas","bCompareCanvas","iMinWords","g_oProgressBar","addProgressBar","setTimeout","iOldTextComparisonAccuracy","g_oSettings","g_oUserSettings","TextComparisonAccuracy","oArtWorkSequentialPages","g_oTextCompare_AutoSelection","extractSequentialPages","oCompareSequentialPages","getExactWordMatches","exactMatches","processExactMatches","oSequentialPagesForMatching","iTimeoutAmount","length","processPhrase","phrase","oPages","index","bInitialRun","percentageIndex","updateProgress","textSelectionGroups","g_oTextCompare","getTextSelectionGroup","selectedGroup","getHighestGroupOrder","autoSelectLinkId","g_iAutoSelectLinkId","group","selectedIndexes","bAutoSelectionFound","startDirectMatchSelectionForPages","text","pageNumber","g_iCurrentPage","handleTextSelection","renderTextCompareAnnotations","sort","a","b","removeProgressBar","g_oGreenlightMessages","displaySuccessBubble","c_szMatchesFoundAndSelected","displayWarningBubble","c_szNoMatchesFound","getSelectedPhrases","oAlreadySelectedPhrases","oGroups","i","combinedSelectionText","j","g_oTextSelections","g_oSelectionWordsText","push","trim","updateProgressWithDelay","totalWords","callback","oWords","getPagesFullText","split","oWordsCompare","iHighestWordLength","szCurrentPhrase","foundPhrases","previousSelectedIndexes","bSuccess","iLastTimeout","iAddedWords","iFailedWords","processWord","indexOf","uniqueFoundPhrases","seenTexts","Set","has","add","oWord","JSON","parse","stringify","replace","iszCurrentWordLength","bHasFoundSomethingAtEnd","slice","join","number","count","message","bPartTwo","percentage","parseInt","updateProressBar","ConfirmToStartFullDocumentSelection","toggleTextCompareFullDocumentSelectionOptions","g_bArtworkTextDataLoaded","g_bCompareTextDataLoaded","g_oViewer","g_oArtworkViewer","g_oDoc","documentId","g_oCompare","g_oCompareViewer","displayErrorBubble","iMatchFromDocument","$","val","window"],"mappings":"AAcA,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BpF,iCAAiCI,UAAU6B,eAAiB,SAAUmE,OAAQC,MAAOC,QAASC,UAG1F,IAAIC,WAAaC,SAASL,OAASC,MAAQ,KAG3CG,YAAc,EAGVD,WACAC,YAAc,IAIlB9F,eAAegG,iBAAiBF,WAAYF,UAOhDtG,iCAAiCI,UAAUuG,oCAAsC,WAKnF,GAHMxE,eAAeyE,gDAGhBzE,eAAe0E,0BAA6B1E,eAAe2E,yBAAhE,CAMA,GAAIC,UAAUC,iBAAiBC,OAAOC,aAAeC,WAAWC,iBAAiBH,OAAOC,WAEvF,OADA5D,sBAAsB+D,mBAAmB,2EAClC,EAGF,IAAIC,mBAAqBb,SAASc,EAAE,8DAA8DC,MAAO,IACrG/G,UAAYgG,SAASc,EAAE,4DAA4DC,MAAO,IAEnE,IAAvBF,mBAEAvH,qCAAqCM,6BAA6B8G,WAAWC,iBAAkBL,UAAUC,kBAAkB,EAAOvG,WAKlIV,qCAAqCM,6BAA6B0G,UAAUC,iBAAkBG,WAAWC,kBAAkB,EAAM3G,gBApB1I6C,sBAAsB+D,mBAAmB,6CAyBxCI,OAAOzH,iCAAmCA,iCArY9C","file":"GreenlightTextCompare_FullDocumentSelection-9dcdcb0928.js","sourcesContent":["/*\r\n * Copyright (c) 2024 SGS Europe. All rights reserved.\r\n *\r\n * This program is the CONFIDENTIAL and PROPRIETARY property of SGS Europe.\r\n * Any unauthorized use, reproduction, or transfer of this program is strictly\r\n * prohibited.\r\n *\r\n * File Name: GreenlightTextCompare_FullDocumentSelection.js\r\n *\r\n * Description: The class containing the functionality required by the Greenlight for text compare auto auto selection.\r\n * \r\n */\r\n\r\n// The text tools object.\r\nvar g_oTextCompare_FullDocumentSelection = {};\r\n\r\n(function () {\r\n \"use strict\";\r\n\r\n /**\r\n * Load the text compare auto auto selection for the page.\r\n */\r\n function TextCompareFullDocumentSelection() {\r\n this.SHORT_TIMEOUT = 25;\r\n this.LONG_PAGE_CHANGED_TIMEOUT = 1150;\r\n }\r\n\r\n /**\r\n * Start the auto auto selection process.\r\n * @param {object} oCompareCanvas - The compare canvas.\r\n * @param {object} oArtworkCanvas - The artwork canvas.\r\n * @param {boolean} bCompareCanvas - If the compare canvas is being used.\r\n * @param {number} iMinWords - The minimum number of words to match.\r\n */\r\n TextCompareFullDocumentSelection.prototype.processFullDocumentSelection = function (oCompareCanvas, oArtworkCanvas, bCompareCanvas, iMinWords) {\r\n\r\n // Lock the screen with the progress bar.\r\n g_oProgressBar.addProgressBar(\"Preparing...\", true);\r\n\r\n // Begin calculating within a timeout to allow the progress bar message to be shown.\r\n setTimeout(function () {\r\n // Keep track of the original text comparison accuracy.\r\n var iOldTextComparisonAccuracy = g_oSettings.g_oUserSettings.TextComparisonAccuracy;\r\n g_oSettings.g_oUserSettings.TextComparisonAccuracy = 1;\r\n\r\n // Extract sequential pages for artwork.\r\n var oArtWorkSequentialPages = g_oTextCompare_AutoSelection.extractSequentialPages(oArtworkCanvas, oCompareCanvas, null);\r\n\r\n // Extract sequential pages for compare which we match words on.\r\n var oCompareSequentialPages = g_oTextCompare_AutoSelection.extractSequentialPages(oCompareCanvas, oArtworkCanvas, null);\r\n\r\n // Get the exact matches.\r\n g_oTextCompare_FullDocumentSelection.getExactWordMatches(oArtWorkSequentialPages, oArtworkCanvas, oCompareCanvas, oCompareSequentialPages, bCompareCanvas, iMinWords, function(exactMatches) {\r\n // Process the exact matches.\r\n g_oTextCompare_FullDocumentSelection.processExactMatches(exactMatches, oCompareCanvas, oArtworkCanvas, oArtWorkSequentialPages, bCompareCanvas, oCompareSequentialPages);\r\n\r\n // Reset the users text comparison accuracy.\r\n g_oSettings.g_oUserSettings.TextComparisonAccuracy = iOldTextComparisonAccuracy;\r\n });\r\n\r\n }, 100);\r\n };\r\n\r\n /**\r\n * Processes and selects the exact matches found during the auto auto selection process.\r\n * @param {Array} exactMatches - The array of exact matches.\r\n * @param {object} oCompareCanvas - The compare canvas.\r\n * @param {object} oArtworkCanvas - The artwork canvas.\r\n * @param {Array} oArtWorkSequentialPages - The sequential pages for the artwork.\r\n * @param {boolean} bCompareCanvas - If the compare canvas is being used.\r\n * @param {Array} oSequentialPagesForMatching - The sequential pages for matching.\r\n */\r\n TextCompareFullDocumentSelection.prototype.processExactMatches = function (exactMatches, oCompareCanvas, oArtworkCanvas, oArtWorkSequentialPages, bCompareCanvas, oSequentialPagesForMatching) {\r\n var iTimeoutAmount = g_oTextCompare_FullDocumentSelection.SHORT_TIMEOUT;\r\n\r\n function processPhrase(phrase, oCompareCanvas, oArtworkCanvas, oPages, bCompareCanvas, index, bInitialRun) {\r\n setTimeout(function () {\r\n\r\n // Update the progress bar, accounting for the fact that we run through each canvas one after the other.\r\n var percentageIndex = bInitialRun ? index + 1 : exactMatches.length + index + 1;\r\n g_oTextCompare_FullDocumentSelection.updateProgress(percentageIndex, exactMatches.length * 2, \"Applying Matches...\", true);\r\n\r\n var iOldTextComparisonAccuracy = g_oSettings.g_oUserSettings.TextComparisonAccuracy;\r\n g_oSettings.g_oUserSettings.TextComparisonAccuracy = 1;\r\n\r\n if (bInitialRun && index > 0) {\r\n var textSelectionGroups = g_oTextCompare.getTextSelectionGroup(bCompareCanvas);\r\n // The auto-selected group will always be the highest group order.\r\n var selectedGroup = g_oTextCompare_AutoSelection.getHighestGroupOrder(textSelectionGroups);\r\n selectedGroup.autoSelectLinkId = g_oTextCompare_AutoSelection.g_iAutoSelectLinkId++;\r\n exactMatches[index - 1].group = selectedGroup;\r\n }\r\n // Clear any existing indexes.\r\n g_oTextCompare_AutoSelection.selectedIndexes = [];\r\n\r\n var bAutoSelectionFound = g_oTextCompare_AutoSelection.startDirectMatchSelectionForPages(phrase.text, oArtworkCanvas, oPages[0], false);\r\n if (!bAutoSelectionFound && g_oTextCompare_AutoSelection.selectedIndexes.length === 0) {\r\n bAutoSelectionFound = g_oTextCompare_AutoSelection.startDirectMatchSelectionForPages(phrase.text, oArtworkCanvas, oPages[0], true);\r\n }\r\n\r\n // Check if the page will change.\r\n if (g_oTextCompare_AutoSelection.selectedIndexes.length > 1 || g_oTextCompare_AutoSelection.selectedIndexes[0].pageNumber !== oArtworkCanvas.g_iCurrentPage) {\r\n iTimeoutAmount = g_oTextCompare_FullDocumentSelection.LONG_PAGE_CHANGED_TIMEOUT * g_oTextCompare_AutoSelection.selectedIndexes.length;\r\n }\r\n else {\r\n iTimeoutAmount = g_oTextCompare_FullDocumentSelection.SHORT_TIMEOUT;\r\n }\r\n\r\n if (bInitialRun) {\r\n g_oTextCompare_AutoSelection.handleTextSelection(!bCompareCanvas, oArtworkCanvas, null, false, false);\r\n }\r\n else {\r\n g_oTextCompare_AutoSelection.handleTextSelection(!bCompareCanvas, oArtworkCanvas, phrase.group, true, false);\r\n }\r\n\r\n g_oTextCompare.renderTextCompareAnnotations();\r\n\r\n if (index < exactMatches.length - 1) {\r\n g_oSettings.g_oUserSettings.TextComparisonAccuracy = iOldTextComparisonAccuracy;\r\n processPhrase(exactMatches[index + 1], oCompareCanvas, oArtworkCanvas, oPages, bCompareCanvas, index + 1, bInitialRun);\r\n }\r\n else if (index === exactMatches.length - 1) {\r\n if (bInitialRun) {\r\n setTimeout(function () {\r\n var textSelectionGroups = g_oTextCompare.getTextSelectionGroup(bCompareCanvas);\r\n // The auto-selected group will always be the highest group order.\r\n var selectedGroup = g_oTextCompare_AutoSelection.getHighestGroupOrder(textSelectionGroups);\r\n selectedGroup.autoSelectLinkId = g_oTextCompare_AutoSelection.g_iAutoSelectLinkId++;\r\n\r\n exactMatches[index].group = selectedGroup;\r\n\r\n exactMatches.sort(function (a, b) {\r\n if (a.selectedIndexes[0].pageNumber === b.selectedIndexes[0].pageNumber) {\r\n return a.selectedIndexes.length - b.selectedIndexes.length;\r\n }\r\n return a.selectedIndexes[0].pageNumber - b.selectedIndexes[0].pageNumber;\r\n });\r\n\r\n iTimeoutAmount = g_oTextCompare_FullDocumentSelection.SHORT_TIMEOUT;\r\n g_oSettings.g_oUserSettings.TextComparisonAccuracy = iOldTextComparisonAccuracy;\r\n processPhrase(exactMatches[0], oArtworkCanvas, oCompareCanvas, oSequentialPagesForMatching, !bCompareCanvas, 0, false);\r\n }, iTimeoutAmount);\r\n }\r\n else {\r\n g_oProgressBar.removeProgressBar();\r\n g_oTextCompare_AutoSelection.selectedIndexes = [];\r\n g_oGreenlightMessages.displaySuccessBubble(exactMatches.length + \" \" + g_oTextCompare_FullDocumentSelection.c_szMatchesFoundAndSelected, 100);\r\n g_oSettings.g_oUserSettings.TextComparisonAccuracy = iOldTextComparisonAccuracy;\r\n }\r\n }\r\n }, iTimeoutAmount);\r\n }\r\n\r\n // If we have matches, process these, otherwise remove the progress bar.\r\n if (exactMatches.length > 0) {\r\n processPhrase(exactMatches[0], oCompareCanvas, oArtworkCanvas, oArtWorkSequentialPages, bCompareCanvas, 0, true);\r\n }\r\n else {\r\n g_oGreenlightMessages.displayWarningBubble(g_oTextCompare_FullDocumentSelection.c_szNoMatchesFound, 100);\r\n g_oProgressBar.removeProgressBar();\r\n\t\t}\r\n };\r\n\r\n /**\r\n * Retrieves the currently selected phrases from the text comparison groups.\r\n * @param {boolean} bCompareCanvas - Indicates if the compare canvas is being used.\r\n * @returns {Array} An array of already selected phrases.\r\n */\r\n TextCompareFullDocumentSelection.prototype.getSelectedPhrases = function (bCompareCanvas) {\r\n var oAlreadySelectedPhrases = [];\r\n var oGroups = g_oTextCompare.getTextSelectionGroup(bCompareCanvas);\r\n\r\n for (var i = 0; i < oGroups.length; i++) {\r\n var group = oGroups[i];\r\n var combinedSelectionText = \"\";\r\n for (var j = 0; j < group.g_oTextSelections.length; j++) {\r\n var selection = group.g_oTextSelections[j];\r\n combinedSelectionText += selection.g_oSelectionWordsText + \" \";\r\n }\r\n oAlreadySelectedPhrases.push(combinedSelectionText.trim());\r\n }\r\n\r\n return oAlreadySelectedPhrases;\r\n };\r\n\r\n /**\r\n * Updates the progress bar with a delay.\r\n * @param {number} index - The current index of the word being processed.\r\n * @param {number} totalWords - The total number of words to process.\r\n */\r\n TextCompareFullDocumentSelection.prototype.updateProgressWithDelay = function (index, totalWords) {\r\n setTimeout(function () {\r\n g_oTextCompare_FullDocumentSelection.updateProgress(index + 1, totalWords, \"Calculating Matches...\", false);\r\n }, 0);\r\n };\r\n\r\n /**\r\n * Retrieves exact matches.\r\n * @param {Array} oArtWorkSequentialPages - The sequential pages for the artwork.\r\n * @param {object} oArtworkCanvas - The artwork canvas.\r\n * @param {object} oCompareCanvas - The compare canvas.\r\n * @param {Array} oSequentialPagesForMatching - The sequential pages for matching.\r\n * @param {boolean} bCompareCanvas - Indicates if the compare canvas is being used.\r\n * @param {number} iMinWords - The minimum number of words to match.\r\n * @returns {Array} An array of found phrases with their selected indexes.\r\n */\r\n TextCompareFullDocumentSelection.prototype.getExactWordMatches = function (oArtWorkSequentialPages, oArtworkCanvas, oCompareCanvas, oSequentialPagesForMatching, bCompareCanvas, iMinWords, callback) {\r\n // Get the full text and list of words from the first page for the artwork document.\r\n var szFullTextAW = g_oTextCompare_AutoSelection.getPagesFullText(oArtWorkSequentialPages[0], oArtworkCanvas);\r\n var oWords = szFullTextAW.split(\" \");\r\n\r\n var oAlreadySelectedPhrases = g_oTextCompare_FullDocumentSelection.getSelectedPhrases(bCompareCanvas);\r\n\r\n // Get the full text and list of words from the first page for the compare document.\r\n var szFullTextCompare = g_oTextCompare_AutoSelection.getPagesFullText(oSequentialPagesForMatching[0], oCompareCanvas);\r\n var oWordsCompare = szFullTextCompare.split(\" \");\r\n\r\n // Find the longest word length of the compare document.\r\n var iHighestWordLength = 0;\r\n for (var i = 0; i < oWordsCompare.length; i++) {\r\n if (oWordsCompare[i].length > iHighestWordLength) {\r\n iHighestWordLength = oWordsCompare[i].length;\r\n }\r\n }\r\n\r\n var szCurrentPhrase = \"\";\r\n var foundPhrases = [];\r\n var previousSelectedIndexes = [];\r\n var bSuccess = false;\r\n var iLastTimeout = 0;\r\n var iAddedWords = 0;\r\n var iFailedWords = 1;\r\n\r\n function processWord(i) {\r\n if (i >= oWords.length) {\r\n // Check if the last phrase should be pushed to foundPhrases\r\n if (szCurrentPhrase.split(\" \").length >= iMinWords && szCurrentPhrase !== \"\" && previousSelectedIndexes.length > 0 && oAlreadySelectedPhrases.indexOf(szCurrentPhrase) === -1) {\r\n foundPhrases.push({ text: szCurrentPhrase, selectedIndexes: previousSelectedIndexes });\r\n }\r\n\r\n // Remove duplicates based on the text property\r\n var uniqueFoundPhrases = [];\r\n var seenTexts = new Set();\r\n\r\n for (var j = 0; j < foundPhrases.length; j++) {\r\n if (!seenTexts.has(foundPhrases[j].text)) {\r\n uniqueFoundPhrases.push(foundPhrases[j]);\r\n seenTexts.add(foundPhrases[j].text);\r\n }\r\n }\r\n\r\n foundPhrases = uniqueFoundPhrases;\r\n\r\n // Call the callback function with the found phrases\r\n if (callback) {\r\n callback(foundPhrases);\r\n }\r\n return;\r\n }\r\n\r\n g_oTextCompare_FullDocumentSelection.updateProgressWithDelay(i + 1, oWords.length);\r\n\r\n var oWord = oWords[i];\r\n szCurrentPhrase !== \"\" ? szCurrentPhrase += \" \" + oWord : szCurrentPhrase = oWord;\r\n\r\n if (szCurrentPhrase.split(\" \").length < iMinWords) {\r\n iAddedWords = 0;\r\n iFailedWords = 1;\r\n // Call the timeout every 25 words or more to allow the DOM to update.\r\n if (i - iLastTimeout > 25) {\r\n iLastTimeout = i;\r\n setTimeout(function() { processWord(i + 1); }, 0);\r\n } else {\r\n processWord(i + 1);\r\n }\r\n return;\r\n }\r\n\r\n iAddedWords++;\r\n\r\n var bAutoSelectionFound = g_oTextCompare_AutoSelection.startDirectMatchSelectionForPages(szCurrentPhrase, oCompareCanvas, oSequentialPagesForMatching[0], false);\r\n if (!bAutoSelectionFound && g_oTextCompare_AutoSelection.selectedIndexes.length === 0) {\r\n bAutoSelectionFound = g_oTextCompare_AutoSelection.startDirectMatchSelectionForPages(szCurrentPhrase, oCompareCanvas, oSequentialPagesForMatching[0], true);\r\n }\r\n\r\n if (g_oTextCompare_AutoSelection.selectedIndexes.length > 0 && i !== oWords.length - 1) {\r\n iFailedWords = 1;\r\n iAddedWords = 0;\r\n bSuccess = true;\r\n previousSelectedIndexes = JSON.parse(JSON.stringify(g_oTextCompare_AutoSelection.selectedIndexes));\r\n g_oTextCompare_AutoSelection.selectedIndexes = [];\r\n processWord(i + 1);\r\n }\r\n else if ((szCurrentPhrase.replace(/\\s/g, '').length < iHighestWordLength || iAddedWords < 5) && (!bSuccess || iAddedWords < 5) && i !== oWords.length - 1) {\r\n if (bSuccess) {\r\n // Count the extra failed words\r\n iFailedWords++;\r\n\t\t\t\t}\r\n processWord(i + 1);\r\n } else {\r\n var iszCurrentWordLength = szCurrentPhrase.split(\" \").length;\r\n var bHasFoundSomethingAtEnd = g_oTextCompare_AutoSelection.selectedIndexes.length > 0\r\n && i === oWords.length - 1\r\n && iszCurrentWordLength >= iMinWords;\r\n\r\n if (g_oTextCompare_AutoSelection.selectedIndexes.length === 0 && bSuccess) {\r\n // Remove any extra failed words\r\n var words = szCurrentPhrase.split(\" \");\r\n szCurrentPhrase = words.slice(0, -iFailedWords).join(\" \");\r\n i -= iFailedWords - 1;\r\n\r\n } else if (g_oTextCompare_AutoSelection.selectedIndexes.length > 0) {\r\n previousSelectedIndexes = JSON.parse(JSON.stringify(g_oTextCompare_AutoSelection.selectedIndexes));\r\n g_oTextCompare_AutoSelection.selectedIndexes = [];\r\n }\r\n\r\n if (szCurrentPhrase.split(\" \").length >= iMinWords && bSuccess) {\r\n if (foundPhrases.indexOf(szCurrentPhrase) === -1 && oAlreadySelectedPhrases.indexOf(szCurrentPhrase) === -1) {\r\n foundPhrases.push({ text: szCurrentPhrase, selectedIndexes: previousSelectedIndexes });\r\n }\r\n bSuccess = false;\r\n previousSelectedIndexes = [];\r\n szCurrentPhrase = \"\";\r\n processWord(i);\r\n } // Something was found in the last index that hasnt already been added\r\n\t\t\t\telse if (bHasFoundSomethingAtEnd &&\r\n foundPhrases.indexOf(szCurrentPhrase) === -1 &&\r\n oAlreadySelectedPhrases.indexOf(szCurrentPhrase) === -1) {\r\n foundPhrases.push({ text: szCurrentPhrase, selectedIndexes: previousSelectedIndexes });\r\n bSuccess = false;\r\n previousSelectedIndexes = [];\r\n szCurrentPhrase = \"\";\r\n processWord(oWords.length);\r\n\t\t\t\t}\r\n else {\r\n bSuccess = false;\r\n previousSelectedIndexes = [];\r\n szCurrentPhrase = \"\";\r\n processWord(i - iszCurrentWordLength + 2);\r\n }\r\n }\r\n }\r\n\r\n processWord(0);\r\n };\r\n\r\n /**\r\n * Updates the progress bar during the auto auto selection process.\r\n * @param {number} number - The current progress number.\r\n * @param {number} count - The total count for the progress.\r\n * @param {string} message - The message to display on the progress bar.\r\n * @param {boolean} bPartTwo - Indicates if this is the second part of the process.\r\n */\r\n TextCompareFullDocumentSelection.prototype.updateProgress = function (number, count, message, bPartTwo) {\r\n \r\n // Determine the percentage we are at.\r\n var percentage = parseInt(number / count * 100);\r\n\r\n // Divide the percentage by two as this is one of two parts.\r\n percentage /= 2;\r\n\r\n // If this is part two, add the initial 50%.\r\n if (bPartTwo) {\r\n percentage += 50;\r\n }\r\n\r\n // Update the progress bar.\r\n g_oProgressBar.updateProressBar(percentage, message);\r\n };\r\n\r\n /**\r\n * Confirms and starts the auto auto selection process.\r\n * Validates the necessary conditions and initiates the process based on the selected document and minimum words.\r\n */\r\n TextCompareFullDocumentSelection.prototype.ConfirmToStartFullDocumentSelection = function () {\r\n // Hide the auto auto options.\r\n g_oTextCompare.toggleTextCompareFullDocumentSelectionOptions();\r\n\r\n //// If text has not been loaded for one or more canvas, this can not be used.\r\n\t\tif (!g_oTextCompare.g_bArtworkTextDataLoaded || !g_oTextCompare.g_bCompareTextDataLoaded) {\r\n\t\t\tg_oGreenlightMessages.displayErrorBubble(\"One or more documents have no live text.\");\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// Make sure document Ids are different for a full document auto match.\r\n\t\tif (g_oViewer.g_oArtworkViewer.g_oDoc.documentId === g_oCompare.g_oCompareViewer.g_oDoc.documentId) {\r\n\t\t\tg_oGreenlightMessages.displayErrorBubble(\"Document auto matching can not be performed against the same document.\");\r\n\t\t\treturn false;\r\n }\r\n\r\n var iMatchFromDocument = parseInt($('#textComparison_FullDocumentSelection_selMatchFromDocument').val(), 10);\r\n var iMinWords = parseInt($('#textComparison_FullDocumentSelection_inputMinMatchWords').val(), 10);\r\n\r\n if (iMatchFromDocument === 0) {\r\n // Process the full document auto selection, searches through approval document for matching text on the compare.\r\n g_oTextCompare_FullDocumentSelection.processFullDocumentSelection(g_oCompare.g_oCompareViewer, g_oViewer.g_oArtworkViewer, false, iMinWords);\r\n \r\n }\r\n\t\telse {\r\n // Process the full document auto selection, searches through compare document for matching text on the approval.\r\n g_oTextCompare_FullDocumentSelection.processFullDocumentSelection(g_oViewer.g_oArtworkViewer, g_oCompare.g_oCompareViewer, true, iMinWords);\r\n\t\t}\r\n };\r\n\r\n // Add the text compare auto selection to the window object.\r\n window.TextCompareFullDocumentSelection = TextCompareFullDocumentSelection;\r\n}());"]}