/**
 * An autosuggest textbox control.
 * @class
 * @scope public
 */
 var iThis;
function AutoSuggestControl(oTextbox /*:HTMLInputElement*/,oSuggest,oSuggestor,oTargetUrl,oSearchType,oAjax,oUrl) {
       
    
    /**
     * The textbox to capture.
     * @scope private
     */
     iThis=this;
    this.textbox /*:HTMLInputElement*/ = oTextbox;
    this.eMultiSelect=oSuggestor;
    this.tbody=document.createElement('tbody');
    this.eMultiSelect.appendChild(this.tbody); 
	this.suggest=oSuggest;
    this.resultCount=0;
    this.loader=document.getElementById('suggestLoadingDiv');
    this.suggestIndexField=document.getElementById("suggestIndex");
    this.suggestIndex=this.suggestIndexField.value;
	this.targetUrl=oTargetUrl;
	if(oAjax){
	this.ajax=oAjax;
	this.url=oUrl;
	}else{
	this.ajax=false;
	this.url='';
	}
    this.processing=false;
    this.searchType=oSearchType
    
     this.onlineList="";
     this.privateList="";
     this.offlineList="";
        //initialize the control
    this.init();
    
}

/**
 * Autosuggests one or more suggestions for what the user has typed.
 * If no suggestions are passed in, then no autosuggest occurs.
 * @scope private
 * @param aSuggestions An array of suggestion strings.
 */
AutoSuggestControl.prototype.autosuggest = function () {
    var iCount=0;
     
    //make sure there's at least one suggestion
    if (this.aSuggestions.length > 0) {
	        //this.typeAhead(this.aSuggestions[0]);
			
			this.eMultiSelect.style.visibility="hidden";
            this.eMultiSelect.parentNode.style.visibility="hidden";

            
            while(this.tbody.hasChildNodes()){
            this.tbody.removeChild(this.tbody.firstChild);
            }
            
             
           
		for (i=0; i < this.aSuggestions.length; i++) {
			if (this.aSuggestions[i] != undefined || this.aSuggestions[i].trim() !="") {
                if(iCount<resultLimit){
				var eOption = document.createElement('tr');
                var eColumn = document.createElement('td');
                var eInput = document.createElement('input');
				eOption.setAttribute('id','suggestTr'+(iCount+1)); 
                eOption.setAttribute('style','width:150px;');
                eOption.setAttribute('index',iCount+1);
                eColumn.setAttribute('id',"suggestTd"+(iCount+1)); 
                eColumn.setAttribute('index',iCount+1);  
				eColumn.innerHTML = this.aSuggestions[i];
                eInput.setAttribute('type','hidden');
                eInput.setAttribute('id','id'+(iCount+1));
                eInput.setAttribute('value',this.aSuggestionsValues[i]);
                eOption.className="nonSelectedSuggestion";   
                eOption.appendChild(eColumn);
                eOption.appendChild(eInput);
				this.tbody.appendChild(eOption);    
                iCount++;
               }
			}
		}
		
    }
	if (iCount < 1) {
			this.eMultiSelect.style.visibility = 'hidden';
			this.eMultiSelect.parentNode.style.visibility= "hidden";
		}else{   
            this.eMultiSelect.style.visibility = 'visible';
            this.eMultiSelect.parentNode.style.visibility= 'visible';
            
                var oThis=this;
                for(var i=1;i<=iCount;i++){
                   var eOption=document.getElementById('suggestTr'+i);
                   eOption.onmouseover=function(oEvent){
                   if (!oEvent) {
                    oEvent = window.event;
                    }
           var dataId;       
          if(oEvent.srcElement){
            dataId=oEvent.srcElement.index;
			if(!dataId)
			   dataId=oEvent.srcElement.getAttribute('index');
         }else if(oEvent.target){
            dataId=(oEvent.target.getAttribute('index'));
			
         }  
          if(!dataId){
          dataId=oThis.suggestIndex;
          }
                       
                      
                       oThis.suggestIndex=dataId;
                       oThis.suggestIndexField.value =oThis.suggestIndex  ; 
                       oThis.selectResult();
                       
                   
                }
                 eOption.onmouseout=function(oEvent){
                   if (!oEvent) {
                    oEvent = window.event;
                    }
                    if(oEvent.srcElement){
            		dataId=oEvent.srcElement.index;
					if(!dataId)
			   dataId=oEvent.srcElement.getAttribute('index');
         }else{
            dataId=(oEvent.target.getAttribute('index'));
         }
          if(!dataId){
          dataId="f";
          }
                    
                    oThis.suggestIndex=dataId;
                       oThis.suggestIndexField.value =oThis.suggestIndex  ; 
                       oThis.selectResult();
                   }
                 
                 eOption.onclick=function(oEvent){
                   if (!oEvent) {
                    oEvent = window.event;
                    }
                   oThis.handleClick(oEvent);
                   }
                }
            this.resultCount=iCount;
		}
};


