﻿// JScript File

        function fnddjs1(sndr,evt,arr,searchbx,search4)
        {
          
            document.getElementById("id1").value="";
            var t
            t=document.getElementById(searchbx).value
            s='';
           //alert(t);
            if (t.length>=3)
            {
                customarray1[0]="Searching...Please Wait"
                customarray[0]="Searching...Please Wait"
                for(var v=1;v<=5;v++)
                    {
                        customarray1[v]="";
                        customarray[v]="";
                    }
                //actb_keywords[0]="Searching...Please Wait"
                showdropdown1(sndr,evt,arr,searchbx,search4)
                
                var strurl;
               
               if(search4=='100')
                {
                strurl=server_url + "searchccg.aspx?f=list&name=" + document.getElementById(searchbx).value +"&within=1";
                }
                else
                {
                strurl=server_url + "searchajx.aspx?f=list&name=" + document.getElementById(searchbx).value + "&cs="+search4
                }
                             
                openXMLCon()
                    
                  xmlhttp.onreadystatechange=function() {
                  if (xmlhttp.readyState==4) 
                  {
                  var s=new String(xmlhttp.responseText);
                  //alert(s)
                    if (s.length==0)
                        {
                            customarray1='';
                            customarray=''
                            actb_keywords='';
                            actb_removedisp1();
                            return;
                        }
                    
                    s=s.substring(0,s.length-1);
                    //document.form1.txtarea.value=s;
                    var arrstr=s.split("^")
                    //customarray1=""
                    //customarray=""
                    customarray1=s.split("^")
                    //customarray=s.split(",")
                    customarray=s.split("^")
                    var innerstr
                    innerstr='';
                    var temp =new String();
                    var si;
                    //alert(customarray1.length);
                    for(var i=0;i<customarray1.length;i++)
                        {
                            temp=customarray1[i]
                            //alert(temp);
                            si=temp.indexOf("~");
                            temp=temp.substring(0,si);
                            customarray1[i]=temp;
                            
                           
                        }
                        
                   //alert(customarray1.length);
                    flagdisplay=true;
              
                    showdropdown1(sndr,evt,arr,searchbx,search4)
                  }
                  
                 }
                 //alert(strurl);
                 xmlhttp.open("GET", strurl,true);
                 xmlhttp.send(null)
                }
                }
        
     function fnloaddefxml(id)
        {
        profile="";
        fnprofile_table()
        flagprof_display=false;
           openXMLCon()  
           var strurl
          strurl=server_url + "searchajx.aspx?f=profile&id=" + id
          xmlhttp.onreadystatechange=function() {
                    //alert(xmlhttp.readyState);
                  if (xmlhttp.readyState==4) 
                  {
                    profile=new String(xmlhttp.responseText);
                    flagprof_display=true
                    fnprofile_table();
                    //alert(s)
                    //return s;
                    //flagdisplay=true;
                  }
               }   
                 xmlhttp.open("GET", strurl,true);
                 xmlhttp.send(null)
        }

/* ---- Variables ---- */
var actb_timeOut = -1; // Autocomplete Timeout in ms (-1: autocomplete never time out)
var actb_lim = 200;    // Number of elements autocomplete can show (-1: no limit)
var actb_firstText = false; // should the auto complete be limited to the beginning of keyword?
/* ---- Variables ---- */

/* --- Styles --- */
var actb_bgColor = '#faedfc';
var actb_textColor = 'Black';
var actb_hColor = '#faedfc';
var actb_fFamily = 'Trebuchet MS';
var actb_fSize = '12px';
var actb_hStyle = 'text-decoration:underline;font-weight="bold"';
/* --- Styles --- */

