/*
* Copyright (c) 2008 Azeus Systems, Ltd.
* All rights reserved.
*/

<!--
/*
 *  lbjs02.js    02/01/2002
 *  Spenson Shih
 *
 *  Dependencies:
 *  1. utils.js
 *  2. number.js
 *  3. date.js
 *  4. messages.js (messages.jsp)
 *  5. strings.js (for date controls)
 *
 *  Amendment History:
 *  1.  Change performed by Andrei Felix on 25.1.2002
 *      Changed aMandatory to aNullable in procedure addItem for consistency with ISWeb BO.
 *
 *  2. Change performed by Amil Reyes on 29.1.2002
 *      Added new property _Window to TItemServer constructor to point to
 *      window object containing the TItemServer instance
 *
 *  3.  Change performed by Amil Reyes on 8.2.2002
 *      Added TItemServer.submitFake(bCheckModified).
 *       Added bNoValidation parameter to TItemServer_checkModified.
 *
 *  4.  Change performed by Andrei Felix on 14.2.2002
 *      Added TItemServer_showDMSErrors to support DMS-style js errors.
 *
 *  5.  Change performed by Amil Reyes on 2.4.2002
 *      Trims date controls before validation.
 *
 *  6.  Change performed by Spenson Shih on 19.4.2002
 *      Fixed TItem.isArray() to return false if controls is array of checkbox.
 *
 *  7.  Change performed by Amil Reyes on 23.4.2002
 *      Add TItemServer_focusFirstItem - called after IS reset and every time
 *      MSG_NO_CHANGES is displayed.
 *
 *  8.  Change perfomed by Spenson Shih on 25.4.2002
 *      Add Parent attribute in TItem to handle focus of date controls.
 *
 *  9.  Change perfomed by Spenson Shih on 25.4.2002
 *      Add checking of Child items in TItem.isModified().
 *
 *  10. Change performed by Spenson Shih on 2.5.2002
 *      Removed validateMaxLength in TItem.
 *      Modified TItem.format() not to set the value back to control for STRING data types.
 *      Modified TItemServer.reset() to call TItem.reset() for hidden fields only,
 *      and call form.reset().
 *      Auto-compute MaxValue and MinValue for Long and Double data type for TItem.
 *
 *  11. Change performed by Spenson Shih on 3.5.2002
 *      Added function isCheckbox to TItem, to return true if control is an array of checkbox.
 *      Used in TItem.validate to validate checkbox as 1 value.
 *
 *  12. Change performed by Amil Reyes 17.5.2002
 *      Added support to focus the specific control in date controls.
 *
 *  13. Change performed by Spenson Shih on 25.5.2002
 *      Added function isListBox to TItem, to return true if control is of type 'select-multiple'.
 *      Used in TItem.validate to validate list box as 1 array value.
 *
 *  14. Change performed by Spenson Shih on 30.5.2002
 *      TItemServer.isModified() always return false.
 *      Remove all checking of modified data before submission.
 *
 *  15. Change performed by Spenson Shih on 31.5.2002
 *      Fixed bug in validation of RegEx for numeric types. When user input
 *      is '+', '-', or '.' only.
 *
 *  16. Change performed by Spenson Shih on 11.6.2002
 *      Fixed TItemServer.focusFirstItem if first item is a date control.
 *
 *  17. Change performed by Spenson Shih on 25.6.2002
 *      Add setDateTimeControls() to handle Timestamp types w/ HH:mm.
 *
 *  18. Change performed by Spenson Shih on 16.8.2002
 *      TItemServer.focusFirstItem does nothing to prevent error window
 *      being minimized to background
 *
 *  19. Change performed by Spenson Shih on 19.8.2002
 *      Function _getTypeRegExp will return null for string data type to avoid
 *      netscape crash when string length is very long.  Possibly caused by
 *      javascript function's call stack overflowing in RegEx implementation.
 *
 *  20. Change performed by Spenson Shih on 5.9.2002
 *      TItem_Validator_validateNumberRange should perform validation only if
 *      value is not null.
 *
 *  21. Change performed by Spenson Shih on 12.9.2002
 *      Adjust width of error window to 310 to avoid overlap between
 *      scrollbar & error message (jabber w/ Harry).
 *
 *  22. Change performed by Spenson Shih on 7.10.2002
 *      Modify TItem.validate() to support validation of array date controls
 *      for GS3200 - Public Holidays.
 *
 *  23. Change performed by Spenson Shih on 12.10.2002
 *      Fix bug in TItem.validate(), comparison should use == rather
 *      than =.
 *
 *  24. Change performed by Spenson Shih on 17.10.2002
 *      Add call to setActionIS(null) in TItemServer constructor.
 *
 *  25. Change performed by Spenson Shih on 17.10.2002
 *      Add MSG_NON_EXISTING_DATE_DD_MM error message for date controls w/o year.
 *
 *  26. Change performed by Spenson Shih on 29.11.2002
 *      In TItem.validate(), must copy MinValue and MaxValue when creating items
 *      for array elements.
 *
 *  27. Change performed by Spenson Shih on 2.12.2002
 *      In TItem.getAsLongArray(), getAsDoubleArray(), getAsBigDecimalArray(),
 *      check if array element is null before converting to numeric value to add
 *      to element.
 *
 *  28. Change performed by Andrei Felix on 1.13.2003
 *      Modified TItem_validate(bOnline) to record the index of the item where a validation error
 *      occured for item arrays, and added the item number in the message.
 *
 *  29. Change performed by Spenson Shih on 1.21.2002
 *      Fix TItem_validateDateRange to handle null MinValue and MaxValue.
 *
 *  30. Change performed by Andrei Felix on 1.28.2003
 *      Modified TItem_validate(bOnline) to set _ControlFocusOnError to the control array.
 *
 *  31. Change performed by Spenson Shih on 2.4.2003
 *      Fix TItem.validateDateExist() to handle case where 1/1/1 is input for date but
 *      time-component is null.
 *  32. Change performed by Zhen on 10.17.2003
 *      Default Time to 9:00 AM is not given. function modified is TItem_Validator_validateDateTimeControls.
 */

var AzTypes = new Object();
AzTypes.STRING      = 0;
AzTypes.LONG        = 1;
AzTypes.DOUBLE      = 2;
AzTypes.BOOLEAN     = 3;
AzTypes.DATE        = 4;
AzTypes.TIME        = 5;
AzTypes.TIMESTAMP   = 6;
AzTypes.BIG_DECIMAL = 7;

