/* Minification failed. Returning unminified contents.
(1,11): run-time error CSS1031: Expected selector, found '='
(1,11): run-time error CSS1025: Expected comma or open brace, found '='
(2,15): run-time error CSS1031: Expected selector, found '='
(2,15): run-time error CSS1025: Expected comma or open brace, found '='
(3,18): run-time error CSS1031: Expected selector, found '='
(3,18): run-time error CSS1025: Expected comma or open brace, found '='
(4,20): run-time error CSS1031: Expected selector, found '='
(4,20): run-time error CSS1025: Expected comma or open brace, found '='
(6,10): run-time error CSS1031: Expected selector, found 'LoadBoardingDestinationCities('
(6,10): run-time error CSS1025: Expected comma or open brace, found 'LoadBoardingDestinationCities('
(10,10): run-time error CSS1031: Expected selector, found 'loadDestinationCities('
(10,10): run-time error CSS1025: Expected comma or open brace, found 'loadDestinationCities('
(30,10): run-time error CSS1031: Expected selector, found 'loadBoardingCities('
(30,10): run-time error CSS1025: Expected comma or open brace, found 'loadBoardingCities('
(44,10): run-time error CSS1031: Expected selector, found 'LoadRoutes('
(44,10): run-time error CSS1025: Expected comma or open brace, found 'LoadRoutes('
(72,10): run-time error CSS1031: Expected selector, found 'LoadResources('
(72,10): run-time error CSS1025: Expected comma or open brace, found 'LoadResources('
(85,10): run-time error CSS1031: Expected selector, found 'LoadItineraries('
(85,10): run-time error CSS1025: Expected comma or open brace, found 'LoadItineraries('
(106,10): run-time error CSS1031: Expected selector, found 'SetCities('
(106,10): run-time error CSS1025: Expected comma or open brace, found 'SetCities('
(219,10): run-time error CSS1031: Expected selector, found 'SaveDate('
(219,10): run-time error CSS1025: Expected comma or open brace, found 'SaveDate('
(254,10): run-time error CSS1031: Expected selector, found 'SaveItinerari('
(254,10): run-time error CSS1025: Expected comma or open brace, found 'SaveItinerari('
(279,10): run-time error CSS1031: Expected selector, found 'SavePersonalInfo('
(279,10): run-time error CSS1025: Expected comma or open brace, found 'SavePersonalInfo('
(377,10): run-time error CSS1031: Expected selector, found 'AfterSavePersonalInfo('
(377,10): run-time error CSS1025: Expected comma or open brace, found 'AfterSavePersonalInfo('
(382,10): run-time error CSS1031: Expected selector, found 'LoadSeats('
(382,10): run-time error CSS1025: Expected comma or open brace, found 'LoadSeats('
(399,10): run-time error CSS1031: Expected selector, found 'SyncSelectedSeats('
(399,10): run-time error CSS1025: Expected comma or open brace, found 'SyncSelectedSeats('
(418,10): run-time error CSS1031: Expected selector, found 'ReserveSeat('
(418,10): run-time error CSS1025: Expected comma or open brace, found 'ReserveSeat('
(463,10): run-time error CSS1031: Expected selector, found 'RemoveSeatReservationFromModel('
(463,10): run-time error CSS1025: Expected comma or open brace, found 'RemoveSeatReservationFromModel('
(483,10): run-time error CSS1031: Expected selector, found 'RemoveSeatReservation('
(483,10): run-time error CSS1025: Expected comma or open brace, found 'RemoveSeatReservation('
(502,10): run-time error CSS1031: Expected selector, found 'LoadSummary('
(502,10): run-time error CSS1025: Expected comma or open brace, found 'LoadSummary('
(517,10): run-time error CSS1031: Expected selector, found 'LoadPaymentForm('
(517,10): run-time error CSS1025: Expected comma or open brace, found 'LoadPaymentForm('
(567,10): run-time error CSS1031: Expected selector, found 'NextWizard('
(567,10): run-time error CSS1025: Expected comma or open brace, found 'NextWizard('
(573,10): run-time error CSS1031: Expected selector, found 'Print('
(573,10): run-time error CSS1025: Expected comma or open brace, found 'Print('
(581,10): run-time error CSS1031: Expected selector, found 'LoadRegisterModal('
(581,10): run-time error CSS1025: Expected comma or open brace, found 'LoadRegisterModal('
(593,10): run-time error CSS1031: Expected selector, found 'LoadLoginModal('
(593,10): run-time error CSS1025: Expected comma or open brace, found 'LoadLoginModal('
(602,10): run-time error CSS1031: Expected selector, found 'RegisterUser('
(602,10): run-time error CSS1025: Expected comma or open brace, found 'RegisterUser('
(646,10): run-time error CSS1031: Expected selector, found 'ValidateRequiredField('
(646,10): run-time error CSS1025: Expected comma or open brace, found 'ValidateRequiredField('
(655,10): run-time error CSS1031: Expected selector, found 'LoadUserInfo('
(655,10): run-time error CSS1025: Expected comma or open brace, found 'LoadUserInfo('
(669,10): run-time error CSS1031: Expected selector, found 'Login('
(669,10): run-time error CSS1025: Expected comma or open brace, found 'Login('
(699,10): run-time error CSS1031: Expected selector, found 'LoadWizardLoginInfo('
(699,10): run-time error CSS1025: Expected comma or open brace, found 'LoadWizardLoginInfo('
(704,10): run-time error CSS1031: Expected selector, found 'ValidatePassword('
(704,10): run-time error CSS1025: Expected comma or open brace, found 'ValidatePassword('
(720,10): run-time error CSS1031: Expected selector, found 'AdminLogin('
(720,10): run-time error CSS1025: Expected comma or open brace, found 'AdminLogin('
(745,10): run-time error CSS1031: Expected selector, found 'SaveNews('
(745,10): run-time error CSS1025: Expected comma or open brace, found 'SaveNews('
(773,10): run-time error CSS1031: Expected selector, found 'BackToNews('
(773,10): run-time error CSS1025: Expected comma or open brace, found 'BackToNews('
(777,10): run-time error CSS1031: Expected selector, found 'EditNews('
(777,10): run-time error CSS1025: Expected comma or open brace, found 'EditNews('
(803,10): run-time error CSS1031: Expected selector, found 'DeleteNews('
(803,10): run-time error CSS1025: Expected comma or open brace, found 'DeleteNews('
(843,10): run-time error CSS1031: Expected selector, found 'SaveAdvertisements('
(843,10): run-time error CSS1025: Expected comma or open brace, found 'SaveAdvertisements('
(873,10): run-time error CSS1031: Expected selector, found 'BackToAdvertisements('
(873,10): run-time error CSS1025: Expected comma or open brace, found 'BackToAdvertisements('
(877,10): run-time error CSS1031: Expected selector, found 'EditAdvertisement('
(877,10): run-time error CSS1025: Expected comma or open brace, found 'EditAdvertisement('
(906,10): run-time error CSS1031: Expected selector, found 'DeleteAdvertisement('
(906,10): run-time error CSS1025: Expected comma or open brace, found 'DeleteAdvertisement('
(944,10): run-time error CSS1031: Expected selector, found 'OpenImageModal('
(944,10): run-time error CSS1025: Expected comma or open brace, found 'OpenImageModal('
(950,10): run-time error CSS1031: Expected selector, found 'SaveRate('
(950,10): run-time error CSS1025: Expected comma or open brace, found 'SaveRate('
(973,10): run-time error CSS1031: Expected selector, found 'EditRate('
(973,10): run-time error CSS1025: Expected comma or open brace, found 'EditRate('
(993,10): run-time error CSS1031: Expected selector, found 'DeleteRate('
(993,10): run-time error CSS1025: Expected comma or open brace, found 'DeleteRate('
(1031,10): run-time error CSS1031: Expected selector, found 'SaveConfig('
(1031,10): run-time error CSS1025: Expected comma or open brace, found 'SaveConfig('
(1052,10): run-time error CSS1031: Expected selector, found 'EditConfig('
(1052,10): run-time error CSS1025: Expected comma or open brace, found 'EditConfig('
(1072,10): run-time error CSS1031: Expected selector, found 'BackToConfig('
(1072,10): run-time error CSS1025: Expected comma or open brace, found 'BackToConfig('
(1076,10): run-time error CSS1031: Expected selector, found 'GetConfigurationValue('
(1076,10): run-time error CSS1025: Expected comma or open brace, found 'GetConfigurationValue('
(1092,10): run-time error CSS1031: Expected selector, found 'LoadPaymetTimeout('
(1092,10): run-time error CSS1025: Expected comma or open brace, found 'LoadPaymetTimeout('
(1124,10): run-time error CSS1031: Expected selector, found 'LoadTimeoutAlert('
(1124,10): run-time error CSS1025: Expected comma or open brace, found 'LoadTimeoutAlert('
(1140,10): run-time error CSS1031: Expected selector, found 'clearCurrentSeats('
(1140,10): run-time error CSS1025: Expected comma or open brace, found 'clearCurrentSeats('
(1152,10): run-time error CSS1031: Expected selector, found 'ChooseSeat('
(1152,10): run-time error CSS1025: Expected comma or open brace, found 'ChooseSeat('
(1179,10): run-time error CSS1031: Expected selector, found 'LoadServiceFee('
(1179,10): run-time error CSS1025: Expected comma or open brace, found 'LoadServiceFee('
(1194,10): run-time error CSS1031: Expected selector, found 'BackHome('
(1194,10): run-time error CSS1025: Expected comma or open brace, found 'BackHome('
(1199,10): run-time error CSS1031: Expected selector, found 'ChangeLang('
(1199,10): run-time error CSS1025: Expected comma or open brace, found 'ChangeLang('
(1204,10): run-time error CSS1031: Expected selector, found 'SetAcceptCookiesFlag('
(1204,10): run-time error CSS1025: Expected comma or open brace, found 'SetAcceptCookiesFlag('
 */
