

var oinputField; //考慮到很多函數中都要使用
	    var oPopDiv; 	//因此採用全局變量的形式
	    var oColorsUl;
	    var xmlHttp;
	    var tmpKeyword;
	    function createXMLHttpRequest() {
	        if (window.ActiveXObject)
	            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	        else if (window.XMLHttpRequest)
	            xmlHttp = new XMLHttpRequest();
	    }
	    function initVars() {
	        //初始化變量
	        //alert("aa");
	        oinputField = document.forms["form2"].vkeyword;
	        oPopDiv = document.getElementById("popup");
	        oColorsUl = document.getElementById("colors_ul");
	    }
	    function clearColors() {
	        //清除提示內容
	        for (var i = oColorsUl.childNodes.length - 1; i >= 0; i--)
	            oColorsUl.removeChild(oColorsUl.childNodes[i]);
	        oPopDiv.className = "hide";
	    }
	    function setColors(the_colors) {
	        //顯示提示框，傳入的參數即為匹配出來的結果組成的數組
	        clearColors(); //每輸入一個字母就先清除原先的提示，再繼續
	        oPopDiv.className = "show";
	        var oLi;
	        for (var i = 0; i < the_colors.length; i++) {
	            //將匹配的提示結果逐一顯示給用戶
	            oLi = document.createElement("li");
	            oColorsUl.appendChild(oLi);
	            oLi.appendChild(document.createTextNode(the_colors[i]));

	            oLi.onmouseover = function() {
	                this.className = "mouseOver"; //鼠標經過時高亮
	            }
	            oLi.onmouseout = function() {
	                this.className = "mouseOut"; //離開時恢復原樣
	            }
	            oLi.onclick = function() {
	                //用戶點擊某個匹配項時，設置輸入框為該項的值
	                oinputField.value = this.firstChild.nodeValue;
	                clearColors(); //同時清除提示框
	                document.form2.submit();
	            }
	        }
	    }
	    function findColors() {
	        
	        initVars(); 	//初始化變量
	        //alert (oinputField.value);
	        if (tmpKeyword != oinputField.value) {
	            tmpKeyword = oinputField.value;
	            if (oinputField.value.length > 0) {
	                createXMLHttpRequest(); 	//將用戶輸入發送給服務器
	                var sUrl = "../../ajax/ajax_pages_yel_pag.asp?vkeyword=" + oinputField.value + "&timestamp=" + new Date().getTime();
	                xmlHttp.open("GET", sUrl, true);
	                xmlHttp.onreadystatechange = function() {
	                    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
	                        var aResult = new Array();
	                        if (xmlHttp.responseText.length) {
	                            aResult = xmlHttp.responseText.split(",");
	                            setColors(aResult); //顯示服務器結果
	                        }
	                        else
	                            clearColors();
	                    }
	                }
	                xmlHttp.send(null);
	            }
	            else
	                clearColors(); //無輸入時清除提示框（例如用戶按del鍵）
	        }
	    }