/*	autocomplete_better.js
	----------------------
	genereer uitklaplijst met woorden.
	zie kopje Variables - deze kunnen eventueel overruled worden bij een body-onload,
	bijv. door actb_firstText op false te zetten zodat op delen van woorden gezocht wordt

	1. voorbeeld aanroep ZONDER volledige woordenlijst (woordenlijst gedefinieerd in array arrWords

		<input
			style='width:70px; border-right:none; height:18px;'
			type='text'
			name='contactlabel{$formdata['contactid'][$i]}'
			value='(Dial code)'
			AUTOCOMPLETE='off'
			onfocus='if (!actb_display) this.select();'
			onkeydown='actb_checkkey(event,actb_lim)'
			onkeyup=\x22actb_tocomplete(this,event,arrDialCodes)\x22
			onblur=\x22if (!actb_mouse_on_list) { actb_removedisp(this); actb_validate_result(this,arrDialCodes,'(Dial code)'); document.objform.contactdata{$formdata['contactid'][$i]}a1.value = this.value.replace(/[^0-9\-]/g, ''); }\x22
			onchange=\x22if (!actb_mouse_on_list) { actb_validate_result(this, arrDialCodes, '(Dial code)'); document.objform.contactdata{$formdata['contactid'][$i]}a1.value = this.value.replace(/[^0-9\-]/g, ''); fchange(1,'address'); }\x22
		>

	2. voorbeeld aanroep MET volledige woordenlijst (woordenlijst gedefinieerd in array arrWords

		<input
			onkeydown='actb_checkkey(event,actb_lim)'
			onkeyup='actb_tocomplete(this,event,arrWords)'
			onclick='if (!actb_display) actb_listAll(this,event,arrWords)'
			onfocus='if (!actb_display) this.select()'
			onblur='if (!actb_mouse_on_list) actb_removedisp(this)'
			onchange=\x22fchange(1,'identification')\x22
			style='width:100%; height:18px; background:#fff url(gfx/search12x12.gif) right center no-repeat;'
			type='text'
			id='title'
			name='title'
			value=\"{$formdata['title']}\"
			AUTOCOMPLETE='off'
		>

*/


/* ---- Variables ---- */
var actb_timeOut 	= -1;	// Autocomplete Timeout in ms (-1: autocomplete never time out)
var actb_lim 		= -1;	// Number of elements autocomplete can show (-1: no limit)
var actb_maxHeight	= 150;	// maximum height of autocomplete-box in pixels (-1: no limit)
var actb_firstText 	= true; // should the auto complete be limited to the beginning of keyword? (true | false)
var actb_mouse 		= true; // Enable Mouse Support
var actb_matchWidth	= true;	// if true, make width of lookup-list same as parent-field
var actb_tabIsEnter = true;	// if true, a tab acts like pressing enter: the selected item in the list will be chosen

/* ---- Variables ---- */

/* --- Styles --- */
var actb_bgColor 	= '#ffffff'; 	//'#ffffff';
var actb_textColor 	= '#000000';	//'#2020a0';
var actb_hColor 	= '#e0e8f0'; 	//'#2020a0';
var actb_thColor 	= '#2020a0'; 	//'#2020a0'; '#FFFFFF';
var actb_fFamily 	= 'Arial';
var actb_fSize 		= '11px'; 		//'12px';
var actb_hStyle 	= 'font-weight:bold';
var actb_indentStyle= 'margin-left:4px; padding-left:6px; background:url(gfx/lir2.gif) left top no-repeat;';

/* --- Styles --- */

