<%@ language = "JavaScript" %>
<% /*
    $Revision$
    $Id$

    File:               res_search_plan_obj_v2.asp
    Descripion:         Toon objecten planbord
    Parameters:
    Context:            vanuit res_search.asp
    Note:               Via het potloodje kan edit-mode worden geactiveerd.
*/
%>

<!--#include file="../Shared/common.inc"-->
<!--#include file="../shared/iface.inc"-->
<!--#include file="../Shared/discxalg3d.inc"-->
<!--#include file="res_plan_obj_v2.inc"-->
<!--#include file="res.inc"-->
<!--#include file="../ins/ins.inc"-->

<%
FCLTHeader.Requires({plugins: ["jQuery"],
                          js: ["date.js", "jquery-ui.js", "../res/res_plan.js"],
                         css: ["../res/res.css"]});

var initcollapsed = true;
var collapseThreshold = 0; // klap automatisch open als er maximaal zoveel regels zijn.

var urole = getQParamSafe("urole");
var rsv_ruimte_key = getQParamInt("rsv_ruimte_key", -1);
var dis_key = getQParamInt("dis_key", -1); // (Alleen) default openklappen
var srtact = getFParamInt("srtact", -1);
var mld_opdr_key = getFParamInt("mld_opdr_key", -1); // opdracht/resource mode

var resourcetypes = getFParamIntArray("resourcetypes", [1]); /* 4 = Personenresource is exclusief gemaakt met personenmode */

var ins_disc_min_level_arr = [];
if (inArray(1, resourcetypes)) /* 1 = Reserveerbaar object */
    ins_disc_min_level_arr.push(1);
if (inArray(4, resourcetypes)) /* 4 = Personenresource */
    ins_disc_min_level_arr.push(4);
if (inArray(5, resourcetypes)) /* 5 = Werkplekken */
    ins_disc_min_level_arr.push(5);

var dateoffset=0; // TODO deeplinking??
var date_from = getFParamDate("date_from", new Date((new Date).getTime() + dateoffset));
var date_to = getFParamDate("date_to", new Date(date_from.getTime()));
var samedate = (date_from.midnight().getTime() == date_to.midnight().getTime());

var show_park = getFParamInt("park", 0)==1;

var fnStep;
if (getFParam("fnStep", "")) {
    fnStep = "parent.fnStepPlanbord";
}

var fronto = (urole == "fo");
var backo = (urole == "bo");
var frontend = (urole == "fe");

var newres = getQParamInt("reservNew", 0) == 1;

if (urole == "fo") {
    var autfunction = "WEB_RESFOF";
} else if (urole == "bo") {
    var autfunction = "WEB_RESBOF";
} else {
    var autfunction = "WEB_RESUSE";
}

var authparams = user.checkAutorisation(autfunction);

var disc_key = getQParamInt("disc", -1);

var objcatmulti  = getFParamIntArray("objcatmulti", []);
var act_key_arr = getFParamIntArray("act", []);

// discard activity filter in case of filter on objcatmulti
if ((srtact > 0 || act_key_arr.length) && objcatmulti.length == 0)
{ // Voeg de disciplines van de (soort)activiteit(en) aan de objectcatalogus toe.
    var wheres = [];
    if (srtact > 0) {
        wheres.push("ra.res_srtactiviteit_key = " + srtact);
    }
    if (act_key_arr.length) {
        wheres.push("rad.res_activiteit_key IN (" + act_key_arr.join(",") + ")");
    }
    var sql = "SELECT rad.res_discipline_key"
            + "  FROM res_activiteit ra"
            + "     , res_activiteitdiscipline rad"
            + " WHERE " + wheres.join(" AND ")
            + "   AND rad.res_activiteit_key = ra.res_activiteit_key";
    var oRs = Oracle.Execute(sql);
    while (!oRs.EOF) {
        objcatmulti.push(oRs("res_discipline_key").value);
        oRs.MoveNext();
    }
    oRs.Close();
}

%>
<html>
<head>
<%  FCLTHeader.Generate()

// Bereken dynamisch breedte blokjes

