﻿
function writeSearchLog() {
    return;
    $.get("/ajax/WriteSearchLog.aspx", {
        words: encodeURIComponent($('#keyWord').val())
    },
            function(data) {
                if (data.length > 0) {
                }
            });
}

var active = -1;
var lastKeyValue = '';
var lastKeyPressCode = 0;
function lookup(keyWord) {
    if (keyWord.length == 0) {
        $('#suggestions').hide();
    } else {
        if (keyWord != lastKeyValue) {
            lastKeyValue = keyWord;
            $.get("/ajax/getsearch.aspx", {
                words: encodeURIComponent(keyWord)
            },
            function(data) {
                if (data.length > 0) {
                    $('#suggestions').show();
                    $('#autoSuggestionsList').html(data);
                    $("li", $('#autoSuggestionsList')).removeClass("ac_over");
                    $("#autoSuggestionsList li").hover(function() {
                        $("li", $('#autoSuggestionsList')).removeClass("ac_over");
                        $(this).addClass("ac_over");
                        active = $("li", $('#autoSuggestionsList')).indexOf($(this).get(0));
                    },
                    function() {
                        $(this).removeClass("ac_over");
                    });
                    active = -1;
                }
            });
        } else if ($('#autoSuggestionsList').html() != '') {
            $('#suggestions').show();
        }
    }
}
$(document).ready(function() {
    $('#keyWord').keyup(function(e) {
        lastKeyPressCode = e.keyCode;
        if ((lastKeyPressCode > 32 && lastKeyPressCode < 41) || (lastKeyPressCode > 8 && lastKeyPressCode < 32)) {
            return false;
        } else {
            lookup($('#keyWord').val());
        }
    });
    $('#keyWord').keydown(function(e) {
        switch (e.keyCode) {
            case 38:
                e.preventDefault();
                moveSelect(-1);
                break;
            case 40:
                e.preventDefault();
                moveSelect(1);
                break;
            case 9:
            case 13:
                break;
            default:
                break;
        }
    }).blur(function() {
        fill();
    });
});
function submit_headerfrom() {
    if ($('#keyWord').val() == '菜谱名 食材 功效') {
        return false;
    }
    var submit_from = true;
    if (active != -1) {
        var lis = $("li", $('#autoSuggestionsList'));
        if (lis) {
            var jump_href = $(lis[active]).find("a").attr('href');
            if (jump_href != '') {
                location.href = jump_href;
                submit_from = false;
            }
        }
    }
    if (submit_from == true) {
        $('#suggestions_from').submit();
    }
}
function fill(thisValue) {
    $('#keyWord').val(thisValue);
    setTimeout("$('#suggestions').hide();", 200);
}
function moveSelect(step) {
    var lis = $("li", $('#autoSuggestionsList'));
    if (!lis) return;
    active += step;
    if (active < 0) {
        active = 0;
    } else if (active >= lis.size()) {
        active = lis.size() - 1;
    }
    var li_val = $(lis[active]).html();
    li_val = li_val.toLowerCase();
    var find1 = li_val.indexOf('</span>');
    var find2 = li_val.indexOf('</a>', find1);
    var words_val = li_val.substring(find1 + 7, find2);
    if (words_val != '') {
        $('#keyWord').val(words_val);
    }
    lis.removeClass("ac_over");
    $(lis[active]).addClass("ac_over");
};
function showall(id, dd, href) {
    zthtml = $('.' + dd).html();
    if (zthtml == '') {
        $.get(href,
        function(data) {
            if (data) {
                $('.' + dd).html($('.' + id + ' .data_ul').html());
                $('.' + id + ' .data_ul').html(data);
            }
        });
    } else if (zthtml != '') {
        $('.' + dd).html($('.' + id + ' .data_ul').html());
        $('.' + id + ' .data_ul').html(zthtml);
    }
    $('.' + id + " .last").hide();
    $('.' + id + " .jingj").show();
}
function backup(id, dd) {
    if ($('.' + dd).html() != '') {
        zthtml = $('.' + id + ' .data_ul').html();
        $('.' + id + ' .data_ul').html($('.' + dd).html());
        $('.' + dd).html(zthtml);
    }
    $('.' + id + " .jingj").hide();
    $('.' + id + " .last").show();
}
$(function() {
    var tab_menu_li = $('.tab_menu li');
    $('.list .tab_box div:gt(0)').hide();
    $('.tab .tab_box div:gt(0)').hide();
    $('.jrtj .tab_box .box:gt(0)').hide();
    $('#con2 .right2 .tab_box div:gt(0)').hide();
    $('#classtab .tab_box div:gt(0)').hide();
    tab_menu_li.mouseover(function() {
        $(this).addClass('current').siblings().removeClass('current');
        var tab_menu_li_index = tab_menu_li.index(this);
        $('.tab_box div').eq(tab_menu_li_index).show().siblings().hide();
    })
});
$(function() {
    $('.#t_nav li.gd a.a_gd').click(function() {
        $('#m_nav .sub_nav .sousuo').removeClass("relative");
        $('.#t_nav li.gd ul').slideDown('fast');
    }).blur(function() {
        $('.#t_nav li.gd ul').slideUp('fast');
        $('#m_nav .sub_nav .sousuo').addClass("relative");
    });
});
$(function() {
    $(".module_up_down").click(function() {
        tmp_html = $("#content #right .cs .nr").html();
        $("#content #right .cs .nr").html($("#content #right .cs .con").html());
        $("#content #right .cs .con").html(tmp_html);
        $(this).hide();
        $(".module_up_up").show();
    });
    $(".module_up_up").click(function() {
        tmp_html = $("#content #right .cs .con").html();
        $("#content #right .cs .con").html($("#content #right .cs .nr").html());
        $("#content #right .cs .nr").html(tmp_html);
        $(this).hide();
        $(".module_up_down").show();
        window.scrollTo(0, 0);
    });
});
$(function() {
    $("#keyWord").focus(function() {
        if ($(this).val() == '菜谱名 食材 功效') {
            $(this).val("");
        }
    }).blur(function() {
        if ($(this).val() == '') {
            $(this).val('菜谱名 食材 功效');
        }
    });
    $("#content #left .list .news li").hover(function() {
        $(this).addClass("li_bg");
    },
    function() {
        $(this).removeClass("li_bg");
    });
    $("#content #left .list .news1 .wzlb .wz").hover(function() {
        $(this).addClass("li_bg2");
    },
    function() {
        $(this).removeClass("li_bg2");
    });
});

function news_reply() {
    $('#saytext').focus();
    $('#repid').val(0);
}
$(function() {
    $('#t_nav .t_li').hover(function() {
        $(this).children('span').show();
    },
    function() {
        $(this).children('span').hide();
    });
});
$(function() {
    $('.titl .menu li.wzdh').hover(function() {
        $(this).children('ul').show();
        $(this).children('span').show();
        $(this).children('a').addClass("border");
        $(this).children('a').children('em').text("▲");
    },
    function() {
        $(this).children('ul').hide();
        $(this).children('span').hide();
        $(this).children('a').removeClass("border");
        $(this).children('a').children('em').text("▼")
    });
});
$(function() {
    $('.titl .menu li.zn').hover(function() {
        $(this).children('div').show();
        $(this).children('span').show();
        $(this).children('a').removeClass("test").addClass("border2");
        $(this).children('a').children('em').text("▲");
    },
    function() {
        $(this).children('div').hide();
        $(this).children('span').hide();
        $(this).children('a').removeClass("border2").addClass("test");
        $(this).children('a').children('em').text("▼")
    });
});
