var ddmLastMenuOpened;
			function dropDownMenu_onclickOutside( e ){
				if(!e) e = window.event;
	
				if(e.srcElement)
					var srcElement = e.srcElement;
				else
					var srcElement = e.target; 
				
				if( ddmLastMenuOpened && e != ddmLastMenuOpened.dropDownDiv){
					var p = srcElement;
					
					while( p.tagName != 'BODY'){
						if( p.className && p.className == 'dropDownDiv' ){
							return;
						}
						
						p = p.parentNode;
						
					}
					
					ddmLastMenuOpened.remove();
				}
			}

			//OnSmth functions
            function dropDownMenu_returnFalse(){
                return false;
            }

            function dropDownMenu_void(){
                return;
            }            
            
            function dropDownMenuElement_onmouseover(){
                this.elementObj.select();
            }

            function dropDownMenuElement_onmousedown(){
                this.elementObj.dropDownMenuObject.submit();
            }
            
            function dropDownMenuElement_onmouseout(){
                this.elementObj.deselect();
            }            
            // /OnSmth functions

            function dropDownMenu( inputObj, formObj, height ){
            }
            
            
            dropDownMenu.prototype.___construct = function( inputObj, formObj ){
                this.options = new Array();
                this.selectedIndex = false;                
                
                this.dropDownDiv = false;
                this.obj = inputObj;
                this.obj.dropDownMenu = this;
                
                this.form = formObj;
                this.form_onsubmit = this.form.onsubmit;
                
                this.timeoutRnd = '';
                this.prevValue = '';
                
                this.called = false;
                this.url = false;
                
                if( document.all ){
                    inputObj.onkeypress = function(){
                        if(keyPressedCode == 13 && typeof( this.dropDownMenu.selectedIndex ) != 'boolean' ){
                            this.dropDownMenu.onenter();
                            return false;
                        }
                    }
                }                
            }
            
            dropDownMenu.prototype.clear = function(){
                this.deselect();
                
                while(this.options.length)
                    this.options[0].remove();
                    
                this.options = new Array();
                this.selectedIndex = false;
            }
            
            dropDownMenu.prototype.create = function(){
                if( this.dropDownDiv ){
                    this.clear();
                }else{
                    this.dropDownDiv = document.createElement('DIV');
                    this.dropDownDiv.className = 'dropDownDiv';
                    
                    this.dropDownDiv.style.left = getX( this.obj );
                    this.dropDownDiv.style.top = getY( this.obj ) + this.obj.clientHeight;
                    
                    this.dropDownDiv.style.width = this.width ? this.width : this.obj.clientWidth;
                    this.dropDownDiv.style.height = this.height ? this.height : '200px';
                    this.dropDownDiv.style.overflow = 'auto';
                    
                    document.body.appendChild( this.dropDownDiv );
                    
                }
                
                this.form.onsubmit = dropDownMenu_returnFalse;
                
				ddmLastMenuOpened = this;
            	document.body.onmousedown = dropDownMenu_onclickOutside;
            }
            
            dropDownMenu.prototype.remove = function(){ 
                this._remove();
            }            
            
            dropDownMenu.prototype._remove = function(){ 
                if( typeof(this.dropDownDiv) == 'boolean' ){
                    return;
                }
                    
                this.deselect();
                this.clear();
                
                this.dropDownDiv.parentNode.removeChild( this.dropDownDiv );
                this.dropDownDiv = false;
                
                this.form.onsubmit = this.form_onsubmit;
                
                this.called = false;
                
                document.body.onmousedown = dropDownMenu_void;
                ddmLastMenuOpened = false;
            }
            
            dropDownMenu.prototype.deselect = function( text ){
                if( typeof(this.selectedIndex) == 'boolean' || !( typeof(this.options) == 'array' && this.options[ this.selectedIndex ]) ){
                    this.selectedIndex = false;
                    return;
                }
                
                this.options[ this.selectedIndex ].deselect();
            }
            
            dropDownMenu.prototype.add = function( text, value, html ){
                if( !html )
                    var html = false;
                    
                if( !value || value == false || value == null ){
                    var value = text;
                }

                var key = this.options.length;
                this.options[ key ] = new dropDownMenuElement( this, key, text, value, html );
            }
                 
            
            
            dropDownMenu.prototype.setUrl = function( url )
            {
                
                //alert( 123 );
                this.url = url;
            }
            
            
            dropDownMenu.prototype.setDataFromUrl = function()
            {
                if( !this.url )
                    return false;
                    
                    setLoaderOn( this.obj, true, 2 );
                    
                    var req = new JsHttpRequest();
                    
                    var ddmObj = this;
                    
                    req.onreadystatechange = function() {
                        if (req.readyState == 4) {
                            removeLoaderFrom( ddmObj.obj, true );
                            
                            if( req.responseJS && req.responseJS.variants && req.responseJS.variants.length ){
                                 ddmObj.create();
                                 
                                for( var i = 0; i < req.responseJS.variants.length; i++ ){
                                   ddmObj.add( req.responseJS.variants[i] );
                                }
                            }
                        }
                    }
                  
                    req.open(null, this.url, true);
                    req.send( {value: this.obj.value } );                    
            }            

                   
            function dropDownMenuElement( dropDownMenuObject, index, text, value ){
                this.dropDownMenuObject = dropDownMenuObject;
                
                this.index = index;
                this.value = value;
                this.selected = false;
                
                this.spanNode = document.createElement('SPAN');
                this.spanNode.elementObj = this;
                
                this.spanNode.className = 'dropDownElement';
                //if( html ){
                    var htmlDiv = document.createElement('DIV');
                    htmlDiv.innerHTML = text;
                    this.spanNode.appendChild( htmlDiv );
                /*}else{
                    this.spanNode.appendChild( document.createTextNode( text ) );
                }*/
                
                
                this.spanNode.onmouseover = dropDownMenuElement_onmouseover;
                this.spanNode.onmousedown = dropDownMenuElement_onmousedown;
                
                this.spanNode.onmouseout = dropDownMenuElement_onmouseout;
                
                this.dropDownMenuObject.dropDownDiv.appendChild( this.spanNode );
            }
            
            dropDownMenuElement.prototype.remove = function(){
                if( !this.spanNode )
                    return true;
                                    
                this.spanNode.parentNode.removeChild( this.spanNode )
                this.spanNode = null;
                
                var newOptions = new Array();
                
                for( var i = 0; i < this.dropDownMenuObject.options.length; i++){
                    var el = this.dropDownMenuObject.options[i];
                    if( el.spanNode ){
                        var key = newOptions.length;
                        newOptions[ key ] = el;
                        newOptions[ key ].index = key;
                    }
                }
                
                this.dropDownMenuObject.options = newOptions;
            }
            
            dropDownMenuElement.prototype.select = function(){
                if( typeof(this.dropDownMenuObject.selectedIndex) != 'boolean' 
                    && this.dropDownMenuObject.options[ this.dropDownMenuObject.selectedIndex ]){
                    
                        this.dropDownMenuObject.options[ this.dropDownMenuObject.selectedIndex ].deselect();
                }
                
                this.spanNode.className = this.spanNode.className + ' selected';
                this.dropDownMenuObject.selectedIndex = this.index;
            }
            
            dropDownMenuElement.prototype.deselect = function(){
                this.spanNode.className = this.spanNode.className.replace(' selected', '');
                this.dropDownMenuObject.selectedIndex = false;
            }
            
            
            dropDownMenu.prototype.up = function(){
                if( !this.options.length )
                    return;
                    
                var key;
                
                if( typeof(this.selectedIndex) == 'boolean' || this.selectedIndex == 0 )
                    key = this.options.length - 1;
                else
                    key = this.selectedIndex - 1
                    
                this.options[ key ].select();
            }            
            
            dropDownMenu.prototype.down = function(){
                if( !this.options.length )
                    return;
                    
                var key;
                
                if( typeof(this.selectedIndex) == 'boolean' || this.selectedIndex == (this.options.length - 1) )
                    key = 0;
                else
                    key = this.selectedIndex + 1;
                    
                this.options[ key ].select();
            }
            
            dropDownMenu.prototype.submit = function(){
                if( typeof(this.selectedIndex) == 'boolean' || !this.options[this.selectedIndex] ){
                    return;
                }
                                
                var v = this.options[ this.selectedIndex ].value;
                this.prevValue = trim(v);
                
                this.remove();
                
                this.obj.value = v;
                this.obj.focus();
                
                //inuptAutocomplite( this.obj );
            }
            
     
            dropDownMenu.prototype.setData = function( _timeoutRnd ){
                if( this.url )
                {
                    this.setDataFromUrl()
                }   
                else
                {
                    this.add(' укажи ');
                    this.add(' метод ');
                    this.add(' setData ');
                    this.add(' лентяй!! ');
                }
            }
            
            dropDownMenu.prototype.open = function( arg ){
            	
            	            	
                this.create();
                
                this.setData( arg );
                
                if( this.options.length == 0 ){
                    this.remove();             
                    return;
                }   
            }
            
            dropDownMenu.prototype.onkeyup = function( _timeoutRnd ){
                var v = trim( this.obj.value );

                if( _timeoutRnd ){
                    if( _timeoutRnd == this.timeoutRnd && v && this.prevValue != v){
                        this.open();    
                        this.prevValue = v;
                    }
                    
                    if(!v && this.dropDownDiv && !this.called){
                        this.remove();
                    }
                                        
                    return ;
                }
                
                this.timeoutRnd = Math.random();
                
                if( keyPressedCode == 38 ){ //up
                    this.up();
                    return;
                }

                if( keyPressedCode == 40 ){ //down
                    if( !this.dropDownDiv ){
                        this.open();
                        this.called = true;
                    }else{
                        this.down();
                    }
                    
                    return;
                }
                
                if( keyPressedCode == 13 ){ //enter
                    this.onenter();
                }
                
                if( keyPressedCode == 27 || keyPressedCode == 9 ){ //esc
                    this.remove();
                    return false;
                }
            }
            
            dropDownMenu.prototype.onenter = function(){
                    if(this.dropDownDiv == false)
                        return;
                        
                    this.submit();
                    return;                
            }
            
                        
            function getX( el ){
                var xPos;
                
                xPos = el.offsetLeft; 
                var tempEl = el.offsetParent; 
                
                while (tempEl != null)  
                { 
                      xPos += tempEl.offsetLeft; 
                      tempEl = tempEl.offsetParent; 
                } 
                
                return xPos; 
            }
            
            function getY( el ){
                var yPos;
                
                yPos = el.offsetTop; 
                var tempEl = el.offsetParent; 
                
                while (tempEl != null)  
                { 
                      yPos += tempEl.offsetTop; 
                      tempEl = tempEl.offsetParent; 
                } 
                
                return yPos; 
            }
            
            var keyPressedCode = false;
            
            function keyPresed(e) {
                var code;
                
                if (!e) e = window.event;
                
                if (e.keyCode) code = e.keyCode;
                else if (e.which) code = e.which;                

                keyPressedCode = code;                
            }             
            
            function trim( text ){
                return text.replace(/^[\s]+/, '').replace(/[\s]+$/, '');
            }            
            
            
            document.onkeydown = keyPresed;