var width_px = getQParamInt("width_px", 1024);
var nr_days = Math.round(1+(date_to.midnight() - date_from.midnight())/24/60/60/1000);
var hour_px = res.hour_px(width_px - 250, nr_days);
%>

<script type="text/javascript">
        var tijdbalken = [];
<%
        tijdbalken_kop = new Tijdbalken(date_from, nr_days, S("res_t1"), S("res_t2"), fnStep);
        tijdbalken_kop.render();
        var index_tb_render;
        for (index_tb_render = 0; index_tb_render < tijdbalken_kop.tijdbalk_arr().length; index_tb_render++)
        {
%>
            tijdbalken.push(<%=tijdbalken_kop.tijdbalk_arr()[index_tb_render].render_object()%>);
<%
        }
%>
    var tb;
    var hour_px;
    var blokje;
    $(function() {
        var tb = tijdbalken[0];
        var hour_px = tb._unit_px() * tb._units_hour;
        var blokje = hour_px * <%=safe.jsfloat(S("res_h"))%>;
    });
    var startx; // start positie van het slepen (left);
    var starty; // start positie van het slepen (top);

    var rsv_ruimte_key = -1;
    var urole = "<%=urole%>";

    // Worden in res_plan.js gebruikt:
    var res_van = new Date(<%=date_from.getTime()%>);
    var res_tot = new Date(<%=date_to.getTime()%>);

    window.lastFilter = "";

