function checkinput(){
var word= document.getElementById("names").value;
if(word==""){
  alert("请输入关键字");
}
else{
  document.getElementById("findform").submit();
	}
}
var xmlHttp;
var completeDiv;
var inputField;
var nameTable;
var nameTableBody;
var p=0;
var maxlen=10;
var minlen=1;
var mouseontable=0;
function createXMLHttpRequest(){
	if(window.ActiveXObject){
	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
else if(window.XMLHttpRequest){
    xmlHttp=new XMLHttpRequest();
 	}
}
function initVars(){
              inputField=document.getElementById("names");
              nameTable=document.getElementById("name_table");
              completeDiv=document.getElementById("popup");
              nameTableBody=document.getElementById("name_table_body");
}
function findNames(){
	initVars();			 
	if (window.event.keyCode==27){
			   clearNames();
			   return;
	}
    if(inputField.value.length>0&&trim(inputField.value)!=""){
    createXMLHttpRequest();
    var url="/getname.asp?name="+inputField.value+"";
                  xmlHttp.open("GET",url,true);
				  xmlHttp.setRequestHeader( "Content-Type", "text/html;charset=UTF-8");
                  xmlHttp.onreadystatechange=callback;
                  xmlHttp.send(null);
     }else{
                  clearNames();
   }        
}
function downdownkey(){    
	if(p<maxlen){
	if(p!=0){
	nameTableBody.childNodes[p-1].style.backgroundColor="#ffffff";
	}
	nameTableBody.childNodes[p].style.backgroundColor="#3399CC";
	inputField.value= nameTableBody.childNodes[p].innerText;
	p=p*1+1;
	}
	else{     
	nameTableBody.childNodes[p-1].style.backgroundColor="#ffffff";
	nameTableBody.childNodes[0].style.backgroundColor="#3399CC";
	inputField.value= nameTableBody.childNodes[0].innerText;
	p=1;
	}
}
function upupkey(){    
if(p>minlen){
	p=p*1-2;
	nameTableBody.childNodes[p-1].style.backgroundColor="#ffffff";
	nameTableBody.childNodes[p].style.backgroundColor="#3399CC";
	inputField.value= nameTableBody.childNodes[p].innerText;
	p=p*1+1;
	}
	else{  
	 return;
	}
}
function callback(){
 if(xmlHttp.readyState==4){
    if(xmlHttp.status==200){
	var  xmlDom = new ActiveXObject("Microsoft.XMLDOM") 
		if(xmlHttp.responseText!="<response></response>"){
			xmlDom.loadXML(xmlHttp.responseText);
            setNames(xmlDom.getElementsByTagName("name"));
		}
		else{
		clearNames();
		}
          } else if (xmlHttp.status==204){
          clearNames();
           }
       }
}
function setNames(the_names){          
              clearNames();
			  var  newkey="";
              var size=the_names.length;
              setOffsets();
              var row,cell,txtNode,tbody,rowhead,cellhead;
			   rowhead=document.createElement("tr");
			   cellhead=document.createElement("td");
			   cellhead.setAttribute("colspan","2");
			   cellhead.setAttribute("align","right");
			   cellhead.colspan="2";
			   cellhead.innerHTML="搜索结果";
			   rowhead.appendChild(cellhead);    
			  nameTableBody.appendChild(rowhead);    
              for(var i=0;i<size;i++){
                  var nextNode=the_names[i].firstChild.data;
                  var text=the_names[i].attributes(0).value; 
				  var key= the_names[i].attributes(1).value; 
				 
                  row=document.createElement("tr");
                  cell=document.createElement("td");
				  cell2=document.createElement("td");
				  cell.id=i;
                  txtNode=document.createTextNode(nextNode);
                   cell.onmouseout=function(){
				     
				    if(mouseontable=1)
					  {
				     this.parentNode.style.backgroundColor="#FFFFFF";
					  }
					}
                  cell.onmouseover=function(){
				     if(mouseontable=1)
					 {
				   this.parentNode.style.backgroundColor="#fdf2f9";
				   
				   populateName(this);
				   }
				   }   
 

                  cell.setAttribute("border","0"); 
			 
				  cell.style.color= "#000000"; 
				  cell.style.paddingLeft="5px";
				   cell2.setAttribute("border","0"); 
				    cell2.setAttribute("align","right");
					cell2.style.color= "#000000"; 
					 	cell2.style.paddingRight= "5px"; 
                cell.onclick=function(){populateName(this);clearNames();}  
                  
                  //===================================        
            	nameTableBody.appendChild(row);     
				nameTableBody.style.lineHeight="18px";
                  row.appendChild(cell);    
				  row.appendChild(cell2); 
				 
				var arrKey=key.split(""); 

				newkey=""
				for(var tempint=0;tempint<arrKey.length;tempint++)
				{
					if(nextNode.indexOf(arrKey[tempint])>=0)
					{
						newkey+="<strong><font color=#d91b94>"+arrKey[tempint]+"</font></strong>";
						}
						else
						{
							newkey+=arrKey[tempint];
							}
					}
				 
				 
                cell.innerHTML=newkey;
				cell2.innerText=text;
                //===================================    
				
              }              
          }
          function setOffsets(){
              var end=inputField.offsetWidth;
              var left=calculateOffsetLeft(inputField);
              var top=calculateOffsetTop(inputField)+inputField.offsetHeight;
              
              completeDiv.style.border="black 1px solid"
              completeDiv.style.left=left+"px";
              completeDiv.style.top=top+"px";
              nameTable.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 populateName(cell){
			  try {
		      var str=cell.innerText;
              inputField.value=str;
			  p=cell.id*1+1;
			  }catch(err){}
             //clearNames();
          } 
function clearNames(){
  p=0;
  var ind=nameTableBody.childNodes.length;
  //alert("1.下拉菜单个数="+ind);
  for(var i=ind-1;i>=0;i--){
  nameTableBody.removeChild(nameTableBody.childNodes[i]);
  }
  ind=nameTableBody.childNodes.length;
  //alert("2.下拉菜单个数="+ind);
   completeDiv.style.border="none";
  }    
 function clearstyle(){
	var ind=nameTableBody.childNodes.length;
    //alert("1.下拉菜单个数="+ind);
     for(var i=ind-1;i>=0;i--){
    nameTableBody.childNodes[i].style.backgroundColor="#FFFFFF";
	}
}      
function ltrim(s){ 
return s.replace( /^\s*/, ""); 
}
function rtrim(s){ 
return s.replace( /\s*$/, ""); 
}
function trim(s){ 
return rtrim(ltrim(s)); 
}
function upkey(e) {
return e.keyCode==38;
	}
function downkey(e) {
return e.keyCode==40;
}	
function downSubmitKey() {
	if(window.event.keyCode==13){
	document.ilogin.submit(); 
	}
}
function setmouseon(){
  mouseontable=1;
}
function setmouseout(){
  mouseontable=0;
}