/////



  AutoSuggestControl.prototype.attachMouseEvents=function(i,className){
             var oThis=this;  
                   var eOption=document.getElementById('suggestTr'+i);
                   eOption.onmouseover=function(oEvent){
                   if (!oEvent) {
                    oEvent = window.event;
                    }
           var dataId;       
          if(oEvent.srcElement){
            dataId=oEvent.srcElement.index;
            if(!dataId)
               dataId=oEvent.srcElement.getAttribute('index');
         }else if(oEvent.target){
            dataId=(oEvent.target.getAttribute('index'));
            
         }  
          if(!dataId){
          dataId=oThis.suggestIndex;
          }
                       
                      
                       oThis.suggestIndex=dataId;
                       oThis.suggestIndexField.value =oThis.suggestIndex  ; 
                       oThis.selectResult();
                       
                   
                }
                 eOption.onmouseout=function(oEvent){
                   if (!oEvent) {
                    oEvent = window.event;
                    }
                    if(oEvent.srcElement){
                    dataId=oEvent.srcElement.index;
                    if(!dataId)
               dataId=oEvent.srcElement.getAttribute('index');
         }else{
            dataId=(oEvent.target.getAttribute('index'));
         }
          if(!dataId){
          dataId="f";
          }
                    
                    oThis.suggestIndex=dataId;
                       oThis.suggestIndexField.value =oThis.suggestIndex  ; 
                       oThis.selectResult();
                   }
                 
                 eOption.onclick=function(oEvent){
                   if (!oEvent) {
                    oEvent = window.event;
                    }
                   oThis.handleClick(oEvent);
                   }
                
  };

////New Processing for model List


/**
 * Autosuggests one or more suggestions for what the user has typed.
 * If no suggestions are passed in, then no autosuggest occurs.
 * @scope private
 * @param aSuggestions An array of suggestion strings.
 */
