﻿Type.registerNamespace("GIRO.Web.UI.WebControls");
   
                             // Enum: GIRO.Web.UI.WebControls.ComboBoxEvents
GIRO.Web.UI.WebControls.ComboBoxEvents = function() {};
GIRO.Web.UI.WebControls.ComboBoxEvents.prototype = 
{
   SelectedIndexChanged    : 0,
   Clear                   : 1,
   ClearAndReQuery         : 2,
   ItemsRequesting         : 3,
   ItemsRequested          : 4,
   ReQuery                 : 5,
   ReQueryOnLoad           : 6
}
GIRO.Web.UI.WebControls.ComboBoxEvents.registerEnum("GIRO.Web.UI.WebControls.ComboBoxEvents");

                             // Enum: GIRO.Web.UI.WebControls.Keys
GIRO.Web.UI.WebControls.Keys = function() {};
GIRO.Web.UI.WebControls.Keys.prototype = 
{
   BackSpace               :   8,
   Tab                     :   9,
   Enter                   :  13,
   Shift                   :  16,
   Escape                  :  27,
   Space                   :  32,
   PageUp                  :  33,
   Left                    :  37,
   Up                      :  38,
   Right                   :  39,
   Down                    :  40,
   Del                     :  46,
   F1                      : 112,
   F12                     : 123
}
GIRO.Web.UI.WebControls.Keys.registerEnum("GIRO.Web.UI.WebControls.Keys");

                            // Class: GIRO.Web.UI.WebControls.ItemsRequestingEventArgs
GIRO.Web.UI.WebControls.ItemsRequestingEventArgs = function() 
   {
   GIRO.Web.UI.WebControls.ItemsRequestingEventArgs.initializeBase(this); 
   
   this._clientData = null;
   }
GIRO.Web.UI.WebControls.ItemsRequestingEventArgs.prototype = 
   {
   GetClientData : function() { return (this._clientData); },
   SetClientData : function(value) { this._clientData = value; }
   }
GIRO.Web.UI.WebControls.ItemsRequestingEventArgs.registerClass("GIRO.Web.UI.WebControls.ItemsRequestingEventArgs", Sys.EventArgs);

                            // Class: GIRO.Web.UI.WebControls.ComboBox
GIRO.Web.UI.WebControls.ComboBox = function(element) 
   {
   GIRO.Web.UI.WebControls.ComboBox.initializeBase(this, [element]);

   this._clientStateField = null;   
                
   this._autoPostBack = null;
   this._clientID = null;
   this._errorText = null;
   this._id = null;
   this._loadingText = null;
   this._onClientDataFunction = null;   
   this._onClientReQueryFunction = null;
   this._onClientSelectionChangeFunction = null; 
   this._queryAll = null;
   this._queryRows = null;
   this._reQueryText = null;
   this._skin = null;

   this._radComboBoxClientID = null;
   this._selectedIndex = null;
   this._styleContainerHiddenClientID = null;

   this._radComboBox = null;

   this._ensureDontScrollOnTop = null;
   this._forceSelectOnRequested = null;
   this._hasUserTypedText = null;
   this._hideDropDownZoneOnLoading = null;
   this._highlightedTextStartIndex = null;
   this._isLoading = null;
   this._isReQuerying = null;
   this._isWaitingForAParentToRequest = null;   
   this._isWaitingForReQueryOnLoad = null;   
   this._isWaitingRequestItems = null;
   this._lastMatchingItemText = null;
   this._originalMarkFirstMatch = null;
   this._performMatch = null;
   this._processBackSpaceOnNextHighlight = null;
   this._resetCount = null;
   this._responseData = null;
   this._highlightedItemToRestore = null;    
   this._textBeforeReQuery = null;
   this._userTextBeforeItemToggle = null;   
   
   this._onApplicationLoaded$delegate = null; 
}    

