
var xmlhttp;
var SearchString;
//var popup;
var DisplayTable;
//var CUSIPTableBody;


function Init(SearchFieldID,DisplayFieldID){
SearchString=document.getElementById(SearchFieldID);

//popup=document.getElementById("popup");
DisplayTable=document.getElementById(DisplayFieldID);

}

function getSuggestions(SearchID,SearchFieldID, DisplayFieldID, SearchLength)
{
	Init(SearchFieldID,DisplayFieldID);
	if (SearchString.value.length >= SearchLength) {
		ProcessRequest(SearchID);
	}

	else {
		ClearSuggestions();
	}
}



function ProcessRequest(SearchID){
xmlhttp=null;
var url="SearchDataForAJAX.asp?SearchID=" + SearchID + "&SearchString=" + escape(SearchString.value)+ "&pseudoParam= "+new Date().getTime();
//alert(url);
if (window.XMLHttpRequest)
  {// code for IE7, Firefox, Mozilla, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE5, IE6
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=onResponse;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  //alert("Your browser does not support XMLHTTP.");
  }
}

function onResponse()
{
if(xmlhttp.readyState!=4) return;
if(xmlhttp.status!=200)
  {
  //alert("Problem retrieving XML data");
  return;
  }
  
var x=xmlhttp.responseText;
if (x.length > 0){
	setOffsets;

	var str = "<table cellpadding=1 width=" + SearchString.offsetWidth + " cellspacing=0>"
	x = str + x 
	x = x + "</table>"
	
	DisplayTable.style.border="groove";
	DisplayTable.style.borderRightWidth="thin";
	DisplayTable.style.borderBottomWidth="thin";
	DisplayTable.style.borderLeftWidth="thin";
	DisplayTable.style.borderTopWidth="0";
	DisplayTable.style.verticalAlign = 'top';
	DisplayTable.style.backgroundColor  = '#ffffff';

	DisplayTable.innerHTML=x;
}
else{
	DisplayTable.innerHTML="";
	DisplayTable.style.border="none";
}

}

function PopulateCusip(cell){
SearchString.value=cell.firstChild.nodeValue;
ClearSuggestions();
}



function setOffsets(){
var end=SearchString.offsetWidth;
var left=calculateOffsetLeft(SearchString);
var top =calculateOffsetTop(SearchString) + SearchString.offsetHeight;

DisplayTable.style.border = "Black 1 px solid";
DisplayTable.style.left = left + "px";
DisplayTable.style.top = top + "px";
DisplayTable.style.width = end + "px";
}



function calculateOffsetLeft(field)
{
	return calculateOffset(field, "offsetLeft");
}

function calculateOffsetTop(field)
{
	return calculateOffset(field, "offsetTop");
}

function calculateOffset(field, attr)
{
	var offset = 0;
	while (field){
		offset += field[attr];
		field=field.offsetParent;	
	}
	return offset
}



function ClearSuggestions(){
if (DisplayTable != null){
	DisplayTable.innerHTML="";
	DisplayTable.style.border="none";
	}
}

function MouseOver(ele){
ele.style.backgroundColor = "#CCCCCC";

}

function MouseOut(ele){
ele.style.backgroundColor = "white";

}

function DivMouseOut(){
ClearSuggestions();
}



var mDivMOver = false;
document.onclick = function() {
if (!mDivMOver)
	ClearSuggestions();
}