AutoSuggestControl.prototype.modelAutosuggest = function () {
    var iCount=0;
     
     while(this.tbody.hasChildNodes()){
            this.tbody.removeChild(this.tbody.firstChild);        
            }
     this.eMultiSelect.style.visibility="hidden";
     this.eMultiSelect.parentNode.style.visibility="hidden";
    //make sure there's at least one suggestion
    if (this.aSuggestions.length > 0 || this.aPrivateSuggestions.length > 0 || this.aOnlineSuggestions.length > 0) {
            
            this.eMultiSelect.style.visibility="hidden";
            this.eMultiSelect.parentNode.style.visibility="hidden";
           
            while(this.tbody.hasChildNodes()){
            this.tbody.removeChild(this.tbody.firstChild);
            }
    }
            var oLen=4;
            var pLen=3
            var offLen=3;
            var tLen=10;
            
            if(this.aOnlineSuggestions.length<oLen){
            oLen=this.aOnlineSuggestions.length;
            }
          
            if(this.aPrivateSuggestions.length<pLen){
            pLen=this.aPrivateSuggestions.length;
            }
        
             if(oLen+pLen<7){
                if(oLen<pLen){
                pLen=7-oLen;
             }
                else{
                oLen=7-pLen;
             }
             }
 
            if(oLen+pLen+offLen<10){
            offLen=10-pLen+oLen;
            }
            if(this.aSuggestions.length<offLen){
            offLen=this.aSuggestions.length;
            }


            
            
         //  alert("On "+oLen+" P "+pLen+" Off "+offLen); 
            
          //  alert(this.aOnlineSuggestions.length+"  "+oLen);            
            if(this.aOnlineSuggestions.length>=1){ 
                var eOption = document.createElement('tr');
                var eColumn = document.createElement('td');
                eOption.setAttribute('style','width:150px;');
                eColumn.innerHTML = suggestListOnline; 
                eOption.className="suggestionLabel"; 
                eOption.appendChild(eColumn);  
                this.tbody.appendChild(eOption);   
                for (i=0; i < this.aOnlineSuggestions.length; i++) {
                if (this.aOnlineSuggestions[i] != undefined || this.aOnlineSuggestions[i].trim() !="") {
                if(iCount<resultLimit && iCount<(oLen)){
                var eOption = document.createElement('tr');
                var eColumn = document.createElement('td');
                var eInput = document.createElement('input');
                eOption.setAttribute('id','suggestTr'+(iCount+1)); 
                eOption.setAttribute('style','width:150px;');
                eOption.setAttribute('index',iCount+1);
                eColumn.setAttribute('id',"suggestTd"+(iCount+1)); 
                eColumn.setAttribute('index',iCount+1);  
                eColumn.innerHTML = this.aOnlineSuggestions[i];
                eInput.setAttribute('type','hidden');
                eInput.setAttribute('id','id'+(iCount+1));
                eInput.setAttribute('value',this.aOnlineSuggestionsValues[i]);
                eOption.className="nonSelectedSuggestion";
                eOption.appendChild(eColumn);
                eOption.appendChild(eInput);
                this.tbody.appendChild(eOption);  
                iCount++;
                this.attachMouseEvents(iCount);
               }else{
               break;
               }
            }
        }
            }
        if(this.aPrivateSuggestions.length>=1 ){
         var eOption = document.createElement('tr');
                var eColumn = document.createElement('td');
                eOption.setAttribute('style','width:150px;');
                eColumn.innerHTML = suggestListPrivate;
                eOption.className="suggestionLabel";    
                eOption.appendChild(eColumn);  
                this.tbody.appendChild(eOption); 
        for (i=0; i < this.aPrivateSuggestions.length; i++) {
            if (this.aPrivateSuggestions[i] != undefined || this.aPrivateSuggestions[i].trim() !="") {
                if(iCount<resultLimit && (iCount-oLen)<pLen){
                var eOption = document.createElement('tr');
                var eColumn = document.createElement('td');
                var eInput = document.createElement('input');
                eOption.setAttribute('id','suggestTr'+(iCount+1)); 
                eOption.setAttribute('style','width:150px;');
                eOption.setAttribute('index',iCount+1);
                eColumn.setAttribute('id',"suggestTd"+(iCount+1)); 
                eColumn.setAttribute('index',iCount+1);  
                eColumn.innerHTML = this.aPrivateSuggestions[i];
                eInput.setAttribute('type','hidden');
                eInput.setAttribute('id','id'+(iCount+1));
                eInput.setAttribute('value',this.aPrivateSuggestionsValues[i]);
                eOption.className="nonSelectedSuggestion";
                eOption.appendChild(eColumn);
                eOption.appendChild(eInput);
                this.tbody.appendChild(eOption);    
                iCount++;
                this.attachMouseEvents(iCount);  
               }
               else{
               break;
               }
            }
        }     
        }
        //alert(this.aSuggestions.length);
        if(this.aSuggestions.length>=1 && iCount<resultLimit){ 
         var eOption = document.createElement('tr');
                var eColumn = document.createElement('td');
                eOption.setAttribute('style','width:150px;');
                eColumn.innerHTML = suggestListOffline; 
                eOption.className="suggestionLabel";   
                eOption.appendChild(eColumn);  
                this.tbody.appendChild(eOption);    
        for (i=0; i < this.aSuggestions.length; i++) {
            if (this.aSuggestions[i] != undefined || this.aSuggestions[i].trim() !="") {
                if(iCount<resultLimit){
                var eOption = document.createElement('tr');
                var eColumn = document.createElement('td');
                var eInput = document.createElement('input');
                eOption.setAttribute('id','suggestTr'+(iCount+1)); 
                eOption.setAttribute('style','width:150px;');
                eOption.setAttribute('index',iCount+1);
                eColumn.setAttribute('id',"suggestTd"+(iCount+1)); 
                eColumn.setAttribute('index',iCount+1);  
                eOption.className="suggestionLabel";
                eColumn.innerHTML = this.aSuggestions[i];
                eInput.setAttribute('type','hidden');
                eInput.setAttribute('id','id'+(iCount+1));
                eInput.setAttribute('value',this.aSuggestionsValues[i]);
                eOption.appendChild(eColumn);
                eOption.appendChild(eInput);
                this.tbody.appendChild(eOption);    
                iCount++;
                this.attachMouseEvents(iCount);  
               }
               else{
               break;
               }
            }
        }
        }
        
    
    if (iCount < 1) {
            this.eMultiSelect.style.visibility = 'hidden';
            this.eMultiSelect.parentNode.style.visibility= "hidden";
        }else{   
            this.eMultiSelect.style.visibility = 'visible';
            this.eMultiSelect.parentNode.style.visibility= 'visible';
            
                
            this.resultCount=iCount;
        }
};





