/* Minification failed. Returning unminified contents.
(1,1): run-time error CSS1019: Unexpected token, found '$'
(1,2): run-time error CSS1019: Unexpected token, found '('
(1,3): run-time error CSS1019: Unexpected token, found ')'
(1,5): run-time error CSS1030: Expected identifier, found 'ready('
(1,5): run-time error CSS1019: Unexpected token, found 'ready('
(1,20): run-time error CSS1031: Expected selector, found '('
(1,20): run-time error CSS1025: Expected comma or open brace, found '('
(159,2): run-time error CSS1019: Unexpected token, found ')'
(161,10): run-time error CSS1031: Expected selector, found 'updateform('
(161,10): run-time error CSS1025: Expected comma or open brace, found 'updateform('
 */
$().ready(function () {

    $('.frm-select-voucher').on('submit', function (e) {
        e.preventDefault();

        var form = $(this);

        var voucherType = form.find('#VoucherType').val();
        var data;

        switch (voucherType) {
            case "Book":
                data = {
                    "voucherId": form.find('#book_CardTypeID').val(),
                    "noOfPeople": form.find('input.input-quantity').val(),
                    "voucherType": voucherType,
                    "giftVoucherValue": 0
                };
                break;
            case "Voucher":
                data = {
                    "voucherId": form.find('#voucher_CardTypeID').val(),
                    "noOfPeople": 1,
                    "voucherType": voucherType,
                    "giftVoucherValue": 0
                };
                break;
            case "GiftVoucher":
                data = {
                    "voucherId": "",
                    "noOfPeople": 1,
                    "voucherType": voucherType,
                    "giftVoucherValue": form.find('#giftVoucher').val()
                };
                break;
            default:
                data = null;
                break;
        }


        if (data !== undefined && data.noOfPeople !== undefined && data.voucherId !== undefined) {
            form.find('.alert-danger').hide();
            $.ajax({
                type: "GET",
                url: "/Voucher/GetVoucherForm",
                data: data,
                contentType: "application/html; charset=utf-8",
                dataType: 'html',
                success: function (response) {
                    $("#vouchers").html(response);
                    window.scrollTo(0, 500);
                    $('form').data('validator', null);
                    $.validator.unobtrusive.parse($('form'));
                }, error: function (response) {

                    $.get("/Voucher/GetError", function (response) {
                        form.find('.alert-danger').html(response).show();
                    });

                }
            });
        }
        else {
            form.find('.alert-danger').html("Please enter the number of people").show();
        }
    });


    $('.voucher-info').on('click', function (e) {
        e.preventDefault();

        $.ajax({
            type: "GET",
            url: "/Voucher/EditVoucherDetails",
            data: { "itemId": $(this).data("id") },
            contentType: "application/html; charset=utf-8",
            dataType: 'html',
            success: function (response) {
                $("#vouchers").html(response);
                $('form').data('validator', null);
                $.validator.unobtrusive.parse($('form'));
            }, error: function (response) {
                $.get("/Voucher/GetError", function (response) {
                    form.find('.alert-danger').html(response).show();
                });
            }
        });
    });


    //$('.frm-select-gift').on('submit', function (e) {
    //    e.preventDefault();

    //    var form = $(this);

    //    var voucher = form.find('#giftVoucher').val();

    //    if (voucher !== '') {
    //        form.find('.alert-danger').hide();

    //        $.ajax({
    //            type: "POST",
    //            url: '@Url.Action("AddGiftCardToBasket","Voucher")',
    //            data: { "value": voucher },
    //            success: function (response) {
    //                alert("item added");
    //                form.find('.alert-danger').hide();
    //            }, error: function (response) {
    //                $.get("/Voucher/GetError", function (response) {
    //                    form.find('.alert-danger').html(response).show();
    //                });
    //            }
    //        });
    //    }
    //    else {
    //        form.find('.error').text("Sorry something went wrong");
    //        form.find('.alert-danger').show();
    //    }
    //});

    $('body').on('submit', '#voucher-form', function (e) {
        e.preventDefault();

        var form = $(this);

        $.validator.unobtrusive.parse(".validation-form");
        $("#voucher-form").validate();

        if ($("#voucher-form").valid()) {
            $.ajax({
                type: "POST",
                url: $("#voucher-form").attr("action"),
                data: $("#voucher-form").serialize(),
                success: function (response) {
                    if (response === "" || response === undefined) {
                        window.location.href = "";
                    }
                    else {
                        $("#vouchers").html(response);
                        $('form').data('validator', null);
                        $.validator.unobtrusive.parse($('form'));
                    }

                },
                error: function (response) {
                    $.get("/Voucher/GetError", function (response) {
                        form.find('.alert-danger').html(response).show();
                    });
                }
            });
        }
    });


    $('body').on('click', 'input[type=radio]', function () {
        updateform($(this).val());
    });
});

function updateform(selectedOption) {
    switch (selectedOption) {
        case 'TODELIVER':
            $('#RecipientDetails').hide();
            $('#DeliveryDetails').show();
            break;
        case 'EMAILED':
            $('#RecipientDetails').show();
            $('#DeliveryDetails').hide();
            break;
        default:
            $('#RecipientDetails').hide();
            $('#DeliveryDetails').hide();
            break;
    }
}