function doFilter(event)
{
    var valThis = $autofilter.val().toLowerCase();
    if (valThis != window.lastFilter) {
        showLoader();
        delayed(500, _doFilter);
    }
    function _doFilter() {
        function textFromCollection(collection)
        {
            var _text = "";
            collection.each(function () { _text += $(this).text().trim(); });
            return _text.toLowerCase();
        }
        var $more = $("div.resplanbordlimited > a");
        var $gridrows;
        if ($more.length > 0 && $more.first().is(":visible"))
        {
            $gridrows = $("div.grid > div.body div.labelgrid").not(".res_nofit");
        }
        else
        {
            $gridrows = $("div.grid > div.body div.labelgrid");
        }
        var valThis = $autofilter.val().toLowerCase();
        $gridrows.each(function() {
            var $this = $(this);
            var found = (valThis.trim().length == 0 || textFromCollection($("div[data-disc=" + $this.attr("data-disc") + "][data-row=" + $this.attr("data-row") + "]").not(".rc")).indexOf(valThis) > -1);
            $("div[data-row=" + $this.attr("data-row") + "][data-disc=" + $this.attr("data-disc") + "]").toggle(found);
        });
        FcltMgr.resized();
        hideLoader();
        window.lastFilter = valThis;
    }
}

    function res_print()
    {
       window.print();
    }

    function res_change()
    {
        var tb = tijdbalken[0];
        var hour_px = tb._unit_px() * tb._units_hour;
        var blokje = hour_px * <%=safe.jsfloat(S("res_h"))%>;
        var startx; // start positie van het slepen (left);
        var starty; // start positie van het slepen (top);
        $('div.rc').droppable({
                        tolerance: 'pointer',
                        drop: function(event, ui) {
                                 // First column of the dropped on row
                                 var jtr = $(this).nextAll("div.labelgrid").first();
                                 // First column of the dragged from row
                                 var dragfrom = $(ui.draggable);
                                 var dragfromrow = dragfrom.prevAll("div.labelgrid").first();
                                 // Langs welke as wordt er nu verschoven?
                                 // X-as: ruimte blijft hetzelfde (res_ruimte_key blijft hetzelfde)
                                 // Y-as: Tijd blijft hetzelfde (fres_van blijft hetzelfde)
                                 var axis = ui.draggable.draggable("option", "axis");

                                 // LET OP: Het verschoven blok is met of zonder schoonmaaktijd. En schoonmaaktijd wordt in het planbord niet goed bepaald en is altijd 1 blokje
                                 var old_dx = startx - jtr.offset().left;
                                 var new_dx = ui.offset.left - $("div.plantimegrid.first").first().offset().left;
                                 old_dx = old_dx / hour_px + <%=safe.jsfloat(S("res_t1"))%>;
                                 new_dx = new_dx / hour_px + <%=safe.jsfloat(S("res_t1"))%> + Number(dragfrom.attr("prc") || 0);
                                 var rsv_ruimte_key = dragfrom.attr("rsv_key"); // nieuwe rsv_ruimte_key
                                 var new_res_deel_key = jtr.attr("id"); // nieuwe res_deel_key
                                 var old_res_deel_key = dragfromrow.attr("id"); // oorspronkelijke res_deel_key

                                 // Als er niets gewijzigd is dan modal popup scherm niet tonen
                                 var noChange = (axis == "x" && old_dx == new_dx) || (axis == "y" && new_res_deel_key == old_res_deel_key)
                                 if (new_res_deel_key &&
                                     !noChange)
                                 {
                                       var url = "./res_update_obj.asp?rsv_deel_key="+ui.draggable[0].getAttribute("rsv_deel_key")
                                               + "&res_deel_key="+(axis == "x"? old_res_deel_key : new_res_deel_key)
                                               + "&preclean=" + ($(ui.draggable).attr("prc") || 0)
                                               + "&fres_van=" + new_dx;
                                       FcltMgr.openModalDetail(url, "",
                                                                    { callback: function (data)
                                                                        {
                                                                            if (data.refresh)
                                                                            {
                                                                                <% if (fnStep)
                                                                                    Response.Write(fnStep + "(0,0)"); // hersubmit vanuit parent
                                                                                %>
                                                                            }
                                                                         }
                                                                     }
                                                        );
                                    }

                        }
                });

        // TODO: hetzij voorkomen hetzij ondersteunen dat naar andere dag gesleept wordt
        $('div.planbord').each(function ()
            {
                     var x, y;
                     var that = this;
                     var element = $(this).find('div.gepland').not('.overflowleft,.overflowright,.res_extern,.res_blok');
                     element.draggable(
                             { cursor: 'crosshair' ,
                               containment: $(that), //.find(".plantd.reserv"),
                               addClasses: false,
                               opacity: 0.75,
                               revert: true,
                               start: function(event, ui)
                                      {
                                        $(ui.helper).css({ width: $(this).css("width"), height: $(this).css("height") });
                                        window.beingdragged = true; /* to prevent onclick */
                                        x = event.originalEvent.pageX;
                                        y = event.originalEvent.pageY;
                                        startx = ui.offset.left; // start positie van het slepen (left);
                                        starty = ui.offset.top; // start positie van het slepen (top);
                                      },
                               drag: function(event, ui)
                                     {
                                       if (x && y && (Math.abs(event.originalEvent.pageX - x) > 5 || Math.abs(event.originalEvent.pageY - y) > 5))
                                       {
                                         axis = Math.abs(event.originalEvent.pageX - x) > Math.abs(event.originalEvent.pageY - y) ? 'x' : 'y';
                                         element.draggable('option', 'axis', axis);
                                         x = y = null;
                                       }
                                     },
                               stop: function()
                                     {
                                       x = y = null;
                                       element.draggable('option', 'axis', false);
                                     },
                               helper: 'clone',
                               iframeFix: true,
                               scroll: false
                             });
            });
        $("#btnchange").html(L("lcl_res_edit_inplanbord"))
                       .addClass("noHover")
                       .removeClass("btn_disabled"); // Remove disabled CSS
        return true;                                 // But keep button onClick disabled
    };

</script>

</head>
<body>
<%
    var buttons = [];
    if (authparams.PRSwritelevel < 9 && authparams.ALGwritelevel < 9 && samedate)
    {
        buttons.push({ icon: "fa-fclt-edit", title: L("lcl_change"), action: 'res_change()', singlepress: true, id: "btnchange" });
    }
    buttons.push({ icon: "fa-list-ul",  title: L("lcl_res_legenda"), action: 'openLegenda()' });
    buttons.push({ icon: "fa-print",  title: L("lcl_print_table"), action: 'res_print()' });
    if (fnStep)
        buttons.push({ icon: "fa-fclt-refresh", title: L("lcl_refresh"), action: fnStep + "(0, 0)" });

