// JavaScript Document
function AutoComplete_Callback(obj)
{	
//	alert(obj);
	//obj = obj.split(",");
	divId = obj.shift();	// Getting the div Id from the first element of the returned array and removes it from the array
	txtId = obj.shift();	// Getting the text box Id from the second element of the returned array and removes it from the array		
	var namesList = document.getElementById(divId);
	if(obj.length > 0)
	{
		obj.sort();
		namesList.style.className = "DivVisible";		
		// Create a div to append at the top of list with close button to close the list
		var rowClose = document.createElement('div');
		rowClose.innerHTML = '<div style="background-color: rgb(196, 196, 196); text-align:right;"> ' + 
				'<a href="javascript: hideList(\'' + divId + '\');" title="Close"> ' +
						'<img src="../../AllApps/GUIs/images/cancel.jpg" alt="Close" border="0" vspace="2" /></a>&nbsp;' +
				'</div>';
		// Clearing the previously filled list of suggestions
		namesList.innerHTML = "";
		try
		{
			namesList.style.display = "table-row";			
		}
		catch(ex)
		{
			namesList.style.display = "inline";
		}
		namesList.appendChild(rowClose);
		//alert(obj);
		for (var i = 0; i < obj.length; i++)
		{
			var listItem = document.createElement('div');
			// Adding events to each item making them selectable
			listItem.onmouseover = function() {
				this.className = "rowHighlight";
			}
			listItem.onmouseout = function() {
				this.className = "rowUnHighlight";
			}
			listItem.onclick = function() {
				document.getElementById(txtId).value = this.firstChild.innerHTML;
				var elementIndex = obj.search(this.firstChild.innerHTML);
				document.getElementById("hdn"+txtId).value = obj[elementIndex][1];
				namesList.style.display = "none";
			}
			listItem.className = "rowUnHighlight";
			listItem.innerHTML = "<div>" + obj[i][0] + "</div>";
			namesList.appendChild(listItem);
		}
	}
	else
	{
		namesList.style.display = "none";
		namesList.innerHTML = "";
	}
}
function hideList(spID)
{
	if (document.getElementById(spID))
	 	document.getElementById(spID).style.display='none';
}
Array.prototype.search = function(s,q){
 var len = this.length;
  for(var i=0; i<len; i++){
   if(this[i].constructor == Array){
    if(this[i].search(s,q)){
      return i;
      break;
    }
   }
   else {
    if(q){
     if(this[i].indexOf(s) != -1){
        return true;
        break;
     }
    }
	else {
     if(this[i]==s){
      return true;
      break;
     }
    }
   }
  }
 return false;
}