var _dateRegExp = new Array(
   {Pattern:'MMMM', RegExpStr:'(January|February|March|April|May|June|July|Auguest|September|October|November|December)'}
 , {Pattern:'MMM', RegExpStr:'(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)'}
 , {Pattern:'MM', RegExpStr:'((0?[1-9])|(10|11|12))'}
 , {Pattern:'M', RegExpStr:'((0?[1-9])|(10|11|12))'}
 , {Pattern:'dd', RegExpStr:'(((0?[1-9])|((1|2)\\d)|(30|31)))'}
 , {Pattern:'d', RegExpStr:'(((0?[1-9])|((1|2)\\d)|(30|31)))'}
 , {Pattern:'yyyy', RegExpStr:'(\\d{4})'}
 , {Pattern:'yy', RegExpStr:'(\\d{2})'}
 , {Pattern:'HH', RegExpStr:'(((0|1)?[0-9])|(2[0-3]))'}
 , {Pattern:'mm', RegExpStr:'([0-5]?[0-9])'}
)

function _getTypeRegExp(aType, aFormat) {
  aFormat = String(aFormat);
  if (aType == AzTypes.STRING) return null; // /^(.|\f|\n|\r)*$/;
  if (aType == AzTypes.LONG) return /^(\+|-)?(\d+,)*(\d+)$/;
  if (aType == AzTypes.DOUBLE || aType == AzTypes.BIG_DECIMAL) return /^(\+|-)?((((\d+,)*(\d+))(\.\d*)?)|((\.\d+)))$/;
  if (aType == AzTypes.BOOLEAN) {
    var aBool = ['true'|'false'];
    if (aFormat != null) {
      aFormat = String(aFormat);
      aBool = aBool.concat(aFormat.split(','));
    }
    return new RegExp('^(' + aBool.join('|') + ')$', 'i');
  }
  if (aType == AzTypes.DATE || aType == AzTypes.TIME || aType == AzTypes.TIMESTAMP) {
    var sRegExp = '^';
    var i = 0;
    while (i<aFormat.length) {
      var fmt = aFormat.substring(i,aFormat.length);
      var j;
      var bFound = false;
      for (j=0; j<_dateRegExp.length; j++) {
        if (fmt.indexOf(_dateRegExp[j].Pattern) == 0) {
          sRegExp += _dateRegExp[j].RegExpStr;
          i += _dateRegExp[j].Pattern.length;
          bFound = true;
          break;
        }
      }
      if (!bFound) {
        sRegExp += aFormat.charAt(i++);
      }
    }
    sRegExp += '$';
    return new RegExp(sRegExp, 'i');
  }
  return null;
}

function _getMaxValue(aMaxLength, aDataFormat) {
  var i;
  var s = "";
  for (i=0; i<aMaxLength; i++) {
    s = s + '9';
  }

  var n = aDataFormat.search(/\.0*/);
  n = aDataFormat.substring(n).length - 1;
  if (n > 0) {
    s = s + '.';
    for (i=0; i<n; i++) {
      s = s + '9';
    }
  }
  return String(s);
}

/*
 * class TItem
 */
function TItem(aName, aControl, aType, aFormat, aLength, aMandatory, aDescription, aTemp) {
  this.ValidationEnabled=true;
  this.Name = aName;

  this.Control = aControl;
  this.Control.setValue = TItem_Control_setValue;
  this.Control.getValue = TItem_Control_getValue;
  this.Control.clear = TItem_Control_clear;

  this.Type = aType;

  this.MaxLength = aLength;
  if (this.Type == AzTypes.LONG && this.MaxLength > 0) {
    this.MaxValue = Math.pow(10, this.MaxLength) - 1;
    this.MinValue = -1 * this.MaxValue;
  } else if (this.Type == AzTypes.DOUBLE && this.MaxLength > 0) {
    this.MaxValue = Number(_getMaxValue(this.MaxLength, aFormat));
    this.MinValue = -1 * this.MaxValue;
  } else if (this.Type == AzTypes.BIG_DECIMAL && this.MaxLength > 0) {
    this.MaxValue = new BigDecimal(_getMaxValue(this.MaxLength, aFormat));
    this.MinValue = this.MaxValue.negate();
  } else {
    this.MaxValue = Number.POSITIVE_INFINITY;
    this.MinValue = Number.NEGATIVE_INFINITY;
  }

  this.Mandatory = aMandatory;
  this.Description = aDescription;
  this._OnlineValidators = [TItem_Validator_validateRegEx];
  this._Validators = [TItem_Validator_validateMandatory, TItem_Validator_validateRegEx];
  this.DataFormat = aFormat;
  this._RegEx = _getTypeRegExp(this.Type, this.DataFormat);
  if (this.Type == AzTypes.LONG || this.Type == AzTypes.DOUBLE || this.Type == AzTypes.BIG_DECIMAL) {
    this.addValidator(TItem_Validator_validateTrim, false, 0);
    this.addValidator(TItem_Validator_validateNumberRange, false);
  } else if (this.Type == AzTypes.DATE) {
    this.addValidator(TItem_Validator_validateDateRange, false);
  } else if (this.Type == AzTypes.STRING) {
    this.addValidator(TItem_Validator_validateMaxLength, false);
  }

  this.Child = new Object();
  this.Owner = null;
  this.Parent = null;
  this._ControlFocus = this.Control;

  if (!aTemp) {
    if (this.isArray())
      this.setInitValue(this.getAsStringArray());
    else
     this.setInitValue(this.getAsString());
  }

  return this;
}

TItem.prototype.addValidator = TItem_addValidator;
TItem.prototype.validate = TItem_validate;
TItem.prototype.validateOnline = TItem_validateOnline;

TItem.prototype.setValue = TItem_setValue;
TItem.prototype.setInitValue = TItem_setInitValue;
TItem.prototype.clear = TItem_clear;
TItem.prototype.reset = TItem_reset;
TItem.prototype.format = TItem_format;
TItem.prototype.isModified = TItem_isModified;
TItem.prototype.equals = TItem_equals;

TItem.prototype.getValue = TItem_getValue;
TItem.prototype.getAsObject = TItem_getAsObject;
TItem.prototype.getAsString = TItem_getAsString;
TItem.prototype.getAsLong = TItem_getAsLong;
TItem.prototype.getAsDouble = TItem_getAsDouble;
TItem.prototype.getAsBoolean = TItem_getAsBoolean;
TItem.prototype.getAsDate = TItem_getAsDate;
TItem.prototype.getAsTime = TItem_getAsTime;
TItem.prototype.getAsTimestamp = TItem_getAsTimestamp;
TItem.prototype.getAsBigDecimal = TItem_getAsBigDecimal;

TItem.prototype.isNull = TItem_isNull;
TItem.prototype.focus = TItem_focus;

TItem.prototype.setDateControls = TItem_setDateControls;
TItem.prototype.setDateTimeControls = TItem_setDateTimeControls;