IFRAMER_HEADER(L("lcl_res_frame_voorziening"), buttons);
  var res_hint = L("lcl_res_planbord_hint1");
  if (res_hint)
    %><span class="fld"><%=res_hint%></span><%
%>
<div id="list">
<%
    var params = { hour_px: hour_px,
                   reg_key: getFParamInt("regiokey", -1),
                   dist_key: getFParamInt("districtkey", -1),
                   loc_key: getFParamInt("locatiekey", null),
                   loc_key_arr: getFParamIntArray("locatiekey", []),
                   geb_key: getFParamInt("gebouwkey", null),
                   geb_key_arr: getFParamIntArray("gebouwkey", []),
                   ver_key: getFParamInt("verdiepingkey", null),
                   ver_key_arr: getFParamIntArray("verdiepingkey", []),
                   rui_key: getFParamInt("ruimtekey", null),
                   act_key_arr: getFParamIntArray("act", []),
                   objcat_keys:  objcatmulti,
                   mld_opdr_key   : mld_opdr_key,
                   personenmode: mld_opdr_key > 0 || inArray(4, resourcetypes),
                   fnStep : fnStep,
                   srtact : srtact,
                   planbord: true,
                   autfunction: autfunction,
                   res_van: date_from
                 }


//    ==========================================================================
//    Description:        Bouwen van het voorzieningen edit blok voor een reservering

  // Tel in elke catalogus hoeveel objecten in de gekozen ruimte echt gereservererd kunnen worden.
  // Als dat er nul zijn dan tonen we de discipline namelijk niet.
  var deel_params = {  select_fields  : " DISTINCT 1 ",
                       reg_key        : params.reg_key,
                       dist_key       : params.dist_key,
                       loc_key        : params.loc_key,
                       loc_key_arr    : params.loc_key_arr,
                       geb_key        : params.geb_key,
                       geb_key_arr    : params.geb_key_arr,
                       ver_key        : params.ver_key,
                       ver_key_arr    : params.ver_key_arr,
                       personenmode   : params.personenmode,
                       act_key_arr    : params.act_key_arr,
                       sdisc          : "dis.ins_discipline_key",
                       autfunction    : autfunction,
                       res_tot        : params.res_tot
                    };
  var sql_aantal = " ( " + get_res_deel_sql(deel_params) + ") aantal ";

  sql= "SELECT dis.ins_discipline_key,"
     + " ins_discipline_volgnr,"
     + "       "+ lcl.xsqla('dis.ins_discipline_omschrijving','dis.ins_discipline_key') +","
     +         sql_aantal
     + "  FROM RES_v_aanwezigDISCIPLINE dis"
     + "  WHERE ins_discipline_min_level IN (" + ins_disc_min_level_arr.join(",") + ")"
     + "   AND dis.ins_discipline_key IN("
     + "        SELECT g.ins_discipline_key FROM fac_v_webgebruiker g, fac_functie f "
     + "         WHERE g.fac_functie_key = f.fac_functie_key "
     + "           AND f.fac_functie_code = " + safe.quoted_sql(autfunction)
     + "           AND g.fac_gebruiker_alg_level_read < 9"
     + "           AND g.prs_perslid_key ="+user_key
     + "        )"

   if (inArray(4, resourcetypes)) // personen
   {
     sql +="   AND dis.ins_discipline_key IN"
         + "        (SELECT res_discipline_key" /* DISTINCT */
         + "           from res_deel R, prs_perslid p"
         + "          where r.res_deel_verwijder IS NULL"
         + "            and R.res_prs_perslid_key = p.prs_perslid_key)";
    }
    else
    {
     sql +="   AND dis.ins_discipline_key IN"
         + "        (SELECT res_discipline_key" /* DISTINCT */
         + "           from res_deel R, ins_deel D"
         + "          where r.res_deel_verwijder IS NULL"
         + "            and R.res_ins_deel_key=D.ins_deel_key)";
    }

    if (show_park)
        sql += " AND dis.INS_DISCIPLINE_KEY = " + S("vis_parking_key");
    else if (S("vis_parking_key")>0)
        sql += " AND dis.INS_DISCIPLINE_KEY != " + S("vis_parking_key")

  if (disc_key>0) sql=sql  + " and dis.ins_discipline_key ="+disc_key;

  if (params.objcat_keys.length) sql=sql + " AND dis.ins_discipline_key IN ("+params.objcat_keys.join(",")+" )";

  if (S("res_fe_discs_only_in_res") != -1 && !fronto && !backo)
     sql=sql  + " and dis.ins_discipline_key NOT IN ("+S("res_fe_discs_only_in_res")+") ";
  sql += " GROUP BY ins_discipline_key, ins_discipline_volgnr, "+ lcl.xsql('ins_discipline_omschrijving','dis.ins_discipline_key');

  sql=sql  + " ORDER BY ins_discipline_volgnr, 3";
  oRs1 = Oracle.Execute( sql );
