function mOut(li_id){
    document.getElementById(li_id).style.background= "#f0fbeb";
    document.getElementById(li_id).className=="";
}
var div_pointer = -1;
function mMove(li_id)
{
	document.getElementById(li_id).className=="select";
	document.getElementById(li_id).style.background= "#3399ff";
	div_pointer = li_id;
}
function mDown(li_id){
	var context=document.getElementById("realhidden"+div_pointer).value;
	document.getElementById("Text1").value=context;
    li_hidden();
}
function li_hidden(){
    document.getElementById("showHtml").innerHTML="";
    document.getElementById("showHtml").style.visibility= "hidden";
}
String.prototype.trim = function() {
	return this.replace(/[(^\s+)(\s+$)]/g,"");
}
function checkKey(evt)
{
	if(evt.keyCode==40 || evt.keyCode==38 || evt.keyCode==13){
		var keyChar = evt.keyCode;
        if(keyChar==38){
            if (div_pointer == 0 || div_pointer == -1){
				return;
			}
	            mOut(div_pointer);
	            mMove(div_pointer-1);
        }else if(keyChar==40){
            if (div_pointer == 20){
				return;
			}
        		if (div_pointer != -1){
	            	mOut(div_pointer);
	            }
	            mMove(parseInt(div_pointer)+parseInt(1));
        }else if(keyChar==13){
           mDown(div_pointer);
        }
    }else{
		div_pointer = -1;
        sendData();
    }
}
//--------------------------------------------------------   
document.onkeydown=keyEnter;

function keyEnter(e){   
	 var   iKeyCode;
	if(window.event){
	    iKeyCode=window.event.keyCode; 
	}else if(event.which){
	    iKeyCode=event.which;
	} 
	if(iKeyCode==13){ 
	    return false; 
	} 
}   
var isie=0;
var xmlHttp=getXmlHttpRequestObject();
function getXmlHttpRequestObject(){
   var xhr=null;
   try{
	   xhr= new ActiveXObject('Msxml2.XMLHTTP');
	   isie=1;
	}catch(e){
	   try{
		    xhr= new ActiveXObject('Microsoft.XMLHTTP');
		    isie=1;
	   }catch(e){
		    try{
			     xhr= new XMLHttpRequest();
			     isie=0;
		    }catch(e){
		    }
	   }
	}

	if(!xhr&&typeof XMLHttpRequest!='undefined') {
		 xhr=new XMLHttpRequest();
	}

	return xhr;
}
function sendData(){
	var text=document.getElementById("Text1").value;
	if (text.trim() == ""){
		document.getElementById("showHtml").innerHTML="";
		document.getElementById("showHtml").style.visibility= "hidden";
		return false;
	}
	xmlHttp.open("get",encodeURI("/jqpsdiv/?skey="+encodeURIComponent(text)),true);

	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState==4){
			var getResult=xmlHttp.responseText;
			document.getElementById("showHtml").style.visibility= "";
			document.getElementById("showHtml").innerHTML=getResult;
		}
	}

	xmlHttp.send("jqs");
}    
function xmlHandle(){
    if(xmlHttp.readyState==4){
        var getResult=xmlHttp.responseText;
        document.getElementById("showHtml").style.visibility= "";
        document.getElementById("showHtml").innerHTML=getResult;
    }
}