﻿// JScript File
function actb(obj,lookupURL,ouputFunc,objQuery,objOutput,outputOnSelect,fetchOnce,fetch_first_char,fetchAll){
	/* ---- Public Variables ---- */
	this.actb_timeOut = -1; // 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 = true; // should the auto complete be limited to the beginning of keyword?
	this.actb_mouse = true; // Enable Mouse Support
	this.actb_delimiter = new Array(); //new Array(';',',');  // Delimiter for multiple autocomplete. Set it to empty array for single autocomplete
	this.actb_startcheck = 1; // Show widget only after this number of characters is typed in.
	/* ---- Public Variables ---- */

	/* --- Styles --- */
	this.actb_bgColor = '#ffffff';
	this.actb_textColor = '#00688d';
	this.actb_hColor = '#e7f4fe';
	this.actb_fFamily = 'Verdana';
	this.actb_fSize = '11px';
	this.actb_hStyle = 'text-decoration:underline;font-weight="bold"';
	/* --- Styles --- */
	this.actb_className='actbBG'; // Added By HK
	this.actb_textClassName='actbText'; // Added By HK
	this.actb_objQueryValue=''; // Added By HK
	this.actb_fetchOnce=false; // Added By HK
	this.actb_fetch_first_char=false; //Added by HK
	this.actb_prev_first_char='';
	this.actb_fetchAll=false;
	
	this.actb_lookupURL=lookupURL;

	/* ---- 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_curr = null;
	var actb_rangeu = 0;
	var actb_ranged = 0;
	var actb_bool = new Array();
	var actb_pre = 0;
	var actb_toid;
	var actb_tomake = false;
	var actb_getpre = "";
	var actb_mouse_on_list = 0;
	var actb_kwcount = 0;
	var actb_caretmove = false;
	this.actb_keywords =null;// new Array();
	var actb_outputFunc=ouputFunc;
	var actb_selected=false;
	var actb_selectedVals;
	var obj_query=null;
	var obj_output=null;
	var actb_changed=false; //-- by HK
	var actb_mouse_clicked=false //-- by HK
	var actb_search=true;//-- by HK
	var actb_last_found_word="";//-- by HK
	var actb_last_key_code=0;
	/* ---- Private Variables---- */
	
	
	this.actb_close=function(){actb_removedisp();}; //-- by HK
	
	
	//this.actb_keywords = null; // commented by HK
	var actb_self = this;

	actb_curr = obj;

	obj_query=objQuery; // added by HK
	obj_output=objOutput; // added by HK
	if (fetchOnce!=null)
	    actb_self.actb_fetchOnce=fetchOnce;
	if (fetchAll!=null)
	    actb_self.actb_fetchAll=fetchAll;
	

	if (fetch_first_char!=null)    
	    actb_self.actb_fetch_first_char=fetch_first_char;
	
	actb_addEvent(actb_curr,"focus",actb_setup);
	function actb_setup()
	{
	    actb_addEvent(document,"keydown",actb_checkkey);
	    actb_addEvent(actb_curr,"blur",actb_clear);
	    actb_addEvent(document,"keypress",actb_keypress);
	    actb_addEvent(actb_curr,"paste",actb_paste);
		if (actb_mouse_clicked==false)
		    actb_changed=false;
		else
		    actb_mouse_clicked=false;
	}

	function actb_clear(evt)
	{
		if (!evt) evt = event;
		removeEvent(document,"keydown",actb_checkkey);
		removeEvent(actb_curr,"blur",actb_clear);
		removeEvent(document,"keypress",actb_keypress);
	    removeEvent(actb_curr,"paste",actb_paste);

		if(actb_mouse_on_list!=1)
		{
		    /*if (obj_output!=null) // Added by HK
		    {
		        obj_output.value=actb_selectedVals.value;
		     }*/
		     //alert(actb_changed);
		     //alert("hehe");
		    if (outputOnSelect==null || outputOnSelect==false) 
		    {
		        if (actb_outputFunc!=null && actb_changed==true)
		            actb_outputFunc(actb_selected,actb_selectedVals);
		    }
		}
	}
	
	function actb_parse(n,n2)
	{
		if (actb_self.actb_delimiter.length > 0){
			var t = actb_delimwords[actb_cdelimword].trim().addslashes();
			var plen = actb_delimwords[actb_cdelimword].trim().length;
		}else
		{
			var t = actb_curr.value.addslashes();
			var plen = actb_curr.value.length;
		}
		var tobuild = '';
		var i;

		if (actb_self.actb_firstText){
			var re = new RegExp("^" + t, "i");
		}else
		{
			var re = new RegExp(t, "i");
		}
		if(n2==null)
		{
		    var p = n.search(re);
		    for (i=0;i<p;i++){
			    tobuild += n.substr(i,1);
		    }
		    tobuild += "<font style='"+(actb_self.actb_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);
		    }
		}
		else
		{
		    var p = n.search(re);
	            for (i=0;i<p;i++)
	            {
		            tobuild += n.substr(i,1);
	            }
	            for (i=p;i<plen+p;i++){
		            tobuild += n.substr(i,1);
	            }
	            if (tobuild.toLowerCase()==actb_curr.value.toLowerCase())
	            {
		            tobuild="<font style='"+(actb_self.actb_hStyle)+"'>"+tobuild+"</font>";
		            for (i=plen+p;i<n.length;i++)
		            {
		                tobuild += n.substr(i,1);
	                }
	            }    
	            else{tobuild=n;}
		}
		return tobuild;
	}
	
	function actb_generate(){
		if (document.getElementById('tat_table')){ actb_display = false;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';
		a.style.position='absolute';
		a.style.zIndex='200';
		a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft(actb_curr) + "px";
		//a.style.backgroundColor=actb_self.actb_bgColor; //Commented By HK
		//a.style.width=actb_curr.style.width; // added By HK
		a.style.width=actb_curr.offsetWidth; // added By HK
		a.className=actb_self.actb_className;
		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;
					first = false;
					actb_pos = counter;
				}else if(actb_pre == i){
					r.style.backgroundColor = actb_self.actb_hColor;
					first = false;
					actb_pos = counter;
				}else{
					r.style.backgroundColor = actb_self.actb_bgColor;
				}
				r.id = 'tat_tr'+(j);
				c = r.insertCell(-1);
				/* commented by hk
				c.style.color = actb_self.actb_textColor;
				c.style.fontFamily = actb_self.actb_fFamily;
				c.style.fontSize = actb_self.actb_fSize;
				*/
				c.className=actb_self.actb_textClassName;
				c.innerHTML = "<div>"+actb_parse(actb_self.actb_keywords[i].name,actb_self.actb_keywords[i].n2)+"</div><div class='GrayTextSmall'>"+actb_self.actb_keywords[i].desc+"</div><div class='LineDotted'>&nbsp;</div>"; //hk_change
				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; // Commented By HK
				c = r.insertCell(-1);
				/* -- Commented BY HK
				c.style.color = actb_self.actb_textColor;
				c.style.fontFamily = 'arial narrow';
				c.style.fontSize = actb_self.actb_fSize;*/
				c.align='center';
				
				c.className=actb_self.actb_textClassName; // By HK
				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_waitbox()
	{
	    if (document.getElementById('actb_waitbox_div'))
	        return;
	    a = document.createElement('div');
	    a.style.position='absolute';
	    a.style.zIndex='200';
		a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft(actb_curr) + "px";
		a.id = 'actb_waitbox_div';
		a.innerHTML="Fetching data...";
		a.className="actb_waitbox";
        document.body.appendChild(a);
	}
	function actb_waitbox_remove()
	{
	    if (document.getElementById('actb_waitbox_div')){ document.body.removeChild(document.getElementById('actb_waitbox_div')); }
    }
    
	function actb_remake(){
		document.body.removeChild(document.getElementById('tat_table'));
		a = document.createElement('table');
		a.cellSpacing='1px';
		a.cellPadding='2px';
		a.style.position='absolute';
	    a.style.zIndex='200';
		a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft(actb_curr) + "px";
		//a.style.backgroundColor=actb_self.actb_bgColor; // HK
		//a.style.width=actb_curr.style.width;
		a.style.width=actb_curr.offsetWidth; // added By HK
		a.className=actb_self.actb_className;
		
		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; // Commented By HK
			c = r.insertCell(-1);
			/* Commented By HK
			c.style.color = actb_self.actb_textColor;
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_self.actb_fSize;
			*/
			c.className=actb_self.actb_textClassName;
			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; // Commmented By HK
					r.id = 'tat_tr'+(j);
					c = r.insertCell(-1);
					/*Commented By HK
					c.style.color = actb_self.actb_textColor;
					c.style.fontFamily = actb_self.actb_fFamily;
					c.style.fontSize = actb_self.actb_fSize;
					*/
					c.className=actb_self.actb_textClassName;// hk_change
					//c.innerHTML = actb_parse(actb_self.actb_keywords[i].name); 
					c.innerHTML = "<div>"+actb_parse(actb_self.actb_keywords[i].name,actb_self.actb_keywords[i].n2)+"</div><div class='GrayTextSmall'>"+actb_self.actb_keywords[i].desc+"</div><div class='LineDotted'>&nbsp;</div>"; //hk_change
					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; // Commented BY HK
			c = r.insertCell(-1);
			/*
			Commented By HK
			c.style.color = actb_self.actb_textColor;
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_self.actb_fSize;
			*/
			c.className=actb_self.actb_textClassName; // Added BY HK
			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;
		actb_pos--;
		if (actb_pos < actb_rangeu) actb_moveup();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor; 
		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;
		actb_pos++;
		if (actb_pos > actb_ranged) actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		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;
		actb_pos++;
		actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		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;
		actb_pos--;
		actb_moveup();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		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){
		actb_mouse_clicked=true
		if (!evt) evt = event;
		if (!actb_display) return;
		actb_curr.focus(); // added by HK
		actb_changed=true; // added by HK
		
		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;
		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;
		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_insertword(vals){
	    var a;
	    a=vals.name;
		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];
				}
			}
			actb_curr.value = str;
			setCaret(actb_curr,l);
		}
		else
		{
			actb_curr.value = a;
		}
        /* ------added by HK*/
		//alert(id);
		actb_selected=true;
		actb_selectedVals=vals;
		//actb_outputFunc(vals);
		
		if(obj_output!=null)
		{
		    obj_output.value=vals.value;
		}
	
        /* ---------------*/		
		actb_mouse_on_list = 0;
		actb_removedisp();
	}
	function actb_penter(){
		if (!actb_display) return;
		actb_display = false;
		var word = '';
		var c = 0;
		var varId=-1;
		var i=0;
		for (i=0;i<=actb_self.actb_keywords.length;i++){
			if (actb_bool[i]) c++;
			if (c == actb_pos){
				word = actb_self.actb_keywords[i].name;
				varId = actb_self.actb_keywords[i].value;
				break;
			}
		}
		actb_insertword(actb_self.actb_keywords[i]);
		l = getCaretStart(actb_curr);
		//alert("selected");
	    if (outputOnSelect==true) 
	    {
	        if (actb_outputFunc!=null && actb_changed==true)
	            actb_outputFunc(actb_selected,actb_selectedVals);
	    }

	}
	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);
			actb_waitbox_remove();
		}
	}
	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;
			case 17:
			    actb_last_key_code=17;
			    break;	
			default:
				//setTimeout(function(){actb_tocomplete(a)},50);
				//***** Added By HK *********
		        if(obj_output!=null)
		        {
		            obj_output.value="";
		        }
		        actb_changed=true;
		        if (actb_search)
		        {
		            //actb_waitbox();
				    setTimeout(function(){actb_getData(a)},50);
				}
				else
				{
				    var currentVal=actb_curr.value;
				    if(a==8 && actb_curr.value!=""){currentVal=currentVal.substr(0,currentVal.length-1);}
				    
				    if (a==86 && actb_last_key_code==17 )
				    {
				        //alert('called');
				        actb_search=true;
		                actb_waitbox();
			            setTimeout(function(){actb_getData(a)},50);
				    
				    }
				    else if (currentVal=="" || currentVal==actb_last_found_word ||  currentVal.length<=actb_last_found_word.length)
				    {
				        actb_search=true;
		                //actb_waitbox();
			            setTimeout(function(){actb_getData(a)},50);
				    }
				}
				actb_last_key_code=a;
			    //******************
				break;
		}
	}
	
	function actb_paste(evt)
	{
	    //alert(actb_curr.value);
	    //actb_getData(null);
	    setTimeout(function(){actb_getData()},50);
	}
	
	
