/* 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 ''#departDate''
(1,16): run-time error CSS1019: Unexpected token, found ')'
(1,18): run-time error CSS1030: Expected identifier, found 'datepicker('
(1,18): run-time error CSS1019: Unexpected token, found 'datepicker('
(1,29): run-time error CSS1019: Unexpected token, found '{'
(2,15): run-time error CSS1030: Expected identifier, found ' '
(2,20): run-time error CSS1031: Expected selector, found 'Date('
(2,20): run-time error CSS1025: Expected comma or open brace, found 'Date('
(23,2): run-time error CSS1019: Unexpected token, found ')'
(24,1): run-time error CSS1019: Unexpected token, found '$'
(24,2): run-time error CSS1019: Unexpected token, found '('
(24,3): run-time error CSS1019: Unexpected token, found ''#departDate''
(24,16): run-time error CSS1019: Unexpected token, found ')'
(24,18): run-time error CSS1030: Expected identifier, found 'datepicker('
(24,18): run-time error CSS1019: Unexpected token, found 'datepicker('
(24,29): run-time error CSS1019: Unexpected token, found ''setDate''
(24,38): run-time error CSS1019: Unexpected token, found ','
(24,40): run-time error CSS1019: Unexpected token, found ''today''
(24,47): run-time error CSS1019: Unexpected token, found ')'
(26,1): run-time error CSS1019: Unexpected token, found '$'
(26,2): run-time error CSS1019: Unexpected token, found '('
(26,3): run-time error CSS1019: Unexpected token, found ''#arriveDate''
(26,16): run-time error CSS1019: Unexpected token, found ')'
(26,18): run-time error CSS1030: Expected identifier, found 'datepicker('
(26,18): run-time error CSS1019: Unexpected token, found 'datepicker('
(26,29): run-time error CSS1019: Unexpected token, found '{'
(27,15): run-time error CSS1030: Expected identifier, found ' '
(27,16): run-time error CSS1031: Expected selector, found ''today''
(27,16): run-time error CSS1025: Expected comma or open brace, found ''today''
(40,2): run-time error CSS1019: Unexpected token, found ')'
(41,1): run-time error CSS1019: Unexpected token, found '$'
(41,2): run-time error CSS1019: Unexpected token, found '('
(41,3): run-time error CSS1019: Unexpected token, found ''#arriveDate''
(41,16): run-time error CSS1019: Unexpected token, found ')'
(41,18): run-time error CSS1030: Expected identifier, found 'datepicker('
(41,18): run-time error CSS1019: Unexpected token, found 'datepicker('
(41,29): run-time error CSS1019: Unexpected token, found ''setDate''
(41,38): run-time error CSS1019: Unexpected token, found ','
(41,40): run-time error CSS1019: Unexpected token, found ''+3d''
(41,45): run-time error CSS1019: Unexpected token, found ')'
(43,1): run-time error CSS1019: Unexpected token, found '$'
(43,2): run-time error CSS1019: Unexpected token, found '('
(43,3): run-time error CSS1019: Unexpected token, found ''#roundTrip''
(43,15): run-time error CSS1019: Unexpected token, found ')'
(43,17): run-time error CSS1030: Expected identifier, found 'click('
(43,17): run-time error CSS1019: Unexpected token, found 'click('
(43,32): run-time error CSS1031: Expected selector, found '('
(43,32): run-time error CSS1025: Expected comma or open brace, found '('
(51,2): run-time error CSS1019: Unexpected token, found ')'
(53,22): run-time error CSS1031: Expected selector, found '='
(53,22): run-time error CSS1025: Expected comma or open brace, found '='
(58,4): run-time error CSS1031: Expected selector, found '('
(58,4): run-time error CSS1025: Expected comma or open brace, found '('
(62,5): run-time error CSS1062: Expected semicolon or closing curly-brace, found '$'
(63,5): run-time error CSS1062: Expected semicolon or closing curly-brace, found '$'
(66,22): run-time error CSS1031: Expected selector, found '='
(66,22): run-time error CSS1025: Expected comma or open brace, found '='
(67,13): run-time error CSS1031: Expected selector, found '='
(67,13): run-time error CSS1025: Expected comma or open brace, found '='
(69,10): run-time error CSS1031: Expected selector, found 'GetAirlines('
(69,10): run-time error CSS1025: Expected comma or open brace, found 'GetAirlines('
(187,10): run-time error CSS1031: Expected selector, found 'checkAirline('
(187,10): run-time error CSS1025: Expected comma or open brace, found 'checkAirline('
(204,10): run-time error CSS1031: Expected selector, found 'GetAirlinesCookie('
(204,10): run-time error CSS1025: Expected comma or open brace, found 'GetAirlinesCookie('
(225,19): run-time error CSS1031: Expected selector, found '='
(225,19): run-time error CSS1025: Expected comma or open brace, found '='
(226,9): run-time error CSS1030: Expected identifier, found 'change('
(226,9): run-time error CSS1031: Expected selector, found 'change('
(226,9): run-time error CSS1025: Expected comma or open brace, found 'change('
(257,2): run-time error CSS1019: Unexpected token, found ')'
(259,15): run-time error CSS1031: Expected selector, found '='
(259,15): run-time error CSS1025: Expected comma or open brace, found '='
(260,4): run-time error CSS1031: Expected selector, found '('
(260,4): run-time error CSS1025: Expected comma or open brace, found '('
(263,20): run-time error CSS1031: Expected selector, found '='
(263,20): run-time error CSS1025: Expected comma or open brace, found '='
(264,4): run-time error CSS1031: Expected selector, found '('
(264,4): run-time error CSS1025: Expected comma or open brace, found '('
(269,10): run-time error CSS1031: Expected selector, found 'SetOriginList('
(269,10): run-time error CSS1025: Expected comma or open brace, found 'SetOriginList('
(322,10): run-time error CSS1031: Expected selector, found 'SetDestinationList('
(322,10): run-time error CSS1025: Expected comma or open brace, found 'SetDestinationList('
(345,11): run-time error CSS1030: Expected identifier, found 'change('
(345,11): run-time error CSS1031: Expected selector, found 'change('
(345,11): run-time error CSS1025: Expected comma or open brace, found 'change('
(347,2): run-time error CSS1019: Unexpected token, found ')'
(349,10): run-time error CSS1031: Expected selector, found 'GetAirlineSchedules('
(349,10): run-time error CSS1025: Expected comma or open brace, found 'GetAirlineSchedules('
(382,10): run-time error CSS1031: Expected selector, found 'GetAirlineSchedulesWithVerifycation('
(382,10): run-time error CSS1025: Expected comma or open brace, found 'GetAirlineSchedulesWithVerifycation('
(417,10): run-time error CSS1031: Expected selector, found 'setCookie('
(417,10): run-time error CSS1025: Expected comma or open brace, found 'setCookie('
(424,10): run-time error CSS1031: Expected selector, found 'getCookie('
(424,10): run-time error CSS1025: Expected comma or open brace, found 'getCookie('
(435,10): run-time error CSS1031: Expected selector, found 'checkCookie('
(435,10): run-time error CSS1025: Expected comma or open brace, found 'checkCookie('
(447,15): run-time error CSS1031: Expected selector, found '='
(447,15): run-time error CSS1025: Expected comma or open brace, found '='
(448,15): run-time error CSS1031: Expected selector, found '='
(448,15): run-time error CSS1025: Expected comma or open brace, found '='
(449,16): run-time error CSS1031: Expected selector, found '='
(449,16): run-time error CSS1025: Expected comma or open brace, found '='
(450,11): run-time error CSS1030: Expected identifier, found 'change('
(450,11): run-time error CSS1031: Expected selector, found 'change('
(450,11): run-time error CSS1025: Expected comma or open brace, found 'change('
(472,2): run-time error CSS1019: Unexpected token, found ')'
(474,1): run-time error CSS1019: Unexpected token, found '$'
(474,2): run-time error CSS1019: Unexpected token, found '('
(474,3): run-time error CSS1019: Unexpected token, found ''#passenger''
(474,15): run-time error CSS1019: Unexpected token, found ')'
(474,17): run-time error CSS1030: Expected identifier, found 'click('
(474,17): run-time error CSS1019: Unexpected token, found 'click('
(474,32): run-time error CSS1031: Expected selector, found '('
(474,32): run-time error CSS1025: Expected comma or open brace, found '('
(480,2): run-time error CSS1019: Unexpected token, found ')'
(482,1): run-time error CSS1019: Unexpected token, found '$'
(482,2): run-time error CSS1019: Unexpected token, found '('
(482,3): run-time error CSS1019: Unexpected token, found ''#doneSelect''
(482,16): run-time error CSS1019: Unexpected token, found ')'
(482,18): run-time error CSS1030: Expected identifier, found 'click('
(482,18): run-time error CSS1019: Unexpected token, found 'click('
(482,33): run-time error CSS1031: Expected selector, found '('
(482,33): run-time error CSS1025: Expected comma or open brace, found '('
(484,2): run-time error CSS1019: Unexpected token, found ')'
(486,1): run-time error CSS1019: Unexpected token, found '$'
(486,2): run-time error CSS1019: Unexpected token, found '('
(486,11): run-time error CSS1031: Expected selector, found ')'
(486,11): run-time error CSS1025: Expected comma or open brace, found ')'
(529,2): run-time error CSS1019: Unexpected token, found ')'
 */
