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

    File:               CAD/default.asp
    Description:        Hoofdscherm voor Facilitor Graphics II
    Parameters:
        mode            optional: default 0=binnen[MODE_IN], 1=buiten[MODE_OUT].
        loc_key         optional locatie key (default eigen werkplek)
        scenario_key    optional: dan zitten we in PRJ-mode (en impliciet binnen)
        floor_key       optional (als in scenario_mode)
        concept         optional, naast de actuele tekening wordt de concept-tekening getoond om de verschillen te checken
                        de overige functionaliteit is daar beperkter (en mag wellicht nog beperkter, maar boeie)
    Context:            Geen, wordt geopend in een nieuw window
    Note:
*/
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/plaatsselector.inc" -->
<!-- #include file="./tabs.inc" -->
<!-- #include file="FGII.inc" -->

<%
FCLTHeader.Requires({ js: ["jquery-ui.js", "./main.js", "./draganddrop.js", "date.js"],
                      css: ["../slnkdwf/slnkdwf.css"]
                    });

var inoutMode = getQParamInt("mode", MODE_IN);
var loc_key = getQParamInt("loc_key", user.alg_locatie_key());
var scenario_key = getQParamInt("scenario_key", 0);   // current scenario, 0 voor geen
var concept = getQParamInt("concept", 0) == 1;   // concept er naast?
var showcontour = getQParamInt("contour", 1) == 1; // Contour initieel tonen?
var objectmove = getQParamInt("objectmove", 0); // Handles bij objecten tonen (om te kunnen verplaatsen)?

var floor_key = getQParamInt("floor_key", user.alg_verdieping_key());  // current floor
if (floor_key > 0)
{
  sql = " SELECT g.alg_locatie_key, g.alg_gebouw_key"
      + "   FROM alg_verdieping v, alg_gebouw g"
      + "  WHERE g.alg_gebouw_key = v.alg_gebouw_key"
      + "    AND v.alg_verdieping_key = " + floor_key;

  oRs = Oracle.Execute(sql);
  if (!oRs.eof)
  {
    loc_key = oRs("alg_locatie_key").value;
    bld_key = oRs("alg_gebouw_key").value;
  }
  oRs.close();
}
else
{
  bld_key = -1;
}

var my_cadrechten = user.func_enabled("CAD"); // negeer scope, we kunnen zo maar van verdieping wisselen
var autfunction=(scenario_key == 0)? "WEB_CADUSE" : "WEB_PRJBOF";
var authparams = user.checkAutorisation(autfunction); // voor kiezen *andere* verdiepingen

cleanup_tempfolder (); // FGII werkt niet zonder schrijfrechten op temp dus
                       // heb je in ieder geval wel de rechten om op te ruimen

if (scenario_key != 0)
{
  var scenario_omschrijving = "";
  sql = " SELECT m.mld_melding_omschrijving"
      + "   FROM prj_scenario s, mld_melding m"
      + "  WHERE s.mld_melding_key = m.mld_melding_key"
      + "   AND prj_scenario_key = " + scenario_key;
  var oRs = Oracle.Execute(sql);
  if (!oRs.eof)
    scenario_omschrijving = oRs(0).value;
  oRs.Close();
}
// Altijd scrollbar voor lange tabbladen onderin.  Voorkom dat
// hij er soms bijkomt en een repaint van het plaatje veroorzaakt.
%>
<html style='overflow-y:scroll'>
  <head>
<%  FCLTHeader.Generate(); %>
    <title><%=(scenario_key == 0)? L("lcl_graphics") : (L("lcl_prj_graphics") + ": " + L("lcl_prj_scenario") + " " + scenario_omschrijving) %> </title>

    <script type="text/javascript">
      var scenario_key = <%=scenario_key%>;
      var floor_key = <%=floor_key%>;
      var objectmove = <%=objectmove%>;

      function onScenarioChange(sel)
      {
        /*global*/scenario_key = sel[sel.selectedIndex].value;
        floor_key = $("#verdiepingkey").val();
        OnFloorChanged(floor_key, true); // Keep zoom
      }

      function OnLocationChanged(sel)
      {
<%      if (inoutMode == MODE_OUT)
        { %>
          ter = -1;
          loc_key = $("#locatiekey").val();
          if (loc_key > 0)
          {
              $("#terr").load("../cad/loadTerreinOptions.asp?loc_key=" + loc_key, myRefresh);
          }
<%      } %>
      }

      var forceRoom = -1; // dadelijk highlighten (main.js/gotoRoom)
      function OnFloorChanged()
      {
        floor_key = -1; // Eventjes invalid
        resetMap();
        floor_key = $("#verdiepingkey").val();
        if (floor_key > 0)
        {
<%        if (scenario_key == 0)
          { %>
            $("#rooms").load("../cad/loadRuimteOptions.asp?floor_key=" + floor_key + "&ruimte_key=" + forceRoom, myRefresh);
<%        }
          else
          { %>
            updatePRJRooms(floor_key, scenario_key); // Load the rooms when not loaded yet
<%        } %>
        }
        // else is aanroeper daar zelf verantwoordelijk voor
        forceRoom = -1;
        RefreshLegenda(); // Deze altijd omdat hij toch onafhankelijk is van de inhoud van het plaatje
      }

