/*
     $Revision$
     $Id$

     File:        cnt_list.js
*/
function cntEdit(row)
{
  $(row).addClass('dirty');
  var cnt_key = row.getAttribute("ROWKEY");

  url = "appl/cnt/cnt_contract.asp?cnt_key=" + cnt_key + "&urole=" + urole;
  FcltMgr.openDetail(url);
}

function reloadList(json, textStatus)
{
  if (parent.document.body.id === "searchbody") {
    // liefst doe ik FcltMgr.reload maar dit is een POST form. Dat komt niet over.
    parent.document.forms.u2.submit();
  } else { // Subtabjes gaan wel via een GET (en kunnen dus FcltMgr.reload gebruiken)
    FcltMgr.reload();
  }
}

function cntForApproval(rowArray, isMulti)
{
  var cntData = JSON.parse(rowArray[0].getAttribute("ROWDATA"));
  FcltMgr.confirm(L("lcl_cnt_forward_forapproval").format(cntData.cntNummerIntern), { autoconfirm: isMulti }, function() {
      var cntKeyString = getKeyString(rowArray);
      var data = { cnt_key: cntKeyString };
      protectRequest.dataToken(data);
      $.post("../cnt/cnt_forapproval.asp",
          data,
          FcltCallbackAndThen(reloadList),
          "json");
  });
}

function cntSplit(rowArray, isMulti)
{
  cnt_key_arr = getKeyString(rowArray);
  var subject = L("lcl_cnt_newversion");
  var url = "cnt_split.asp?cnt_key=" + cnt_key_arr;
  FcltMgr.openModalDetail(url, subject, { width:500, height: 360, callback: function() { return reloadList(); } });
}

function cntClose(rowArray, isMulti)
{
  var cntData = JSON.parse(rowArray[0].getAttribute("ROWDATA"));
  FcltMgr.confirm(L("lcl_cnt_inactivate_upd").format(cntData.cntNummerIntern),
                  { autoconfirm: isMulti },
                  function()
                  {
                    var cntKeyString = getKeyString(rowArray);
                    var data = { cnt_key: cntKeyString };
                    protectRequest.dataToken(data);
                    $.post("../cnt/cnt_inactivate.asp",
                           data,
                           FcltCallbackAndThen(reloadList),
                           "json");
                  });
}

function cntKenmerk(rowArray, isMulti)
{
  var cntKeyString = getKeyString(rowArray);
  var confirmstr = ( rowArray.length == 1
                   ? L("lcl_shared_doaction1").format(L("lcl_properties"))
                   : L("lcl_shared_doaction").format(L("lcl_properties"),rowArray.length)
                   );
  FcltMgr.confirm( confirmstr
                 , { autoconfirm: isMulti }
                 , function()
                   {
                     var cntUrl = "../cnt/cnt_edit_kenmerk_multi.asp?urole=" + urole + "&cnt_key=" + cntKeyString;
                     FcltMgr.openModalDetail( cntUrl,
                                              L("lcl_multiedit_kenmerk"),
                                              { callback: function(json) { FcltCallbackAndThen(reloadList(json)); } }
                                            );
                   }
                 );
}