﻿var xmlhttp;
	function SetListPos(oDiv) {//设置列表位置使其在文本况下方
		var oInput=document.topform.keyword;
		if(document.all){
			
			oDiv.style.left=oInput.offsetLeft+'px';
			oDiv.style.top=oInput.offsetTop+oInput.offsetHeight+"px";
			oDiv.style.width=oInput.offsetWidth-2+'px';
			
			
		}else{
			oDiv.style.left=oInput.offsetLeft+'px';
			oDiv.style.top=oInput.offsetTop+oInput.offsetHeight+"px";
			oDiv.style.width=oInput.offsetWidth-2+'px';
		}			
	}
	
	function FillList(oDiv,strList){
		SetListPos(document.getElementById('divlist'));
		
		arrList=window.eval(strList);
		oDiv.selectindex=-1;//设置选中项目为空
		if(arrList.length>0){
			
			var html="<ul>"
			for(var i=0;i<arrList.length;i++){
				html+="<li onmouseover=\"this.className='li_sel'\" onmouseout=\"this.className=''\""
				html+="onclick='Td_click(this,document.getElementById(\"keyword\"),document.getElementById(\"divlist\"))'"
				html+=" >"+arrList[i].name+"</li>"
			}
			
			html+="<li style=\"text-align:right;padding-right:5px;\"><a href=\"#\" onclick='ShowList(document.getElementById(\"divlist\"),\"none\");return false;'>Close</a></li>"
			
			html+="</ul>"
			oDiv.innerHTML=html;
			ShowList(document.getElementById('divlist'),'block');
		}
		else{
			ShowList(oDiv,'none');
			oDiv.innerHTML="";
		}
	}
	
	function ShowList(oDiv,strDisplay){
		oDiv.style.display=strDisplay;
	}
	
	function CreateXmlHttp(){
		if(document.all)
			return new ActiveXObject("Microsoft.XMLHTTP");
		else
			return new XMLHttpRequest();	
	}
	
	function HandleStateChange(){
		if(4==xmlhttp.readyState){
			var oDiv=document.getElementById("divlist");
			if(200==xmlhttp.status){
				var strResponse=xmlhttp.responseText;
				FillList(oDiv,strResponse);
			}
			else{
				alert("Error Request ！"+xmlhttp.responseText)
				ShowList(oDiv,'[]');
			}
		}
	}
	
	function HandleInputChange(strInput){
		if(strInput!=""){
			xmlhttp=CreateXmlHttp();
			xmlhttp.open("post","/getKeyword.asp",true);
			xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			xmlhttp.onreadystatechange=HandleStateChange;
			xmlhttp.send("word=" + escape(strInput));
		}else{
			var oDiv=document.getElementById('divlist');
			ShowList(oDiv,'none');
			oDiv.innerHTML="";
		}
			
	}
	
	function Td_click(oTd,oInput,oDiv){
		oInput.value=oTd.innerHTML;
		ShowList(oDiv,'none');
		onsubmits();
	}
	
	function ChangeListSelect(oDiv,strOperation){
		var nItemCount=oDiv.getElementsByTagName('li').length-1;
		var nSelIndex=parseInt(oDiv.selectindex);
		//恢复以前选中的项目
		if(nSelIndex!=-1)
			oDiv.getElementsByTagName('li')[nSelIndex].className='';
		
		//改变选中项目
		var i=strOperation=="push"?1:-1;
		if(nSelIndex+i<-1)
			oDiv.selectindex=nItemCount-1;
		if(nSelIndex+i>=-1 && nSelIndex+i<nItemCount) 
			oDiv.selectindex=nSelIndex+i;
		if(nSelIndex+i>=nItemCount)
			oDiv.selectindex=-1
		
		//显示现在选中的项目
		nSelIndex=parseInt(oDiv.selectindex);
		if(nSelIndex!=-1)
			oDiv.getElementsByTagName('li')[nSelIndex].className='li_sel';
	}
	
	function  HandleKeyUp(oInput,oDiv,e){
		var evt=window.event||e;
		var keycode=evt.keyCode||evt.witch;
		switch(keycode){
			case 9://处理tab键（失败，无法触发）
				oDiv.style.display='none';
				break;
			case 13://处理回车键
				var nIndex=oDiv.selectindex;
				
				if(nIndex||nIndex==0){
					oInput.value=oDiv.getElementsByTagName('li')[nIndex]?oDiv.getElementsByTagName('li')[nIndex].innerHTML:oInput.value;
					oDiv.style.display='none';
					onsubmits();
				}
				break;	
			case 38://处理方向键上箭头
 				ChangeListSelect(oDiv,"pop");
				break;
			case 40://处理方向键下肩头
 				ChangeListSelect(oDiv,"push");
				break;
			default://处理正常的字符输入
				HandleInputChange(oInput.value);
		}
	}
	
	function HandleKeyDown(oDiv,e){
		var evt=window.event||e;
		var keycode=evt.keyCode||evt.witch;
		if(keycode==9){//处理tab键
			oDiv.style.display='none';
		}
	}
	
	function  ShowRecord(strName){
		
	}
	
	//SetListPos(document.getElementById('divlist'));
	
	
	
	
function chage(sid){
	var a=document.getElementById(sid);
	if (a){

		var b=Array("s1","s2","s3","s4","s5","s6","s7");
		
		for (var i=0;i<b.length;i++){
		
				if(document.getElementById(b[i]))
					document.getElementById(b[i]).className="topuncheck";
			
		}
		a.className="topcheck";
		
		
		switch (a.id){
			case "s1":
				document.topform.action="/product/productSearch.asp";
				document.topform.Ntype.value=1;
				break;
			case "s2":
				document.topform.action="/Fair/results.asp";
				document.topform.Ntype.value=2;
				break;
			case "s3":
				document.topform.action="/company/companySearch.asp";
				document.topform.Ntype.value=3;
				break;
			case "s4":
				document.topform.action="/buy/buySearch.asp";
				document.topform.Ntype.value=4;
				break;
			case "s5":
				document.topform.action="/Report/results.asp";
				document.topform.Ntype.value=5;
				break;
			case "s6":
				document.topform.action="/report_club/bbssearch.asp";
				document.topform.Ntype.value=6;
				break;
			case "s7":
				document.topform.action="/biz/results.asp";
				document.topform.Ntype.value=7;
				break;
		}
	
	}
}


function onsubmits(){
	if(document.topform.keyword.value=="" || document.topform.keyword.value=="Please input key words"){
		alert("Please input key words");
		document.topform.keyword.value="";
		document.topform.keyword.focus()
	}else{
		document.getElementById("siframe").src="/inkeyword.asp?keyword="+escape(document.topform.keyword.value)+"&Ntype="+escape(document.topform.Ntype.value);
		document.topform.submit();
	}

}

function delKeyword(obj){
	if (obj.value=="Please input key words"){
		obj.value="";
	}
}