//AutoSuggestControl.prototype.handleBlur = function (oEvent /*:Event*/) {
/*     this.eMultiSelect.style.visibility = 'hidden';  
     this.eMultiSelect.parentNode.style.visibility= 'hidden';
};
*/
//AutoSuggestControl.prototype.handleBlur = function (oEvent /*:Event*/) {
/*     this.eMultiSelect.style.visibility = 'hidden';  
     this.eMultiSelect.parentNode.style.visibility= 'hidden';        
};    
  */
//AutoSuggestControl.prototype.handleSelect = function (oEvent /*:Event*/) { 
		//this.textbox.value=this.eMultiSelect.options[this.eMultiSelect.selectedIndex].text;
		
//};


AutoSuggestControl.prototype.handleSelectKeyUp = function (oEvent /*:Event*/) {

    var iKeyCode = oEvent.keyCode;
       
    //make sure not to interfere with non-character keys
    if (iKeyCode == 13) {
        //ignore
         this.eMultiSelect.style.visibility = 'hidden';
         this.eMultiSelect.parentNode.style.visibility= 'hidden';
    }
};


AutoSuggestControl.prototype.handleClick = function (oEvent /*:Event*/) {
         this.eMultiSelect.style.visibility = 'hidden';
         this.eMultiSelect.parentNode.style.visibility= "hidden";
         var dataId=0;
         if(oEvent.srcElement){
            dataId=oEvent.srcElement.getAttribute('index');
         }else{
            dataId=(oEvent.target.getAttribute('index'));
         }
          if(!dataId){
          dataId=this.suggestIndex;
          }
		 
		 if(document.getElementById('id'+dataId).value)
		 {
         var did=document.getElementById('id'+dataId).value;
		 }
		 
		 var location=this.targetUrl+did;
         location= location.replace(/\&amp;/g,'&');
         //alert(location);
        document.location=location; 
};

//AutoSuggestControl.prototype.handleChange = function (oEvent /*:Event*/) {
    
         //this.eMultiSelect.options[this.eMultiSelect.selectedIndex].style.selected="#FFFFFF"; 
//};

/**
 * Handles keyup events.
 * @scope private
 * @param oEvent The event object for the keyup event.
 */
