
var stock = new Array();

//検索関数
function exFind(q) {
    for(var i=stock.length-1;i>-1;i--)
	stock[i][0].parentNode.replaceChild(stock[i][1],stock[i][0]);
    stock.length=0;

    q = q.replace(/^\s+|\s+$/g,'');
    if(! q) return;
    exFindSub(document.body);
}

//検索関数(サブ)
function exFindSub(oo) {
    var q = exFind.arguments[0];
    for(var o = oo;o;o=o.nextSibling){
	if(o.nodeType == 3) {
	    var result = o.nodeValue.indexOf(q);
	    if(result >= 0){
		if(stock.length==0 || stock[stock.length-1][0]!=o.parentNode)
		    stock.push([o.parentNode,o.parentNode.cloneNode(true)]);
		if(result)o = o.splitText(result);
		if(q.length != o.nodeValue.length)
		    o.splitText(q.length);
		var span = document.createElement('span');
		span.className = 'FindItem';
		span.appendChild(
				 document.createTextNode(q));
		o.parentNode.replaceChild(span,o);
		o = span;
	    }
	} else if(o.firstChild) exFindSub(o.firstChild);
    }
}
//テスト用
function findWord(o) {
    exFind(o.elements[0].value);
    return false;
}

