function autocomplete( textBoxId, containerDivId ) {
    var ac = this;
    this.textbox    = document.getElementById(textBoxId);
    this.div        = document.getElementById(containerDivId);
    this.list       = this.div.getElementsByTagName('div');
    this.pointer    = null;
	

    this.textbox.onkeydown = function( e ) {
        e = e || window.event;
        switch( e.keyCode ) {
            case 38: //up
                ac.selectDiv(-1);
                break;
            case 40: //down
                ac.selectDiv(1);
                break;
        }
    }

    this.selectDiv = function( inc ) {
        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					= this.list[this.pointer].dir;
			
			url									= this.list[this.pointer].title;
			document.zoeken.action				= url;
        }
        if( this.pointer === null ) {
            this.pointer = 0;
            this.list[this.pointer].className = 'active';
            this.textbox.value = this.list[this.pointer].dir;
			
			url									= this.list[this.pointer].title;
			document.zoeken.action				= url;
        }
    }
} 

new autocomplete( 'q', 'livesearch' );
