

var __aspxLoadFilteredItemsCallbackPrefix = "CBLF";
var __aspxCorrectFilterCallbackPrefix = "CBCF";
var __aspxDropDownNameSuffix = "_DDD";
var __aspxCalendarNameSuffix = "_C";
var __aspxListBoxNameSuffix = "_L";
ASPxClientDropDownEdit = _aspxCreateClass(ASPxClientButtonEditBase, {
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);
        this.DropDown = new ASPxClientEvent();
        this.CloseUp = new ASPxClientEvent();
        
        this.ddHeightCache = __aspxInvalidDimension;
        this.ddWidthCache = __aspxInvalidDimension;
        this.dropDownButtonIndex = -1;
        this.droppedDown = false;
        this.lastSuccessText = "";

        aspxGetDropDownCollection().Add(this);
    },
    Initialize: function(){
        var pc = this.GetPopupControl();
        if(_aspxIsExists(pc))
            pc.allowCorrectYOffsetPosition = false;
        this.AssignClientAttributes();
        this.InitKeyboardInput();
        ASPxClientEdit.prototype.Initialize.call(this);
    },
    InitKeyboardInput: function(){
        var kbInput = this.GetInputElement();        
        if (_aspxIsExistsElement(kbInput)){
            _aspxAttachKBSupportEventsToElement(kbInput, this.name);
            this.lastSuccessText = kbInput.value;
        }
    },
    AssignClientAttributes: function(){
        var element = this.GetDropDownButton();
        if(_aspxIsExistsElement(element))
            _aspxPreventElementDragAndSelect(element, true);
    },
    GetDropDownButton: function(){
        return this.GetButton(this.dropDownButtonIndex);
    },
    GetPopupControl: function(){
        return aspxGetControlCollection().Get(this.name + __aspxDropDownNameSuffix);
    },
    GetDropDownInnerControlName: function(suffix){
        var pc = this.GetPopupControl();
        if(_aspxIsExists(pc))
            return this.GetPopupControl().name + suffix;
        return "";
    },
    GetDropDownHeight: function(){
        return 0;
    },
    GetDropDownWidth: function(){
        return 0;
    },
    ShowDropDownArea: function(isRaiseEvent){
		aspxGetDropDownCollection().RegisterDroppedDownControl(this);
		
        var pc = this.GetPopupControl();
        var element = this.GetMainElement();
        var pcwElement = pc.GetWindowElement(-1);
        
        _aspxSetElementDisplay(pcwElement, true);
        // Order is importante. Width with scroll bar dependance on Height
        var height = this.GetDropDownHeight();
        var width = this.GetDropDownWidth();
        if(this.ddHeightCache != height || this.ddWidthCache != width){
            pc.SetSize(width, height);
            this.ddHeightCache = height;
            this.ddWidthCache = width;
        }
        pc.popupVerticalOffset = - _aspxGetClientTop(element);
        pc.ShowAtElement(element);
        if(isRaiseEvent && _aspxIsExists(this.RaiseDropDown))
            this.RaiseDropDown();
        
        this.droppedDown = true;
    },
    HideDropDownArea: function(isRaiseEvent){
        var pc = this.GetPopupControl();
        if (_aspxIsExists(pc)){
            pc.Hide();
            if(isRaiseEvent && _aspxIsExists(this.RaiseCloseUp))
                this.RaiseCloseUp();
            aspxGetDropDownCollection().UnregisterDroppedDownControl(this);
            this.droppedDown = false;
        }
    },
    ProcessInternalButtonClick: function(number) {
        return this.dropDownButtonIndex == number;
    },
    ToggleDropDown: function(){
        this.OnApplyChanges();
        if(this.droppedDown)
            this.HideDropDownArea(true);
        else
            this.ShowDropDownArea(true);        
    },
    SetTextInternal: function(text){
        if(!this.readOnly)
            ASPxClientButtonEditBase.prototype.SetValue.call(this, text);
    },
    // base events
    OnValueChanged: function() {
        this.lastSuccessText = this.FindInputElement().value;
        ASPxClientEdit.prototype.OnValueChanged.call(this);
    },
    
    OnApplyChanges: function(){
    },
    OnCancelChanges: function(){
        this.SetTextInternal(this.lastSuccessText);
    },
    OnClick: function(){
        this.SetFocus();
    },    
    OnDropDown: function(evt) { 
        this.ToggleDropDown();
        return this.droppedDown ? _aspxCancelBubble(evt) : true;
    },
    OnDocumentMouseDown: function() {
        this.HideDropDownArea(true);
    },
    OnDocumentMouseUp: function() {
    },
    OnDDButtonMouseMove: function(evt){
    },
    OnCloseUp: function(evt){
        this.HideDropDownArea(true);
    },
    OnOpenAnotherDropDown: function(){
        this.HideDropDownArea(true);
    },
    OnTextChanged: function() {
        this.ParseValue();
    },
    
    // keyboard support
    OnArrowUp: function(evt){
        if(evt.altKey) {
            this.ToggleDropDown();
            return true;
        }
        return false;
    },
    OnArrowDown: function(evt){
        if(evt.altKey) {
            this.ToggleDropDown();
            return true;
        }
        return false;
    },    
    OnEscape: function(){
        this.OnCancelChanges();
        this.HideDropDownArea(true);
        return true;
    },
    // API
    RaiseCloseUp: function(){
        if(!this.CloseUp.IsEmpty()){
            var args = new ASPxClientEventArgs();
            this.CloseUp.FireEvent(this, args);
        }
    },
    RaiseDropDown: function(){
        if(!this.DropDown.IsEmpty()){
            var args = new ASPxClientEventArgs();
            this.DropDown.FireEvent(this, args);
        }
    },
    ShowDropDown: function(){
        this.ShowDropDownArea(false);
    },
    HideDropDown: function(){
        this.HideDropDownArea(false);
    }
});

