this.actb_bgColor ='#E5E5E7'; //'#888888';
this.actb_textColor ='#000000'; //'#FFFFFF';
this.actb_hColor ='#8F9C40'; //'#000000';
this.actb_fFamily = 'Verdana';
this.actb_fSize = '11px';
this.actb_hStyle = 'font-weight:bold;'; //text-decoration:underline;
var actb_lim=20;
var actb_total = 0;
var actb_pre = 0;
var actb_toid;
var actb_timeOut = -1;
var actb_rangeu = 0;
var actb_ranged = 0;
var actb_mouse=true;
var actb_delimwords = new Array();
var actb_cdelimword = 0;
var actb_delimchar = new Array();
var actb_display = false;
var actb_pos = 0;
var actb_curr = null;
var actb_bool = 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;


function getdata(e,datatype,datalocation){
//datalocation :  srchtext id.
//datatype: file to read (all/artist/product)
    var a = e.keyCode || e.which;
    switch(a){
        case 38:
	        actb_goup();
	        return false;
        case 40:
            actb_godown();
            return false;
            break;
        default:
            if(a==13 || a==9){
                if (actb_display){actb_removedisp();return (a==13)?false:true;}
                else{return true;}
            }
            var matcheddata ='';
            var dataloc = document.getElementById(datalocation);
            var datatyp=document.getElementById(datatype);
            datatyp=(datatyp==null)?datatype:datatyp.value;
            var dat=dataloc.value;
            dat=dat.replace("&","~");
            var url = getBaseReal() + "Handlers/AutoComplete.ashx?"+ '&type='+datatyp + '&data=' + dat ;
            var xmlHttp = createXMLHttpRequest();
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {    
                     if(xmlHttp.responseText != '') {
                         matcheddata = xmlHttp.responseText; 
                         var arr=new Array();           
                         arr=matcheddata.split(',');
                         actb_generate(arr,datalocation);
                         }
                     else{actb_removedisp();}
               }
            }  
            xmlHttp.open("GET", url, true);
            xmlHttp.send(null);
            break;
    }
}
function getdataitem(e,page){
    var x=e.keyCode || e.which;
    if(x==13 || x==9){
       if (actb_display){
            actb_removedisp();
            if(x==13){
                switch(page){
                    case 1:
                    getSearchDetails('../Web/Search.aspx','search','type','mp3_check');
                    break;
                    case 2:
                    getAdvancedSearchDetails('artistName','genreId','productTitle','range','mp3_check');
                    break;
                }
            }
            return true;
       }
       else{return true;}
    }
}
function actb_generate(list,keyval){
    if (document.getElementById('tat_table')){ actb_display = false;document.body.removeChild(document.getElementById('tat_table')); } 
    actb_curr = document.getElementById(keyval);
    actb_keywords=list;
    var actb_kwcount = actb_keywords.length;
    actb_total=actb_keywords.length;
    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.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
	a.style.left = curLeft(actb_curr) + "px";
	a.style.backgroundColor=actb_bgColor;
	a.style.zIndex ='1000';
	a.style.width=(keyval=='search')? '250px':'180px';
	a.id = 'tat_table';
	document.body.appendChild(a);
	var i;
	var first = true;
	var j = 1;
	if (actb_mouse){
		a.onmouseout = actb_table_unfocus;
		a.onmouseover = actb_table_focus;
	}
	var counter = 0;
	for (i=0;i<actb_keywords.length;i++){
		//if (actb_bool[i]){
			counter++;
			r = a.insertRow(-1);
			if (first){ //&& !actb_tomake
				r.style.backgroundColor = actb_hColor;
				first = false;
				actb_pos = counter;
			}else if(actb_pre == i){
				r.style.backgroundColor = actb_hColor;
				first = false;
				actb_pos = counter;
			}else{
				r.style.backgroundColor = actb_bgColor;
			}
			r.id = 'tat_tr'+(j);
			c = r.insertCell(-1);
			c.style.color = actb_textColor;
			c.style.fontFamily = actb_fFamily;
			c.style.fontSize = actb_fSize;
			c.innerHTML = actb_parse(actb_keywords[i]);
			if(c.innerHTML == '')continue;
			c.id = 'tat_td'+(j);
			c.setAttribute('pos',j);
			if (actb_mouse){
				c.style.cursor = 'pointer';
				//c.onclick=actb_mouseclick;
				c.onmousedown=actb_mouseclick;
				c.onmouseover = actb_table_highlight;
			}
			j++;
		//}
		if (j - 1 == actb_total && j < actb_total){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_bgColor;
			c = r.insertCell(-1);
			c.style.color = actb_textColor;
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_fSize;
			c.align='center';
			replaceHTML(c,'\\/');
			if (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_table_focus(){
	actb_mouse_on_list = 1;
}
function actb_table_unfocus(){
	actb_mouse_on_list = 0;
	if (actb_toid) clearTimeout(actb_toid);
	if (actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_timeOut);
}
function actb_parse1(n){
	var tobuild = '';
	var i;
	for (i=0;i<n.length;i++){
		tobuild += n.substr(i,1);
	}
	tobuild += "<font style='"+(actb_hStyle)+"'>"
	for (i=n.length;i<actb_curr.length;i++){
		tobuild += n.substr(i,1);
	}
	tobuild += "</font>";
		for (i=actb_curr.length;i<n.length;i++){
		tobuild += n.substr(i,1);
	}
	return tobuild;
}
function actb_parse(n){
    var t=actb_curr.value.addslashes();
    var re = new RegExp(t, "i");	
    var p = n.search(re);
    p=(p<0)?0:p;
    
	var tobuild = '';
	var i;
	for (i=0;i<p;i++){
		tobuild += n.substr(i,1);
	}
	tobuild += "<font style='"+(actb_hStyle)+"'>"
	for (i=p;i<p+actb_curr.value.length;i++){
		tobuild += n.substr(i,1);
	}
	tobuild += "</font>";
		for (i=p+actb_curr.value.length;i<n.length;i++){
		tobuild += n.substr(i,1);
	}
	return tobuild;
}
function actb_godown(){
	if (!actb_display) return;
	if (actb_pos == actb_total){ 
	        actb_curr.value=(navigator.appName == "Microsoft Internet Explorer")?document.getElementById('tat_tr'+actb_pos).innerText:document.getElementById('tat_tr'+actb_pos).textContent;
	    return;
	}
	document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
	actb_pos++;
	if (actb_pos > actb_ranged) actb_movedown();
	document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hColor;
	if (actb_toid) clearTimeout(actb_toid);
	if (actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_timeOut);
    actb_curr.value=(navigator.appName == "Microsoft Internet Explorer")?document.getElementById('tat_tr'+actb_pos).innerText:document.getElementById('tat_tr'+actb_pos).textContent;
}
function actb_goup(){
	if (!actb_display) return;
	if (actb_pos == 1){
	    actb_curr.value=(navigator.appName == "Microsoft Internet Explorer")?document.getElementById('tat_tr'+actb_pos).innerText:document.getElementById('tat_tr'+actb_pos).textContent;
	    return;
	 }
	document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
	actb_pos--;
	if (actb_pos < actb_rangeu) actb_moveup();
	document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hColor;
	if (actb_toid) clearTimeout(actb_toid);
	if (actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_timeOut);
	actb_curr.value=(navigator.appName == "Microsoft Internet Explorer")?document.getElementById('tat_tr'+actb_pos).innerText:document.getElementById('tat_tr'+actb_pos).textContent;
}
function actb_movedown(){
	actb_rangeu++;
	actb_ranged++;
	actb_remake();
}
function actb_moveup(){
	actb_rangeu--;
	actb_ranged--;
	actb_remake();
}
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.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
	a.style.left = curLeft(actb_curr) + "px";
	a.style.backgroundColor=actb_bgColor;
	a.style.width='250px';
	a.id = 'tat_table';
	if (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_bgColor;
		c = r.insertCell(-1);
		c.style.color = actb_textColor;
		c.style.fontFamily = 'arial narrow';
		c.style.fontSize = actb_fSize;
		c.align='center';
		replaceHTML(c,'/\\');
		if (actb_mouse){
			c.style.cursor = 'pointer';
			c.onclick = actb_mouse_up;
		}
	}
	for (i=0;i<actb_keywords.length;i++){
		//if (actb_bool[i]){
			if (j >= actb_rangeu && j <= actb_ranged){
				r = a.insertRow(-1);
				r.style.backgroundColor = actb_bgColor;
				r.id = 'tat_tr'+(j);
				c = r.insertCell(-1);
				c.style.color = actb_textColor;
				c.style.fontFamily = actb_fFamily;
				c.style.fontSize = actb_fSize;
				c.innerHTML = actb_parse(actb_keywords[i]);
				c.id = 'tat_td'+(j);
				c.setAttribute('pos',j);
				if (actb_mouse){
					c.style.cursor = 'pointer';
					//c.onclick=actb_mouseclick;
					c.onmousedown=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_bgColor;
		c = r.insertCell(-1);
		c.style.color = actb_textColor;
		c.style.fontFamily = 'arial narrow';
		c.style.fontSize = actb_fSize;
		c.align='center';
		replaceHTML(c,'\\/');
		if (actb_mouse){
			c.style.cursor = 'pointer';
			c.onclick = actb_mouse_down;
		}
	}
}
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_penter(){
    if (!actb_display) return;
    actb_display = false;
    var word = '';var c = 0;
    for (var i=0;i<=actb_keywords.length;i++){
	     c++;
	    if (c == actb_pos){
		    word = actb_keywords[i];
		    break;
	    }
    }
	actb_curr.value = word;
	setCaret(actb_curr,word.length);
	actb_removedisp();
}
function actb_table_highlight(){
    actb_mouse_on_list = 1;
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = 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_hColor;
    if (actb_toid) clearTimeout(actb_toid);
    if (actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_timeOut);
}
function actb_removedisp(){
	actb_display = 0;
	if (document.getElementById('tat_table')){ 
	    document.body.removeChild(document.getElementById('tat_table')); 
	}
	if (actb_toid) clearTimeout(actb_toid);
}
function check()
{
    if(actb_display){document.getElementById('tat_table').style.display = 'none';}
}
//function SetEnd(TB){ //createRange()....for mozilla;  createTextRange...IE
//if (TB.createTextRange){
//var FieldRange = TB.createTextRange();
//FieldRange.moveStart('character', TB.value.length);
//FieldRange.collapse();
//FieldRange.select();}}