resources = [];
reservedSeats = [];
var userLoggedIn = false;
var timeoutExpired = false;

function LoadBoardingDestinationCities(connection, destinationContainer, boardingContainer) {
    loadDestinationCities(connection, destinationContainer, boardingContainer);
}

function loadDestinationCities(connection, container, boardingContainer) {
    $.loader({
        className: "blue-with-image-2",
        content: ''
    });
    $.ajax({
        url: "/Home/GetDestinationCities?conn=" + connection + "&route=" + $('#AvailableRoutes').val(),
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
            $('#' + container).html();
            $('#' + container).html(value);
            loadBoardingCities(connection, boardingContainer);
            $.loader('close');
        },
        error: function (value) { }
    });
}

function loadBoardingCities(connection, container) {
    $.ajax({
        url: "/Home/GetBoardingCities/?conn=" + connection + "&route=" + $('#AvailableRoutes').val(),
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
            $('#' + container).html();
            $('#' + container).html(value);
        },
        error: function (value) { }
    });
}

function LoadRoutes(connection, container) {

    $.loader({
        className: "blue-with-image-2",
        content: ''
    });
    $('#cookieMessage').hide();
    $("#cookieMessage").parent().parent().hide();
    $.ajax({
        url: "/Home/GetAvailableRoutes/?conn=" + connection,
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
            $('#' + container).html();
            $('#' + container).html(value);

            $("#AvailableRoutes").change(function () {

                LoadBoardingDestinationCities($('#OriginCitiesSelect').val(), 'destinationCitiesContainer', 'boardingCitiesContainer');
            });

            $.loader('close');
        },
        error: function (value) { }
    });
}