<%  if (user.has("WEB_CADMGT")) { %>
      function gothema (tkey)
      {
          var url = "appl/mgt/cad_thema.asp?id="+tkey;
          FcltMgr.openDetail(url);
      }
<%  }%>

      /************************************************************\
      * We know all we need. Now refresh the image on the right
      \************************************************************/
      function myRefresh()
      { // $("#rooms:option").dblclick(function() { MMap.zoom2DWG(???) });

        sDiscsChanged();

<%      if (inoutMode == MODE_IN) { %>
           myRefreshInside();
<%      } else { %>
           myRefreshOutside();
<%      } %>
      }

      function getCustomParameters(noVKey)
      {
        var thmRKey = -1;
        var thmIKey = -1;
        var thmWKey = -1;
        var lblKey = -1;
        var lblRKey = -1;
        var lblIKey = -1;
        var lblWKey = -1;
<%    if (inoutMode == MODE_IN) { %>
        var key = floor_key;
<%    } else { %>
        var key = $("#locatiekey").val();
<%    } %>

        var thmRSelect = document.getElementById("sThemaIn");
        if (thmRSelect)
            thmRKey = thmRSelect[thmRSelect.selectedIndex].value;
        var thmISelect = document.getElementById("sThemaIn2");
        if (thmISelect)
            thmIKey = thmISelect[thmISelect.selectedIndex].value;
        var thmWSelect = document.getElementById("sThemaIn3");
        if (thmWSelect)
            thmWKey = thmWSelect[thmWSelect.selectedIndex].value;

        var lblRSelect = document.getElementById("sLabelIn1");
        if (lblRSelect)
        {
            lblKey = lblRSelect[lblRSelect.selectedIndex].value;  // nog ff compatibel
            lblRKey = lblRSelect[lblRSelect.selectedIndex].value;
        }
        var lblISelect = document.getElementById("sLabelIn2");
        if (lblISelect)
        {
            lblIKey = lblISelect[lblISelect.selectedIndex].value;
        }
        var lblWSelect = document.getElementById("sLabelIn3");
        if (lblWSelect)
        {
            lblWKey = lblWSelect[lblWSelect.selectedIndex].value;
        }

        var keyListArr = [];
        $("#sDiscsIn input[type=checkbox]").each(function ()
                {
                    if (this.checked)
                        keyListArr.push($(this).val());
                });
        var keyList = keyListArr.join(",");

        var c0 = document.getElementById("contour0");
        var c1 = document.getElementById("contour1");
        var c2 = document.getElementById("contour2");
        var contmode = -1; // Welke contour (alt1/alt2) moet ik tonen
        if (c0&&c0.checked) contmode = 0;
        if (c1&&c1.checked) contmode = 1;
        if (c2&&c2.checked) contmode = 2;

<%    if (inoutMode == MODE_IN && S("prs_werkplek_implicit") == 0) { %>
        var wp = document.getElementById("werkplek").checked? 1 : 0;
<%    } else { %>
        var wp = 0;
<%    } %>
        var rmList = selectedRoomsList("<%=(inoutMode==MODE_IN)? "rooms" : "terr"%>");
        var datumfilter = $("#datumfilter select").val();

        return (noVKey?"":("&vkey=" + key))+
               "&gKey=" + $("#gebouwkey").val() +  // (voor printen)
               "&scenario_key="+scenario_key+
               "&thema=" + thmRKey +
               "&themaR=" + thmRKey +
               "&themaI=" + thmIKey +
               //TODO "&themaW=" + thmWKey +
               "&thema_key=" + thmRKey +  // infobord verwacht het thema onder deze naam
               "&label=" + lblKey +
               "&labelR=" + lblRKey +
               "&labelI=" + lblIKey +
               "&labelW=" + lblWKey +
               "&werkplek=" + wp +
               "&mode=<%=inoutMode%>"+
               "&contmode="+contmode+
               "&objectmove="+objectmove+
               (rmList != ""? "&highlight=" + escape(rmList) : "") +
               (keyList != ""? "&discs=" + keyList : "") +
               (datumfilter? "&datumfilter=" + datumfilter: "");
      }

      function myRefreshInside()
      {
        if (floor_key > 0)
        {
          MMap.SetCustomParameters(getCustomParameters())
          MMap.Refresh(false, true); // Try not to zoom extents, wel force
<%        if (concept)
          { %>
            MMap2.SetCustomParameters(getCustomParameters() + "&concept=1")
            MMap2.Refresh(); // Try not to zoom extents
<%        } %>
          showReport(null);
        }
        else
        {
          MMap.SetText(L("lcl_fg_select_floor"));
          showReport();
        }
      }

      function myRefreshOutside()
      {
        var loc_key = $("#locatiekey").val();
        if (loc_key)
        {
          MMap.SetCustomParameters(getCustomParameters())
          MMap.Refresh(false, true); // Try not to zoom extents, wel force
          showReport(null);
        }
        else
        {
          MMap.SetText(L("lcl_select_location"));
          showReport();
        }
      }

      /************************************************************\
      *
      \************************************************************/
      function MMap_onIMGRefresh()
      {
      }

      function MMap_onMapperLoad(pSLNKEvent)
      {
<%      if (concept)
        { %>
          if (pSLNKEvent.success)
              MMap2.zoom2DWG((pSLNKEvent.viewminX+pSLNKEvent.viewmaxX) / 2,
                             (pSLNKEvent.viewminY+pSLNKEvent.viewmaxY) / 2,
                             (pSLNKEvent.sizeX) / (pSLNKEvent.viewmaxX - pSLNKEvent.viewminX)
                             );
<%      } %>
      }

      function MMap_onDblClick()
      {
        // Liefst willen we 'alles aan buffer toevoegen' maar dat is complexer
      }

      /************************************************************\
      * Gets fired after the user drops something on the drawing.
      * Enabled in function EnableDragAndDrop
      \************************************************************/
      function MMap_onDrop(SlnkEvent)
      {
        dragAndDropNotify(SlnkEvent);
      }

      // notifyDrop is de functie die aangeroepen wordt als de drop voltooid is
      // html is wat je daadwerkelijk kunt droppen
      function EnableDragAndDrop(notifyDrop, html)
      {
        dragAndDropNotify = notifyDrop;
        MMap.EnableDragAndDrop(html);
      }

      // Pas een symbool (ins_deel of prs_werkplek)(via Ajax) in de database aan
      function ChangeSymbol(symbolKey, params)
      {
        if (symbolKey.match(/^I:/)) // INS_DEEL
        {
          var url = "./ins_change.asp?deel_key=" + symbolKey.substring(2);
        }
        else if (symbolKey.match(/^P:/)) // PRJ_DEEL
        {
          var url = "./ins_change.asp?deel_key=" + symbolKey.substring(2);
        }
        else if (symbolKey.match(/^IW:/)) // WERKPLEK gebonden INS_DEEL
        {
          var url = "./ins_change.asp?wpdeel=1&deel_key=" + symbolKey.substring(3);
        }
        else if (symbolKey.match(/^W:/)) // PRS_WERKPLEK
        {
          var url = "./wp_change.asp?wp_key=" + symbolKey.substring(2);
        }
        else
          return; // Zeer vreemd

        url += "&floor=" + floor_key;
        url += "&scenario_key=" + scenario_key;
        url += params;
        var data = {};
        <% protectRequest.dataToken("data"); %>
        $.post(url, data, FcltCallbackAndThen(myRefresh), "json");
      }

      function DoMoveSymbol(deelKey, orgX, orgY, dwgX, dwgY, lblContour)
      {
        var params;
        if (orgX)
        {
          params  = "&newX=" + dwgX + "&newY=" + dwgY;
          params += "&orgX=" + orgX + "&orgY=" + orgY;
          params += "&Contour=" + lblContour;
        }
        else
          params = "&clearXY=1"

        ChangeSymbol(deelKey, params)
      }

      function RemoveSymbol(deelKey)
      {
        FcltMgr.confirm(L("lcl_obj_del_confirm"), function() {
          ChangeSymbol(deelKey, "&delete=1");
        });
      }

      var _symbolKey; // wordt gezet in MMap_onPickcontextmenu
      function RotateSymbol(symbolKey, angle)
      {
        if (typeof angle == "undefined")
        {
          angle = prompt(L("lcl_cad_enterangle"), '0');  // default de huidige rotatie is vriendelijker dan 0, maar niet zomaar bekend
          if (angle && !isNaN(parseInt(angle, 10)))
              ChangeSymbol(symbolKey, "&rot=" + parseInt(angle));
        }
        else
          ChangeSymbol(symbolKey, "&deltarot=" + parseFloat(angle));
      }

      function ScaleSymbol(angle)
      {
        var scl = prompt('Geef schaal', '1.0');
        if (scl && !isNaN(parseFloat(scl)))
          ChangeSymbol(_symbolKey, "&scale=" + parseFloat(scl));
      }

      function AlignSymbol(evt)
      {
        var params = "&AutoAlign=1" + getCustomParameters();
        params += "&findX=" + PickEvtX + "&findY=" + PickEvtY;
        params += MMap.qryShow;
        ChangeSymbol(_symbolKey, params);
      }

      // Gebruiker heeft 'eigenschappen' in het contextmenu gekozen.
      function showSymbol(SlnkEvent)
      {
        SlnkEvent = SlnkEvent || {};
        var intKey = -1;
        if (scenario_key > 0)
        {
          // TODO: Hier willen we eigenlijk ins_info.asp van het originele symbool tonen
          FcltMgr.alert("Not supported in scenario mode");
          return intKey;
        }
        if (_symbolKey.match(/^IW:/)) // INS_DEEL aan werkplek
        {
          intKey = _symbolKey.substring(3);
          if (SlnkEvent.click_urlI)
            FcltMgr.openModalDetail(SlnkEvent.click_urlI + intKey, L("lcl_shared_object"), { callback: myRefresh, alwaysCallback: true });
          else
            FcltMgr.openDetail("appl/ins/ins_deel.asp?urole=bo&ins_key=" + intKey);
        }
        if (_symbolKey.match(/^I:/)) // INS_DEEL aan ruimte
        {
          intKey = _symbolKey.substring(2);
          if (SlnkEvent.click_urlI)
            FcltMgr.openModalDetail(SlnkEvent.click_urlI + intKey, L("lcl_shared_object"), { callback: myRefresh, alwaysCallback: true });
          else
            FcltMgr.openDetail("appl/ins/ins_deel.asp?urole=bo&ins_key=" + intKey);
        }
        if (_symbolKey.match(/^W:/)) // PRS of PRJ_WERKPLEK
        {
          intKey = _symbolKey.substring(2);
          if (SlnkEvent.click_urlW)
            FcltMgr.openModalDetail(SlnkEvent.click_urlW + intKey, L("lcl_workspace") + ": " + SlnkEvent.ContourLabel, { callback: myRefresh, alwaysCallback: true });
          else
          {
    <%        if (S("prs_werkplek_implicit") == 0) //Impliciet FLEX ook
              { %>
                FcltMgr.openDetail("appl/alg/alg_wp.asp?key=" + intKey);
    <%        }
              else
              { %>
                if (window._wp_type == 1) // Impliciet flex
                    FcltMgr.openDetail("appl/alg/alg_wp.asp?key=" + intKey);
                else
                {
                    var url = "../prs/prs_edit_perslidwerkplek.asp?wp_key=" + intKey;
                    FcltMgr.openModalDetail(url, L("lcl_change"), {callback: myRefresh });
                }
    <%        } %>
          }
        }
        return intKey;
      }

      /************************************************************\
      * This event gets fired by the SLNKDWF viewer after the user
      * clicked on the drawing.
      * Note that by now myFindInIMG.asp has already translated
      * the room-label or object-label into a ALG_RUIMTE_KEY
      * or INS_DEEL_KEY
      \************************************************************/
      function MMap_onClick(SlnkEvent)
      {   //FcltMgr.alert("Geklikt op dwgXY=" + SlnkEvent.dwgX + "," + SlnkEvent.dwgY +
          //              " \ndat is " + SlnkEvent.ContourKey + " op laag: " + SlnkEvent.ContourLayer +
          //              " \nof (text)object " + SlnkEvent.TextLabel + " op laag: " + SlnkEvent.TextLayer +
          //              " \nmet key=" + SlnkEvent.Key+
          //              " \nen urlR=" + SlnkEvent.click_urlR +
          //              " \nen urlI=" + SlnkEvent.click_urlI +
          //              " \nen urlW=" + SlnkEvent.click_urlW
          //              );
        switch (SlnkEvent.Param)
        {
          case "onclick":
          case "ondblclick":
          {
            if (SlnkEvent.Key &&
                    (SlnkEvent.TextLabel != "" ||
                    SlnkEvent.ContourLayer == "SLNK Symbols"))
            { // Zoek het object of de werkplek (die staan ook op Symbols)
              window._symbolKey = SlnkEvent.Key; // Onthouden
              window._wp_type = SlnkEvent.wp_type; // Onthouden
              var intKey = showSymbol(SlnkEvent); // Hetzelfde als bij 'Eigenschappen' kiezen in de context

              var wp_key = -1;
              if (SlnkEvent.Key.match(/^W:/)) // WERKPLEK
              {
                wp_key = intKey;
                intKey = "";
              }

              // naar de tabjes doorgeven, bijvoorbeeld PRJ werkplek symbool.
              showReport(intKey, wp_key);
            }
            else // Op ruimte geklikt
            {    // buiten tekening klikken wist highlight if (SlnkEvent.ContourKey != "")

              if (SlnkEvent.click_urlR && SlnkEvent.Key)
              {
                FcltMgr.openModalDetail(SlnkEvent.click_urlR + SlnkEvent.Key + "&caddwgX=" + SlnkEvent.dwgX + "&caddwgY=" + SlnkEvent.dwgY,
                           L("lcl_room") + ": " + SlnkEvent.ContourLabel, { callback: myRefresh, alwaysCallback: true })
              }
              else
              {
                  var sl = document.getElementById("<%=inoutMode == MODE_IN? "rooms" : "terr"%>");
                  if (!SlnkEvent.event.ctrlKey) // Allow Ctrl key for Multi-select, Jos opperde nog forceren naar Multiselect mocht dat niet zo zijn
                    sl.selectedIndex = -1;

                  var ob = sl.options;
                  found = false;
                  for (i = 0; i<ob.length; i++)
                  {
                    if (ob[i].value == SlnkEvent.Key)
                    {
                      ob[i].selected = true;
                    }
                  }
                  myRefresh(); // (un)highlight selected room
              }
            }
            break;
          }
          case "ONMOVE":
          {
            if (SlnkEvent.fromKey != -1 && SlnkEvent.fromDwgX) // Nieuwe plek
            {
              //if (SlnkEvent.ContourLayer != 'SLNK Contours')
              //FcltMgr.confirm("Buiten ruimte geplaatst. Doorgaan?", function() {

                DoMoveSymbol(SlnkEvent.fromKey,
                             SlnkEvent.fromDwgX, SlnkEvent.fromDwgY,
                             SlnkEvent.dwgX, SlnkEvent.dwgY, SlnkEvent.ContourKey)
              //});
            }
            break;
          }
          case "ONCOPY": // Dit kan een symbool zijn of een werkplek
          {
            newSymbol(SlnkEvent, true); // isCopy
            break;
          }
          case "ONROTATE":
          {
            if (SlnkEvent.fromKey != -1 && SlnkEvent.fromDwgX && SlnkEvent.dwgX != SlnkEvent.fromDwgX) // Nieuwe rotatie
            {
              var angle = Math.atan((SlnkEvent.dwgY - SlnkEvent.fromDwgY) / (SlnkEvent.dwgX - SlnkEvent.fromDwgX));
              var rot = Math.round(0.5 + (360 + angle / 3.1415926 * 180) % 360);
              if (SlnkEvent.fromDwgX > SlnkEvent.dwgX)
                rot = (rot + 180) % 360;
              ChangeSymbol(SlnkEvent.fromKey, "&deltarot=" + rot)
            }
            break;
          }
        }
      }

      /************************************************************\
      * Wordt aangeroepen als gebruiker rechts klikt op pickboxje
      * van een symbool
      *   myEvent.symbolKey
      *   myEvent.event
      \************************************************************/

      function MMap_onPickcontextmenu(myEvent)
      {
        _symbolKey = myEvent.symbolKey; // Onthouden
        // TODO: Context menu afhankelijk maken van autorisatie en soort geklikt object
        PickEvtX = myEvent.event.clientX;
        PickEvtY = myEvent.event.clientY;
        MMap.showContextMenu(myEvent.event, document.getElementById("PickcontextMenu"));
      }

      /************************************************************\
      * Gets fired after the user presses Print.
      \************************************************************/
      function MMap_onPrint_callback(data)
      {
        if (data.cancel) return false; // cancel
        if (data.style == "SLNKDWF")
        {
          MMap.PrintDialog();
          return; // Done
        }

        // Dan maar advanced
        var url = "../cad/PrintFG.asp";
        url += "?XSLmode=" + data.style;
        url += getCustomParameters();
        var pngURL = MMap.GetPrintURL(true); // true for current zoom

        if (data.allFloor)
        {
          MMap.SetCustomParameters(getCustomParameters(true)); // Even zonder vKey
          var pngURL = MMap.GetPrintURL(true); // true for current zoom
          MMap.SetCustomParameters(getCustomParameters());
          url += "&allFloor=1";
          data.DWGscale = -1; // Altijd FIT
        }
        if (data.DWGscale == 0) // current
        {
            data.DWGscale = MMap.gSLNKEvent.scaleY;
        }
        else if (data.DWGscale == -1) // Maximaal
        {
            pngURL += "&maximize=1"; // omdat anders -1 een aanduiding is van DWGSchaal 1:1
        }
        else if (data.DWGscale > 0) // factor gekozen in select-box
        {
            data.DWGscale = -data.DWGscale; // speel vals: negatief betekent: paperScale (ipv. pixelScale)
        }

        url += "&DWGscale=" + data.DWGscale;
        url += "&pngURL=" + escape(pngURL);

        FcltMgr.windowopen(url);
      }

      function MMap_onPrint(SlnkEvent)
      {
<%      if (inoutMode == MODE_OUT)
        { %>
          return true; // Altijd alleen de default 'Flexibel' optie
<%      }
        else
        { %>
          var sFeatures="dialogHeight:400px;dialogWidth:600px;status=no";
          var url="../cad/printWhat.asp?x=x"+getCustomParameters();
          FcltMgr.openModalDetail(url, L("lcl_print"),
                                  { callback: MMap_onPrint_callback }
                                 );
<%      } %>
      }

      var has_thema_datum_filter = false;
      function sThemeChanged()
      {
        if (!has_label_datum_filter)
        {
            $("#datumfilter").hide();
        }

        var sThema = document.getElementById("sThemaIn");
        var thmRKey = sThema[sThema.selectedIndex].value;
        /*global*/has_thema_datum_filter = sThema[sThema.selectedIndex].getAttribute("has_datum_filter");
        if (has_thema_datum_filter)
        {
            $("#datumfilter select").empty().load("loadDatumFilterOptions.asp?thema=" + thmRKey,
                function () {
                                $("#datumfilter").show();
                                myRefresh();            // Plaatje aanpassen
                                RefreshLegenda(true);   // Legenda aanpassen en in beeld brengen
                            });
        }
        else
        {
            myRefresh();            // Plaatje aanpassen
            RefreshLegenda(true);   // Legenda aanpassen en in beeld brengen
        }
      }

      // Updatable thema's kunnen filter uitbreiden
      var legendaFilter = "V";  // Default op verdieping
      function onLegendaFilterChange(niveau)
      {
        legendaFilter = niveau;
        RefreshLegenda();
      }

      // De legenda is afhankelijk van wat er daadwerkelijk op de verdieping (database)
      // voorkomt, daarom wordt hij heel vaak gerefreshed
      function RefreshLegenda(scrollintoview)
      {
<%      if (inoutMode == MODE_IN)
        { %>
          var pSelect = "verdiepingkey"
<%      }
        else
        { %>
          var pSelect = "locatiekey"
<%      } %>

        var sThema = document.getElementById("sThemaIn");      // Listboxje 1 is er altijd
        var thmRKey = sThema[sThema.selectedIndex].value;
        var legenddiv = document.getElementById("legendCell");
        legenddiv.style.display = "none";
        if (thmRKey > 0)
        {
            var pKey = parseInt($("#"+pSelect).val());
            if (pKey > 0)
            {
                $("#fLegenda1").load(
                          "Legenda.asp?thema=" + thmRKey +
                                      "&showtitle=0" +
                                      "&scenario_key=" + scenario_key +
                                      "&parentKey=" + pKey + "&mode=<%=inoutMode%>" +
                                      "&legendaFilter="+legendaFilter,
                          scrollintoview?function () { scrollview($("#fLegenda1"));}:null
                    )
                legenddiv.style.display = "block";
<%  if (user.has("WEB_CADMGT")) { %>
                document.getElementById("legend1").innerHTML="<span class='details' onclick='gothema("+thmRKey+")'>"+(sThema[sThema.selectedIndex].innerHTML).replace('*','')+"</span>";
<% } else { %>
                document.getElementById("legend1").innerHTML=sThema[sThema.selectedIndex].innerHTML;
<% }  %>
             }
        }
        else
        {
          document.getElementById("fLegenda1").innerHTML="";
          document.getElementById("legend1").innerHTML="";
        }

        sThema2 = document.getElementById("sThemaIn2")      // Listboxje 2 is er als (S("fg_ins_symbols"))
        if (sThema2) // is in feite ook if (S("fg_ins_symbols"))
        {
            var thmIKey = sThema2[sThema2.selectedIndex].value;
            document.getElementById("fLegenda2").innerHTML="";
            if (thmIKey > 0)
            {
                var pKey = parseInt($("#"+pSelect).val());
                if (pKey > 0)
                {
                    $("#fLegenda2").load(
                              "Legenda.asp?thema=" + thmIKey +
                                          "&showtitle=0" +
                                          "&scenario_key=" + scenario_key +
                                          "&parentKey=" + pKey + "&mode=<%=inoutMode%>" +
                                          "&legendaFilter="+legendaFilter,
                              scrollintoview?function () { scrollview($("#fLegenda2"));}:null
                        )
                    legenddiv.style.display = "block";
              <%  if (user.has("WEB_CADMGT")) { %>
                    document.getElementById("legend2").innerHTML="<span class='details' onclick='gothema("+thmIKey+")'>"+sThema2[sThema2.selectedIndex].innerHTML+"</span>";
              <% } else { %>
                    document.getElementById("legend2").innerHTML=sThema2[sThema2.selectedIndex].innerHTML;
              <% }  %>
                }
            }
            else
            {
                document.getElementById("fLegenda2").innerHTML="";
                document.getElementById("legend2").innerHTML="";
            }
         } // sThema2
      }

      var has_label_datum_filter = false;
      function sLabelChanged(newLabel)
      {
        var lblKey = newLabel[newLabel.selectedIndex].value;
        if (!has_thema_datum_filter);
        {
            $("#datumfilter").hide();
        }
        /*global*/has_label_datum_filter = newLabel[newLabel.selectedIndex].getAttribute("has_datum_filter");
        if (has_label_datum_filter)
        {
            $("#datumfilter select").empty().load("loadDatumFilterOptions.asp?label=" + lblKey,
                function () {   $("#datumfilter").show()
                                myRefresh()
                            });
        }
        else
        {
            myRefresh();
        }
      }

      function sDiscsChanged()
      { // Werkt de lijst met symbolen bij
<%      if (S("fg_ins_symbols"))
        { %>
          $("#dinsLegend").load("LoadInsLegenda.asp?x=x" + getCustomParameters(),
                    function(respText) {
                        var empty = $(respText).find("img").length == 0; // Beetje illegaal
                        $("tr#tinsLegend").toggle(!empty);
                        });
<%      } %>
      }

      function toggleContour(cnt)
      {
        if (cnt.checked) // Mogelijk anderen uitzetten
        {
          var c0 = document.getElementById("contour0");
          var c1 = document.getElementById("contour1");
          var c2 = document.getElementById("contour2");
          if (cnt.id == "contour0")
          {
            if (c1) c1.checked=false;
            if (c2) c2.checked=false;
          }
          else if (cnt.id == "contour1")
          {
            if (c0) c0.checked=false;
            if (c2) c2.checked=false;
          }
          else // contour2
          {
            if (c0) c0.checked=false;
            if (c1) c1.checked=false;
          }
        }
        myRefresh();
      }

      function showReport(obj_key, wp_key)
      {
        var tabParam = (obj_key? "obj=" + obj_key : "dummy=")
                     + (wp_key? "&wp_key=" + wp_key : "")
                     + getCustomParameters();

        tabSetParam(tabParam);
        tabRefresh();
      }

      function toInfobord()
      {
	      FcltMgr.stopPropagation(evt);
        var url = "../cad/InfoBord.asp?floor_key=" + floor_key + getCustomParameters();
        FcltMgr.windowopen(url,'FG3DShow',
                        "directories=no,location=no,menubar=no,"
                      + "resizable=yes,status=no,titlebar=yes,toolbar=no");
      }

      function toTekeningen(evt)
      {
	      FcltMgr.stopPropagation(evt);
        var bld_key = $("#gebouwkey").val();
        FcltMgr.openDetail("appl/cad/tekening_search.asp?autosearch=1&gebouw_key="+bld_key, L("lcl_menu_fg_tekeningen"));
      }

      function onFullScreen(evt)
      {
	      FcltMgr.stopPropagation(evt);
        var url = "../cad/maximize.asp?x=x" + getCustomParameters();
        FcltMgr.windowopen(url,'FGShow',
                      "directories=no,location=no,menubar=no,"
                    + "resizable=yes,status=no,titlebar=yes,toolbar=no");

      }

      function gotoEditmode(evt)
      {
  	    FcltMgr.stopPropagation(evt);
  	    objectmove = 1 - objectmove;
        MMap.EnablePickpoints(objectmove == 1);
        if (objectmove == 1)
          MMap.$("#ImgEdit").addClass("active");
        else
          MMap.$("#ImgEdit").removeClass("active");
        sDiscsChanged(); //  triggert legenda herladen
      }

      function searchLabel(evt)
      {
  	    FcltMgr.stopPropagation(evt);
        var loc = $("#locatiekey").val();
        var url="../cad/any_search.asp?floor_key=" + floor_key + "&loc_key=" + loc + getCustomParameters();
        FcltMgr.openModalDetail(url, L("lcl_cad_search"),
                                    { callback: function (data)
                                                {
                                                    gotoRoom(data);
                                                }
                                    }
                                )
      }

      function togglePanes(evt)
      {
	        FcltMgr.stopPropagation(evt);
          var tabpane = $("#fgtabtoggler");
          toggleTabLayout (tabpane);
          var navpane = $("#fgmenutoggler");
          toggleLayout (navpane);
          globalpanesdown = !globalpanesdown;
          if (globalpanesdown)
            MMap.$("#ImgTogglePanes").html("<%=I("fa-chevron-double-up")%>");
          else
            MMap.$("#ImgTogglePanes").html("<%=I("fa-chevron-double-down")%>");
      }

      function scrollview(elm)
      {
        return;  // wat gebeurt er zonder? Nu zoekveld weg is, mag dit weg imho
        //var navdiv = $('#navigationCell');
        //var top = elm.position().top + navdiv.scrollTop();
        //var bottom = top + elm.height();

        //if (bottom > navdiv.height() + navdiv.scrollTop())
        //navdiv.scrollTop(Math.min(top, bottom - navdiv.height() + 5));
      }

      // Open/dicht klappen blokje
      function toggleFG(elm, idList)
      {
        $(elm).toggleClass("openFG closedFG");
        var idl = idList.split(/\s*,\s*/);
        for (var i = 0; i < idl.length; i++)
        {
          $("#"+idl[i]).toggle();
          if ($("#"+idl[i]).length)
              $("#"+idl[i]).prev(".multi_select_toggle, .multi_suggest_toggle").toggle();
          var $lastelm = $("#"+idl[i]);
        }
        if ($(elm).hasClass("openFG") && $lastelm.length)
        {   // Probeer lastelm in beeld te brengen
            scrollview($lastelm);
        }
        $(".fa-chevron-circle-down, .fa-chevron-circle-right", $(elm)).toggleClass("fa-chevron-circle-down fa-chevron-circle-right");
      }

      function resetMap()
      {
        if (!MMap || !MMap.Reset)
            return; // Safari: te vroeg
        MMap.Reset();
        MMap.SetLabelPosition(<%=S("fg_labelPosition")%>);
        MMap.SetIMGGenerator("../cad/mySlnk2IMG.asp");
        // Door de volgende regel kunnen symbolen versleept worden
        MMap.SetKeyToSymbol("../cad/mykeyToSymbol.asp");

        if (scenario_key > 0)
          MMap.SetPaperColor(<%=S("prj_fg_papercolor")%>);
        else
          MMap.SetPaperColor(<%=S("fg_paperColor")%>);

        if ($('#MMap2').length)
        {
          MMap2.Reset();
          MMap2.SetLabelPosition(<%=S("fg_labelPosition")%>);
          MMap2.SetIMGGenerator("../cad/mySlnk2IMG.asp");

          MMap2.SetPaperColor(<%=S("fg_paperColorCpt")%>);
        }
      }

      // Wordt automagisch aangeroepen als tabje wordt geactiveerd
      var isVisible = true;
      function fcltontabshow()
      {
          isVisible = true;
      }
      function fcltontabhide()
      {
          isVisible = false;
      }

      var pctImg = 65; // vertical Percentage for image
      function resizeIframes()
      {
        if (!isVisible)
            return; // Don't bother

        var height = parseInt(document.documentElement.clientHeight);
        var td2=document.getElementById("theTabs");
        if (td2.style.marginLeft == "")
        {
          var height2 = Math.floor(height * pctImg / 100);
        }
        else
        {
          var height2 = height; // Want de tabjes zijn naar rechts geschoven
        }
        if (document.getElementById('MMap').style.height != Math.floor(height * pctImg / 100) + "px")
        {
          $('#MMap').css('height', Math.floor(height * pctImg / 100) + "px");
          $('#mapCell').css('height', Math.floor(height * pctImg / 100) + "px");
        }
        $('#navigationCell').height(height2 - 1);
        $("#legendCell").css("maxHeight", height2 - 33); // Legendcell heeft een top van 32px (hoogte van navigationCell - 32px dus)
        $("#fgmenutoggler").css("top", $('#MMap').height() - $("#fgmenutoggler").outerHeight() - 3 + "px");
        if ($("#fgmenutoggler").hasClass("collapsed")){
            $("#fgmenutoggler").css("left", 0);
            $("#fgmenutoggler").html("<%=I("fa-caret-right", { fastyle: "fas" })%>");
        }
        else{
            $("#fgmenutoggler").css("left", $("#navigationCell").width() - $("#fgmenutoggler").width() + 2);
            $("#fgmenutoggler").html("<%=I("fa-caret-left", { fastyle: "fas" })%>");
        }

        $("#fgtabtoggler").css('top' , $('#MMap').height() - (window.pctImg == 100?$("#fgtabtoggler").height():0) + "px");
        $("#fgtabtoggler").css('left', $(window).width() - $("#fgtabtoggler").width() - 8 + "px");

        resizetabIframe();
      };
      $(function () { resizeIframes(); });

      var needInit = <%= concept?2:1 %>
      function init(main)
      {
        needInit--;
        if (needInit > 0)
            return; // concept afwachten

        MMap.EnablePickpoints(objectmove == 1);

<% if (!concept) { %>
        if (main)
        {
            MMap.addButtonAfter("ImgRefresh",
                                    { id:"ImgSearch",
                                      alt:"Search in text",
                                      label: L("lcl_cad_search"),
                                      onClick: searchLabel,
                                      icon: "fa-search-location fa-flip-horizontal"
                                    });
              MMap.addButtonAfter("ImgSearch",
                                      { id:"ImgEdit",
                                        alt:"Edit",
                                        label: L("lcl_cad_editmode"),
                                        onClick: gotoEditmode,
                                        toggleonly: true,
                                        icon: "fa-fclt-edit"
                                      });

            MMap.addButtonAfter("ImgEdit",
                                    { id:"ImgTogglePanes",
                                      alt:"Toggle panes",
                                      label: L("lcl_cad_togglepanes"),
                                      onClick: togglePanes,
                                      icon: "fa-chevron-double-down"
                                    });
            globalpanesdown = false;
            MMap.addButtonAfter("ImgTogglePanes",
                                    { id:"ImgInfoBoard",
                                      alt:"As Infobord",
                                      label: L("lcl_cad_infoboard"),
                                      onClick: toInfobord,
                                      icon: "fa-cube"
                                    });
            MMap.addButtonAfter("ImgInfoBoard",
                                    { id:"ImgMaximize",
                                      alt:"Maximize",
                                      label: L("lcl_cad_maximize"),
                                      onClick: onFullScreen,
                                      icon: "fa-external-link"
                                    });
<%        if (user.has("WEB_CADFOF")) { %>
              MMap.addButtonAfter("ImgMaximize",
                                      { id:"ImgDrawing",
                                        alt:"To drawing",
                                        label: L("lcl_menu_fg_tekeningen"),
                                        onClick: toTekeningen,
                                        icon: "fa-folder-open"
                                      });
<%        } %>
        }
<% } %>
        OnLocationChanged(document.getElementById("loc"));
<%      if (floor_key>0) { %>
          OnFloorChanged(); // Vullen listbox ruimte
<%      } %>
        // eerste keer vullen legenda

        sDiscsChanged(); // Vullen legenda en 'toevoeg' listbox
        draginit();

        var timerID=null;
        window.onresize = function()
        {
        	if (timerID) clearTimeout(timerID);
            timerID = setTimeout(resizeIframes, 100);// use a delay for IE because the resize event fires repeatly
        }

        resizeIframes();
        resetMap();
        // Komt vanzelf? myRefresh();
      }

      // start Symbolen draggen vanuit menu. Zie LoadInsLegenda.asp

      // variant op draganddrop.js/dragstart
      // Wij willen bij het starten van het draggen een ander (op schaal) symbool gebruiken
      // bronInfo { type:"W" } voor werkplekken,
      //          { type: "I", key: 1234") ins_srtdeel_key
      //          { type: "L", key: 1234") ins_legendawaarde_key
      function mydragstart(evt, imgHTML, bronInfo)
      {
        /* global */ naviTop = $("#navigationCell").scrollTop();

        if (!evt) evt=window.event;
        var elmSymbol = document.getElementById("dragSymbol");
        elmSymbol.innerHTML=imgHTML;
        elmSymbol.style.display = 'block';
        elmSymbol.setAttribute("bronInfoType", bronInfo.type);
        elmSymbol.setAttribute("bronInfoKey", bronInfo.key);
        dragAndDropNotify = notifyDrop;
        dragapproved=true;
        dragElement=elmSymbol;
        temp1=evt.clientX;
        temp2=evt.clientY;
        dragStartX=evt.clientX;
        dragStartY=evt.clientY;
        correctieY = 0;  // extra correctie hier niet nodig
        dragmove(evt);
      }

      // Start draggen van een nieuw INS_DEEL
      function Reposition(elmSymb)
      {
        elmSymb.style.top  = (- (elmSymb.naturalHeight||elmSymb.height) / 2) + "px";
        elmSymb.style.left = (- (elmSymb.naturalWidth||elmSymb.width) / 2) + "px";
      }

      function mydragstartINS(evt, srtdeel_key)
      {
        // Door de Reposition truc centreert het symbool rond de cursor.
        // Dat is niet 100% correct want eigenlijk zouden we rond het zwaartepunt van de symboolcontour moeten centreren
        var imgHTML = "<img alt='" + L("lcl_drag_file") + "' style='position:absolute;top:-40px;left:-40px' onload='if (parent.Reposition) parent.Reposition(this)'";
            imgHTML+= "     src =\"../cad/mysymbol.asp?paperColor="+MMap.gSLNKEvent.paperColor+"&srtdeel="+srtdeel_key+"&sdwgScale=" + MMap.gSLNKEvent.scaleY + "\">";
        mydragstart(evt, imgHTML, { type:"I", key:srtdeel_key });
      }

      // Start draggen van een nieuwe werkplek
      function mydragstartWP(evt)
      {
        var imgHTML = "<img alt='" + L("lcl_drag_file") + "' style='position:absolute;top:-10px;left:-10px' onload='if (parent.Reposition) parent.Reposition(this)'";
            imgHTML+= "     src =\"../cad/myWerkplek.asp?paperColor="+MMap.gSLNKEvent.paperColor+"&sdwgScale=" + MMap.gSLNKEvent.scaleY + "\">";
        mydragstart(evt, imgHTML, { type:"W" });
      }

      // Start draggen van een legendawaarde
      function mydragstartLegenda(evt, safe_inlineStyle, waarde)
      {
        var imgHTML = "<div class='legendakleur' style='position:absolute;top:-10px;left:-10px;'>"
                    + "   <div class='legendakleurblokje' style='" + safe_inlineStyle + "'>&nbsp;</div>"
                    + "</div>"
        mydragstart(evt, imgHTML, { type: "L", key:waarde });
      }

      function selectLegendaCallback(data)
      {
        var i, j;
        var sl = document.getElementById("<%=inoutMode == MODE_IN? "rooms" : "terr"%>");
        sl.selectedIndex = -1; // leeg beginnen
        var ob = sl.options;
        for (i in data.keys)
        {
          for (j = 0; j<ob.length; j++)
          {
            if (ob[j].value == data.keys[i])
            {
              ob[j].selected = true;
            }
          }

        }
        myRefresh()
      }
      // Geklikt op een legendawaarde tekst. Highlight bijbehorende ruimtes
      function selectfromLegenda(evt, tekst)
      {
        // FcltMgr.alert("Geklikt op 'kleur': {0}, tijd om die te highlighten".format(tekst));
        var url = "cad_selectbylegend.asp?legenddesc=" + escape(tekst);
        url += getCustomParameters();
        $.post(url, {}, FcltCallbackAndThen(selectLegendaCallback), "json");
      }

      // Wordt aangeroepen als we boven het plaatje komen met ons dragobject
      function drag_onMouseOut(dragElement, evt)
      {
        EnableDragAndDrop(notifyDrop, dragElement.innerHTML);
      }

      // Wordt aangeroepen als we klaar zijn met draggen
      function drag_onDragEnd(dragElement, evt)
      { // 5.2.1 Met FireFox komen we hier nooit?
        var elmSymbol = document.getElementById("dragSymbol");
        elmSymbol.style.display = 'none';
        $("#navigationCell").scrollTop(naviTop);
        if (!evt) evt=window.event;
        MMap.doDrop(evt, evt.clientX - $("#mapCell").offset().left, evt.clientY - $("#mapCell").offset().top);
      }

      // Callback functie: er is iets gedropt op het plaatje
      // (een symbool of werkplek vanuit de legenda)
      function notifyDrop(SlnkEvent)
      {
        var ruimteKey = SlnkEvent.Key;
        if (!ruimteKey)
        {
          // niet op herkenbare ruimte gedropt
          return;
        }

        if (dragElement.getAttribute("bronInfoType") == "L") // Legendawaarde
        {
          var ruimteKey = SlnkEvent.Key;
          // TODO: oppassen voor droppen op WPs of objecten. Nu doen we niks als NaN (bv I:999 of W:999)
          // en krijgt de user effectief toevallig een herkansing.
          var url = "legenda_create.asp?room_key=" + ruimteKey; // gedropt op ruimte
          url += "&lwkey="+dragElement.getAttribute("bronInfoKey");
          if (SlnkEvent.event.shiftKey)
              url+="&addmode=1"; // Toevoegen aan de ruimte ipv vervangen

          url += getCustomParameters(); // Geeft ook mooi thema-key mee

          var data = {};
          <% protectRequest.dataToken("data"); %>
          if (!isNaN(ruimteKey))
            $.post(url, data, FcltCallbackAndThen(myRefresh), "json");
        }
        else
            newSymbol(SlnkEvent, false); // !isCopy, isMove dus
        dragapproved=false;
        dragElement.style.display="none";
        document.onmousemove=null;
      }

