/*
     $Revision$
     $Id$
*/

var changed_bits = 0;
var changed_mode = 0;
var parking_key = typeof s_vis_parking_key !== "undefined" ? s_vis_parking_key : null;  // Waarde toegekend in model_res_deel.inc
var multi_reservering = typeof insMultiReserve !== "undefined" ? insMultiReserve : null;

$(function ()
{   // initialisatie
    if (multi_reservering)
    {   // Zo wordt gelijk de selectbox verplicht gezet.
        $(function ()
        {   // Deze ready wrapper zorgt dat dit wordt uitgevoerd na de ready die de multi_cb toevoegd
            $("#scf_multi_bookingdiscipline").click().prop("disabled", true);
            $("#scf_multi_scope").click().prop("disabled", true);
            $("#scope").val(-1).change();
        });
    }

    $("#bookingdiscipline").change(function() {change_res_discipline_key(); });
    $("#_available").click(function() {SelectBits(); });


    var disc_key = $("#bookingdiscipline").val();
    if (!disc_key || disc_key != parking_key )
    {
        $("#_available").parent().parent().hide();
    }
});

function change_res_discipline_key()
{
    var disc_key = $("#bookingdiscipline").val();
    if (disc_key == parking_key)
    {
        $("#_available").parent().parent().show();
    }
    else
    {
        $("#_available").parent().parent().hide();
    }
    changed_mode = 1;
}

function SelectBits()
{
    var proturl = "../ins/ins_bitsform.asp"
                + "?eenheid=5"
                + "&bits=" + $("#availabilitybits").val();
    parent.FcltMgr.openModalDetail(proturl, "Select moment",
                { callback: function (data)
                        { if (data.eenheid >= 0)
                          {
                             $("#availabilitybits").val(data.bits);
                             changed_bits = 1;
                          }
                        }
                } );
}

function pre_submit()
{
    var ch_mode = (changed_mode == 1);
    var ch_bits = (changed_bits == 1);
    var disc_key = $("#bookingdiscipline").val();
    if (!multi_reservering &&disc_key && disc_key == parking_key)
    {
        if (ch_mode && !ch_bits)
        {
          FcltMgr.alert(L("res_deel_select"));
          return false;
        }
    }
    else // is geen parkeerplaats
    {
        $("#availabilitybits").val(0);
    }

    if (multi_reservering)
    {   // Enable checkboxen. Anders worden waarden niet opgeslagen.
        $("#scf_multi_bookingdiscipline").prop("disabled", false);
        $("#scf_multi_scope").prop("disabled", false);
    }

    return true;
}

function qrcode(key, title) {
    var url = "../fac/fac_print_qrcode.asp?title=" + encodeURIComponent(title)
                                        + "&text=" + encodeURIComponent("/?u=res_object&k=" + key);
    FcltMgr.openModalDetail(url, { titel: L("lcl_make_qrc_title2") });
}