AutoSuggestControl.prototype.handleKeyUp = function (oEvent /*:Event*/) {

    var iKeyCode = oEvent.keyCode;
	                  //alert(iKeyCode);
    //make sure not to interfere with non-character keys
    if ((iKeyCode!=8 && iKeyCode < 32) || (iKeyCode >= 33 && iKeyCode <= 46) || (iKeyCode >= 112 && iKeyCode <= 123)) {
        if(this.eMultiSelect.style.visibility=="visible"){ 
        if(iKeyCode==40){
        if(this.suggestIndex=="f"){
            this.suggestIndex=1;
            this.suggestIndexField.value= this.suggestIndex;
        }else if(this.suggestIndex==this.resultCount) {
            this.suggestIndex="f";
            this.suggestIndexField.value =this.suggestIndex  ;
        }
        else{
            this.suggestIndex++;
            this.suggestIndexField.value= this.suggestIndex ;
        }
         this.selectResult();
        }else if(iKeyCode==38){
                if(this.suggestIndex=="f"){
            this.suggestIndex=this.resultCount;
            this.suggestIndexField.value =this.suggestIndex  ;
        }else if(this.suggestIndex==1){
              this.suggestIndex="f";
            this.suggestIndexField.value =this.suggestIndex  ;
        }
        else{
            this.suggestIndex--;
            this.suggestIndexField.value =this.suggestIndex  ;
        }
        this.selectResult();
        }else if(iKeyCode==13){
       this.handleClick(oEvent);
        } 
        
        }
        //ignore
    } else {
        //request suggestions from the suggestion provider
		
             while(this.tbody.hasChildNodes()){
            this.tbody.removeChild(this.tbody.firstChild);        
            }
		if(this.ajax){
        if(this.textbox.value.length==charLimit && this.textbox.value.trim()!=""){
        this.suggest.value="";
        var tempUrl=this.url+'&SearchText='+this.textbox.value;
		this.getXMLObject();
        var xml=this.xmlHttp;
        var sugg=this.suggest;
        if(this.textbox.value.length>=charLimit && iKeyCode!=8 ){
        
        this.loader.style.visibility='visible';
        this.loader.style.height='25px';
        }
        var oThis = this;
		this.xmlHttp.onreadystatechange=function (){
        if(oThis.xmlHttp.readyState==4 || oThis.xmlHttp.readyState=="complete"){
        oThis.eMultiSelect.style.visibility = 'visible';
        oThis.eMultiSelect.parentNode.style.visibility= 'visible';
        oThis.loader.style.visibility='hidden';
        oThis.loader.style.height='0px';
        oThis.suggest.value=oThis.xmlHttp.responseText;
        oThis.tempValue=oThis.textbox.value;
        oThis.eMultiSelect.style.visibility = 'hidden';
        oThis.eMultiSelect.parentNode.style.visibility= "hidden";
           if(oThis.textbox.value.length<charLimit && iKeyCode==8 ){
           oThis.loader.style.visibility='hidden';
           oThis.loader.style.height='0px';

            }else{
        oThis.processList(oThis.textbox.value);
            }
        
        }
        }
		this.xmlHttp.open("GET",tempUrl,true)
		this.xmlHttp.send(null);
		}
		}
		if(this.textbox.value.length>charLimit){
            this.tempValue=this.textbox.value;
            this.processList(this.textbox.value);
       }
    
	}
   
    if(this.textbox.value.length<charLimit){
            this.eMultiSelect.style.visibility = 'hidden';
            this.eMultiSelect.parentNode.style.visibility= "hidden";
    }
};

AutoSuggestControl.prototype.selectResult=function(className){
		 // alert(this.suggestIndex);
         //var selClass="nonSelectedSuggestion";
         
          if(this.suggestIndex!="f"){
          for(var i=1;i<=this.resultCount;i++)
          if(document.getElementById("suggestTr"+i).className=="selectedSuggestionLabel")
          document.getElementById("suggestTr"+i).className="suggestionLabel";
          else if(document.getElementById("suggestTr"+i).className=="selectedSuggestion")
          document.getElementById("suggestTr"+i).className="nonSelectedSuggestion";
          var sel=document.getElementById("suggestTr"+this.suggestIndex);
		  
		  //alert(document.getElementById("suggestTd"+this.suggestIndex));
          this.textbox.value= document.getElementById("suggestTd"+this.suggestIndex).innerHTML; 
          if(sel.className=="nonSelectedSuggestion")
          sel.className="selectedSuggestion";
          else
          sel.className="selectedSuggestionLabel"; 
          }else if(this.suggestIndex=="f"){
          for(var i=1;i<=this.resultCount;i++)
          if(document.getElementById("suggestTr"+i).className=="selectedSuggestionLabel")
          document.getElementById("suggestTr"+i).className="suggestionLabel";
          else if(document.getElementById("suggestTr"+i).className=="selectedSuggestion")
          document.getElementById("suggestTr"+i).className="nonSelectedSuggestion";
          this.textbox.value=this.tempValue;
          }
}  ;

