function CSOption(data,value,HTMLo,className) {
 this.data=data;
 this.value=value;
 this.HTMLo=HTMLo;
 this.className=className ? className : null;
 return this;
}

/*

USSAGE:

Create
new CSelect(container,name,width,height,bwidth,lwidth,lheight,nodef_val);
 container       - object, where select stored
 name            - name of form field width value
 width           - width of select area
 height          - height of select area
 bwidth          - width of button
 lwidth, lheight - size of drop down list
 nodef_value     - value if no selected


Set class names
setClassName(selectCN,selectAreaCN,selectButtonCN,dselectCN,dselectAreaCN,dselectButtonCN,dropDownCN,dropDownListCN,dropDownListItemCN,dropDownListItemSelectedCN)
 selectCN                   - class name for select
 selectAreaCN               - class name for select area
 selectButtonCN             - class name for button area
 dselectCN                  - class name for disabled select
 dselectAreaCN              - class name for disabled select area
 dselectButtonCN            - class name for disabled button area
 dropDownCN                 - class name for drop down area
 dropDownListCN             - class name for scrolling list
 dropDownListItemCN         - class name for standard item in list
 dropDownListItemSelectedCN - class name for selected item in list

Add option to end of list, return option's object
addOption(data,val,selected,classname)
 data      - option's text
 val       - option's value
 selected  - true, if selected
 classname - option's custom classname

Insert option before other option, return option's object
insertBeforeOption(before,data,val,selected,classname)
 before    - option, insert before it
 data      - option's text
 val       - option's value
 selected  - true, if selected
 classname - option's custom classname

Unselect 
setUnselected()

Select option by option's object
setSelectedByObj(o,notify,user)
 o      - option's object
 notify - true if need notification
 user   - true (user intervention) or false (program) for notification

Select option by option's text
setSelectedByOption(data,notify,user)
 data      - option's text
 notify - true if need notification
 user   - true (user intervention) or false (program) for notification

Select option by option's value
setSelectedByValue(val,notify,user)
 val    - option's value
 notify - true if need notification
 user   - true (user intervention) or false (program) for notification

Set onchange function
setOnchangeFunc(func)
func - function name, like .setOncahngeFunc(test), where
test is: function test(user,po,so,co)  { ... }
          user - true (user intervention), false (program)
          po - previous option's object
          so - selected option's
          co - calnedar's object

Set control enable / disable
Enable(state)
 state - true for enable / false for disable
*/



function CSelect(container,name,width,height,bwidth,lwidth,lheight,nodef_val) {
 this.container=container;
 this.options=new Array();
 this.name=name;
 this.width=width;
 this.height=height;
 this.bwidth=bwidth;
 this.lwidth=lwidth;
 this.lheight=lheight;
 this.selected=null;
 this.firstSelected=null;
 this.nodef_val=nodef_val ? nodef_val : "";
 this.disabled=false;
 this.onchange=null;

 this.selectCN="s_select";
 this.selectAreaCN="s_selectArea";  
 this.selectButtonCN="s_selectButton";  

 this.dselectCN="s_dselect";
 this.dselectAreaCN="s_dselectArea";  
this.dselectButtonCN="s_dselectButton";  

 this.dropDownCN="s_dropDown";
 this.dropDownListCN="s_dropDownList";
 this.dropDownListItemCN="s_dropDownListItem";
 this.dropDownListItemSelectedCN="s_dropDownListItemSelected";

 var eclass=this;

 var tb=FCrEl(this.container,"TABLE","cellspacing=0; cellpadding=0; bgcolor=#f0f0f0; border=0; height="+this.height+"; width="+this.width+"; class="+this.selectCN,"tableLayout: fixed;");
 this.HTMLo=tb;

 tb=FCrEl(tb,"TBODY");
 var tr=FCrEl(tb,"TR","valign=middle; height=100%","cursor: pointer;");
 tr.onclick=function(e) {
  if (eclass.disabled) return;

  if (e!=-1) {
      if (e) e.cancelBubble=true;
          else event.cancelBubble=true;
  }
   var o=eclass.dropDownHTMLo.style; //TR
   var od=eclass.dropDownHTMLo.firstChild.firstChild; //DIV
   if (o.display=="none") {
       if (CSelect.opened) document.onclick(-1);
       CSelect.onclick=document.onclick;
       CSelect.opened=true;
       o.display="";

       if (od.firstChild.offsetHeight<eclass.lheight) {
           od.style.height=od.firstChild.offsetHeight+(e ? 0 : 2);
       } else od.style.height=eclass.lheight;

       document.onclick=function(e) {
        eclass.dropDownHTMLo.style.display="none";
        document.onclick=CSelect.onclick;
        CSelect.onclick=null;
        CSelect.opened=false;
       }

   } else document.onclick(-1);
 }
 
 tr.ondblclick=function(e){if (!e) this.onclick(e);}

 var td=FCrEl(tr,"TD","nowrap=1; width=100%; class="+this.selectAreaCN);
 var dv=FCrEl(td,"DIV","nowrap=1;","width: 100%; overflow: hidden;");
 FCrEl(dv,"text","");

 this.selectedHTMLo=dv;
//  FCrEl(tr,"TD","width="+this.bwidth+"; align=center; class="+this.selectButtonCN,"","\u25BC"); 
 td=FCrEl(tr,"TD","width="+this.bwidth+" align=center; class="+this.selectButtonCN); 
 td=FCrEl(td,"INPUT","type=button; align=left;","width: "+this.bwidth+"; height: 100%; border: 0px; fontFamily: Arial; fontSize: 10px;");
 td.value="\u25BC";
 
 tr=FCrEl(tb,"TR","","display: none;");
 this.dropDownHTMLo=tr;
 td=FCrEl(tr,"TD");

 dv=FCrEl(td,"DIV","class="+this.dropDownCN,"position: absolute; zIndex: 100; width: "+this.lwidth+"; height: "+this.lheight+"; overflowX: hidden; overflowY: auto;");
 tb=FCrEl(dv,"TABLE", "width=100%; cellspacing=0; cellpadding=0; border=0; class="+this.dropDownListCN);
 tb=FCrEl(tb,"TBODY");
 this.dropDownListHTMLo=tb;

 this.hiddenValueHTMLo=document.getElementById(this.name);
 
 if(!document.getElementById(this.name)) //:::::::::::::::::::::::::::::::::::::::::lera's correction
  this.hiddenValueHTMLo=FCrEl(this.container,"INPUT","type=hidden; name="+this.name);

 this.setUnselected();
 
}