ASPxClientDropDownCollection = _aspxCreateClass(ASPxClientCollection, {
    constructor: function(){
		this.constructor.prototype.constructor.call(this);
		
		this.droppedControlName = "";
		this.focusedControlName = "";
    },
    GetFocusedDropDown: function(){
        return this.Get(this.focusedControlName);
    },
    SetFocusedDropDownName: function(name){
        this.focusedControlName = name;
    },
    OnDDButtonMouseMove: function(evt){
        var dropDownControl = this.Get(this.droppedControlName);
        if(_aspxIsExists(dropDownControl))
            dropDownControl.OnDDButtonMouseMove(evt);
    },
    OnDocumentMouseDown: function(evt){
        this.CloseDropDownByDocumentEvent(evt, false);
        this.ClearFocusedDropDownByDocumentEvent(evt);
    },
    OnResize: function(evt){
        this.CloseDropDownByDocumentEvent(evt, true);
    },
    
    CloseDropDownByDocumentEvent: function(evt, isResize){
        var dropDownControl = this.Get(this.droppedControlName);
        if(_aspxIsExists(dropDownControl) && (this.IsEventNotFromControlSelf(evt, dropDownControl) || isResize))
            dropDownControl.OnDocumentMouseDown();
    },
    ClearFocusedDropDownByDocumentEvent: function(evt){
        var focusedDropDown = this.GetFocusedDropDown();
        if(_aspxIsExists(focusedDropDown) && this.IsEventNotFromControlSelf(evt, focusedDropDown))
            this.SetFocusedDropDownName("");        
    },
    IsEventNotFromControlSelf: function(evt, control){
        // Prevent DocumentOnClick event fired by the DropDown control and DropDownElement(Mozilla only) click
        var srcElement = _aspxGetEventSource(evt);
        var popupControl = control.GetPopupControl();
        return (srcElement == null || !_aspxIsExists(popupControl) || (srcElement != null && _aspxGetParentById(srcElement, control.GetMainElement().id) == null &&
            _aspxGetParentById(srcElement, popupControl.GetWindowElementId(-1)) == null));
    },
    OnDocumentMouseUp: function(evt){
        var dropDownControl = this.Get(this.droppedControlName);
        if(_aspxIsExists(dropDownControl))
            dropDownControl.OnDocumentMouseUp();
    },
    RegisterDroppedDownControl: function(dropDownControl){
        var previousDropDownControl = this.Get(this.droppedControlName);
        if(_aspxIsExists(previousDropDownControl))
            previousDropDownControl.OnOpenAnotherDropDown();
        this.droppedControlName = dropDownControl.name;
    },
    UnregisterDroppedDownControl: function(dropDownControl){
        if(this.droppedControlName == dropDownControl.name)
            this.droppedControlName = "";
    }
});
ASPxClientDateEdit = _aspxCreateClass(ASPxClientDropDownEdit, {
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);
        this.dateFormatter = new ASPxDateFormatter();        
        this.calendarMainElementOnClick = null;        
        
        //set from server        
        this.date = null;        
        this.dateOnError = "u";
        this.allowNull = true;
        this.calendarOwnerName = null;
        this.DateChanged = new ASPxClientEvent();
    },
    Initialize: function() {
        var calendar = this.GetCalendar();
        if(_aspxIsExists(calendar)) {
			this.calendarMainElementOnClick = _aspxCreateEventHandlerFunction("aspxEdDECMainElementClick", this.name);            
            if (__aspxNS)
                calendar.GetMainElement().style.borderCollapse = "separate";
        }
        ASPxClientDropDownEdit.prototype.Initialize.call(this);
    },
        
    ShowDropDownArea: function(isRaiseEvent){
        var cal = this.GetCalendar();
        if(_aspxIsExists(cal))            
            cal.SetValue(this.date);
        cal.forceMouseDown = true;
        __aspxActiveCalendar = cal;
        
		cal.SelectionChanging.ClearHandlers();
		cal.SelectionChanging.AddHandler(ASPxClientDateEdit.CreateDelegate(this, this.OnCalendarSelectionChanging));
		
		cal.MainElementClick.ClearHandlers();
		cal.MainElementClick.AddHandler(this.calendarMainElementOnClick);
        
        ASPxClientDropDownEdit.prototype.ShowDropDownArea.call(this, isRaiseEvent);        
    },    	  
    GetPopupControl: function() { // overriden
		var calendarOwner = this.GetCalendarOwner();
		if(calendarOwner != null)
			return calendarOwner.GetPopupControl();
		return ASPxClientDropDownEdit.prototype.GetPopupControl.call(this);
    },    
    GetCalendar: function() {    
        var name = this.GetDropDownInnerControlName(__aspxCalendarNameSuffix);
        return aspxGetControlCollection().Get(name);
    },
    GetCalendarOwner: function() {
		if(!this.calendarOwnerName)
			return null;
		return aspxGetControlCollection().Get(this.calendarOwnerName);
    },
    GetFormattedDate: function() {
        if(!this.date)
            return "";
        return this.dateFormatter.Format(this.date);
    },
    RaiseValueChangedEvent: function() {
        var processOnServer = ASPxClientEdit.prototype.RaiseValueChangedEvent.call(this);
        if(_aspxIsExists(this.RaiseDateChanged))
            processOnServer = this.RaiseDateChanged(processOnServer);
        return processOnServer;
    },
    OnApplyChanges: function(){
        this.OnTextChanged();
    },
    OnCalendarSelectionChanging: function(sender, e) {
        if(!this.GetCalendar().isDateChangingByKeyboard) {
            this.HideDropDownArea(true);
            var date = null;
            if (_aspxIsExists(e.selection))
                date = e.selection.GetFirstDate();
            else
                date = this.GetCalendar().GetValue();
                
            if(date != null && this.date != null) {
                date.setHours(this.date.getHours());
                date.setMinutes(this.date.getMinutes());
                date.setSeconds(this.date.getSeconds());
                date.setMilliseconds(this.date.getMilliseconds());
            }         
            this.ChangeDate(date);
            this.SelectInputElement();
        }
    },
    OnCalendarMainElementClick: function() {
        this.SetFocus();
    },
    OnDropDown: function(evt){
        this.SetFocus();
        return ASPxClientDropDownEdit.prototype.OnDropDown.call(this, evt);
    },
    
    // KeyBoard support
    OnKeyDown: function(evt){
        return false;
    },
    OnArrowUp: function(evt){
        var isProcessed = ASPxClientDropDownEdit.prototype.OnArrowUp.call(this, evt);
        if (!isProcessed && this.IsDropDownCalendarActive())
            this.GetCalendar().OnArrowUp(evt);
        return true;
    },
    OnArrowDown: function(evt){
        var isProcessed = ASPxClientDropDownEdit.prototype.OnArrowDown.call(this, evt);
        if (!isProcessed && this.IsDropDownCalendarActive())
            this.GetCalendar().OnArrowDown(evt);
        return true;
    },
    OnArrowLeft: function(evt){
        if (this.IsDropDownCalendarActive()) {
            this.GetCalendar().OnArrowLeft(evt);
            return true;
        }
        return false;
    },
    OnArrowRight: function(evt){
        if (this.IsDropDownCalendarActive()) {    
            this.GetCalendar().OnArrowRight(evt);
            return true;
        }
        return false;
    },
    
    OnPageUp: function(evt){
        if (this.IsDropDownCalendarActive()) {    
            this.GetCalendar().OnPageUp(evt);
            return true;
        }
        return false;        
    },
    OnPageDown: function(evt){
        if (this.IsDropDownCalendarActive()) {
            this.GetCalendar().OnPageDown(evt);
            return true;
        }
        return false;        
    },
    OnEndKeyDown: function(evt) {
        if (this.IsDropDownCalendarActive()) {
            this.GetCalendar().OnEndKeyDown(evt);
            return true;
        }
        return false;
    },
    OnHomeKeyDown: function(evt) {
        if (this.IsDropDownCalendarActive()) {
            this.GetCalendar().OnHomeKeyDown(evt);
            return true;
        }
        return false;    
    },
    
    OnEnter: function() {
        var isProcessed = false; // hack for defaultbutton
        if (this.droppedDown) {
            if (this.GetCalendar().IsFastNavigationActive())
                this.GetCalendar().GetFastNavigation().Hide();
            else
                this.OnCalendarSelectionChanging(null);
            isProcessed = true;
        }
        else
            this.OnApplyChanges();
        return isProcessed;
    },
    OnEscape: function() {
        if (this.GetCalendar().IsFastNavigationActive())
            this.GetCalendar().OnEscape();
        else
            return ASPxClientDropDownEdit.prototype.OnEscape.call(this);
        return true;
    },
        
    ParseValue: function() {
        var value = ASPxClientButtonEditBase.prototype.GetValue.call(this);
        if(value == null || value == "") {
            this.allowNull ? this.ChangeDate(null) : this.UpdateDateEditInputs();
        } else {
            var date = this.ParseDate(value);
            if(!date || !this.GetCalendar().IsDateInRange(date)) {
                switch(this.dateOnError) {
                    case "n":
						this.allowNull ? this.ChangeDate(null) : this.UpdateDateEditInputs();
						break;
                    case "t":
                        this.ChangeDate(new Date());
                        break;
                    default:
						this.UpdateDateEditInputs();                        
                        break;
                }
            } else
                this.ChangeDate(date);
        }
    },
    ParseDate: function(str) {
        return this.dateFormatter.Parse(str);
    },
    
    GetValue: function() {
        return this.date;
    },    
    GetValueString: function() {
		if(this.date == null)
			return null;
		var result = ASPxClientCalendar.GetInvariantDateString(this.date);
		// time
		var time = { 
			h: this.date.getHours(),
			m: this.date.getMinutes(),
			s: this.date.getSeconds()
		};
		for(var key in time) {		
			var str = time[key].toString();
			if(str.length < 2)
				str = "0" + str;				
			time[key] = str;			
		}		
		result += " " + time.h + ":" + time.m + ":" + time.s;
		var msec = this.date.getMilliseconds();
		if(msec > 0)
			result += "." + msec.toString();		
		return result;
    },
    SetValue: function(date) {        
        this.date = date;
        this.UpdateDateEditInputs();        
    },
    UpdateDateEditInputs: function() {        
		ASPxClientButtonEditBase.prototype.SetValue.call(this, this.GetFormattedDate());
		var input = this.GetTimestampInput();
		if(input != null)		
			input.value = this.date == null ? "N" : this.date.valueOf() - 60000 * this.date.getTimezoneOffset();
    },
    GetTimestampInput: function() {
		return _aspxGetElementById(this.name + "_TS");
    },    
    ChangeDate: function(date) {
        var oldDate = this.date;
        this.SetValue(date);
        if(!this.AreDatesEqualExact(oldDate, date)) {
            this.RaisePersonalStandardValidation();
            this.OnValueChanged();
        }        
    },
    AreDatesEqualExact: function(date1, date2) {
        if(date1 == null && date2 == null)
            return true;
        if(date1 == null || date2 == null)
            return false;
        return date1.getTime() == date2.getTime();
    },
    IsDropDownCalendarActive: function() {
        return this.droppedDown && !this.GetCalendar().IsFastNavigationActive();
    },
    // API
    RaiseDateChanged: function(processOnServer) {
        if(!this.DateChanged.IsEmpty()) {
            var args = new ASPxClientProcessingModeEventArgs(processOnServer);
            this.DateChanged.FireEvent(this, args);
            processOnServer = args.processOnServer;
        }
        return processOnServer;
    },
    SetDate: function(date) {
        this.SetValue(date);
    },
    GetDate: function() {
        return this.date;
    }
});