$('#departDate').datepicker({
    startDate: new Date(),
    format: "DD, d M yyyy",
    language: 'id'
}).on('changeDate', function (e) {
    
    var oldDate = new Date(e.date);
    var newDate = new Date(e.date);
    newDate.setDate(oldDate.getDate() + 3);
    var month = newDate.getMonth() + 1;
    if (month < 10) {
        month = '0' + month;
    }
    $("#brangkatFormatted").val(e.format('yyyy-mm-dd'));
    
    $('#arriveDate').datepicker('remove');
    $('#arriveDate').datepicker({
        startDate: oldDate,
        format: "DD, d M yyyy",
        language: 'id'
    });
    $('#arriveDate').datepicker('setDate', newDate);
});
$('#departDate').datepicker('setDate', 'today');

$('#arriveDate').datepicker({
    startDate: 'today',
    format: "DD, d M yyyy",
    language: 'id'
}).on('changeDate', function (e) {

    var newDate = new Date(e.date);
    var month = newDate.getMonth() + 1;
    if (month < 10) {
        month = '0' + month;
    }

    $("#kembaliReformatted").val(newDate.getFullYear() + "-" + month + "-" + newDate.getDate());

});
$('#arriveDate').datepicker('setDate', '+3d');

$('#roundTrip').click(function () {
    if (this.checked) {
        $('#arriveDate').show();
        $('#roundTrip').val(true);
    } else {
        $('#arriveDate').hide();
        $('#roundTrip').val(false);
    }
});

