home *** CD-ROM | disk | FTP | other *** search
- // Copernic Agent helper methods for Internet Explorer
-
-
- // ShowAdvancedSearch & StartSearch result code
- copernicAgent_OK = 0;
- copernicAgent_Failed = -1;
- copernicAgent_QueryTooLong = -2;
-
- // Search mode
- copernicAgent_ModeAllWords = 0;
- copernicAgent_ModeAnyWords = 1;
- copernicAgent_ModeExactPhrase = 2;
-
- // Internal constants
- copernicAgent_ProtocolPrefix = "copernicagentsearch:";
- copernicAgent_SearchWindowName = "CopernicAgentSearch";
- copernicAgent_ProtocolFlagInteractive = 1;
-
- // Internal variable
- var copernicAgent = null;
-
-
- // Initialize Copernic Agent helper object
- function copernicAgent_Init()
- {
- try
- {
- copernicAgent = new ActiveXObject("CopernicAgentExt.ApplicationHelper");
- return copernicAgent_OK;
- }
- catch (e)
- {
- copernicAgent = null;
- return copernicAgent_Failed;
- }
- }
-
- // Load Copernic Agent category list
- function copernicAgent_LoadCategoryList(comboBox, strDefaultCategory)
- {
- if (copernicAgent)
- {
- try
- {
- var categories = copernicAgent.categories;
- var count = categories.count;
- var i = 0;
-
- // Load category list
- comboBox.length = count;
- while (i < count)
- {
- var category = categories.item(i);
-
- comboBox.options[i].text = category.displayname;
- comboBox.options[i].value = category.id;
-
- i++;
- }
-
- if (i == 0)
- {
- // No category available
- comboBox.length = 1;
- comboBox.options[0].text = strDefaultCategory;
- comboBox.options[0].value = "";
- }
-
- // Select first category
- if (comboBox.selectedIndex < 0)
- ASelectBox.selectedIndex = 0;
-
- return copernicAgent_OK;
- }
- catch (e)
- {
- return copernicAgent_Failed;
- }
- }
- else
- {
- comboBox.length = 1;
- comboBox.options[0].text = strDefaultCategory;
- comboBox.options[0].value = "";
-
- return copernicAgent_Failed;
- }
- }
-
-
- // Get Copernic Agent version string
- // Returns "" if the version is lower than 6.1 or is unknown
- function copernicAgent_GetVersion()
- {
- if (copernicAgent)
- {
- try
- {
- return copernicAgent.Version;
- }
- catch (e)
- {
- return "";
- }
- }
- else
- {
- return "";
- }
- }
-
-
- // Show advanced search dialog
- function copernicAgent_ShowAdvancedSearch(category, query, mode)
- {
- if (copernicAgent)
- {
- var url = copernicAgent_ProtocolPrefix + escape(escape(query)) + ":" + escape(escape(category)) + ":" + mode + ":" + copernicAgent_ProtocolFlagInteractive;
-
- if (url.length <= 256)
- {
- top.window.window.navigate(url);
-
- if (window.name == copernicAgent_SearchWindowName)
- {
- setTimeout("window.close();", 500);
- }
-
- return copernicAgent_OK;
- }
- else
- {
- return copernicAgent_QueryTooLong;
- }
- }
- else
- {
- return copernicAgent_Failed;
- }
- }
-
-
- // Start search
- function copernicAgent_StartSearch(category, query, mode)
- {
- if (copernicAgent)
- {
- var url = copernicAgent_ProtocolPrefix + escape(escape(query)) + ":" + escape(escape(category)) + ":" + mode;
-
- if (url.length <= 256)
- {
- top.window.window.navigate(url);
-
- if (window.name == copernicAgent_SearchWindowName)
- {
- setTimeout("window.close();", 500);
- }
-
- return copernicAgent_OK;
- }
- else
- {
- return copernicAgent_QueryTooLong;
- }
- }
- else
- {
- return copernicAgent_Failed;
- }
- }
-
-
- // Returns true if trimmed string is empty
- function isStringEmpty(str)
- {
- if (str.length == 0)
- {
- return(true);
- }
-
- var j = 0;
- for (var i = 0; i < str.length; i++)
- {
- if (str.charAt(i) == " ")
- {
- j++;
- }
- }
-
- return(j == str.length);
- }
-
-
- // Returns true if query contains "and" or "or"
- function containsBooleanOperators(str)
- {
- var inquote = false;
- var tmp = "";
-
- for (var i = 0; i < str.length; i++)
- {
- ch = str.charAt(i);
-
- if (ch == '"')
- {
- inquote = !inquote;
- tmp = tmp + " ";
- }
- else if (!inquote)
- {
- tmp = tmp + ch;
- }
- }
-
- tmp = " " + tmp.toLowerCase() + " ";
-
- return((tmp.indexOf(" and ") < 0) && (tmp.indexOf(" or ") < 0));
- }
-
-
- // Validate query and display error dialog if any error occur
- function validateQuery(category, query, mode, strExactWithQuotesError, strBooleanOperatorConfirm, strEmptyCategory)
- {
- if (isStringEmpty(category))
- {
- alert(strEmptyCategory);
- return copernicAgent_Failed;
- }
-
- if ((mode == copernicAgent_ModeExactPhrase) && (query.indexOf('"') >= 0))
- {
- alert(strExactWithQuotesError);
- return copernicAgent_Failed;
- }
-
- if ((!containsBooleanOperators(query)) && (!confirm(strBooleanOperatorConfirm)))
- {
- return copernicAgent_Failed;
- }
-
- return copernicAgent_OK;
- }
-