/* ---- Constants ---- */
var actb_keywords 		= new Array();	// hierin komt lijst met keywords welke wordt opgegeven bij aanroepen van actb_tocomplete()
var actb_display 		= false;		// deze bool houdt bij of uitklaplijst momenteel getoond wordt of niet
var actb_pos 			= 0;
var actb_total 			= 0;
var actb_curr 			= null;			// hierin wordt object-referentie naar input-veld geplaatst
var actb_rangeu 		= 0;
var actb_ranged 		= 0;
var actb_bool 			= new Array();	// hierin komt lijst met bools welke woorden wel en welke niet in lijst moeten komen. lijst strookt met actb_keywords()
var actb_pre 			= 0;			// index van te highlighten woord in uitklaplijst. stel deze in alvorens actb_generate() aan te roepen, en zet daarbij actb_tomake op true
var actb_tomake 		= false;		// indien op false, dan wordt 1e woord in uitklaplijst gehighlight in actb_generate()
var actb_mouse_on_list	= false; //true;
var actb_toid;
var actb_regexp_indent	= new RegExp(/^([\t\>]+)/);	// regexp voor woorden in actb_keywords() die beginnen met tab of > teken: deze krijgen een inspringing. handig voor maken van visuele hierarchie

//var actb_item_clicked = false;
//var actb_tid_focus;

/* ---- Functions ---- */

// ============================================================
// genereer HTML voor 1 woord in de uitklaplijst met 'matching' woorden, waarbij het matching gedeelte vh woord vetgedrukt wordt
// aangeroepen door actb_generate() en actb_remake()
// ============================================================

