Searching for a string in a web page I have written the below code to search for a string in a web page. This is working fine but I need suggestions on improving this code to start using this. This is written to work under IE.

$(document).ready(function() 
{
var NotFounds = [];
function countString(s) {
  var re = new RegExp(s, 'gi');
  var text = document.body.createTextRange().text;
  var matches = text.replace(/\s+/g, ' ').match(re);
  return matches? matches.length : 0;
}
// This function is the Sentence search function.
function doSearch(tex) {
    if (document.body.createTextRange) {
        var textRange = document.body.createTextRange();
        textRange.collapse(true);
        if(textRange.findText(tex)) {
            countString(tex) &gt; 1 ? textRange.execCommand("BackColor", false, "#FF6600") : textRange.execCommand("BackColor", false, "yellow");
            textRange.collapse(false);
        }
        else
        {
            NotFounds.push(tex);
        }
    }
}
function trim(value) {
    var temp = value;
    var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
    if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
    var obj = / +/g;
    temp = temp.replace(obj, " ");
    if (temp == " ") { temp = ""; }
    return temp;
 }
function SearchQueue(text)
 {
    if(text !== null) 
    {
        if($('#NotFounds').size() &gt; 0)
        {
            $('#NotFounds').detach();
        }
        text = text.replace(/^\s*$[\n\r]{1,}/gm, '');
        text = text.replace(/”/g, "\"");
        text = text.replace(/“/g, "\"");
        text = text.replace(/”/g, "\"");
        text = text.replace(/’/g, "\'");
        text = text.replace(/‘/g, "\'");
        text = text.replace(/–/g, "\-");
        text = text.replace(/—/g, "\-");
        text = text.replace(/–/g, "\-");
        var txt1=text;
        text = trim(txt1);
        var SearchItems = text.split(/\r\n|\r|\n/);
        document.designMode = "on";
        for(var i=0;i&lt;SearchItems.length;i++)
        {
            var textTrim = $.trim(SearchItems[i]);
            doSearch(textTrim);
        }
        document.designMode = "off";
        if(NotFounds.length &gt; 0)
        {
            var st = "&lt;center&gt;&lt;b&gt;Mismatched texts are...&lt;/b&gt;&lt;/center&gt;";
            for(var k=0;k&lt;NotFounds.length;k++)
            {
                st = st + "&lt;br&gt;Mismatch "+ (k+1) + ". &lt;span style='color:blue'&gt;" + NotFounds[k] + "&lt;/span&gt;";
            }
            st = st + "&lt;/font&gt;";
            $('body').prepend('&lt;div id="NotFounds" style="width:100%;border:1px solid gray"&gt;&lt;/div&gt;');
            $('#NotFounds').html(st);
            alert("Some items are mismatched... Please check at the top of the page.");
        }
    }
  }
var body = $('body');
var OrigBody = body.html();
$('body').dblclick(function() {
    var txt = window.clipboardData.getData("Text");
    var ClipText = txt.replace(/[a-zA-Z0-9\?\&amp;\=\%\#]+s\=(\w+)(\&amp;.*)?/,"$1");
    if ($.browser.msie) {
        NotFounds = [];         
        SearchQueue(ClipText.replace(/\%20|\+/g,"\|"));
    }
});
shortcut.add("Ctrl+Z",function() {
    body.html(OrigBody);
  });
shortcut.add("Up",function() {
    $('b,i,u,sup,sub,strong,font,a').wrap('&lt;font style="color:blue"&gt;&lt;/font&gt;');
  });
shortcut.add("Right",function() {
     $('table').filter(function() { return ($(this).find('input').size() &gt; 0); }).find('tr').each(function()
    {
        $(this).find('input').filter(function(){
            return (Math.round(Math.random()) == 1);
        }).each(function()
        {
            switch(this.type) {
                case 'checkbox':
                case 'radio':
                    this.checked = true;
                        break;
                case 'password':
                case 'select-multiple':
                case 'select-one':
                case 'text':
                case 'textarea':
                    $(this).val('2');
                        break;
            }
        });
    });
    $('#forwardbutton').trigger('click');
});
 });
Instead of wrapping your code in $(document).ready(function(){, you should put the &lt;script&gt; tag at the bottom of file ( right before closing &lt;/body&gt; ), then you script will get executed right after the DOM is ready.
Do not use innerHTML for working with DOM
Stop selecting DOM element each time you want to do something with it. It is an expensive operation. Instead get the element once and store in a variable.
Your trim() method initializes obj twice.
Do not use .length in loops. Instead assign value to variable and reuse it.


And, honestly, get rid of jQuery. You are not using for anything special. Only simple DOM manipulations.