TItem.prototype.isCheckbox = TItem_isCheckbox;
TItem.prototype.isListBox = TItem_isListBox;
TItem.prototype.isArray = TItem_isArray;
TItem.prototype.getAsObjectArray = TItem_getAsObjectArray;
TItem.prototype.getAsStringArray = TItem_getAsStringArray;
TItem.prototype.getAsLongArray = TItem_getAsLongArray;
TItem.prototype.getAsDoubleArray = TItem_getAsDoubleArray;
TItem.prototype.getAsBooleanArray = TItem_getAsBooleanArray;
TItem.prototype.getAsDateArray = TItem_getAsDateArray;
TItem.prototype.getAsTimeArray = TItem_getAsTimeArray;
TItem.prototype.getAsTimestampArray = TItem_getAsTimestampArray;
TItem.prototype.getAsBigDecimalArray = TItem_getAsBigDecimalArray;

// events
TItem.prototype.BeforeValidate = null;
TItem.prototype.AfterValidate = null;

TItem.prototype.showError = TItem_showError;

TItem.prototype.setValidationEnabled = TItem_setValidationEnabled;


function TItem_setValidationEnabled(aValue){
  this.ValidationEnabled=aValue;
}

function TItem_addValidator(fValidator, bOnline, nIndex) {
  if (fValidator != null && fValidator.constructor == Function) {
    nIndex2 = nIndex;
    if (nIndex == null || isNaN(Number(nIndex))) nIndex2 = this._OnlineValidators.length;
    if (bOnline) {
      this._OnlineValidators.splice(nIndex2, 0, fValidator);
    }
    if (nIndex == null || isNaN(Number(nIndex))) nIndex2 = this._Validators.length;
    this._Validators.splice(nIndex2, 0, fValidator);
    return fValidator;
  }
  return null;
}

function TItem_isCheckbox() {
  return (this.Control && this.Control[0] && this.Control[0].type == 'checkbox');
}

function TItem_isListBox() {
  return (this.Control && this.Control.type && this.Control.type == 'select-multiple');
}

function appendItemNumber(is, item_no) {
  if (isNaN(item_no)) return;
  if (is != null && is.ErrorMsg.length > 0) {
    // some validators like the date control validator appends its own item number
    if (is.ErrorMsg[is.ErrorMsg.length - 1].message.indexOf(' (Item ') == -1)
      is.ErrorMsg[is.ErrorMsg.length - 1].message += ' (Item ' + item_no + ')';
  }
}

function TItem_validate(bOnline) {
  var i;
  if (!this.ValidationEnabled) return true;
  if (this.BeforeValidate) this.BeforeValidate();
  //if (!this.isModified()) return true;
  var validators = this._Validators;
  if (bOnline) validators = this._OnlineValidators;
  this._ERR_INDEX = -1;

  for (i=0; i<validators.length; i++) {
    if (this.isArray() && !this.isCheckbox() && !this.isListBox()) {
      var j;
      var array_no_err = true;
      for (j=0; j<this.Control.length; j++) {
        var di = new TItem(this.Name, this.Control[j], this.Type, this.DataFormat, this.MaxLength, this.Mandatory, this.Description, true);
        di.MinValue = this.MinValue;
        di.MaxValue = this.MaxValue;
        di.Owner = this.Owner;
        // copy Child items from parent
        if (this.Type == AzTypes.DATE) {
          di._INDEX = j;
          di.setDateControls(this.Child['DAY'].Control[j], this.Child['MONTH'].Control[j], this.Child['YEAR'].Control[j]);
        }
        else this._ControlFocusOnError = this.Control;
        if (!validators[i](di)) {
          if (this._ERR_INDEX == -1) this._ERR_INDEX = j;
          appendItemNumber(this.Owner, j + 1);
          if (this.AfterValidate) this.AfterValidate(false);
          array_no_err = false;
        }
      }
      if (!array_no_err) return false;
    } else if (!validators[i](this)) {
      if (this.AfterValidate) this.AfterValidate(false);
      return false;
    }
  }
  if (this.AfterValidate) this.AfterValidate(true);
  this.format();
  return true;
}

function TItem_validateOnline() {
  return this.validate(true);
}

function TItem_setValue(aValue) {
  if (aValue == null) {
    this.clear();
    return aValue;
  }
  var sFormattedVal;
  if (aValue.constructor == Array) {
    sFormattedVal = aValue;
    var i;
    for (i=0; i<aValue.length; i++) {
      sFormattedVal[i] = Util.format(aValue[i], this.DataFormat);
    }
  } else {
    sFormattedVal = Util.format(aValue, this.DataFormat);
  }
  this.Control.setValue(sFormattedVal);
  var obj = this.getAsObject();
  if (this.Child['DAY']) this.Child['DAY'].setValue(obj);
  if (this.Child['MONTH']) this.Child['MONTH'].setValue(obj);
  if (this.Child['YEAR']) this.Child['YEAR'].setValue(obj);
  if (this.Child['HOUR']) this.Child['HOUR'].setValue(obj);
  if (this.Child['MIN']) this.Child['MIN'].setValue(obj);
  return aValue;
}

function TItem_setInitValue(aValue) {
  if (this.Type != AzTypes.STRING)
    this.setValue(aValue, true);
  if (this.isArray())
    this._InitValue = this.getAsStringArray();
  else
    this._InitValue = this.getAsString();
}

function TItem_format() {
  if (this.isNull()) return;
  var obj;
  var sFormattedVal;
  if (this.isArray()) {
    obj = this.getAsObjectArray();
    var i;
    for (i=0; i<obj.length; i++) {
      obj[i] = Util.format(obj[i], this.DataFormat);
    }
    sFormattedVal = obj;
  } else {
    obj = this.getAsObject();
    sFormattedVal = Util.format(obj, this.DataFormat);
  }
  if (this.Type != AzTypes.STRING)
    this.Control.setValue(sFormattedVal);
}

function TItem_clear() {
  this.Control.clear();
  if (this.Child['DAY']) this.Child['DAY'].clear();
  if (this.Child['MONTH']) this.Child['MONTH'].clear();
  if (this.Child['YEAR']) this.Child['YEAR'].clear();
  if (this.Child['HOUR']) this.Child['HOUR'].clear();
  if (this.Child['MIN']) this.Child['MIN'].clear();
}

function TItem_reset() {
  this.setValue(this._InitValue);
}

function TItem_equals(obj) {
  if (this.isArray()) {
    if (isArray(obj)) {
      obj = String(Util.format(obj, this.DataFormat));
      var o = String(this.getAsStringArray());
      return String(obj) == String(this.getAsStringArray());
    }
    if (obj == null) {
      var b = true;
      var i;
      var o = this.getAsObjectArray();
      for (i=0; i<o.length; i++) {
        b = b && (o[i] == null || o[i] == '');
      }
      return b;
    }
    return false;
  } else {
    var o = Util.format(obj, this.DataFormat);
    var o2 = this.getAsString();
    return String(o) == String(o2);
  }
}