var AirlineroundTrip = $('#roundTrip');
//console.log(AirlineroundTrip.attr("checked", false));
//if (AirlineroundTrip.attr("checked", false)) {
//    AirlineroundTrip.click();
//}
if ($("#roundTrip").is(':checked')) {
    $('#arriveDate').show();
    $('#roundTrip').val(true);
} else {
    $('#arriveDate').hide();
    $('#roundTrip').val(false);
}

var domesticAirlines = ["QZ", "QG", "GA", "JT", "JTB", "SJ", "TNU", "TN", "XN"];
var airline = $("#airline");

function GetAirlines(element) {
    $(element).attr('onclick', null).off('click');
    var domesticOptions = new Array();
    var interOptions = new Array();
    var dataStorage = getStorage("airlineListInd");
    if (dataStorage && JSON.parse(dataStorage).length > 0) {
        $.blockUI({ message: '<img alt=\'loading\' src=\'/Content/images/Loading.gif\' /><br/>Sedang mengambil maskapai' });

        airline.empty();
        // put option on selected dropdown 
        airline.append(new Option("Semua Maskapai", "ALL"));

        //data = JSON.parse(dataStorage);
        //for (var i = 0; i < data.length; i++) {
        //    var item = data[i];
        //    var newOption = new Option(item.name, item.id);
        //    if (typeof window.defaultAirlineValue !== "undefined" && item.id === window.defaultAirlineValue) {
        //        newOption.selected = true;
        //    }
        //    if (item.id.toLowerCase() !== "all") {
        //        var status = "ok";
        //        for (var ii = 0; ii < domesticAirlines.length; ii++) {
        //            if (item.id.toLowerCase() === domesticAirlines[ii].toLowerCase()) {
        //                domesticOptions.push(newOption);
        //                status = "done";
        //                break;
        //            }
        //        }
        //        if (status === "ok") {
        //            interOptions.push(newOption);
        //        }
        //    } else {
        //        airline.append(new Option("Semua Maskapai", "ALL"));
        //    }
        //}

        if (domesticOptions.length > 0) {
            for ( i = 0; i < domesticOptions.length; i++) {
                airline.append(domesticOptions[i]);
            }
        }
        if (interOptions.length > 0) {
            for ( i = 0; i < interOptions.length; i++) {
                airline.append(interOptions[i]);
            }
        }

        $.unblockUI();
        if (typeof window.defaultAirlineValue !== "undefined") {
            airline.change();
        }
        $("#clickAirline").click();
    } else {
        $.blockUI({ message: '<img alt=\'loading\' src=\'/Content/images/Loading.gif\' /><br/>Sedang mengambil maskapai untuk pertama kali' });
        $.ajax({
            url: "/Airlines/getAirlinesList",
            type: 'POST',
            async: true,
            dataType: 'json',
            data: {},
            cache: true,
            success: function (result) {
                airline.empty();
                // put option on selected dropdown 
                airline.append(new Option("Pilih Maskapai", ""));
                if (result.length > 0) {
                    setStorage("airlineListInd", JSON.stringify(result));
                }
                for (var i = 0; i < result.length; i++) {
                    var item = result[i];
                    var newOption = new Option(item.name, item.id);
                    if (typeof window.defaultAirlineValue !== "undefined" && item.id === window.defaultAirlineValue) {
                        newOption.selected = true;
                    }
                    if (item.id.toLowerCase() !== "all") {
                        var status = "ok";
                        for (var ii = 0; ii < domesticAirlines.length; ii++) {
                            if (item.id.toLowerCase() === domesticAirlines[ii].toLowerCase()) {
                                domesticOptions.push(newOption);
                                status = "done";
                                break;
                            }
                        }
                        if (status === "ok") {
                            interOptions.push(newOption);
                        }
                    } else {
                        airline.append(new Option("Semua Maskapai", "ALL"));
                    }
                }

                if (domesticOptions.length > 0) {
                    for ( i = 0; i < domesticOptions.length; i++) {
                        airline.append(domesticOptions[i]);
                    }
                }
                if (interOptions.length > 0) {
                    for ( i = 0; i < interOptions.length; i++) {
                        airline.append(interOptions[i]);
                    }
                }
                $.unblockUI();

                if (typeof window.defaultAirlineValue !== "undefined") {
                    airline.change();
                }
                $("#clickAirline").click();
                $("#airline").val("ALL");
                $("#airline").change();
            },

            error: function () {
                $.unblockUI();
            }
        });
    }
}