%>
    <script>
<%

  if (!params.forSelectRoom && authparams.PRSwritelevel < 9 && authparams.ALGwritelevel < 9)
  { %>
      function deel_save_callback(json)
      {
        var data = {};
        data["chk_" + json.res_deel_key] = 'on';
        protectRequest.dataToken(data);
        $.post("res_edit_objcat_save.asp?urole=fo&verynew=1&rsv_ruimte_key=" + json.rsv_ruimte_key,
               data,
               FcltCallbackClose,
               "json");
      }

      function roomGridClick(evt, urole, act_key_arr)
      {
          var target_object = find_datetime_from_target(evt.target);
          var $target = $(evt.target);
          var $labelgrid = $target.nextAll("div.labelgrid").first();
          if (target_object)
          {
              if (window.beingdragged)
              {
                  window.beingdragged = false;
                  return;
              }
              var res_deel_key = $labelgrid.attr("id");
              var res_van = new Date(target_object.res_date);
              res_van.setHours(target_object.h, target_object.m, 0, 0);
        <% if (mld_opdr_key > 0)
        {
        %>
            var res_tot = new Date(res_van);
            res_tot.setHours(res_tot.getHours() + 1); // even hardcoded 1 uur.
            var data = {
                        mld_opdr_key: <%=mld_opdr_key%>,
                        res_deel_key: res_deel_key,
                        res_van: res_van.getTime(),
                        res_tot: res_tot.getTime()
                     }
            protectRequest.dataToken(data);
            $.post("res_mld_opdr_save.asp",
                   data,
                   FcltCallbackAndThen(deel_save_callback),
                   "json");
            return;
        <%
        }
        %>
              // Gewoon intern
              var cmd = "appl/res/res_reservering.asp"
                      + "?restype=CV"
                      + "&res_deel_key=" + res_deel_key
                      + "&res_van=" + res_van.getTime()
                      + (act_key_arr.length == 1 ? "&activiteit_key=" + act_key_arr[0] : "")
                      + "&urole=" + urole;
              FcltMgr.openDetail(cmd);
          }
      }
<%  } %>
        function beforeprint() {
            // a4 is 842px at 72dpi
            set_borders_margins(tijdbalken[0], 842 / $(document).width());
        }
        function afterprint() {
            set_borders_margins(tijdbalken[0]);
        }
        var $rc_first;
        var $clonedH2;
        var $originalGridHeader;
        var $clonedGridHeader;
        var $autofilter;
        $(function()
        {
            $rc_first = $("div.rc").first();
            $('body').append('<div id="timetip" style="display: none;"></div>');
            $('body').append("<div style='display:none;' class='gridsearch busyloading'>" + I("fa-fclt-spinner fa-4x") + "</div>");
            $("div.planbordgrid").on("mouseenter mousemove mouseout" + (typeof roomGridClick == "function" ? " click" : ""), tooltipDateTime);
            var $discDivs = $("div.insdiscgrid").on("click", toggleDisc);
            if ($discDivs.length > 2 && <%=(initcollapsed ? "true" : "false")%>)
            {
                $discDivs.each(
                    function ()
                    {
                        var $this = $(this);
                        if ($("span.badge", $this).text() <= <%=collapseThreshold%>)
                        {
                            $this.click();
                        }
                    }
                );
            }
            else
            {
                $discDivs.first().trigger("click");
            }
            set_borders_margins(tijdbalken[0]);
            setTimeout(function() { $(window).on("resize", resize_reservations); }, 500);
            var $clonedH2 = $("div.fcltframeheader").clone(true);
            $clonedH2.addClass("floating");
            $originalGridHeader = $("div.grid div.header").first();
            $clonedGridHeader = $originalGridHeader.clone(true);
            $clonedGridHeader.addClass("floating");
            $("body").prepend($clonedH2);
            $("div.grid").first().prepend($clonedGridHeader).css("grid-template-rows", "50px 1fr");
            setTimeout(function() {$clonedGridHeader.width($originalGridHeader.width());}); // give room-selector time to resize
            // resize after the extra header is set
            FcltMgr.resized();
            $(window).on("beforeprint", beforeprint);
            $(window).on("afterprint", afterprint);
            var root = document.documentElement;
            root.style.setProperty('--gridtop', ($("div.grid").first().length > 0 ? $("div.grid").first().position().top + "px" : 0));
            $(window.parent).on("scroll", function() {
                var formHeight = $(window.frameElement).offset().top; // FcltMgr.getElement("form[name=u2]").height();
                root.style.setProperty('--toppos',
                    Math.max($(window.parent).scrollTop() - formHeight, 0) + "px");
            });
            // autofilter
            var $autofilterAfter = $("h2.fcltframeheader").find("#iframerextratitle");
            if ($autofilterAfter.length == 0)
            {
                $autofilter = $("<input id='autofilter' type='text' placeholder='"+L("lcl_autofilter")+"' style='align-self:center;grid-area: 1/1/3/1;'>");
                $("div.grid div.header.floating div.planbordgrid").prepend($autofilter);
            }
            else
            {
                $autofilter = $("<input id='autofilter' type='text' placeholder='"+L("lcl_autofilter")+"'>");
                $autofilterAfter.after($autofilter);
            }
            $autofilter.click(function (e) { e.stopPropagation() })
                            .keyup(function (e) {
                                if (e.which == 27) {
                                    $autofilter.val("");
                                }
                                doFilter();
                            });
        });
        function resize_reservations()
        {
            set_borders_margins(tijdbalken[0]);
            // reset resizable en draggable when div.rc.first hasClass.droppable
            if ($rc_first.hasClass("ui-droppable"))
            {
                res_change();
            }
            $clonedGridHeader.width($originalGridHeader.width());
        }
        var lasteventtype;
        function tooltipDateTime(evt)
        {
            if ($(evt.target).hasClass("rc"))
            {
                if (evt.type == "mouseenter" || lasteventtype == "mouseout")
                {
                    tooltipDateTimeMouseenter(evt);
                }
                else if (evt.type == "mousemove")
                {
                    tooltipDateTimeMousemove(evt);
                }
                else if (evt.type == "mouseout")
                {
                    tooltipDateTimeMouseout(evt);
                }
                if (evt.type == "click" && $(this).closest(".grid").data("writable"))
                {
                    roomGridClick(evt, '<%=urole%>', [<%=deel_params.act_key_arr.join(",")%>]);
                }
            }
            lasteventtype = evt.type;
        }
        // find date and time on target's grid-column
        function find_datetime_from_target(target)
        {
            var target_column = target.style.gridArea.split("/")[1].trim();
            var index;
            var result = {};
            var start_time;
            var h;
            var m;
            var tb;
            for (index = 0; index < tijdbalken.length; index++)
            {
                tb = tijdbalken[index];
                if (tb._start_column <= target_column && tb._end_column >= target_column)
                {
                    start_time = tb._p_res_t1 + ((target_column - tb._start_column ) * tb._unit_length);
                    result.h = Math.floor(start_time);
                    result.m = Math.floor((start_time - result.h)*60);
                    result.res_date = tb._res_date;
                    break
                }
            }
            return result;
        }
        // render date and time on target's grid-column
        function render_datetime_from_target(target)
        {
            var target_object = find_datetime_from_target(target);
            var text = "";
            if (target_object)
            {
              var h = target_object.h;
              if (h < 10) h = "0" + h;
              var m = target_object.m;
              if (m < 10) m = "0" + m;
              text = toDateString(new Date(target_object.res_date)) + ' ' + h + ':' + m;
            }
            return text;
        }
        function tooltipDateTimeMouseenter(evt)
        {
                $("#timetip").html(render_datetime_from_target(evt.target))
                            .css({ left: parseInt(evt.pageX, 10) + 10 + "px",
                                    top: parseInt(evt.pageY, 10) - 25 + "px"
                                  })
                            .show();
        }
        function tooltipDateTimeMousemove(evt)
        {
            $("#timetip").css({ left: parseInt(evt.pageX, 10) + 10 + "px",
                                top: parseInt(evt.pageY, 10) - 25 + "px"
                              });
        }
        function tooltipDateTimeMouseout(evt)
        {
            $("#timetip").hide();
        }
    </script>