function TItem_isModified() {
  //if (this.isNull()) return (this._InitValue != null || this._InitValue != '');
  var b = (!this.equals(this._InitValue));
  for (c in this.Child) {
    b = b || this.Child[c].isModified();
  }
  return b;
}

function TItem_getValue() {
  return getControlValue(this.Control);
}

function TItem_getAsString() {
  var val = this.getValue();
  if (isArray(val)) val = val[0];
  var sValue = Util.format(val, this.DataFormat);
  return String(sValue);
}

function TItem_getAsLong() {
  if (this.isNull()) return 0;
  var val = this.getValue();
  if (isArray(val)) val = val[0];
  var sValue = Util.cleanNumberString(val);
  return Math.floor(Number(sValue));
}

function TItem_getAsDouble() {
  if (this.isNull()) return 0;
  var val = this.getValue();
  if (isArray(val)) val = val[0];
  var sValue = Util.cleanNumberString(val);
  return Number(sValue);
}

function TItem_getAsBoolean() {
  if (this.isNull()) return false;
  var val = this.getValue();
  if (isArray(val)) val = val[0];
  var b = Util.StringToBoolean(val, this.DataFormat);
  return Boolean(b);
}

function TItem_getAsDate() {
  if (this.isNull()) return new Date(0);
  var val = this.getValue();
  if (isArray(val)) val = val[0];
  var sValue = val;
  var dt = Util.StringToDate(sValue, this.DataFormat);
  if (dt == null) return null;
  var n = dt.getTime();
  dt = new Date(n - n % 360000);
  return dt;
}

function TItem_getAsTime() {
  if (this.isNull()) return new Date(0);
  var val = this.getValue();
  if (isArray(val)) val = val[0];
  var sValue = val;
  var dt = Util.StringToDate(sValue, this.DataFormat);
  if (dt == null) return null;
  var n = dt.getTime();
  dt = new Date(n % 86400000);
  return dt;
}

function TItem_getAsTimestamp() {
  if (this.isNull()) return new Date(0);
  var val = this.getValue();
  if (isArray(val)) val = val[0];
  var sValue = val;
  return Util.StringToDate(sValue, this.DataFormat);
}

function TItem_getAsBigDecimal() {
  if (this.isNull()) return new BigDecimal('0.0');
  var val = this.getValue();
  if (isArray(val)) val = val[0];
  var sValue = val;
  return Util.StringToBigDecimal(sValue, this.DataFormat);
}

function TItem_getAsObject() {
  if (this.isNull()) return null;
  if (this.Type == AzTypes.STRING) return this.getAsString();
  if (this.Type == AzTypes.LONG) return this.getAsLong();
  if (this.Type == AzTypes.DOUBLE) return this.getAsDouble();
  if (this.Type == AzTypes.DATE) return this.getAsDate();
  if (this.Type == AzTypes.TIME) return this.getAsTime();
  if (this.Type == AzTypes.TIMESTAMP) return this.getAsTimestamp();
  if (this.Type == AzTypes.BOOLEAN) return this.getAsBoolean();
  if (this.Type == AzTypes.BIG_DECIMAL) return this.getAsBigDecimal();
  return null;
}

function TItem_isNull() {
  var val = this.getValue();
  if (val == null) return true;
  if (String(val).trimWS() == '') return true;
  if (val.constructor == Array) {
    if (val.length == 0) return true;
    var i;
    var bNull = true;
    for (i=0; i<val.length; i++)
      bNull = bNull && (val[i] == null || val[i] == '' || String(val[i]).trimWS() == '');
    return bNull;
  }
  return (val == '');
}

function TItem_focus(bSelect) {
  if (bSelect != false) bSelect = true;
  if (!this._ControlFocus) return;
  if (isControlArray(this._ControlFocus)) {
    if (this._ControlFocus[0].focus) this._ControlFocus[0].focus();
    if (bSelect && this._ControlFocus[0].select) this._ControlFocus[0].select();
  } else {
    if (this._ControlFocus.focus) this._ControlFocus.focus();
    if (bSelect && this._ControlFocus.select) this._ControlFocus.select();
  }
}

function TItem_isArray() {
  var c = this.Control;
  if (c == null) return false;
  if (c.type)
    if (c.type == 'select-multiple') return true;
  return (isControlArray(c) && c[0].type != 'radio');
}

function TItem_getAsObjectArray() {
  if (this.isNull()) return [];
  if (this.Type == AzTypes.STRING) return this.getAsStringArray();
  if (this.Type == AzTypes.LONG) return this.getAsLongArray();
  if (this.Type == AzTypes.DOUBLE) return this.getAsDoubleArray();
  if (this.Type == AzTypes.DATE) return this.getAsDateArray();
  if (this.Type == AzTypes.TIME) return this.getAsTimeArray();
/*
  if (this.Type == AzTypes.TIMESTAMP) return this.getAsTimestampArray();
  if (this.Type == AzTypes.BOOLEAN) return this.getAsBooleanArray();
*/
  if (this.Type == AzTypes.BIG_DECIMAL) return this.getAsBigDecimalArray();
  return null;
}

function TItem_getAsStringArray() {
  var s = this.getValue();
  if (isArray(s)) {
    var i;
    for (i=0; i<s.length; i++) {
      s[i] = String(s[i]);
    }
    return s;
  }
  if (s == null || s == '') return [];
  return [String(s)];
}

function TItem_getAsLongArray() {
  var val = this.getValue();
  if (isArray(val)) {
    var i;
    for (i=0; i<val.length; i++) {
      if (!(val[i] == null || val[i] == ''))
        val[i] = Math.floor(Number(Util.cleanNumberString(val[i])));
    }
    return val;
  }
  if (val == null || val == '') return [];
  return [Math.floor(Number(Util.cleanNumberString(val)))];
}

function TItem_getAsDoubleArray() {
  var val = this.getValue();
  if (isArray(val)) {
    var i;
    for (i=0; i<val.length; i++) {
      if (!(val[i] == null || val[i] == ''))
        val[i] = Number(Util.cleanNumberString(String(val[i])));
    }
    return val;
  }
  if (val == null || val == '') return [];
  return [Number(Util.cleanNumberString(String(val)))];
}

function TItem_getAsBigDecimalArray() {
  var val = this.getValue();
  if (isArray(val)) {
    var i;
    for (i=0; i<val.length; i++) {
      if (!(val[i] == null || val[i] == ''))
        val[i] = Util.StringToBigDecimal(String(val[i]), this.DataFormat);
    }
    return val;
  }
  if (val == null || val == '') return [];
  return [Util.StringToBigDecimal(String(val), this.DataFormat)];
}