function checkAirline(airlineID) {
    if (airlineID !== "") {
        var hasValue = false;
        $("#airline > option").each(function () {
            if (this.value === airlineID) {
                hasValue = true;
            }
        });
        if (hasValue === true) {
            $("#airline").val(airlineID);
            $("#airline").change();
            $('#airlineName').val(airline[0][airline[0].selectedIndex].text);
            $('#airlineName').change();
        }
    }
}

function GetAirlinesCookie() {
    var airlinesCount = getCookie("airlinesKey");
    if (airlinesCount > 0) {
        airline.empty();
        airline.append(new Option("Pilih Maskapai", ""));
        for (var i = 0; i < airlinesCount; i++) {
            var id = getCookie("airlinesKey" + i);
            var name = getCookie("airlinesValue" + i);
            var newOption = new Option(name, id);
            if (typeof window.defaultAirlineValue !== "undefined" && item.ID === window.defaultAirlineValue) {
                newOption.selected = true;
            }
            airline.append(newOption);
        }

        if (typeof window.defaultAirlineValue !== "undefined") {
            airline.change();
        }
    }
};

var airlineRoutes = new Array();
airline.change(function () {
    var dataStorage = getStorage(airline.val());
    if (dataStorage && JSON.parse(dataStorage).length > 0) {
        $.blockUI({ message: '<img alt=\'loading\' src=\'/Content/images/Loading.gif\' /><br/>Mohon tunggu, sedang mengambil rute ' + $(this).val() });

        data = JSON.parse(dataStorage);
        airlineRoutes[airline.val()] = new Array();
        var index = 0;
        for (var i = 0; i < data.length; i++) {
            airlineRoutes[airline.val()][index] = [data[i].origin, data[i].destination, data[i].originName, data[i].destinationName];
            index++;
        }
        $.unblockUI();
    }
    SetOriginList();

    if (airline.val() === "GA") {
        if ($("#flightClass").hasClass("hidden")) {
            $("#flightClass").removeClass("hidden");
        }
        if (!$("#flightSearchButton").hasClass("pull-right")) {
            $("#flightSearchButton").addClass("pull-right");
        }
    } else {
        if (!$("#flightClass").hasClass("hidden")) {
            $("#flightClass").addClass("hidden");
        }
        if ($("#flightSearchButton").hasClass("pull-right")) {
            $("#flightSearchButton").removeClass("pull-right");
        }
    }
});