// Kopieer een symbool of werkplek vanuit de tekening (draggen en dan shift indrukken)
// Of maak een nieuw symbool of werkplek aan (draggen vanuit navigate pane)
// symbolen kunnen vervolgens weer gedropt zijn op een werkplek
// isCopy is true voor kopie (vanuit de tekening) en false voor draggen vanuit legenda
// globale dragElement.bronInfo is gezet en daar zien we het onderscheid aan
      function newSymbol(SlnkEvent, isCopy)
      {
        var ruimteKey = SlnkEvent.Key;
        if (!ruimteKey || (SlnkEvent.ContourLayer != "SLNK Contours" && !ruimteKey.match(/^W:/)))
        {
          FcltMgr.alert(L("lcl_fg_obj_firstnew")); // Eerst in ruimte of op werkplek
          return;
        }

        var dwgX = SlnkEvent.dwgX;
        var dwgY = SlnkEvent.dwgY;

        var loc = $("#locatiekey").val();

        if (isCopy)
        {
          if (SlnkEvent.fromKey.match(/^W:/))
            var url= "wp_create.asp?wp_key=" + SlnkEvent.fromKey.substring(2);
          else
            var url= "ins_create.asp?deel_key=" + SlnkEvent.fromKey;
        }
        else
        {
          if (dragElement.getAttribute("bronInfoType") == "W")
            var url= "wp_create.asp?x=x";
          else
            var url= "ins_create.asp?srtdeel_key=" + dragElement.getAttribute("bronInfoKey");
        }

        url += "&loc_key=" + loc +  getCustomParameters();

        // Werkplek is nog niet vertaald door mySlnk2IMG.asp/myFindKeys()
        if (SlnkEvent.ContourKey.match(/^W:/))
          url += "&wp_key="+SlnkEvent.ContourKey.substring(2); // gedropt op werkplek
        else
          url += "&room_key="+ruimteKey; // gedropt op ruimte

        if (!SlnkEvent.event.ctrlKey)
          url += "&dwgX="+dwgX+"&dwgY="+dwgY;

        var data = {};
        <% protectRequest.dataToken("data"); %>
        $.post(url, data, FcltCallbackAndThen(myRefresh), "json")
      }

      function toggleLayout(elm)
      {
        $(elm).toggleClass("collapsed");
        $("#navigationCell").toggleClass("collapsed");
        if ($("#navigationCell").hasClass("collapsed"))
            $("#mapCell").css("margin-left", 0);
        else
            $("#mapCell").css("margin-left", "");
        resizeIframes();
      }

      function toggleTabLayout(elm)
      {
        $(elm).toggleClass("collapsed");
        window.pctImg = window.pctImg == 65?100:65;
        resizeIframes();

        if($("#fgtabtoggler").hasClass("collapsed")){
          $("#fgtabtoggler").html("<%=I("fa-caret-up", { fastyle: "fas" })%>");
        } else {
          $("#fgtabtoggler").html("<%=I("fa-caret-down", { fastyle: "fas" })%>");
        }
      }
    </script>
  </head>

