function WCombo76(Prefix)
{
    this.Prefix = Prefix;
    this.filterEnabled = true;
    this.uniqueId = '';
    this.fixedList = true;
    this.name = '';
    this.serverId = '';
    this.KeyInputDelay = 300;
    this.AutoPostBack = false;
    this.DataTextFieldIndex = null;
    this.MaxPopupHeight = 200;
    this.MasterCB = null;
	this.fastFind = false;
	this.DetailCBs = new Array();
	this.requestParams = new Array();
	this.fastFind = false;
	this.Width = null;
	this.PopupWidth = null;
	this.CountOfDisplayedRow = 100;
	this.CurCountOfDisplayedRow = this.CountOfDisplayedRow;
	this.container = null;
	this.allowNull = false;
	this.multiSelect = false;
	this.textForAllSelection = 'All';
	this.textForNoneSelection = 'None';
	this.portionLoadingRecords = false;
	this.popupDirection = 'RightDownwards';
	
    this.edtState = document.getElementById(this.Prefix + 'edtState');
    this.wgrData = null;    
    this.divPopup = document.getElementById(this.Prefix + 'divPopup');
    (this.edtMain = document.getElementById(this.Prefix + 'edtMain')).WCombo76 = this;
    this.tdFooter = document.getElementById(this.Prefix + 'tdFooter');
    this.tdData = document.getElementById(this.Prefix + 'tdData');
    this.tdAllRowsButton = document.getElementById(this.Prefix + 'tdAllRowsButton');
    this.tblMain = document.getElementById(this.Prefix + 'tblMain');
    this.tdDown = document.getElementById(this.Prefix + 'tdDown');
   
    this.divMsg = document.getElementById('divMsg');

    this.lastKeyValue = null;
    this.readyState = 'complete';
    this.KeyInputTimer = null;
    this.stateDOM = null;
    this.type = 'WCombo76';
    this.LastTR = null;
    this.DataSrcChanger = '';
    this.beforeSetFilterText = null;
    this.lastStartingString = '';
    this.settedParams = null;
    this.beforeKeyDown_popupIsOpen = false;
    
    this.__value = null;
    
  	/*events*/
	this.onSelectedValueChanged = null;
	this.onblur = null;
    this.onkeydown = null;
    this.onfocus = null;
    this.onSelectItem = null;
    this.onAfterSetFilter = null;
	
	/*consts*/
	this.ALLStartingString = '!!ALL';
	this.NULLSelectedValue = '!!NULL';
	this.pageRowCount = 12;


    this.init = function()
    {
        if (this.edtState)
        {
            try
            {
                this.stateDOM = this.wgrData.newXMLDOM();
                this.stateDOM.loadXML(this.decode(this.edtState.value));
                this.lastKeyValue = this.getSelectedValue();
            }
            catch(ex)
            {
                this.stateDOM = null;
            }
        }
    }
    
    this.btnDown_OnClick = function(event)
	{   
	    1;
	    if (this.readyState == 'complete'  &&  this.getEnabled())
    		if (this.divPopup.style.display == 'none') this.showPopup()
		    else this.hidePopup();
	}
	
	this.showPopup = function()
	{
	    if (this.divPopup.parentNode.tagName != 'BODY')
	    {
	        document.body.insertBefore(this.divPopup, document.body.firstChild);
	        this.wgrData.moveStateHiddens(this.tblMain);
	    }
	
	    this.divPopup.style.display = '';
		this.setPopupSize();
		
	    if (!this.wgrData.isEmpty)  this.wgrData.scrollToCurTR(false);
		this.setFilter(this.ALLStartingString, 'btnDown_OnClick');
		this.edtMain.focus();
	}

	this.hidePopup = function()
	{   
    	this.divPopup.style.display = 'none';
		
		if (this.lastKeyValue != this.getSelectedValue())
		{ 
			    this.ValueChanged();
			    if (this.AutoPostBack) this.doPostBack('SelectedIndexChanged');
		}
	}
	
	this.getCurTR = function()
	{
		return this.wgrData.CurTR;
	}
	
	this.getTextValue = function(tr)
	{
	    if (tr) 
	        if (this.wgrData.isGroupTR(tr))
	        {
                var spanCapt = tr.cells.item(0) ? tr.cells.item(0).getElementsByTagName('span')[0] : null;
                if (spanCapt)
                    return spanCapt.firstChild.nodeValue;
            }
	        else if (this.DataTextFieldIndex >= 0 &&  tr.cells.item(this.DataTextFieldIndex))
    	        return tr.cells.item(this.DataTextFieldIndex).firstChild.nodeValue;

        return '';
	}
	
	this.getKeyValue = function(tr)
	{
        if (!tr) return this.allowNull ? this.NULLSelectedValue : -1;			
        return this.wgrData.getTRID(tr);
	}
	
	this.setwgrData = function(value)
	{
	1;
	    if (value)
	    {
		    this.wgrData = value;
		    this.wgrData.wcbParent = this;
		}
	}
	
	this.setSelectedValue = function(rowKind, value)
	{
	1;
	    if (value == this.NULLSelectedValue  && this.allowNull)
	    {
	        this.setCurTR(null);
			this.wgrData.setCurTR(null);
			return true;
	    }
	    else if (value != null)
	    {
	        var newTR = null;
		    if (!this.wgrData.isEmpty  &&  (newTR = this.wgrData.findTR(rowKind, value))) 
		    {
			    if (temp = this.getCurTR()) temp.className = this.wgrData.getClassName(temp);
			    this.setCurTR(newTR);
			    this.wgrData.setCurTR(newTR);
			    return true;
		    }
		    else
		    {
		        this.__value = value; 
		        this.settedParams = '';
		        this.setFilter(this.ALLStartingString, 'setSelectedValue', value);
		        return false;
		    }
        }
        else
            this.setCurTR(null);
	}
	
	this.refreshMultiSelectText = function()
	{
	    if (this.wgrData.selectedRows.isSelectedNone())
	        this.edtMain.value = this.textForNoneSelection;
	    else if (this.wgrData.selectedRows.isSelectedAll())
	        this.edtMain.value = this.textForAllSelection;
	    else
	        this.edtMain.value = this.wgrData.selectedRows.toString(this.DataTextFieldIndex, '; ');
	    
	    if (this.tdFooter) 
	        this.tdFooter.innerHTML = this.wgrData.selectedRows.count().toString() + ' of ' + this.wgrData.getParamFromXML('TotalRowsCount') + ' selected';
	}
	
	this.refreshFooterText = function(context)
    {
        if (context.tdFooter) 
                if (context.multiSelect)
                {
	                if (temp = context.stateDOM.selectSingleNode('state/footerText'))
	                    context.tdFooter.innerHTML = temp.text;
	            }
                else
                    context.tdFooter.innerHTML = (!context.wgrData.isEmpty ? context.wgrData.rowCount().toString() + ' of ' + context.wgrData.getParamFromXML('TotalRowsCount')  : 0)+ ' retrieved';	                
    }
	
	this.RowClick = function(tr)
	{
	1;
		if (!this.multiSelect)
		{
		    this.setCurTR(tr);
		    this.divPopup.style.display = 'none';
		    if (this.lastKeyValue != this.getSelectedValue())
		    { 
	            this.ValueChanged();
			    if (this.AutoPostBack) this.doPostBack('SelectedIndexChanged');
		    }
		}
		else
		    this.refreshMultiSelectText();

		this.edtMain.focus();
		this.LastTR = tr;
	}
	
	this.setCurTR = function(value)
	{
	1;
		if (!this.wgrData.isEmpty  && this.fixedList) this.wgrData.setCurTR(value);
		if (this.edtMain.value != this.getTextValue(value) && !this.multiSelect) this.edtMain.value = this.getTextValue(value);
		var selectedNode = this.stateDOM ? this.stateDOM.selectSingleNode('state/selected') : null;
		if (selectedNode)
		{
		    selectedNode.text = this.getKeyValue(value);
		    selectedNode.setAttribute('text', this.edtMain.value);
		    selectedNode.setAttribute('kind', value  && this.wgrData.isGroupTR(value) ? 'Group' : 'Data');
		}
		this.saveState();
	}
	
	this.getSelectedValue = function()
	{
	1;
	    if (this.multiSelect)
	    {
	        var selectedRowsNode = this.wgrData.getStateChildNode('selectedRows');
	        return selectedRowsNode ? selectedRowsNode.xml : '';
	    }
	    else
	    {
    		var selectedNode = this.stateDOM ? this.stateDOM.selectSingleNode('state/selected') : null;
	        return selectedNode ? selectedNode.text : null;
	    }
	}
	
	this.getSelectedKind = function()
	{
	    var selectedNode = this.stateDOM ? this.stateDOM.selectSingleNode('state/selected') : null;
	    var kindAttr = selectedNode ? selectedNode.attributes.getNamedItem('kind') : null;
		return kindAttr ? kindAttr.value : null;
	}
	
	this.getSelectedText = function()
	{
		return this.edtMain.value;
	}
	
	this.setSelectedText = function(value)
	{
	    this.edtMain.value = value;
	}
	
	this.KeyDown = function(event)
	{   
	    this.beforeKeyDown_popupIsOpen = this.popupIsOpen();
	    
		switch (event.keyCode)
		{  
			case 40: //down
			{
			    if (this.readyState == 'complete')
			        if (event.altKey)
			            if (this.divPopup.style.display == 'none') this.showPopup();
			            else;
			        else
			            if (!this.getCurTR())  this.showPopup();
			            else this.setCurTR(this.wgrData.moveTR(1));
			}break;
			case 38: //up
			{
			    if (this.readyState == 'complete')
			        if (event.altKey)
			            if ( this.divPopup.style.display != 'none') this.hidePopup();
			            else;
			         else
			            if (!this.getCurTR())  this.showPopup();
			            else this.setCurTR(this.wgrData.moveTR(-1));
			}break;
			case 34: case 33: //page down, page up
			{
			    if (this.readyState == 'complete')
    	            if (!this.getCurTR())  this.showPopup();
		            else this.setCurTR(this.wgrData.moveTR( event.keyCode == 34 ? this.pageRowCount : -this.pageRowCount));
			}break;
			case 36: case 35: //home, end
			{
			    if (this.readyState == 'complete'  &&  event.ctrlKey)
    	            if (!this.getCurTR())  this.showPopup();
		            else this.setCurTR(this.wgrData.moveTR( event.keyCode == 35 ? 'end' : 'home'));
			}break;
			case 13: //enter
			{
		        this.RowClick(this.getCurTR());
		        if (this.multiSelect)
		        {
		            this.divPopup.style.display = 'none';
          		    if (this.lastKeyValue != this.getSelectedValue())
		            { 
	                    this.ValueChanged();
			            if (this.AutoPostBack) this.doPostBack('SelectedIndexChanged');
		            }
                }		            
			}break;
			case 27: /*esc*/
			{
				if (temp = this.getCurTR()) temp.className = this.wgrData.getClassName(temp);
				if (this.LastTR) 
				{
				    this.setCurTR(this.LastTR);
				    this.ValueChanged();
				}
				this.divPopup.style.display = 'none';
				event.returnValue = false;
			}break;
			case 39:/*right*/ case 37: /*left*/ case 35: /*end*/ case 36: /*home*/ case 20: /*capsLock*/ case 16: /*shift*/ 
			case 18: /*alt*/ case 17: /*ctrl*/
				break;
			case 9: /*tab*/
			{
			    if (!event.shiftKey) this.tabbed = true;
			    
            }break;
            
            case 82: /*r*/
            {
                if (event.ctrlKey) return;
            }
            
            case 65: /*a*/
            {
                if (event.ctrlKey && this.multiSelect && this.popupIsOpen())
                {
                    this.tdFooterAll_onclick();
                    event.returnValue = false;
                    return;
                }
            }
            
			default: 
			{   
			    if (this.multiSelect)
                {
                    if (event.keyCode == 32)
                    {
                        if (this.wgrData.CurTR)
	                        if(this.wgrData.selectedRows.isSelectedTR(this.wgrData.CurTR))
                            {
                                if (this.wgrData.allowEmptySelection || this.wgrData.selectedRows.count() > 1)
                                    this.wgrData.selectedRows.unselectTR(this.wgrData.CurTR);
                            }                        
                            else
                                this.wgrData.selectedRows.selectTR(this.wgrData.CurTR);
                        this.refreshMultiSelectText();
                    }                        
                }                    
			    else if (this.filterEnabled)
			    {
				    window.clearTimeout(this.KeyInputTimer);
				    this.KeyInputTimer = null;
				    return false;
				}
				else if (!this.fastFind  &&  this.fixedList) 
				    event.returnValue = false;
			}
		}
		
        if (this.onkeydown) this.onkeydown(event);
       // if (event.preventDefault) event.preventDefault();
	    event.cancelBubble = true;
	}
	
    this.KeyUp = function(event)
	{
	    var SpecKeys  = new Array(40, 38, 13, 27, 9, 39, 37, 35, 36, 20, 16, 18, 17, 33, 34);
		if (ArrayIndexOf(SpecKeys, event.keyCode) != -1)  
		{
		    event.returnValue = false;
		    return false;
		}
		
		if (this.filterEnabled)
		{
			var __this = this;
			if (!this.KeyInputTimer)
				this.KeyInputTimer = window.setTimeout(
					function()
					{ 
					     if (__this.divPopup.style.display == 'none') 
					     {
					        if (__this.divPopup.parentNode.tagName != 'BODY')
	                            document.body.insertBefore(__this.divPopup, document.body.firstChild);
					        __this.setPopupPosition();
					        __this.divPopup.style.display = '';
					     }
					    if (!__this.setFilter(null, 'FilterChanged'))__this.edtMain.value = __this.lastStartingString ;
						__this.KeyInputTimer = null;
					}, this.KeyInputDelay);
	    }
	    else if (this.fastFind  &&  !this.wgrData.isEmpty)
	    {
	        if (this.divPopup.style.display == 'none') 
	        {
	            if (this.divPopup.parentNode.tagName != 'BODY')
	                document.body.insertBefore(this.divPopup, document.body.firstChild);    
	        
	            this.divPopup.style.display = '';
	            this.setPopupSize();
	        }
	        var tr = this.wgrData.fastFind(this.edtMain.value, this.DataTextFieldIndex);
	        if (tr)
	        {
	            this.wgrData.setCurTR(tr);
	            this.wgrData.scrollToCurTR(tr);
    		    this.lastStartingString = this.edtMain.value;
    		}
    		else this.edtMain.value = this.lastStartingString;
		}
	}
	
	this.createRequestParamsNode = function(methodNode)
	{
	    if (this.requestParams  && this.requestParams.length > 0)
	    {
	        var resNode = methodNode.selectSingleNode('requestParams');
	        var doc = methodNode.ownerDocument;
	        if (resNode) methodNode.removeChild(resNode);
	        resNode = doc.createNode(1, 'requestParams', '');
    	    
	        for (var param_i = 0; param_i < this.requestParams.length; param_i++)
	        {
	            var param = this.requestParams[param_i];
	            if (param  &&  (param.type == 'ExtComboBox'  ||  param.type == 'WCombo76'))
	                resNode.appendChild( doc.createNode(1, param.serverId, '') ).text = param.getSelectedValue();
	                //res += param.serverId + '=' + param.getSelectedValue() + ';';
	        }
	        return resNode;
	    }
	    else return null;
	}
	
	this.doCallback = function(args, callbackMethod)
	{
	    this.readyState = 'loading';
	    if (this.tdFooter) this.tdFooter.innerHTML = 'Loading..';

        if (!this.container)
	        WebForm_DoCallback(this.uniqueId, args.xml, callbackMethod, this, this.onCalbackError, false);
        else	        
        {
            var methodNode = args ? args.documentElement : null;
            var methodName = methodNode ? methodNode.attributes.getNamedItem('name').value : '';
            var c = new WContainer76_Service();
            c.call_control = this;
	        this.container.CallServer(this.uniqueId, methodName, args.xml, this, callbackMethod, this.onCalbackError, c)
	    }
	}
	
	this.setFilter = function(value, changer, selectedValue)
	{
        var argsDOM = this.wgrData.newXMLDOM();
        var StartString = value != null ? value : this.edtMain.value;
        var methodNode = argsDOM.createElement('method');
        this.wgrData.dom_appendAttr(methodNode, 'name', 'SetFilter')
        if (this.stateDOM)
        {
            var stateNode = methodNode.appendChild(this.stateDOM.documentElement.cloneNode(true));
            if (this.wgrData.stateDOM)
            {
                var wgrDataStateNode = stateNode.appendChild(argsDOM.createElement('wgrData'));
                wgrDataStateNode.appendChild(this.wgrData.stateDOM.documentElement.cloneNode(true));
            }
        }
        
        this.wgrData.dom_appendNode(methodNode, 'StartString', StartString);
        if (this.MasterCB)
            this.wgrData.dom_appendNode(methodNode, 'MasterValue', this.MasterCB.edtMain.value != '' ? this.MasterCB.getSelectedValue() : 'null');
            
        if (value == this.ALLStartingString)
            this.wgrData.dom_appendNode(methodNode, 'SelectedValue', selectedValue ? selectedValue : this.getSelectedValue());
            
        if (changer == 'FilterChanged') this.CurCountOfDisplayedRow = this.CountOfDisplayedRow;
        
        this.wgrData.dom_appendNode(methodNode, 'CountOfDisplayedRow', this.CurCountOfDisplayedRow);
        
        var requestParamsNode = this.createRequestParamsNode(methodNode);
        if (requestParamsNode) methodNode.appendChild(requestParamsNode);
        
        this.DataSrcChanger = changer;
        
        this.beforeSetFilterText = this.edtMain.value;
        argsDOM.appendChild(methodNode);

        var temp = null;
        var newParams = 'StartString=' + StartString + ';' +
                        'MasterValue=' + ((temp = argsDOM.selectSingleNode('method/MasterValue')) ? temp.text : '' ) + ';' + 
                        'CountOfDisplayedRow=' + ((temp = argsDOM.selectSingleNode('method/CountOfDisplayedRow')) ? temp.text : '' ) + ';' + 
                        (requestParamsNode ? requestParamsNode.xml + ';' : '');                        
        try
        {        
            if (this.filterEnabled  &&  newParams != this.settedParams)
            {
                this.doCallback(argsDOM, this.callbackSetFilter);
                this.settedParams = newParams; 
                return true;
            }
            else 
            {
                this.DataSrcChanger = '';
                this.refreshFooterText(this); //SNV[+]
                return false;
            }
        }
        finally
        {
            argsDOM = null;
        }
        
	}
	
	this.callbackSetFilter = function(args, context)
	{
	    context.readyState = 'loaded';
	    var responseXML = context.wgrData.newXMLDOM();
	    try
	    {
	        responseXML.loadXML(args);
	    }
	    catch(ex)
	    {
	        responseXML = null;
	    }
	    
	    if (responseXML)
	    {
	        var dataNode = responseXML.selectSingleNode('response/Data');
          
            context.wgrData.reload(dataNode ? dataNode.xml : null);
	        var startStringNode = responseXML.selectSingleNode('response/StartString');
	       // var startString = startStringNode.text;
	        var startString = startStringNode.firstChild ? startStringNode.firstChild.nodeValue : '';
	        var currentText = context.edtMain.value;
	        
	        if (context.fixedList  &&  !context.wgrData.isEmpty)
			{
			    var selectedTR = null;              
			    if (startString == context.ALLStartingString)
			       selectedTR = context.wgrData.findTR(context.getSelectedKind(), context.getSelectedValue());
                
			    if (selectedTR == null)
			        selectedTR = context.wgrData.firstTR(context.DataSrcChanger != 'btnDown_OnClick'  && context.DataSrcChanger != 'OnMasterValueChanged');
			    
			    if ((context.beforeSetFilterText == currentText  ||  context.DataSrcChanger != 'FilterChanged')  /*&& (!context.allowNull || context.DataSrcChanger != 'btnDown_OnClick')*/)
			    {
			        var selectedNode = responseXML.selectSingleNode('response/state/selected');
			        if (selectedNode)
			            context.wgrData.CurTR = context.wgrData.findTR(selectedNode.attributes.getNamedItem('kind').value, selectedNode.text); 
    			    
			        context.wgrData.setCurTR(selectedTR);
			        context.wgrData.scrollToCurTR(false);
			        context.setCurTR(context.LastTR = context.wgrData.CurTR);
			    }
			}
			else context.setCurTR(context.LastTR = null);
			 
	        if (startString != context.ALLStartingString  &&  context.beforeSetFilterText == currentText  && context.DataSrcChanger == 'FilterChanged')
	        {
	            context.edtMain.value = startString;
	            context.lastStartingString = startString;
	        }
	        
			 context.setPopupSize();
	    }
	    
	    if (!context.wgrData.isEmpty)  
		    context.tdAllRowsButton.parentNode.style.display = context.wgrData.rowCount().toString() == context.wgrData.getParamFromXML('TotalRowsCount') ? 'none' : '';
        else context.tdAllRowsButton.parentNode.style.display = 'none';
	    
	    context.readyState = 'complete';
	    context.refreshFooterText(context); //SNV[+]
	    //SNV[-]if (context.tdFooter) 
	    //SNV[-]    context.tdFooter.innerHTML = (!context.wgrData.isEmpty ? context.wgrData.rowCount().toString() + ' of ' + context.wgrData.getParamFromXML('TotalRowsCount')  : 0)+ ' retrieved';
	        
        switch (context.DataSrcChanger)
		{
			case 'OnDetailValueChanged':
			{
				if (context.getSelectedValue() == '-1' &&  !context.wgrData.isEmpty  &&  context.DetailCBs.length > 0  &&   context.DetailCBs[0].ExtTable)
				{
					context.setSelectedValue('Data', context.DetailCBs[0].wgrData.getMasterValueFromXML(context.DetailCBs[0].getSelectedValue()));
					context.ValueChanged();
				}				
			}break;
			case 'OnMasterValueChanged':
			{
			    __this = context;
			    window.setTimeout(
			        function ()
			        {
	    			    for (var i = 0; i < __this.DetailCBs.length; i++) 
    					    if (__this.DetailCBs[i]) __this.DetailCBs[i].OnMasterValueChanged();
    			    }, 1);
                
			}break;
			case 'setSelectedValue': 
			{
			    if (!context.wgrData.isEmpty) 
		        {
			        var newTR = context.wgrData.findTR('Data', context.__value);
			        if (newTR)
			        {
				        if (temp = context.getCurTR()) temp.className = context.wgrData.getClassName(temp);
				        context.setCurTR(newTR);
				        context.wgrData.setCurTR(newTR);
			        }
		        }
			}break;
		}	        
	        
        context.DataSrcChanger = '';
        if (context.onAfterSetFilter) context.onAfterSetFilter(context);
	}
	
	this.setPopupSize = function()
	{
	1;
        if (!this.wgrData.isEmpty)
        {
            var headerHeight = 0;
	        if (this.wgrData.ShowHeader && !this.wgrData.headerInTable)
                headerHeight =  this.wgrData.trHeader.offsetHeight;
        
            
            var h = this.wgrData.tblMain.clientHeight < this.MaxPopupHeight ? this.wgrData.tblMain.clientHeight + headerHeight : this.MaxPopupHeight;
            if (h != 0)
                this.wgrData.setHeight(  h + 'px' );
           
        }
        else
            this.wgrData.setHeight( (this.wgrData.divNoData.clientHeight != 0 ? this.wgrData.divNoData.clientHeight : 100) + 'px');
            
        this.setPopupPosition();
	}
	
    this.getAbsolutePosition = function(obj)
    {
        var ap = WebForm_GetElementPosition(obj);
        return {left: ap.x, top: ap.y, scrollLet: 0, scrollTop: 0, height: obj.offsetHeight};
    }
	
	
	this.setPopupPosition = function()
	{
        var edtPos = position.getXY(this.tblMain);
        
        if (this.popupDirection.indexOf('Downwards') != -1)
            this.divPopup.style.top = edtPos[1] + this.tblMain.offsetHeight + 'px';
        else 
        {
            var bodyHeight = document.body.clientHeight;
            this.divPopup.style.bottom = bodyHeight - edtPos[1] + 'px';
        }
            
        if (this.popupDirection.indexOf('Right') != -1)
            this.divPopup.style.left = edtPos[0] + 'px';
        else
        {
            var bodyWidth = document.body.clientWidth;
            var divMargin = parseInt(position.getStyle(this.divPopup, 'marginRight'), 10) || 0;
            this.divPopup.style.right = bodyWidth - this.tblMain.offsetWidth - edtPos[0] - divMargin + 'px';
        }
	}
	
	this.window_onresize = function()
	{
	    if (this.divPopup.style.display != 'none')
	        this.setPopupPosition();
	}
	
	if (window.attachEvent)
        window.attachEvent('onresize', Function.createDelegate(this, this.window_onresize));
    else
        window.addEventListener('resize', Function.createDelegate(this, this.window_onresize), false);

    
	this.onCalbackError = function(args, context)
	{
	    this.DataSrcChanger = '';
	    context.readyState = 'complete';
	}

	this.edtMain_Click = function(event)
	{
		if (this.filterEnabled  ||  this.fastFind) this.edtMain.select();
	}
	
	this.elementBelongThis = function(element)
	{
	    if (element && element.nodeType == 3 && element.parentNode)
	        element = element.parentNode;
	
	    var elementId = element && element.id ? element.id : '';
	    var parentElementId = element  &&  element.parentNode && element.parentNode.id ? element.parentNode.id : '';
	    
	    return elementId.indexOf(this.Prefix) != -1  ||  parentElementId.indexOf(this.Prefix) != -1  ||  elementId == this.edtMain.id;
	}
	
	this.edtMain_OnBlur = function(event)
	{
        if (this.readyState == 'loading'  ||  this.KeyInputTimer != null)
	    {
	        try
	        {
	            this.edtMain.focus();
	        }
	        catch(ex) {}
	        this.edtMain.value = this.edtMain.value;
	        event.cancelBubble = true;
            return event.returnValue = false;
         }
	
	    var activeElement = event && event.explicitOriginalTarget ?  event.explicitOriginalTarget : document.activeElement;
		if (!this.elementBelongThis(activeElement) || (activeElement  &&  activeElement.id == this.edtMain.id) )
		{
			this.divPopup.style.display = 'none';
			if (this.fixedList)
			{
			    if (this.allowNull  && this.edtMain.value.trim() == '')
		            this.setSelectedValue('', null);
                else if (!this.wgrData.isEmpty &&  !this.multiSelect && typeof this.getCurTR() != 'undefined') 
                    this.setCurTR(this.LastTR = this.getCurTR());
			}
			else
			{
			    var selectedNode = this.stateDOM ? this.stateDOM.selectSingleNode('state/selected') : null;
		        if (selectedNode)
		            selectedNode.setAttribute('text', this.edtMain.value);
		        this.saveState();
			}
			 
			if (this.onblur) this.onblur(event);
			
			
			if (this.lastKeyValue != this.getSelectedValue())
		    { 
			    this.ValueChanged();
			    if (this.AutoPostBack) this.doPostBack('SelectedIndexChanged');
		    }
		}
		else
		    window.setTimeout(Function.createDelegate(this, 
		        function()
		        {
    		        this.edtMain.focus();
                }), 0);
	}

    this.encode = function(s)
    {
        return s.ReplaceAll("<", "&lt;").ReplaceAll(">", "&gt;");
    }

    this.decode = function(s)
    {
        return s.ReplaceAll("&lt;", "<").ReplaceAll("&gt;", ">");
    }
    
	this.saveState = function()
	{
	    this.edtState.value = this.encode(this.stateDOM.xml);
	}
	
	this.AllRowsButton_OnClick = function(event)
	{
	    if (this.portionLoadingRecords)
	        this.CurCountOfDisplayedRow += this.CountOfDisplayedRow;
	    else
	        this.CurCountOfDisplayedRow = -1;
	        
	    this.setFilter(this.ALLStartingString, 'AllRowsButton_OnClick');
	}
	
	this.doPostBack = function(eventArgument) 
	{
		if (!this.container)
		{
		    var theform = document.forms[0];
		    theform.__EVENTTARGET.value = this.uniqueId;
		    theform.__EVENTARGUMENT.value = eventArgument;
		    theform.submit();
		}
		else
		    __doWCPostBack(this.container, this.uniqueId, eventArgument)
	}
	
	this.OnMasterValueChanged = function()
	{   
		this.setFilter(this.ALLStartingString, 'OnMasterValueChanged');
	}
	
	this.OnDetailValueChanged = function(DetailCB)
	{
		if (this.wgrData.isEmpty) this.setFilter(this.ALLStartingString, 'OnDetailValueChanged');
		if (this.getSelectedValue() == '-1' &&  !this.wgrData.isEmpty)
		{
			this.setSelectedValue('Data', DetailCB.ExtTable.getMasterValueFromXML(DetailCB.getSelectedValue()));
			this.ValueChanged();
		}
	}
	
	this.ValueChanged = function(onServer)
	{
	    this.lastKeyValue = this.getSelectedValue();
		for (var i = 0; i < this.DetailCBs.length; i++) 
			if (this.DetailCBs[i]) this.DetailCBs[i].OnMasterValueChanged();
			
		//if (this.MasterCB) this.MasterCB.OnDetailValueChanged(this);
		if (this.onSelectedValueChanged) this.onSelectedValueChanged(this.parent, onServer);
		if (this.onSelectItem) eval(this.onSelectItem);
	}	
	
	this.focus = function()
	{
	1;
	    this.edtMain.focus();
	    if (this.filterEnabled  ||  this.fastFind) this.edtMain.select();
	}
	
	this.setMasterCB = function(value)
	{
		this.MasterCB = value;
		this.MasterCB.DetailCBs[this.MasterCB.DetailCBs.length] = this;
	}
	
	this.setWidth = function(value)
	{
	    var tdDownWidth = this.tdDown.offsetWidth;
	    this.edtMain.style.width = (this.tblMain.style.width = value) - tdDownWidth;
	}
	
	this.setTop = function(value)
	{
	    this.tblMain.style.top = value;
	}
	
	this.setLeft = function(value)
	{
	    this.tblMain.style.left = value;
	}
	
	this.setAbsolutePosition = function()
	{
	    this.tblMain.style.position = 'absolute';
	}
	
	this.moveToBody = function()
	{
	    this.tblMain.insertBefore(this.divPopup, document.body.firstChild);
	}
	
	this.setVisibility = function(value)
	{
	    this.divPopup.style.display = 'none';
	    this.tblMain.style.display = value ? '' : 'none';
        var displayNode = this.stateDOM.selectSingleNode('state/simpleState/Display');
            if (displayNode) displayNode.text = value ? '' : 'none';
        this.saveState();            
	}
	
	this.edtMain_onfocus = function(event)
	{
	1;
        if (this.onfocus) this.onfocus(event);
	}
	
	this.popupIsOpen = function()
	{
	    return this.divPopup.style.display == '';
	}
	
	this.setAllValueText = function(value)
	{
        this.setSimpleState('AllValueText', value);
        if (this.wgrData)
            this.wgrData.setAllTextValue(value);
        
        var selectedNode = this.stateDOM.selectSingleNode('state/selected');
	    if (selectedNode && selectedNode.text == '-1')
	        selectedNode.setAttribute('text', value);
	}
	
	this.setSimpleState = function(name, value)
	{
	    var simpleStateNode = this.stateDOM ? this.stateDOM.selectSingleNode('state/simpleState') : null;
	    if (simpleStateNode)
        {
            var paramNode = simpleStateNode.selectSingleNode(name);         
            if (!paramNode)
                paramNode = simpleStateNode.appendChild( this.stateDOM.createElement(name) );
                
            paramNode.text = value;
            this.saveState();
        }    
	}
	
	this.saveState = function()
	{
	    this.edtState.value = this.encode(this.stateDOM.xml);
	}
	
	this.StoreState = function()
	{
	    1;
	    return this.stateDOM ? this.stateDOM.documentElement : null;
	}
	
	this.refreshStateXML = function(newDataNode, oldStateDOM)
    {
        this.stateDOM.loadXML( newDataNode.selectSingleNode('state').xml);
        var simpleStateNode = this.stateDOM.selectSingleNode('state/simpleState');
    
        for (var oldStateNode = oldStateDOM.documentElement.firstChild; oldStateNode; oldStateNode = oldStateNode.nextSibling)
            if (oldStateNode.nodeName != 'simpleState')
            {
                if (!this.stateDOM.selectSingleNode('state/' + oldStateNode.nodeName))
                    this.stateDOM.documentElement.appendChild(oldStateNode.cloneNode(true));
            }
            else
                for (var oldSStateNode = oldStateNode.firstChild; oldSStateNode; oldSStateNode = oldSStateNode.nextSibling)
                    if (!this.stateDOM.selectSingleNode('state/simpleState/' + oldSStateNode.nodeName))
                        simpleStateNode.appendChild(oldSStateNode.cloneNode(true));
    }
	
	this.RestoreState = function(node)
	{
	    var oldStateDOM = this.wgrData.newXMLDOM();
	    if (this.stateDOM) oldStateDOM.appendChild( this.stateDOM.documentElement.cloneNode(true) );
	
	    try
	    {
	        this.refreshStateXML(node, oldStateDOM);
	    }
	    catch(ex)
	    {
	        this.stateDOM = null;
	    }
	    
	    var newAllValueTextNode = node.selectSingleNode('state/simpleState/AllValueText');
	    if (newAllValueTextNode)
	        this.setAllValueText(newAllValueTextNode.text);
	    
	    if (this.stateDOM &&  this.DataSrcChanger == '')
	    {
	        var dataTextFieldIndexNode = this.getSimpleStateNode('DataTextFieldIndex');
	        if (dataTextFieldIndexNode) 
	        {
	            this.DataTextFieldIndex = parseInt(dataTextFieldIndexNode.text);
	            dataTextFieldIndexNode.parentNode.removeChild(dataTextFieldIndexNode);
            }	            
	    
	        var selectedNode = this.stateDOM.selectSingleNode('state/selected');
	        if (selectedNode && this.edtMain.value != selectedNode.getAttribute('text'))
	            this.edtMain.value = selectedNode.getAttribute('text');
	            
            var displayNode = node.selectSingleNode('state/simpleState/Display');
            if (displayNode)
	            this.setVisibility(displayNode.text != 'none');
	            
          
            this.edtMain.disabled = !this.getEnabled();	            
            
            /*SNV[-]
               if (this.tdFooter) 
                if (this.multiSelect)
                {
	                if (temp = node.selectSingleNode('state/footerText'))
	                    this.tdFooter.innerHTML = temp.text;
	            }
                else
                    this.tdFooter.innerHTML = (!this.wgrData.isEmpty ? this.wgrData.rowCount().toString() + ' of ' + this.wgrData.getParamFromXML('TotalRowsCount')  : 0)+ ' retrieved';	                
            SNV[-] */
            this.refreshFooterText(this); //SNV[+]
	        
	        if (oldStateDOM)
	        {
	            var oldSelectedNode = oldStateDOM.selectSingleNode('state/selected');
		        var oldSelectedValue = oldSelectedNode ? oldSelectedNode.text : null;
		        if (oldSelectedValue != this.getSelectedValue())
		            this.ValueChanged(true);
	        }
	    }
	    
	    this.saveState();
    }	    

    this.getSimpleStateNode = function(name)
	{
	    return this.stateDOM.selectSingleNode('state/simpleState/' + name);
	}

    this.getEnabled = function()
	{
	    if (this.stateDOM)
	    {
	        var enabledNode = this.getSimpleStateNode('Enabled');
	        return !enabledNode || enabledNode.text.toUpperCase() == 'TRUE';
	    }
	    return true; 
	}
	
	this.setEnabled = function(Enabled)
	{
	    this.setSimpleState('Enabled', Enabled ? 'TRUE' : 'FALSE');
	    this.edtMain.disabled = !this.getEnabled();	 
	}

	
	this.tdFooterAll_onclick = function(event)
	{
	    this.wgrData.selectedRows.selectAllTR();
	    this.wgrData.saveState();
	    this.refreshMultiSelectText();
	}
	
	this.tdFooterNone_onclick = function(event)
	{
	    this.wgrData.selectedRows.unselectAllTR(true);
	    this.refreshMultiSelectText();
	}
}
