function DComboBoxControl(selectBox, textBox, icon, flyAnchor, options){
       
       if(options == null){
           options = {suggestEffect: false, highlightInTextBox: true, searchLettersCount: 3, highLightSearchLetters: true, ignoreCase: true, flyDivHeight: 300};
       }      
			 
       /*@@@ C @@@*/var bShowAlwaysAllItems = (options.suggestEffect == null) ? true : !options.suggestEffect;
       /*@@@ C @@@*/var bHighlightInTextBox = (options.highlightInTextBox == null) ? true : !options.highlightInTextBox; if(bShowAlwaysAllItems) bHighlightInTextBox=false;
       /*@@@ C @@@*/var bIgnoreCase = (options.ignoreCase == null) ? true : options.ignoreCase;
       /*@@@ C @@@*/var iSearchByFirstLetters = (options.searchLettersCount == null) ? 3 : options.searchLettersCount; //@@@ 0 or greater zero
       /*@@@ C @@@*/var bHighlightSearchLetters = (options.highLightSearchLetters == null) ? true : options.highLightSearchLetters;	 
       /*@@@ C @@@*/var iFlyHeight = (options.flyDivHeight == null || options.flyDivHeight < 0 ) ? 300 : options.flyDivHeight;
			 
       if(typeof(selectBox) == 'string'){selectBox =  document.getElementById(selectBox);}
       if(typeof(textBox) == 'string'){textBox =  document.getElementById(textBox);}
       if(icon!=null){if(typeof(icon) == 'string'){icon =  document.getElementById(icon);}}
       if(flyAnchor!=null){if(typeof(flyAnchor) == 'string'){flyAnchor = document.getElementById(flyAnchor);}}if(flyAnchor==null)flyAnchor=textBox;			 
   
       var fly;
       if(flyAnchor.nextSibling == null){
          fly = flyAnchor.parentNode.appendChild(document.createElement("DIV"));
       }else{
          fly = flyAnchor.parentNode.insertBefore(document.createElement("DIV"), flyAnchor.nextSibling);
       }
   
       fly.style.position = "relative";      
       fly = fly.appendChild(document.createElement("DIV"));
       fly.style.position = "absolute";
       fly.className = "comboboxcontrol-fly-container";
       fly.style.display = "none";
       
       var flyItems = new Array();             

	   //@@@ call after manual changing of selectedIndex on selectbox	
	   this.RefreshSelectedIndex = function(){
			SetTextInTextBox(selectBox.options[selectBox.selectedIndex].text);
	   }
	   
	   //@@@ optionally call after .RefreshSelectedIndex()
       this.FireOnChangeEvent = function(){
            SendOnChangeNotification();
       }
	     
	   //@@@ call after modifing of list items in the select box
	   this.Refresh = function(){			      						
			fly.style.display = "none";
			fly.innerHTML = "";
			if(iFlyHeight > 0){
			   fly.style.overflowY = "visible";
			}
			flyItems = new Array();											
						
			selectBox.DComboBoxControl_KeyboardArrowItem = null;
						
			for(var i = 0; i < selectBox.options.length; i++){
				var oOpt = selectBox.options[i];
								
				if(i == 0 && oOpt.value == ""){
					//@@@ skip first empty item
					flyItems.push(null);
					continue;	
				}
								
				var ctlItem = document.createElement("DIV");
				//ctlItem.id = selectBox.id + "__flyitem__" + i;
				ctlItem.DComboBoxControl_ValueIndex = i;
																								
				ctlItem.className = "comboboxcontrol-fly-item";															
								
				fly.appendChild(ctlItem);
				flyItems.push(ctlItem);
								
				var hdlClick = FlyItemClickHandlerCreator(ctlItem);								
				window.addEventListener ? ctlItem.addEventListener('click', hdlClick, false) : ctlItem.attachEvent('onclick', hdlClick);
				var hdlMouseOver = FlyItemMouseHandlerCreator(ctlItem, true);								
				window.addEventListener ? ctlItem.addEventListener('mouseover', hdlMouseOver, false) : ctlItem.attachEvent('onmouseover', hdlMouseOver);
				var hdlMouseOut = FlyItemMouseHandlerCreator(ctlItem, false);								
				window.addEventListener ? ctlItem.addEventListener('mouseout', hdlMouseOut, false) : ctlItem.attachEvent('onmouseout', hdlMouseOut);
			}
						
			this.RefreshSelectedIndex();	 
	   }
			 
			 
	   function ValidateItems(showAllItems){
		    //if(fly.style.display == "none") return;

            if(!showAllItems && bShowAlwaysAllItems) showAllItems = true;
				 					 
		    var sText = GetTextInTextBox();
			var sSearchText;
			if(iSearchByFirstLetters > 0){
			    sSearchText = sText.substr(0, iSearchByFirstLetters);
			}else{
			    sSearchText = sText;
			}
				 
			var ctlLastItem = null;
			var ctlSelectedItem = null;			 
			for(var i = 0; i < selectBox.options.length; i++){
				var oOpt = selectBox.options[i];

				if(i == 0 && oOpt.value == "") continue;	//@@@ skip first empty item

				var ctlItem = flyItems[i]; //document.getElementById(selectBox.id + "__flyitem__" + i);							 
				if(ctlItem != null){
					var sItemText = (bIgnoreCase) ? oOpt.text.toLowerCase() : oOpt.text;
					var iFoundPosition = (bHighlightSearchLetters) ? sItemText.indexOf(sSearchText) : -1;
					var bSelect = (sText == sItemText);																			
																												
					if(showAllItems || iFoundPosition >= 0){										      
						ctlItem.style.display = "";												
					
						FlyItemMouseHandler(ctlItem, false);

						var sClassName = ctlItem.className;
		                sClassName = sClassName.replace(/[ ]?comboboxcontrol\-fly\-item\-selected/,"");
		                if(bSelect) sClassName = sClassName + " comboboxcontrol-fly-item-selected";
		                ctlItem.className = sClassName;
												
						var sHtml;
						if(iFoundPosition >= 0){
							    sHtml = oOpt.text.substr(0, iFoundPosition) + '<strong>'  + oOpt.text.substr(iFoundPosition, sSearchText.length)  + '</strong>' + oOpt.text.substr(iFoundPosition + sSearchText.length);																																						   																														
						}else{
							    sHtml = oOpt.text;
						}
						ctlItem.innerHTML = sHtml;
						ctlLastItem = ctlItem;
						if(ctlSelectedItem == null && bSelect) ctlSelectedItem	= ctlItem;							
					}else{
				        ctlItem.style.display = "none";
					}																		  
				}					 
			}
			return {firstSelectedItem: ctlSelectedItem, lastVisibleItem: ctlLastItem};		 			 
	   }
			 
			 
       function TextBoxKeyDownHandler_Arrows(dir){										 
						     
			if(fly.style.display == "none"){
			   //@@@ open fly
			   if(dir > 0)ShowFly();			 
			   return;
            }
			
			//@@@ now fly is opened.....
					 					 
			if(dir == 0){
				//@@@ "enter" key
				//@@@ save selected value
				var ctlItem = selectBox.DComboBoxControl_KeyboardArrowItem;
				if(ctlItem != null && ctlItem.style.display != "none"){
				     SetSelectedIndex(ctlItem.DComboBoxControl_ValueIndex);
				}else{
				     if(!TryFindValueByTextBoxAndRegisterIt()){
					    //@@@ evaluate "esc" key
					    SetTextInTextBox(selectBox.options[selectBox.selectedIndex].text);
				     }
				}
				fly.style.display = "none";
				return;
			}
					 
			var ctlCurr = selectBox.DComboBoxControl_KeyboardArrowItem;
			var ctlNew = null;
					 
			if(ctlCurr == null){
				//@@@ find start element
				var ctlFirst = null; 					 
				var sText = GetTextInTextBox();		 
					      								
				for(var i = 0; i < selectBox.options.length; i++){
					var oOpt = selectBox.options[i];														
							 
					var ctlItem = flyItems[i]; //document.getElementById(selectBox.id + "__flyitem__" + i);
					if(ctlItem != null){
						if(ctlItem.style.display == "none") continue;						
												 
						var sItemText = (bIgnoreCase) ? oOpt.text.toLowerCase() : oOpt.text;							           
						if(sText == sItemText){
							selectBox.DComboBoxControl_KeyboardArrowItem = ctlItem;
							ctlCurr = ctlItem;
							break;
						}else if(ctlFirst == null){
							ctlFirst = ctlItem;
						}
					}
				}
								
				if(ctlCurr == null){
				    selectBox.DComboBoxControl_KeyboardArrowItem = ctlFirst;
				    //ctlCurr = ctlFirst;
				    ctlNew = ctlFirst;
				}									 																																																					     																			  							 			 
			}										 
					 
			if(ctlCurr != null){
			     //@@@ get new element					     
				 var iCurr = ctlCurr.DComboBoxControl_ValueIndex;
				 var iNew = iCurr
				 while(true){
				     iNew = iNew + dir;
				     if(iNew < 0 || iNew >= selectBox.options.length){
					     return; //@@@ the edges
					 }
									 
					 if(iNew == 0 && selectBox.options[0].value == ""){
						 return //@@@ empty edge
					 }
									 
					 var ctlNew1 = flyItems[iNew]; //document.getElementById(selectBox.id + "__flyitem__" + iNew);
					 if(ctlNew1 != null && ctlNew1.style.display != "none"){
					     ctlNew = ctlNew1; 
						 break;
					 }									 									 
				 }							 							 							 							 						 
			 }			 
					 
			 if(ctlNew != null){
				 //@@@ register new element
				 if(ctlCurr != null) FlyItemMouseHandler(ctlCurr, false);
				 FlyItemMouseHandler(ctlNew, true);
				 selectBox.DComboBoxControl_KeyboardArrowItem = ctlNew;
				 if(iFlyHeight > 0) ctlNew.scrollIntoView(false);							 
			 }	
					 														 					 					 
		}//@@@ TextBoxKeyDownHandler_Arrows()
			 			 			 
        function FlyItemClickHandlerCreator(item){return function(e){FlyItemClickHandler(item);};}
		function FlyItemClickHandler(item){
		    if(iTextBoxBlurHandlerTimerId != null){
			    clearTimeout(iTextBoxBlurHandlerTimerId);
				iTextBoxBlurHandlerTimerId = null;
            }
			SetSelectedIndex(item.DComboBoxControl_ValueIndex);
			fly.style.display = "none";	
			//try{textBox.focus();}catch(e){}					 				 
		}
			 
			 
        function FlyItemMouseHandlerCreator(item, over){return function(e){FlyItemMouseHandler(item, over);};}
		function FlyItemMouseHandler(item, over){
			var sClassName = item.className;
			sClassName = sClassName.replace(/[ ]?comboboxcontrol\-fly\-item\-over/,"");
			if(over) sClassName = sClassName + " comboboxcontrol-fly-item-over";
			item.className = sClassName;					
		}			 	 		 
			 
			 			 			 
		function ShowFly(showAllItems){
			var oValidateItemsResult = ValidateItems(showAllItems);		
			var ctlLastItem = oValidateItemsResult.lastVisibleItem;
			var ctlSelected = oValidateItemsResult.firstSelectedItem;
			fly.style.display = "";
			fly.style.width = flyAnchor.offsetWidth + "px";
			if(iFlyHeight > 0){
			    var bMakeScroll = (ctlLastItem != null && ctlLastItem.offsetTop + ctlLastItem.offsetHeight > iFlyHeight);
			    if(bMakeScroll){
     				 fly.style.height = iFlyHeight + "px";
					 fly.style.overflowY = "auto";
					 if(ctlSelected != null){
					    var iTmp = ctlSelected.offsetTop + ctlSelected.offsetHeight - fly.scrollTop;
						if(iTmp <0 || iTmp >= iFlyHeight) ctlSelected.scrollIntoView(false);
					 }
				}else{
				     fly.style.overflowY = "visible";
					 fly.style.height = "";
				}					 					     
			 }
		}
			 
	    function TryFindValueByTextBoxAndRegisterIt(){
			var bFound = false;
			var sText = GetTextInTextBox();
			for(var i = 0; i < selectBox.options.length; i++){
			     var sItemText;
				 if(i == 0 && selectBox.options[i].value == ""){
				    sItemText = "";
				 }else{
				    sItemText = (bIgnoreCase) ? selectBox.options[i].text.toLowerCase() : selectBox.options.text;
				 }
				 if(sItemText == sText){
				     SetSelectedIndex(i); //@@@ register
					 bFound = true;
					 break;
				 }
			 }
			 return bFound;
		}			 
			 
		function SetSelectedIndex(selectedIndex){
		     if(selectBox.selectedIndex != selectedIndex){
			     if(selectedIndex >= 0 && selectedIndex < selectBox.options.length){
    			    selectBox.selectedIndex = selectedIndex;
                    SetTextInTextBox(selectBox.options[selectedIndex].text);
    				//SendOnChangeNotification();
    				setTimeout(function(){SendOnChangeNotification();}, 0);
				 }
			 }else{
			     var sTextToBe = selectBox.options[selectedIndex].text;
			     if(bIgnoreCase) sTextToBe = sTextToBe.toLowerCase();
				 var sText = GetTextInTextBox();
				 if(sText != sTextToBe) SetTextInTextBox(selectBox.options[selectedIndex].text);								
			 }
		}
			 
		function SetTextInTextBox(text){
			textBox.value = text;
					 
			var ctlItem = selectBox.DComboBoxControl_KeyboardArrowItem;
			if(ctlItem != null){
			    FlyItemMouseHandler(ctlItem, false);
			}
			selectBox.DComboBoxControl_KeyboardArrowItem = null;
	    }
		function GetTextInTextBox(){
			var sText = textBox.value;
			if(selectBox.options[0].value == "" && selectBox.options[0].text == sText){
			    return "";
			}else{	
			    if(bIgnoreCase) sText = sText.toLowerCase();
			}
			return sText.replace(/((^[\s]+)|([\s]+$))/g,""); //@@@ trim
		}
		//function GetTextInTextBoxNetto(){ return textBox.value; }
			 
		function SendOnChangeNotification(){
			if(window.addEventListener){
    		    if(typeof(selectBox.onchange) == "function"){
                    selectBox.onchange();
                }
			}else{
				selectBox.fireEvent("onchange");
			}
		}			 			
			 
		function TextBoxKeyDownHandler(ev){			     					 
			 switch(ev.keyCode){
			     case 13 : //@@@ enter
					     TextBoxKeyDownHandler_Arrows(0);
						 break;
				 case 38 : //@@@ up
					     TextBoxKeyDownHandler_Arrows(-1);
						 return false;									 
						 break;
				 case 40 : //@@@ down
					     TextBoxKeyDownHandler_Arrows(1);
						 return false;
						 break;
				 case 27 : //@@@ esc
					     SetTextInTextBox(selectBox.options[selectBox.selectedIndex].text);
		                 fly.style.display = "none";
					     break;
				 default :
					     //ValidateItems();
						 ShowFly();	 
			} 
		}			 
		function TextBoxChangedHandler(){
		     ValidateItems();
		}			 
		function TextBoxClickHandler(){			     
			 ShowFly();
			 if(bTextBoxFocusHandler){
			    TextBoxFocusHandler1();
				bTextBoxFocusHandler = false;
			 }
		}
		var bTextBoxFocusHandler = false;
		function TextBoxFocusHandler(){
            bTextBoxFocusHandler = true;					 			     
		}
		function TextBoxFocusHandler1(){
		    if(selectBox.selectedIndex == 0 && selectBox.options[0].value == ""){
			     textBox.value = "";
			}else{
			     var sText = textBox.value;
				 if(sText != ""){
				     if(window.addEventListener){
					     textBox.selectionStart = 0; textBox.selectionEnd = 0;
					 }else{
					     try{textBox.select();var oRange = textBox.createTextRange();oRange.collapse(true);oRange.moveEnd('character', 0);oRange.moveStart('character', 0);oRange.select();}catch(e){} 
					 }
		     	     /*if(iSearchByFirstLetters > 0 && sText.length > iSearchByFirstLetters){
					                          //@@@ select first letters
											  if(window.addEventListener){
												     //@@@ mozilla
												     //textBox.selectionStart = 0; textBox.selectionEnd = iSearchByFirstLetters;
													 textBox.selectionStart = iSearchByFirstLetters; //textBox.selectionEnd = iSearchByFirstLetters;
											  }else{
												     //@@@ ie
													 var sTextToHiglight = sText.substring(iSearchByFirstLetters); //sText.substr(0, iSearchByFirstLetters);													 
												     try{textBox.select(); var oRange = textBox.createTextRange();oRange.findText(sTextToHiglight);oRange.select();}catch(e){}
											  }
						}else{
									      //@@@ select all 
										  textBox.select();
						}*/
			     }
			}
			return true;
			//TextBoxClickHandler();																		      										
        }
			 
        var iTextBoxBlurHandlerTimerId = null;
		function TextBoxBlurHandler(e){			     
			if(iTextBoxBlurHandlerTimerId != null){
				clearTimeout(iTextBoxBlurHandlerTimerId);
			}
			if(bFlyMouseDown){
				bFlyMouseDown = false;
				return;
			}
			iTextBoxBlurHandlerTimerId = setTimeout(function(){TextBoxBlurHandler1();}, 100);
		}
		function TextBoxBlurHandler1(){
			if(!TryFindValueByTextBoxAndRegisterIt()){
				//@@@ not found : so like esc button
				SetTextInTextBox(selectBox.options[selectBox.selectedIndex].text);
			}
			fly.style.display = "none";					 
		}
			 						 
		function IconClickHandler(){
		    if(iTextBoxBlurHandlerTimerId != null){
			    clearTimeout(iTextBoxBlurHandlerTimerId);
				iTextBoxBlurHandlerTimerId = null;
		    }
		    ShowFly(true);
		    try{textBox.focus();}catch(e){}
		}
			 
		var bFlyMouseDown = false;
		function FlyMouseDownHadler(){
		    bFlyMouseDown = true;					 
		}
		function FlyMouseUpHadler(){
		    //bFlyMouseDown = false;
		    try{textBox.focus();}catch(e){}					 
		}			 			 
			 			 			 
		this.Refresh(); //@@@ init items
			 
		//@@@ init event handlers
		window.addEventListener ? textBox.addEventListener('keyup', TextBoxKeyDownHandler, false) : textBox.attachEvent('onkeyup', TextBoxKeyDownHandler);
		window.addEventListener ? textBox.addEventListener('change', TextBoxChangedHandler, false) : textBox.attachEvent('onchange', TextBoxChangedHandler);
		window.addEventListener ? textBox.addEventListener('click', TextBoxClickHandler, false) : textBox.attachEvent('onclick', TextBoxClickHandler);				    
        if(bHighlightInTextBox)
		     window.addEventListener ? textBox.addEventListener('focus', TextBoxFocusHandler, false) : textBox.attachEvent('onfocus', TextBoxFocusHandler);
		window.addEventListener ? textBox.addEventListener('blur', TextBoxBlurHandler, false) : textBox.attachEvent('onblur', TextBoxBlurHandler);			 				 
		if(icon != null) window.addEventListener ? icon.addEventListener('click', IconClickHandler, false) : icon.attachEvent('onclick', IconClickHandler);
		 
		window.addEventListener ? fly.addEventListener('mousedown', FlyMouseDownHadler, false) : fly.attachEvent('onmousedown', FlyMouseDownHadler);
		window.addEventListener ? fly.addEventListener('mouseup', FlyMouseUpHadler, false) : fly.attachEvent('onmouseup', FlyMouseUpHadler);    
		//window.addEventListener ? fly.addEventListener('scroll', FlyScrollHadler, false) : fly.attachEvent('onscroll', FlyScrollHadler);
				
		selectBox.DComboBoxControl = this;		 	      
}//@@@ class ComboBoxControl

