home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / res / textfunc.tpl < prev    next >
Text File  |  2013-04-03  |  37KB  |  1,090 lines

  1. var avtBrowserInfo = {
  2.     check: function(r) {
  3.         return r.test(this.ua);
  4.     },
  5.     init: function()
  6.     {
  7.         this.ua = navigator.userAgent.toLowerCase();
  8.         this.isChrome = this.check(/chrome/);
  9.         this.isIE = this.check(/msie/);
  10.         this.isIE6 = this.check(/msie 6/);
  11.         this.isIE7 = this.check(/msie 7/);
  12.         this.isIE8 = this.check(/msie 8/);
  13.         this.isIE9 = this.check(/msie 9/);
  14.         this.isIE10 = this.check(/msie 10/);
  15.         this.isWebKit = this.check(/webkit/);
  16.         this.isGecko = !this.isWebKit && this.check(/gecko/);
  17.         this.browserID = 0;
  18.         if (navigator.appName === 'Netscape')
  19.         {
  20.             if (this.ua.lastIndexOf('firefox/') > 0)
  21.                 this.browserID = 1;
  22.             else if (this.ua.lastIndexOf('chrome/') > 0)
  23.                 this.browserID = 2;
  24.         }
  25.     }
  26. };
  27.  
  28. avtBrowserInfo.init();
  29. var avtFindingVar = {
  30.     currentFindDoc: null,
  31.     isHighlight: false,
  32.     isFindAsSentence: false,
  33.     isIgnoreCase: true,
  34.     isFirstFind: true,
  35.     matchCount: 0,
  36.     keywords: "",
  37.     keywordsArray: [],
  38.     avantTagArray: [],
  39.     tagName: "mark", //span for ie678;
  40.     color: ['Yellow', 'Red', 'Aqua', 'Fuchsia', 'Blue', 'Lime'],
  41.     bkColor: ['Red', 'Aqua', 'Fuchsia', 'Blue', 'Lime', 'Yellow'],
  42.     notFoundKeywords: "",
  43.     lastFoundKeywords: "",
  44.     Recursive: false,
  45.     init: function()
  46.     {
  47.         if (avtBrowserInfo.isIE)
  48.         {
  49.             if ((avtBrowserInfo.isIE6) || (avtBrowserInfo.isIE7) || (avtBrowserInfo.isIE8))
  50.                 avtBrowserInfo.tagName = "span";
  51.             else
  52.                 avtBrowserInfo.tagName = "mark";
  53.         }
  54.         else
  55.             avtBrowserInfo.tagName = "mark";
  56.     }
  57. };
  58. avtFindingVar.init();
  59. var avtUtility = {
  60.   GetWindow: function()
  61.   {
  62.     if(avtBrowserInfo.isGecko)
  63.       return gBrowser.contentWindow;
  64.     else
  65.       return window;
  66.   },
  67.   GetDocument: function()
  68.   {
  69.     if(avtBrowserInfo.isGecko)
  70.       return gBrowser.contentWindow.document;
  71.     else
  72.       return document;
  73.   },
  74.     trim: function(str)
  75.     {
  76.         for (var i = 0; i < str.length && str.charAt(i) === " "; i++)
  77.             ;
  78.         for (var j = str.length; j > 0 && str.charAt(j - 1) === " "; j--)
  79.             ;
  80.         if (i > j)
  81.             return "";
  82.         return str.substring(i, j);
  83.     },
  84.     isAvantTag: function(obj)
  85.     {
  86.         if (obj.getAttribute("isAvant") == "1")
  87.             return true;
  88.         else
  89.             return false;
  90.     },
  91.     markAvantTag: function(obj)
  92.     {
  93.         obj.setAttribute("isAvant", "1");
  94.     },
  95.     AvantStripVowelAccent: function(str)
  96.     {
  97.         var rExps = [/[\xC0-\xC2]/g, /[\xE0-\xE2]/g,
  98.             /[\xC8-\xCA]/g, /[\xE8-\xEB]/g,
  99.             /[\xCC-\xCE]/g, /[\xEC-\xEE]/g,
  100.             /[\xD2-\xD4]/g, /[\xF2-\xF4]/g,
  101.             /[\xD9-\xDB]/g, /[\xF9-\xFB]/g];
  102.  
  103.         var repChar = ['A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u'];
  104.  
  105.         for (var i = 0; i < rExps.length; ++i)
  106.             str = str.replace(rExps[i], repChar[i]);
  107.  
  108.         return str;
  109.     },
  110.     EmptyArray: function(arrayObj)
  111.     {
  112.         for (var i = arrayObj.length - 1; i >= 0; i--)
  113.         {
  114.             var obj = arrayObj.pop();
  115.             obj = null;
  116.         }
  117.     },
  118.     SplitKeywordsBySpace: function()
  119.     {
  120.         var strs = new Array();
  121.         strs = avtFindingVar.keywords.split(" ");
  122.         this.EmptyArray(avtFindingVar.keywordsArray);
  123.         for (var i = 0; i < strs.length; i++)
  124.         {
  125.             if ((strs[i] !== "\"") && (strs[i] !== "\'"))
  126.             {
  127.                 strs[i] = strs[i].replace("\"", "");
  128.                 strs[i] = strs[i].replace("\'", "");
  129.                 strs[i] = strs[i].replace(",", "");
  130.                 strs[i] = strs[i].replace("\\", "");
  131.  
  132.                 strs[i] = strs[i].replace("/", "");
  133.                 strs[i] = strs[i].replace(".", "");
  134.                 strs[i] = strs[i].replace("(", "");
  135.                 strs[i] = strs[i].replace(")", "");
  136.                 strs[i] = this.trim(strs[i]);
  137.                 if(strs[i] !== "")
  138.                     avtFindingVar.keywordsArray.push(strs[i]);
  139.             }
  140.         }
  141.         this.EmptyArray(strs);
  142.     },
  143.     FindNextDoc: function(currentDoc, direction)
  144.     {
  145.         if (this.Undefined(currentDoc))
  146.             return null;
  147.         var win = null;
  148.         if (avtBrowserInfo.isIE)
  149.             win = currentDoc.parentWindow;
  150.         else
  151.             win = currentDoc.defaultView;
  152.         if (direction > 0)
  153.         {
  154.             if ((this.NotUndefined(win.frames)) && (win.frames.length > 0))
  155.             {
  156.                 var doc = null;
  157.                 if (avtBrowserInfo.isGecko)
  158.                 {
  159.                     if (this.NotUndefined(win.frames[0].document))
  160.                         doc = win.frames[0].document;
  161.                     else
  162.                         doc = win.frames[0].contentDocument;
  163.                 }
  164.                 else
  165.                     doc = win.frames[0].document;
  166.                 if (this.NotUndefined(doc))
  167.                     return doc;
  168.                 else
  169.                     return null;
  170.             }
  171.             else
  172.             {
  173.                 return this.FindNextDocEx(currentDoc, direction);
  174.             }
  175.         }
  176.         else
  177.         {
  178.             var doc = this.FindNextDocEx(currentDoc, direction);
  179.             if (this.NotUndefined(doc))
  180.                 return doc;
  181.             else
  182.             {
  183.                 if (this.Undefined(win))
  184.                     return null;
  185.                 if (this.NotUndefined(win.parent) &&
  186.                     ((win.name !== win.parent.name) ||
  187.                     (win.document.URL !== win.parent.document.URL)))
  188.                     return win.parent.document;
  189.                 else
  190.                     return null;
  191.             }
  192.         }
  193.     },
  194.     FindNextDocEx: function(currentDoc, direction)
  195.     {
  196.         var F = false;
  197.         var doc = null;
  198.         var win = null;
  199.         if (avtBrowserInfo.isIE)
  200.             win = currentDoc.parentWindow;
  201.         else
  202.             win = currentDoc.defaultView;
  203.         if (this.Undefined(win))
  204.             return null;
  205.         if (this.NotUndefined(win.parent) &&
  206.             ((win.name !== win.parent.name) ||
  207.             (win.document.URL !== win.parent.document.URL)))
  208.         {
  209.             if (direction > 0)
  210.             {
  211.                 for (var n = 0; n <= win.parent.frames.length - 2; n++)
  212.                 {
  213.                     if (avtBrowserInfo.isGecko)
  214.                     {
  215.                         if (this.NotUndefined(win.parent.frames[n].document))
  216.                             doc = win.parent.frames[n].document;
  217.                         else
  218.                             doc = win.parent.frames[n].contentDocument;
  219.                     }
  220.                     else
  221.                         doc = win.parent.frames[n].document;
  222.  
  223.                     if (this.NotUndefined(doc))
  224.                     {
  225.                         var tmpWin = null;
  226.                         if (avtBrowserInfo.isIE)
  227.                             tmpWin = doc.parentWindow;
  228.                         else
  229.                             tmpWin = doc.defaultView;
  230.                         if ((tmpWin.name === win.name) &&
  231.                             (doc.URL === win.document.URL) &&
  232.                             (doc == win.document))
  233.                         {
  234.                             if (avtBrowserInfo.isGecko)
  235.                             {
  236.                                 if (this.NotUndefined(win.parent.frames[n + 1].document))
  237.                                   doc = win.parent.frames[n + 1].document;
  238.                                 else
  239.                                   doc = win.parent.frames[n + 1].contentDocument;
  240.                             }
  241.                             else
  242.                                 doc = win.parent.frames[n + 1].document;
  243.                             if (this.NotUndefined(doc))
  244.                             {
  245.                                 F = true;
  246.                                 break;
  247.                             }
  248.                         }
  249.                     }
  250.                 }
  251.             }
  252.             else
  253.             {
  254.                 for (var n = 1; n <= win.parent.frames.length - 1; n++)
  255.                 {
  256.                     if (avtBrowserInfo.isGecko)
  257.                     {
  258.                         if(this.NotUndefined(win.parent.frames[n].contentDocument))
  259.                             doc = win.parent.frames[n].contentDocument;
  260.                         else
  261.                             doc = win.parent.frames[n].document;
  262.                     }
  263.                     else
  264.                         doc = win.parent.frames[n].document;
  265.  
  266.                     if (this.NotUndefined(doc))
  267.                     {
  268.                         var tmpWin = null;
  269.                         if (avtBrowserInfo.isIE)
  270.                             tmpWin = doc.parentWindow;
  271.                         else
  272.                             tmpWin = doc.defaultView;
  273.                         if ((tmpWin.name === win.name) &&
  274.                             (doc.URL === win.document.URL) &&
  275.                             (doc == win.document))
  276.                         {
  277.                             if (avtBrowserInfo.isGecko)
  278.                             {
  279.                                 if(this.NotUndefined(win.parent.frames[n - 1].contentDocument))
  280.                                     doc = win.parent.frames[n - 1].contentDocument;
  281.                                 else
  282.                                     doc = win.parent.frames[n - 1].document;
  283.                             }
  284.                             else
  285.                                 doc = win.parent.frames[n - 1].document;
  286.                             if (this.NotUndefined(doc))
  287.                             {
  288.                                 F = true;
  289.                                 break;
  290.                             }
  291.                         }
  292.                     }
  293.                 }
  294.             }
  295.  
  296.             if (!F)
  297.             {
  298.                 doc = win.parent.document;
  299.                 if (direction > 0)
  300.                     return this.FindNextDocEx(doc, direction);
  301.             }
  302.         }
  303.         else
  304.             doc = null;
  305.         return doc;
  306.     },
  307.     NotUndefined: function(obj)
  308.     {
  309.         if ((obj === null) || (typeof(obj) === 'undefined'))
  310.             return false;
  311.         else
  312.             return true;
  313.     },
  314.     Undefined: function(obj)
  315.     {
  316.         return !this.NotUndefined(obj);
  317.     },
  318.     RebuildSelection: function(win, range)
  319.     {
  320.         var selection = win.getSelection();
  321.         var rangeCopy = range.cloneRange();
  322.         if ((rangeCopy.endOffset == rangeCopy.startOffset) && 
  323.             this.NotUndefined(rangeCopy.commonAncestorContainer))
  324.         {
  325.             if ((rangeCopy.commonAncestorContainer.nodeType == 1) &&
  326.                 (rangeCopy.commonAncestorContainer.childNodes.length > rangeCopy.startOffset))
  327.             {
  328.                 var oEle = rangeCopy.commonAncestorContainer.childNodes[rangeCopy.startOffset];
  329.                 if( (this.NotUndefined(oEle)) && (oEle.nodeType == 1) && 
  330.                     (oEle.tagName.toLowerCase() == "input") && (oEle.type == "text"))
  331.                 {
  332.                     var oTextBox = range.commonAncestorContainer.childNodes[rangeCopy.startOffset];
  333.                     if(oEle.selectionStart !== oEle.selectionEnd)
  334.                         oTextBox.setSelectionRange(oEle.selectionStart, oEle.selectionEnd);
  335.                     else
  336.                         oTextBox.setSelectionRange(0, oEle.value.length);
  337.                 }
  338.                 else
  339.                     selection.addRange(range);    
  340.             }
  341.             else
  342.                 selection.addRange(range);
  343.         }
  344.         else
  345.             selection.addRange(range);
  346.         rangeCopy.detach();
  347.         return selection;
  348.     },
  349.     FindNearestKeywords: function(win, matchCase, searchUpward)//chrome,ff
  350.     {
  351.         var results = [];
  352.         var selection = win.getSelection();
  353.         var curRange = null;
  354.         if (this.NotUndefined(selection) && (selection.rangeCount > 0))
  355.             curRange = selection.getRangeAt(0);
  356.  
  357.         for (var i = 0; i < avtFindingVar.keywordsArray.length; i++)
  358.         {
  359.             var keywords = avtFindingVar.keywordsArray[i];
  360.             if (this.NotUndefined(selection))
  361.             {
  362.                 selection.removeAllRanges();
  363.                 if (this.NotUndefined(curRange))
  364.                 {
  365.                     this.RebuildSelection(win, curRange);
  366.  
  367.                     if(searchUpward)
  368.                         selection.collapseToStart();
  369.                     else
  370.                         selection.collapseToEnd();
  371.                 }
  372.             }
  373.             var bFound = false;
  374.             try{      
  375.                 bFound = win.find(keywords, matchCase, searchUpward, false, false, false, false);
  376.             }
  377.             catch(e)
  378.             {
  379.                 //alert(e);
  380.             }
  381.             if (bFound)
  382.             {
  383.                 if (this.NotUndefined(selection))
  384.                     selection = win.getSelection();
  385.                 if (selection.rangeCount > 0)
  386.                 {
  387.                     var keywordRange = selection.getRangeAt(0);
  388.                     if (this.NotUndefined(keywordRange))
  389.                         results.push({"range": keywordRange, "keyword": keywords});
  390.                 }
  391.             }
  392.         }
  393.         var miniPosIdx = 0;
  394.         var ret = null;
  395.         if (results.length >= 1)
  396.         {
  397.             for (var i = 1; i < results.length; i++)
  398.             {
  399.                 if (!searchUpward)
  400.                 {
  401.                     if (results[miniPosIdx].range.compareBoundaryPoints(0, results[i].range) === 1)
  402.                     {
  403.                         results[miniPosIdx].range.detach();
  404.                         miniPosIdx = i;
  405.                     }
  406.                     else
  407.                         results[i].range.detach();
  408.                 }
  409.                 else
  410.                 {
  411.                     if (results[miniPosIdx].range.compareBoundaryPoints(2, results[i].range) === -1)
  412.                     {
  413.                         results[miniPosIdx].range.detach();
  414.                         miniPosIdx = i;
  415.                     }
  416.                     else
  417.                         results[i].range.detach();
  418.                 }
  419.             }
  420.             ret = {"range": results[miniPosIdx].range, "keyword": results[miniPosIdx].keyword};
  421.         }
  422.         else
  423.             ret = null;
  424.         
  425.         if (this.NotUndefined(ret) && this.NotUndefined(ret.range))
  426.         {
  427.             selection.removeAllRanges();
  428.             //this.RebuildSelection(win, ret.range);
  429.             if (this.NotUndefined(curRange))
  430.             {
  431.                 this.RebuildSelection(win, curRange);
  432.  
  433.                 if(searchUpward)
  434.                     selection.collapseToStart();
  435.                 else
  436.                     selection.collapseToEnd();
  437.             }
  438.             
  439.             try{      
  440.                 bFound = win.find(ret.keyword, matchCase, searchUpward, false, false, false, false);
  441.             }
  442.             catch(e)
  443.             {
  444.                 //alert(e);
  445.             }
  446.         }
  447.         this.EmptyArray(results);
  448.         results = null;
  449.         return ret;
  450.     
  451.     },
  452.     FindNearestKeywordsIE: function(direction, flag, currentDoc)
  453.     {
  454.         var results = [];
  455.         for (var i = 0; i < avtFindingVar.keywordsArray.length; i++)
  456.         {
  457.             var keywords = avtFindingVar.keywordsArray[i];
  458.             var textRangeCopy = currentDoc.parentWindow["textRange"].duplicate();
  459.             bFound = textRangeCopy.findText(keywords, direction, flag);
  460.             if (bFound)
  461.                 results.push({"textRange": textRangeCopy, "keyword": keywords});
  462.             else
  463.                 delete textRangeCopy;
  464.         }
  465.         var miniPosIdx = 0;
  466.         var ret = null;
  467.         if (results.length >= 1)
  468.         {
  469.             for (var i = 1; i < results.length; i++)
  470.             {
  471.                 if (direction > 0)
  472.                 {
  473.                     if (results[miniPosIdx].textRange.compareEndPoints("StartToStart", results[i].textRange) == 1)
  474.                         miniPosIdx = i;
  475.                 }
  476.                 else
  477.                 {
  478.                     if (results[miniPosIdx].textRange.compareEndPoints("EndToEnd", results[i].textRange) == -1)
  479.                         miniPosIdx = i;
  480.                 }
  481.             }
  482.             ret = {"textRange": results[miniPosIdx].textRange, "keyword": results[miniPosIdx].keyword};
  483.         }
  484.         else
  485.             ret = null;
  486.         this.EmptyArray(results);
  487.         results = null;
  488.         return ret;
  489.     },
  490.     PosNearestKeywords: function(text)
  491.     {
  492.         var tmpText = text;
  493.         if (avtFindingVar.isIgnoreCase)
  494.             tmpText = tmpText.toLowerCase();
  495.         var results = [];
  496.         for (var i = 0; i < avtFindingVar.keywordsArray.length; i++)
  497.         {
  498.             var pos = tmpText.indexOf(avtFindingVar.keywordsArray[i]);
  499.             var styleIdx = i % avtFindingVar.color.length;
  500.             results.push({"pos": pos, "keyword": avtFindingVar.keywordsArray[i], "styleIdx": styleIdx});
  501.         }
  502.         var miniPosIdx = 0;
  503.         var ret = null;
  504.         if (results.length > 1)
  505.         {
  506.             for (var i = 1; i < results.length; i++)
  507.             {
  508.                 if (results[miniPosIdx].pos === -1)
  509.                     miniPosIdx = i;
  510.                 else if ((results[miniPosIdx].pos > results[i].pos) && (results[i].pos >= 0))
  511.                     miniPosIdx = i;
  512.             }
  513.             ret = {"pos": results[miniPosIdx].pos, "keyword": results[miniPosIdx].keyword, "styleIdx": results[miniPosIdx].styleIdx};
  514.         }
  515.         else
  516.             ret = {"pos": results[0].pos, "keyword": results[0].keyword, "styleIdx": results[0].styleIdx};
  517.         this.EmptyArray(results);
  518.         results = null;
  519.         return ret;
  520.     },
  521.     DressUp: function(obj, styleIdx)
  522.     {
  523.         var color = avtFindingVar.color[styleIdx];
  524.         var bgColor = avtFindingVar.bkColor[styleIdx];
  525.         if (!avtBrowserInfo.isIE)
  526.             obj.style.display = "inline-block";
  527.         obj.style.marginLeft = "0px";
  528.         obj.style.marginRight = "0px";
  529.         obj.style.marginTop = "0px";
  530.         obj.style.marginBottom = "0px";
  531.         obj.style.paddingLeft = "0px";
  532.         obj.style.paddingTop = "0px";
  533.         obj.style.paddingRight = "0px";
  534.         obj.style.paddingBottom = "0px";
  535.         obj.style.width = "auto";
  536.         obj.style.height = "auto";
  537.         obj.style.color = color;
  538.         obj.style.textIndent = "0px";
  539.         obj.style.backgroundColor = bgColor;
  540.     },
  541.     FindInDoc: function(currentDoc, direction, isFirstFind)
  542.     {
  543.         var bFound = false;
  544.         var matchCase = !avtFindingVar.isIgnoreCase;
  545.         avtFindingVar.currentFindDoc = currentDoc;
  546.         if (avtBrowserInfo.browserID !== 0)
  547.         {
  548.             if (this.GetWindow().find)
  549.             {
  550.                 var searchUpward = false;
  551.                 if (direction > 0)
  552.                     searchUpward = false;
  553.                 else
  554.                     searchUpward = true;
  555.                 var win = currentDoc.defaultView;
  556.                 var ret = this.FindNearestKeywords(win, matchCase, searchUpward);
  557.                 if (this.NotUndefined(ret))
  558.                     bFound = true;
  559.             }
  560.         }
  561.         else
  562.         {
  563.             if (currentDoc.body && currentDoc.body.createTextRange)
  564.             {
  565.                 if (this.Undefined(currentDoc.parentWindow["textRange"]) || (isFirstFind))
  566.                 {
  567.                     currentDoc.parentWindow["textRange"] = currentDoc.body.createTextRange();
  568.                     currentDoc.parentWindow["textRange"].setEndPoint("EndToStart", currentDoc.parentWindow["textRange"]);
  569.                 }
  570.                 else
  571.                 {
  572.                     currentDoc.parentWindow["textRange"].execCommand("UnSelect", true, "");
  573.                     if (direction > 0)
  574.                         currentDoc.parentWindow["textRange"].setEndPoint("StartToEnd", currentDoc.parentWindow["textRange"]);
  575.                     else
  576.                         currentDoc.parentWindow["textRange"].setEndPoint("EndToStart", currentDoc.parentWindow["textRange"]);
  577.                 }
  578.                 var flag = 0;
  579.                 if (matchCase)
  580.                     flag = flag + 4;
  581.                 if (direction <= 0)
  582.                     flag = flag + 1;
  583.                 var ret = this.FindNearestKeywordsIE(direction, flag, currentDoc);
  584.                 if (this.NotUndefined(ret) && this.NotUndefined(ret.textRange))
  585.                 {
  586.                     bFound = true;
  587.                     currentDoc.parentWindow["textRange"] = ret.textRange;
  588.                     currentDoc.parentWindow["textRange"].select();
  589.                 }
  590.             }
  591.         }
  592.         return bFound;
  593.     },
  594.     HasBodyTag: function(doc)
  595.     {
  596.         var oBodyList = doc.getElementsByTagName("body");
  597.         if (this.Undefined(oBodyList))
  598.             return false;
  599.         else if (oBodyList.length <= 0)
  600.             return false;
  601.         else if (oBodyList[0].tagName.toLowerCase() === "frameset")
  602.             return false;
  603.         else
  604.             return true;
  605.     },
  606.     ResetFindCursor: function()
  607.     {
  608.         var doc = this.GetDocument();
  609.         if (avtBrowserInfo.isIE)
  610.         {
  611.             doc.parentWindow["textRange"] = null;
  612.       if(avtFindingVar.Recursive)
  613.       {
  614.         while (this.NotUndefined(doc))
  615.         {
  616.           doc = this.FindNextDoc(doc, 1);
  617.           while (this.NotUndefined(doc) && this.Undefined(doc.body))
  618.             doc = this.FindNextDoc(doc, 1);
  619.           if (this.NotUndefined(doc) && this.NotUndefined(doc.body))
  620.           {
  621.             doc.parentWindow["textRange"] = null;
  622.           }
  623.           else
  624.             break;
  625.         }
  626.       }
  627.         }
  628.         else
  629.         {
  630.             this.ClearSelection(doc);
  631.             if(avtFindingVar.Recursive)
  632.             {
  633.                 while (this.NotUndefined(doc))
  634.                 {
  635.                     doc = this.FindNextDoc(doc, 1);
  636.                     while (this.NotUndefined(doc) && this.Undefined(doc.body))
  637.                         doc = this.FindNextDoc(doc, 1);
  638.                     if (this.NotUndefined(doc) && this.NotUndefined(doc.body))
  639.                     {
  640.                         this.ClearSelection(doc);
  641.                     }
  642.                     else
  643.                         break;
  644.                 }
  645.             }
  646.         }
  647.         avtFindingVar.currentFindDoc = null;
  648.     },
  649.     ClearSelection: function(doc)
  650.     {
  651.         if (this.NotUndefined(doc) && this.NotUndefined(doc.defaultView))
  652.         {
  653.             var s = doc.defaultView.getSelection();
  654.       if(this.NotUndefined(s))
  655.         s.removeAllRanges();
  656.         }
  657.     },
  658.     Find: function(keywords, isFindAsSentence, direction, matchCase, isFirstFind)
  659.     {
  660.         avtFindingVar.isFindAsSentence = isFindAsSentence;
  661.  
  662.         avtFindingVar.isIgnoreCase = !matchCase;
  663.         if (avtFindingVar.isIgnoreCase)
  664.             avtFindingVar.keywords = keywords.toLowerCase();
  665.         else
  666.             avtFindingVar.keywords = keywords;
  667.         //prepare keywords array
  668.         if (!isFindAsSentence)
  669.             this.SplitKeywordsBySpace();
  670.         else
  671.         {
  672.             this.EmptyArray(avtFindingVar.keywordsArray);
  673.             avtFindingVar.keywordsArray.push(avtFindingVar.keywords);
  674.         }
  675.  
  676.         var bFound = false;
  677.         var currentDoc = this.GetDocument();
  678.         //remove all textranges
  679.         if (isFirstFind == true)
  680.         {
  681.             this.ResetFindCursor();
  682.         }
  683.         else if (this.NotUndefined(avtFindingVar.currentFindDoc))
  684.             currentDoc = avtFindingVar.currentFindDoc;
  685.  
  686.         var bFound = this.FindInDoc(currentDoc, direction, isFirstFind);
  687.         if(avtFindingVar.Recursive)
  688.         {
  689.             while (!bFound)
  690.             {
  691.                 currentDoc = this.FindNextDoc(currentDoc, direction);
  692.  
  693.                 while (this.NotUndefined(currentDoc) && (!this.HasBodyTag(currentDoc)))
  694.                     currentDoc = this.FindNextDoc(currentDoc, direction);
  695.  
  696.                 if (this.NotUndefined(currentDoc) && this.HasBodyTag(currentDoc))
  697.                 {
  698.                     bFound = this.FindInDoc(currentDoc, direction, isFirstFind);
  699.                 }
  700.                 else
  701.                     break;
  702.             }
  703.         }
  704.         return bFound;
  705.     },
  706.     Highlight: function(keywords, isFindAsSentence, isIgnoreCase)
  707.     {
  708.         avtFindingVar.isFindAsSentence = isFindAsSentence;
  709.         avtFindingVar.isIgnoreCase = isIgnoreCase;
  710.         if (isIgnoreCase)
  711.             avtFindingVar.keywords = keywords.toLowerCase();
  712.         else
  713.             avtFindingVar.keywords = keywords;
  714.         if (!isFindAsSentence)
  715.             this.SplitKeywordsBySpace();
  716.         else
  717.         {
  718.             this.EmptyArray(avtFindingVar.keywordsArray);
  719.             avtFindingVar.keywordsArray.push(avtFindingVar.keywords);
  720.         }
  721.     
  722.         var currentDoc = this.GetDocument();
  723.         avtFindingVar.matchCount = 0;
  724.         this.HighlightInDoc(currentDoc);
  725.         if(avtFindingVar.Recursive)
  726.         {
  727.             while (this.NotUndefined(currentDoc))
  728.             {
  729.                 currentDoc = this.FindNextDoc(currentDoc, 1);
  730.                 while (this.NotUndefined(currentDoc) && this.Undefined(currentDoc.body))
  731.                 currentDoc = this.FindNextDoc(currentDoc, 1);
  732.                 if (this.NotUndefined(currentDoc) && this.NotUndefined(currentDoc.body))
  733.                 {
  734.                     this.HighlightInDoc(currentDoc);
  735.                 }
  736.                 else
  737.                     break;
  738.             }
  739.         }
  740.         return avtFindingVar.matchCount;
  741.     },
  742.     HighlightInNode: function(node, currentDoc)
  743.     {
  744.         if (this.Undefined(node))
  745.             return 0;
  746.         if (node.hasChildNodes)
  747.         {
  748.             for (var i = 0; i < node.childNodes.length; i++)
  749.             {
  750.                 if (this.HighlightInNode(node.childNodes[i], currentDoc) == 1)
  751.                     i++;
  752.             }
  753.         }
  754.         if (node.nodeType == 3)
  755.         {
  756.             var text = this.GetTransformedValue(node);
  757.             var findResult = this.PosNearestKeywords(text);
  758.             if (findResult.pos !== -1)
  759.             {
  760.                 var nv = node.nodeValue;
  761.                 var ni = findResult.pos;
  762.  
  763.                 var before = currentDoc.createTextNode(nv.substr(0, ni));
  764.  
  765.                 var docWordVal = nv.substr(ni, findResult.keyword.length);
  766.                 var after = currentDoc.createTextNode(nv.substr(ni + findResult.keyword.length));
  767.  
  768.                 var hiwordtext = currentDoc.createTextNode(docWordVal);
  769.                 var hiword = currentDoc.createElement(avtFindingVar.tagName);
  770.                 hiword.id = "avantTag_" + avtFindingVar.matchCount;
  771.                 hiword.appendChild(hiwordtext);
  772.                 this.DressUp(hiword, findResult.styleIdx);
  773.                 var pn = node.parentNode;
  774.                 before = pn.insertBefore(before, node);
  775.                 hiword = pn.insertBefore(hiword, node);
  776.                 this.markAvantTag(hiword);
  777.                 after = pn.insertBefore(after, node);
  778.                 pn.removeChild(node);
  779.                 avtFindingVar.matchCount++;
  780.                 return 1;
  781.             }
  782.         }
  783.         return 0;
  784.     },
  785.     HighlightInDoc: function(currentDoc)
  786.     {
  787.         var pn = null;
  788.         var fromPos = 0;
  789.         pn = currentDoc.body;
  790.         fromPos = 0;
  791.         var matchCount = 0;
  792.         if (this.NotUndefined(pn) && (pn.hasChildNodes))
  793.         {
  794.             for (var i = fromPos; i < pn.childNodes.length; i++)
  795.             {
  796.                 if (this.HighlightInNode(pn.childNodes[i], currentDoc) == 1)
  797.                     i++;
  798.             }
  799.         }
  800.         return matchCount;
  801.     },
  802.     UnHighlight: function()
  803.     {
  804.         var currentDoc = this.GetDocument();
  805.         var matchCount = this.UnHighlightInDoc(currentDoc);
  806.     try
  807.     {
  808.       if(avtFindingVar.Recursive)
  809.       {
  810.         while (this.NotUndefined(currentDoc))
  811.         {
  812.           currentDoc = this.FindNextDoc(currentDoc, 1);
  813.           while (this.NotUndefined(currentDoc) && this.Undefined(currentDoc.getElementsByTagName("body")))
  814.             currentDoc = this.FindNextDoc(currentDoc, 1);
  815.           if (this.NotUndefined(currentDoc) && this.NotUndefined(currentDoc.body))
  816.           {
  817.             matchCount += this.UnHighlightInDoc(currentDoc);
  818.           }
  819.           else
  820.             break;
  821.         }
  822.       }
  823.     }
  824.     catch (e) {
  825.             //alert("unhighlight:" + e);
  826.         }
  827.  
  828.         for (var i = 0; i < avtFindingVar.avantTagArray.length; i++)
  829.         {
  830.             var pn = avtFindingVar.avantTagArray[i].parentNode;
  831.             pn.removeChild(avtFindingVar.avantTagArray[i]);
  832.         }
  833.         this.EmptyArray(avtFindingVar.avantTagArray);
  834.         avtFindingVar.matchCount = 0;
  835.         this.ResetFindCursor();
  836.         return matchCount;
  837.     },
  838.     GetNodeValue: function(node)
  839.     {
  840.         var nodeValue = "";
  841.         if (this.NotUndefined(node))
  842.         {
  843.             if (this.NotUndefined(node.nodeValue))
  844.                 nodeValue = node.nodeValue;
  845.             else
  846.                 nodeValue = node.innerHTML;
  847.         }
  848.         return nodeValue;
  849.     },
  850.     SetNodeValue: function(node, value)
  851.     {
  852.         if (this.NotUndefined(node))
  853.         {
  854.             if (node.nodeType == 3)
  855.                 node.nodeValue = value;
  856.             else
  857.                 node.innerHTML = value;
  858.         }
  859.  
  860.     },
  861.     UnHighlightNode: function(node)
  862.     {
  863.         var matchCount = 0;
  864.         if (node.hasChildNodes)
  865.         {
  866.       try
  867.       {
  868.         for (var i = 0; i < node.childNodes.length; i++)
  869.           matchCount += this.UnHighlightNode(node.childNodes[i]);
  870.       }
  871.       catch(e)
  872.       {
  873.         //alert(e);
  874.       }
  875.         }
  876.         if (node.nodeType == 3) {
  877.             var pn = node.parentNode;
  878.             if (this.isAvantTag(pn))
  879.             {
  880.         try{
  881.                 avtFindingVar.avantTagArray.push(pn);
  882.                 var pnValue = "";
  883.                 {
  884.                     var prevSib = pn.previousSibling;
  885.                     var nextSib = pn.nextSibling;
  886.                     nextSib.nodeValue = prevSib.nodeValue + node.nodeValue + nextSib.nodeValue;
  887.                     prevSib.nodeValue = '';
  888.                     node.nodeValue = '';
  889.                 }
  890.                 matchCount++;
  891.         }
  892.         catch(e)
  893.         {
  894.           //alert(e);
  895.         }
  896.             }
  897.         }
  898.         return  matchCount;
  899.     },
  900.     UnHighlightInDoc: function(currentDoc)
  901.     {
  902.         var pn = null;
  903.         var matchCount = 0;
  904.         pn = currentDoc.body;
  905.         if (avtBrowserInfo.isIE && this.NotUndefined(currentDoc.parentWindow) && this.NotUndefined(currentDoc.parentWindow["textRange"]))
  906.         {
  907.             currentDoc.parentWindow["textRange"].setEndPoint("StartToEnd", currentDoc.parentWindow["textRange"]);
  908.             currentDoc.parentWindow["textRange"].execCommand("UnSelect", false, "");
  909.             currentDoc.parentWindow["textRange"] = null;
  910.         }
  911.         matchCount = this.UnHighlightNode(pn);
  912.         return matchCount;
  913.     },
  914.     GetTextTransform: function(obj)
  915.     {
  916.         var textTransform = "";
  917.         if (this.NotUndefined(obj))
  918.         {
  919.             if (avtBrowserInfo.isIE)
  920.             {
  921.                 if (this.NotUndefined(obj.currentStyle))
  922.                 {
  923.                     if (this.NotUndefined(obj.currentStyle.textTransform))
  924.                         textTransform = obj.currentStyle.textTransform;
  925.                 }
  926.             }
  927.             else
  928.             {
  929.                 var win = obj.ownerDocument.defaultView;
  930.                 if (this.NotUndefined(win))
  931.                 {
  932.                     var style = win.getComputedStyle(obj);
  933.                     if (this.NotUndefined(style))
  934.                     {
  935.                         if (this.NotUndefined(style.textTransform))
  936.                             textTransform = style.textTransform;
  937.                     }
  938.                 }
  939.             }
  940.         }
  941.         if (this.Undefined(textTransform))
  942.             textTransform = "";
  943.         textTransform = textTransform.toLowerCase();
  944.         return textTransform;
  945.     },
  946.     GetTransformedValue: function(textNode)
  947.     {
  948.         var pn = textNode.parentNode;
  949.         while (this.NotUndefined(pn))
  950.         {
  951.             if (pn.nodeType == 3)
  952.                 pn = pn.parentNode;
  953.             else
  954.                 break;
  955.         }
  956.         if (this.Undefined(pn))
  957.         {
  958.             return textNode.value;
  959.         }
  960.         else
  961.         {
  962.             var textTransform = this.GetTextTransform(pn);
  963.             if (textTransform === "lowercase")
  964.                 return textNode.nodeValue.toLowerCase();
  965.             else if (textTransform === "uppercase")
  966.                 return textNode.nodeValue.toUpperCase();
  967.             else
  968.                 return textNode.nodeValue;
  969.         }
  970.     }
  971. };
  972.  
  973. function avtHighlight(keywords, ARecursive)
  974. {
  975.   if(avtUtility.Undefined(ARecursive))
  976.     ARecursive = true;
  977.   avtFindingVar.Recursive = ARecursive;
  978.   try{
  979.  
  980.     keywords = unescape(keywords).replace(/^\s+|\s+$/g, "");
  981.     avtUtility.UnHighlight(ARecursive);
  982.  
  983.     var matchCount = avtUtility.Highlight(keywords, false, true, ARecursive);
  984.  
  985.     if (avtBrowserInfo.isIE)
  986.     {
  987.       if (matchCount > 0)
  988.         window.external.TextFound;
  989.       return "0";
  990.     }
  991.   
  992.     if(matchCount > 0)
  993.       return "1";
  994.     else
  995.       return "0";
  996.   }
  997.   catch(e)
  998.   {
  999.     //alert(e);
  1000.     return "0";
  1001.   }
  1002. }
  1003.  
  1004. function avtFind(keywords, isFindAsSentence, matchCase, direction, isFirstFind, ARecursive)
  1005. {
  1006.   if(avtUtility.Undefined(ARecursive))
  1007.     ARecursive = true;
  1008.   avtFindingVar.Recursive = ARecursive;
  1009.   
  1010.   var bFound = false;
  1011.     keywords = unescape(keywords).replace(/^\s+|\s+$/g, "");
  1012.     if (avtUtility.Undefined(isFirstFind))
  1013.         isFirstFind = false;
  1014.   if(!matchCase)
  1015.     keywords = keywords.toLowerCase();
  1016.   if (keywords !== avtFindingVar.keywords)
  1017.       isFirstFind = true;
  1018.   if (isFirstFind)
  1019.       avtUtility.ResetFindCursor();
  1020.   if (avtFindingVar.notFoundKeywords === keywords)
  1021.   {
  1022.     isFindAsSentence = false;
  1023.         bFound = avtUtility.Find(keywords, isFindAsSentence, direction, matchCase, isFirstFind);
  1024.   }
  1025.   else
  1026.   {
  1027.     bFound = avtUtility.Find(keywords, isFindAsSentence, direction, matchCase, isFirstFind);
  1028.     if(isFirstFind && (direction < 0) && (!bFound) )
  1029.     {
  1030.       var nFound = 0;
  1031.       while(true)
  1032.       {
  1033.         bFound = avtUtility.Find(keywords, isFindAsSentence, 1, matchCase, false);
  1034.         if(bFound == false)
  1035.           break;
  1036.         else 
  1037.           nFound ++;
  1038.       }
  1039.       if(nFound > 0)
  1040.         bFound = true;
  1041.     }
  1042.     if (isFindAsSentence && !bFound)
  1043.     {
  1044.       if (isFirstFind)
  1045.       {
  1046.         avtFindingVar.notFoundKeywords = keywords;
  1047.         avtUtility.ResetFindCursor();
  1048.         isFindAsSentence = false;
  1049.         bFound = avtUtility.Find(keywords, isFindAsSentence, direction, matchCase, isFirstFind);
  1050.       }
  1051.     }
  1052.   }
  1053.  
  1054.   if (bFound)
  1055.     avtFindingVar.lastFoundKeywords = keywords;
  1056.   else
  1057.   {        
  1058.     if (avtFindingVar.lastFoundKeywords == keywords)
  1059.     {
  1060.       if(direction > 0)
  1061.       {
  1062.         avtFindingVar.matchCount = 0;
  1063.         avtUtility.ResetFindCursor();
  1064.         bFound = avtUtility.Find(keywords, isFindAsSentence, direction, matchCase, true);
  1065.       }
  1066.       else
  1067.       {
  1068.         while(true)
  1069.         {
  1070.           bFound = avtUtility.Find(keywords, isFindAsSentence, 1, matchCase, isFirstFind);
  1071.           if(bFound == false)
  1072.             break;
  1073.         }
  1074.         bFound = true;
  1075.       }
  1076.     } 
  1077.   }
  1078.   
  1079.   if (avtBrowserInfo.isIE)
  1080.   {
  1081.     if (bFound)
  1082.       window.external.TextFound;
  1083.     return "0";
  1084.   }
  1085.   
  1086.   if(bFound)
  1087.     return "1";
  1088.   else
  1089.     return "0";
  1090. }