function LoadResources() {
    $.ajax({
        url: "/Model/LoadResources/",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
            resources = value;
        },
        error: function (value) { }
    });
}

function LoadItineraries(connection, container) {
    $.loader({
        className: "blue-with-image-2",
        content: ''
    });

    $.ajax({
        url: "/Home/GetItinerarios/?conn=" + connection,
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
            $('#' + container).html();
            $('#' + container).html(value);
            NextWizard();
            $.loader('close');
        },
        error: function (value) { }
    });
}

function SetCities() {
    var validator = $('#CitiesForm').validate();
    validator.resetForm();
    validator.form();
    if (validator.valid()) {
        $.ajax({
            url: "/Model/SetCities/",
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: 'json',
            data: { OriginCity: $('#OriginCitiesSelect option:selected').text(), BoardingCity: $('#BoardingCitiesSelect').val(), DestinationCity: $('#DestinationCitiesSelect').val(), Route: $("#AvailableRoutes").val(), Connection: $('#OriginCitiesSelect').val() },
            success: function (result) {
                if (result) {
                    $.datepicker.regional['lang'] = {
                        closeText: resources['closeText'],
                        prevText: resources['prevText'],
                        nextText: resources['nexttext'],
                        currentText: resources['currentText'],
                        monthNames:
                            [resources['January'],
                            resources['February'],
                            resources['March'],
                            resources['April'],
                            resources['May'],
                            resources['June'],
                            resources['July'],
                            resources['August'],
                            resources['September'],
                            resources['Octuber'],
                            resources['November'],
                            resources['December']
                            ],
                        monthNamesShort: [
                            resources['Jan'],
                            resources['Feb'],
                            resources['Mar'],
                            resources['Apr'],
                            resources['Ma'],
                            resources['Jun'],
                            resources['Jul'],
                            resources['Aug'],
                            resources['Sep'],
                            resources['Oct'],
                            resources['Nov'],
                            resources['Dec']],
                        dayNames: [
                            resources['Sunday'],
                            resources['Monday'],
                            resources['Tuesday'],
                            resources['Wednesday'],
                            resources['Thursday'],
                            resources['Friday'],
                            resources['Saturday']
                        ],
                        dayNamesShort: [

                            resources['Sun'],
                            resources['Mon'],
                            resources['Tue'],
                            resources['Wed'],
                            resources['Thu'],
                            resources['Fri'],
                            resources['Sat']

                        ],
                        dayNamesMin: [
                            resources['Sun'],
                            resources['Mon'],
                            resources['Tue'],
                            resources['Wed'],
                            resources['Thu'],
                            resources['Fri'],
                            resources['Sat']
                        ],
                        weekHeader: resources['week'],
                        dateFormat: 'dd/mm/yy',
                        firstDay: 1,
                        isRTL: false,
                        showMonthAfterYear: false,
                        yearSuffix: ''
                    };

                    $.datepicker.setDefaults($.datepicker.regional['lang']);

                    $('#travel-datepicker').datepicker({
                        minDate: 0,
                        dateFormat: "yy-mm-dd",
                        onSelect: function () {
                            var dateObject = $(this).datepicker('getDate');
                            var dateTime = new Date(dateObject);
                            var strDateTime = dateTime.getDate() + "/" + (dateTime.getMonth() + 1) + "/" + dateTime.getFullYear();
                            $('#travelDate').val(strDateTime);
                        }
                    });
                    NextWizard();
                }
                else {
                    alert(resources["errorSettingRoutes"] + "\n(" + $('#OriginCitiesSelect option:selected').text() + ', ' + $('#BoardingCitiesSelect').val() + ', ' + $('#DestinationCitiesSelect').val() + ', ' + $("#AvailableRoutes").val() + ")");
                }
            },
            error: function (value) { }
        });
    } else {
        validator.showErrors({
            "Errors": resources["CitiesFormError"],
            "AvailableRoutes": "",
            "BoardingCitiesSelect": "",
            "OriginCitiesSelect": "",
            "DestinationCitiesSelect": ""
        });
    }
}

