﻿// JavaScript Document

var xmlHttp,searchBoxId,KeyClueBoxId,searchBoxName;
searchBoxId = "searchkey";
searchBoxName = "searchkey";
KeyClueBoxId = "autoKeyClue";
xmlhttp = createXMLHttpRequest();
var j=-1;
var temp_str;

function getKeyWord(){
    var searchBox = document.getElementById(searchBoxId);//��ȡ�ı������
	var KeyClueBox = document.getElementById(KeyClueBoxId);
	if(searchBox == null || KeyClueBox == null) return;
	if(searchBox.name != searchBoxName) return;
    if(searchBox.value=="") return;
    var top=0;
    var left=0;
	var obj = searchBox;
    while(obj){//��ѭ���õ��ļ��������ҳ���еľ��λ��
        top += obj.offsetTop;
        left += obj.offsetLeft;
        obj = obj.offsetParent;
    }
    xmlhttp.open("get","/CL_KWIPT.asp?keyword="+searchBox.value,true);
    xmlhttp.onreadystatechange = function(){
        if(xmlhttp.readyState == 4)
        {
            if(xmlhttp.status == 200)
            {
                if(xmlhttp.responseText!=""){
                    KeyClueBox.innerHTML = unescape(xmlhttp.responseText);//�Ѻ�̨���ص������䵽��ʾ��
                    KeyClueBox.style.left = left + "px";//������ʾ���λ��,��
                    KeyClueBox.style.top = (top + 21) + "px";//������ʾ���λ��,��
                    KeyClueBox.style.display = "block";//������ʾ��ɼ�
                }else{
                    KeyClueBox.innerHTML = "";//�����ʾ��
                    KeyClueBox.style.display = "none";//������ʾ�㲻�ɼ�
                }
            }
            else{
            
            }
        }
    }
    xmlhttp.setRequestHeader("If-Modified-Since","0");
    xmlhttp.send(null);
}
function hideClue(){
       document.getElementById(KeyClueBoxId).innerHTML = "";//�����ʾ��
       document.getElementById(KeyClueBoxId).style.display = "none";//������ʾ�㲻�ɼ�
}
function getLiList(){
	var lis = document.getElementById(KeyClueBoxId)	.getElementsByTagName("ul")[0].getElementsByTagName("li");
	return lis;
}
//��������¼�
		function keyupdeal(e){
			var keyc;
			if(window.event){
				keyc=e.keyCode;
				}
			else if(e.which){
				keyc=e.which;
				}
			if(keyc!=40 && keyc!=38){
				getKeyWord();
				temp_str=document.getElementById(searchBoxId).value;
			}
			}

		function set_style(num){
			for(var i=0;i<getLiList().length;i++){
				var li_node=getLiList()[i];
				if(li_node.getAttribute("id")=='ajax'){
					li_node.className="";
					li_node.getElementsByTagName("span")[0].style.color = "";
					li_node.childNodes[1].className="r";
					li_node.style.backgroundColor="#FFFFFF";	
				}
			}
			if(j>=0 && j<getLiList().length){
				var i_node=getLiList()[j];
				if(i_node.getAttribute("id")=='ajax'){
					i_node.style.backgroundColor="#3366CC";
					i_node.className='focusLi';
					i_node.getElementsByTagName("span")[0].style.color = "#FFF";
					i_node.childNodes[1].className='r_focus';
				}

			}
		}
		function mo(nodevalue){
			j=nodevalue;
			set_style(j);
			if(j>=0 && j<getLiList().length){
				document.getElementById(searchBoxId).value=getLiList()[j].childNodes[0].childNodes[0].nodeValue;
			}
			else{
				document.getElementById(searchBoxId).value=temp_str;
			}
		}
		function form_submit(){
			if(j>=0 && j<getLiList().length){
				document.getElementById(searchBoxId).value=getLiList()[j].childNodes[0].childNodes[0].nodeValue;
				}
		 hideDiv();
			//document.search.submit();
		}
		function hide_suggest(){
			var nodes=document.body.childNodes;
			for(var i=0;i<nodes.length;i++){
				if(nodes[i]!=document.getElementById(searchBoxId)){
					$("keytishi").innerHTML="";
					}
				}
			}
			
function keydowndeal(e){
			var keyc;
			if(window.event){
				keyc=e.keyCode;
				}
			else if(e.which){
				keyc=e.which;
				}
			if(keyc==40 || keyc==38){
			if(keyc==40){
				if(j<getLiList().length){
					j++;
					if(j>=getLiList().length){
						j=-1;
					}
				}
				if(j>=getLiList().length){
						j=-1;
					}
			}
			if(keyc==38){
				if(j>=0){
					j--;
					if(j<=-1){
						j=getLiList().length;
					}
				}
				else{
					j=getLiList().length-1;
				}
			}
			set_style(j);
			if(j>=0 && j<getLiList().length){
				document.getElementById(searchBoxId).value=getLiList()[j].childNodes[0].childNodes[0].nodeValue;
				}
			else{
				document.getElementById(searchBoxId).value=temp_str;
				}
			}
}