<%
    var any = false;
    params.suppressHeader = false;
    while( !oRs1.eof ) {
        if (oRs1("aantal").Value > 0) {
            any = true;
            %>
                         <%params.ins_discipline_omschrijving = oRs1("INS_DISCIPLINE_OMSCHRIJVING").value%>
                      <div class="objcatdiv">
        <%
          make_plan_obj(oRs1("INS_DISCIPLINE_KEY").value, date_from, date_to, params);
          // write only first header
          params.suppressHeader = true;
        %>
                      </div>
    <%
        }
        oRs1.MoveNext();
    }
    oRs1.close();
    if (!any)
        Response.Write("<table><tr><td>" + L("lcl_empty_rstable") + "</td></tr></table>");
%>
<script type="text/javascript">
    function openLegenda()
    {
        var myPosition = "right top+30";
        if (elems.$originalHeaderRow && elems.$originalHeaderRow.length)
            myPosition = "right-15 top+"+(parseInt(elems.$fcltFrameHeader.css("top"))+30);
        params = { width: "auto",
                   resizable: false,
                   position: { my: "right top", at: myPosition },
                   title: L("lcl_res_legenda"),
                   create: FcltMgr.fnCreateCloseButton("div#legenda")
                 }
        $('div#legenda').dialog(params).dialog('open');
  	    FcltMgr.resized();
    }