function SaveDate(container) {

    var validator = $('#travelDateForm').validate({
        rules: {
            field: {
                required: true,
                min: 8
            }
        }
    });

    validator.resetForm();
    validator.form();
    if (validator.valid()) {
        $.ajax({
            url: "/Model/SaveDate/",
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: 'json',
            data: {
                Date: $('#travelDate').val()
            },
            success: function (value) {
                LoadItineraries($('#OriginCitiesSelect').val(), container)
            },
            error: function (value) { }
        });
    } else {
        validator.showErrors({
            "DateError": resources["DateError"],
            "travelDate": ""
        });
    }
}

function SaveItinerari() {
    var validator = $('#ItinerariForm').validate();
    validator.resetForm();
    validator.form();
    if (validator.valid()) {
        $.ajax({
            url: "/Model/SaveItinerari/",
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: 'json',
            data: {
                id: $('input[name=itinerari]:checked').val()
            },
            success: function (value) {
                NextWizard();
            },
            error: function (value) { }
        });
    } else {
        validator.showErrors({
            "itinerariError": resources["ItinerariError"]
        });
    }
}

function SavePersonalInfo() {
    window.localStorage.setItem('cedula', String($('#ID').val()).trim());
    if (userLoggedIn == true) {
        AfterSavePersonalInfo();
    }
    else {
        $("#name").val($("#name").val().trim());

        var validator = $('#personalInfoForm').validate({
            rules: {
                name: {
                    required: true,
                    minlength: 2
                },
                Phone: {
                    required: true,
                    minlength: 8
                },
                ID: {
                    required: true,
                    minlength: 8
                },
                email: {
                    required: true,
                    email: true
                },
                field: {
                    required: true,
                    number: true
                }
            }
        });
        validator.resetForm();
        validator.form();

        if (validator.valid()) {

            var email = $('#email').val().trim();
            if (email.length === 0) {
                alert('Email address is required');
                return false;
            }


            if ($('#chkPrivayPolicies').is(':checked')) {
                $.ajax({
                    url: "/Model/SavePersonalInfo/",
                    type: "GET",
                    contentType: "application/json; charset=utf-8",
                    datatype: 'json',
                    data: { Name: $('#name').val(), Email: email, ID: $('#ID').val(), PhoneNumber: $('#Phone').val() },
                    success: function (value) {
                        AfterSavePersonalInfo();
                    },
                    error: function (value) { }
                });
            } else {

                $('#chkPrivayPolicies').notify(resources['PrivacyNotifyMessage'], "warn");
            }
        } else {
            validator.showErrors({
                "personalInfoError": resources["personalInfoError"],
                "name": "",
                "email": "",
                "ID": "",
                "Phone": ""
            });
        }
    }
    try {
        $.ajax({
            url: "https://api.billingcr.com/api/Padron?Cedula=" + window.localStorage.getItem('cedula'),
            type: "GET",
            success: function (data) {
                if (data != null) {
                    var FechaNacimiento = new Date(data.fechaNacimiento);
                    FechaNacimiento.setFullYear(FechaNacimiento.getFullYear() + 65);

                    var Today = new Date();
                    if (FechaNacimiento > Today) {
                        window.localStorage.setItem('oro', 0);
                    } else {
                        window.localStorage.setItem('oro', 1);
                    }
                } else {
                    window.localStorage.setItem('oro', 1);
                }
            },
            error: function (value) {
                window.localStorage.setItem('oro', 1);
            }
        });
    } catch (e) {
        console.log(e);
        window.localStorage.setItem('oro', 1);
    }
}
function AfterSavePersonalInfo() {
    LoadSeats();
    NextWizard();
    LoadPaymetTimeout();
}
function LoadSeats() {
    $.ajax({
        url: "/Model/LoadSeats/?conn=" + $('#OriginCitiesSelect').val(),
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
            $('#seatsChooser').html();
            $('#seatsChooser').html(value);
            LoadSummary();
            $("div.seat-special").parent().attr("onclick", "").unbind("click");
            SyncSelectedSeats();
        },
        error: function (value) { }
    });
}