var originAir = $("#origin");
if (typeof window.defaultOriginValue === "undefined" || window.defaultOriginValue === "") {
    window.defaultOriginValue = originAir.val();
}
var destinationAir = $("#destination");
if (typeof window.defaultDestinationValue === "undefined" || window.defaultDestinationValue === "") {
    window.defaultDestinationValue = destinationAir.val();
}


function SetOriginList() {
    if (typeof window.defaultOriginValue === "undefined" || window.defaultOriginValue === "") {
        window.defaultOriginValue = originAir.val();
    }
    originAir.empty();

    if (typeof window.defaultDestinationValue === "undefined" || window.defaultDestinationValue === "") {
        window.defaultDestinationValue = destinationAir.val();
    }
    destinationAir.empty();

    if (airlineRoutes[airline.val()] !== undefined) {
        var newOption = new Option("Pilih Satu", "", true);
        originAir.append(newOption);
        var tempID = "";
        for (var i = 0; i < airlineRoutes[airline.val()].length; i++) {
            var originID = airlineRoutes[airline.val()][i][0];
            if (tempID !== originID) {
                if ($('#origin option[value=' + originID + ']').length === 0) {
                    newOption = new Option(airlineRoutes[airline.val()][i][2], airlineRoutes[airline.val()][i][0]);
                    if (typeof window.defaultOriginValue !== "undefined" && originID === window.defaultOriginValue) {
                        newOption.selected = true;
                    }
                    originAir.append(newOption);
                }
                tempID = originID;
            }
        }
        originAir.change();
        window.defaultOriginValue = "";
        
    } else {
        newOption = new Option("Pilih Satu", "", true);
        originAir.append(newOption);
        originAir.change();
    }
    originAir.change();

    if ($("#originhelp").val() !== "") {
        originAir.val($("#originhelp").val());
        originAir.change();
        $("#originhelp").val("");
    }
    if ($("#destinationhelp").val() !== "" && originAir.val() !== "") {
        destinationAir.val($("#destinationhelp").val());
        $("#destinationhelp").val("");
        destinationAir.change();
        if (airline.val() && originAir.val() && destinationAir.val()) {
            GetAirlineSchedules();
        }
    }
};

