var obMatch;						/* Object containing match */
var reSearch;						/* Search regular expression */


function VisitNodeFirst(ob)
{
    if (ob.nodeType == 3) {				/* If text node */
	if (ob.nodeValue.search(reSearch) >= 0) {	/* If match found */
	    do {					/* Loop to find element */
		ob = ob.parentNode;			/* Go to parent */
	    } while (ob.nodeType != 1);			/* Loop until element node found */
	    obMatch = ob;				/* Remember match */
	    return false;				/* Stop search */
	}
    }
    return true;					/* Keep going */
}


function WalkTree(obRoot, vf, vl)
{
    var fUp;						/* Go up flag */
    var ob;						/* Object */

    fUp = false;					/* Clear flag */
    for (ob = obRoot; ob != null; ) {			/* Loop to traverse tree */
	if (!fUp) {					/* If not ascending */
	    if (vf != null && !vf(ob)) {		/* If preorder traversal requestes termination */
		break;					/* Exit loop */
	    }
	    if (ob.firstChild != null) {		/* If there are children */
		ob = ob.firstChild;			/* Go to first child */
		continue;				/* Next node */
	    }
	}
	if (ob.nextSibling != null) {			/* If there are siblings */
	    ob = ob.nextSibling;			/* Go to next sibling */
	    fUp = false;				/* Clear flag */
	    continue;					/* Next node */
	}
	fUp = true;					/* Ascending (don't visit children again) */
	ob = ob.parentNode;				/* Go to parent */
	if ((vl != null && !vl(ob)) || ob == obRoot) {	/* If postorder traversal requests termination or back to root */
	    break;					/* Exit loop */
	}
    }
}


function ScrollToObject(ob)
{
    var h;						/* Height */

    /*
     *  IE provides a nifty function called scrollIntoView() which does
     *  the drudge-work for us; unfortunately, Opera and Mozilla don't.
     */
    h = 0;						/* Initialize */
    for (;;) {						/* Loop to compute height */
	h += ob.offsetTop;				/* Get top of object */
	if (ob.offsetParent == document.body) {		/* If offset relative to document's body */
	    break;					/* Exit loop */
	}
	ob = ob.offsetParent;				/* Get object to which offset is relative */
    }
    window.scrollTo(0, h);				/* Scroll to desired height */
}


function FindText(s)
{
    s = s.replace(/\*/g, "\\w*");			/* Replace asterisks */
    s = s.replace(/ +/g, "\\W+");			/* Replace spaces */
    s = s.replace(/\+/g, "\\W+");			/* Replace pluses */
    s = "\\b".concat(s, "\\b");				/* Add word breaks */
    reSearch = new RegExp(s, "i");			/* Build search expression */
    obMatch = null;					/* Assume no match */
    WalkTree(document.body, VisitNodeFirst, null);	/* Walk the document tree */
    if (obMatch != null) {				/* If we found a match */
	ScrollToObject(obMatch);			/* Scroll it into view */
	return true;					/* Success */
    }
    return false;					/* Not found */
}
