﻿function nascondi(){
document.getElementById('suggerimenti').style.visibility = 'hidden';
}
function nascondisub(){
document.getElementById('suggerimenti').style.visibility = 'hidden';
document.seguro.submit();
}


function boldize(stringa)
{
// var htstring = document.boldo.testo1.value;
var stripped = stringa.replace(/(<([^>]+)>)/ig,"");
return stripped;
}
function sottoponi(collegamento, testo){
document.seguro.action=collegamento;
document.seguro.ricerca.value=boldize(testo);
}


function autocomplete( textBoxId, containerDivId, ricerca ) {
    var ac = this;
    this.textbox     = document.getElementById(textBoxId);
    this.div         = document.getElementById(containerDivId);
    this.list        = this.div.getElementsByTagName('a');
    this.pointer     = null;
    this.textbox.setAttribute("autocomplete", "off");
    
    this.textbox.onkeyup = function( e ) {
        e = e || window.event;
         if(e.keyCode != 40 && e.keyCode != 38 && e.keyCode != 13){
       ac.pointer = null;
       
       document.getElementById('suggerimenti').style.visibility = 'visible';
       
       caricaTesto(ac.textbox.value,'suggerimenti')
       
       }
        switch( e.keyCode ) {
            case 38: //up
                ac.selectDiv(-1);
                
                break;
            case 40: //down
                ac.selectDiv(1);
                
                break;
            case 13: //enter
            break;    
        }
       
    }

    this.selectDiv = function( inc ) {
        if( this.pointer + inc >= this.list.length ) {
        this.list[this.pointer].className = '';
        this.list[0].className = 'active';
        this.pointer = null;
}
        if( this.pointer !== null && this.pointer+inc >= 0 && this.pointer+inc < this.list.length ) {
            this.list[this.pointer].className = '';
            this.pointer += inc;
            this.list[this.pointer].className = 'active';
            this.textbox.value = boldize(this.list[this.pointer].innerHTML);
            document.seguro.action=this.list[this.pointer].href;
            //document.seguro.pointer.value=this.pointer +'-' + this.list.length;
        }
        if( this.pointer === null ) {
            this.pointer = 0;
            this.list[this.pointer].className = 'active';
            this.textbox.value = boldize(this.list[this.pointer].innerHTML);
            document.seguro.action=this.list[this.pointer].href;
            //document.seguro.pointer.value=this.pointer;
        }
    }
} 