function TItem_getAsDateArray() {
  var val = this.getValue();
  if (isArray(val)) {
    var i;
    for (i=0; i<val.length; i++) {
      var dt = Util.StringToDate(val[i], this.DataFormat);
      if (dt == null) val[i] = null;
      else {
        var n = dt.getTime();
        dt = new Date(n - n % 360000);
        val[i] = dt;
      }
    }
    return val;
  }
  if (val == null || val == '') return [];
  var dt = Util.StringToDate(val, this.DataFormat);
  if (dt == null) return [];
  var n = dt.getTime();
  dt = new Date(n - n % 360000);
  return [dt];
}

function TItem_getAsTimeArray() {
  var val = this.getValue();
  if (isArray(val)) {
    var i;
    for (i=0; i<val.length; i++) {
      var dt = Util.StringToDate(val[i], this.DataFormat);
      if (dt == null) val[i] = null;
      else {
        var n = dt.getTime();
        dt = new Date(n % 86400000);
        val[i] = dt;
      }
    }
    return val;
  }
  if (val == null || val == '') return [];
  var dt = Util.StringToDate(val, this.DataFormat);
  if (dt == null) return [];
  var n = dt.getTime();
  dt = new Date(n % 86400000);
  return [dt];
}

function TItem_getAsTimestampArray() {
  var val = this.getValue();
  if (isArray(val)) {
    var i;
    for (i=0; i<val.length; i++) {
      var dt = Util.StringToDate(val[i], this.DataFormat);
      if (dt == null) val[i] = null;
      val[i] = dt;
    }
    return val;
  }
  if (val == null || val == '') return [];
  var dt = Util.StringToDate(val, this.DataFormat);
  if (dt == null) return [];
  return [dt];
}

function TItem_getAsBooleanArray() {
  var val = this.getValue();
  if (isArray(val)) {
    var i;
    for (i=0; i<val.length; i++) {
      val[i] = Util.StringToBoolean(val[i], this.DataFormat);
    }
    return val;
  }
  if (val == null || val == '') return [];
  return [Util.StringToBooelean(val, this.DataFormat)];
}

function TItem_showError(msg, params) {
  if (document.layers) window.captureEvents(Event.BLUR | Event.FOCUS);
  Util.showMsgBox(msg, params);
  if (document.layers) setTimeout('window.releaseEvents(Event.BLUR | Event.FOCUS);', 200);
}

function TItem_setDateControls(ctrlDay, ctrlMonth, ctrlYear) {
  if (this.Type != AzTypes.DATE) return;
  this.Child['DAY'] = new TItem(this.Name + '_DAY', ctrlDay, AzTypes.DATE, this.DataFormat.match(/d{1,2}/), 0, this.Mandatory, this.Description + ' (Day)');
  this.Child['MONTH'] = new TItem(this.Name + '_MONTH', ctrlMonth, AzTypes.DATE, this.DataFormat.match(/M{1,3}/), 0, this.Mandatory, this.Description + ' (Month)');
  this.Child['YEAR'] = new TItem(this.Name + '_YEAR', ctrlYear, AzTypes.DATE, this.DataFormat.match(/y{1,4}/), 0, this.Mandatory, this.Description + ' (Year)');

  this.Child['DAY'].Owner = this.Owner;
  this.Child['MONTH'].Owner = this.Owner;
  this.Child['YEAR'].Owner = this.Owner;

  this.Child['DAY'].Parent = this;
  this.Child['MONTH'].Parent = this;
  this.Child['YEAR'].Parent = this;

  this.Control.focus = new Function('document.'+this.Owner._Form.name+'.'+ctrlDay.name +'.focus();');

//  this.Child['DAY'].AfterValidate = TItem_Date_setDate;
//  this.Child['MONTH'].AfterValidate = TItem_Date_setDate;
//  this.Child['YEAR'].AfterValidate = TItem_Date_setDate;
  this.addValidator(TItem_Validator_validateDateExist, true, 0);
  this.addValidator(TItem_Validator_validateDateControls, true, 0);
//  this.AfterValidate = TItem_Date_setDate;
  this._ControlFocus = ctrlDay;
  this._ControlFocusOnError = ctrlDay;

  this.setDate = TItem_Date_setDate;
}

function TItem_setDateTimeControls(ctrlDay, ctrlMonth, ctrlYear, ctrlHour, ctrlMin) {
  if (this.Type != AzTypes.TIMESTAMP) return;
  this.Child['DAY'] = new TItem(this.Name + '_DAY', ctrlDay, AzTypes.DATE, this.DataFormat.match(/d{1,2}/), 0, this.Mandatory, this.Description + ' (Day)');
  this.Child['MONTH'] = new TItem(this.Name + '_MONTH', ctrlMonth, AzTypes.DATE, this.DataFormat.match(/M{1,3}/), 0, this.Mandatory, this.Description + ' (Month)');
  this.Child['YEAR'] = new TItem(this.Name + '_YEAR', ctrlYear, AzTypes.DATE, this.DataFormat.match(/y{1,4}/), 0, this.Mandatory, this.Description + ' (Year)');
  this.Child['HOUR'] = new TItem(this.Name + '_HOUR', ctrlHour, AzTypes.TIME, this.DataFormat.match(/H{1,2}/), 0, this.Mandatory, this.Description + ' (Hour)');
  this.Child['MIN'] = new TItem(this.Name + '_MIN', ctrlMin, AzTypes.TIME, this.DataFormat.match(/m{1,2}/), 0, this.Mandatory, this.Description + ' (Minute)');

  this.Child['DAY'].Owner = this.Owner;
  this.Child['MONTH'].Owner = this.Owner;
  this.Child['YEAR'].Owner = this.Owner;
  this.Child['HOUR'].Owner = this.Owner;
  this.Child['MIN'].Owner = this.Owner;

  this.Child['DAY'].Parent = this;
  this.Child['MONTH'].Parent = this;
  this.Child['YEAR'].Parent = this;
  this.Child['HOUR'].Parent = this;
  this.Child['MIN'].Parent = this;

  this.Control.focus = new Function('document.'+this.Owner._Form.name+'.'+ctrlDay.name +'.focus();');

  this.addValidator(TItem_Validator_validateDateExist, true, 0);
  this.addValidator(TItem_Validator_validateDateTimeControls, true, 0);

  this._ControlFocus = ctrlDay;
  this._ControlFocusOnError = ctrlDay;

  this.setDate = TItem_Date_setDateTime;
}

function TItem_Date_setDate(result) {
  if (!result) {
    this.Owner._ControlFocus = this.Control;
    return;
  }
  if (this.Child['MONTH'].isNull() || this.Child['DAY'].isNull() || this.Child['YEAR'].isNull()) {
    this.clear();
    return;
  }

  var d = new Date(0);
  if (d == null || d.constructor != Date) d = new Date(0);

  var d1 = this.Child['YEAR'].getAsDate();
  if (d1 == null) return;
  d.setFullYear(d1.getFullYear());

  d1 = this.Child['MONTH'].getAsDate();
  if (d1 == null) return;
  d.setMonth(d1.getMonth());

  d1 = this.Child['DAY'].getAsDate();
  if (d1 == null) return;
  d.setDate(d1.getDate());
  this.setValue(d);
}