CSelect.prototype.setClassName=function(selectCN,selectAreaCN,selectButtonCN,dselectCN,dselectAreaCN,dselectButtonCN,dropDownCN,dropDownListCN,dropDownListItemCN,dropDownListItemSelectedCN) {
 if (selectCN!=null)                   this.selectCN=selectCN;
 if (selectAreaCN!=null)               this.selectAreaCN=selectAreaCN;
 if (selectButtonCN!=null)             this.selectButtonCN=selectButtonCN;
 if (dselectCN!=null)                  this.dselectCN=dselectCN;
 if (dselectAreaCN!=null)              this.dselectAreaCN=dselectAreaCN;
 if (dselectButtonCN!=null)            this.dselectButtonCN=dselectButtonCN;
 if (dropDownCN!=null)                 this.dropDownCN=dropDownCN;
 if (dropDownListCN!=null)             this.dropDownListCN=dropDownListCN;
 if (dropDownListItemCN!=null)         this.dropDownListItemCN=dropDownListItemCN;
 if (dropDownListItemSelectedCN!=null) this.dropDownListItemSelectedCN=dropDownListItemSelectedCN;
}

CSelect.prototype.addOption=function(data,val,selected,classname) {
 return this.insertBeforeOption(null,data,val,selected,classname);
}

CSelect.prototype.insertBeforeOption=function(before,data,val,selected,classname) {
 var eclass=this;
 if (!classname) classname=this.dropDownListItem;

 var tr=FCrEl(null,"TR","height=1");
 var o=new CSOption(data,val,tr,classname);
 this.options.push(o);

 tr.style.cursor="pointer";
 tr.option=o;
 tr.onmouseover=function() {this.className=eclass.dropDownListItemSelectedCN;}
 tr.onmouseout=function() {this.className=this.option.className;}
 tr.onclick=function() {eclass.setSelectedByObj(this.option,true,true); }
 var td=FCrEl(tr,"TD","nowrap=1; title="+o.data+"; class="+classname,"",o.data);
 if (before)  this.dropDownListHTMLo.insertBefore(tr,before.HTMLo);
     else this.dropDownListHTMLo.appendChild(tr);

 if (selected) {this.firstSelected=o; this.setSelectedByObj(o);}
 return o;
}

CSelect.prototype.setUnselected=function() {
 this.selectedHTMLo.className=this.selectedAreaCN;
 this.selectedHTMLo.firstChild.nodeValue="...";
 this.selectedHTMLo.title="";
 this.selected=null;
 this.hiddenValueHTMLo.value=this.nodef_val;
}

CSelect.prototype.setSelectedByObj=function(o,notify,user) {
 var po;
 if (o==null) {this.setUnselected(); return;}
 this.selectedHTMLo.firstChild.nodeValue=o.data;
 this.selectedHTMLo.className=o.className;
 this.selectedHTMLo.title=o.data;
 po=this.selected;
 this.selected=o;
 this.hiddenValueHTMLo.value=o.value;
 if (notify && this.onchange) this.onchange(user ? user : false,po,o,this);
}

CSelect.prototype.setSelectedByOption=function(data,notify,user) {
 for (var i=0;i<this.options.length;i++) {
      if (this.options[i].data==data) {this.setSelectedByObj(this.options[i],notify,user); return true;}
 }
 return false;
}

CSelect.prototype.setSelectedByValue=function(val,notify,user) {
 for (var i=0;i<this.options.length;i++) {
      if (this.options[i].value==val) {this.setSelectedByObj(this.options[i],notify,user); return true;}
 }
 return false;
}

CSelect.prototype.setOnchangeFunc=function(func) {
 this.onchange=func;
}

CSelect.prototype.GetSelected=function() {
 return this.selected;
}

CSelect.prototype.Enable=function(state) {
 this.disabled=!state;
 if (this.disabled) {
     this.hiddenValueHTMLo.name="";
     this.HTMLo.className=this.dselectCN;
     this.HTMLo.firstChild.firstChild.firstChild.className=this.dselectAreaCN;
     this.HTMLo.firstChild.firstChild.firstChild.nextSibling.className=this.dselectButtonCN;
 } else {
         this.hiddenValueHTMLo.name=this.name;
         this.HTMLo.className=this.selectCN;
         this.HTMLo.firstChild.firstChild.firstChild.className=this.selectAreaCN;
         this.HTMLo.firstChild.firstChild.firstChild.nextSibling.className=this.selectButtonCN;
        }

}

CSelect.onclick=null;
CSelect.opened=false;