<%
    var menuoptions =
    [
      {id:"",   alt:"",   label: L("lcl_slnk_rotateright"),        onClick: "parent.RotateSymbol(parent._symbolKey,-90)",  icon: "fa-undo fa-flip-horizontal",  button: 0, menu: 1 },
      {id:"",   alt:"",   label: L("lcl_slnk_rotateleft"),         onClick: "parent.RotateSymbol(parent._symbolKey,90)",   icon: "fa-undo",  button: 0, menu: 1 },
      {id:"",   alt:"",   label: L("lcl_slnk_rotate180"),          onClick: "parent.RotateSymbol(parent._symbolKey,180)",  icon: "fa-fclt-refresh",  button: 0, menu: 1 },
      {id:"",   alt:"",   label: L("lcl_slnk_rotate0"),            onClick: "parent.RotateSymbol(parent._symbolKey,0)",    icon: "fa-circle-notch",  button: 0, menu: 1 },
      {id:"",   alt:"",   label: L("lcl_slnk_alignwall"),          onClick: "parent.AlignSymbol(event)",                   icon: "fa-ruler-combined",  button: 0, menu: 1 },
      {id:"",   alt:"",   label: L("lcl_slnk_rotatefree"),         onClick: "parent.RotateSymbol(parent._symbolKey)",      icon: "fa-drafting-compass",  button: 0, menu: 1 },
      {id:"",   alt:"",   label: L("lcl_slnk_scale"),              onClick: "parent.ScaleSymbol()",                        icon: "fa-arrows",     button: 0, menu: 1 },
      {id:"",   alt:"",   label: L("lcl_slnk_resetpos"),           onClick: "parent.DoMoveSymbol(parent._symbolKey, null)",icon: "fa-location",   button: 0, menu: 1 },
      {id:"",   alt:"",   label: L("lcl_slnk_delete"),             onClick: "parent.RemoveSymbol(parent._symbolKey)",      icon: "fa-trash-alt",   button: 0, menu: 1 },
      {id:"",   alt:"",   label: L("lcl_slnk_properties"),         onClick: "parent.showSymbol()",                         icon: "fa-info-square",   button: 0, menu: 1 }
    ];