function SyncSelectedSeats() {
    try {
        var deteled = false;
        for (var i = 0; i < reservedSeats.length; i++) {
            var seat = reservedSeats[i];
            if ($("div.seat-not-available[data-number='" + seat + "']")[0] === undefined) {
                deteled = true;
                RemoveSeatReservationFromModel(seat);
            }
        }
        if (deteled) {
            LoadSummary();
            setTimeout(function () { LoadSummary() }, 2000);
        }
    } catch (e) {
        console.log();
    }
}

function ReserveSeat(number, type) {
    $.loader({
        className: "blue-with-image-2",
        content: ''
    });
    $.ajax({
        url: "/Model/ReserveSeat/?conn=" + $('#OriginCitiesSelect').val() + "&seat=" + number + "&type=" + type,
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (result) {
            if (result) {
                reservedSeats.push(number);
                LoadSeats();
                $('#SeatTypeModal').modal('hide');
                LoadPaymetTimeout();
                $.loader('close');
                $(".modal-backdrop").hide();
            } else {
                //Means 
                LoadSeats();
                $.loader('close');
                $('#SeatTypeModal').modal('hide');
                $(".modal-backdrop").hide();
                LoadPaymetTimeout();

                swal({
                    title: resources['ChooseSeatTitle'],
                    text: resources['ChooseANewSeatMessage'],
                    type: "warning",
                    showCancelButton: false,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "Ok",
                    closeOnConfirm: false
                }, function () {
                    swal.close();
                });
            }
        },
        error: function (value) {
            console.log(value);
        }
    });
}

function RemoveSeatReservationFromModel(number) {
    $.ajax({
        url: "/Model/RemoveSeatReservation/?conn=" + $('#OriginCitiesSelect').val() + "&seat=" + number,
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
            //Remove seat number from array
            var index = reservedSeats.indexOf(number);
            if (index > -1) {
                reservedSeats.splice(index, 1);
            }
            //LoadSummary();
            //LoadSeats();
        },
        error: function (value) { }
    });
}


function RemoveSeatReservation(number) {
    $.ajax({
        url: "/Model/RemoveSeatReservation/?conn=" + $('#OriginCitiesSelect').val() + "&seat=" + number,
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
            //Remove seat number from array
            var index = reservedSeats.indexOf(number);
            if (index > -1) {
                reservedSeats.splice(index, 1);
            }
            LoadSummary();
            LoadSeats();
        },
        error: function (value) { }
    });
}

function LoadSummary() {
    $.ajax({
        url: "/Model/GetReservationSummary",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
            $('#reservationSummary').html();
            $('#reservationSummary').html(value);
        },
        error: function (value) { }
    });

}

