﻿$(function() {
    $("#search").click(function() {
        //alert("asdas");
        var sp = $("#searchPane");
        var sq = "ci=" + $("#selectCategoryID").val() +
                 "&cp=" + $("#currentPage").val() +
                 "&sq=" + $("input#sName", sp).val() +
                 "&fp=" + $("input#sPrice", sp).val() +
                 "&tp=" + $("input#sPrice2", sp).val();
        $.each($(".searchItemT1", sp), function() {
            sq = sq + "&" + $("input[type=hidden]", this).val() + "=" + $("select:first", this).val() +
                      ";" + $("select:last", this).val();
            //alert($("select:first", this).val());
            //alert($("select:last", this).val());
        });
        $.each($(".searchItemT2", sp), function() {
            sq = sq + "&" + $("input[type=hidden]", this).val() + "=" + $(".svalue", this).val();
        });
        alert(sq);
        $.post(
            "/Catalog.aspx/GetProd",
            { qu: sq },
            function(res) { },
            "json");
    });
    $("#sh_sp_btn").click(function() {
        $(".shpan").slideToggle("slow");
        if ($(this).text() == "Скрыть панель поиска") {
            $(this).text("Показать панель поиска");
            $.post(
                "/Catalog.aspx/ShowHideSPane",
                { s: 0 },
                function() { },
                "json");
        } else {
            $(this).text("Скрыть панель поиска");
            $.post(
                "/Catalog.aspx/ShowHideSPane",
                { s: 1 },
                function() { },
                "json");
        }

    });

    $.fn.addToChart = function(pId, vId) {
        $.post(
            "/Catalog.aspx/AddToChart",
            { id: pId, vid:vId },
            function(res) {
                $("#curPrice").text(res.nPrice);
            },
            "json");
        return false;
    }

    $.fn.removeFromChart = function(pId) {
        $.post(
            "/Catalog.aspx/RemoveFromChart",
            { id: pId },
            function(res) {
                $("#curPrice").text(res.nPrice);
            },
            "json");
        return false;
    }
});
