/*
     $Revision$
     $Id$
*/

function checkInput(evt)
{
  evt = evt || window.event;
  var obj_evt = evt.srcElement || evt.target;
  var obj = $("#"+ obj_evt.id);

  checkInputChk(obj, false);
}

function checkInputChk(obj, submitting)
{
  var new_val = obj.val(); //value;
  var sk_kenmerktype = obj.attr("value1");
  var sk_nmin = parseInt(obj.attr("value3"),10);
  var sk_nmax = parseInt(obj.attr("value4"),10);

  if (sk_kenmerktype == 'N')
  {
    if( new_val == "" || new_val >= 0 || (!isNaN(new_val) && isGoodNumber(new_val,true,true,-1,-1) &&
        parseInt(new_val,10) >= 0 ))
    {
      i = obj.attr("id").substring(3);
      last_value = parseInt($("#last_val"+i).val(),10);
      if( new_val == "" ) new_val = last_value;
      if( new_val < last_value && !submitting )
      {
          FcltMgr.alert(L("lcl_ins_value_to_low"),
                        { fnafterclose: function() {obj.focus();}
                        }
                       );
          return false;
      }
      else if( !isNaN(sk_nmin) && new_val < sk_nmin && !submitting)
      {
          FcltMgr.alert(L("lcl_ins_value_below_nmin"),
                        { fnafterclose: function() {obj.focus();}
                        }
                       );
          return false;
      }
      else if( !isNaN(sk_nmax) && new_val > sk_nmax && !submitting)
      {
          FcltMgr.alert(L("lcl_ins_value_below_nmax"),
                        { fnafterclose: function() {obj.focus();}
                        }
                       );
          return false;
      }
      return true;
    }
    else
    {
        if (!submitting)
        {
            FcltMgr.alert(L("lcl_ins_bad_value"),
                            { fnafterclose: function() {obj.focus();}
                            }
                         );
            return false;
        }
    }
  }
  else
  {
    // yet, only numerical kenmerktypes are supported
    // FcltMgr.alert(L("lcl_obj_only_num"));
    obj.val("");
  }
}
