/*
		 **************************************************得到Google下拉效果
		 */
		
		//定义一个XMLHttpRequest的对象
		var XMLHttpReq = false;
		var inputField ;
		var divfind ;
		var tablefind;
		var bodyfind;
		//用于分析是哪一个行变色
		var RowX = -1;
		//用于分析鼠标在那一个行上面变色
		var MouseEle;
		//用于存储文本框的值
		var fieldValue;
		//得到XMLHttpRequest对象
		function createrequest(){
			if(window.XMLHttpRequest)
			{
				XMLHttpReq = new XMLHttpRequest();
			}
			else if(window.ActiveXObject)
			{
				try{
					XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
				}catch(e){
					try{
						XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
					}catch(e){}
				}
			}
		}
		
		//文本框中的内容发生变化后即键盘键按下起来后触发此事件
		function findKeyword(event)
		{
			//获得当前点击事件的键盘编码
			var key = -1;
			//得到按下键的值
            try{ 
                   key=window.event.keyCode;  //取得键盘Code编号
             } 
             catch(a){ //对于Firefox来说，不支持event.keyCode
                   key=findKeyword.arguments[0].keyCode; 
             } 
			//如果是方向键或者是回车键的话就不改变
			if(key == 37 || key == 38 || key == 39 ||key == 40 || key == 13)
				return;
			RowX = -1;
			//分别得到所有HTML构件对象
			inputField = document.getElementById("names");
			divfind = document.getElementById("popup");
			tablefind = document.getElementById("findtable");
			bodyfind = document.getElementById("findbody");
			//分析检索框中的值是否大于零
			if(inputField.value.length > 0)
			{
				createrequest();
				var url = "../inc/getkeyword.jsp?keyword="+encodeURIComponent(inputField.value);
				XMLHttpReq.open("GET",url,true);
				XMLHttpReq.onreadystatechange = processResponse;
				XMLHttpReq.send(null);
			}
			//如果检索框中的值为非零的话，则清空findbody中的值
			else
			{
				clearKeywords();
			}
		}

		//Ajax返回的结果进行显示的函数
		function processResponse()
		{
			if(XMLHttpReq.readyState == 4)
			{
				if(XMLHttpReq.status == 200)
				{
					setKeywords(XMLHttpReq.responseXML.getElementsByTagName("res"));
				}
				else
				{
					
				}
			}
		}
		//将返回的检索词即检索数量显示到界面中去
		function setKeywords(reses)
		{
			
			//清空相关检索词提示框
			clearKeywords();
			//设置相关检索词提示框的边界大小
			setOffsets();
			//定义行   列    值得参数
			var row,cell1,cell2,txtNode1,txtNode2,input1,input2;
			var res,key,keycount;
			for(var i=0;i<reses.length;i++)
			{
				
				//得到第I个相关检索词
				res = reses[i];
				//得到res中相对应的相关检索词及相关检索词的数目
				key = res.getElementsByTagName("keyword")[0].firstChild.data;
				//将相应的关键词和相应的关键词数量加入到相应关键词提示框中
				//建立tr td  Text对象
				row = document.createElement("tr");
				cell1 = document.createElement("td");
				cell2 = document.createElement("td");
				txtNode1 = document.createTextNode(key);
				txtNode2 = document.createTextNode("");
				//设置TD的CSS样式
				row.onmouseout = function(){changeEntryColor(RowX);this.bgColor = "#FFFAFA";MouseEle=null;};
				row.onmouseover = function(){changeEntryColor(RowX);this.bgColor = "blue";MouseEle=this;};
				//设置背景颜色
				row.setAttribute("bgcolor","#FFFAFA");
				row.setAttribute("border",0);
				cell1.appendChild(txtNode1);
				cell2.appendChild(txtNode2);
				cell1.setAttribute("align","left");
				cell2.setAttribute("align","right");
				row.appendChild(cell1);
				row.appendChild(cell2);
				row.onclick = function(){getKeyword(this)};
				bodyfind.appendChild(row);
			}
		}
		 //设置显示位置                
		function setOffsets() 
		{
			//分别得到所有HTML构件对象
			inputField = document.getElementById("names");
			divfind = document.getElementById("popup");
			tablefind = document.getElementById("findtable");
			bodyfind = document.getElementById("findbody");
			tablefind.style.width = inputField.offsetWidth + "px";
			var left = calculateOffset(inputField, "offsetLeft");
			var top = calculateOffset(inputField, "offsetTop") + inputField. offsetHeight;
			divfind.style.border = "black 1px solid";
			divfind.style.left = left + "px";
			divfind.style.top = top + "px";
			divfind.style.width = tablefind.style.width;
		}
		//计算显示位置
		function calculateOffset(field, attr) 
		{
			var offset = 0;
			while(field) {
			offset += field[attr]; 
			field = field.offsetParent;
			}
			return offset;
		}
		//将检索词提示框中的关键词赋予文本框中
		function getKeyword(cell)
		{
			inputField.value = cell.firstChild.firstChild.nodeValue;
			clearKeywords();
		}
		//清空相关检索词提示框中的数据
		function clearKeywords()
		{
			inputField = document.getElementById("names");
			divfind = document.getElementById("popup");
			tablefind = document.getElementById("findtable");
			bodyfind = document.getElementById("findbody");
			var index = bodyfind.childNodes.length;
			for(var i=index-1;i>=0;i--)
				bodyfind.removeChild(bodyfind.childNodes[i]);
			bodyfind.style.border = "none";
			divfind.style.border = "none";
		}
		
		function documentKeyDown(event)
		{
			//获得当前点击事件的键盘编码
			var documentkey = -1;
			//得到按下键的值
            try{ 
                   documentkey=window.event.keyCode;  //取得键盘Code编号
             } 
             catch(a){ //对于Firefox来说，不支持event.keyCode
                   documentkey=documentKeyDown.arguments[0].keyCode; 
             } 
			if(documentkey == 13)
			{
				clearKeywords();
				return;
			}
			else if(documentkey == 37 || documentkey == 38)
			{
				prePage();
			}
			else if( documentkey == 39 || documentkey == 40)
			{
				nxtPage();
			}
		}
		
		//向上翻页  1、修改背景颜色，2、修改RowX 3、修改文本框的值
		function prePage()
		{
			//分别得到所有HTML构件对象
			inputField = document.getElementById("names");
			divfind = document.getElementById("popup");
			tablefind = document.getElementById("findtable");
			bodyfind = document.getElementById("findbody");
			try{
			//将鼠标变色的行置零
			if(MouseEle != null)
				MouseEle.bgColor="#FFFAFA";
			MouseEle = null;
			//分析当前的行数是否为0和-1'
			if(RowX == -1)
			{
				//将文本框的值保存
				fieldValue = inputField.value;
				//将最后一个孩子节点的值赋予文本框
				
				inputField.value = bodyfind.lastChild.firstChild.firstChild.nodeValue;
				//得到findbody的最后一个孩子节点
				bodyfind.lastChild.bgColor="blue";
				//将当前的行数修改
				RowX = bodyfind.childNodes.length-1;
			}
			//当此时第0行获取焦点时
			else if(RowX == 0)
			{
				//修改文本框的值
				inputField.value = fieldValue;
				//修改当前行的背景颜色
				bodyfind.firstChild.bgColor="#FFFAFA";
				//修改当前行的行数
				RowX = -1;
			}
			else
			{
				//修改文本框的值
				inputField.value = bodyfind.childNodes[RowX-1].firstChild.firstChild.nodeValue;
				//修改当前行的北京颜色以及上一行的背景颜色
				bodyfind.childNodes[RowX].bgColor="#FFFAFA";
				bodyfind.childNodes[RowX-1].bgColor = "blue";
				//修改行数
				RowX = RowX-1;
			}}catch(e){}
		}
		//向下翻页  1、修改背景颜色，2、修改RowX 3、修改文本框的值
		function nxtPage()
		{
			//分别得到所有HTML构件对象
			inputField = document.getElementById("names");
			divfind = document.getElementById("popup");
			tablefind = document.getElementById("findtable");
			bodyfind = document.getElementById("findbody");
			try{
			//将鼠标变色的行置零
			if(MouseEle != null)
				MouseEle.bgColor="#FFFAFA";
			MouseEle = null;
			//分析当前的行数是否为findbody.length-1和-1
			if(RowX == -1)
			{
				//将文本框的值保存
				fieldValue = inputField.value;
				//将第一个孩子节点的值赋予文本框
				inputField.value = bodyfind.firstChild.firstChild.firstChild.nodeValue;
				//得到findbody的第一个孩子节点
				bodyfind.firstChild.bgColor="blue";
				//将当前的行数修改
				RowX = 0;
			}
			//当此时第0行获取焦点时
			else if(RowX == (bodyfind.childNodes.length-1))
			{
				//修改文本框的值
				inputField.value = fieldValue;
				//修改当前行的背景颜色
				bodyfind.lastChild.bgColor="#FFFAFA";
				//修改当前行的行数
				RowX = -1;
			}
			else
			{
				//修改文本框的值
				inputField.value = bodyfind.childNodes[RowX+1].firstChild.firstChild.nodeValue;
				//修改当前行的背景颜色以及下一行的背景颜色
				bodyfind.childNodes[RowX].bgColor="#FFFAFA";
				bodyfind.childNodes[RowX+1].bgColor = "blue";
				//修改行数
				RowX = RowX+1;
			}}catch(e){}

		}
		function changeEntryColor(index)
		{
			if(index != -1)
				bodyfind.childNodes[index].bgColor="#FFFAFA";
			index = -1;
		}
		document.onkeydown=documentKeyDown;