%>
  <body id="searchbody">
    <div id="dragSymbol" class="fgdragsymbol" style="display:none;position:absolute;z-index:1;">Hier komt dragsymbool</div>
    <div id="datumfilter" class="fgdatumfilter" style="display:none;position:absolute;z-index:1;left:240px;top:1px"><select onchange='myRefresh()'></select></div>
    <div id="PickcontextMenu" class="slnkmenu" style="display:none">
      <div class="menuItem menuTitle"><%=L("lcl_slnk_symbolmenu")%></div>
<%
    for (var butt in menuoptions) {
        if (menuoptions[butt].menu == 1)
        {
            Response.Write("<div class='menuItem' monClick='"+menuoptions[butt].onClick+"'>"+I(menuoptions[butt].icon+" fa-lg")+"&nbsp;"+menuoptions[butt].label+"</div>");
        }
    }
%>
    </div>

      <div id='navigationCell'>
        <table cellpadding="0" cellspacing="0">
          <!-- ==========================
               SCENARIOS
               ============================ -->
<%        if (scenario_key > 0)
          { %>
            <tr>
              <td valign="top" align="left" id="scenario_help"><%=L("lcl_prj_scenario")%></td>
            </tr>
            <tr>
              <td>
<%              // We tonen hier de scenarios die bij dezelfde melding horen, alternatieven voor dezelfde actie dus.
                sql = "SELECT prj_scenario_key, prj_scenario_omschrijving FROM prj_scenario "
                      + " WHERE mld_melding_key = "
                      + "         (SELECT mld_melding_key FROM prj_scenario"
                      + "           WHERE prj_scenario_key = " + scenario_key + ")"
                      + "    OR (prj_scenario_key = " + scenario_key + " AND mld_melding_key IS NULL)"
                      + " ORDER BY 2"

                 FCLTselector("scenario",
                              sql,
                              { initKey: scenario_key,
                                onChange: "onScenarioChange(this)"
                              });
%>
              </td>
            </tr>
<%        } %>
          <!-- ==========================
               LOKATIES
          ============================ -->
          <tr>
            <td class="fixedFG"><%=I("fa-stop-circle fa-2x")%>&nbsp;<%= (inoutMode == MODE_IN ? L("lcl_fg_navigator_in") : L("lcl_fg_navigator_out")) %></td>
          </tr><tr><td>
