﻿function xFormElementRestriction(element) {
  if (!(element instanceof xForm) &&
      !(element instanceof xFormElement) &&
      !(element instanceof xFormElementGroup)) {
    throw new Exception('invalid argument given');
  }

  this.element = element;
  this.rmin = 0;
  this.rmax = 0;
  this.rrequired = false;
  this.rfilter = '';
  this.rcustom = null;
  this.rapply = null;

  this.parse();
}

xFormElementRestriction.prototype.parse = function() {
  for (var i = 0; i < xFormElementRestriction.attributes.length; i++) {
    var r = new String(xFormElementRestriction.attributes[i]);
    this['r' + r] = this.element.getCustomProperty(r, 'restriction');
  }
};

xFormElementRestriction.prototype.isEnabled = function() {
  return this.rapply == 'yes';
};

xFormElementRestriction.attributes = new Array('min', 'max', 'required', 'filter', 'custom', 'apply');