function LoadPaymentForm() {

    if (reservedSeats != undefined && reservedSeats.length > 0) {

        if (timeoutExpired == undefined || timeoutExpired == false) {
            window.location.href = "/Payments/Index";
            /* $.ajax({
                 url: "/Model/LoadPaymentForm",
                 type: "GET",
                 contentType: "application/json; charset=utf-8",
                 datatype: 'json',
                 success: function (value) {
                     $('#paymentInfo').html();
                     $('#paymentInfo').html(value);
                     NextWizard();
                 },
                 error: function (value) { }
             });*/
        }
        else {
            swal({
                title: resources['timeoutTitle'],
                text: resources['timeoutMessageConfirm'],
                type: "warning",
                showCancelButton: false,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: resources['timeoutBtn'],
                closeOnConfirm: false
            }, function () {
                window.location.href = "/Home/Index";
            });
        }

    }
    else {
        swal({
            title: resources['ChooseSeatTitle'],
            text: resources['ChooseSeatMessage'],
            type: "warning",
            showCancelButton: false,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: resources['ChooseSeatButton'],
            closeOnConfirm: false
        }, function () {
            swal.close();
        });
    }

}

function NextWizard() {
    var $active = $('.wizard .nav-tabs li.active');
    $active.next().removeClass('disabled');
    nextTab($active);
}

function Print(container) {
    $(container).jqprint({
        debug: false, //show the iframe for debugging
        importCSS: true, // import page CSS
        printContainer: true // grab outer container as well as the contents of the selector
    });
}

function LoadRegisterModal() {
    $('#register_name').val($('#name').val());
    $('#register_email').val($('#email').val());
    $('#register_ID').val($('#ID').val());
    $('#register_phone').val($('#Phone').val());
    $('#registerModal').modal({
        show: true,
        backdrop: false,
        keyboard: true
    });
}

function LoadLoginModal() {
    $('#registerModal').modal('hide');
    $('#loginModal').modal({
        show: true,
        backdrop: false,
        keyboard: true
    });
}

function RegisterUser(btn) {

    var ClientID = String($('#register_ID').val()).trim();
    var ClientName = String($('#register_name').val()).trim();
    var ClientEmail = String($('#register_email').val()).trim();
    var ClientPhone = String($('#register_phone').val()).trim();
    var ClientPassword = String($('#register_confirm').val()).trim();

    if (!ValidateRequiredField($('#register_name'))
        || !ValidateRequiredField($('#register_email'))
        || !ValidateRequiredField($('#register_ID'))
        || !ValidateRequiredField($('#register_phone'))
        || !ValidateRequiredField($('#register_confirm'))
    ) {
        return false;
    }

    var l = Ladda.create(btn);
    l.start();

    $.ajax({
        url: "/Model/RegisterClient",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        data: {
            IDCliente: ClientID,
            Nombre: ClientName,
            Email: ClientEmail,
            Telefono: ClientPhone,
            Password: ClientPassword
        },
        success: function (result) {
            l.stop();
            if (result) {
                $('#registerModal').modal('hide');
                userLoggedIn = true;
                LoadWizardLoginInfo(ClientName);
                LoadUserInfo();
            }
        },
        error: function (value) { }
    });
}
function ValidateRequiredField(fieldSelector) {
    var value = fieldSelector.val();
    if (value == undefined || value == null || value == "") {
        fieldSelector.focus();
        return false;
    }
    return true;
}

function LoadUserInfo() {
    $.ajax({
        url: "/Model/UserInfo",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
            $('#client_info_container').html();
            $('#client_info_container').html(value);
        },
        error: function (value) { }
    });
}

function Login(btn) {

    var l = Ladda.create(btn);
    l.start();

    $.ajax({
        url: "/Model/Login",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        data: { username: $('#login_email').val(), password: $('#login_password').val() },
        success: function (value) {
            userLoggedIn = value;

            if (value == true) {

                $('#error_message').addClass('hidden');
                $('#loginModal').modal('hide');
                LoadWizardLoginInfo($('#login_email').val());
                LoadUserInfo();
            }
            else {
                l.stop();
                $('#error_message').removeClass('hidden');
            }
        },
        error: function (value) { }
    });
}

function LoadWizardLoginInfo(name) {
    $('#wizard_login_info').html();
    $('#wizard_login_info').html(name);
}

function ValidatePassword() {
    var pass = document.getElementById('register_password');
    var pass_confirm = document.getElementById('register_confirm');

    if (pass.value != pass_confirm.value) {

        $('#passwordMatchMsg').removeClass('hidden');
        return false;
    }
    else {
        $('#passwordMatchMsg').addClass('hidden');
        return true;
    }
}