<%
          FCLTplaatsselector(authparams.ALGreadlevel, {no_table: true,
                                                       nolabel: true,
                                                       locatiekey: loc_key,
                                                       gebouwkey: bld_key,
                                                       verdiepingkey: floor_key,
                                                       startlevel: 2, // Locatie
                                                       autoselect: true,
                                                       filtercode: "CAD",
                                                       moreinfo: false,
                                                       eindlevel: (inoutMode == MODE_IN ? 4 : 2), // Verdieping of locatie
                                                       onLocChange: "OnLocationChanged()",
                                                       onVerChange: "OnFloorChanged()"
                                                     });
%></td></tr>

<%
          if (inoutMode == MODE_IN)
          {
              if (S("prs_werkplek_implicit") == 0)
              {
                  // Alleen bij expliciete werkplekken
                  // Hebben ik schrijfrechten op werkplekken?
                  // We negeren nog even verdieping, dat controleert het wp_create save script wel.
                  var sql =  "SELECT MIN(fac_gebruiker_alg_level_write) lvl"
                          + "  FROM fac_v_webgebruiker w, fac_functie f"
                          + " WHERE w.fac_functie_key = f.fac_functie_key "
                          + "   AND w.prs_perslid_key = " + user_key
                          + "   AND fac_functie_code = 'WEB_PRSBOF'";
                  var oRs = Oracle.Execute(sql);
                  var canWriteWP = !oRs.Eof && oRs("lvl").Value < 9;
                  oRs.Close();
%>
              <tr id="wps">
                <td style="padding:5px 0 0 0;">
                    <input id="werkplek" type="checkbox" onclick='myRefresh();'>
                    <label for="werkplek">
                      <span <%= canWriteWP ? "style='cursor:grab' onmousedown='mydragstartWP(event)'" : "" %>>
                            <%=L("lcl_fg_thema_werkplek")%>
                      </span>
                    </label>
                  </td>
              </tr>
<%            } %>

            <!-- ==========================
                 RUIMTES
            ============================ -->
            <tr class="openFG" id="rooms_help" onClick="toggleFG(this, 'tr_rooms, conts');">
              <td><%=I("fa-chevron-circle-right fa-2x")%>&nbsp;<%=L("lcl_fg_room_filter")%></td>
            </tr>

            <tr id="conts" style="display:none">
              <td style="padding:0;">
                <input id="contour0" type="checkbox" <%=showcontour?"checked":""%> onclick='toggleContour(this)'>
                <label for="contour0"><%=L("lcl_fg_thema_contour")%></label>
<%
                if ((my_cadrechten.canRead('WEB_CADBOF') || my_cadrechten.canRead('WEB_CADFOF')) && inoutMode == MODE_IN)
                {   // Gebruik -2 en -3 voor de alternatieve lagen
                  if (S("fg_contourlayers_alt1")!=""&&S("fg_labellayers_alt1") != "")
                  { %>
                    <br><input id="contour1" type="checkbox" onclick='toggleContour(this)'>
                    <label for="contour1"><%=L("lcl_fg_thema_contour_alt1")%></label>
<%                }
                  if (S("fg_contourlayers_alt2")!=""&&S("fg_labellayers_alt2") != "")
                  { %>
                    <br><input id="contour2" type="checkbox" onclick='toggleContour(this)'>
                    <label for="contour2"><%=L("lcl_fg_thema_contour_alt2")%></label>
<%                }
                } %>
              </td>
            </tr>

            <tr id="tr_rooms" style="display:none">
            <td>
            <%
                sql = "";
                FCLTselector("rooms",
                     sql,
                     { initKey: -1,
                       emptyOption: "", // loadRuimteOptions bepaalt deze pas echt na verdiepingskeuze
                       initEmpty: true,
                       size: 5,
                       multi: true,
                       startmulti: true,  // deze select wordt door functies gebruikt om ruimtes te hiliten, en dan moet deze multi zijn
                       onChange: "myRefresh()"
                     });
            %>
            </td>
            </tr>
<%        }
          else
          { // buiten
%>
            <!-- ==========================
                 TERREINEN
             ============================ -->

            <tr class="openFG" id="rooms_help" onClick="toggleFG(this, 'tr_terr');">
              <td><%=I("fa-chevron-circle-right fa-2x")%>&nbsp;<%=L("lcl_fg_terr_filter")%></td>
            </tr>
            <tr id="tr_terr" style="display:none">
              <td>
<%              sql = "";
                if (loc_key > 0)
                    sql = "SELECT alg_terreinsector_key,"
                        + "      alg_terreinsector_naam"
                        + "  FROM alg_v_aanwezigterreinsector"
                        + " WHERE alg_locatie_key = " + loc_key
                        + " ORDER BY 2";

                FCLTselector("terr",
                     sql,
                     { initKey: -1,
                       emptyOption: "",
                       initEmpty: true,
                       size: 6,
                       multi: true,
                       startmulti: true,
                       onChange: "myRefresh()"
                     });
%>
              </td>
            </tr>
<%        } %>

          <!-- ==========================
               INS DISCIPLINES tonen voor de layers
          ============================ -->
          <tr class="closedFG" onClick="toggleFG(this, 'insDisc<%=(inoutMode == MODE_IN)? ", insZoek" : ""%>');">
          <td><%=I("fa-chevron-circle-right fa-2x")%>&nbsp;<%=L("lcl_fg_obj_filter")%></td>
          </tr>
          <tr id="insDisc" style="display:none">
            <td>
<%
              if (scenario_key == 0)
                var sqlfilter = " fac_functie_code IN ('WEB_INSMAN', 'WEB_INSUSE')"    // @??@?SCOPE nog?
              else
                var sqlfilter = " fac_functie_code = 'WEB_INSPRJ'";

              if (S("fg_publiclayers").length)
                sqlfilter += " OR d.ins_discipline_key IN (" + S("fg_publiclayers").join(",") + ")"

              sql = "SELECT DISTINCT d.ins_discipline_key"
                  + ",                " + lcl.xsqla('d.ins_discipline_omschrijving', 'd.ins_discipline_key')
                  + ",                BITAND(dp.ins_disc_params_type, " + (inoutMode == MODE_IN? 4 : 8) + ") defaultOn "
                  + " FROM fac_v_my_disciplines m, ins_v_aanwezigdiscipline d, ins_disc_params dp "
                  + " WHERE d.ins_discipline_key = m.ins_discipline_key(+)" // outer joins voor S("fg_publiclayers")
                  + "   AND m.prs_perslid_key (+)="+user_key
                  + "   AND d.ins_discipline_min_level = 1"
                  + "   AND dp.ins_disc_params_cadlayers IS NOT NULL"
                  + "   AND BITAND(dp.ins_disc_params_type, " + (inoutMode == MODE_IN? 1 : 2) + ")>0"
                  + "   AND dp.ins_discipline_key = d.ins_discipline_key"
                  + "   AND (" + sqlfilter + ")"
                  + "   ORDER BY 2,1";

              var oRs = Oracle.Execute(sql);

              Response.Write("<div class='fgdiscblock' id='sDiscsIn'>");
              while (!oRs.eof)
              {
                var disc_key = oRs("ins_discipline_key").value;
                Response.Write("\n<div class='fgdiscipline'>");
                CHECKBOX("fldcheck", "fgdisc" + disc_key, oRs("defaulton").value > 0, {value: disc_key, html: "onchange='myRefresh()'"});
                Response.Write("<label for='fgdisc"+disc_key+"'>"+safe.html(oRs("ins_discipline_omschrijving").value)+"</label>");
                Response.Write("</div>");
                oRs.MoveNext();
              }
              oRs.Close();
              Response.Write("</div>");