function SetDestinationList(originID) {
    destinationAir.empty();
    newOption = new Option("Pilih Satu", "", true);
    destinationAir.append(newOption);
    if (airlineRoutes[airline.val()] !== undefined) {
        for (var i = 0; i < airlineRoutes[airline.val()].length; i++) {
            if (originID === airlineRoutes[airline.val()][i][0]) {
                var destinationID = airlineRoutes[airline.val()][i][1];
                newOption = new Option(airlineRoutes[airline.val()][i][3], airlineRoutes[airline.val()][i][1]);
                if (typeof window.defaultDestinationValue !== "undefined" && destinationID === window.defaultDestinationValue) {
                    newOption.selected = true;
                }
                destinationAir.append(newOption);
            }
        }
        //if (typeof window.defaultDestinationValue !== "undefined" && window.defaultDestinationValue !== "") {
        destinationAir.change();
        window.defaultDestinationValue = "";
        //}
    }
    destinationAir.change();
}

originAir.change(function () {
    SetDestinationList(originAir.val());
});

function GetAirlineSchedules() {
    var airlineID = airline.val();
    var tripType = "OneWay"; // Modified by fachreza 18 Agst 2020

    var departDate = $("#brangkatFormatted").val();
    var returnDate = $("#kembaliReformatted").val();
    if ($("#roundTrip").is(':checked')) {
        tripType = "RoundTrip"; // Modified by fachreza 18 Agst 2020
    }else{
        returnDate = null;
    }

    var paxAdult = $("#ipaxAdult").val();
    var paxChild = $("#ipaxChild").val();
    var paxInfant = $("#ipaxInfant").val();

    var originID = originAir.val();
    var originDetail = $("#origin option:selected").text();
    var destinationID = destinationAir.val();
    var destinationDetail = $("#destination option:selected").text();

    var airlineDetail = airline[0][airline[0].selectedIndex].text;
    var airlineFlightClass = $("#airlineFlightClass").val();


    $.blockUI({ message: '<img alt=\'loading\' src=\'/Content/images/Loading.gif\' /><br/>Sedang mengambil jadwal penerbangan' });
    $.post("/Airlines/getAllSchedules", { airlineDetail: airlineDetail, airlineID: airlineID, tripType: tripType, origin: originID, destination: destinationID, departDate: departDate, returnDate: returnDate, paxAdult: paxAdult, paxChild: paxChild, paxInfant: paxInfant, promoCode: "", airlineAccessCode: "", originDetail: originDetail, destinationDetail: destinationDetail, airlineFlightClass: airlineFlightClass },
        function (result) {
            $("#ScheduleView").html(result);
            $.unblockUI();
        });
}