function actb_parse(n){
	//var t = actb_curr.value.replace("'","\'");
	//t = t.replace('"','\"'); //.replace(/[\-\+\\\.]/g, '');

	// check of woord begint met > of tab, zoja, laat deze dan inspringen
	var indentWord = n.match(actb_regexp_indent);
	if (indentWord) {
		n = n.replace(actb_regexp_indent, '');
		//indentWord = "<span title='"+indentWord[1].length+"' style='padding-left:" + (indentWord[1].length * 5).toString() + "px;'>";
		indentWord = "<div style='" + actb_indentStyle + "'>";
	} else {
		indentWord = '';
	}

	var t = actb_curr.value.replace(/([^0-9a-z ])/gi, '\\$1');
	var tobuild = '';
	var i;
	var dicky = 0;

	// match alleen op begin van woord of ook op deel in woord?
	if (actb_firstText){
		// match alleen op beginletter van woord
		var re = new RegExp("^" + t, "i");
		var re2 = false;
	}else{
		// match op elk deel in woord
		//var re = new RegExp(t, "i");
		//top.document.title = t;
		var re = new RegExp("^" + t, "i");
		var re2 = new RegExp("[ /]" + t, "i"); // stel input is "UK" dan matchen ook "GB/UK" en "GB UK"
	}
	var p = n.search(re);

	if (p == -1 && re2) {
		p = n.search(re2);
		dicky = 1;
	}

//alert(n + ': ' + p);

	if (p != -1) {
		for (i=0;i<p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "<span style='"+(actb_hStyle)+"'>";
		for (i=p;i<t.length+p+dicky;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "</span>";
		for (i=t.length+p+dicky;i<n.length;i++){
			tobuild += n.substr(i,1);
		}
	} else {
		tobuild = n;
	}

	if (indentWord.length) tobuild = indentWord + tobuild + '</div>';

	return tobuild;
}

// ============================================================
// geef absolute positie op van een relatief element
// curPos('x') geeft x-positie op, curPos('y') geef y-positie
// ============================================================

function curPos(mode){
	actb_toreturn = 0;
	var obj = actb_curr;
	while(obj){
		actb_toreturn += (mode == 'x') ? obj.offsetLeft : obj.offsetTop;
		obj = obj.offsetParent;
	}
	return actb_toreturn;
}

// ============================================================
// genereer nieuwe autocomplete-lijst. wordt aangeroepen door actb_tocomplete()
// ============================================================

function actb_generate(actb_bool){
	var d = document.getElementById('tat_div');
	if (!d) {
		d = document.createElement('div');
		d.id = 'tat_div';
		d.onmouseover = actb_table_focus;
		d.onmouseout= actb_table_unfocus;
		d.onmousedown = actb_field_focus;
		//d.onscroll = actb_field_focus;
		//d.mouseup = actb_field_focus;

		document.body.appendChild(d);
	}

	d.style.visibility = 'hidden';

	if (document.getElementById('tat_table')) d.removeChild(document.getElementById('tat_table'));
	a = document.createElement('table');
	//actb_layout_table(d, a);
	a.id = 'tat_table';
    if (actb_mouse){
        a.onmouseover = actb_table_focus;
        a.onmouseout= actb_table_unfocus;
    }
	d.appendChild(a);
//alert('hello');
	var i;
	var first = true;
	var j = 1;

	var counter = 0;
	for (i=0;i<actb_keywords.length;i++){

		// nieuwe rij?
		if (actb_bool[i]){
			counter++;
			r = a.insertRow(-1);
			if (first && !actb_tomake){
				actb_highlight(r,1);
				first = false;
				actb_pos = counter;
				hl=1;
			}else if(actb_pre == i){
				actb_highlight(r,1);
				first = false;
				actb_pos = counter;
				hl=1;
			}else{
				actb_highlight(r,0);
				hl=0;
			}
			r.id = 'tat_tr'+(j);
			c = r.insertCell(-1);
			c.style.padding		= "2px";
			c.style.color 		= (hl ? actb_thColor : actb_textColor);
			c.style.fontFamily 	= actb_fFamily;
			c.style.fontSize 	= actb_fSize;
			c.style.cursor		= "default";
			c.innerHTML 		= actb_parse(actb_keywords[i]);
			c.id = 'tat_td'+(j);
			if (actb_mouse) {
				c.onmouseover=actb_mouseover;
				c.onmouseout=actb_mouseout;
				c.onclick=actb_mouseclick;
			}
			j++;
		}

		// maak arrow-down knopje?
		if (j - 1 == actb_lim && j < actb_total){
			r = a.insertRow(-1);
			actb_highlight(r,0);
			i = document.createElement('img');
			i.src = "gfx/down.gif";
			c = r.insertCell(-1);
			c.align				='center';
			c.style.textAlign	='center';
			c.style.padding 	="2px";
			//c.style.cursor		="hand";
			c.appendChild(i);
			if (actb_mouse){
				// user klikt op scrolldown-knopje
				//c.onclick = actb_mouse_down;
			}
			break;
		}
	}
	actb_rangeu = 1;
	actb_ranged = j-1;
	actb_display = true;
	//actb_tid_focus = setInterval("focusfucker()", 100);
	if (actb_pos <= 0) actb_pos = 1;

	// toon de uiteindelijke 'autocomplete' box
	actb_layout_table(d, a, counter); //if (counter>0) d.style.visibility = 'visible';
	//alert(actb_curr.value);
	//actb_curr.select();
}

// ============================================================
// update lijst (deze functie wordt alleen aangeroepen indien actb_lim != -1 oftewel als lijst gelimiteerd wordt)
// ============================================================

function actb_remake(){
//alert('yo');
	var d = document.getElementById('tat_div');
	if (!d) {
		d = document.createElement('div');
		d.id = 'tat_div';
		d.onmouseover = actb_table_focus;
		d.onmouseout= actb_table_unfocus;
		d.onmousedown = actb_field_focus;
		//d.onscroll = actb_field_focus;
		//d.mouseup = actb_field_focus;
		document.body.appendChild(d);
	}
	d.style.visibility = 'hidden';

	d.removeChild(document.getElementById('tat_table'));
	a = document.createElement('table');
	//actb_layout_table(d, a);
	a.id = 'tat_table';
    if (actb_mouse){
        a.onmouseover = actb_table_focus;
        a.onmouseout= actb_table_unfocus;
    }
	d.appendChild(a);
	var i;
	var first = true;
	var j = 1;
	if (actb_rangeu > 1){
/*
		r = a.insertRow(-1);
		actb_highlight(r,0);
		c = r.insertCell(-1);
		c.style.color = actb_textColor;
		//c.style.fontFamily = 'arial narrow';
		c.style.fontSize = actb_fSize;
		c.align='center';
		c.innerHTML = '/\\';
		if (actb_mouse){
			c.onclick = actb_mouse_up;
		}
*/
	}

	var counter = 0;
	for (i=0;i<actb_keywords.length;i++){
		if (actb_bool[i]){
			// maak nieuwe rij?
			if (j >= actb_rangeu && j <= actb_ranged){
				counter++;
				r = a.insertRow(-1);
				actb_highlight(r,0);
				r.id = 'tat_tr'+(j);
				c = r.insertCell(-1);
				c.style.padding 	= "2px";
				c.style.color 		= actb_textColor;
				c.style.fontFamily 	= actb_fFamily;
				c.style.fontSize 	= actb_fSize;
				c.style.cursor		= "default";
				c.innerHTML = actb_parse(actb_keywords[i]);
				c.id = 'tat_td'+(j);
				if (actb_mouse) {
					c.onmouseover=actb_mouseover;
					c.onmouseout=actb_mouseout;
					c.onclick=actb_mouseclick;
				}
				j++;
			}else{
				j++;
			}
		}
		if (j > actb_ranged) break;
	}
	// maak arrow-down-knopje?
	if (j-1 < actb_total){
		r = a.insertRow(-1);
		actb_highlight(r,0);
		i = document.createElement('img');
		i.src = "gfx/down.gif";
		c = r.insertCell(-1);
		c.align				= 'center';
		c.style.textAlign	= 'center';
		c.style.padding 	= "2px";
		//c.style.cursor		="hand";
		c.appendChild(i);
		if (actb_mouse){
			// user klikt op scrolldown-knopje
			//c.onclick = actb_mouse_down;
		}
	}

	// toon de uiteindelijke 'autocomplete' box
	actb_layout_table(d, a, counter); //d.style.visibility = 'visible';
}

function actb_goup(){
	if (!actb_display) return;
	if (actb_pos == 1) return;
	actb_highlight(document.getElementById('tat_tr'+actb_pos),0);
	actb_pos--;
	if (actb_pos < actb_rangeu) actb_moveup();
	actb_highlight(document.getElementById('tat_tr'+actb_pos),1);
	actb_scrollIntoView(document.getElementById('tat_tr'+actb_pos));

	if (actb_toid) clearTimeout(actb_toid);
	if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
}

function actb_godown(){
	if (!actb_display) return;
//alert('hier? ' + actb_pos);
	if (actb_pos == actb_total) return;
	actb_highlight(document.getElementById('tat_tr'+actb_pos),0);
	actb_pos++;
	if (actb_pos > actb_ranged) actb_movedown();
	actb_highlight(document.getElementById('tat_tr'+actb_pos),1);
	actb_scrollIntoView(document.getElementById('tat_tr'+actb_pos));

	if (actb_toid) clearTimeout(actb_toid);
	if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
}

// ============================================================
// user drukt cursor-up
// ============================================================

function actb_movedown(){
	actb_rangeu++;
	actb_ranged++;
	actb_remake();
}

// ============================================================
// user drukt cursor-down
// ============================================================

function actb_moveup(){
	actb_rangeu--;
	actb_ranged--;
	actb_remake();
}

/* Mouse */

// ============================================================
// user klikt op scrolldown-knop
// ============================================================

function actb_mouse_down(){
	actb_highlight(document.getElementById('tat_tr'+actb_pos), 0);
	actb_pos++;
	actb_movedown();
	actb_highlight(document.getElementById('tat_tr'+actb_pos),1);
	actb_curr.focus();
	actb_moue_on_list = 0;
	if (actb_toid) clearTimeout(actb_toid);
	if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
}

// ============================================================
// user klikt item in lijst aan (TD in TABLE)
// ============================================================

function actb_mouseclick(){
//alert('klik');
	if (!actb_display) return;
	//actb_item_clicked = true;
	actb_mouse_on_list = 0;
	actb_display = 0;
	//clearInterval(actb_tid_focus);
	actb_curr.value = (document.all ? this.innerText : this.textContent); // Firefox Fixed: this.textContent
	//alert(this.innerText);
	actb_removedisp();

	// indien de functie fchange() bestaat, probeer wijziging te registreren
	if (typeof(fchange) == 'function') tryCode("fchange(1,'')", false);
}

function actb_mouseover(){
	//window.status = actb_pos
	if (this.parentNode.rowIndex == actb_pos-1) return;
	actb_highlight(this.parentNode,1);
}
function actb_mouseout(){
	//window.status = actb_pos
	if (this.parentNode.rowIndex == actb_pos-1) return;
	actb_highlight(this.parentNode,0);
}

function actb_table_focus(){
//top.document.title='Focussed :)';
	actb_mouse_on_list = 1;
}
function actb_table_unfocus(){
//top.document.title='Unfocussed :(';
	actb_mouse_on_list = 0;
	if (actb_toid) clearTimeout(actb_toid);
	if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
}

// ============================================================
// user heeft op enter gedrukt in input-field:
// kies highlighted item in uitklaplijst, kopieer deze naar inputfield en verberg uitklaplijst
// ============================================================

function actb_penter(){
	actb_mouse_on_list = 0;	// muis is niet meer op lijst: moet gezet worden om box weg te halen
	if (!actb_display) return;
	actb_display = 0;
	//clearInterval(actb_tid_focus);
	var word = '';
	var c = 0;
	for (var i=0;i<=actb_keywords.length;i++){
		if (actb_bool[i]) c++;
		if (c == actb_pos){
			word = actb_keywords[i].replace(actb_regexp_indent, '');
			break;
		}
	}
	a = word;//actb_keywords[actb_pos-1];//document.getElementById('tat_td'+actb_pos).;
	if (a.length) actb_curr.value = a;
	actb_removedisp();

	// indien de functie fchange() bestaat, probeer wijziging te registreren
	if (typeof(fchange) == 'function') tryCode("fchange(1,'')", false);
}

// ============================================================
// haal autocomplete-uitklaplijst weg
// aanroep: <input onblur='if (!actb_mouse_on_list) actb_removedisp(this)'>
// ============================================================

function actb_removedisp(){
//alert('away');
//alert(actb_mouse_on_list);
	if (!actb_mouse_on_list) {
		//alert('weg ermee!!');
		actb_display = 0;
		//clearInterval(actb_tid_focus);
		if (document.getElementById('tat_table')) {
			document.getElementById('tat_div').removeChild(document.getElementById('tat_table'));
			document.getElementById('tat_div').style.visibility = 'hidden';
		}
		if (actb_toid) clearTimeout(actb_toid);
	}
}

// ============================================================
// input onkeydown aanroep:
// registreer welke toets is ingedrukt en kies welke actie daarbij past
// aanroep: <input onkeydown='actb_checkkey(event,actb_lim)'>
// ============================================================

function actb_checkkey(evt,listlen){
	if (listlen) actb_lim = listlen;// limiteer aantal items
	a = evt.keyCode;
	if (a == 38) { 					// arrow-up key
		actb_goup();
	} else if (a == 40) { 			// arrow-down key
		actb_godown();
	} else if (a == 9){				// tab: wel of geen autocomplete afhankelijk van actb_tabIsEnter configuratie
		if (actb_tabIsEnter) {
			actb_penter();
		} else {
			actb_table_unfocus();
		}
	} else if (a == 9 || a == 13) {	// enter: wel autocomplete
		actb_penter();
	}
}

// ============================================================
// input onkeyup aanroep:
// prepareer lijst met woorden die matchen bij input-value mbv regular expressions
// aanroep: <input onkeyup='actb_tocomplete(this,event,arrWords)'>
// ============================================================

function actb_tocomplete(sndr,evt,arr){
	//actb_curr.focus();
	//alert(eval(arr));
	//return;
	//alert(typeof eval(arr));
	//return;
	if (arr) actb_keywords = arr;

	// geen lijst genereren indien arrow-up/down of enter toets is aangeslagen
	if (evt.keyCode == 38 || evt.keyCode == 40 || evt.keyCode == 13) return;

	var i, curWord;
	if (actb_display){
		var word = 0;
		var c = 0;
		for (i=0;i<=actb_keywords.length;i++){
			if (actb_bool[i]) c++;
			if (c == actb_pos){
				word = i;
				break;
			}
		}
		actb_pre = word;//actb_pos;
	} else {
		actb_pre = -1;
	}

	if (!sndr) var sndr = evt.srcElement;
	actb_curr = sndr;
	//actb_curr.focus();

	// verberg lijst indien geen tekstveld leeg is
	if (sndr.value == ''){
		actb_removedisp();
		return;
	}
	//var t = sndr.value.replace("'","\'");
	//t = t.replace('"','\"'); //.replace(/[\+\\\.\-]/g, '');
var t = sndr.value.replace(/([^0-9a-z ])/gi, '\\$1');

	if (actb_firstText){
		var re = new RegExp("^" + t, "i");
var re2 = false;
	}else{
		//var re = new RegExp(t, "i");
var re = new RegExp("^" + t, "i");
var re2 = new RegExp("[ /]" + t, "i");	// stel input is "UK" dan matchen ook "GB/UK" en "GB UK"
	}

	actb_total = 0;
	actb_tomake = false;
	for (i=0;i<actb_keywords.length;i++){
		actb_bool[i] = false;
		curWord = actb_keywords[i].replace(actb_regexp_indent, '');
		if (re.test(curWord) || (re2 && re2.test(curWord))){
			actb_total++;
			actb_bool[i] = true;
			if (actb_pre == i) actb_tomake = true;
		}
	}
	if (actb_toid) clearTimeout(actb_toid);
	if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);

//setTimeout("top.document.title = actb_curr.value; actb_curr.focus()", 200);

	// genereer nieuwe autocomplete-lijst
	actb_generate(actb_bool);
}

// ============================================================
// highlight woord/rij in de woordenlijst
// ============================================================

function actb_highlight(obj,hl) {
	if (hl) {
		obj.style.backgroundColor = actb_hColor;
		if (obj.childNodes.length) {
			for (i=0; i<obj.childNodes.length;i++) obj.childNodes[i].style.color = actb_thColor;
		}
	} else {
		obj.style.backgroundColor = actb_bgColor;
		if (obj.childNodes.length) {
			for (i=0; i<obj.childNodes.length;i++) obj.childNodes[i].style.color = actb_textColor;
		}
	}
}

// ============================================================
// positioneer en formatteer de uitklaplijst (nadat deze is gegenereerd)
// ============================================================

function actb_layout_table(objDiv, objTable, numItems) {
	if (!numItems) return;

//alert(getElement('tat_table'));
	if (actb_matchWidth) objDiv.style.width = (actb_curr.offsetWidth) + 'px';
	if (actb_maxHeight > 0 && objTable.offsetHeight > actb_maxHeight) {
		objDiv.style.height = actb_maxHeight + 'px';
		objDiv.style.overflowY = 'auto';
		//objDiv.scrollTop = 5;
		//objDiv.style.width = (objTable.offsetWidth + 20) + 'px';
	} else {
		objDiv.style.height = 'auto';
		objDiv.style.overflowY = 'visible';
	}

	if (actb_matchWidth) objTable.style.width = '100%';
	objTable.cellSpacing='0px';
	objTable.cellPadding='2px';

	//objDiv.style.visibility = 'hidden';
	objDiv.style.position='absolute';
	objDiv.style.zIndex='2';
	objDiv.style.top = eval(1 + curPos('y') + actb_curr.offsetHeight) + "px";
	objDiv.style.left = curPos('x') + "px";
	objDiv.style.backgroundColor=actb_bgColor;
	objDiv.style.border = "1px solid #000000";
	objDiv.style.visibility = 'visible';
}

// ============================================================
// check of waarde van tekstveld in lijst voorkomt, zoniet vervang dan door default-value
// ============================================================

function actb_validate_result(obj, arr, defValue) {
	if (!inArray(arr, obj.value)) {
		obj.value = defValue.length ? defValue : arr[0];
	}
	return obj.value;
}

function actb_field_focus() {
	//alert('yo');
	//actb_curr.blur();
	//setTimeout('actb_curr.blur()', 50);
	setTimeout('actb_curr.focus()', 50);
}

// ============================================================
// positioneer item in uitklaplijst dusdanig dat deze in beeld (viewport van DIV) komt dmv scrollen van parent-div
// ============================================================

function actb_scrollIntoView(obj) {
	var vpScrTop = getElement('tat_div').scrollTop;
	var vpHeight = getElement('tat_div').offsetHeight;
	var iTop     = obj.offsetTop;
	var iBottom  = iTop + obj.offsetHeight;
	if (iBottom > vpHeight) {
		getElement('tat_div').scrollTop = iBottom - vpHeight;
	} else if (iTop < vpScrTop) {
		getElement('tat_div').scrollTop = iTop;
	}
	//top.document.title = 'scrollTop: ' + vpScrTop + ' / itemTop: ' + iTop;
}

// ============================================================
// toon volledig lijst van alle keywords
// aanroep: <input onclick='if (!actb_display) actb_listAll(this,event,arrWords)'>
// NB: dit is een optionele functie die bij input-onclick de volledig lijst toont, maar mag weggelaten worden indien geen behoefte aan volledige lijst
// ============================================================

function actb_listAll(sndr,evt,arr) {
	if (!sndr) var sndr = evt.srcElement;
	actb_curr 		= sndr;		// input-object
	actb_pre 		= -1;		// vooralsnog komt waarde in tekstveld niet in keywords-lijst voor dus hebben we geen index voor selected word
	actb_tomake 	= false;	// zorg ervoor dat in actb_generate() het eerste woord in keywords-lijst highlight
	actb_total 		= 0;		// teller voor aantal woorden
	actb_keywords	= arr;		// lijst met woorden

	// loop door woordenlijst en schakel ze allemaal aan in de array actb_bool
	for (var i=0; i<actb_keywords.length;i++){
		actb_bool[i] = true;
		actb_total++;

		// komt waarde uit tekstveld voor in woordenlijst? zorg er dan voor dat actb_generate() dit woord highlight!
		if (actb_curr.value.toLowerCase() == actb_keywords[i].replace(actb_regexp_indent, '').toLowerCase()) {
			actb_pre = i;
			actb_tomake = true;
		}
	}

	// genereer nieuwe autocomplete-lijst
	actb_generate(actb_bool);

	// scroll highlighted item in beeld
	if (actb_pre != -1) {

		var colH = getElement('tat_div').offsetHeight;
		var sclH = getElement('tat_div').scrollHeight;
		var yOff = getElement('tat_td'+(actb_pre+1)).offsetTop;

//alert(colH + ' : ' + sclH);
//alert(getElement('tat_td'+actb_pre).innerHTML);
		// heeft deze kolom een scrollbar? zoja positioneer selected item dan item beeld
		if (sclH>colH) {
			getElement('tat_div').scrollTop = Math.round(yOff - colH/2.5);	// centreer rij in vertikaal in midden
		}

	}
}