/* ---- Constants ---- */
var actb_keywords = 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;
/* ---- Constants ---- */
var txtthis;
var thisevent;
var cursel;
var actb_top_pos;
var actb_left_pos;
function actb_parse(n){


	//alert(actb_curr.value);
    var t = escape(actb_curr.value);
    var tobuild = '';
    var i;
    if (actb_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 += ""
    for (i=p;i<t.length+p;i++){
        tobuild += n.substr(i,1);
    }
    tobuild += "";
    for (i=t.length+p;i<n.length;i++){
        tobuild += n.substr(i,1);
    }
		 if(actb_curr.value.search(",")>0)
            {
	            tobuild = tobuild.substr(1);
	        }
	        else
			{
				tobuild = tobuild.substr(0);
	        }
	     
    //alert(tobuild);
    return tobuild;
}
function actb_generate1(actb_bool,searchbx,search4){
//alert('deepak');
//alert(customarray1.length);
//alert(actb_bool)
   if (document.getElementById('deep1')) document.body.removeChild(document.getElementById('deep1'));
//    if (document.getElementById('deep1')) document.body.removeChild(document.getElementById('deep1'));
   var ni = document.createElement('Div');
   
ni.setAttribute('id','deep1');

   //b.id='deep';
//n1.Class='scrollbar';
//ni.style.height='40px';
//ni.style.width='200px';
//ni.style.overflow='Auto';
    a = document.createElement('table');
    a.cellSpacing='1px';
    a.cellPadding='2px';
    a.width='140px';
//    a.height='100px'
    a.border='1px';
//    a.style.position='absolute';
  actb_top_pos= eval(curTop() + actb_curr.offsetHeight) + "px";
   actb_left_pos= curLeft() + "px";
  // ni.style.top =actb_top_pos;
//   a.style.left =actb_left_pos;
  a.style.backgroundColor=actb_bgColor;
    a.id = 'tat_table';
   ni.style.height='200px';
    ni.style.width='140px';
   ni.style.overflow='Auto';
    ni.className = 'scrollbar';
    ni.style.top =actb_top_pos; 
    ni.style.position='absolute';
     ni.style.left =actb_left_pos;
        if (document.getElementById('deep1')) alert('Yes1');
   //document.getElementById(deep1).className = 'scrollbar'; 
 ni.appendChild(a);
     document.body.appendChild(ni);
    //

   
//document.getElementById('div1').appendchild(document.getElementById('tat_table')));
  
    var tword;
    var i;
    var first = true;
    var j = 1;
    var counter = 0;
    //actb_lim=50;
    actb_total=customarray1.length
    //alert(actb_total);
  //alert(customarray1.length);
    for (i=0;i<customarray1.length;i++)
        {
          //alert(customarray1[i])
            counter++;
            r = a.insertRow(-1);
             if (first && !actb_tomake){
                r.style.backgroundColor = actb_hColor;
                first = false;
                actb_pos = counter;
                cursel=actb_pos;
            }else if(actb_pre == i){
                r.style.backgroundColor = actb_hColor;
                first = false;
                actb_pos = counter;
                cursel=actb_pos;
            }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.align='left';
            tword=customarray1[i];
            //entry_id1=tword.split("~");
            //entry_id[i]=entry_id1[1];
            //tword=entry_id1[0];
            tword=tword.toLowerCase();
            tword=tword.replace(document.getElementById(searchbx).value,"<u>" + document.getElementById(searchbx).value + "</u>")
            tword=tword.toUpperCase()
            //alert(tword)
            if((i==0) && (customarray1[0]=="Searching...Please Wait"))
            {
                c.innerHTML =tword;
            }
            else
            {
                c.innerHTML ="<a  href=javascript:fnpopup1(" + j +",'"+searchbx+"','"+search4+ "') class=link2>" + tword + "</a>";
            }
            c.id = 'tat_td'+(j);
            j++;
            
        if (j - 1 == actb_lim && j < actb_total){
            r = a.insertRow(-1);
            r.style.backgroundColor = actb_bgColor;
            c = r.insertCell(-1);
            c.style.color = actb_textColor;
            c.style.fontFamily = 'Georgia narrow';
            c.style.fontSize = actb_fSize;
            c.align='left';
			c.innerHTML = '<a  href=javascript:actb_godown("'+searchbx+'",'+search4+')><img src=images/down-arrow.gif border="0" width=10 align="right"></a>';
           break;
        }
    }
   
  if (actb_pos <= 0) actb_pos = 1;
}
function curTop1(){
    actb_toreturn = 0;
    obj = actb_curr;
    while(obj){
        actb_toreturn += obj.offsetTop;
        obj = obj.offsetParent;
    }
    return actb_toreturn;
}
function curLeft1(){
    actb_toreturn = 0;
    obj = actb_curr;
    while(obj){
        actb_toreturn += obj.offsetLeft;
        obj = obj.offsetParent;
    }
    return actb_toreturn;
}
function actb_remake1(searchbx,search4){
 if (document.getElementById('deep1')) document.body.removeChild(document.getElementById('deep1'));
   var ni = document.createElement('Div');
   
ni.setAttribute('id','deep1');

    a = document.createElement('table');
    a.cellSpacing='1px';
    a.cellPadding='2px';
   a.width='210px';
//    a.height='100px'
    a.border='1px';
//    a.style.position='absolute';
  actb_top_pos= eval(curTop() + actb_curr.offsetHeight) + "px";
   actb_left_pos= curLeft() + "px";
  // ni.style.top =actb_top_pos;
//   a.style.left =actb_left_pos;
//   a.style.backgroundColor=actb_bgColor;
    a.id = 'tat_table';
   ni.style.height='250px';
    ni.style.width='210px';
   ni.style.overflow='Auto';
    ni.className = 'scrollbar';
    ni.style.top =actb_top_pos; 
    ni.style.position='absolute';
     ni.style.left =actb_left_pos;
        if (document.getElementById('deep1')) alert('Yes1');
   //document.getElementById(deep1).className = 'scrollbar'; 
 ni.appendChild(a);
     document.body.appendChild(ni);

    var i;
    var first = true;
    var j = 1;
    var tword
    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 = 'Georgia narrow';
        c.style.fontSize = actb_fSize;
        c.align='left';
     
        c.innerHTML = '<a href=javascript:actb_goup("'+searchbx+'",'+search4+')><img src=images/up-arrow.gif border="0" width=10 align="right"></a>';
    }
    actb_total=customarray1.length
    for (i=0;i<customarray1.length;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.align='left';

                tword=customarray1[i];
                tword=tword.toLowerCase()
                tword=tword.replace(document.getElementById(searchbx).value,"<u>" + document.getElementById(searchbx).value + "</u>")
                tword=tword.toUpperCase()

                if((i==0) && (customarray1[0]=="Searching...Please Wait"))
                {
                    c.innerHTML =tword;
                }
                else
                {
                    c.innerHTML ="<a  href=javascript:fnpopup1(" + j +",'"+searchbx+"','"+search4+ "') onmouseover=fnmouseover(" + j + ") onmouseout=fnremovedef()  class=link2>" + tword + "</a>";
                }
                c.id = 'tat_td'+(j);
                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 = 'Georgia narrow';
        c.style.fontSize = actb_fSize;
        c.align='left';
        c.innerHTML = '<a  href=javascript:actb_godown("'+searchbx+'",'+search4+')><img src=images/down-arrow.gif border="0" width=10 align="right"></a>';
    }
}
function actb_goup1(searchbx,search4){
	actb_pos=cursel;
    if (!actb_display) return;
    if (actb_pos == 1) return;
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
    actb_pos--;
    if (actb_pos < actb_rangeu) actb_moveup1(searchbx,search4);
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hColor;
    cursel=actb_pos;
    if (actb_toid) clearTimeout(actb_toid);
    if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp1()",actb_timeOut);
    fnmouseover1(actb_pos);
}
function actb_godown1(searchbx,search4){

    if(customarray.length>1)
    {
	    
	    actb_pos=cursel;
        if (!actb_display) return;
        if (actb_pos == actb_total) return;
        document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
        actb_pos++;
        if (actb_pos > actb_ranged) actb_movedown(searchbx,search4);
        document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hColor;
        cursel=actb_pos;
        if (actb_toid) clearTimeout(actb_toid);
        if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
        fnmouseover1(actb_pos);
    }
}
function actb_movedown1(searchbx,search4){
    actb_rangeu++;
    actb_ranged++;
    actb_remake1(searchbx,search4);
}
function actb_moveup1(searchbx,search4){
    actb_rangeu--;
    actb_ranged--;
    actb_remake1(searchbx,search4);
}
function actb_penter1(){
//     fnddjs()
    if (!actb_display) return;
    actb_display = 0;
    var word = '';
    var temp1 = new String();
    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];
            word=customarray1[i];
            temp1=customarray[i];
            //alert(temp);
            si=temp1.indexOf("~");
            temp1=temp1.substr(si+1,temp1.length)
            document.getElementById("id1").value=temp1;
            break;
        }
    }
    a = word;//actb_keywords[actb_pos-1];//document.getElementById('tat_td'+actb_pos).;
     var t = actb_curr.value;
    //var n1=t.lastIndexOf(",")
	//t=t.substr(0,n1+1);
	
    //actb_curr.value =actb_curr.value + a;
    actb_curr.value =a;
    actb_removedisp1();
}
function actb_removedisp1(){
    actb_display = 0;
    if (document.getElementById('deep1')) document.body.removeChild(document.getElementById('deep1'));

}
function actb_checkkey1(evt,searchbx,search4){
    a = evt.keyCode;
   
//alert('a');
    if (a == 38){ // up key
        actb_goup1(searchbx,search4);
    }else if(a == 40){ // down key
        actb_godown1(searchbx,search4);
    }else if(a ==13){
        //actb_penter();
            fnremovedef1()
        fnpopup1(actb_pos,searchbx,search4);
     
    }
    else if(a ==27){
       actb_removedisp1();
    }
    
    //this.focus();
}
function actb_tocomplete1(sndr,evt,arr,searchbx,search4){
    
       if ((evt.type=="keyup") && (document.getElementById(searchbx).value==''))
        {
            actb_removedisp1();
        }
        
    if (evt.keyCode == 38 || evt.keyCode == 40 || evt.keyCode == 13) return;
    flagdisplay=false;
    fnddjs1(sndr,evt,arr,searchbx,search4)
   
}
function showdropdown1(sndr,evt,arr,searchbx,search4)
    {
    //alert(arr.length)
    //alert('c');
      flagdisplay=true
    if  (flagdisplay==true)
        {
       
    txtthis=sndr;
	thisevent=evt;
 	//if (arr) actb_keywords = arr;
 	actb_keywords = arr;
 	var i;
 	//alert('a');
    if (actb_display){ 
    //alert(actb_keywords.length);
        var word = 0;
        var c = 0;
        
        for (var 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;

    if (sndr.value == ''){
        actb_removedisp1();
        return;
    }
    var t = sndr.value;
    var n1=t.lastIndexOf(",")
    //alert(t.substr(n1))
	if((t.substr(n1))==',')
		{
			t=t.substr(n1);
		}
	else
		{
			t=t.substr(n1+1);
		}
	if (actb_firstText){
        var re = new RegExp("^" + t, "i");
    }
    else{
        var re = new RegExp(t, "i");
    }
    
    actb_total = 0;
    actb_tomake = false;
    for (i=0;i<actb_keywords.length;i++){
        actb_bool[i] = false;
        if (re.test(actb_keywords[i])){
            actb_total++;
            actb_bool[i] = true;
            if (actb_pre == i) actb_tomake = true;
        }
    }
    
    if (actb_toid) clearTimeout(actb_toid);
      //alert(actb_timeOut);
    if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp1()",actb_timeOut);
   
actb_removedisp1();
   
//    fnremovedef();
     
    var tvalue=document.getElementById(searchbx).value
      
      //alert(tvalue.length);
    if (tvalue.length>=3)
        {
       //alert('deep');
            actb_generate1(actb_bool,searchbx,search4);        
        }
    else
        {
             fnremovedef1()
        }
    }  
    
    }

function fnremovedef1()
    {
//         actb_display = 0;

    if (document.getElementById('def_table')) document.body.removeChild(document.getElementById('def_table'));
//    if (actb_toid) clearTimeout(actb_toid);
    }
function fnsearchgo1(searchbx,search4)
    {
    
        if(document.getElementById("id1").value!="")
            {
                if(searchbx=='companyname' || searchbx=='peoplename')
                {
                
                }
                else
                {
                if(search4=='100')
                {
                window.location=server_url + "innerpage.aspx?" + document.getElementById("id1").value;
                }
                else
                {
                window.location=server_url + "viewprofile.aspx?id=" + document.getElementById("id1").value;
                }
                }
            }
        else if((document.getElementById(searchbx).value!="" ) && (document.getElementById("id1").value==""))
            {
                window.location=server_url + "searchsoul.aspx?ufrom=searchsoul&type=basic&identyfier="+ search4;
            }
    }

function fnpopup1(k,searchbx,search4)
	{
	
	 if (customarray!='')
	    {
	   	fnremovedef()
		actb_pos=k-1;
		actb_curr.value =customarray1[k-1];
		actb_removedisp();
		
		var temp1
		temp1=customarray[k-1];
        si=temp1.indexOf("~");
        temp1=temp1.substr(si+1,temp1.length)
        document.getElementById("id1").value=temp1;
        
        fnsearchgo1(searchbx,search4);
        //alert(temp1);
		//actb_penter()
		}
	}

