﻿function ITGetElementById(id)
{
    if (document.getElementById(id))
        return document.getElementById(id);
    else
        if (document.all)
            return document.all[id];
        else
            if (document.layers && document.layers[id])
                return (document.layers[id]);
            else
                return false;
}

function ListEl(ListId, idFiedName, nameFieldName)
{
     this.Id = ListId;
     this.El = ITGetElementById(ListId);
     this.IFN = idFiedName;
     this.NFN = nameFieldName;
}
ListEl.prototype.Fill = function(Atable)
{
     this.clear();
     for(var ij=0; ij<Atable.Rows.length; ij++)
     {
          var Op = new Option(Atable.Rows[ij][this.NFN], Atable.Rows[ij][this.IFN]);
          this.El.options[this.El.length] = Op;
     }
}
ListEl.prototype.FillRows = function(Rows)
{
     this.clear();
     for(var ij=0; ij<Rows.length; ij++)
     {
          var Op = new Option(Rows[ij][this.NFN], Rows[ij][this.IFN]);
          this.El.options[this.El.length] = Op;
     }
}
ListEl.prototype.clear = function()
{
     for (i=this.El.length-1;i>=0;i--)
     {
          if (Number(this.El.options[i].value)>=0) this.El.options[i] = null;
     }
     if (this.El.options[0]!=null)
          this.El.options[0].selected=true;
}
ListEl.prototype.clearVal = function(EL_VALUE)
{
     for (i=this.El.length-1;i>=0;i--)
     {
          if (Number(this.El.options[i].value)==EL_VALUE) this.El.options[i] = null;
     }
     if (this.El.options[0]!=null)
          this.El.options[0].selected=true;
}
ListEl.prototype.getListValuesArray =function(withdots)
{
     res = new Array();
     y=-1;
     for (i=0;i<this.El.length;i++)
     {
          if (this.El.options[i].selected)
          {
               var CurVal = this.El.options[i].value;
               if (CurVal.indexOf("-1",0)!=-1) continue;
               y++;
               res[y]= (withdots)?"."+CurVal+".":CurVal;
          }
     }
     return res;
}
ListEl.prototype.SelectedValue =function()
{
     res = "-1";
     for (i=0;i<this.El.length;i++)
     {
          if (this.El.options[i].selected)
          {
               var res = this.El.options[i].value;
               break;
          }
     }
     return res;
}
ListEl.prototype.SetToValue = function(val)
{
     for (i=0;i<this.El.length;i++)
     {
          if (this.El.options[i].value==val)
          {
               this.El.options[i].selected = true;
          }
     }
}

