var divclick = false;
$(document).ready(function () {
    $(".basketImage").click(function () {
        var prodData = $(this).parent().parent();
        var cntAmount = prodData.children(".cntAmount");
        var cntAdded = prodData.children(".cntAdded");
        prodData.parent().siblings().children().children(".cntAdded").hide();
        cntAdded.hide();
        cntAmount.show();
        cntAmount.children(".amount").focus();
        cntAmount.children(".amount2").focus();
    });
    $(".emptyBasketLink").click(function () {
        $(".emptyCart").val('True');
    });
    $('.amount').keyup(function (e) {
        var button = $(this).parent().children(".submit");
        if ($(this).val().length == 0) {
            button.attr('disabled', 'true');
        } else {
            button.removeAttr('disabled');
        }
        var regExpr = new RegExp("^[0-9]*$");
        if (!regExpr.test($(this).val())) {
            $(this).parent().parent().children(".cntErrorBox").show();
            button.attr('disabled', 'true');
        } else {
            $(this).parent().parent().children(".cntErrorBox").hide();
        }
    });
    $('.amount').keydown(function (e) {
        if (e.keyCode == 13) {
            $(this).parent().children(".submit").click();
            e.preventDefault();
        }
    });
    $('.amount').blur(function () {
        if (divclick) return (divclick = false);
        $(this).parent().parent().children(".cntErrorBox").hide();
        $(this).parent().hide();
    });
    $(".emptyBasketLink").click(function () {
        $(".emptyCart").val('True');
    });

    $(".addProduct").click(function (event) {
        var container = $(this).parent().parent();
        var amount = $(this).parent().children(".amount").val();
        var sku = container.children(".sku").val();
        ajaxReload({ catalog: "catalog", sku: sku, quantityInput: amount, macro: "ShiftSmallCart" }, "#smallCart");
        container.children(".cntAmount").hide();
        container.children(".cntAdded").show();
        divclick = false;
        event.preventDefault();
    });
    $('.addProduct').mousedown(function () {
        divclick = true;
    });

    $(".addProduct2").click(function (event) {
        var container = $(this).parent().parent();
        var amount = $(this).parent().children(".amount2").val();
        var sku = container.children(".sku").val();
        ajaxReload({ catalog: "catalog", sku: sku, quantityInput: amount, macro: "ShiftSmallCart" }, "#smallCart");
        container.children(".cntAmount").hide();
        container.children(".cntAdded").show();
        divclick2 = false;
        event.preventDefault();
    });

    $('.addProduct2').mousedown(function () {
        divclick2 = true;
    });
});