function TItem_Date_setDateTime(result) {
  if (!result) {
    this.Owner._ControlFocus = this.Control;
    return;
  }
  if (this.Child['MONTH'].isNull() || this.Child['DAY'].isNull() || this.Child['YEAR'].isNull() ) {
    this.clear();
    return;
  }

  var d = new Date(0);
  if (d == null || d.constructor != Date) d = new Date(0);

  var d1 = this.Child['YEAR'].getAsDate();
  if (d1 == null) return;
  d.setFullYear(d1.getFullYear());

  d1 = this.Child['MONTH'].getAsDate();
  if (d1 == null) return;
  d.setMonth(d1.getMonth());

  d1 = this.Child['DAY'].getAsDate();
  if (d1 == null) return;
  d.setDate(d1.getDate());

  d1 = this.Child['HOUR'].getAsTime();
  if (d1 == null) return;
  d.setHours(d1.getHours());

  d1 = this.Child['MIN'].getAsTime();
  if (d1 == null) return;
  d.setMinutes(d1.getMinutes());

  this.setValue(d);
}

function TItem_Validator_validateMandatory(anItem) {
  if (anItem.Mandatory && anItem.isNull()) {
    anItem.showError(LBJSErrorMsgs.MSG_MANDATORY, [anItem.Description]);
    return false;
  }

  return true;
}

function TItem_Validator_validateRegEx(anItem) {
  var sValue = anItem.getAsStringArray();
  if (sValue.length == 0) return true;
  if (anItem._RegEx != null) {
    for (var i=0; i<sValue.length; i++) {
      if (sValue[i].length == 0) break;
      if (anItem.Type == AzTypes.LONG || anItem.Type == AzTypes.DOUBLE) {
        sValue[i] = Util.cleanNumberString(String(sValue[i]));
      }
      if (!sValue[i].match(anItem._RegEx)) {
        anItem.showError(LBJSErrorMsgs.MSG_INVALID_VALUE, [anItem.Description, sValue[i]]);
        return false;
      }
    }
  }
  return true;
}

function TItem_Validator_validateTrim(anItem) {
  anItem.setValue(anItem.getAsString().trim());
  return true;
}

function TItem_Validator_validateNumberRange(anItem) {
  if (anItem.isNull()) return true;

  if (anItem.Type == AzTypes.DOUBLE) {
    var nValue = anItem.getAsDouble();
    if (nValue < anItem.MinValue || nValue > anItem.MaxValue) {
      anItem.showError(LBJSErrorMsgs.MSG_RANGE_EXCEEDED, [anItem.Description, Util.format(anItem.MinValue, anItem.DataFormat), Util.format(anItem.MaxValue, anItem.DataFormat)]);
      return false;
    }
    return true;
  } else if (anItem.Type == AzTypes.LONG) {
    var nValue = anItem.getAsLong();
    if (nValue < anItem.MinValue || nValue > anItem.MaxValue) {
      anItem.showError(LBJSErrorMsgs.MSG_RANGE_EXCEEDED, [anItem.Description, Util.format(anItem.MinValue, anItem.DataFormat), Util.format(anItem.MaxValue, anItem.DataFormat)]);
      return false;
    }
    return true;
  } else if (anItem.Type == AzTypes.BIG_DECIMAL) {
    var nValue = anItem.getAsBigDecimal();
    if (nValue.compareTo(anItem.MinValue) < 0 || nValue.compareTo(anItem.MaxValue) > 0) {
      anItem.showError(LBJSErrorMsgs.MSG_RANGE_EXCEEDED, [anItem.Description, Util.format(anItem.MinValue, anItem.DataFormat), Util.format(anItem.MaxValue, anItem.DataFormat)]);
      return false;
    }
    return true;
  }
}

function TItem_Validator_validateMaxLength(anItem) {
  var sValue = anItem.getAsString();
  if (anItem.MaxLength > 0 && sValue.lengthb() > anItem.MaxLength) {
    anItem.showError(LBJSErrorMsgs.MSG_MAX_LENGTH_EXCEEDED, [anItem.Description, Util.format(anItem.MaxLength, '#,##0'),Util.format(Math.floor(anItem.MaxLength/3), '#,##0')]);
    return false;
  }
  return true;
}

function TItem_Validator_validateDateControls(anItem) {
  anItem._ControlFocus = anItem.Child['DAY'].Control;

  // trim date controls
  anItem.Child['DAY'].setValue(anItem.Child['DAY'].getAsString().trim());
  anItem.Child['MONTH'].setValue(anItem.Child['MONTH'].getAsString().trim());
  anItem.Child['YEAR'].setValue(anItem.Child['YEAR'].getAsString().trim());

  if (anItem.Child['DAY'].isNull() ||
       anItem.Child['MONTH'].isNull() ||
       anItem.Child['YEAR'].isNull()) {
//    anItem.clear();
    return true;
  }

  var dayError = !anItem.Child['DAY'].validate();
  if (dayError) appendItemNumber(anItem.Owner, anItem._INDEX + 1);
  var monError = !anItem.Child['MONTH'].validate();
  if (monError) appendItemNumber(anItem.Owner, anItem._INDEX + 1);
  var yrError = !anItem.Child['YEAR'].validate();
  if (yrError) appendItemNumber(anItem.Owner, anItem._INDEX + 1);

  if (dayError) anItem._ControlFocusOnError = anItem.Child['DAY'].Control;
  else if (monError) anItem._ControlFocusOnError = anItem.Child['MONTH'].Control;
  else if (yrError) anItem._ControlFocusOnError = anItem.Child['YEAR'].Control;

  if (!dayError && !monError && !yrError) {
    return true;
  }
  return false;
}