function DComboBoxControl_FindSelectBox(selectBox){
    if(selectBox == null) return null;
    if(typeof(selectBox) == 'string') selectBox =  document.getElementById(selectBox);
    if(selectBox.DComboBoxControl == null) return null;
    return selectBox;
}

var DComboBoxControl_OnTheFlyHandlers = new Array();
var DComboBoxControl_iPpageOnLoadHandlerStatus = 0; var DComboBoxControl__bOperaIsInited = false;

function DComboBoxControl_pageOnLoad(){
   if(DComboBoxControl_iPpageOnLoadHandlerStatus == 2) return;
   if(window.opera){
      if(document.readyState != "complete" || DComboBoxControl__bOperaIsInited){
         return;
      }
      DComboBoxControl__bOperaIsInited = true;
   }   
   DComboBoxControl_iPpageOnLoadHandlerStatus = 2;
	 
   /*var selBoxCols = document.getElementsByTagName("SELECT");
	 for(var i=0; i<selBoxCols.length; i++){
      var oSelectBox = selBoxCols[i];//document.getElementById(selBoxCols[i]);
      if(oSelectBox!=null){
			    if(oSelectBox.style.display == "none"){
			       alert(oSelectBox.id + "\n" + oSelectBox.value + "\n" + oSelectBox.options[oSelectBox.selectedIndex].text);
             //oSelectBox.initControlFromPersistance();
					}
      }
   }*/
	 
   for(var i=0; i<DComboBoxControl_OnTheFlyHandlers.length; i++){
      var oHdl = DComboBoxControl_OnTheFlyHandlers[i];
	  oHdl();
   }
   DComboBoxControl_OnTheFlyHandlers.length = 0;
}

function DComboBoxControl_RegisterOnTheFlyHandler(handler){
   if(handler == null) return;
   if(typeof(handler) == "string" && handler != ""){
	   if(handler.indexOf("(") > 0)
	       handler = function(){eval(handler);}
	   else
		   handler = function(){eval(handler + "();");}		
   }
   if(typeof(handler) != "function") return;
				
   if(DComboBoxControl_iPpageOnLoadHandlerStatus == 2 || window.opera){
		handler();
   }else{
        if(true){
            DComboBoxControl_OnTheFlyHandlers.push(handler);            
            if(DComboBoxControl_iPpageOnLoadHandlerStatus == 0){
                DComboBoxControl_iPpageOnLoadHandlerStatus = 1;
                window.addEventListener ? window.addEventListener('load', DComboBoxControl_pageOnLoad, false) : window.attachEvent('onload', DComboBoxControl_pageOnLoad);
            }
        }else{
            window.addEventListener ? window.addEventListener('load', handler, false) : window.attachEvent('onload', handler);        
        }		
   }
}