/*
     $Revision$
     $Id$

     File:        fin_show_factuur.js
*/
function fin_change(fin_status)
{
  FcltMgr.confirm(L("lcl_fin_approve_again"), { autoconfirm: fin_status != 6 }, function() {
    if (FcltMgr.startEdit(window))
      window.location.href = "../fin/fin_edit_factuur.asp?fin_key=" + fin_key + "&embedded=1";
  });
}

function fin_print()
{
  window.open('./fin_xml.asp?fin_key=' + fin_key);
}

function finMailCallback(data)
{
  FcltMgr.alert(L("lcl_fin_inv_mailed") + data.emails);
}

function fin_approve()
{
  FcltMgr.confirm(L("lcl_fin_approve_factuur").format(fin_key), function() {
      // Goedkeuren scherm
      var data = {
          fin_key: fin_key
      };
      protectRequest.dataToken(data);
      $.post("fin_approve.asp?a=1",
          data,
          FcltCallbackRefresh,
          "json");
  });
}

function fin_goedkeuren()
{
  FcltMgr.confirm(L("lcl_fin_goedkeuren_factuur").format(fin_key), function() {
      var data = {
          fin_key: fin_key
      };
      protectRequest.dataToken(data);
      $.post("fin_goedkeur.asp?a=1",
          data,
          FcltCallbackRefresh,
          "json");
  });
}

function fin_unapprove()
{
  FcltMgr.confirm(L("lcl_fin_unapprove_factuur").format(fin_key), function() {
      var data = {
          fin_key: fin_key
      };
      protectRequest.dataToken(data);
      $.post("fin_unapprove.asp",
          data,
          FcltCallbackRefresh,
          "json");
  });
}

function fin_reject(mode)
{
  FcltMgr.confirm(L("lcl_fin_reject_factuur").format(fin_key), function() {
      var data = {
          fin_key: fin_key
      };
      protectRequest.dataToken(data);
      $.post((mode == "F" ? "fin_approve.asp?r=1" : "fin_goedkeur.asp?r=1"), // Afwijzen bij het Fiatteren(F) of Goedkeuren(G).
          data,
          FcltCallbackRefresh,
          "json");
  });
}

function fin_unreject()
{
  FcltMgr.confirm(L("lcl_fin_unreject_factuur").format(fin_key), function() {
      // Goedkeuren scherm
      var data = {
          fin_key: fin_key
      };
      protectRequest.dataToken(data);
      $.post("fin_unreject.asp",
          data,
          FcltCallbackRefresh,
          "json");
  });
}

function fin_delete()
{
    FcltMgr.confirm(L("lcl_fin_delete_factuur").format(fin_key), function() {
        var data = {
            fin_key: fin_key
        };
        protectRequest.dataToken(data);
        $.post("fin_delete.asp",
            data,
            FcltCallbackClose,
            "json");
    });
}

function fin_copy()
{
  url = "appl/FIN/fin_factuur.asp?fin_key=" + fin_key + "&fin_copy=1";
  FcltMgr.openDetail(url, L("lcl_fin_copy") + ' ' + L("lcl_fin_invoice"));
}