function GetAirlineSchedulesWithVerifycation() {
    var airlineID = $("#airlineIDVer").val();
    var tripType = "RoundTrip";

    var departDate = $("#departDateVer").val();
    var returnDate = $("#returnDateVer").val();

    if ($("#tripTypeVer").val() === 'OneWay' || $("#tripTypeVer").val() === '1') {
        tripType = "OneWay";
        returnDate = null;
    }

    var paxAdult = $("#paxAdultVer").val();
    var paxChild = $("#paxChildVer").val();
    var paxInfant = $("#paxInfantVer").val();

    var originID = $("#originIDVer").val();
    var destinationID = $("#destinationIDVer").val();

    var originDetail = $("#originDetail").val();
    var destinationDetail = $("#destinationDetail").val();

    var airlineAccessCode = $("#verifycationInput").val();
    var airlineDetail = $('#airlineName').val();


    $.blockUI({ message: '<img alt=\'loading\' src=\'/Content/images/Loading.gif\' /><br/>Sedang mengambil jadwal penerbangan' });
    $.post("/Airlines/getAllSchedules", { airlineDetail: airlineDetail, airlineID: airlineID, tripType: tripType, destinationDetail: destinationDetail, originDetail: originDetail, origin: originID, destination: destinationID, departDate: departDate, returnDate: returnDate, paxAdult: paxAdult, paxChild: paxChild, paxInfant: paxInfant, promoCode: "", airlineAccessCode: airlineAccessCode },
        function (result) {
            $("#ScheduleView").html(result);
            $.unblockUI();
        });
}


function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    var expires = "expires=" + d.toUTCString();
    document.cookie = cname + "=" + cvalue + "; " + expires;
}

function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) === ' ') c = c.substring(1);
        if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
    }
    return "";
}

function checkCookie() {
    var user = getCookie("username");
    if (user !== "") {
        alert("Welcome again " + user);
    } else {
        user = prompt("Please enter your name:", "");
        if (user !== "" && user !== null) {
            setCookie("username", user, 365);
        }
    }
}

var ipaxAdult = $("#ipaxAdult");
var ipaxChild = $("#ipaxChild");
var ipaxInfant = $("#ipaxInfant");
ipaxAdult.change(function () {
    var temp = ipaxChild.val();
    ipaxChild.empty();
    for (var i = 0; i < 10 - parseInt(ipaxAdult.val()); i++) {
        var newOption = new Option(i, i);
        if (temp === i) {
            newOption.selected = true;
        }
        ipaxChild.append(newOption);
    }
    ipaxChild.change();

    temp = ipaxInfant.val();
    ipaxInfant.empty();
    for ( i = 0; i < parseInt(ipaxAdult.val()) + 1; i++) {
         newOption = new Option(i, i);
        if (temp === i) {
            newOption.selected = true;
        }
        ipaxInfant.append(newOption);
    }
    ipaxInfant.change();
});

$('#passenger').click(function () {
    if ($('#layer').is(":hidden") === true) {
        $('#layer').attr("hidden", false);
    } else {
        $('#layer').attr("hidden", true);
    }
});

$('#doneSelect').click(function () {
    $('#layer').attr("hidden", true);
});

$(document).on('click', '.number-spinner button', function () {
    var btn = $(this),
        oldValue = btn.closest('.number-spinner').find('input').val().trim(),
        newVal = 0;

    var category = btn.closest('.number-spinner').find('input').attr('id');
    var defaultValue = (category === "ipaxAdult") ? 1 : 0;

    var allow = true;

    var adult = parseInt($('#ipaxAdult').val());
    var child = parseInt($('#ipaxChild').val());
    var baby = parseInt($('#ipaxInfant').val());
    //var max = adult + child;

    if (btn.attr('data-dir') === 'up') {
        if (adult >= 9 && category === "ipaxAdult") {
            //alert("Maksimum 17 penumpang (dewasa dan anak)");
            allow = false;
        }
        if (category === "ipaxChild" && child >= 8) {
            allow = false;
        }
        if (category === "ipaxInfant" && baby >= 1) {
            allow = false;
        }

        newVal = (allow) ? parseInt(oldValue) + 1 : oldValue;
    } else {
        newVal = (oldValue > defaultValue) ? parseInt(oldValue) - 1 : defaultValue;
    }

    if (category === "ipaxAdult") {
        adult = newVal;
    } else if (category === "ipaxChild") {
        child = newVal;
    } else {
        baby = newVal;
    }

    $('#passenger').val(adult + " Dewasa, " + child + " Anak, " + baby + " Bayi");

    btn.closest('.number-spinner').find('input').val(newVal);
});


