function actba(objx,cax){
	/* ---- Public Variables ---- */
	this.actba_timeOut = -1; // Autocomplete Timeout in ms (-1: autocomplete never time out)
	this.actba_lim = 6000;    // Number of elements autocomplete can show (-1: no limit)
	this.actba_firstText = false; // should the auto complete be limited to the beginning of keyword?
	this.actba_mouse = true; // Enable Mouse Support
	this.actba_delimiter = new Array(';',',');  // Delimiter for multiple autocomplete. Set it to empty array for single autocomplete
	this.actba_startcheck = 3; // Show widget only after this number of characters is typed in.
	/* ---- Public Variables ---- */

	/* --- Styles --- */
	this.actba_bgColor = '#888888'; 
	this.actba_textColor = '#FFFFFF'; 
	this.actba_hColor = '#000000';
	this.actba_fFamily = 'Verdana';
	this.actba_fSize = '12px';
	this.actba_hStyle = 'text-decoration:underline;font-weight="bold"';
	/* --- Styles --- */

	/* ---- Private Variables ---- */
	var actba_delimwords = new Array();
	var actba_cdelimword = 0;
	var actba_delimchar = new Array();
	var actba_display = false;
	var actba_pos = 0;
	var actba_total = 0;
	var actba_curr = null;
	var actba_rangeu = 0;
	var actba_ranged = 0;
	var actba_bool = new Array();
	var actba_pre = 0;
	var actba_toid;
	var actba_tomake = false;
	var actba_getpre = "";
	var actba_mouse_on_list = 1;
	var actba_kwcount = 0;
	var actba_caretmove = false;
	this.actba_keywords = new Array();
	/* ---- Private Variables---- */
	
	this.actba_keywords = cax;
	var actba_self = this;

	actba_curr = objx;
	
	addEvent(actba_curr,"focus",actba_setup);
	function actba_setup(){
		addEvent(document,"keydown",actba_checkkey);
		addEvent(actba_curr,"blur",actba_clear);
		addEvent(document,"keypress",actba_keypress);
		/*return form.submit();*/
	}

	function actba_clear(evt){
		if (!evt) evt = event;
		removeEvent(document,"keydown",actba_checkkey);
		removeEvent(actba_curr,"blur",actba_clear);
		removeEvent(document,"keypress",actba_keypress);
		actba_removedisp();
	}
	function actba_parse(n){
		if (actba_self.actba_delimiter.length > 0){
			var t = actba_delimwords[actba_cdelimword].trim().addslashes();
			var plen = actba_delimwords[actba_cdelimword].trim().length;
		}else{
			var t = actba_curr.value.addslashes();
			var plen = actba_curr.value.length;
		}
		var tobuild = '';
		var i;

		if (actba_self.actba_firstText){
			var re = new RegExp("^" + t, "i");
		}else{
			var re = new RegExp(t, "i");
		}
		var p = n.search(re);
				
		for (i=0;i<p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "<font style='"+(actba_self.actba_hStyle)+"'>"
		for (i=p;i<plen+p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "</font>";
			for (i=plen+p;i<n.length;i++){
			tobuild += n.substr(i,1);
		}
		return tobuild;
	}
	function actba_generate(){
		if (document.getElementById('tat_table')){ actba_display = false;document.body.removeChild(document.getElementById('tat_table')); } 
		if (actba_kwcount == 0){
			actba_display = false;
			return;
		}
		a = document.createElement('table');
		a.cellSpacing='1px';
		a.cellPadding='2px';
		a.style.position='absolute';
		a.style.top = eval(curTop(actba_curr) + actba_curr.offsetHeight) + "px";
		a.style.left = curLeft(actba_curr) + "px";
		a.style.backgroundColor=actba_self.actba_bgColor;
		a.id = 'tat_table';
		document.body.appendChild(a);
		var i;
		var first = true;
		var j = 1;
		if (actba_self.actba_mouse){
			a.onmouseout = actba_table_unfocus;
			a.onmouseover = actba_table_focus;
		}
		var counter = 0;
		for (i=0;i<actba_self.actba_keywords.length;i++){
			if (actba_bool[i]){
				counter++;
				r = a.insertRow(-1);
				if (first && !actba_tomake){
					r.style.backgroundColor = actba_self.actba_hColor;
					first = false;
					actba_pos = counter;
				}else if(actba_pre == i){
					r.style.backgroundColor = actba_self.actba_hColor;
					first = false;
					actba_pos = counter;
				}else{
					r.style.backgroundColor = actba_self.actba_bgColor;
				}
				r.id = 'tat_tr'+(j);
				c = r.insertCell(-1);
				c.style.color = actba_self.actba_textColor;
				c.style.fontFamily = actba_self.actba_fFamily;
				c.style.fontSize = actba_self.actba_fSize;
				c.innerHTML = actba_parse(actba_self.actba_keywords[i]);
				c.id = 'tat_td'+(j);
				c.setAttribute('pos',j);
				if (actba_self.actba_mouse){
					c.style.cursor = 'pointer';
					c.onclick=actba_mouseclick;
					c.onmouseover = actba_table_highlight;
				}
				j++;
			}
			if (j - 1 == actba_self.actba_lim && j < actba_total){
				r = a.insertRow(-1);
				r.style.backgroundColor = actba_self.actba_bgColor;
				c = r.insertCell(-1);
				c.style.color = actba_self.actba_textColor;
				c.style.fontFamily = 'arial narrow';
				c.style.fontSize = actba_self.actba_fSize;
				c.align='center';
				replaceHTML(c,'\\/');
				if (actba_self.actba_mouse){
					c.style.cursor = 'pointer';
					c.onclick = actba_mouse_down;
				}
				break;
			}
		}
		actba_rangeu = 1;
		actba_ranged = j-1;
		actba_display = true;
		if (actba_pos <= 0) actba_pos = 1;
	}
	function actba_remake(){
		document.body.removeChild(document.getElementById('tat_table'));
		a = document.createElement('table');
		a.cellSpacing='1px';
		a.cellPadding='2px';
		a.style.position='absolute';
		a.style.top = eval(curTop(actba_curr) + actba_curr.offsetHeight) + "px";
		a.style.left = curLeft(actba_curr) + "px";
		a.style.backgroundColor=actba_self.actba_bgColor;
		a.id = 'tat_table';
		if (actba_self.actba_mouse){
			a.onmouseout= actba_table_unfocus;
			a.onmouseover=actba_table_focus;
		}
		document.body.appendChild(a);
		var i;
		var first = true;
		var j = 1;
		if (actba_rangeu > 1){
			r = a.insertRow(-1);
			r.style.backgroundColor = actba_self.actba_bgColor;
			c = r.insertCell(-1);
			c.style.color = actba_self.actba_textColor;
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actba_self.actba_fSize;
			c.align='center';
			replaceHTML(c,'/\\');
			if (actba_self.actba_mouse){
				c.style.cursor = 'pointer';
				c.onclick = actba_mouse_up;
			}
		}
		for (i=0;i<actba_self.actba_keywords.length;i++){
			if (actba_bool[i]){
				if (j >= actba_rangeu && j <= actba_ranged){
					r = a.insertRow(-1);
					r.style.backgroundColor = actba_self.actba_bgColor;
					r.id = 'tat_tr'+(j);
					c = r.insertCell(-1);
					c.style.color = actba_self.actba_textColor;
					c.style.fontFamily = actba_self.actba_fFamily;
					c.style.fontSize = actba_self.actba_fSize;
					c.innerHTML = actba_parse(actba_self.actba_keywords[i]);
					c.id = 'tat_td'+(j);
					c.setAttribute('pos',j);
					if (actba_self.actba_mouse){
						c.style.cursor = 'pointer';
						c.onclick=actba_mouseclick;
						c.onmouseover = actba_table_highlight;
					}
					j++;
				}else{
					j++;
				}
			}
			if (j > actba_ranged) break;
		}
		if (j-1 < actba_total){
			r = a.insertRow(-1);
			r.style.backgroundColor = actba_self.actba_bgColor;
			c = r.insertCell(-1);
			c.style.color = actba_self.actba_textColor;
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actba_self.actba_fSize;
			c.align='center';
			replaceHTML(c,'\\/');
			if (actba_self.actba_mouse){
				c.style.cursor = 'pointer';
				c.onclick = actba_mouse_down;
			}
		}
	}
	function actba_goup(){
		if (!actba_display) return;
		if (actba_pos == 1) return;
		document.getElementById('tat_tr'+actba_pos).style.backgroundColor = actba_self.actba_bgColor;
		actba_pos--;
		if (actba_pos < actba_rangeu) actba_moveup();
		document.getElementById('tat_tr'+actba_pos).style.backgroundColor = actba_self.actba_hColor;
		if (actba_toid) clearTimeout(actba_toid);
		if (actba_self.actba_timeOut > 0) actba_toid = setTimeout(function(){actba_mouse_on_list=0;actba_removedisp();},actba_self.actba_timeOut);
	}
	function actba_godown(){
		if (!actba_display) return;
		if (actba_pos == actba_total) return;
		document.getElementById('tat_tr'+actba_pos).style.backgroundColor = actba_self.actba_bgColor;
		actba_pos++;
		if (actba_pos > actba_ranged) actba_movedown();
		document.getElementById('tat_tr'+actba_pos).style.backgroundColor = actba_self.actba_hColor;
		if (actba_toid) clearTimeout(actba_toid);
		if (actba_self.actba_timeOut > 0) actba_toid = setTimeout(function(){actba_mouse_on_list=0;actba_removedisp();},actba_self.actba_timeOut);
	}
	function actba_movedown(){
		actba_rangeu++;
		actba_ranged++;
		actba_remake();
	}
	function actba_moveup(){
		actba_rangeu--;
		actba_ranged--;
		actba_remake();
	}

	/* Mouse */
	function actba_mouse_down(){
		document.getElementById('tat_tr'+actba_pos).style.backgroundColor = actba_self.actba_bgColor;
		actba_pos++;
		actba_movedown();
		document.getElementById('tat_tr'+actba_pos).style.backgroundColor = actba_self.actba_hColor;
		actba_curr.focus();
		actba_mouse_on_list = 0;
		if (actba_toid) clearTimeout(actba_toid);
		if (actba_self.actba_timeOut > 0) actba_toid = setTimeout(function(){actba_mouse_on_list=0;actba_removedisp();},actba_self.actba_timeOut);
	}
	function actba_mouse_up(evt){
		if (!evt) evt = event;
		if (evt.stopPropagation){
			evt.stopPropagation();
		}else{
			evt.cancelBubble = true;
		}
		document.getElementById('tat_tr'+actba_pos).style.backgroundColor = actba_self.actba_bgColor;
		actba_pos--;
		actba_moveup();
		document.getElementById('tat_tr'+actba_pos).style.backgroundColor = actba_self.actba_hColor;
		actba_curr.focus();
		actba_mouse_on_list = 0;
		if (actba_toid) clearTimeout(actba_toid);
		if (actba_self.actba_timeOut > 0) actba_toid = setTimeout(function(){actba_mouse_on_list=0;actba_removedisp();},actba_self.actba_timeOut);
	}
	function actba_mouseclick(evt){
		if (!evt) evt = event;
		if (!actba_display) return;
		actba_mouse_on_list = 0;
		actba_pos = this.getAttribute('pos');
		actba_penter();
	}
	function actba_table_focus(){
		actba_mouse_on_list = 1;
	}
	function actba_table_unfocus(){
		actba_mouse_on_list = 0;
		if (actba_toid) clearTimeout(actba_toid);
		if (actba_self.actba_timeOut > 0) actba_toid = setTimeout(function(){actba_mouse_on_list = 0;actba_removedisp();},actba_self.actba_timeOut);
	}
	function actba_table_highlight(){
		actba_mouse_on_list = 1;
		document.getElementById('tat_tr'+actba_pos).style.backgroundColor = actba_self.actba_bgColor;
		actba_pos = this.getAttribute('pos');
		while (actba_pos < actba_rangeu) actba_moveup();
		while (actba_pos > actba_ranged) actba_movedown();
		document.getElementById('tat_tr'+actba_pos).style.backgroundColor = actba_self.actba_hColor;
		if (actba_toid) clearTimeout(actba_toid);
		if (actba_self.actba_timeOut > 0) actba_toid = setTimeout(function(){actba_mouse_on_list = 0;actba_removedisp();},actba_self.actba_timeOut);
	}
	/* ---- */

	function actba_insertword(a){
		if (actba_self.actba_delimiter.length > 0){
			str = '';
			l=0;
			for (i=0;i<actba_delimwords.length;i++){
				if (actba_cdelimword == i){
					prespace = postspace = '';
					gotbreak = false;
					for (j=0;j<actba_delimwords[i].length;++j){
						if (actba_delimwords[i].charAt(j) != ' '){
							gotbreak = true;
							break;
						}
						prespace += ' ';
					}
					for (j=actba_delimwords[i].length-1;j>=0;--j){
						if (actba_delimwords[i].charAt(j) != ' ') break;
						postspace += ' ';
					}
					str += prespace;
					str += a;
					l = str.length;
					if (gotbreak) str += postspace;
				}else{
					str += actba_delimwords[i];
				}
				if (i != actba_delimwords.length - 1){
					str += actba_delimchar[i];
				}
			}
			actba_curr.value = str;
			setCaret(actba_curr,l);
		}else{
			actba_curr.value = a;
		}
		actba_mouse_on_list = 0;
		actba_removedisp();
	}
	function actba_penter(){
		if (!actba_display) return;
		actba_display = false;
		var word = '';
		var c = 0;
		for (var i=0;i<=actba_self.actba_keywords.length;i++){
			if (actba_bool[i]) c++;
			if (c == actba_pos){
				word = actba_self.actba_keywords[i];
				break;
			}
		}
		actba_insertword(word);
		l = getCaretStart(actba_curr);
	}
	function actba_removedisp(){
		if (actba_mouse_on_list==0){
			actba_display = 0;
			if (document.getElementById('tat_table')){ document.body.removeChild(document.getElementById('tat_table')); }
			if (actba_toid) clearTimeout(actba_toid);
		}
	}
	function actba_keypress(e){
		if (actba_caretmove) stopEvent(e);
		return !actba_caretmove;
	}
	function actba_checkkey(evt){
		if (!evt) evt = event;
		a = evt.keyCode;
		caret_pos_start = getCaretStart(actba_curr);
		actba_caretmove = 0;
		switch (a){
			case 38:
				actba_goup();
				actba_caretmove = 1;
				return false;
				break;
			case 40:
				actba_godown();
				actba_caretmove = 1;
				return false;
				break;
			case 13: case 9:
				if (actba_display){
					actba_caretmove = 1;
					actba_penter();
					return false;
				}else{
					return true;
				}
				break;
			default:
				setTimeout(function(){actba_tocomplete(a)},50);
				break;
		}
	}

	function actba_tocomplete(kc){
		if (kc == 38 || kc == 40 || kc == 13) return;
		var i;
		if (actba_display){ 
			var word = 0;
			var c = 0;
			for (var i=0;i<=actba_self.actba_keywords.length;i++){
				if (actba_bool[i]) c++;
				if (c == actba_pos){
					word = i;
					break;
				}
			}
			actba_pre = word;
		}else{ actba_pre = -1};
		
		if (actba_curr.value == ''){
			actba_mouse_on_list = 0;
			actba_removedisp();
			return;
		}
		if (actba_self.actba_delimiter.length > 0){
			caret_pos_start = getCaretStart(actba_curr);
			caret_pos_end = getCaretEnd(actba_curr);
			
			delim_split = '';
			for (i=0;i<actba_self.actba_delimiter.length;i++){
				delim_split += actba_self.actba_delimiter[i];
			}
			delim_split = delim_split.addslashes();
			delim_split_rx = new RegExp("(["+delim_split+"])");
			c = 0;
			actba_delimwords = new Array();
			actba_delimwords[0] = '';
			for (i=0,j=actba_curr.value.length;i<actba_curr.value.length;i++,j--){
				if (actba_curr.value.substr(i,j).search(delim_split_rx) == 0){
					ma = actba_curr.value.substr(i,j).match(delim_split_rx);
					actba_delimchar[c] = ma[1];
					c++;
					actba_delimwords[c] = '';
				}else{
					actba_delimwords[c] += actba_curr.value.charAt(i);
				}
			}

			var l = 0;
			actba_cdelimword = -1;
			for (i=0;i<actba_delimwords.length;i++){
				if (caret_pos_end >= l && caret_pos_end <= l + actba_delimwords[i].length){
					actba_cdelimword = i;
				}
				l+=actba_delimwords[i].length + 1;
			}
			var ot = actba_delimwords[actba_cdelimword].trim(); 
			var t = actba_delimwords[actba_cdelimword].addslashes().trim();
		}else{
			var ot = actba_curr.value;
			var t = actba_curr.value.addslashes();
		}
		if (ot.length == 0){
			actba_mouse_on_list = 0;
			actba_removedisp();
		}
		if (ot.length < actba_self.actba_startcheck) return this;
		if (actba_self.actba_firstText){
			var re = new RegExp("^" + t, "i");
		}else{
			var re = new RegExp(t, "i");
		}

		actba_total = 0;
		actba_tomake = false;
		actba_kwcount = 0;
		for (i=0;i<actba_self.actba_keywords.length;i++){
			actba_bool[i] = false;
			if (re.test(actba_self.actba_keywords[i])){
				actba_total++;
				actba_bool[i] = true;
				actba_kwcount++;
				if (actba_pre == i) actba_tomake = true;
			}
		}

		if (actba_toid) clearTimeout(actba_toid);
		if (actba_self.actba_timeOut > 0) actba_toid = setTimeout(function(){actba_mouse_on_list = 0;actba_removedisp();},actba_self.actba_timeOut);
		actba_generate();
	}
	return this;
	
}
