/*
     $Revision$
     $Id$
*/

function BI(bikey, pkey, akey)
{
   this.bikey = bikey;
   this.pkey = pkey;
   this.akey = akey;
}

function checkInput(evt)
{
  evt = evt || window.event;
  var obj = evt.srcElement || evt.target;
  var val = obj.value.replace(",", ".");
  var valid = true;
  var error = "";

  var i = obj.id.substring(3);
  var remaining = parseFloat(document.getElementById('rem'+i).value.replace(",", "."));
  if (val == "" || val == 0 ||
      (!isNaN(val) && isGoodNumber(val, false, false, -1, -1) &&
       ((remaining > 0 && parseFloat(val) >= 0) || (remaining < 0 && parseFloat(val) <= 0))))
  {
    if (val == "") val = 0;
    valid = !((remaining > 0 && val > remaining) || (remaining < 0 && val < remaining));
    error = L("lcl_bes_exceed_value");
    if (!isRetour && valid && ins_mode > 0 && ins_srtdeel_key > 0)
    {
      var instock = parseFloat($("#instock" + i).val());
      var delivered = parseFloat($("#cnt" + i).val()) || 0;
      var retour = instock < 0 || delivered < 0;
      var itemeenh = $("#itemeenh" + i).val();
      if (retour)
      {
        valid = instock <= delivered;
        error = L("lcl_bes_insuf_return").format((instock * -1) + " " + itemeenh);
      }
      else
      {
        valid = instock >= delivered;
        error = L("lcl_bes_insuf_instock").format(instock + " " + itemeenh);
      }
    }
    else if (!isRetour && valid && ins_mode > 0 && ins_srtdeel_key < 0)
    { // Zou niet voor moeten komen.
      valid = false;
      error = L("lcl_bes_notlinkedto_obj_type");
      iface.button.disable("btn_delivery_submit"); // Disable de "Opslaan" button.
    }
  }
  else
  {
    error = L("lcl_bes_bad_value");
    valid = false;
  }
  validateField(obj, valid, error);
  return valid;
}

function complete()
{
 var cnt = document.u2.max_o_i.value;
 for (i = 0; i < cnt; i ++)
 {
   rem_value = document.u2['rem'+i].value;
   document.u2['cnt'+i].value = rem_value;
 }
}
