var nFind = 0;

function findReset(){
nFind = 0;
}

function findNext(str) {
	var txt, i, found; 
	var IsInternetExplorer,IsGecko;
    if (str == "") return false; 

    if (navigator.userAgent.indexOf('IE') != -1) {
	    IsInternetExplorer = true;
    }
    else if (navigator.userAgent.indexOf('Gecko') != -1) {
	    IsGecko = true;
    }
    else {
	    alert("Funzionalita' non supportata dal browser in uso");
	    return false;
    }

    if (IsGecko) { 
        if (window.find(str)) {
            found = true;
            if ( nFind > 0 ) for (i = 0; i < nFind && (found = window.find(str)) != false; i++) { }
            nFind++; 
            if (!found) { //riavvia la ricerca
                nFind = 0;
                return findInPage(str);
            }
        }
        else 
            nFind=0; 
        if (nFind == 0) {
            alert("Testo non trovato"); 
        }
        return false;
    }

    if (IsInternetExplorer) { 
        txt = window.document.body.createTextRange(); 
        for (i = 0; i <= nFind && (found = txt.findText(str)) != false; i++) { 
            txt.moveStart("character", 1);
            txt.moveEnd("textedit");
        }

        if (found) { // Testo trovato
            txt.moveStart("character", -1); txt.findText(str); 
            txt.select(); 
            txt.scrollIntoView(); 
            nFind++; 
        } 
        else // Testo non trovato
            { 
            if (nFind > 0) { // riavvia la ricerca
                nFind = 0;
                findInPage(str);
            }
            else {
                alert("Testo non trovato"); 
            }
            return false;
        } 
    }
}