ASPxClientDateEdit.CreateDelegate = function(object, method) {
	function handler(sender, e) {
		method.call(object, sender, e);
	}
	return handler;		
}

__aspxCCValueInputSuffix = "VI";
ASPxClientComboBox = _aspxCreateClass(ASPxClientDropDownEdit, {
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);        
        this.SelectedIndexChanged = new ASPxClientEvent();
        
        this.filterTimerId = -1;
        this.lbEventLockCount = 0;
        
        // Callback
        this.allowMultipleCallbacks = false;
        this.isCallbackMode = false;
        this.isPerformCallback = false;
        this.changeSelectAfterCallback = 0;
        // Filtering
        this.isFilterEnabled = false;
        this.isEnterLocked = false;
        this.filter = "";
        
        this.isToolbarItem = false;
        this.isDropDownListStyle = true;
        this.dropDownHeight = "";
        this.dropDownWidth = "";
        this.readOnly = false;
        
        // Cashe
        this.listBox = null;
        this.lastSuccessValue = "";
        this.islastSuccessValueInit = false;
    },
    Initialize: function(){
        var lb = this.GetListBoxControl();
        if(_aspxIsExists(lb))
            lb.ownerName = this.name;
        
        var mainElement = this.GetMainElement();
        if(_aspxIsExists(ddbutton))
            _aspxAttachEventToElement(mainElement, __aspxNS ? "DOMMouseScroll" : "mousewheel", aspxCBMouseWheel);    
        var input = this.FindInputElement();
        var ddbutton = this.GetDropDownButton();
        if(_aspxIsExists(ddbutton))
            _aspxAttachEventToElement(ddbutton, "mousemove", aspxCBDDButtonMMove);
        if(this.isFilterEnabled)
            _aspxAttachEventToElement(input, "keyup", aspxCBKeyUp);
        if(this.isDropDownListStyle && __aspxIE){
            _aspxPreventElementDragAndSelect(mainElement, true);
            _aspxPreventElementDragAndSelect(input, true);
            if(_aspxIsExists(ddbutton))
                _aspxPreventElementDragAndSelect(ddbutton, true);
        }
        if(this.isToolbarItem){
            mainElement.unselectable="on";
            input.unselectable="on";
            if(_aspxIsExists(input.offsetParent))
                input.offsetParent.unselectable="on";
            if(_aspxIsExists(ddbutton))
                ddbutton.unselectable="on";
            if(_aspxIsExists(lb)){
                var table = lb.GetListTable();
                for(var i = 0; i < table.rows.length; i ++){
                    for(var j = 0; j < table.rows[i].cells.length; j ++){
                        table.rows[i].cells[j].unselectable="on";
                    }
                }
            }
        }
        
        this.RemoveRaisePSValidationFromListBox();
        this.RedirectStandardValidators();
        this.UpdateValueInput();
        this.InitDropDownSize();
        
        ASPxClientDropDownEdit.prototype.Initialize.call(this);
    },
        
    CorrectSizeCore: function() {
        ASPxClientEdit.prototype.CorrectSizeCore.call(this);
        this.ddHeightCache = __aspxInvalidDimension;
        this.ddWidthCache = __aspxInvalidDimension;
    },
    EnableStyleControllerForDDButton: function(){
        var element = this.GetDropDownButton();
        if(_aspxIsExists(element)){
            var controller = aspxGetStateController();
            this.ReplaceElementControlStyleItem(controller.hoverItems, element, this.ddButtonHoverStyle);
            this.ReplaceElementControlStyleItem(controller.pressedItems, element, this.ddButtonPressedStyle);
            this.ReplaceElementControlStyleItem(controller.selectedItems, element, this.ddButtonSelectedStyle);
        }
    },
    DisableStyleControllerForDDButton: function(){
        var element = this.GetDropDownButton();
        if(_aspxIsExists(element)){
            var controller = aspxGetStateController();
            this.ddButtonHoverStyle = this.ReplaceElementControlStyleItem(controller.hoverItems, element, null);
            this.ddButtonPressedStyle = this.ReplaceElementControlStyleItem(controller.pressedItems, element, null);
            this.ddButtonSelectedStyle = this.ReplaceElementControlStyleItem(controller.selectedItems, element, null);
        }
    },
    ReplaceElementControlStyleItem: function(items, element, newStyleItem){
        var styleItem = items[element.id];
        items[element.id] = newStyleItem;
        return styleItem;
    },
    
    RemoveRaisePSValidationFromListBox: function() {
        var listBox = this.GetListBoxControl();
        if (_aspxIsExists(listBox))
            listBox.RaisePersonalStandardValidation = function() { };
    },
    RedirectStandardValidators: function() {
        var valueInput = this.GetValueInput();
        if(_aspxIsExistsElement(valueInput) && _aspxIsExists(valueInput.Validators)) {
            for(var i = 0; i < valueInput.Validators.length; i++)
                valueInput.Validators[i].controltovalidate = valueInput.id;
        }
    },
    DropDownButtonPush: function(){
        if(__aspxIE || __aspxOpera) 
            this.DropDownButtonPushCommon();
        else
            this.DropDownButtonPushMozilla();
    },
    DropDownButtonPop: function(){
        if(__aspxIE || __aspxOpera) 
            this.DropDownButtonPopCommon();
        else
            this.DropDownButtonPopMozilla();
    },
    DropDownButtonPushCommon: function(){
        if(this.droppedDown) return;
        var buttonElement = this.GetDropDownButton();
        if(_aspxIsExists(buttonElement)){
            var controller = aspxGetStateController();
            controller.SetCurrentHoverElement(null);
            var element = controller.GetPressedElement(buttonElement);
            if(_aspxIsExists(element))
                controller.DoSetPressedState(element);
        }
    },
    DropDownButtonPopCommon: function(){
        if(!this.droppedDown) return;
        var buttonElement = this.GetDropDownButton();
        if(_aspxIsExists(buttonElement)){
            var controller = aspxGetStateController();
            var element = controller.GetPressedElement(buttonElement);
            if(_aspxIsExists(element))
                controller.DoClearPressedState(element);
        }
    },
    DropDownButtonPushMozilla: function(){
        if(this.droppedDown) return;
        this.DisableStyleControllerForDDButton();
        var controller = aspxGetStateController();
        controller.savedCurrentPressedElement = null;
    },
    DropDownButtonPopMozilla: function(){
        if(!this.droppedDown) return;
        this.EnableStyleControllerForDDButton();
        var controller = aspxGetStateController();
        var buttonElement = this.GetDropDownButton();
        if(_aspxIsExists(buttonElement)){
            var element = controller.GetPressedElement(buttonElement);
            if(_aspxIsExists(element))
                controller.DoClearPressedState(element);
            controller.currentPressedElement = null;
            element = controller.GetHoverElement(buttonElement);
            if(_aspxIsExists(element))
                controller.SetCurrentHoverElement(element);
        }
    },
    FindItemIndexByText: function(lb, text){
        if (!_aspxIsExists(lb)) return;
        for(var i = 0; i < lb.GetItemCount(); i ++){
            if(lb.GetItem(i).text == text)
                return i;
        }
        return -1;
    },
    GetValueInputToValidate: function(){
        return this.GetValueInput();
    },
    GetValueInput: function(){
        return document.getElementById(this.name + "_" + __aspxCCValueInputSuffix);
    },
    GetListBoxControl: function(){
        if(!_aspxIsExistsElement(this.listBox)){
            var name = this.GetDropDownInnerControlName(__aspxListBoxNameSuffix);
            this.listBox = aspxGetControlCollection().Get(name);
        }
        return this.listBox;
    },
    GetListBoxScrollDivElement: function(){
        return this.GetListBoxControl().GetScrollDivElement();
    },
    GetDropDownHeight: function(){
        return (this.ddHeightCache != __aspxInvalidDimension) ? this.ddHeightCache : this.InitListBoxHeight();
    },
    GetDropDownWidth: function(){
        return (this.ddWidthCache != __aspxInvalidDimension) ? this.ddWidthCache : this.InitListBoxWidth();
    },
    SetText: function (text){
        var lb = this.GetListBoxControl();
        var index = this.FindItemIndexByText(lb, text);
        this.SelectIndex(index);
        this.SetTextInternal(text);
        this.lastSuccessText = text;
        this.lastSuccessValue = index >= 0 ? lb.GetValue() : text;
        this.islastSuccessValueInit = true;
    },
    GetValue: function(){
        return this.islastSuccessValueInit ? this.lastSuccessValue : this.GetValueInternal();
    },
    GetValueInternal: function(){
        var text = ASPxClientDropDownEdit.prototype.GetValue.call(this);
        var lb = this.GetListBoxControl();
        if (_aspxIsExists(lb)){
            var index = this.FindItemIndexByText(lb, text);
            lb.SelectIndex(index, false); // Prevent to direct input value changing
            if(index != -1)
                return lb.GetValue();
        }
        return text;
    },
    SetValue: function(value){
        var lb = this.GetListBoxControl();
        lb.SetValue(value);
        // TODO Extract method with OnSelectChanged (params: value)
        var item = lb.GetSelectedItem();
        var text = _aspxIsExists(item) ? item.text : value;
        this.SetTextInternal(text);
        this.lastSuccessText = text;
        this.lastSuccessValue = item != null ? item.value : text;
        this.islastSuccessValueInit = true;
        
        this.UpdateValueInput();
        //
    },
    UpdateValueInput: function() {
        var input = this.GetValueInput();
        var value = this.GetValue();
        input.value = value != null ? value : "";
    },
    
    CollectionChanged: function(){
        if(this.GetListBoxControl().APILockCount == 0)
            this.InitDropDownSize();
    },
    InitDropDownSize: function(){
        var pc = this.GetPopupControl();
        if(_aspxIsExists(pc) && this.IsDisplayed()) {
            var pcwElement = pc.GetWindowElement(-1);
            if(_aspxIsExistsElement(pcwElement)){
                var isPcwDisplayad = _aspxGetElementDisplay(pcwElement);
                if(!isPcwDisplayad)
                    pc.SetWindowDisplay(-1, true);
                this.ddHeightCache = this.InitListBoxHeight();
                this.ddWidthCache = this.InitListBoxWidth();
                pc.SetSize(this.ddWidthCache, this.ddHeightCache);
                if(!isPcwDisplayad)
                    pc.SetWindowDisplay(-1, false);
            }
        }
    },
    InitListBoxHeight: function(){
        var lbScrollDiv = this.GetListBoxScrollDivElement();
        var height = this.dropDownHeight;
        var lb = this.GetListBoxControl();
        lb.GetMainElement().style.height = "0px";
        var lbHeight = 0;
        if(height == ""){
            var listHeight = lb.GetListTableHeight();
            var count = lb.GetItemCount();
            if(count > 7)
                height = ((listHeight / count) * 7) + "px";
            else
                height = count == 0 ? "0px" : listHeight + "px";
            lbScrollDiv.style.height = height;
            lbHeight = lbScrollDiv.offsetHeight;
        } else {
            var lbMainElement = lb.GetMainElement();
            lbMainElement.style.height = "0px";
            lbScrollDiv.style.height = "0px";
            lbMainElement.style.height = height;
            var trueLbOffsetHeight = lbMainElement.offsetHeight;
            var trueLbClientHeight = lbMainElement.clientHeight;
            lbScrollDiv.style.height = lbMainElement.clientHeight + "px";
            lbHeightCorrection = lbMainElement.offsetHeight - trueLbOffsetHeight;
            lbScrollDiv.style.height = (trueLbClientHeight - lbHeightCorrection) + "px";
            lbHeight = lbMainElement.offsetHeight;
        }
        lb.InitializePageSize();
        return lbHeight;
    },
    InitListBoxWidth: function(){
        var mainElement = this.GetMainElement();
        var lb = this.GetListBoxControl();
        var lbMainElement = lb.GetMainElement();
        var lbScrollDiv = this.GetListBoxScrollDivElement();
        var lbTable = lb.GetListTable();
        lbMainElement.style.width = "";
        lbScrollDiv.style.width = "100%";
        
        if(this.dropDownWidth != ""){
            lbMainElement.style.width = this.dropDownWidth;
            lbScrollDiv.style.width = lbMainElement.clientWidth + "px";
            var difference = lbTable.offsetWidth - lbScrollDiv.clientWidth;
            if(!__aspxIE && difference > 0){
                lbMainElement.style.width = (lbMainElement.offsetWidth + difference) + "px";
                lbScrollDiv.style.width = (lbMainElement.clientWidth)  + "px";
            }
        }
        else {
            var pc = this.GetPopupControl();
            var width = lbTable.offsetWidth;
            var scrollWidth = lb.GetVerticalScrollBarWidth();
            var isBrowserPutScrollOnContent = !__aspxIE || __aspxIE55;
            var isBrowserAbleAnimScroll = !__aspxMozilla || __aspxFirefox || !pc.enableAnimation;
            if(isBrowserPutScrollOnContent && isBrowserAbleAnimScroll)
                width += scrollWidth;
            lbScrollDiv.style.width = width + "px";
            if(__aspxFirefox && lbMainElement.offsetWidth < lbScrollDiv.offsetWidth)
                lbMainElement.style.width = "0%"; // FIX B19014
            var widthDifference = mainElement.offsetWidth - lbMainElement.offsetWidth;
            if(widthDifference > 0){
                lbScrollDiv.style.width = (width + widthDifference) + "px";
                var twoBorderSize = (lbMainElement.offsetWidth - lbMainElement.clientWidth);
                lbMainElement.style.width = (width + widthDifference + twoBorderSize) + "px"; // prevent lbMainElement size hover ScrollBar
            }
        }
        return lbScrollDiv.offsetWidth;
    },
    SelectIndex: function(index){
        var lb = this.GetListBoxControl();
        var isSelectionChanged = lb.SelectIndex(index, false);
        var item = lb.GetSelectedItem();
        var text = item != null ? item.text : "";
        
        if(isSelectionChanged){
            this.SetTextInternal(text);
            this.lastSuccessText = text;
            this.lastSuccessValue = item != null ? item.value : text;
            this.islastSuccessValueInit = true;
        }
        return isSelectionChanged;
    },
    SelectIndexSilent: function(lb, index){
        this.lbEventLockCount ++;
        lb.SelectIndexInternal(index);
        this.lbEventLockCount --;
    },
    SelectInputText: function(){
        var input = this.GetInputElement();
        _aspxSetInputSelection(input, 0, input.value.length);
    },
    ShowDropDownArea: function(isRaiseEvent){
        var lb = this.GetListBoxControl();
        if(!_aspxIsExists(lb) || lb.GetItemCount() == 0) 
            return;
        var pc = this.GetPopupControl();


        ASPxClientDropDownEdit.prototype.ShowDropDownArea.call(this, isRaiseEvent);
        if(__aspxMozilla && pc.enableAnimation) {// Prevent mozilla wrong animation
            this.DisableLBDivOverflow();
            window.setTimeout(aspxCBMozillaOverflowOn, pc.animationMaxDelay / 2, this.name);
        }
        
        var text = ASPxClientDropDownEdit.prototype.GetValue.call(this);
        var lbItem = lb.GetSelectedItem();
        var lbText = lbItem != null ? lbItem.text : "";
        if(text != lbText && text != null && lbText != ""){
            var newSelectedIndex = this.FindItemIndexByText(lb, text);
            lb.SelectIndex(newSelectedIndex, false);
        }
        lb.EnsureSelectedItemVisible();
        lb.CallbackSpaceInit();
    },
    HideDropDownArea: function(isRaiseEvent){
        this.DropDownButtonPop();
        this.FilteringStop();
        ASPxClientDropDownEdit.prototype.HideDropDownArea.call(this, isRaiseEvent);
    },
    EnableLBDivOverflow: function(){
        var divElement = this.GetListBoxScrollDivElement();
        divElement.style.overflow = "auto";
    },
    DisableLBDivOverflow: function(){
        var divElement = this.GetListBoxScrollDivElement();
        divElement.style.overflow = "hidden";
    },
    // Filtering
    OnFiltering: function(evt){
        if(this.isFilterEnabled && evt.keyCode != 16 && !evt.ctrlKey && !evt.altKey){
            _aspxClearTimer(this.filterTimerId);
            var input = this.FindInputElement();
            var newFilter = input.value.toLowerCase();
            if(evt.keyCode == 8 && _aspxHasInputSelection(input) && newFilter == this.filter)
                this.FilteringBackspace(false);
            else if(this.IsFilterKeycode(evt.keyCode))
                this.FilterByTimer();
        }
    },
    FilterByTimer: function(){
        this.isEnterLocked = true;
        this.filterTimerId = _aspxSetTimeout("aspxCBFilterByTimer('" + this.name + "')", 100);
    },
    EnshureShowDropDownArea: function(){
        if(!this.droppedDown)
            this.ShowDropDownArea(true);
    },
    Filtering: function(){
        var input = this.FindInputElement();
        var newFilter = input.value.toLowerCase();
        if(this.filter != newFilter || newFilter == "" || this.isDropDownListStyle){
            this.filter = newFilter;
            this.EnshureShowDropDownArea();
            
            if(this.isCallbackMode)
                this.FilteringOnServer();
            else
                this.FilteringOnClient(input); 
        } else 
            this.isEnterLocked = false;
    },
    FilteringBackspace: function(isBefore){
        if(this.isFilterEnabled){
            var input = this.FindInputElement();
            if(!isBefore){
                var text = input.value;
                var newInput = text.substring(0, text.length - 1);
                input.value = newInput;
                this.FilterByTimer();
            } 
            return _aspxHasInputSelection(input);
        }
        return false;
    },
    GetCallbackArguments: function(){
        var args = this.GetCallbackArgumentsChild();
        if(this.isCallbackMode)
            args += this.GetCallbackArgumentsInternal();
        return args;
    },
    GetCallbackArgumentsInternal: function(){
        var args = "";
        if(this.filter != "")
            args = this.GetCallbackArgumentFilter(this.filter);
        return args;
    },
    GetCallbackArgumentFilter: function(value){
        var callbackPrefix = this.isDropDownListStyle ? __aspxCorrectFilterCallbackPrefix : __aspxLoadFilteredItemsCallbackPrefix;
        return this.FormatCallbackArg(callbackPrefix, value);
    },
    GetCallbackArgumentsChild: function(){
        var lb = this.GetListBoxControl();
        return lb.GetCallbackArguments();
    },
    FilteringOnServer: function(){
        if(!this.InCallback()){
            this.GetListBoxControl().ClearItems();
            this.SendCallback();
        }
    },
    FilteringOnClient: function(input){
        var filter = this.filter.toLowerCase();
        var lb = this.GetListBoxControl();
        var listTable = lb.GetListTable();
        var count = lb.GetItemCount();
        var text = "";
        var isSatisfy = false;
        var isFirstSatisfyItemFinded = false;
        
        if(this.isDropDownListStyle){
            var coincide = new Array(count);
            var maxCoincide = 0;
            for(var i = count - 1; i >= 0; i--) {
                coincide[i] = this.GetCoincideCharCount(lb.GetItem(i).text.toLowerCase(), filter);
                if(coincide[i] > maxCoincide)
                    maxCoincide = coincide[i];
            }
            filter = filter.substr(0, maxCoincide);
            this.GetInputElement().value = filter;
        }
        for(var i = 0; i < count; i ++){
            text = lb.GetItem(i).text; //TODO create able to get server-cached text
            isSatisfy = this.isDropDownListStyle ? (coincide[i] == maxCoincide) : 
                (text.toLowerCase().indexOf(filter) == 0);
            _aspxSetElementDisplay(listTable.rows[i], isSatisfy);
            if(!isFirstSatisfyItemFinded && isSatisfy){
                var isTextClearing = !this.isDropDownListStyle && this.filter == "" && this.filter != text;
                if(!isTextClearing)
                    this.FilteringHighlightComplitedText(i, text);
                this.SelectIndexSilent(lb, isTextClearing ? -1 : i);
                isFirstSatisfyItemFinded = true;
            }
        }
        if(this.isDropDownListStyle)
            this.filter = filter;
        if(!isFirstSatisfyItemFinded)
            this.HideDropDownArea(true);
        this.isEnterLocked = false;
    },
    GetCoincideCharCount: function(text, filter) {
        while(filter != "" && text.indexOf(filter) != 0) {
            filter = filter.slice(0, -1);
        }
        return filter.length;
    },
    FilteringHighlightComplitedText: function(index, filterItemText){
        var lb = this.GetListBoxControl();
        var input = this.FindInputElement();
        var text = input.value;
        var valueLenght = text.length;
        var itemTextLenght = filterItemText.length;
        
        input.value = filterItemText;
        _aspxSetInputSelection(input, valueLenght, itemTextLenght);
    },
    FilteringStop: function(){
        if(this.isFilterEnabled){
            this.isEnterLocked = false;
            if(!this.isCallbackMode)
                this.FilteringStopClient();
        }
    },
    FilteringStopClient: function(){
        var lb = this.GetListBoxControl();
        var listTable = lb.GetListTable();
        var count = lb.GetItemCount();
        for(var i = 0; i < count; i ++)
            _aspxSetElementDisplay(listTable.rows[i], true);
    },
    IsFilterKeycode: function(keyCode){
        return keyCode == 8 || keyCode == 32 || keyCode > 45;
    },
    // LoadingPanel
    ShowLoadingPanel: function() {    
        var lb = this.GetListBoxControl();
        var loadingParentElement = lb.GetScrollDivElement().parentNode;
        this.loadingDivElement = this.CreateLoadingDiv(loadingParentElement);
        this.loadingPanelElement = this.CreateLoadingPanelWithAbsolutePosition(loadingParentElement, loadingParentElement);
    },
    HideLoadingPanel: function() {
        if(_aspxIsExistsElement(this.loadingPanelElement)) {
            this.loadingPanelElement.parentNode.removeChild(this.loadingPanelElement);                        
            this.loadingPanelElement = null;
        }
        if(_aspxIsExistsElement(this.loadingDivElement)){
            this.loadingDivElement.parentNode.removeChild(this.loadingDivElement);
            this.loadingDivElement = null;
        }
    },
    // CallbackMode
    FormatCallbackArg: function(prefix, arg) { // REFACTOR with ASPxGrigView, replace to Callback.js
        if(arg == null) return "";
        if(!_aspxIsExists(arg.length) && _aspxIsExists(arg.value)) {
            arg = arg.value;
        }
        if(arg == null || arg == "") return "";
        return prefix + "|" + arg.length + ';' + arg + ';';
    },
    OnAfterCallback: function(){
        this.CollectionChanged();
        this.HideLoadingPanel();
        this.isPerformCallback = false;
    },
    OnCallback: function(result) {
        this.GetListBoxControl().OnCallback(result);
        this.OnCallbackInternal(result);
        this.OnAfterCallback();
    },
    OnCallbackError: function(result){
        this.GetListBoxControl().OnCallbackError(result);
        this.OnAfterCallback();
    },
    OnCallbackInternal: function(result){
        this.OnFilterCallback(result);
        if(this.changeSelectAfterCallback > 0){
            var lb = this.GetListBoxControl();
            this.SelectNeighbourInternal(lb, lb.GetSelectedIndexInternal() + this.changeSelectAfterCallback);
            this.changeSelectAfterCallback = 0;
        }
    },
    OnFilterCallback: function(result){
        var lb = this.GetListBoxControl();
        if(lb.GetItemCount() > 0){
            var firstItemText = lb.GetItem(0).text;
            var isTextClearing = !this.isDropDownListStyle && this.filter == "" && this.filter != firstItemText;
            if(!isTextClearing){
                var isFilterRollBack = this.CheckForFilterRollback(lb, firstItemText);
                var isNonFilterChangingCallback = (lb.GetSelectedItem() == null);
                if(isFilterRollBack || isNonFilterChangingCallback){
                    this.FilteringHighlightComplitedText(0, firstItemText);
                    this.SelectIndexSilent(lb, 0);
                }
            }
            if(!this.isPerformCallback)
                this.EnshureShowDropDownArea();
        } else
            this.HideDropDownArea(true);
        this.isEnterLocked = false;
    },
    CheckForFilterRollback: function(lb, firstItemText){
        var isHasCorrection = false;
        var filter = this.filter.toLowerCase();
        firstItemText = firstItemText.toLowerCase();
        
        while(firstItemText.substring(0, filter.length).toLowerCase() != filter){
            filter = filter.slice(0, -1);
            isHasCorrection = true;
        }
        if(isHasCorrection){
            this.filter = this.filter.substring(0, filter.length);
            this.FindInputElement().value = this.filter;
        } 
        return isHasCorrection;
    },
    SendCallback: function(){
        this.ShowLoadingPanel();
        argument = this.GetCallbackArguments();
        this.CreateCallback(argument);
    },
    
    // Key Board support
    SelectNeighbour: function (step){
        if(this.isToolbarItem && !this.droppedDown) return;
        
        var lb = this.GetListBoxControl();
        var listTable = lb.GetListTable();
        var index = lb.GetSelectedIndexInternal();
        var count = lb.GetItemCount();
        if(count > 0){
            var isFirstPageDown = index == -1 && step == lb.scrollPageSize;
            var newIndex =  isFirstPageDown ? step : this.GetNeighbourIndex(listTable.rows, count, index, step);
            this.SelectNeighbourInternal(lb, newIndex);
            lb.ScrollToItemVisible(newIndex);
        }
    },
    SelectNeighbourInternal: function(lb, index){
        if(this.droppedDown){
            this.SelectIndexSilent(lb, index);
            this.SetTextInternal(lb.GetItem(index).text);
        } else 
            lb.SelectIndexInternal(index);
    },
    GetNeighbourIndex: function(rows, count, startIndex, step){
        var newIndex = startIndex + step;
        if(this.isFilterEnabled && !this.isCallbackMode){
            var stepOne = step > 0 ? 1 : -1;
            var outermostVisibleIndex = startIndex;
            for(var index = startIndex + stepOne; ; index += stepOne){
                if(index < 0 || count <= index){
                    newIndex = outermostVisibleIndex;
                    break;
                }
                if(_aspxGetElementDisplay(rows[index])){
                    outermostVisibleIndex = index;
                    if(index == newIndex)
                        break;
                } else
                    newIndex += stepOne;
            }
        } 
        
        if((step < 0 && newIndex < 0) || step < -count)
            newIndex = 0;
        if((step > 0 && newIndex >= count) || step > count){
            if(this.isCallbackMode){
                var lb = this.GetListBoxControl();
                var bottomSpaser = lb.GetBottomScrollSpacingElement();
                if(_aspxGetElementDisplay(bottomSpaser)){
                    this.changeSelectAfterCallback = 1;
                    lb.LoadNextItemsOnCallback();
                }
            } 
            newIndex = count - 1;
        }
        return newIndex;
    },   
    
    OnKBSKeyDown: function(evt){
        if(evt.keyCode != 16) // Shift will not affect filtering
            _aspxClearTimer(this.filterTimerId);
        if(evt.keyCode == 9){ 
            if(this.isFilterEnabled) // B91550 Tab sends KeyDown without KeyUp
                this.Filtering();
            this.OnApplyChangesAndCloseWithEvents();
        }
        return false;
    },
    OnArrowUp: function(evt){
        var isProcessed = ASPxClientDropDownEdit.prototype.OnArrowUp.call(this, evt);
        if (!isProcessed)
            this.SelectNeighbour(-1);
        return true;
    },
    OnArrowDown: function(evt){
        var isProcessed = ASPxClientDropDownEdit.prototype.OnArrowDown.call(this, evt);
        if (!isProcessed)
            this.SelectNeighbour(1);
        return true;
    },
    OnPageUp: function(){
        return this.OnPageButtonDown(false);
    },
    OnPageDown: function(){
        return this.OnPageButtonDown(true);
    },
    OnPageButtonDown: function(isDown){
        var lb = this.GetListBoxControl();
        if(_aspxIsExists(lb)){
            var direction = isDown ? 1 : -1;
            this.SelectNeighbour(lb.scrollPageSize * direction);
        }
        return true;
    },
    OnHomeKeyDown: function(evt){
        return this.OnHomeEndKeyDown(evt, true);
    },
    OnEndKeyDown: function(evt){
        return this.OnHomeEndKeyDown(evt, false);
    },
    OnHomeEndKeyDown: function(evt, isHome){
        var input = this.GetValueInput();
        if(input.readOnly || evt.ctrlKey){
            var lb = this.GetListBoxControl();
            var count = lb.GetItemCount();
            this.SelectNeighbour(isHome ? -count : count);
            return true;
        }
        return false;
    },
    OnEnter: function(){
        if(!this.isEnterLocked) //Prevent to extra fast push enter while filtering continue
            this.OnApplyChangesAndCloseWithEvents();
        return true;
    },

    OnApplyChanges: function(){
        if(this.isDropDownListStyle && !this.isFilterEnabled) return;
        this.OnApplyChangesInternal();
    },
    OnApplyChangesAndCloseWithEvents: function(){
        this.OnApplyChangesInternal();
        this.HideDropDownArea(true);
    },
    OnApplyChangesInternal: function(){
        this.filter = "";
        var text = this.FindInputElement().value;
        var isChanged = this.lastSuccessText != text;
        if(isChanged){
            var lb = this.GetListBoxControl();
            if(this.isDropDownListStyle && this.FindItemIndexByText(lb, text) < 0){
                var lbItem = lb.GetSelectedItem();
                text = lbItem != null ? lbItem.text : this.lastSuccessText;
            }
        } 
        this.SetText(text);
        if(isChanged)
            this.OnChange();
    },
    OnButtonClick: function(number){
        if(number != this.dropDownButtonIndex){
            this.HideDropDownArea(true);
        }
        ASPxClientButtonEditBase.prototype.OnButtonClick.call(this, number)
    },
    OnCancelChanges: function(){
        ASPxClientDropDownEdit.prototype.OnCancelChanges.call(this);
        this.filter = "";
        var lb = this.GetListBoxControl();
        var index = this.FindItemIndexByText(lb, this.lastSuccessText);
        this.SelectIndexSilent(lb, index)
    },
    OnChange: function(){
        this.UpdateValueInput();
        this.RaisePersonalStandardValidation();
        this.OnValueChanged();
    },
    OnCloseUp: function(evt){
        var evt = _aspxGetEvent(evt);
        if(__aspxFirefox && evt.type == "mouseup" && _aspxGetEventSource(evt).tagName == "DIV") // Prevent FF closing DropDownArea by DropDownArea ScrollBar MouseUp
            return;
        ASPxClientDropDownEdit.prototype.OnCloseUp.call(this, evt);
    },
    OnDDButtonMouseMove: function(evt){
        return (this.droppedDown ? _aspxCancelBubble(evt) : true);
    },
    OnDocumentMouseDown: function(){
        this.OnApplyChangesInternal();
        ASPxClientDropDownEdit.prototype.OnDocumentMouseDown.call(this);
    },
    OnDocumentMouseUp: function() {
        this.DropDownButtonPop();
    },
    OnDropDown: function(evt){
        this.SetFocus();
        var lb = this.GetListBoxControl();
        if(lb.GetItemCount() > 0)
            this.OnDropDownInternal(evt);
        return true;
    },
    OnDropDownInternal: function(evt){
        if(!this.droppedDown)
            this.DropDownButtonPush();
        return ASPxClientDropDownEdit.prototype.OnDropDown.call(this, evt);        
    },
    OnItemClick: function(){
        this.OnSelectChanged();
        this.OnClick();
    },
    OnListBoxClick: function(evt){
        if(!this.InCallback()){
            this.OnApplyChangesInternal();
            this.OnCloseUp(evt);
        }
    },
    OnMouseWheel: function(evt){
        if(!this.droppedDown){
            var wheelDelta = _aspxGetWheelDelta(evt);
            if(wheelDelta > 0)
			    this.SelectNeighbour(-1);
		    else  if(wheelDelta < 0)
			    this.SelectNeighbour(1);
			return _aspxPreventEvent(evt);
		}
    },
    OnFocus: function(){
        this.OnSetFocus(true);
    },
    OnLostFocus: function(){
        this.OnSetFocus(false);
    },
    OnSetFocus: function(isFocused){
        if(isFocused && this.isFilterEnabled && !this.isToolbarItem)
            this.SelectInputText();
        aspxGetDropDownCollection().SetFocusedDropDownName(isFocused ? this.name : "");
    },
    OnSelectChanged: function(){
        if(this.lbEventLockCount > 0) return;
        
        var lb = this.GetListBoxControl();
        // TODO Extract method with SetValue (params: value = "")
        var item = lb.GetSelectedItem();
        var text = item != null ? item.text : "";
        this.lastSuccessText = text;
        this.lastSuccessValue = item != null ? item.value : text;
        this.islastSuccessValueInit = true;
        this.SetTextInternal(text);
        //
        this.OnChange(); 
        
        if(!this.isToolbarItem)
            this.SelectInputElement();
    },
    OnOpenAnotherDropDown: function(){
        this.OnApplyChangesAndCloseWithEvents();
    },
    OnClick: function(){
        if(!this.isToolbarItem)
            ASPxClientDropDownEdit.prototype.OnClick.call(this);
    },    

    ParseValue: function() {
        var newText = ASPxClientButtonEditBase.prototype.GetValue.call(this);
        var oldText = this.GetText();
        if(oldText != newText){
            this.SetText(newText);
            this.OnChange();
        }
    },
    RaiseValueChangedEvent: function() {
        var processOnServer = ASPxClientTextEdit.prototype.RaiseValueChangedEvent.call(this);
        if(_aspxIsExists(this.RaiseSelectedIndexChanged))
            processOnServer = this.RaiseSelectedIndexChanged(processOnServer);
        return processOnServer;
    },
    // API
    RaiseSelectedIndexChanged: function(processOnServer) {
        if(!this.SelectedIndexChanged.IsEmpty()){
            var args = new ASPxClientProcessingModeEventArgs(processOnServer);
            this.SelectedIndexChanged.FireEvent(this, args);
            processOnServer = args.processOnServer;
        }
        return processOnServer;
    },
    AddItem: function(text, value, imageUrl){
        var index = this.GetListBoxControl().AddItem(text, value, imageUrl);
        this.CollectionChanged();
        return index;
    },
    InsertItem: function(index, text, value, imageUrl){
        this.GetListBoxControl().InsertItem(index, text, value, imageUrl);
        this.CollectionChanged();
    },
    RemoveItem: function(index){
        this.GetListBoxControl().RemoveItem(index);
        this.CollectionChanged();
    },
    ClearItems: function(){
        this.GetListBoxControl().ClearItems();
        this.ClearItemsInternal();
    },
    BeginUpdate: function(){
         this.GetListBoxControl().BeginUpdate();
    },
    EndUpdate: function(){
        this.GetListBoxControl().EndUpdate();
        this.CollectionChanged();
    },
    MakeItemVisible: function(index){
        var lb = this.GetListBoxControl();
        lb.MakeItemVisible(index);
    },
    GetItem: function(index){
        return this.GetListBoxControl().GetItem(index);
    },
    GetItemCount: function(){
        return this.GetListBoxControl().GetItemCount(); 
    },
    GetSelectedIndex: function(){
        return this.GetListBoxControl().GetSelectedIndexInternal();
    },
    SetSelectedIndex: function(index){
        this.SelectIndex(index);
    },
    GetSelectedItem: function(){
        var lb = this.GetListBoxControl();
        var index = lb.GetSelectedIndexInternal();
        return lb.GetItem(index);
    },
    SetSelectedItem: function(item){
        var index = (item != null) ? item.index : -1;
        this.SelectIndex(index);
    },
    GetText: function(){
        return this.lastSuccessText;
    },
    PerformCallback: function(arg) {
        this.isPerformCallback = true;
        this.ClearItemsInternal();
        this.GetListBoxControl().PerformCallback(arg);
    },

    ClearItemsInternal: function(){
        this.SetValue(null);
        this.CollectionChanged();
        var lbScrollDiv = this.GetListBoxScrollDivElement();
        if(_aspxIsExists(lbScrollDiv))
            lbScrollDiv.scrollTop = "0px";
    }
});