%>          </td>
          </tr>
          <!-- ==========================
               Symbolen Legenda
          ============================ -->
<%        if (S("fg_ins_symbols"))
          { %>
            <tr id='tinsLegend' style="display:none" class="closedFG" onClick="toggleFG(this, 'insLegend');">
              <td><%=I("fa-chevron-circle-right fa-2x")%>&nbsp;<%=L("lcl_fg_obj_legend")%></td>
              <!-- <td><%=L("lcl_fg_obj_legend")%></td> -->
            </tr>
            <tr id="insLegend" style="display:none">
              <td><div id="dinsLegend" class="canMaxFG" onclick="this.className=(this.className=='canMaxFG'?'isMaxFG':'canMaxFG');">
<%              /* Gevuld in sDiscsChanged/Ajax.Updater/LoadInsLegenda.asp */ %></div>
              </td>
            </tr>
<%        } %>
          <!-- ==========================
               LABEL THEMA's
          ============================ -->
          <%
            // TODO: zichtbaarheid legendCell moet iets fancier: bij initieel inklappen verschijnt die nu, terwijl die weg moet als je
            // hier inklapt en het alleen zichbaar moet zijn met gekozen kleurthema(s).
          %>
          <tr class="closedFG" onClick="toggleFG(this, 'lblIn0,lblIn1,lblIn2,lblIn3,labelIn,thmIn1,thmIn2,thmIn3,thmIn4,thmIn5,legendCell')">
          <td><%=I("fa-chevron-circle-down fa-2x")%>&nbsp;<%=L("lcl_fg_info")%></td>
          </tr>
          <tr id="lblIn0">
            <td id="sThemaIn_help" align="left" style="margin:0"><label for="sLabelIn"><%=L("lcl_fg_labels")%></label>
            </td>
          </tr>
          <tr id="lblIn1">
            <td>
<%            var bitcode = 0x01; // binnen
              if (inoutMode==MODE_OUT)
                bitcode = 0x02; // buiten
              var scenariobit = (scenario_key == 0 ? 0 : 4);

              // ruimtelabels

              sql = "SELECT CAD_LABEL_KEY,"
                  + lcl.xsqla('CAD_LABEL_OMSCHRIJVING', 'cad_label_key') + ","
                  + lcl.xsqla('cad_label_opmerking', 'cad_label_key')
                  + ", (SELECT 1 FROM user_tab_cols"
                      + " WHERE table_name = UPPER(cad_label_view)"
                      + "   AND column_name = 'FCLT_F_DATUM'"
                      + "   AND data_type = 'DATE') has_datum_filter"
                  + "  FROM CAD_LABEL"
                  + " WHERE BITAND(CAD_LABEL_TYPE, " + bitcode + ") = " + bitcode
                  + "   AND BITAND(CAD_LABEL_TYPE, 4) = " + scenariobit
                  + "   AND BITAND(CAD_LABEL_TYPE, 24) = 0"
                  + "   AND (FAC_FUNCTIE_KEY IS NULL"
                  + "       OR FAC_FUNCTIE_KEY IN "
                  + "               (SELECT FAC_FUNCTIE_KEY FROM fac_v_webgebruiker"
                  + "                  WHERE prs_perslid_key = " + user_key + "))"
                  + " ORDER BY 2";

              FCLTselector("sLabelIn1", sql,
                      { emptyOption: L("lcl_fg_norlabels"),
                        titleCol: "cad_label_opmerking",
                        onChange: "sLabelChanged(this)",
                        extraParamValue: "has_datum_filter"
                      }); %>
            </td>
          </tr>
<%
       if (S("fg_ins_symbols"))
       {
%>
          <tr id="lblIn2">
            <td>
<%
              // objectlabels

              sql = "SELECT CAD_LABEL_KEY,"
                      + lcl.xsqla('CAD_LABEL_OMSCHRIJVING', 'cad_label_key') + ","
                      + lcl.xsqla('cad_label_opmerking', 'cad_label_key')
                      + ", (SELECT 1 FROM user_tab_cols"
                          + " WHERE table_name = UPPER(cad_label_view)"
                          + "   AND column_name = 'FCLT_F_DATUM'"
                          + "   AND data_type = 'DATE') has_datum_filter"
                      + "  FROM CAD_LABEL"
                      + " WHERE BITAND(CAD_LABEL_TYPE, " + bitcode + ") = " + bitcode
                      + "   AND BITAND(CAD_LABEL_TYPE, 4) = " + scenariobit
                      + "   AND BITAND(CAD_LABEL_TYPE, 24) = 16"
                      + "   AND (FAC_FUNCTIE_KEY IS NULL"
                      + "       OR FAC_FUNCTIE_KEY IN "
                      + "               (SELECT FAC_FUNCTIE_KEY FROM fac_v_webgebruiker"
                      + "                  WHERE prs_perslid_key = " + user_key + "))"
                      + " ORDER BY 2";

                  FCLTselector("sLabelIn2", sql,
                          { emptyOption: L("lcl_fg_noilabels"),
                            titleCol: "cad_label_opmerking",
                            onChange: "sLabelChanged(this)",  // TODO: deze labels ook laten werken
                            extraParamValue: "has_datum_filter"
                          }); %>
            </td>
          </tr>
<%     }
       if (S("prs_werkplek_implicit")==0)
       {
%>
          <tr id="lblIn3">
            <td>
<%
              // werkpleklabels
              sql = "SELECT CAD_LABEL_KEY,"
                      + lcl.xsqla('CAD_LABEL_OMSCHRIJVING', 'cad_label_key') + ","
                      + lcl.xsqla('cad_label_opmerking', 'cad_label_key')
                      + ", (SELECT 1 FROM user_tab_cols"
                          + " WHERE table_name = UPPER(cad_label_view)"
                          + "   AND column_name = 'FCLT_F_DATUM'"
                          + "   AND data_type = 'DATE') has_datum_filter"
                      + "  FROM CAD_LABEL"
                      + " WHERE BITAND(CAD_LABEL_TYPE, " + bitcode + ") = " + bitcode
                      + "   AND BITAND(CAD_LABEL_TYPE, 4) = " + scenariobit
                      + "   AND BITAND(CAD_LABEL_TYPE, 24) = 8"
                      + "   AND (FAC_FUNCTIE_KEY IS NULL"
                      + "       OR FAC_FUNCTIE_KEY IN "
                      + "               (SELECT FAC_FUNCTIE_KEY FROM fac_v_webgebruiker"
                      + "                  WHERE prs_perslid_key = " + user_key + "))"
                      + " ORDER BY 2";

                  FCLTselector("sLabelIn3", sql,
                          { emptyOption: L("lcl_fg_nowlabels"),
                            titleCol: "cad_label_opmerking",
                            onChange: "sLabelChanged(this)",  // TODO: deze labels ook laten werken
                            extraParamValue: "has_datum_filter"
                          }); %>
            </td>
          </tr>
<%    } %>
          <!-- ==========================
               KLEUREN THEMA's
          ============================ -->
          <tr id="thmIn2">
            <td id="sThemaIn_help" align="left" style="margin:0"><label for="sThemaIn"><%=L("lcl_fg_themas")%></label>
            </td>
          </tr>
          <tr id="thmIn3">
            <td>
<%            sql = "SELECT CAD_THEMA_KEY, "
                  + lcl.xsql('cad_thema_omschrijving', 'cad_thema_key') + "||DECODE(BITAND(cad_thema_type, 128),128,'*','') cad_thema_omschrijving, "
                  + lcl.xsqla('cad_thema_opmerking', 'cad_thema_key')
                  + ", (SELECT 1 FROM user_tab_cols"
                      + " WHERE table_name = UPPER(cad_thema_view)"
                      + "   AND column_name = 'FCLT_F_DATUM'"
                      + "   AND data_type = 'DATE') has_datum_filter"
                  + "  FROM CAD_THEMA "
                  + " WHERE BITAND(CAD_THEMA_TYPE, " + bitcode + ") = " + bitcode
                  + "   AND BITAND(CAD_THEMA_TYPE, 4) = " + scenariobit
                  + "   AND BITAND(CAD_THEMA_TYPE, 24) = 0"
                  + "   AND (FAC_FUNCTIE_KEY IS NULL"
                  + "       OR FAC_FUNCTIE_KEY IN "
                  + "               (SELECT FAC_FUNCTIE_KEY FROM fac_v_webgebruiker"
                  + "                  WHERE prs_perslid_key = " + user_key + "))"
                  + " ORDER BY 2";

              FCLTselector("sThemaIn", sql,
                      { emptyOption: (inoutMode==MODE_IN ? L("lcl_fg_northema") : L("lcl_fg_notthema")),
                        titleCol: "cad_thema_opmerking",
                        onChange: "sThemeChanged(this)",
                        extraParamValue: "has_datum_filter"
                      }); %>
            </td>
          </tr>
