/* 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 '('
(208,2): run-time error CSS1019: Unexpected token, found ')'
(210,10): run-time error CSS1031: Expected selector, found 'updateform('
(210,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": form.find('#voucher_minimumnumberofpeople').val(),
                    "voucherType": voucherType,
                    "giftVoucherValue": 0
                };
                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, 0);
                    $('form').data('validator', null);
                    $.validator.unobtrusive.parse($('form'));
                    $('.logo-white').hide();
                    $('.logo-dark').show();
                    $('.fa-bars').css('color', 'black');
                }, 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) {
                $(".basket-container").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();
                });
            }
        });
    });


    $('.voucher-proceed').on('click', function (e) {
        e.preventDefault();
        var form = $(this).parents('form');
        var data = {
            "voucherId": "",
            "noOfPeople": 1,
            "voucherType": "GiftVoucher",
            "giftVoucherValue": $('.giftvouchers').val()
        };

        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, 0);
                    $('form').data('validator', null);
                    $.validator.unobtrusive.parse($('form'));
                    $('.logo-white').hide();
                    $('.logo-dark').show();
                    $('.fa-bars').css('color', 'black');
                }, 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();
        }
    });

    $('#feedback-form').on("submit", function (e) {
        e.preventDefault();

        var $form = $('#feedback-form');
        var data = {
            Name: $form.find('#feedbackForm_Name').val(),
            Email: $form.find('#feedbackForm_Email').val(),
            Birthday: $form.find('#feedbackForm_Birthday').val(),
            Business: $form.find('#feedbackForm_Business').val(),
            Phone: $form.find('#feedbackForm_Phone').val()
        };

        $.validator.unobtrusive.parse(".validation-form");
        $form.validate();

        if ($form.valid()) {
            $.ajax({
                type: "POST",
                url: "/Voucher/SendFeedback",
                data: data,
                success: function (response) {
                    if (response.response === "Success") {                       
                        $('.error-alert').hide();
                        $('.success-alert').show();
                    }
                    else {
                        $('.success-alert').hide();
                        $('.error-alert').show();
                    }
                },
                error: function (response) {
                    $('.success-alert').hide();
                    $('.error-alert').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();
                    });
                }
            });
        }
    });

    $('.navbar-collapse').on('hidden.bs.collapse', function () {
        $(".small-basket").css("z-index", 6);
    });

    $('.navbar-collapse').on('show.bs.collapse', function () {
        $(".small-basket").css("z-index", 4);
    });

    $('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;
    }
}

