﻿var searchTab = {
	searchType: 1,
	lastmenu: null,
	menuOn: function(objMenu, stype) {
	    if(objMenu != this.lastmenu)
	    {
		    if(this.lastmenu) {
			    this.lastmenu.className = "";
		    }
		    objMenu.className = "focus_nav_on";
		    this.lastmenu = objMenu;
		    this.searchType = stype;
		}
	}
}
var searchAjax = {
    searchBox: null,
    searchList: null,
    timeout: null,
    onfocus: function() {
        if (!this.searchBox) {
            this.searchBox = document.getElementById("searchBox");
            this.searchList = document.getElementById("searchList");
        }
        this.searchList.style.display = "block";
        this.searchShow();
    },
    onchange: function() {
        if (!this.timeout) {
            this.timeout = setTimeout(this.searchShow, 1000);
        }
    },
    onblur: function() {
        this.timeout = setTimeout(this.searchHide, 100);
    },
    nosubmit: function(evt) {
        if (evt.keyCode == 13) {
            if (window.event) {
                evt.returnValue = false;
            } else {
                evt.preventDefault();
            }
            ToSearch();
        }
    },
    searchShow: function() {
        clearTimeout(searchAjax.timeout);
        searchAjax.timeout = null;
        if (searchAjax.searchBox.value == "") {
            searchAjax.searchList.innerHTML = "请输入搜索内容";
        }
        else {
            SEAjax.GET({
                url: "/Control/searchAjax.ashx?t=" + searchTab.searchType + "&wd=" + searchAjax.searchBox.value,
                success: function(value) {
                    searchAjax.searchList.innerHTML = value;
                }
            });
        }
    },
    searchHide: function() {
        clearTimeout(searchAjax.timeout);
        searchAjax.timeout = null;
        searchAjax.searchList.style.display = "none";
    },
    listOn: function(listObj) {
        this.searchBox.value = listObj.innerHTML;
    }
}
function ToSearch()
{
    if(searchAjax.searchBox.value == "")
    {
        alert("请输入查找关建字");
        return;
    }
    var wd = escape(searchAjax.searchBox.value);
    var url = "";
    switch(searchTab.searchType)
    {
        case 1:
            url = "http://supply.gongqiu.com.cn/trade-0-0-0-0-0-0-0-0-1.shtml?wd=";
            break;
        case 2:
            url = "http://company.gongqiu.com.cn/trade-0-0-0-0-1.shtml?wd=";
            break;
        case 3:
            url = "http://purchase.gongqiu.com.cn/trade-0-0-0-0-0-0-0-0-1.shtml?wd=";
            break;
        case 4:
            url = "http://www.gongqiu.com.cn/search/SearchNews.shtml?kw=";
            break;
        case 5:
            url = "http://www.gongqiu.com.cn/search/SearchAgent.shtml?kw=";
            break;
        case 6:
            url = "http://www.gongqiu.com.cn/search/SearchExpo.shtml?kw=";
            break;
        case 7:
            break;
        default:
            break;
    }
    if(url != "")
    {
        window.location.href = url + wd;
    }
}