// DropDown
var __aspxDropDownCollection = null;
function aspxGetDropDownCollection(){
    if(__aspxDropDownCollection == null)
        __aspxDropDownCollection  = new ASPxClientDropDownCollection();
    return __aspxDropDownCollection;
}

_aspxAttachEventToDocument("mousedown", aspxDropDownDocumentMouseDown);
function aspxDropDownDocumentMouseDown(evt){
    return aspxGetDropDownCollection().OnDocumentMouseDown(evt);
}
_aspxAttachEventToDocument("mouseup", aspxDropDownDocumentMouseUp);
function aspxDropDownDocumentMouseUp(evt){
    return aspxGetDropDownCollection().OnDocumentMouseUp(evt);
}
_aspxAttachEventToElement(window, "resize", aspxCBWindowResize);
function aspxCBWindowResize(evt){
    aspxGetDropDownCollection().OnResize(evt);	
}

function aspxDDDropDown(name, evt){
    if(_aspxGetIsLeftButtonPressed(evt)){
        var dd = aspxGetControlCollection().Get(name);
        if(_aspxIsExists(dd))
            return dd.OnDropDown(evt);
    }
}
function aspxDDCloseUp(name, evt){
    var dd = aspxGetControlCollection().Get(name);
    dd.OnCloseUp(evt);
}