function TItem_Validator_validateDateTimeControls(anItem) {
  anItem._ControlFocus = anItem.Child['DAY'].Control;

  // trim date controls
  anItem.Child['DAY'].setValue(anItem.Child['DAY'].getAsString().trim());
  anItem.Child['MONTH'].setValue(anItem.Child['MONTH'].getAsString().trim());
  anItem.Child['YEAR'].setValue(anItem.Child['YEAR'].getAsString().trim());

  anItem.Child['HOUR'].setValue(anItem.Child['HOUR'].getAsString().trim());
  anItem.Child['MIN'].setValue(anItem.Child['MIN'].getAsString().trim());
/*zhen - set default time to 9 am*/
  if (anItem.Child['HOUR'].isNull()) anItem.Child['HOUR'].setValue('09');
  if (anItem.Child['MIN'].isNull()) anItem.Child['MIN'].setValue('00');

  if (anItem.Child['DAY'].isNull() ||
       anItem.Child['MONTH'].isNull() ||
       anItem.Child['YEAR'].isNull() ||
       anItem.Child['HOUR'].isNull() ||
       anItem.Child['MIN'].isNull()) {
//    anItem.clear();
    return true;
  }

  var dayError = !anItem.Child['DAY'].validate();
  var monError = !anItem.Child['MONTH'].validate();
  var yrError = !anItem.Child['YEAR'].validate();
  var hrError = !anItem.Child['HOUR'].validate();
  var minError = !anItem.Child['MIN'].validate();

  if (dayError) anItem._ControlFocusOnError = anItem.Child['DAY'].Control;
  else if (monError) anItem._ControlFocusOnError = anItem.Child['MONTH'].Control;
  else if (yrError) anItem._ControlFocusOnError = anItem.Child['YEAR'].Control;
  else if (hrError) anItem._ControlFocusOnError = anItem.Child['HOUR'].Control;
  else if (minError) anItem._ControlFocusOnError = anItem.Child['MIN'].Control;


  if (!dayError && !monError && !yrError && !hrError && !minError) {
    return true;
  }
  return false;
}

function TItem_Validator_validateDateExist(anItem) {
  if (anItem.Child['DAY'].isNull() ||
       anItem.Child['MONTH'].isNull() ||
       anItem.Child['YEAR'].isNull()) {
    anItem.clear();
    return true;
  }
  /*removed to allow entering of datetime without time component*/
/*  if ((anItem.Type == AzTypes.TIMESTAMP)&&
      (anItem.Child['HOUR'].isNull() || anItem.Child['MIN'].isNull)){
      anItem.clear();
     return true;
  }*/

  var day = anItem.Child['DAY'].getAsDate().getDate();
  var month = anItem.Child['MONTH'].getAsDate().getMonth();
  var year = anItem.Child['YEAR'].getAsDate().getFullYear();
  var bExist = true;
  if (month == 1) {
    if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
      bExist = (day >= 1 && day <= 29);
    } else bExist = (day >= 1 && day <= 28);
  } else {
    var num_days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    bExist = (day <= num_days[month]);
  }
  if (!bExist) {
    if (anItem.Child['YEAR'].Control.type == "hidden")
      anItem.showError(LBJSErrorMsgs.MSG_NON_EXISTING_DATE_DD_MM, [anItem.Description, anItem.Child['DAY'].getAsString(), anItem.Child['MONTH'].getAsString()]);
    else
      anItem.showError(LBJSErrorMsgs.MSG_NON_EXISTING_DATE, [anItem.Description, anItem.Child['DAY'].getAsString(), anItem.Child['MONTH'].getAsString(), anItem.Child['YEAR'].getAsString()]);
  } else
    anItem.setDate(true);
  return bExist;
}

function TItem_Validator_validateDateRange(anItem) {
  var nValue = anItem.getAsDate();
  if (nValue == null) return true;
  if ((anItem.MinValue != null) && (nValue < anItem.MinValue)) {
    anItem.showError(LBJSErrorMsgs.MSG_DATE_AFTER, [anItem.Description, Util.format(anItem.MinValue, anItem.DataFormat)]);
    return false;
  } else if ((anItem.MaxValue != null) && nValue > anItem.MaxValue) {
    anItem.showError(LBJSErrorMsgs.MSG_DATE_BEFORE, [anItem.Description, Util.format(anItem.MaxValue, anItem.DataFormat)]);
    return false;
  }
  return true;

}

function TItem_Control_getValue() {
  var value, temp_val;
  var i, j;

  value = null;
  if (this[0] && !this.type) {
    value = new Array();
    j = 0;
    for (i=0; i<this.length; i++) {
      temp_val = this[i].getValue();
      if (temp_val) value[j++] = new String(temp_val);
    }
  } else {
    if (this.type == 'text' || this.type == 'hidden'
        || this.type == 'password' || this.type == 'textarea' || this.type == 'file')
      value = new String(this.value);
    else if (this.type == 'checkbox' || this.type == 'radio') {
      if (this.checked) value = new String(this.value);
      else value = '';
    } else if (this.type.indexOf('select')==0) {
      value = new Array();
      j = 0;
      for (i=0; i<this.options.length; i++) {
        if (this.options[i].selected)
          value[j++] = new String(this.options[i].value);
      }
    }
  }
  if (value[0] && value.length == 1) value = value[0];
  return value;
}

function TItem_Control_setValue(aValue, aDefault) {
  if (!aDefault) aDefault = false;
  else aDefault = true;
  setControlValue(this, aValue, aDefault);
}

function TItem_Control_clear() {
  clearControlValue(this);
}



/*
 * class TItemServer
 */
function TItemServer(form) {
  this.Items = new Object();
  this._Validators = [];
  this._Form = form;
  this._Window = window;
  this.ItemOrder = new Array();
//  if (setActionIS) setActionIS(null);
  return this;
}

TItemServer.prototype.addItem = TItemServer_addItem;
TItemServer.prototype.BOI = TItemServer_BOI;
TItemServer.prototype.validate = TItemServer_validate;
TItemServer.prototype.addValidator = TItemServer_addValidator;
TItemServer.prototype.isModified = TItemServer_isModified;
TItemServer.prototype.clear = TItemServer_clear;
TItemServer.prototype.reset = TItemServer_reset;
TItemServer.prototype.submit = TItemServer_submit;
TItemServer.prototype.submitFake = TItemServer_submitFake;
TItemServer.prototype.checkModified = TItemServer_checkModified;
TItemServer.prototype.focusFirstItem = TItemServer_focusFirstItem;

TItemServer.prototype.BeforeValidate = null;
TItemServer.prototype.AfterValidate = null;

function TItemServer_addItem(aName, aControlName, aType, aFormat, aLength, aNullable, aDescription) {
   var di = new TItem(aName, this._Form.elements[aControlName], aType, aFormat, aLength, !aNullable, aDescription);
   di.Owner = this;
   this.Items[aName] = di;
   this.ItemOrder = this.ItemOrder.concat(new Array(di));
//   this.ItemOrder.push(di);
}

function TItemServer_BOI(aName) {
  if (this.Items[aName]) return this.Items[aName];
  return null;
}

function TItemServer_validate() {
  if (this.BeforeValidate) this.BeforeValidate();

  var c;
  var result = true;
  var bValidated = new Object();
  for (c in this.Items) {
    var diResult = this.Items[c].validate();
    bValidated[String(c)] = diResult;
    result = result && diResult;
  }
  var i;
  for (i=0; i<this._Validators.length; i++) {
    var v = this._Validators[i];
    var j;
    var b = true;
    for (j=0; j<v.items.length; j++) {
      b = b && bValidated[v.items[j]];
    }
    if (b)
      result = v.validator(this) && result;
    else result = false;
  }

  if (this.AfterValidate) this.AfterValidate(result);
  return result;
}