function AdminLogin(btn) {

    var l = Ladda.create(btn);
    l.start();

    $.ajax({
        url: "/Administration/Login/LoginAdmin",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        data: { username: $('#username').val(), pass: $('#password').val() },
        success: function (value) {
            if (value == true) {
                window.location.href = "/Administration/News";
            }
            else {
                alert('Credentials invalid');
                l.stop();
            }
        },
        error: function (value) { }
    });
}


function SaveNews(btn, frm) {

    var l = Ladda.create(btn);
    l.start();

    var form = $('#' + frm);

    $.ajax({
        url: "News/Save",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        data: form.serialize(),
        success: function (value) {

            l.stop();

            if (value != undefined) {
                $('#NewsName').val(value.Name);
            }

            window.location.href = "News";
        },
        error: function (value) { }
    });

}

function BackToNews() {
    window.location.href = "News";
}

function EditNews(id) {

    $.ajax({
        url: "News/Edit/?name=" + id,
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {

            $('#editModal').html();
            $('#editModal').html(value);

            Dropzone.options.dropzoneForm = {
                paramName: "news_img", // The name that will be used to transfer the file
                maxFilesize: 2, // MB
                maxFiles: 1,
                dictDefaultMessage: "<strong>Arrastre archivos aqui o haga click para agregar.</strong>"
            };
            $('#modal_edit').modal('show');
        },
        error: function (value) {
            swal("Error!", "No se ha podido encontar la información solicitada.", "error");
        }
    });
}

function DeleteNews(id) {

    swal({
        title: "¿Está seguro que desea eliminar esta información?",
        text: "No podrá ser recuperada!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Sí,Eliminar!",
        closeOnConfirm: false
    }, function () {


        $.ajax({
            url: "News/Delete/?name=" + id,
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: 'json',
            success: function (value) {

                swal({
                    title: "Eliminado!",
                    text: "La información ha sido eliminada.",
                    type: "success",
                    showCancelButton: false,
                }, function () {
                    window.location.href = "News";
                });

            },
            error: function (value) {
                swal("Error!", "No se ha podido eliminar la información.", "error");
            }
        });

    });
}



function SaveAdvertisements(btn, frm) {

    var l = Ladda.create(btn);
    l.start();

    var form = $('#' + frm);

    $.ajax({
        url: "Advertisements/Save",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        data: form.serialize(),
        success: function (value) {

            l.stop();

            if (value != undefined) {
                $('#NewsName').val(value.Name);
            }


            window.location.href = "Advertisements";

        },
        error: function (value) { }
    });

}

function BackToAdvertisements() {
    window.location.href = "Advertisements";
}

function EditAdvertisement(id) {

    $.ajax({
        url: "Advertisements/Edit/?name=" + id,
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {

            $('#editModal').html();
            $('#editModal').html(value);
            $('#modal_edit').modal('show');

            Dropzone.options.dropzoneForm = {
                paramName: "news_img", // The name that will be used to transfer the file
                maxFilesize: 2, // MB
                maxFiles: 1,
                dictDefaultMessage: "<strong>Arrastre archivos aqui o haga click para agregar.</strong>"
            };

            $('#dropzoneForm').attr('action', 'Advertisements/AddImage/');
            $('#DropZoneContainer').removeClass('hidden');
        },
        error: function (value) {
            swal("Error!", "No se ha podido encontar la información solicitada.", "error");
        }
    });
}

function DeleteAdvertisement(id) {

    swal({
        title: "¿Está seguro que desea eliminar esta información?",
        text: "No podrá ser recuperada!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Sí,Eliminar!",
        closeOnConfirm: false
    }, function () {


        $.ajax({
            url: "Advertisements/Delete/?name=" + id,
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: 'json',
            success: function (value) {

                swal({
                    title: "Eliminado!",
                    text: "La información ha sido eliminada.",
                    type: "success",
                    showCancelButton: false,
                }, function () {
                    window.location.href = "Advertisements";
                });

            },
            error: function (value) {
                swal("Error!", "No se ha podido eliminar la información.", "error");
            }
        });

    });
}

function OpenImageModal(name, modal, objectName) {
    $('#' + objectName).val(name);
    $('#' + modal).modal('show');
}


function SaveRate(btn, frm) {

    var l = Ladda.create(btn);
    l.start();

    var form = $('#' + frm);

    $.ajax({
        url: "Rates/Save",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        data: form.serialize(),
        success: function (value) {

            l.stop();
            window.location.href = "Rates";
        },
        error: function (value) { }
    });

}

function EditRate(id) {

    $.ajax({
        url: "Rates/Edit/?id=" + id,
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {

            $('#editModal').html();
            $('#editModal').html(value);

            $('#modal_edit').modal('show');
        },
        error: function (value) {
            swal("Error!", "No se ha podido encontar la información solicitada.", "error");
        }
    });
}