// DateEdit
//function aspxEdDECSelectionChanging(name, evt) {
//    var dateEdit = aspxGetControlCollection().Get(name);
//    if(dateEdit) {
//        dateEdit.OnCalendarSelectionChanging(evt.selection);        
//    }
//}
function aspxEdDECMainElementClick(name) {
    var dateEdit = aspxGetControlCollection().Get(name);
    if(dateEdit)
        dateEdit.OnCalendarMainElementClick();
}

// DropDownEdit
function aspxDDMainElementClick(name, evt){
    var dd = aspxGetControlCollection().Get(name);
    if(dd != null) dd.OnClick();
}
// ComboBox
function aspxCBIClick(name, evt){
    var cb = aspxGetControlCollection().Get(name);
    if(cb != null) cb.OnItemClick();
}
function aspxCBLBClick(name, evt){
    var cb = aspxGetControlCollection().Get(name);
    if(cb != null) cb.OnListBoxClick(evt);
}
function aspxCBMozillaOverflowOn(name){
    var cb = aspxGetControlCollection().Get(name);
    cb.EnableLBDivOverflow();
}
function aspxCBDDButtonMMove(evt){
    return aspxGetDropDownCollection().OnDDButtonMouseMove(evt);
}
function aspxCBMouseWheel(evt){
    var cb = aspxGetDropDownCollection().GetFocusedDropDown();
    if (cb != null) 
        return cb.OnMouseWheel(evt);
}

function aspxCBKeyUp(evt){
    var cb = aspxGetDropDownCollection().GetFocusedDropDown();
    if (cb != null) 
        cb.OnFiltering(evt);
}
function aspxCBFilterByTimer(name){
    var cb = aspxGetControlCollection().Get(name);
    if(cb != null) cb.Filtering();
}