/*
     $Revision$
     $Id$

     File:        opdr_list.js

*/
function opdr_edit(row, finish)
{
  var opdr_key = row.getAttribute("ROWKEY");
  var url = "appl/mld/mld_opdr.asp?urole=" + urole + "&opdr_key=" + opdr_key + "&finish=" + (finish? 1 : 0);
  FcltMgr.openDetail(url, { reuse: true });
}

function opdr_copy(row)
{
  var opdr_key = row.getAttribute("ROWKEY");
  var mldData = eval("(" + row.getAttribute("ROWDATA") + ")");
  if (mldData)
  {
    var mldKey = mldData.mldKey;
    var mldPrefix = mldData.mldPrefix;
    var mldVolgnr = mldData.mldVolgnr;
    var url = "appl/mld/mld_opdr.asp?urole=" + urole + "&opdr_key=" + opdr_key + "&opdr_copy=1";
    FcltMgr.openDetail(url, L("lcl_mld_copy") + " " + L("lcl_shared_order") + " " + mldPrefix + mldKey + "/" + mldVolgnr);
  }
}

function opdr_close_one(row)
{
    opdr_close([row]);
}

function opdr_close(rowArray, isMulti)
{
  var opdrKeyString = getKeyString(rowArray);
  var url = "../mld/opdr_close_confirm.asp?opdr_key=" + opdrKeyString;
  FcltMgr.openModalDetail(url, L("lcl_mld_opdr_close"), { callback: opdrCloseCallback });
}

function opdr_accept(rowArray, isMulti)
{
  var opdrKeyString = getKeyString(rowArray);
  var data = { opdr_key: opdrKeyString };
  protectRequest.dataToken(data);  
  $.post("../mld/opdr_accept.asp",
         data,
         FcltCallbackRefresh,
         "json");
}

function opdr_finish(rowArray, isMulti)
{
  var opdrKeyString = getKeyString(rowArray);
  if (rowArray.length == 1)
    opdr_edit(rowArray[0], true);
  else
  { // Multi
    var data = { opdr_key: opdrKeyString };
    protectRequest.dataToken(data);
    $.post("../mld/opdr_finish.asp",
           data,
           FcltCallbackRefresh,
           "json");
  }
}

function opdr_add_invoice(row)
{
  var opdr_key = row.getAttribute("ROWKEY");
  var mldData = eval("(" + row.getAttribute("ROWDATA") + ")");
  if (mldData)
  {
    var mldKey = mldData.mldKey;
    var mldPrefix = mldData.mldPrefix;
    var mldVolgnr = mldData.mldVolgnr;
    var url = "appl/fin/fin_factuur.asp?referentie=" + mldPrefix + mldKey + "/" + mldVolgnr;
    FcltMgr.openDetail(url, (urole == "fe"? L("lcl_menu_fin_fe") : L("lcl_menu_fin_fo")));
  }
}

function opdr_list_invoice(row)
{
  var opdr_key = row.getAttribute("ROWKEY");
  var mldData = eval("(" + row.getAttribute("ROWDATA") + ")");
  if (mldData)
  {
    var mldKey = mldData.mldKey;
    var mldPrefix = mldData.mldPrefix;
    var mldVolgnr = mldData.mldVolgnr;
    var url = "appl/fin/fin_search.asp?autosearch=1&fin_type=O&opdrnr=" + mldPrefix + mldKey + "/" + mldVolgnr;
    FcltMgr.openDetail(url, (urole == "fe"? L("lcl_menu_fin_fe_overz") : L("lcl_menu_fin_fo_overz")));
  }
}