/*AutoSuggestControl.prototype.handler= function (oThis){
//var oThis = this;
//alert('hello');    
        if(oThis.xmlHttp.readyState==4 || oThis.xmlHttp.readyState=="complete")
       
        oThis.suggest.value=oThis.xmlHttp.responseText;
        oThis.eMultiSelect.style.visibility="visible";
        oThis.eMultiSelect.parentNode.style.visibility="visible";
        }  ;
   
/**
 * Initializes the textbox with event handlers for
 * auto suggest functionality.
 * @scope private
 */
AutoSuggestControl.prototype.init = function () {

    //save a reference to this object
    var oThis = this;
    
    //assign the onkeyup event handler
    this.textbox.onkeyup = function (oEvent) {
    
        //check for the proper location of the event object
        if (!oEvent) {
            oEvent = window.event;
        }    
        
        //call the handleKeyUp() method with the event object
        oThis.handleKeyUp(oEvent);
    };
    this.textbox.onfocus=function(oEvent){
          if (!oEvent) {
            oEvent = window.event;
        }
        if(oThis.textbox.value==defaultText){
			document.getElementById('suggestOurBoxInner').style.height="250px";
           oThis.textbox.value="";
        }
    }
    this.textbox.onblur=function(oEvent){
          if (!oEvent) {
            oEvent = window.event;
        }
        if(oThis.textbox.value.trim()==''){
		   document.getElementById('suggestOurBoxInner').style.height="0px";			
           oThis.textbox.value=defaultText;
        }
    }
	/*
    this.eMultiSelect.onblur= function (oEvent) {
            //check for the proper location of the event object
        if (!oEvent) {
            oEvent = window.event;
        }    
        
        oThis.handleBlur(oEvent);
    };
    
    this.eMultiSelect.onkeyup = function (oEvent) {
    
        //check for the proper location of the event object
        if (!oEvent) {
            oEvent = window.event;
        }    
        
        //call the handleKeyUp() method with the event object
        oThis.handleSelectKeyUp(oEvent);
    };
    this.eMultiSelect.onclick= function (oEvent) {
        //check for the proper location of the event object
        if (!oEvent) {
            oEvent = window.event;
        }    
        
        //call the handleKeyUp() method with the event object
        oThis.handleClick(oEvent)
    };
      */
   
     
};

/**
 * Selects a range of text in the textbox.
 * @scope public
 * @param iStart The start index (base 0) of the selection.
 * @param iLength The number of characters to select.
 */
//AutoSuggestControl.prototype.selectRange = function (iStart /*:int*/, iLength /*:int*/) {

    //use text ranges for Internet Explorer
 /*   if (this.textbox.createTextRange) {
        var oRange = this.textbox.createTextRange(); 
        oRange.moveStart("character", iStart); 
        oRange.moveEnd("character", iLength - this.textbox.value.length);      
        oRange.select();
        
    //use setSelectionRange() for Mozilla
    } else if (this.textbox.setSelectionRange) {
        this.textbox.setSelectionRange(iStart, iLength);
    }     

    //set focus back to the textbox
    this.textbox.focus();      
}; 

/**
 * Inserts a suggestion into the textbox, highlighting the 
 * suggested part of the text.
 * @scope private
 * @param sSuggestion The suggestion for the textbox.
 */
//AutoSuggestControl.prototype.typeAhead = function (sSuggestion /*:String*/) {

    //check for support of typeahead functionality