//****************************************

	function getXMLHTTP_()
	{
		var A_ = null;
		try{
			A_ = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			try{
				A_ = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(oc){
				A_ = null;
			}
		}
		if(!A_ && typeof XMLHttpRequest != "undefined") {
			A_ = new XMLHttpRequest();
		}
		return A_;
	}
	
	var varKeyCode;
	//var xmlHttp;
	
	function actb_getData(keyCode)
	{
        if (actb_self.actb_fetchAll==true)
        {
            if (actb_self.actb_keywords!=null)
            {
                actb_waitbox_remove();
                actb_tocomplete(varKeyCode);
                return;
            }
        }
        if (actb_self.actb_fetchOnce==true && (obj_query==null || actb_self.actb_fetch_first_char==true))
        {
            if (actb_curr.value.substr(0,1)==actb_self.actb_prev_first_char)
            {
                actb_waitbox_remove();
                actb_tocomplete(varKeyCode);
                return;
            }
            
        }
        else if (actb_self.actb_fetchOnce==true && obj_query!=null)
        {
            if (actb_self.actb_objQueryValue==obj_query.value && actb_self.actb_keywords!=null)
            {
                if(actb_self.actb_keywords.length>0)
                {
                    actb_waitbox_remove();
                    actb_tocomplete(varKeyCode);
                    return;
                }
            }    
        }
        actb_waitbox();
        xmlHttp_ = getXMLHTTP_();
        if (xmlHttp_)
        {
	        varKeyCode=keyCode
	        if(obj_query==null)
	        {
	            if(actb_self.actb_fetchOnce==true && actb_self.actb_fetchAll==false)
	            {
	                requestUrl="/"+actb_self.actb_lookupURL+"val="+actb_curr.value.substr(0,1)+"&rnd="+Math.random();
	                actb_self.actb_prev_first_char=actb_curr.value.substr(0,1);
	            }
	            else
	                requestUrl="/"+actb_self.actb_lookupURL+"&val="+actb_curr.value+"&rnd="+Math.random();
	        }
	        else
	        {
	            actb_self.actb_objQueryValue=obj_query.value;
	            actb_self.actb_prev_first_char=actb_curr.value.substr(0,1);
	            requestUrl="/"+actb_self.actb_lookupURL+"&val="+actb_curr.value+"&filter="+actb_self.actb_objQueryValue+"&rnd="+Math.random();
	        }
	        //requestUrl="lookup.aspx?id=cc&val=us&nrd="+Math.random();
	        xmlHttp_.onreadystatechange = doReadyStateChange_;
	        xmlHttp_.open("GET", requestUrl, true);
	        xmlHttp_.send(null);
        }			
	}
	
    function doReadyStateChange_()
    {
	    if (xmlHttp_.readyState == 4)
	    {
		    if (xmlHttp_.status == 200)
		    {
			    //alert(xmlHttp_.responseText);
			    actb_waitbox_remove();
			    actb_self.actb_keywords=eval(xmlHttp_.responseText)
			    if (actb_self.actb_keywords.length==0)
			    {
			        actb_search=false;
			    }
			    else
			        actb_last_found_word=actb_curr.value;
			    actb_tocomplete(varKeyCode);
		    }
		    else
		    {
			    alert("There was a problem in retrieving the data:\n" + xmlHttp_.statusText);
		    }
	    }
    }	
//*****************************************	
	function actb_tocomplete(kc){
	    actb_selected=false // added by HK
		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].trim(); 
			var t = actb_delimwords[actb_cdelimword].addslashes().trim();
		}
		else
		{
			var ot = actb_curr.value;
			var t = actb_curr.value.addslashes();
		}
		if (ot.length == 0){
			actb_mouse_on_list = 0;
			actb_removedisp();
		}
		if (ot.length < actb_self.actb_startcheck) return this;
		if (actb_self.actb_firstText){
			var re = new RegExp("^" + t, "i");
		}else{
			var re = new RegExp(t, "i");
		}

		actb_total = 0;
		actb_tomake = false;
		actb_kwcount = 0;
		if (actb_self.actb_keywords!=null )
		{
		    if (actb_self.actb_keywords.length>0 && actb_self.actb_keywords[0].n2==null)
		    {
		        for (i=0;i<actb_self.actb_keywords.length;i++)
		        {
			        actb_bool[i] = false;
			        if (re.test(actb_self.actb_keywords[i].name)){   // hk change
				        actb_total++;
				        actb_bool[i] = true;
				        actb_kwcount++;
				        if (actb_pre == i) actb_tomake = true;
			        }
		        }
		    }
		    else
		    {
		        for (i=0;i<actb_self.actb_keywords.length;i++)
		        {
			        actb_bool[i] = false;
			        if (re.test(actb_self.actb_keywords[i].name) || re.test(actb_self.actb_keywords[i].n2)){   // hk change
				        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;
}    
