﻿//---------注册函数--------start--//
$(document).ready(function() {

    //---------搜索--------start-----//
    $("#btnSearch").click(function() {
        var isType = $("#IsType").val();
        var txtVal = $("#txtSearch").val();
        if ($.trim(txtVal) == "") { return; }
        if (checkStr(txtVal)) {
            if (isType == "2") {
                location.href = "/product/list--" + $.trim(txtVal) + "-.html";
            }
            else {
                location.href = "/assessment/searchlist--" + $.trim(txtVal) + "-.html";
            }
        }

    });
    //---------搜索--------end-----//
    //---------回车--------start-----//
    $("#txtSearch").keypress(function() {
        var isType = $("#IsType").val();
        var key = window.event ? event.keyCode : event.which;
        if (key == 13) {
            var txtVal = $("#txtSearch").val();
            if ($.trim(txtVal) == "") { return; }
            if (checkStr(txtVal)) {
                if (isType == "2") {
                    location.href = "/product/list--" + $.trim(txtVal) + "-.html";
                }
                else {
                    location.href = "/assessment/searchlist--" + $.trim(txtVal) + "-.html";
                }
            }
        }
    });
    //---------回车--------end-----//

    //---------获得焦点--------start-----//
    $("#txtSearch").focus(function() {
        if ($(this).val() == "请输入关键词") {
            $(this).val("");
        }
    });
    //---------获得焦点--------end-----//
    //---------失去焦点--------start-----//
    $("#txtSearch").blur(function() {
        if ($(this).val() == "") {
            $(this).val(this.defaultValue);// 如果符合条件，则设置内容
        }
    });
    //---------获得焦点--------end-----//

    //------------验证非法字符--------------//
    function checkStr(val) {
        var reg = /([\u4E00-\u9FFF]+)||([a-zA-Z0-9]+)/g;
        if (reg.test($.trim(val))) { return true; }
        else { return false }
    }
    //---------回车--------end-----//
});
//---------注册函数--------end--//
