function autocomplete(obj,ca,firstText,startcheck,fetch,fetchName,addColumnWidth){

	/* Added Styles */
	this.actb_BorderWidth = 1;
	this.actb_offsetTop = 16;
	this.actb_BorderColor = '#7F9DB9';
	this.actb_BorderStyle = 'solid';

	/* ---- Public Variables ---- */
	this.actb_timeOut = 10000; // Autocomplete Timeout in ms (-1: autocomplete never time out)
	this.actb_lim = 10;    // Number of elements autocomplete can show (-1: no limit)
	this.actb_firstText = firstText; // should the auto complete be limited to the beginning of keyword?
	this.actb_mouse = true; // Enable Mouse Support
	this.actb_delimiter = new Array(';',',');  // Delimiter for multiple autocomplete. Set it to empty array for single autocomplete
	this.actb_startcheck = startcheck; // Show widget only after this number of characters is typed in.
	this.actb_fetch = fetch; // fetch the values using AJAX?
	this.actb_fetchName = fetchName; // name of the fetch value
	this.actb_fetched = '' // the last prefix fetched
	this.actb_addColumnWidth = addColumnWidth // the width of the additional column (if there are 2 data rows and only one field)



	this.actb_keywords = ca;
	var actb_self = this;



	/* dyodyo added public vars */
	var MultipleId= false;    // this would be set to true if the user spefied multiple Id's
	var actb_curr = null; // the original actb_curr object, I only moved it here
	var actb_curr_arr = null; // the array where the input fields would be stored
	var dyo_boxWidth = 0; // the width of the autosuggest box

	/* dyodyo added START */

	function dyo_UpdateCurr(n){
		/* this function would split the selected autosuggested value by the user
		to fill the input fields that were specified */

		if (MultipleId){
			data=n.replace(/\s?\[[\S\s]*\]/,"").split(',');
			for (idx in actb_curr_arr){
				if (typeof(data[idx]) !='undefined' ) {
					UpdateValues( actb_curr_arr[idx][0], data[idx]) ; //  actb_curr_arr[idx][0].value=data[idx];
				} else  UpdateValues( actb_curr_arr[idx][0], '' ) ;
			}
		} else {
			actb_curr.value=n.replace(/\s?\[[\S\s]*\]/,"");
		}
	}

	function UpdateValues(obj, val) {
		if (obj === null ) {return;}
		if ( (obj.options!=null) && (obj.options.length!=null) ) {
			for (n=0; n<obj.options.length; n++) {
				if (obj.options[n].value.trim()==val.trim())   {
					obj.selectedIndex=n;
					break;
				}
			}
		} else obj.value=val;
	}

	function GetValue(obj) {
		if (obj==null) {  return '';}
		if ( (obj.options!=null) && (obj.options.length!=null) ) {
			return obj.options[obj.selectedIndex].value; //return select box value
		} else return obj.value; // return normal value
	}

	function split_var(){
		nca=this.actb_keywords;
		data = new Array ();
		for (idx in nca) {
			data.push(nca[idx].split(','));
		}
		this.Split_Arr = data;
	}



	/* This function setup the parameters needed to support multi-field autofilling */
	function getTotalWidth () {
		if (MultipleId) {
			l=actb_curr_arr.length;
			s=actb_curr_arr[l-1][2];
			return parseInt((((actb_curr_arr[l-1][1])+parseInt(s.substr(0,s.length-2))-actb_curr_arr[0][1])))+(actb_self.actb_BorderWidth) + 1 +'px'; //calculate total box width
		} else {
			s=actb_curr;
			return  parseInt(s.substr(0,s.length-2))+(actb_self.actb_BorderWidth)+"px";
		}
	}

	function dyo_setup(){
		if (obj.constructor.toString().indexOf("Array") != -1){ // check if the user specified multiple fields
			// yes an array of Object Id's was specified
			actb_curr_arr=new Array();
			dyo_boxWidth=0;
			for (idx in obj){
				//Store the Specified Input Fields in an Array
				var curItem=new Array();
				curItem[0]=document.getElementById(obj[idx]); //the object
				curItem[1]=curLeft(document.getElementById(obj[idx])); //the row location
				curItem[2]=document.getElementById(obj[idx]).style.width; //the object width;

				actb_curr_arr.push(curItem);


			}
			MultipleId=true;
			actb_curr=actb_curr_arr[0][0];

			if (actb_self.actb_addColumnWidth>0){
				lastItem = actb_curr_arr[actb_curr_arr.length-1];
				curItem=new Array();
				curItem[0]=null; //the object
				s=lastItem[2];
				curItem[1]=lastItem[1]+parseInt(s.substr(0,s.length-2)); //the row location
				curItem[2]=(actb_self.actb_addColumnWidth+2)+"px"; //the object width;
				actb_curr_arr.push(curItem);
			}

			l=actb_curr_arr.length;
			s=actb_curr_arr[l-1][2];
			dyo_boxWidth = parseInt((((actb_curr_arr[l-1][1])+parseInt(s.substr(0,s.length-2))-actb_curr_arr[0][1])+0))+(actb_self.actb_BorderWidth * 2)+"px" ; //calculate total box width

		} else {
			// no a single input field was specified
			actb_curr = document.getElementById(obj);
			dyo_boxWidth = actb_curr.style.width ;
		}
	}

	function AlignToFields(tobuild){
		/* this function aligns the matching arguments to the fields
		*/
		var hasBracket = tobuild.match(/\[[\S\s]*\]/g);
		tobuild = tobuild.replace(/\[/,",[");
		//alert(tobuild);
		tbarr=tobuild.split(',');
		dt='<div class="value_container" style="overflow: hidden; border: none;" >';
		j=0; // a counter of how many fields was specified
		totWidth=0;
		prevLeft=-1;
		prevWidth=-1;


		for (n in tbarr){
			//alert (tbarr.length+' '+n+' '+actb_curr_arr.length);
			if (!hasBracket ||(n<actb_curr_arr.length-1)){
				wid=parseInt(actb_curr_arr[n][2].substr(0,actb_curr_arr[n][2].length-2));
				if(actb_self.actb_BorderWidth!=0){wid-=(actb_self.actb_BorderWidth*4)}else{wid-=4}; //integer current field width and adjust to correct for the cellspacing and padding

				left=actb_curr_arr[n][1]; // integer current field left

				if (prevLeft!=-1) {
					spacewidth=(left-(prevLeft+prevWidth));
					dt+='<div class="cont" ><div style="width:'+spacewidth+'px; margin: 0px; float: left; overflow:hidden; ">&nbsp;</div></div>'; //spacer
				}

				if (hasBracket && n==actb_curr_arr.length-2) wid += addColumnWidth;

				dt+='<div style="overflow:hidden; float: left; height: 100%;width:'+eval(wid-1)+'px; padding-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; margin: 0px;">'+tbarr[n]+'</div>';
				j++;

				prevLeft=left;
				prevWidth=wid;
			}

		}
		dt+="</div>";
		return dt;
	}

	function OtherFieldsIsNotBlank() {
		result=false;
		if (MultipleId) {
			for (n=1; n<actb_curr_arr.length; n++ ) {
				if (typeof(actb_curr_arr[n][0])!="undefined" && (actb_curr_arr[n][0]!=null)) {
					if (actb_curr_arr[n][0].value!='') result=true;
				}
				if (result!=false) {break;}
			}
		}
		return result;
	}

	/* dyodyo added END */

	function processReqChange() {
		if (req.readyState == 4) {
			if (req.status == 200) {
				var r = req.responseText;
				var responseArray = r.split("|");
				actb_self.actb_keywords = responseArray;
				actb_tocomplete(); //call the autocomplete routine . . .
			}
			else {
				//next keystroke will attempt to fetch again
				actb_self.actb_fetched = '';
			}
		}
	}

	function request(url) {
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send(null);
		}
		else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) {
				req.onreadystatechange = processReqChange;
				req.open("GET", url, true);
				req.send();
			}
		}
		else {
			// Sorry, autocomplete currently supports only Internet Explorer and Firefox.
		}
	}


	dyo_setup(); // added by dyodyo


	/* ---- Public Variables ---- */

	/* --- Styles --- */
	this.actb_bgColor = 'white';
	this.actb_textColor = 'black';
	this.actb_hColor = 'navy';
	this.actb_hTextColor = 'white';
	this.actb_fFamily = 'Trebuchet MS';
	this.actb_fSize = '13px';

	this.actb_boxWidth = dyo_boxWidth; // edited

	this.textAlign='left';
	this.Align='left';

	/* --- Styles --- */

	/* ---- Private Variables ---- */
	var actb_delimwords = new Array();
	var actb_cdelimword = 0;
	var actb_delimchar = new Array();
	var actb_display = false;
	var actb_pos = 0;
	var actb_total = 0;


	var actb_rangeu = 0;
	var actb_ranged = 0;
	var actb_bool = new Array();
	var actb_boolSec = new Array();
	var actb_pre = 0;
	var actb_toid;
	var actb_tomake = false;
	var actb_getpre = "";
	var actb_mouse_on_list = 1;
	var actb_kwcount = 0;
	var actb_caretmove = false;
	/* ---- Private Variables---- */



	addEvent(actb_curr,"focus",actb_setup);
	function actb_setup(){
		addEvent(document,"keydown",actb_checkkey);
		addEvent(actb_curr,"blur",actb_clear);
		addEvent(document,"keypress",actb_keypress);
	}

	function actb_clear(evt){
		if (!evt) evt = event;
		removeEvent(document,"keydown",actb_checkkey);
		removeEvent(actb_curr,"blur",actb_clear);
		removeEvent(document,"keypress",actb_keypress);
		actb_removedisp();
	}

	function actb_parse(n){
		if (actb_self.actb_delimiter.length > 0){
			var t = actb_delimwords[actb_cdelimword].addslashes();
			var plen = actb_delimwords[actb_cdelimword].length;
		}else{
			var t = actb_curr.value.addslashes();
			var plen = actb_curr.value.length;
		}
		var tobuild = '';
		var i;

		t=t.toUpperCase();
		if (actb_self.actb_firstText){
			var re = new RegExp("^" + t, "i");
		}else{			
			if (n.indexOf("[")!=-1){		
				var re = new RegExp("^"+t+"|\\["+t+"","i");
			} else {
				var re = new RegExp("^"+t+"|,[\\s]*"+t,"i");
			}
		}
		var p = n.search(re);
		if (n.charAt(p)==","||n.charAt(p)=="[") p++;
		
		for (i=0;i<p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "<b>"
		for (i=p;i<plen+p;i++){
			tobuild += n.substr(i,1);
		}
		tobuild += "</b>";
		for (i=plen+p;i<n.length;i++){
			tobuild += n.substr(i,1);
		}

		//process tobuild here!
		//alert(tobuild);
		if (MultipleId) tobuild=AlignToFields(tobuild);
		tobuild=tobuild.replace(/\[/g,'');
		tobuild=tobuild.replace(/\]/g,'');

		return tobuild;
	}
	function actb_generate(){
		if (document.getElementById('tat_table')){ actb_display = false;if (MultipleId){actb_self.actb_boxWidth=getTotalWidth();} document.body.removeChild(document.getElementById('tat_table')); }
		if (actb_kwcount == 0){
			actb_display = false;
			return;
		}
		a = document.createElement('table');

		a.cellSpacing='1px';
		a.cellPadding='2px';

		if (actb_self.actb_BorderWidth!=0){
			a.style.border=actb_self.actb_BorderWidth +"px "+actb_self.actb_BorderStyle+" "+actb_self.actb_BorderColor;
		} else a.style.border="none";

		a.width=actb_self.actb_boxWidth;
		a.style.position='absolute';

		/* edited to remove flicker */
		a.style.fontFamily = actb_self.actb_fFamily;
		a.style.fontSize = actb_self.actb_fSize;

		a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight + actb_self.actb_BorderWidth + actb_self.actb_offsetTop) + "px";

		a.style.left = curLeft(actb_curr) + "px";

		a.style.overflow='hidden';

		a.style.backgroundColor=actb_self.actb_bgColor;


		a.style.textAlign=actb_self.textAlign;
		a.style.Align=actb_self.Align;

		a.style.color=actb_self.actb_textColor;
		a.id = 'tat_table';
		document.body.appendChild(a);
		var i;
		var first = true;
		var j = 1;
		if (actb_self.actb_mouse){
			a.onmouseout = actb_table_unfocus;
			a.onmouseover = actb_table_focus;
		}
		var counter = 0;
		for (i=0;i<actb_self.actb_keywords.length;i++){
			if (actb_bool[i]){
				counter++;
				r = a.insertRow(-1);
				if (first && !actb_tomake){
					r.style.backgroundColor = actb_self.actb_hColor;
					r.style.color = actb_self.actb_hTextColor;
					first = false;
					actb_pos = counter;
				}else if(actb_pre == i){
					r.style.backgroundColor = actb_self.actb_hColor;
					r.style.color = actb_self.actb_hTextColor;
					first = false;
					actb_pos = counter;
				}else{
					r.style.backgroundColor = actb_self.actb_bgColor;
					r.style.color = actb_self.actb_textColor;
				}
				r.id = 'tat_tr'+(j);
				c = r.insertCell(-1);
				c.style.fontFamily = actb_self.actb_fFamily;
				c.style.fontSize = actb_self.actb_fSize;
				c.innerHTML = actb_parse(actb_self.actb_keywords[i]);
				c.id = 'tat_td'+(j);
				c.setAttribute('pos',j);
				if (actb_self.actb_mouse){
					c.style.cursor = 'pointer';
					c.onclick=actb_mouseclick;
					c.onmouseover = actb_table_highlight;
				}
				j++;
			}
			if (j - 1 == actb_self.actb_lim && j < actb_total){
				r = a.insertRow(-1);
				r.style.backgroundColor = actb_self.actb_bgColor;
				r.style.color = actb_self.actb_textColor;
				c = r.insertCell(-1);
				c.style.fontFamily = actb_self.actb_fFamily;
				c.style.fontSize = actb_self.actb_fSize;
				c.style.fontWeight = 'bold';
				//c.align='center';
				replaceHTML(c,'. . .');
				if (actb_self.actb_mouse){
					c.style.cursor = 'pointer';
					c.onclick = actb_mouse_down;
				}
				break;
			}
		}
		actb_rangeu = 1;
		actb_ranged = j-1;
		actb_display = true;
		if (actb_pos <= 0) actb_pos = 1;
	}
	function actb_remake(){
		if (MultipleId){actb_self.actb_boxWidth=getTotalWidth();}

		document.body.removeChild(document.getElementById('tat_table'));
		a = document.createElement('table');

		a.cellSpacing='1px';
		a.cellPadding='2px';

		if (actb_self.actb_BorderWidth!=0){
			a.style.border=actb_self.actb_BorderWidth +"px "+actb_self.actb_BorderStyle+" "+actb_self.actb_BorderColor;
		} else a.style.border="none";


		a.width=actb_self.actb_boxWidth;
		a.style.position='absolute';
		a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight + actb_self.actb_BorderWidth + actb_self.actb_offsetTop) + "px";
		a.style.left = curLeft(actb_curr) + "px";
		a.style.backgroundColor=actb_self.actb_bgColor;
		a.style.color=actb_self.actb_textColor;

		a.style.overflow='hidden';

		/* edited to remove flicker */
		a.style.fontFamily = actb_self.actb_fFamily;
		a.style.fontSize = actb_self.actb_fSize;

		a.id = 'tat_table';
		if (actb_self.actb_mouse){
			a.onmouseout= actb_table_unfocus;
			a.onmouseover=actb_table_focus;
		}
		document.body.appendChild(a);
		var i;
		var first = true;
		var j = 1;
		if (actb_rangeu > 1){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_self.actb_bgColor;
			r.style.color = actb_self.actb_textColor;
			c = r.insertCell(-1);
			c.style.fontFamily = actb_self.actb_fFamily;
			c.style.fontSize = actb_self.actb_fSize;
			c.style.fontWeight = 'bold';
			//c.align='center';
			replaceHTML(c,'. . .');
			if (actb_self.actb_mouse){
				c.style.cursor = 'pointer';
				c.onclick = actb_mouse_up;
			}
		}
		for (i=0;i<actb_self.actb_keywords.length;i++){
			if (actb_bool[i]){
				if (j >= actb_rangeu && j <= actb_ranged){
					r = a.insertRow(-1);
					r.style.backgroundColor = actb_self.actb_bgColor;
					r.style.color = actb_self.actb_textColor;
					r.id = 'tat_tr'+(j);
					c = r.insertCell(-1);
					c.style.fontFamily = actb_self.actb_fFamily;
					c.style.fontSize = actb_self.actb_fSize;
					c.innerHTML = actb_parse(actb_self.actb_keywords[i]);
					c.id = 'tat_td'+(j);
					c.setAttribute('pos',j);
					if (actb_self.actb_mouse){
						c.style.cursor = 'pointer';
						c.onclick=actb_mouseclick;
						c.onmouseover = actb_table_highlight;
					}
					j++;
				}else{
					j++;
				}
			}
			if (j > actb_ranged) break;
		}
		if (j-1 < actb_total){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_self.actb_bgColor;
			r.style.color = actb_self.actb_textColor;
			c = r.insertCell(-1);
			c.style.fontFamily = actb_self.actb_fFamily;
			c.style.fontSize = actb_self.actb_fSize;
			c.style.fontWeight = 'bold';
			//c.align='center';
			replaceHTML(c,'. . .');
			if (actb_self.actb_mouse){
				c.style.cursor = 'pointer';
				c.onclick = actb_mouse_down;
			}
		}
	}
	function actb_goup(){
		if (!actb_display) return;
		if (actb_pos == 1) return;
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textColor;
		actb_pos--;
		if (actb_pos < actb_rangeu) actb_moveup();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_hTextColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_godown(){
		if (!actb_display) return;
		if (actb_pos == actb_total) return;
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textColor;
		actb_pos++;
		if (actb_pos > actb_ranged) actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_hTextColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_movedown(){
		actb_rangeu++;
		actb_ranged++;
		actb_remake();
	}
	function actb_moveup(){
		actb_rangeu--;
		actb_ranged--;
		actb_remake();
	}

	/* Mouse */
	function actb_mouse_down(){
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textColor;
		actb_pos++;
		actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_hTextColor;
		actb_curr.focus();
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_mouse_up(evt){
		if (!evt) evt = event;
		if (evt.stopPropagation){
			evt.stopPropagation();
		}else{
			evt.cancelBubble = true;
		}
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textColor;
		actb_pos--;
		actb_moveup();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_hTextColor;
		actb_curr.focus();
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_mouseclick(evt){
		if (!evt) evt = event;
		if (!actb_display) return;
		actb_mouse_on_list = 0;
		actb_pos = this.getAttribute('pos');
		actb_penter();
	}
	function actb_table_focus(){
		actb_mouse_on_list = 1;
	}
	function actb_table_unfocus(){
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_table_highlight(){
		actb_mouse_on_list = 1;
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textColor;
		actb_pos = this.getAttribute('pos');
		while (actb_pos < actb_rangeu) actb_moveup();
		while (actb_pos > actb_ranged) actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_hTextColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
	}
	/* ---- */


	/* INSERT ROUTINE */
	function actb_insertword(a){
		if (actb_self.actb_delimiter.length > 0){
			str = '';
			l=0;
			for (i=0;i<actb_delimwords.length;i++){
				if (actb_cdelimword == i){
					prespace = postspace = '';
					gotbreak = false;
					for (j=0;j<actb_delimwords[i].length;++j){
						if (actb_delimwords[i].charAt(j) != ' '){
							gotbreak = true;
							break;
						}
						prespace += ' ';
					}
					for (j=actb_delimwords[i].length-1;j>=0;--j){
						if (actb_delimwords[i].charAt(j) != ' ') break;
						postspace += ' ';
					}
					str += prespace;
					str += a;
					l = str.length;
					if (gotbreak) str += postspace;
				}else{
					str += actb_delimwords[i];
				}
				if (i != actb_delimwords.length - 1){
					str += actb_delimchar[i];
				}
			}
			dyo_UpdateCurr(str);
			setCaret(actb_curr,l);
		}else{
			dyo_UpdateCurr(a);
		}
		actb_mouse_on_list = 0;
		actb_removedisp();
	}


	function actb_penter(){
		if (!actb_display) return;
		actb_display = false;
		var word = '';
		var c = 0;
		for (var i=0;i<=actb_self.actb_keywords.length;i++){
			if (actb_bool[i]) c++;
			if (c == actb_pos){
				word = actb_self.actb_keywords[i];
				break;
			}
		}
		actb_insertword(word);
		l = getCaretStart(actb_curr);
	}
	function actb_removedisp(){
		if (actb_mouse_on_list==0){
			actb_display = 0;
			if (document.getElementById('tat_table')){ document.body.removeChild(document.getElementById('tat_table')); }
			if (actb_toid) clearTimeout(actb_toid);
		}
	}
	function actb_keypress(e){
		if (actb_caretmove) stopEvent(e);
		return !actb_caretmove;
	}
	function actb_checkkey(evt){
		if (!evt) evt = event;
		a = evt.keyCode;
		caret_pos_start = getCaretStart(actb_curr);
		actb_caretmove = 0;
		switch (a){
			case 38:
			actb_goup();
			actb_caretmove = 1;
			return false;
			break;
			case 40:
			actb_godown();
			actb_caretmove = 1;
			return false;
			break;
			case 13: case 9:
			if (actb_display){
				actb_caretmove = 1;
				actb_penter();
				return false;
			}else{
				return true;
			}
			break;
			default:
			setTimeout(function(){actb_tocomplete(a)},50);
			break;
		}
	}

	function actb_tocomplete(kc){
		if (MultipleId){actb_self.actb_boxWidth=getTotalWidth();} //the border-width might have changed so renew the total width info
		if (kc == 38 || kc == 40 || kc == 13) return;
		var i;
		if (actb_display){
			var word = 0;
			var c = 0;
			for (var i=0;i<=actb_self.actb_keywords.length;i++){
				if (actb_bool[i]) c++;
				if (c == actb_pos){
					word = i;
					break;
				}
			}
			actb_pre = word;
		}
		else {
			actb_pre = -1
		};

		if (actb_curr.value == ''){
			actb_mouse_on_list = 0;
			actb_removedisp();
			return;
		}

		if (actb_self.actb_delimiter.length > 0){
			caret_pos_start = getCaretStart(actb_curr);
			caret_pos_end = getCaretEnd(actb_curr);

			delim_split = '';
			for (i=0;i<actb_self.actb_delimiter.length;i++){
				delim_split += actb_self.actb_delimiter[i];
			}
			delim_split = delim_split.addslashes();
			delim_split_rx = new RegExp("(["+delim_split+"])");
			c = 0;
			actb_delimwords = new Array();
			actb_delimwords[0] = '';
			for (i=0,j=actb_curr.value.length;i<actb_curr.value.length;i++,j--){
				if (actb_curr.value.substr(i,j).search(delim_split_rx) == 0){
					ma = actb_curr.value.substr(i,j).match(delim_split_rx);
					actb_delimchar[c] = ma[1];
					c++;
					actb_delimwords[c] = '';
				}else{
					actb_delimwords[c] += actb_curr.value.charAt(i);
				}
			}

			var l = 0;
			actb_cdelimword = -1;
			for (i=0;i<actb_delimwords.length;i++){
				if (caret_pos_end >= l && caret_pos_end <= l + actb_delimwords[i].length){
					actb_cdelimword = i;
				}
				l+=actb_delimwords[i].length + 1;
			}
			var ot = actb_delimwords[actb_cdelimword];
			var t = actb_delimwords[actb_cdelimword].addslashes();
		}else{
			var ot = actb_curr.value;
			var t = actb_curr.value.addslashes();
		}

		var otPrefix = ot.substr(0,actb_self.actb_startcheck);
		if (ot.length < actb_self.actb_startcheck) {
			actb_mouse_on_list = 0;
			actb_removedisp();
			return this;
		}
		else if ((ot.length >= actb_self.actb_startcheck) && (actb_self.actb_fetch) && (otPrefix != actb_self.actb_fetched)) {
			actb_self.actb_fetched = otPrefix; // prevent looping
            request('/autocomplete/'+actb_self.actb_fetchName+'/?pre='+otPrefix);
		}

	actb_total = 0;
	actb_tomake = false;
	actb_kwcount = 0;
		
		
		t = t.toUpperCase();
		if (actb_self.actb_firstText){
			var re = new RegExp("^" + t, "i");
		}

	if (MultipleId) { var nonBlank=OtherFieldsIsNotBlank(); } else {var nonBlank=false;}

	for (i=0;i<actb_self.actb_keywords.length;i++){
		actb_bool[i] = false;
		if (!actb_self.actb_firstText){
			if (actb_self.actb_keywords[i].indexOf("[")!=-1){		
				var re = new RegExp("^"+t+"|\\["+t,"i");
			} else {				
				//var re = new RegExp("?:^|,"+t,"i");
				var re = new RegExp("^"+t+"|(?:,)"+t,"i");
			}
			
		}

		if (re.test(actb_self.actb_keywords[i])){
		if ( (MultipleId) && (nonBlank) ) {
			// match the other fields specified to the respective values of those fields
			candidate=actb_self.actb_keywords[i].replace(/\[[\S\s]*\]/g,'');
			carr=candidate.split(',');
			c_match=true;

			for (n=1; n<carr.length; n++ ) {
				fldValue=GetValue(actb_curr_arr[n][0]).toUpperCase();

				if (fldValue!='') {
					if ( ((carr[n].toUpperCase().trim()) != fldValue) ) {
						c_match=false;
					}
				}
				if (!c_match) break;
			}
			if (c_match){
				actb_total++;
				actb_bool[i] = true;
				actb_kwcount++;
				if (actb_pre == i) actb_tomake = true;
			}

		}
		else {
			//default is match the FIRST specified field
			actb_total++;
			actb_bool[i] = true;
			actb_kwcount++;
			if (actb_pre == i) actb_tomake = true;
		}
	}
}

if (actb_toid) clearTimeout(actb_toid);
if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
actb_generate();
}

return this;
}