/*    if (this.textbox.createTextRange || this.textbox.setSelectionRange){
        var iLen = this.textbox.value.length; 
        this.textbox.value = sSuggestion; 
        this.selectRange(iLen, sSuggestion.length);
    }
};
  */
AutoSuggestControl.prototype.getXMLObject=function(){
this.xmlHttp=null;
	try
  	{
  	  	this.xmlHttp=new XMLHttpRequest();
  	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			this.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			this.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
 	}
};



AutoSuggestControl.prototype.processList=function(val){
this.processing=true;
if(this.searchType=="model"){
this.processModelList(val);
}else{
this.aSuggestions=[];
this.aSuggestionsValues=[];
 
 if(this.suggest.value.trim()!=""){
 this.suggestions=this.suggest.value.split(',');     

 if (val.length > 0){
		//search for matching words
        for (var i=0; i < this.suggestions.length; i++) { 
            if(!skipSearch){
            if (this.suggestions[i].toLowerCase().indexOf(val.toLowerCase()) == 0 ) {
                 var suggestArr=this.suggestions[i].split('-');
                 this.aSuggestions.push(suggestArr[0]);
                 this.aSuggestionsValues.push(suggestArr[1]);
            }         
            }else{
                if (this.suggestions[i].toLowerCase().indexOf(val.toLowerCase()) >= 0 ) {
                 var suggestArr=this.suggestions[i].split('-');
                 this.aSuggestions.push(suggestArr[0]);
                 this.aSuggestionsValues.push(suggestArr[1]);
            }         
            }
            
        }
    }
}
	this.autosuggest();
}
this.processing=false;
};

AutoSuggestControl.prototype.processModelList=function(val){


this.aPrivateSuggestions=[];
this.aPrivateSuggestionsValues=[];

this.aOnlineSuggestions=[];
this.aOnlineSuggestionsValues=[];

this.aSuggestions=[];
this.aSuggestionsValues=[];

 
 if(this.suggest.value.trim()!=""){
 var groups=this.suggest.value.split('|');
 this.onlineList=groups[0];
 this.privateList=groups[1];
 this.offlineList=groups[2];
 
 if (this.onlineList){   
 this.suggestions=this.onlineList.split(',');     

 
        //search for matching words
        for (var i=0; i < this.suggestions.length; i++) { 
                var suggestArr=this.suggestions[i].split('-'); 
                if (suggestArr[0].toLowerCase().indexOf(val.toLowerCase()) >= 0 ) {
                 
                 this.aOnlineSuggestions.push(suggestArr[0]);
                 this.aOnlineSuggestionsValues.push(suggestArr[1]);
            }
            
        }
    }


 if (this.privateList){ 
this.suggestions=this.privateList.split(',');     
     

        //search for matching words
        for (var i=0; i < this.suggestions.length; i++) { 
         var suggestArr=this.suggestions[i].split('-'); 
              if (suggestArr[0].toLowerCase().indexOf(val.toLowerCase()) >= 0 ) {
                 this.aPrivateSuggestions.push(suggestArr[0]);
                 this.aPrivateSuggestionsValues.push(suggestArr[1]);
           
        }
    }
}

 if (this.offlineList){ 
this.suggestions=this.offlineList.split(',');     


        //search for matching words
        for (var i=0; i < this.suggestions.length; i++) { 
        var suggestArr=this.suggestions[i].split('-');
              if (suggestArr[0].toLowerCase().indexOf(val.toLowerCase()) >= 0 ) {
                 
                 this.aSuggestions.push(suggestArr[0]);
                 this.aSuggestionsValues.push(suggestArr[1]);
           
        }
    }
}

 }
    this.modelAutosuggest();
  
};




String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }


function closeSuggestions(){
	  document.getElementById("suggestOurBoxInner").style.height="0px";
      iThis.eMultiSelect.style.visibility = 'hidden';
      iThis.eMultiSelect.parentNode.style.visibility="hidden";
      iThis.suggestIndex="f";
      iThis.textbox.value=defaultText;
}
