var EntryState = { unknown:0, ins:1, upd:2, del:3 };
var objDelimiter = '#|#';
var fieldDelimiter = '#,#';

function addOption (oListbox, text, value, isDefaultSelected, isSelected)
{
  var oOption = document.createElement("option");
  oOption.appendChild(document.createTextNode(text));
  oOption.setAttribute("value", value);

  if (isDefaultSelected) oOption.defaultSelected = true;
  else if (isSelected) oOption.selected = true;

  oListbox.appendChild(oOption);
}

function isUrl(s) {
  var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
  return regexp.test(s);
}

var encodedCharacters = new Array('~', '!', '*', '(', ')', '\'');
var decodedCharacters = new Array('%7E', '%21', '%2A', '%28', '%29', '%60');
function prepareXmlStringForPost(str) {
  str = str.replace(/^\s*((?:[\S\s]*\S)?)\s*$/, '$1');
  str = encodeURIComponent(str);
  for(var i=0; i<encodedCharacters.length; i++)
    str = str.replace(encodedCharacters[i], decodedCharacters[i]);
}

function extend(Child, Parent) {
    var F = function() { }
    F.prototype = Parent.prototype;
    Child.prototype = new F();
    Child.prototype.constructor = Child;
    Child.superclass = Parent.prototype;   
}

// копирует все свойства из src в dst,
// включая те, что в цепочке прототипов src до Object
function mixin(dst, src){
    // tobj - вспомогательный объект для фильтрации свойств,
    // которые есть у объекта Object и его прототипа
    var tobj = {} 
    for(var x in src){
        // копируем в dst свойства src, кроме тех, которые унаследованы от Object
        if((typeof tobj[x] == "undefined") || (tobj[x] != src[x])){
            dst[x] = src[x];
        }
    }
    // В IE пользовательский метод toString отсутствует в for..in
    if(document.all && !document.isOpera){
        var p = src.toString;
        if(typeof p == "function" && p != dst.toString && p != tobj.toString &&
         p != "\nfunction toString() {\n    [native code]\n}\n"){
            dst.toString = src.toString;
        }
    }
}

function SimpleArray () {
  this.rows = [];
  this.getRow = function (id) {
    for (var i = 0; i < this.rows.length; i++)
      if (this.rows[i] != undefined && this.rows[i].id == id)
        return this.rows[i];
    return undefined;
  }
  this.addRow = function (row) {
    if (this.getRow(row.id) == undefined)  {
      this.rows[this.rows.length] = row;
    }
  }
  this.clear = function () {
    this.rows = [];
  }

}

// добавляем методы объекта
mixin(SimpleArray.prototype, {
})

