$(document).ready(function () {
    $("#cat_hprd").hover(function () {
        $(this).children("#htitle").addClass("htitle_over");
        $(this).children("#main_hitem").css("display", "block");
    }, function () {
        $(this).children("#htitle").removeClass("htitle_over");
        $(this).children("#main_hitem").css("display", "none");
    });

    $("#main_hitem .main_hitem_list").hover(function (event) {
        $(this).children("div").css("background", "url(SkinsCss/Css_01/images/sprites.png) #fefae8 no-repeat 0px -343px");
        $(this).children("ul").css("display", "block");
        event.stopPropagation();
    }, function () {
        $(this).children("div").css("background", "url(SkinsCss/Css_01/images/sprites.png) #fdf0f0 no-repeat 178px -4070px");
        $(this).children("ul").css("display", "none");
    })
});

//格式化数字
function format_num(src) {
    val = Math.round(src * 100);
    if (val % 100 == 0) {
        val = val / 100 + ".00";
    }
    else {
        if (val % 10 == 0) {
            val = val / 100 + "0";
        }
        else {
            val = val / 100;
        }
    }
    return val;
}

//顶部搜索
function headsearch() {
    var b = $("#searchkey").val();
    var a = $("#searchcatId").val();
    var c = $("#searchcatname").val();
    if ($.trim(b) == "" || $.trim(b) == "Search Products") {
        $("#searchkey").val("");
        if (a == "") {
            alert("Please input a keyword.");
            return false;
        }
        else {
            //$("#searchFormHead").attr("action", "/wholesale/dirlist.do");
            $("#searchFormHead").submit();
            return false;
        }
    }
    $("#searchFormHead").submit();
    return false;
}

$(document).ready(function () {
    $("#searchkey").focus(function () {
        if ($(this).val() == "Search Products") {
            $(this).val("");
        }
    });
    $("#searchkey").blur(function () {
        $(this).removeClass("input_focus");
        if ($(this).val() == "") {
            $(this).val("Search Products");
        }
    });
});

function doheadsearch() {
    var a = document.getElementById("searchkey").value;
    for (i = 0; i < a.length; i++) {
        if (a.charCodeAt(i) > 255) {
            alert("Please input the information in English ONLY.");
            return true;
        }
    }
    headsearch();
    return false;
}

//顶部搜索菜单
$(document).ready(function () {
    $("#catalog").click(function () {
        $("#catalogListBox")[0].style.display = ($("#catalogListBox")[0].style.display == 'block' ? 'none' : 'block');

    });

    $("#catalogList li[class!='sub-line']").hover(function (event) {
        $(this).addClass("hover");
        $(this).click(function () {
            $("#catalogListBox").css("display", "none");
            $("#searchcatId").val($(this).attr("catalogid"))
            $("#searchcatname").val($.trim($(this).text()))
            $("#catalog").html($(this).text());
            $("#catalogList li:eq(" + $(this).index() + ")").addClass("hover-selected").siblings().removeClass("hover-selected");

        });
    }, function () {
        $(this).removeClass("hover");
    });

});

function searchselected(obj) {
    $("#searchcatId").val(obj)
    $("#searchcatname").val($.trim($("#catalogList li[catalogid='" + obj + "']").text()))
    $("#catalog").html($("#catalogList li[catalogid='" + obj + "']").text());
    $("#catalogList li[catalogid='" + obj + "']").addClass("hover-selected").siblings().removeClass("hover-selected");
}
