$(document).ready(function() {    var height = $(window).height();    var current_height = $("#container").height();    if (current_height <= 500) {        var new_height = $(window).height() - 280;        $("#container").css("height", new_height + "px");    }    $(".tab-menu li a").click(function() {        if ($(this).attr("id") == "l1") {            $("#l2").removeClass("active");            $("#l1").addClass("active");            $("#tab2").hide();            $("#tab1").show();        } else {            $("#l1").removeClass("active");            $("#l2").addClass("active");            $("#tab1").hide();            $("#tab2").show();        }    });    $("ul.select-list2 span").click(function() {        if ($(this).attr("id") != "sizes") {            var p = $(this).parent().parent();            if ($(this).hasClass("active")) {                $(this).removeClass("active");            } else {                $.each(p.children("li").children("span"), function(index, value) {                    $(this).removeClass("active");                })                $(this).addClass("active");            }        }    });    $("ul.select-list span").click(function() {        var p = $(this).parent().parent();        var eid = $(this).attr("data-id");        var type = $(this).attr("type");        var pid = $(this).attr("rel");        if ($(this).hasClass("active")) {            $.post("/catalog/selectprops/", { eid: eid, pid: 0, type: type }, function(data) {}, "json");            $(this).removeClass("active");        } else {            $.each(p.children("li").children("span"), function(index, value) {                $(this).removeClass("active");            })            $.post("/catalog/selectprops/", { eid: eid, pid: pid, type: type }, function(data) {}, "json");            $(this).addClass("active");        }    });    $(".amount").keyup(function() {        var eid = $(this).attr("eid");        $.post("/catalog/refresh/", { eid: eid, count: $("#count_" + eid).val() },            function(data) {                $("#cell" + eid).html(data.cell);                $("#itogo_sum").text(data.sum);        }, "json");    });    $("#make_order").click(function () {        $.post("/user/orderSubmit/", { payment: $('input[name="payment"]:checked').val(), delivery: $('input[name="delivery"]:checked').val(), com: $('#com').val() },            function(data) {                if (data.type == "error") {                    $("#warning_text").text(data.message);                    $("#warning").show();                } else {                    $("#warning_text").text(data.message);                    $("#warning").show();                    $("#warning span.close").bind( "click", function(event, ui) {                        window.location = "/user/history/";                    });                }            }, "json");        return false;    });    $(".tooltip span.close").click(function () {        $(this).parent().hide();    });});function addToBasket() {    var selected_size = "undefined";    var selected_color = "undefined";    var pid = $('#pid').val();    $.each($("#size-select li span"), function (index, value) {        if ($(this).hasClass("active")) selected_size = $(this).attr("rel");    });    $.each($("#color-select li span"), function (index, value) {        if ($(this).hasClass("active")) selected_color = $(this).attr("rel");    });    $.post("/catalog/addToBasket/", { pid: pid, size: selected_size, color: selected_color },        function(data) {            if (data == "Товар добавлен в корзину!") {                $("#basket_add_result").show();                $("#add" + pid).replaceWith('<a class="btn-blue" href="/user/basket/">Перейти в корзину</a>');                UpdateBasket();            }        });}function UpdateBasket() {    $.post("/catalog/UpdateBasket/", {},        function(data) {            document.getElementById("head_korzina").innerHTML = data;        });}function checkForm() {    var cnt = $(".cart tr").length - 1;    var good = 0;    $.each($(".select-list"), function() {        $.each($(this).children("li").children("span"), function() {            if ($(this).hasClass("active")) good += 1;        });    });    if (cnt * 2 != good) {        $("#warning").show();        return false;    } else {        window.location = '/user/profile/';    }}