<%
       if (S("fg_ins_symbols"))
       {
%>
          <tr id="thmIn4">
            <td>
<%
              // eerst toch even snel tellen of deze er wel zijn? Dat zou de selector mogen doen (hideifempty oid)
              sql = "SELECT CAD_THEMA_KEY, "
                  + lcl.xsql('cad_thema_omschrijving', 'cad_thema_key') + "||DECODE(BITAND(cad_thema_type, 128),128,'*','') cad_thema_omschrijving, "
                  + lcl.xsqla('cad_thema_opmerking', 'cad_thema_key')
                  + "  FROM CAD_THEMA "
                  + " WHERE BITAND(CAD_THEMA_TYPE, " + bitcode + ") = " + bitcode
                  + "   AND BITAND(CAD_THEMA_TYPE, 4) = " + scenariobit
                  + "   AND BITAND(CAD_THEMA_TYPE, 24) = 16" // 8+16=symbolen
                  + "   AND (FAC_FUNCTIE_KEY IS NULL"
                  + "       OR FAC_FUNCTIE_KEY IN "
                  + "               (SELECT FAC_FUNCTIE_KEY FROM fac_v_webgebruiker"
                  + "                  WHERE prs_perslid_key = " + user_key + "))"
                  + " ORDER BY 2";

              FCLTselector("sThemaIn2", sql,
                      { emptyOption: L("lcl_fg_noithema"),
                        titleCol: "cad_thema_opmerking",
                        onChange: "sThemeChanged(this)"
                      }); %>
            </td>
          </tr>
<%
       }
       // met een check of die er wel zijn?
       if (S("prs_werkplek_implicit") == 0)
       {
%>
          <tr id="thmIn5">
            <td>
<%
              // eerst toch even snel tellen of deze er wel zijn? Dat zou de selector mogen doen (hideifempty oid)
              sql = "SELECT CAD_THEMA_KEY, "
                  + lcl.xsql('cad_thema_omschrijving', 'cad_thema_key') + "||DECODE(BITAND(cad_thema_type, 128),128,'*','') cad_thema_omschrijving, "
                  + lcl.xsqla('cad_thema_opmerking', 'cad_thema_key')
                  + "  FROM CAD_THEMA "
                  + " WHERE BITAND(CAD_THEMA_TYPE, " + bitcode + ") = " + bitcode
                  + "   AND BITAND(CAD_THEMA_TYPE, 4) = " + scenariobit
                  + "   AND BITAND(CAD_THEMA_TYPE, 24) = 8"  //8+0=werkplekken
                  + "   AND (FAC_FUNCTIE_KEY IS NULL"
                  + "       OR FAC_FUNCTIE_KEY IN "
                  + "               (SELECT FAC_FUNCTIE_KEY FROM fac_v_webgebruiker"
                  + "                  WHERE prs_perslid_key = " + user_key + "))"
                  + " ORDER BY 2";

              FCLTselector("sThemaIn3", sql,
                      { emptyOption: L("lcl_fg_nowthema"),
                        titleCol: "cad_thema_opmerking",
                        onChange: "sThemeChanged(this)"
                      }); %>
            </td>
          </tr>
<%

       }

%>
        </table>
      </div>
      <div id="fgmenutoggler" class='toggler' onClick="toggleLayout(this)" title='<%=L("lcl_toggler")%>'>
      </div>


      <!-- =======================================
        De themalegenda's worden dynamisch gevuld
      ============================================ -->
      <div id="legendCell" class="legendCell" style="display:none">
        <div id="titel" data-toggle="collapse" data-target=".collapsible_legend"><%=L("lcl_fg_legenda")%></div>
        <span class="collapsible_legend show legendtitle" id="legend1"></span>
        <div id="fLegenda1" class="collapsible_legend show" style='overflow-y:visible;overflow-x:hidden;'>
        <% /* Gevuld in Ajax.Updater/Legenda.asp */ %>
        </div>
<%
       if (S("fg_ins_symbols"))
       {
%>
        <div  class="collapsible_legend show" id="flegendaseparator"></div>
        <span class="collapsible_legend show legendtitle" id="legend2"></span>
        <div id="fLegenda2" class="collapsible_legend show" style='overflow-y:visible;overflow-x:hidden;'>
        <% /* Gevuld in Ajax.Updater/Legenda.asp */ %>
        </div>
<%
       }
%>
      </div>

      <!-- ==========================
           HET plaatje
      ============================ -->
      <div id = 'mapCell'>
        <iframe id="MMap" name="MMap" src="../SlnkDWF/ToonIMG.asp?ShowButtons=1&ShowLabelMenu=1"
            frameborder='0' framespacing='0' scrolling='no'
            onLoad='init(true);'
            width="<%=concept? 49 : 100%>%" height="100%">
        </iframe>
<%      if (concept)
        { %>
             <iframe id="MMap2" name="MMap2" src="../SlnkDWF/ToonIMG.asp?ShowButtons=1&ShowLabelMenu=1&concept=1"
                 frameborder='0' framespacing='0' scrolling='no'
                 onLoad='init();'
                 width="49%" height="100%" style="border-left:4px solid #808080">
             </iframe>
<%      } %>
      </div>
      <div id="fgtabtoggler" class='toggler' onClick="toggleTabLayout(this)" title='<%=L("lcl_toggler")%>'><%=I("fa-caret-down", { fastyle: "fas" })%></div>

<%
    if (scenario_key > 0)
    {
        AddTabItem(L("lcl_room"),                 'PRJ7',   'WEB_PRJBOF', '', "../prj/rap_prj7.asp", 'fa-border-all');
        //AddTabItem(L("lcl_prj_workplacecontrol"), 'PRJ1',   'WEB_PRJBOF', '', "../prj/rap_prj3.asp", 'fa-list');
        //AddTabItem(L("lcl_prj_prsbuffer"),        'PRJ6',   'WEB_PRJBOF', '', "../prj/rap_prj6.asp", 'fa-list');
        AddTabItem(L("lcl_prj_objbuffer"),        'PRJ5',   'WEB_PRJBOF', '', "../prj/rap_prj5.asp", 'fa-list');
        //AddTabItem(L("lcl_prj_persons"),          'PRJ9',   'WEB_INSMAN', '', "../prj/rap_prj9.asp", 'fa-users');
        AddTabItem(L("lcl_prj_scenario_notes"),   'PRJ8',   'WEB_PRJBOF', '', "../prj/rap_prj8.asp", 'fa-sticky-note');
        AddTabItem(L("lcl_fg_labels"),            'CAL',   'WEB_PRSBOF', '', "rap_thema.asp?listlabels=1", 'fa-tag');
        AddTabItem(L("lcl_fg_thema"),             'CAT',   'WEB_PRSBOF', '', "rap_thema.asp", 'fa-list');
    }
    else if (inoutMode == MODE_IN)
    {
        if (concept)
            AddTabItem(L("lcl_space_manage_h"),   'ALG',   'WEB_CADBOF', '', S("fg_rap_algc"), 'fa-list');
        else
        {
            AddTabItem(L("lcl_space_manage_h"),   'ALG',   'WEB_CADALG', '', S("fg_rap_alg"), 'fa-border-all');
            AddTabItem(L("lcl_search_pers"),      'PRS',   'WEB_CADPRS', '', S("fg_rap_prs"), 'fa-users');
            AddTabItem(L("lcl_objmanagment_h"),   'INS',   'WEB_CADOBJ', '', S("fg_rap_ins"), 'fa-cubes');
            AddTabItem(L("lcl_cleaning_h"),       'SCH',   'WEB_CADSCH', '', S("fg_rap_sch"), 'fa-list');
            AddTabItem(L("lcl_complains"),        'MLD',   'WEB_CADMLD', '', S("fg_rap_mld"), 'fa-tools');
            AddTabItem(L("lcl_sle_toegang"),      'SLE',   'WEB_CADSLE', '', S("fg_rap_sle"), 'fa-key');
            AddTabItem(L("lcl_cnt_contracts"),    'CNT',   'WEB_CADCNT', '', S("fg_rap_cnt"), 'fa-file-certificate');
            AddTabItem(L("lcl_fg_verhuizing"),    'MOV',   'WEB_PRSBOF', '', S("fg_rap_mov"), 'fa-person-dolly', true);
            AddTabItem(L("lcl_fg_labels"),        'CAL',   'WEB_PRSBOF', '', "rap_thema.asp?listlabels=1", 'fa-tag');
            AddTabItem(L("lcl_fg_thema"),         'CAT',   'WEB_PRSBOF', '', "rap_thema.asp", 'fa-list');
            if (S("fg_ins_symbols"))
            {
              AddTabItem(L("lcl_fg_consistentie"),  'MO2',   'WEB_CADOBJ', '', "../cad/rap_insXY.asp", 'fa-siren-on');
            }
        }
    }
    else // inoutMode == MODE_OUT
    {
        AddTabItem(L("lcl_terra_manage_h"),   'ALG2',  'WEB_CADALG', 'WEB_ALGMAN', S("fg_rap_alg2"), 'fa-list');
        AddTabItem(L("lcl_objmanagment_h"),   'INS2',  'WEB_CADOBJ', 'WEB_INSMAN', S("fg_rap_ins2"), 'fa-cubes');
        AddTabItem(L("lcl_cnt_contracts"),    'CNT',   'WEB_CADCNT', 'WEB_CNTUSE', S("fg_rap_cnt2"), 'fa-file-certificate'); // Stelling: Als je WEB_CNTMAN rechten hebt moet je ook dezelfde WEB_CNTUSE rechten hebben/krijgen.
        //AddTabItem(L("lcl_fg_labels"),            'CAL',   'WEB_PRSBOF', '', "rap_thema.asp?listlabels=1", 'fa-tag');
        //AddTabItem(L("lcl_fg_thema"),             'CAT',   'WEB_PRSBOF', '', "rap_thema.asp", 'fa-list');
    }
%>
        <!-- ==========================
             RAPPORT DEEL
        ============================ -->
        <div id='theTabs' class='frametabs ui-tabs ui-widget ui-widget-content ui-corner-all'>
            <% var nrTabs = CreateTabs();
               if (!nrTabs) {
             %>
                <script>$(function () { toggleTabLayout(document.getElementById("fgtabtoggler")) });</script>
            <% } %>
        </div>
  </body>
</html>
<% ASPPAGE_END(); %>