function TItemServer_addValidator(fValidator, diItems, nIndex) {
  if (fValidator != null && fValidator.constructor == Function) {
    if (!diItems) diItems = [];
    if (nIndex == null || isNaN(Number(nIndex))) nIndex = this._Validators.length;
    this._Validators.splice(nIndex, 0, {validator:fValidator, items:diItems});
    return fValidator;
  }
  return null;
}

function TItemServer_clear() {
  var c;
  for (c in this.Items) this.Items[c].clear();
}

function TItemServer_reset() {
  this._Form.reset();
  var c;
  for (c in this.Items) {
    if (this.Items[c].Type == AzTypes.DATE) {
      this.Items[c].reset();
      if (this.Items[c].Child['DAY'])
        this.Items[c].setDate(true);
    }
    if (this.Items[c].Control && this.Items[c].Control.type && this.Items[c].Control.type == 'hidden') {
      this.Items[c].reset();
    }
  }
  this.focusFirstItem();
}

function TItemServer_focusFirstItem() {
  return;
/*
  for (var i=0; i<this.ItemOrder.length; i++)<script src="../../../../OLD D/training/jsp/FOS/include/lbjs01.js" type="text/javascript"></script> {
    if (this.ItemOrder[i]._ControlFocus.type != 'hidden' && this.ItemOrder[i]._ControlFocus.focus) {
      this.ItemOrder[i].focus(false);
      return;
    } else if (isControlArray(this.ItemOrder[i].Control) && this.ItemOrder[i].Control[0].type != 'hidden' && this.ItemOrder[i].Control[0].focus) {
      this.ItemOrder[i].focus(false);
      return;
    }
  }
*/
}

function TItemServer_isModified() {
/*  var c;
  for (c in this.Items) {
    if (this.Items[c].isModified()) return true;
  }*/
  return false;
}

function TItemServer_submit(bCheckModified) {
  var bResult = this.validate();
/*  if (bResult && bCheckModified && !this.isModified()) {
    Util.showMsgBox(LBJSErrorMsgs.MSG_NO_CHANGES);
    this.focusFirstItem();
    return false;
  }*/
  if (bResult) this._Form.submit();
  return bResult;
}

/* Amil: do validations for submit without actually submitting */
function TItemServer_submitFake(bCheckModified) {
  var bResult = this.validate();
/*  if (bResult && bCheckModified && !this.isModified()) {
    Util.showMsgBox(LBJSErrorMsgs.MSG_NO_CHANGES);
    this.focusFirstItem();
    return false;
  }*/
  return bResult;
}

/* Amil: added bNoValidation parameter */
function TItemServer_checkModified(bNoValidation) {
  var bResult = true;
  if (!bNoValidation) bResult = this.validate();
/*  if (bResult && !this.isModified()) {
    Util.showMsgBox(LBJSErrorMsgs.MSG_NO_CHANGES);
    this.focusFirstItem();
    return false;
  }*/
  return bResult;
}

/**
 * Add customized functions below this text.
 */

function TItem_addError(msg, params) {
  var is = this.Owner;
  if (is == null) return;
  var msg = Util.formatMsg(msg, params);
  var o = {message:msg, item:(this.Parent?this.Parent:this)};
  is.ErrorMsg = is.ErrorMsg.concat(new Array(o));
//  is.ErrorMsg.push(o);
}

function TItemServer_addError(msg, params) {
  var msg = Util.formatMsg(msg, params);
  var o = {message:msg, item:null};
  this.ErrorMsg = this.ErrorMsg.concat(new Array(o));
}

TItem.prototype.showError = TItem_addError;
TItemServer.prototype.showError = TItemServer_addError;

TItemServer.prototype.BeforeValidate = TItemServer_clearErrors;
TItemServer.prototype.AfterValidate = TItemServer_showErrors;

TItemServer.prototype.addMultiItemError = TItemServer_addMultiItemError;


function TItemServer_addMultiItemError(itemliststring, msg, params) {
  var sarrItems = itemliststring.split(',');
  var darrItems = new Array();
  for (var i=0; i<sarrItems.length; i++) {
    if (this.BOI(sarrItems[i]))
      darrItems = darrItems.concat(new Array(this.BOI(sarrItems[i])));
  }
    
  var msg = Util.formatMsg(msg, params);
  var o = {message:msg, item:darrItems};
  this.ErrorMsg = this.ErrorMsg.concat(new Array(o));
}


function TItemServer_clearErrors() {
  this.ErrorMsg = new Array();
}


  function cleanHTMLStr(aStr) {
    var sClean = '';
    if (aStr != null)
    { for (var i=0; i<aStr.length; i++)
      { switch (aStr.charAt(i))
        { case '<': sClean += '&lt;'; break;
          case '>': sClean += '&gt;'; break;
          case '\"': sClean += '&quot;'; break;
          case '\'': sClean += '&#39;'; break;
          case '&': sClean += '&amp;'; break;
          default:
            var c = parseInt(aStr.charAt(i));
            if (c<32 && c>126) sClean += '&#' + c + ';';
            else sClean += aStr.charAt(i);
        }
      }
    }
    return sClean;
  }



function TItemServer_showErrors(result) {

  var errTable = document.getElementById("errTable");
  errTable.style.display = "none";
  this.clearMarkers();
  
  if (result) return;
  if (this.ErrorMsg.length <= 0) return;
  
  errTable.style.display = "block";
  var eErrList = document.getElementById("errList");

  // Write error messages.
  var s = '';
  for (var i=0; i<this.ErrorMsg.length; i++) {
    if (this.ErrorMsg[i].item) {
      if (this.ErrorMsg[i].item.showMarker)
        this.ErrorMsg[i].item.showMarker();
      else if (this.ErrorMsg[i].item.length) {
        for (var j=0; j<this.ErrorMsg[i].item.length; j++)
          this.ErrorMsg[i].item[j].showMarker();
      }
    }
    s += '<li>' + this.ErrorMsg[i].message + '</li>\n';
  }
  eErrList.innerHTML = s;
  window.location.href="#";
}

function TItem_showMarker() {
  var e = document.getElementById("err_" + this.Name);
  if (e)
    e.innerHTML = '&nbsp;<img src="images/warning.gif" style="" align="top" id="licenseIdWarningLogo" height="21" width="25">';
}

function TItem_clearMarker() {
  var e = document.getElementById("err_" + this.Name);
  if (e)
    e.innerHTML = '';
}

TItem.prototype.showMarker = TItem_showMarker;
TItem.prototype.clearMarker = TItem_clearMarker;

function TItemServer_clearMarkers() {
  for (c in this.Items) {
    this.BOI(c).clearMarker();
  }
}

TItemServer.prototype.clearMarkers = TItemServer_clearMarkers;

//-->


