/*
     $Revision$
     $Id$
*/

async function sle_submit()
{
  document.activeElement.blur(); // trigger laatste onChanges
  if (!await validateForm("u2"))
    return false;

  if ($("#sel_items").length && !$("#roomArray").length)
  {
    if (sle_cil_koppelen == 0)
      FcltMgr.alert(L("lcl_sle_select_ruimte"));
    else
      FcltMgr.confirm(L("lcl_sle_add_no_cil"),
                      {}, //{ autoconfirm: isMulti },
                      function() {
                                   window.document.forms.u2.submit();
                                   return true;
                                 });

    return;
  }
  else
    document.forms.u2.submit();
}

function sle_cancel()
{
  FcltMgr.closeDetail(window, { cancel: true } );
}

function AddItem()
{
  var room_key = $("#ruimtekey").val();
  if (room_key <= 0)
  {
    FcltMgr.alert(L("lcl_sle_no_ruimte"));
    return;
  }

  // Indien al in de lijst toegevoegd, dan return
  if ($("input#roomArray[value="+room_key+"]").length)
    return false;

  var room_name = $("#locatie").val() + " - "
                + $("#gebouw").val() + " - "
                + $("#verdieping").val() + " - "
                + $("#alg_ruimte_nr").val();

  CreateRow(room_key, room_name);
}

function CreateRow(room_key, room_name)
{
  // Create drop button
  // tr class sleroom om in sleClose gemakkelijk op te ruimen
  var tr = "<tr class='sleroom'>"
         + "  <td class='result' align='center'>"
         + "    <span class='default-clickable-icon' OnClick='CancelRoom(this)'>" + I("fa-trash-alt") + "</span>"
         + "  </td>"
         + "  <td class='result' align='left'>"
         + "    <input type='hidden' name='roomArray' id='roomArray' value='" + room_key + "'>" + safe.html(room_name)
         + "  </td>"
         + "</tr>";

  $("#sel_items").append(tr);
}
function CancelRoom(cell)
{
  $(cell).closest("tr").remove();
  FcltMgr.resized(window);
}

