﻿function doSearch(key) {
    if (typeof key != "string") { 
        key = $val("myinput");
    }
    if (key != "" && key != "搜索工具") {
        key = escape(key);
        var url = "/Pages/Search.aspx?word=" + key;
        window.location.href = url;
        return false;
    }
    return true;
}
function initSearch() {
    var textbox = $id("myinput");
    var btnsearch = $id("btn_search");

    btnsearch.onclick = function() {
        doSearch(textbox.value);
    }

    textbox.onclick = function() {
        if (this.value == '搜索工具') {
            this.select();
        }
    }

    textbox.onblur = function() {
        if (this.value == '') {
            this.value = '搜索工具';
        }
    }
    
    textbox.onkeypress = function() {
        var keycode = event.keyCode;
        if (keycode == 13) {
            return doSearch(this.value);
        }
        return true;
    }
    var word = $queryString("word");
    if (word != "") {
        $val(textbox, unescape(word));
    }
}