GIRO.Web.UI.WebControls.ComboBox.prototype = 
   {
   initialize : function() 
      {
      GIRO.Web.UI.WebControls.ComboBox.callBaseMethod(this, "initialize");
      
      this.loadClientState();
      this.registerEventHandlers();
      
      this._radComboBox = eval(this._radComboBoxClientID);
      
                             // RadComboBox HiJack
      this._radComboBox._comboBoxInstance = this;
      this._radComboBox.HighlightNextItem = this.radComboBoxHighlightNextItem;
      this._radComboBox.HighlightMatches = this.radComboBoxHighlightMatches;
      this._radComboBox.HighlightPreviousItem = this.radComboBoxHighlightPreviousItem; 
      this._radComboBox.OnDropDownClick = this.radComboBoxOnDropDownClick;      
      this._radComboBox.OnInputChange = this.radComboBoxOnInputChange;
      this._radComboBox.OnInputClick = this.radComboBoxOnInputClick;
      this._radComboBox.OnMoreResultsImageClick = this.radComboBoxOnMoreResultsImageClick;      
      this._radComboBox.OnKeyDown = this.radComboBoxOnKeyDown;
      this._radComboBox.ShouldHighlight = this.radComboBoxShouldHighlight;
      this._radComboBox.ShowDropDown = this.radComboBoxShowDropDown;
      this._radComboBox.DetachDropDown = this.radComboBoxDetachDropDown;
      
                             // Attach Dom events
      var domElementRadComboBoxInput = $get(this._radComboBox.InputID);                             
      this._radComboBox.onClientKeyUp = this.onClientKeyUp;
      this._radComboBox.AttachDomEvent(domElementRadComboBoxInput, "keyup", "onClientKeyUp");
      
      this._ensureDontScrollOnTop = false;
      this._forceSelectOnRequested = false;
      this._hasUserTypedText = false;      
      this._hideDropDownZoneOnLoading = true;
      this._highlightedTextStartIndex = -1;
      this._isLoading = false;         
      this._isWaitingForAParentToRequest = false;
      this._isWaitingForReQueryOnLoad = (this._reQueryText != null && this._reQueryText != "");
      this._isWaitingRequestItems = false;
      this._isReQuerying = false;
      this._lastMatchingItemText = "";
      this._originalMarkFirstMatch = this._radComboBox.MarkFirstMatch;
      this._performMatch = false;
      this._processBackSpaceOnNextHighlight = false;
      this._resetCount = true;
      this._userTextBeforeItemToggle = "";      
      },    

   dispose : function() 
      {
      GIRO.Web.UI.WebControls.ComboBox.callBaseMethod(this, "dispose");
      },
   
   adjustDropDownHeight : function() 
      {
                             // Pointer <this> can be either a reference to the RadComboBox 
                             // or the ComboBox
      var workObject = (typeof(this._comboBoxInstance) == "undefined") ? this : this._comboBoxInstance;
      
      var styleContainer = $get(workObject._styleContainerHiddenClientID);
      if (styleContainer == null)
         return;
      
      var strStyleHeight = workObject.getElementStyle(styleContainer, "height");
      var styleHeight = parseInt(strStyleHeight, 10);      
      
      var dropDownDomElement = $get(workObject._radComboBox.DropDownID);
      
      var heightOfItems = 0;
      for (var i = 0; i < workObject._radComboBox.Items.length; i++)
         {
         var itemDomElement = $get(workObject._radComboBox.Items[i].ClientID);
         if (itemDomElement != null)
            heightOfItems += itemDomElement.clientHeight;
            
         if (heightOfItems >= styleHeight)
            break;
         }
      
      if (heightOfItems < styleHeight)
         dropDownDomElement.style.height = heightOfItems.toString() + "px";
      else
         dropDownDomElement.style.height = strStyleHeight;
         
         
                             // Adjust IFrame height
      
      var elementMoreResultsBox = $get(workObject._radComboBox.MoreResultsBoxID);
      var strStyleHeightMoreResultsBox = elementMoreResultsBox.offsetHeight != 0 ? elementMoreResultsBox.clientHeight : 0;
      
      var styleHeightMoreResultsBox = (elementMoreResultsBox.style.display === "none") ? 0 : parseInt(strStyleHeightMoreResultsBox, 10); 
      
      var newHeight = (heightOfItems < styleHeight ? heightOfItems : styleHeight) + styleHeightMoreResultsBox;            
      if (dropDownDomElement.style.display == "none")
         newHeight = styleHeightMoreResultsBox;
      
      elementIFrameOverlay = $get(workObject._radComboBox.ClientID + "_Overlay");
      if (elementIFrameOverlay != null)
         elementIFrameOverlay.style.height = newHeight.toString() + "px";            
      },       
      
   buildRequestItemsParametersString : function()
      {
      var parameters = { ResetCount:this._resetCount };
      
      var strParameters = Sys.Serialization.JavaScriptSerializer.serialize(parameters);
      strParameters += "~*~*~";
      
      return (strParameters);
      },
      
   clear : function(clearItems) 
      {
      this.clearAndUpdate(clearItems);
         
      var handler = this.get_events().getHandler(GIRO.Web.UI.WebControls.ComboBoxEvents.Clear.toString());
      if (handler != null) 
         handler(this, Sys.EventArgs.Empty);              
   },
   
   clearAndReQuery : function(queryEmptyString) 
      {
      this._isReQuerying = true;
      this._lastMatchingItemText = "";
      this._userTextBeforeItemToggle = "";
      this._hasUserTypedText = false;        
      
      var textToQuery = this._radComboBox.GetText();
      this._textBeforeReQuery = textToQuery;      
      
      if (!this._queryAll)
         this._radComboBox.ClearItems();
      this.saveClientState();      
    
      this._isWaitingRequestItems = true;
      this.requestItems((queryEmptyString === true) ? "" : textToQuery, false /*appendItems*/);      
   },   
   
   clearAndUpdate : function(clearItems)
      {
      if (clearItems)
         this._radComboBox.ClearItems();
      this._radComboBox.ClearSelection();  
      
      this._selectedIndex = -1;
      this._lastMatchingItemText = "";
      this._userTextBeforeItemToggle = "";
      this._hasUserTypedText = false;         
      
      this.saveClientState();      
      
      if (this._onClientSelectionChangeFunction != null && this._onClientSelectionChangeFunction != "")
         {
         var text = "";
         var value = "";
         eval(this._onClientSelectionChangeFunction + "(value, text)");
         }      
      },
   
   clearTextAndReQuery : function()
      {
      this.clearAndUpdate(!this._queryAll);
      this.clearAndReQuery(false /*queryEmptyString*/);      
      },    
      
   doAutoPostBack : function()
      {
      if (this._autoPostBack) __doPostBack(this._clientID, "autoPostBack");
      },      
         
   domUtilsStopEventPropagation : function(e)
      {
      if (e.preventDefault)
         e.preventDefault();
      else
         e.returnValue = false;      
      },              
      
   getElementStyle : function(element, styleProperty)
      {
      if (element.currentStyle)
         var style = element.currentStyle[styleProperty];
      else if (window.getComputedStyle)
         var style = document.defaultView.getComputedStyle(element, null).getPropertyValue(styleProperty);
         
      return style;
      },      
      
   highlightMatches : function(workingObject)   
   {
                             // Pointer <workingObject> must be a reference to 
                             // the RadComboBox
   
      workingObject._comboBoxInstance._highlightedTextStartIndex = -1;
   
	   if (!workingObject.MarkFirstMatch)
	      {
	      if (workingObject._comboBoxInstance._originalMarkFirstMatch == true)
	         workingObject.MarkFirstMatch = true;
	      return;
	      }
   
	   var text = workingObject.GetText();	   
	   
	                            // Backspace processing
      if (!(this._processBackSpaceOnNextHighlight === false && this._queryAll === false) && 
          workingObject.LastKeyCode == GIRO.Web.UI.WebControls.Keys.BackSpace && 
          text.toUpperCase() == workingObject._comboBoxInstance._lastMatchingItemText.toUpperCase())
         {
	      this._processBackSpaceOnNextHighlight == false;
         text = text.substr(0, text.length - 1);                        	   
         if (text === "")
            {
            workingObject.SetText("");
	         workingObject.SetValue("");  
            }
         }
         
      if (text === "")   
         {
         workingObject._comboBoxInstance._userTextBeforeItemToggle = "";  
         workingObject._comboBoxInstance._hasUserTypedText = false;       
         }
         
	   var lastWord = workingObject.GetLastWord(text);
   	
	   if (workingObject.GetLastSeparator(text) == text.charAt(text.length - 1))
	       return;
   	
	   var matchingItem = workingObject.FindFirstMatch(lastWord);
   	
	   if (workingObject.HighlightedItem)
		   workingObject.HighlightedItem.UnHighlight();

	   if (!matchingItem)
	      {
		   if (!workingObject.AllowCustomText)
		      {
			   if (text)
			      {
				   var lastSeparatorIndex = workingObject.GetLastSeparatorIndex(text);
				   if (lastSeparatorIndex < text.length - 1)
				      {
					   workingObject.SetText(text.substring(0, text.length - 1));
					   workingObject.HighlightMatches();
				      }
			      }
		      }
		            
	      workingObject._comboBoxInstance._lastMatchingItemText = "";
		   return;
	      }
	      
	   matchingItem.Highlight();
	   
	                            // Check whether or not to scroll on top
      if (workingObject._comboBoxInstance._ensureDontScrollOnTop === false)
         matchingItem.ScrollOnTop();
      workingObject._comboBoxInstance._ensureDontScrollOnTop = false;

      workingObject._comboBoxInstance._lastMatchingItemText = text;
	   
      var lastSeparatorIndex = workingObject.GetLastSeparatorIndex(text);
      var newText = text.substring(0, lastSeparatorIndex + 1) + matchingItem.Text;
   	
      if (text != newText)
         workingObject.SetText(newText);
   	
	   workingObject.SetValue(matchingItem.Value);
   	
      var startIndex = lastSeparatorIndex + text.length + 1;
      var endIndex = newText.length - startIndex;
   		
                             // Keep trace of highlighted position
      workingObject._comboBoxInstance._highlightedTextStartIndex = startIndex;
      
      if (workingObject._comboBoxInstance._highlightedTextStartIndex != -1)
                             // Keep last user text
         workingObject._comboBoxInstance._userTextBeforeItemToggle = workingObject.GetText().substring(0, workingObject._comboBoxInstance._highlightedTextStartIndex); 
   				
      workingObject.SelectText(startIndex, endIndex);
      },       
      
   initializeElementsDisplay : function() 
      {
      var elementMoreResultsMessage = $get(this._radComboBox.MoreResultsBoxMessageID);
      elementMoreResultsMessage.className = "ComboBoxMoreResultsMessage_" + this._skin;          
      elementMoreResultsMessage.style.display = "block";

      var elementOverlay = $get(this._radComboBox.ClientID + "_Overlay");
      if (elementOverlay != undefined)
         elementOverlay.style.display = "block"; 

      if (this._radComboBox.Items.length > 0 && this._queryAll)
         {
         var elementDropDown = $get(this._radComboBox.DropDownID);
         elementDropDown.style.display = "block";
         
         var elementMoreResults = $get(this._radComboBox.MoreResultsBoxID);
         elementMoreResults.style.display = "none";      
         }
      
      else if (this._radComboBox.Items.length > 0 && !this._queryAll)     
         {
         var elementDropDown = $get(this._radComboBox.DropDownID);
         elementDropDown.style.display = "block";
         elementDropDown.scrollTop = elementDropDown.scrollHeight;  
         
         var elementMoreResults = $get(this._radComboBox.MoreResultsBoxID);
         elementMoreResults.style.display = "block"; 
         
         var elementMoreResultsImage = $get(this._radComboBox.ClientID + "_MoreResultsBoxImage");
         elementMoreResultsImage.style.display = "block"; 
         
         elementMoreResultsMessage.style.display = "none";
         
         if (typeof(this._responseData.HasMoreAvailableItems) !== "undefinded")                     
            if (!this._responseData.HasMoreAvailableItems)
               elementMoreResults.style.display = "none";
         }
         
      else
         {
         var elementDropDown = $get(this._radComboBox.DropDownID);
         elementDropDown.style.display = "none";
                  
         var elementMoreResults = $get(this._radComboBox.MoreResultsBoxID);
         elementMoreResults.style.display = "block";
         
         var elementMoreResultsImage = $get(this._radComboBox.ClientID + "_MoreResultsBoxImage");
         elementMoreResultsImage.style.display = "none";          
         }   
   
      this.adjustDropDownHeight();
      },      
      
   loadClientState : function() 
      {
      if (this._clientStateField == null) return;
      
      var value = this._clientStateField.value;
      var payload = Sys.Serialization.JavaScriptSerializer.deserialize(value);
      
      if (payload != null)
         {
         this._selectedIndex = payload.SelectedIndex;
         this._reQueryText = payload.ReQueryText;
         this._styleContainerHiddenClientID = payload.StyleContainerHiddenClientID;         
         this._radComboBoxClientID = payload.RadComboBoxClientID; 
         }
      },      
    
   onApplicationLoaded : function(sender, args)
      {
      if (args.get_isPartialLoad())
         return;
      
      this.reQueryOnLoad();
      },
    
   onClientBlur : function(comboBox) 
      {
      if (this._isWaitingForAParentToRequest)
         return;

      if (comboBox.FindItemByText(comboBox.GetText()) == null)
         if (comboBox.Items.length == 1)
            comboBox.SetText(comboBox.Items[0].Text);
         else
            this.clearAndReQuery(false /*queryEmptyString*/);            
      },
      
   onClientCallBackError : function(comboBox)
      {
      this._isLoading = false;
      this.clear(true /*clearItems*/);
      
      var elementDropDown = $get(this._radComboBox.DropDownID);
      elementDropDown.style.display = "none";      
      
      var elementMoreResults = $get(this._radComboBox.MoreResultsBoxID);
      elementMoreResults.style.display = "block";       
      
      var elementMoreResultsImage = $get(this._radComboBox.ClientID + "_MoreResultsBoxImage");
      elementMoreResultsImage.style.display = "none";        
      
      var elementMoreResultsMessage = $get(this._radComboBox.MoreResultsBoxMessageID);
      elementMoreResultsMessage.className = "ComboBoxMoreResultsMessage_" + this._skin;          
      elementMoreResultsMessage.style.display = "block";
      elementMoreResultsMessage.innerHTML = this._errorText;
      
      this.adjustDropDownHeight();
      
      return (false);
      },    
    
   onClientDropDownOpening : function(comboBox) 
      {
      if (!this._isLoading)
         this.initializeElementsDisplay();
      },   
      
   onClientItemsRequested : function(comboBox) 
      {
      this._isLoading = false; 
      this._resetCount = false;     
            
      if (this._performMatch == true)
         {
         this.highlightMatches(this._radComboBox);
         this._performMatch = false;
         }
            
      if (this._isWaitingRequestItems)
         {
         var text = "";
         var value = ""; 
         var item = comboBox.FindItemByText(comboBox.GetText());
         if (item != null)
            {
            text = item.Text;
            value = item.Value;
            
            if (this._reQueryText === text || (this._textBeforeReQuery != null && this._textBeforeReQuery === text))
               this._radComboBox.MarkFirstMatch = false;
                        
            this._selectedIndex = item.Index;
            this._radComboBox.SelectedItem = item;
            this.saveClientState();
            }
         else
            {
            this._selectedIndex = -1;
            comboBox.ClearSelection();
            }
            
         if (this._onClientSelectionChangeFunction != null && this._onClientSelectionChangeFunction != "")
            eval(this._onClientSelectionChangeFunction + "(value, text)");
         
         this._isWaitingForAParentToRequest = false;
         this._isWaitingForReQueryOnLoad = false;
         this._isWaitingRequestItems = false;
         
         var handler = this.get_events().getHandler(GIRO.Web.UI.WebControls.ComboBoxEvents.ItemsRequested.toString());
         if (handler != null) 
            handler(this, Sys.EventArgs.Empty); 
         }
         
      if (this._isReQuerying)
         {
         if (this._onClientReQueryFunction != null && this._onClientReQueryFunction != "")
            eval(this._onClientReQueryFunction);
         
         this._isReQuerying = false;
         
         var handler = this.get_events().getHandler(GIRO.Web.UI.WebControls.ComboBoxEvents.ClearAndReQuery.toString());
         if (handler != null) 
            handler(this, Sys.EventArgs.Empty);         
         }   

      if (this._highlightedItemToRestore != null)
         {                 
         this._radComboBox.HighlightedItem = this._highlightedItemToRestore;
         this._highlightedItemToRestore = null;
         }

      if (this._forceSelectOnRequested)
         {
         this._radComboBox.SelectFirstMatch();
         this._forceSelectOnRequested = false;
         }

      var responseHiddenDomElement = $get(this._clientID + "_ResponseHidden");
      this._responseData = Sys.Serialization.JavaScriptSerializer.deserialize(responseHiddenDomElement.value);

      this.initializeElementsDisplay();

      this.saveClientState();  
      },
      
   onClientItemsRequesting : function(comboBox) 
      {      
      this._isLoading = true;
      
      if (!(comboBox.Items.length > 0 && this._queryAll))
          this.setElementsDisplayOnLoading(this); 
      this._hideDropDownZoneOnLoading = true;     
      
      var clientDataString = this.buildRequestItemsParametersString();
      
      if (this._onClientDataFunction != null && this._onClientDataFunction != "")
         clientDataString += eval(this._onClientDataFunction);
      else
         {
         var handler = this.get_events().getHandler(GIRO.Web.UI.WebControls.ComboBoxEvents.ItemsRequesting.toString());
         if (handler != null) 
            {
            var eventArgs = new GIRO.Web.UI.WebControls.ItemsRequestingEventArgs();
            handler(this, eventArgs);   
            clientDataString += eventArgs.GetClientData();
            }
         }
         
      this._radComboBox.ClientDataString = clientDataString;
      },  
      
   onClientKeyUp : function(e)
      {
                            // Do not call explicitly.
                            // Pointer <this> refers to the RadComboBox      
      
      if (!e) e = event;
      var keyCode = e.keyCode || e.which;
      
      var currentText = this.GetText();
      if (keyCode === GIRO.Web.UI.WebControls.Keys.BackSpace && 
          currentText.toUpperCase() == this._comboBoxInstance._lastMatchingItemText.toUpperCase() && 
          !this._comboBoxInstance._queryAll)
                             // Force ReQuery in !QueryAll
         this.SetText(currentText.substr(0, currentText.length - 1));
      },      
      
   onClientSelectedIndexChanged : function(comboBoxItem) 
      {
      if (this._selectedIndex == comboBoxItem.Index)
         return;
      
      this._selectedIndex = comboBoxItem.Index;
      
      if (this._onClientSelectionChangeFunction != null && this._onClientSelectionChangeFunction != "")
         {
         var text = (comboBoxItem.Text != null) ? comboBoxItem.Text : "";      
         var value = (comboBoxItem.Value != null) ? comboBoxItem.Value : "";      
         eval(this._onClientSelectionChangeFunction + "(value, text)");
         }

      var handler = this.get_events().getHandler(GIRO.Web.UI.WebControls.ComboBoxEvents.SelectedIndexChanged.toString());
      if (handler != null) 
         handler(this, Sys.EventArgs.Empty);         
         
      this.saveClientState();
      
      this.doAutoPostBack()
      },        
      
   radComboBoxHighlightNextItem : function()
      {
                            // Called by the RadcomboBox. Do not call explicitly.
                            // Pointer <this> refers to the RadComboBox
                            
      var currentItem = this.HighlightedItem; 
      var proposedIndex = 0;
       
      if (currentItem)
	      proposedIndex = currentItem.Index + 1;
       
      proposedIndex = this.FindNextAvailableIndex(proposedIndex);
       
      if (proposedIndex >= this.Items.length)
         proposedIndex = 0;
       
      if (proposedIndex < this.Items.length)
         {
         this.Items[proposedIndex].Highlight();
         this.Items[proposedIndex].ScrollIntoView();
	      this.Items[proposedIndex].Text;
	      var lastSeparatorIndex = this.GetLastSeparatorIndex(this.GetText());
         var textToSet = this.GetText().substring(0, lastSeparatorIndex + 1) + this.Items[proposedIndex].Text;
   	   
         this.SetText(textToSet);
         this.SetValue(this.Items[proposedIndex].Value);
         }
      },
   
   radComboBoxHighlightMatches : function()   
      {
      this._comboBoxInstance.highlightMatches(this);
      },     
   
   radComboBoxHighlightPreviousItem : function()
      {
                            // Called by the RadcomboBox. Do not call explicitly.
                            // Pointer <this> refers to the RadComboBox
                            
      var currentItem = this.HighlightedItem;
      var proposedIndex = 0;
       
      if (currentItem)
		   proposedIndex = currentItem.Index - 1;
   		
   	if (this.Items.length == 0)
   	   return;
   	   	
      proposedIndex = this.FindPrevAvailableIndex(proposedIndex);
       
      if (proposedIndex < 0)
         proposedIndex = this.Items.length - 1;
       
      if (proposedIndex >= 0)
         {
          this.Items[proposedIndex].Highlight();
          this.Items[proposedIndex].ScrollIntoView();
          this.Items[proposedIndex].Text;
    	    var lastSeparatorIndex = this.GetLastSeparatorIndex(this.GetText());
	       var textToSet = this.GetText().substring(0, lastSeparatorIndex + 1) + this.Items[proposedIndex].Text;
   	     
	       this.SetText(textToSet);
          this.SetValue(this.Items[proposedIndex].Value);
          }
      },   
   
   radComboBoxOnDropDownClick : function(e)
   {
	   var target = this.GetEventTarget(e);
	   var item = this.FindNearestItem(target);
   	
	   if (!item || !item.Enabled) 
	      return;
   	
	   this.HideDropDown();
	   this.PerformSelect(item);
   	
	   this.SelectText(this.GetText().length, this.GetText().length);

                             // Keep user text	   
	   this._comboBoxInstance._userTextBeforeToggle = this.GetText();
   },   
   
   radComboBoxOnInputChange : function()
      {
                            // Called by the RadcomboBox. Do not call explicitly.
                            // Pointer <this> refers to the RadComboBox   
                            
      this.SetValue("");
      this.TextHidden.value = this.InputDomElement.value;
      
      if (this._comboBoxInstance._isLoading === false && 
          this.EnableLoadOnDemand && 
          !this.SuppressChange && 
          !(this._comboBoxInstance._queryAll && this.Items.length != 0))
         {
	 	   var me = this;
   	 	
	 	   if (this.RequestTimeoutID > 0)
 		      {
 			   window.clearTimeout(this.RequestTimeoutID);
 			   this.RequestTimeoutID = 0;
 		      }
 		      
         if (!this.DropDownVisible)
            {
            if (!this._comboBoxInstance._queryAll)
               this._comboBoxInstance.setElementsDisplayOnLoading(this._comboBoxInstance);   
			   this.ShowDropDown();
			   }
		   
		   this.RequestTimeoutID = window.setTimeout(function() { me.RequestItems(me.GetText(), false); }, this.ItemRequestTimeout);
		   
		   return;
         }
            
      if (!this.SuppressChange && this.ShouldHighlight())
		   this.HighlightMatches();
      },   
      
   
   radComboBoxOnInputClick : function()
      {
                            // Called by the RadcomboBox. Do not call explicitly.
                            // Pointer <this> refers to the RadComboBox
      
	   if (this.ShowDropDownOnTextboxClick && !this.DropDownVisible)
		   this.ShowDropDown();
      },
     
   radComboBoxOnMoreResultsImageClick : function()
      {
                            // Called by the RadcomboBox. Do not call explicitly.
                            // Pointer <this> refers to the RadComboBox      
      
      this._comboBoxInstance._hideDropDownZoneOnLoading = false;
      
                            // Ensure that the mark first match scroll on top 
                            // won't apply on return
      this._comboBoxInstance._ensureDontScrollOnTop = true;                      
      
                            // Ensure right text to request
      var textToRequest = (this._comboBoxInstance._highlightedTextStartIndex == -1) ? this.GetText() : this.GetText().substring(0, this._comboBoxInstance._highlightedTextStartIndex);
	   
	                         // If user has not entered some text
      if (this._comboBoxInstance._hasUserTypedText === false)
         textToRequest = "";                      
      else
         this.SetText(textToRequest);
           
      this.RequestItems(textToRequest, true /*appendItems*/);
      },     
      
   radComboBoxOnKeyDown : function(e) 
      {
                            // Called by the RadcomboBox. Do not call explicitly.
                            // Pointer <this> refers to the RadComboBox      
            
      if (!e) e = event;
    
      var keyCode = e.keyCode || e.which;
      this.LastKeyCode = keyCode;

      this.Changed = true;

      e.returnValue = true;      
      this.FireEvent(this.OnClientKeyPressing, this, e);
      if (!e.returnValue)	
         return;
         
      if (keyCode === RadComboBox.Keys.Escape)
         {
         this.HideDropDown();                     
         this._comboBoxInstance.clearTextAndReQuery();
         this._comboBoxInstance.domUtilsStopEventPropagation(e);  
         return;
         }
	
      else if (keyCode === RadComboBox.Keys.Enter || keyCode === RadComboBox.Keys.Tab)
         {         
         if (this.GetText() == "")
            {
            this.HideDropDown();
            if (keyCode === RadComboBox.Keys.Enter)
               if (typeof(event) != "undefined")
                  event.keyCode = RadComboBox.Keys.Tab;
               else
                  e.keyCode = RadComboBox.Keys.Tab;     // Bug in FF
                  
                             // Simulate the Blur
            this._comboBoxInstance.clearAndReQuery(false /*queryEmptyString*/);
            
            return;
            }
         
         if (this.FindItemByText(this.GetText()) != null)
            {
            if (this.Items.length == 1)
               this.SetText(this.Items[0].Text);
          
            this.HideDropDown();
            
            if (keyCode === RadComboBox.Keys.Enter)
               this.PerformSelect(this.HighlightedItem);
           
            this.RaiseClientBlur();
            this.SelectItemOnBlur();
            this.Focused = false;
            
            if (keyCode === RadComboBox.Keys.Enter)
               if (typeof(event) != "undefined")
                  event.keyCode = RadComboBox.Keys.Tab;
               else
                  e.keyCode = RadComboBox.Keys.Tab;     // Bug in FF
            }
         else
            {
            this._comboBoxInstance._performMatch = true;
            this._comboBoxInstance.domUtilsStopEventPropagation(e);
            }

         return;
         }
             
      else if (keyCode === RadComboBox.Keys.Down && this._comboBoxInstance._isLoading === false)
         {
         this._comboBoxInstance.domUtilsStopEventPropagation(e);
        
         if (e.altKey)
         {
            this.ToggleDropDown();
            return;
         }
                  
         if (this.DropDownVisible)
            {
            var currentItem = this.HighlightedItem; 
            if (!this._comboBoxInstance._queryAll && currentItem != null && currentItem.Index == (this.Items.length - 1) && 
                this._comboBoxInstance._responseData != null && this._comboBoxInstance._responseData.HasMoreAvailableItems != null && 
                this._comboBoxInstance._responseData.HasMoreAvailableItems)
               {
               this._comboBoxInstance._hideDropDownZoneOnLoading = false;
               this._comboBoxInstance._highlightedItemToRestore = currentItem;
               
               this.RequestItems(this._comboBoxInstance._userTextBeforeItemToggle, true /*appendItems*/);
               }
            else
               this.HighlightNextItem();
            }
         else
            {
            this.SelectFirstMatch();
            if (this.HighlightedItem != null)
               this.Items[this.HighlightedItem.Index].ScrollIntoView();
            this._comboBoxInstance._forceSelectOnRequested = true;
            
            if (this.Items.length == 0)
               this._comboBoxInstance.requestItems("", false /*appendItems*/);
            else
               this._comboBoxInstance.initializeElementsDisplay();
            
            this.PositionDropDown();
	         this.InputDomElement.focus();
   	
            this._comboBoxInstance.adjustDropDownHeight(); 
            }
         
         return;
         }
       
      else if (keyCode === RadComboBox.Keys.Up && this._comboBoxInstance._isLoading === false)
         {
         this._comboBoxInstance.domUtilsStopEventPropagation(e);
        
         if (e.altKey)
            {
            this.ToggleDropDown();
            return;
            }
         
         if (this.DropDownVisible)
            this.HighlightPreviousItem();
            
         return;
         }
         
      else if (keyCode === GIRO.Web.UI.WebControls.Keys.BackSpace &&  this._comboBoxInstance._isLoading === true)  
         {
         this.MarkFirstMatch = false;
         }
         
      else if (keyCode !== GIRO.Web.UI.WebControls.Keys.BackSpace)
         {
         this._processBackSpaceOnNextHighlight = true;
         }
         
      else if (keyCode == RadComboBox.Keys.Left || keyCode == RadComboBox.Keys.Right)
         return;

      else if (keyCode < RadComboBox.Keys.Space && keyCode !== GIRO.Web.UI.WebControls.Keys.BackSpace)
         return;

      else if (keyCode >= RadComboBox.Keys.PageUp && keyCode < RadComboBox.Keys.Del)
         return;

      else if (keyCode >= RadComboBox.Keys.F1 && keyCode <= RadComboBox.Keys.F12)
         return;
         
      else if (keyCode === GIRO.Web.UI.WebControls.Keys.BackSpace && this._comboBoxInstance._queryAll === true)
         return;
         
      this._comboBoxInstance._hasUserTypedText = true;
      
      if (this._comboBoxInstance._isLoading === false)
         this._comboBoxInstance.showDropDown();
      },
      
   radComboBoxShouldHighlight : function()
      {
                            // Called by the RadcomboBox. Do not call explicitly.
                            // Pointer <this> refers to the RadComboBox
                            
      if (this.LastKeyCode == GIRO.Web.UI.WebControls.Keys.BackSpace)
         return true;
      
	   if (this.LastKeyCode < RadComboBox.Keys.Space)
		   return false;
       
      if (this.LastKeyCode >= RadComboBox.Keys.PageUp && this.LastKeyCode < RadComboBox.Keys.Del)
		   return false;
       
      if (this.LastKeyCode >= RadComboBox.Keys.F1 && this.LastKeyCode <= RadComboBox.Keys.F12)
		   return false;
      
      return true;
      },  
      
   domUtilityIsIE6 : function()
      {
      return (navigator.userAgent.indexOf("MSIE 6.0") != -1);
      },

   radComboBoxDetachDropDown : function()
      {    
      if ((!document.readyState || document.readyState == "complete" || this._comboBoxInstance.domUtilityIsIE6()) && (!this.IsDetached))
         {
         var parentElement = document.body;

         if (this.DropDownRequiresForm())
            {
            parentElement = this.FindParentForm();
            }

         this.DropDownPlaceholder.parentNode.removeChild(this.DropDownPlaceholder);
         this.DropDownPlaceholder.style.marginLeft = "0";

         parentElement.insertBefore(this.DropDownPlaceholder, parentElement.firstChild);

         this.IsDetached = true;
         }
      },
      
   radComboBoxShowDropDown : function(skipLoadingItems)
      {
                            // Called by the RadcomboBox. Do not call explicitly.
                            // Pointer <this> refers to the RadComboBox  
         
      if (this.DropDownVisible)
         return;
                                
      if (this.FireEvent(this.OnClientDropDownOpening, this) === false)
		   return;
   	
      this.PositionDropDown();
	   this.InputDomElement.focus();
   	
   	this.SelectText(this.GetText().length, this.GetText().length);
   	
	   if (this.EnableLoadOnDemand && this.Items.length == 0 && !skipLoadingItems)
	      this.RequestItems(this.GetText(), false);
                                  
      this._comboBoxInstance.adjustDropDownHeight();
      }, 
      
   registerEventHandlers : function() 
      {
      this._onApplicationLoaded$delegate = Function.createDelegate(this, this.onApplicationLoaded);
      Sys.Application.add_load(this._onApplicationLoaded$delegate);
      },        
      
   reQueryOnLoad : function()
      {    
      if (this._isWaitingForReQueryOnLoad == true)
         {
         var handler = this.get_events().getHandler(GIRO.Web.UI.WebControls.ComboBoxEvents.ReQueryOnLoad.toString());
         if (handler != null) 
            handler(this, Sys.EventArgs.Empty);                   
         else
            {
            this._isWaitingRequestItems = true;
            this.requestItems(this._reQueryText, false /*appendItems*/);            
            }
         }      
      },
      
   requestItems : function(queryText, appendItems) 
      {
      this._isLoading = true;
      
      if (!(this._radComboBox.Items.length > 0 && this._queryAll))
         this.setElementsDisplayOnLoading(this);      
      
      var clientDataString = this.buildRequestItemsParametersString();
      
      if (this._onClientDataFunction != null && this._onClientDataFunction != "")
         clientDataString += eval(this._onClientDataFunction);
      else
         {
         var handler = this.get_events().getHandler(GIRO.Web.UI.WebControls.ComboBoxEvents.ItemsRequesting.toString());
         if (handler != null) 
            {
            var eventArgs = new GIRO.Web.UI.WebControls.ItemsRequestingEventArgs();            
            handler(this, eventArgs);   
            clientDataString += eventArgs.GetClientData();
            }
         }

      this._radComboBox.ClientDataString = clientDataString;
      this._radComboBox.RequestItems(queryText, appendItems);
      },         
      
   saveClientState : function() 
      {
      if (this._clientStateField == null) return;
      
      var selectedIndex = this._selectedIndex;
      var reQueryText = this._reQueryText;
      
      var state = { SelectedIndex:selectedIndex, ReQueryText:reQueryText };
      
      var payload = Sys.Serialization.JavaScriptSerializer.serialize(state);
      this._clientStateField.value = payload;
      
      return (payload);
      },        
      
   setElementsDisplayOnLoading : function(workingObject)   
   {
      var elementDropDown = $get(workingObject._radComboBox.DropDownID);   
      elementDropDown.style.display = this._hideDropDownZoneOnLoading ? "none" : "block";         
         
      var elementOverlay = $get(workingObject._radComboBox.ClientID + "_Overlay");
      if (elementOverlay != undefined)
         elementOverlay.style.display = this._hideDropDownZoneOnLoading ? "none" : "block"; 
         
      var elementMoreResultsBoxMessage = $get(workingObject._radComboBox.MoreResultsBoxMessageID);
      elementMoreResultsBoxMessage.innerHTML = workingObject._loadingText;           
      elementMoreResultsBoxMessage.className = "ComboBoxLoading_" + workingObject._skin; 
      elementMoreResultsBoxMessage.style.display = "block";
         
      var elementMoreResults = $get(workingObject._radComboBox.MoreResultsBoxID);
      elementMoreResults.style.display = "block";
      
      var elementMoreResultsImage = $get(workingObject._radComboBox.ClientID + "_MoreResultsBoxImage");
      elementMoreResultsImage.style.display = "none";
      },      
      
   showDropDown : function()
      {
      if (this._radComboBox.DropDownVisible)
         return;
       
      if (this._queryAll && this._radComboBox.Items.length > 0)
         this.initializeElementsDisplay();
      else
         this.setElementsDisplayOnLoading(this); 
                                
	   this._radComboBox.PositionDropDown();
	   this._radComboBox.InputDomElement.focus();
   	
      this.adjustDropDownHeight();
      }, 


                             // Outside access
         
   ClearAll : function()
      {
      this.clear(this._queryAll ? false : true /*clearItems*/); 
      },       
      
   GetValue : function()
      {
      var value = "";
      if (this._radComboBox != null && this._radComboBox.SelectedItem != null && this._radComboBox.SelectedItem.Value != null)
         value = this._radComboBox.SelectedItem.Value;
      
      return (value);   
      }, 
      
   GetText : function()
      {
      var text = "";
      if (this._radComboBox != null && this._radComboBox.SelectedItem != null && this._radComboBox.SelectedItem.Text != null)
         text = this._radComboBox.SelectedItem.Text;
      
      return (text);   
      },  
      
   ReQuery : function()
      {
      var handler = this.get_events().getHandler(GIRO.Web.UI.WebControls.ComboBoxEvents.ReQuery.toString());
      if (handler != null) 
         handler(this, Sys.EventArgs.Empty);  
      else
         {
         this._isWaitingRequestItems = true;
         this.requestItems(this._reQueryText, false /*appendItems*/);           
         }
      },   
      
   SetReQueryText : function (text, reQueryText)
      {
      if (this._radComboBox != null)
         this._radComboBox.SetText(text);
      this._reQueryText = reQueryText;  
      },  
      
                             // For ScriptControlBase ClientState      
   get_clientStateField : function() {return this._clientStateField; },
   set_clientStateField : function(value) {this._clientStateField = value; },

                             // For ExtenderControlProperty  
   get_AutoPostBack : function() { return (this._autoPostBack); },
   set_AutoPostBack : function(value) { this._autoPostBack = value; },
   get_ClientID : function() { return (this._clientID); },
   set_ClientID : function(value) { this._clientID = value; }, 
   get_ErrorText : function() { return (this._errorText); },
   set_ErrorText : function(value) { this._errorText = value; },    
   get_ID : function() { return (this._id); },
   set_ID : function(value) { this._id = value; },
   get_LoadingText : function() { return (this._loadingText); },
   set_LoadingText : function(value) { this._loadingText = value; },    
   get_OnClientDataFunction : function() { return (this._onClientDataFunction); },
   set_OnClientDataFunction : function(value) { this._onClientDataFunction = value; }, 
   get_OnClientReQueryFunction : function() { return (this._onClientReQueryFunction); },
   set_OnClientReQueryFunction : function(value) { this._onClientReQueryFunction = value; },  
   get_OnClientSelectionChangeFunction : function() { return (this._onClientSelectionChangeFunction); },
   set_OnClientSelectionChangeFunction : function(value) { this._onClientSelectionChangeFunction = value; },  
   get_QueryAll : function() { return (this._queryAll); },
   set_QueryAll : function(value) { this._queryAll = value; }, 
   get_QueryRows : function() { return (this._queryRows); },
   set_QueryRows : function(value) { this._queryRows = value; },         
   get_Skin : function() { return (this._skin); },
   set_Skin : function(value) { this._skin = value; }                                
}
GIRO.Web.UI.WebControls.ComboBox.registerClass("GIRO.Web.UI.WebControls.ComboBox", Sys.UI.Control);

if (typeof(Sys) !== 'undefined') 
   Sys.Application.notifyScriptLoaded(); 
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();