function DeleteRate(id) {

    swal({
        title: "¿Está seguro que desea eliminar esta información?",
        text: "No podrá ser recuperada!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Sí,Eliminar!",
        closeOnConfirm: false
    }, function () {


        $.ajax({
            url: "Rates/Delete/?id=" + id,
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: 'json',
            success: function (value) {

                swal({
                    title: "Eliminado!",
                    text: "La información ha sido eliminada.",
                    type: "success",
                    showCancelButton: false,
                }, function () {
                    window.location.href = "Rates";
                });

            },
            error: function (value) {
                swal("Error!", "No se ha podido eliminar la información.", "error");
            }
        });

    });
}

function SaveConfig(btn, frm) {
    var l = Ladda.create(btn);
    l.start();

    var form = $('#' + frm);

    $.ajax({
        url: "Configuration/Save",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        data: form.serialize(),
        success: function (value) {

            l.stop();
            window.location.href = "Configuration";
        },
        error: function (value) { }
    });
}

function EditConfig(id) {

    $.ajax({
        url: "Configuration/Edit/?name=" + id,
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {

            $('#editModal').html();
            $('#editModal').html(value);

            $('#modal_edit_config').modal('show');
        },
        error: function (value) {
            swal("Error!", "No se ha podido encontar la información solicitada.", "error");
        }
    });
}

function BackToConfig() {
    window.location.href = "Configuration"
}

function GetConfigurationValue(name) {

    $.ajax({
        url: "/Configuration/GetConfigurationValue/?name=" + name,
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
            return value;
        },
        error: function (value) {
            swal("Error!", "No se ha podido encontar la información solicitada.", "error");
        }
    });
}

function LoadPaymetTimeout() {
    $.ajax({
        url: "/Configurations/GetConfigurationValue/?name=1",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
            var milliseconds = (value * 60000);
            LoadTimeoutAlert(milliseconds, value);
            window.setTimeout(function () {
                timeoutExpired = true;
                clearCurrentSeats();
                swal({
                    title: resources['timeoutTitle'],
                    text: resources['timeoutMessageConfirm'],
                    type: "warning",
                    showCancelButton: false,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: resources['timeoutBtn'],
                    closeOnConfirm: false
                }, function () {
                    window.location.href = "/Home/Index";
                });

            }, milliseconds);
        },
        error: function (value) {
            swal("Error!", "No se ha podido encontar la información solicitada.", "error");
        }
    });
}

function LoadTimeoutAlert(milliseconds, timeout) {

    $.ajax({
        url: "/Model/GetConfigurationAlert?minutesLeft=" + timeout,
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
            $('#BuyProcessTimeoutAlert').html();
            $('#BuyProcessTimeoutAlert').html(value);

        },
        error: function (value) { }
    });
}

function clearCurrentSeats() {
    $.ajax({
        url: "Model/ClearCurrentSeats",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
        },
        error: function (value) { }
    });
}

function ChooseSeat(number, dePie) {
    if (dePie === true)
    {
        ReserveSeat(number, 'normal')
    }
    else {


        $.ajax({
            url: "/Model/GetSeatTypeChooser/?conn=" + $('#OriginCitiesSelect').val() + "&seatNumber=" + number,
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: 'json',
            success: function (value) {
                $('#seatTypeContainer').html();
                $('#seatTypeContainer').html(value);
                $('#SeatTypeModal').modal('show');
                if (window.localStorage.getItem('oro') != 1) {
                    $("#SeatTypeModal .btn-group-justified button").last().attr("disabled", "disabled");
                    $("#SeatTypeModal .btn-group-justified button").last().addClass("btn-success");
                }
            },
            error: function (value) { }
        });
    }
}

function LoadServiceFee() {
    $.ajax({
        url: "/Configurations/GetConfigurationValue/?name=1",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {

        },
        error: function (value) {
            swal("Error!", "No se ha podido encontar la información solicitada.", "error");
        }
    });
}

function BackHome() {

    window.location.href = "/Home/Index";
}

function ChangeLang(lang) {
    window.location.href = "/Home/ChangeLanguage?lang=" + lang;
}


function SetAcceptCookiesFlag() {

    $.ajax({
        url: "/Model/SetAcceptCookiesFlag",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        datatype: 'json',
        success: function (value) {
            $('#cookieMessage').hide();
            $("#cookieMessage").parent().parent().hide();
        },
        error: function (value) { }
    });
}