</script>
    <div id="legenda" style="display:none; line-height: 30px;">
      <table id="planbordlegenda">
       <tr><td class="res_definitief"><%= L("lcl_def") %></td></tr>
       <tr><td class="res_optie"><%= L("lcl_optie") %></td></tr>
       <tr><td class="res_definitief_eigen"><%= L("lcl_def_own") %></td></tr>
       <tr><td class="res_optie_eigen"><%= L("lcl_optie_own") %></td></tr>
       <tr><td class="res_blok"><%= L("lcl_blokkade") %></td></tr>
       <tr><td class="res_nietvrij"><%= L("lcl_niet_beschikbaar") %></td></tr>
       <tr><td class="res_vervallen"><%= L("lcl_vervallen") %></td></tr>
       <tr><td class="res_afgemeld"><%= L("lcl_afgemeld") %></td></tr>
       <tr><td class="res_fatalicon res_fatal"><%=I("fa-times")%>&nbsp;<% = L("lcl_dirty") %></td></tr>
<%
   if (S("res_reservering_flags") > 1)
   {
        for (var flagkey=1; flagkey < S('res_reservering_flags'); flagkey++)
        {
            %><tr class="flg"><td><span class='resflag<%=flagkey%>'><%=(flagkey == 0 ? I("fa-fclt-flag0", {fastyle: "far"}) : I("fa-fclt-flag", {fastyle: "fas"}))%></span>&nbsp;<%=L("lcl_res_flag"+flagkey)%></td></tr><%
        }
   }
%>
      </table>
    </div>
</div>
</body>
</html>
<% ASPPAGE_END(); %>
