$(function () {
    function tagFun(tag, box) {
        tag.mouseover(function () {
            tag.removeClass('current');
            $(this).addClass('current');
            box.hide().eq(tag.index($(this))).show();
        });
    }
    tagFun($('.tag li'), $('.search dl'));

    $('#searchBtn1').click(searchDo);
    $('#keyWord2').keyup(function (e) { if (e.which == 13) { searchDo(); return false; } }).mouseover(function () { $(this).focus(); if ($(this).val() == 'Please input the keyword') $(this).val(''); });
    $('#searchBtn2').click(searchCustom);
    $('#ProIntrTxt').keyup(function (e) { if (e.which == 13) { searchCustom(); return false; } });
    function searchDo() {
        var kw = $('#keyWord2').val();
        if ($.trim(kw).length < 1) {
            alert('Please input keywords!');
            $('#keyWord2').focus();
            return false;
        }
        if (IsChinese(kw) || IsHtml(kw)) {
            alert('You entered illegal characters, please correct beforing searching.');
            return false;
        }
        window.open('searchResult.shtml?kw=' + kw.HTMLEncode());
    }
    function searchCustom() {
        var country = $('#countrySelect').val().HTMLEncode();
        var hsCode = $('#HSCodeTxt').val().HTMLEncode();
        var proIntr = $('#ProIntrTxt').val().HTMLEncode();
        if ($.trim(hsCode).length < 1) { alert('Please input HS code.'); $('#HSCodeTxt').focus(); return false; }
        var kw = 'ct=' + country + '&hc=' + hsCode + '&pi=' + proIntr;
        window.open('searchCustom.shtml?' + kw);
    }
    function IsChinese(str) {
        return /[\u4e00-\u9fa5]/.test(str);
    }
    //验证是否包含html标记
    function IsHtml(str) {
        return /<[^<]+>/.test(str);
    }
})
