function stopPropagation(e)
{
return;
    e.cancelBubble = true;
    if (e.stopPropagation)
    {
        e.stopPropagation();
    }
}
if (typeof(window.RadControlsNamespace) == "undefined")
{
	window.RadControlsNamespace = new Object();
}

RadControlsNamespace.AppendStyleSheet = function(callback, clientID, pathToCssFile)
{
	if (!pathToCssFile) 
	{ 
		return; 
	}

	if (!callback)
	{
		document.write("<" + "link" + " rel='stylesheet' type='text/css' href='" + pathToCssFile + "' />");
	}
	else
	{
		var linkObject = document.createElement("LINK");
		linkObject.rel = "stylesheet";
		linkObject.type = "text/css";
		linkObject.href = pathToCssFile;
		document.getElementById(clientID + "StyleSheetHolder").appendChild(linkObject);
	}
}

function RadComboItem()
{
	this.ComboBox = null;
	this.ClientID = null;
	this.Index = 0;
	this.Highlighted =false;
	this.Enabled = true;
	this.Selected = 0;	
	this.Text = "";
	this.Value = "";
	this.Attributes = new Array();	
}
		
RadComboItem.prototype.Initialize = function(json)
{
	for (var propertyName in json)
    {
        this[propertyName] = json[propertyName];
    } 
}

RadComboItem.prototype.Select = function ()
{
    if (this.ComboBox.FireEvent(this.ComboBox.OnClientSelectedIndexChanging, this) === false)
    {
		return;
    }
    
    var text = this.ComboBox.GetText();
    var textToSet = "";
    if(this.ComboBox.MultiComboSelection == true)
    {
            
        if(text == this.Text)
        {
            textToSet = "";
            if(this.DomElement == null)
                this.GetDomElement();
            this.DomElement.firstChild.checked = false;
     }
        else
        {
            var faund = false;
            var values = new Array();
            if(text == this.ComboBox.Items[0].Text)
                text = "";
            if(text.length > 0)
            {
                var values = text.split(";");
                for(var i = 0; i < values.length; i++)
                {
                    if(values[i] == this.Text)
                    {
                        values.splice(i, 1);
                        faund = true
                        break;
                    }
                    
                }
            }
            
            if(faund == false)
            {
                values[values.length] = this.Text;
            }
            
 	        if(this.DomElement == null)
	            this.GetDomElement();
           this.DomElement.firstChild.checked = !faund;
             textToSet = values.join(";");
        }
    }
    else
    {
        var lastSeparatorIndex = this.ComboBox.GetLastSeparatorIndex(text);
	    //Append the item text after the last separator
	    var textToSet = text.substring(0, lastSeparatorIndex + 1) + this.Text;
	}
    this.ComboBox.SetText(textToSet);
    this.ComboBox.SetValue(this.Value);
    this.ComboBox.SelectedItem = this;  
    this.ComboBox.SelectedIndex = this.Index;
    this.Highlight();
    this.ComboBox.FireEvent(this.ComboBox.OnClientSelectedIndexChanged, this);
    this.ComboBox.PostBack();
}

RadComboItem.prototype.Highlight = function()
{
	if (!this.Enabled) return;
	
    if (!this.ComboBox.IsTemplated || this.ComboBox.HighlightTemplatedItems)
    {
		if (this.ComboBox.HighlightedItem)
		{
			this.ComboBox.HighlightedItem.SetCssClass(this.ComboBox.ItemCssClass);
		}

		this.SetCssClass(this.ComboBox.ItemCssClassHover);
    }
	this.ComboBox.HighlightedItem = this;
	this.Highlighted = true;
}

RadComboItem.prototype.UnHighlight = function()
{
	if (!this.ComboBox.IsTemplated || this.ComboBox.HighlightTemplatedItems)
    {
	  this.SetCssClass(this.ComboBox.ItemCssClass);
	}
	
	this.ComboBox.HighlightedItem = null;
	this.Highlighted =false;
}

RadComboItem.prototype.ScrollIntoView = function ()
{
	var itemOffset = this.GetDomElement().offsetTop;
	var itemHeight = this.GetDomElement().offsetHeight;
	var dropDownOffset = this.ComboBox.DropDownDomElement.scrollTop;
	var dropDownVisibleHeight = this.ComboBox.DropDownDomElement.offsetHeight;
	
	if (itemOffset + itemHeight > dropDownOffset + dropDownVisibleHeight)
	{
		this.ComboBox.DropDownDomElement.scrollTop = itemOffset + itemHeight - dropDownVisibleHeight;
	}
	else if (itemOffset + itemHeight <= dropDownOffset)
	{
		this.ComboBox.DropDownDomElement.scrollTop = itemOffset;
	}
}

RadComboItem.prototype.ScrollOnTop = function ()
{
	this.ComboBox.DropDownDomElement.scrollTop = this.GetDomElement().offsetTop;
}

RadComboItem.prototype.NextItem = function ()
{
	return this.ComboBox.Items[this.Index + 1];
}

RadComboItem.prototype.GetDomElement = function ()
{
	if (!this.DomElement)
	{
		this.DomElement = document.getElementById(this.ClientID);
	}
	
	return this.DomElement;
}

RadComboItem.prototype.SetCssClass = function (className)
{
	this.GetDomElement().className = className;
}

function RadComboBox(comboBoxID, comboBoxClientID, showWhileLoading)
{	
	var oldCombo = window[comboBoxClientID];
	
	if (oldCombo != null && typeof(oldCombo.Dispose) != "undefined")
	{	
		oldCombo.Dispose();
	}
	
	if (window.tlrkComboBoxes == null)
	{
		window.tlrkComboBoxes = new Array();
	}
	
	tlrkComboBoxes[tlrkComboBoxes.length] = this;
	
	this.Items = new Array();
	this.ItemMap = new Object();
	
	this.Created = false;
	this.ID = comboBoxID;
	this.ClientID = comboBoxClientID;
	this.TagID = comboBoxClientID;	
	this.DropDownID = comboBoxClientID + "_DropDown";
	this.InputID = comboBoxClientID + "_Input";
	this.ImageID = comboBoxClientID + "_Image";
	this.DropDownPlaceholderID = comboBoxClientID + "_DropDownPlaceholder";
	this.MoreResultsBoxID = comboBoxClientID + "_MoreResultsBox";	
	this.MoreResultsBoxImageID = comboBoxClientID + "_MoreResultsBoxImage";	
	this.MoreResultsBoxMessageID = comboBoxClientID + "_MoreResultsBoxMessage";
	this.Header = comboBoxClientID + "_Header";	
	this.Changed =false;
	this.Focused = false;
	
	this.InputDomElement = document.getElementById(this.InputID);
	
	this.CachedText = this.OriginalText = this.InputDomElement.value;
	this.ImageDomElement = document.getElementById(this.ImageID);
	
	this.DropDownPlaceholder = document.getElementById(this.DropDownPlaceholderID);
	this.DropDownDomElement = document.getElementById(this.DropDownID);
	
	this.MoreResultsImageDomElement = document.getElementById(this.MoreResultsBoxImageID);
	this.MoreResultsBoxMessageDomElement = document.getElementById(this.MoreResultsBoxMessageID);
	
	this.DomElement = document.getElementById(this.ClientID);
	this.ValueHidden = document.getElementById(this.ClientID + "_value");
	this.TextHidden = document.getElementById(this.ClientID + "_text");
	
	
	this.ClientWidthHidden = document.getElementById(this.ClientID + "_clientWidth");
	this.ClientHeightHidden = document.getElementById(this.ClientID + "_clientHeight");
    this.MultiComboSelection = (this.ClientID.indexOf("_MultiComboSelection") > 0);

	this.Enabled = true;
	this.DropDownVisible = false;	
	this.LoadOnDemandUrl = null;
	this.HighlightedItem = null;
	this.SelectedItem = null;
	this.ItemRequestTimeout = 300;
	this.EnableLoadOnDemand = false;	
	this.AutoPostBack = false;
	this.ShowMoreResultsBox = false;
	this.OpenDropDownOnLoad = false;
	this.MarkFirstMatch = false;
	this.IsCaseSensitive = false;
	this.SelectOnTab = true;
	
	this.PostBackReference = null;
	this.LoadingMessage = "Loading...";		
	this.ScrollDownImage = null;
	
	this.ScrollDownImageDisabled = null;
	
	this.Overlay = null;
	this.RadComboBoxImagePosition = "Right";
		
	this.ItemCssClass = null;
	this.ItemCssClassHover = null;
	this.ItemCssClassDisabled = null;
	this.ImageCssClass = null;
	this.ImageCssClassHover = null;
	this.InputCssClass = null;
	this.InputCssClassHover = null;	
	this.LoadingMessageCssClass = "ComboBoxLoadingMessage";	
	this.AutoCompleteSeparator = null;
	this.ExternalCallBackPage = null;
	
	this.OnClientSelectedIndexChanging = null;	
	this.OnClientDropDownOpening = null;	
	this.OnClientDropDownClosing = null;	
	this.OnClientItemsRequesting = null;
	this.OnClientSelectedIndexChanged = null;
	this.OnClientItemsRequested = null;
	this.OnClientKeyPressing = null;
	this.OnClientBlur = null;
	this.OnClientFocus = null;
	
	this.Skin = "Classic";
	
	this.HideTimeoutID = 0;
	this.RequestTimeoutID = 0;
	this.IsDetached = false;
	this.TextPriorToCallBack = null;
	this.AllowCustomText = false;
	this.ExpandEffectString = null;
	this.HighlightTemplatedItems = false;
	this.CausesValidation = false;
	this.ClientDataString = null;
	this.ShowDropDownOnTextboxClick	= true;
	this.ShowWhileLoading = showWhileLoading;
	this.MoreResultsImageHovered = false;
	this.ErrorMessage = null;
	this.AfterClientCallBackError = null;
	this.PostBackActive = false;	
	this.SelectedIndex = -1;
	this.IsTemplated = false;
	this.CurrentText = null;
	this.OffsetX = 0;
	this.OffsetY = 0;
	this.Disposed = false;
	
	var me = this;	
	
	this.DetermineDirection();
	
	this.InputDomElement.setAttribute("autocomplete", "off");
	
	this.DropDownPlaceholder.onselectstart = function() { return false; };	
	
	RadControlsNamespace.DomEventMixin.Initialize(this);
	
	if (this.ImageDomElement)
	{
		this.AttachDomEvent(this.ImageDomElement, "click", "OnImageClick");
	}
	
	this.AttachDomEvent(document, "click", "OnDocumentClick");
	this.AttachDomEvent(this.InputDomElement, "click", "OnInputClick");
	this.AttachDomEvent(this.InputDomElement, "keydown", "OnKeyDown");	
	this.AttachDomEvent(this.InputDomElement, "focus", "OnFocus");
	
	this.AttachDomEvent(this.InputDomElement, "input", "OnInputChange");
	this.AttachDomEvent(this.InputDomElement, "propertychange", "OnInputPropertyChange");
	
	this.AttachDomEvent(this.DropDownPlaceholder, "mouseover", "OnDropDownOver");
	this.AttachDomEvent(this.DropDownPlaceholder, "mouseout", "OnDropDownOut");
	this.AttachDomEvent(this.DropDownPlaceholder, "click", "OnDropDownClick");
	
	if (this.MoreResultsImageDomElement)
	{
		this.AttachDomEvent(this.MoreResultsImageDomElement, "mouseover", "OnMoreResultsImageOver");	
		this.AttachDomEvent(this.MoreResultsImageDomElement, "mouseout", "OnMoreResultsImageOut");
		this.AttachDomEvent(this.MoreResultsImageDomElement, "click", "OnMoreResultsImageClick");	
	}
	
	
	if (typeof(RadCallbackNamespace) != "undefined")
	{
		window.setTimeout(function() { me.FixUp(me.InputDomElement, true) }, 100);	
	}
	else
	{		
		if (window.addEventListener)
		{
			if (window.opera)
			{
				this.AttachDomEvent(window, "load", "OnWindowLoad");
			}
			else
			{
				this.OnWindowLoad();
			}
		}
		else
		{	
			if (document.getElementById(this.ClientID).offsetWidth == 0)
			{
			    this.AttachDomEvent(window, "load", "OnWindowLoad");
			}
			else
			{	
				this.OnWindowLoad();
			}
		}
	}
	this.AttachDomEvent(window, "resize", "OnWindowResize");
	this.AttachDomEvent(window, "unload", "Dispose");
	
}

RadComboBox.prototype.OnWindowResize = function ()
{
	if (this.DropDownVisible)
	{
		this.PositionDropDown();
	}
}

RadComboBox.prototype.Initialize = function (configObject, itemData)
{	
	this.LoadConfiguration(configObject);
	
	if (!this.Enabled)
		this.Disable();
	
	
	this.CreateItems(itemData);
	this.InitCssNames();
	
	if (this.OpenDropDownOnLoad)
	{
		this.AttachDomEvent(window, "load", "OpenOnLoad");
	}
}

RadComboBox.prototype.OpenOnLoad = function () 
{ 
	this.FixUp(this.InputDomElement, false);
	this.ShowDropDown(); 
}

RadComboBox.prototype.OnWindowLoad = function () 
{ 
	this.FixUp(this.InputDomElement, true);
}

RadComboBox.Keys = 
{
	Shift : 16,
	Escape: 27,
	Up : 38,
	Down : 40,
	Left : 37,
	Right : 39,
	Enter : 13,
	Tab : 9,
	Space : 32,
	PageUp : 33,
	Del : 46,
	F1: 112,
	F12 : 123
}

RadComboBox.prototype.FireEvent = function (eventName, firstParam, secondParam, thirdParam)
{
    if (!eventName)
        return;
    
    var lastIndex = eventName.lastIndexOf(")");
    
    if (lastIndex == eventName.length - 1)
    {
		return eval(eventName);
    }
    
    RadComboBoxGlobalFirstParam = firstParam;
	RadComboBoxGlobalSecondParam = secondParam;
	RadComboBoxGlobalThirdParam = thirdParam;
	
	var s = eventName;
	s = s + "(RadComboBoxGlobalFirstParam";
	s = s + ",RadComboBoxGlobalSecondParam";
	s = s + ",RadComboBoxGlobalThirdParam";
	s = s + ");";
			
	return eval(s);	
}

RadComboBox.prototype.PostBack = function()
{
	if (this.PostBackActive) return;
	
	this.PostBackActive = true;
	
	if (this.AutoPostBack)
	{
		if (this.CausesValidation)
		{
			if (typeof(WebForm_DoPostBackWithOptions) != 'function' && !(typeof(Page_ClientValidate) != 'function' || Page_ClientValidate()))
			{
				return;
			}
		}		
		eval(this.PostBackReference);
		this.PostBackActive = false;
	}
}
RadComboBox.prototype.SelectFirstMatch = function()
{
	var itemToSelect = this.FindItemToSelect();
	
	if (itemToSelect && itemToSelect.Enabled)
	{
		itemToSelect.Highlight();
		this.SelectedItem = itemToSelect;
	}
}

RadComboBox.prototype.SelectText = function(startIndex, endIndex)
{	
	if (this.InputDomElement.createTextRange)
	{
		var textRange = this.InputDomElement.createTextRange();
	
		if (startIndex == 0 && endIndex == 0)
		{
			textRange.collapse(true);
			return;
		}
		textRange.moveStart("character", startIndex);
		textRange.moveEnd("character", endIndex);
		textRange.select();
	}
	else
	{
		this.InputDomElement.setSelectionRange(startIndex, startIndex + endIndex);
	}
}
RadComboBox.prototype.OnInputClick = function()
{
	this.SelectFirstMatch();
	this.SelectText(0, this.GetText().length);
	
	if (this.ShowDropDownOnTextboxClick && !this.DropDownVisible)
	{
		this.ShowDropDown();
	}
}
RadComboBox.prototype.OnInputPropertyChange = function()
{
	if (event.propertyName == "value")
	{
		var text = this.GetText();
		if (this.CachedText != text)
		{
			this.CachedText = text;
			this.OnInputChange();
		}
	}
}
RadComboBox.prototype.OnInputChange = function()
{
   //Reset the value (required to support multiple items with the same text)
   this.SetValue("");
   this.TextHidden.value = this.InputDomElement.value;
   if (this.EnableLoadOnDemand && !this.SuppressChange)
   {
	 	var me = this;
	 	
	 	if (this.RequestTimeoutID > 0)
 		{
 			window.clearTimeout(this.RequestTimeoutID);
 			this.RequestTimeoutID = 0;
 		}
        if (!this.DropDownVisible)
		{
			this.ShowDropDown();
		}
		this.RequestTimeoutID = window.setTimeout(function(){me.RequestItems(me.GetText(), false);}, this.ItemRequestTimeout);
		return;
   }
   
   if (!this.SuppressChange && this.ShouldHighlight())
   {
		this.HighlightMatches();
   }
}

RadComboBox.prototype.OnImageClick = function()
{
	this.SelectFirstMatch();
	this.ToggleDropDown();
}

RadComboBox.prototype.OnDocumentClick = function(e)
{ 
	if (!e) e = event;
	
	var target = e.target || e.srcElement;
	
	while (target.nodeType !== 9)
	{
		if (target == this.DomElement || target == this.DropDownPlaceholder)
		{
			return;
		}
		target = target.parentNode;
	}
	
   
	if (this.DropDownVisible)
	{
		this.HideDropDown();
	}
	if (this.Focused)
    {  
		this.RaiseClientBlur();
		if(this.MultiComboSelection == false)
		    this.SelectItemOnBlur();
		this.Focused = false;
		
	}
} 

RadComboBox.prototype.SelectItemOnBlur = function ()
{ 
	var itemToSelect = this.FindItemToSelect();
	if (!itemToSelect && !this.AllowCustomText && this.Items.length > 0)
	{
	  
		if (this.MarkFirstMatch )
		{  
		    if(this.GetText() == "")
		    {
		       this.SetText(this.OriginalText);
		    }
			this.HighlightMatches();
			this.SelectText(0,0);
			itemToSelect = this.HighlightedItem;
		}
	}
	
	this.PerformSelect(itemToSelect);
}

RadComboBox.prototype.FindItemToSelect = function ()
{
	//Required to support multiple items with the same text.
	var itemToSelect = this.FindItemByValue(this.GetValue());
	
	if (!itemToSelect)
		itemToSelect = this.FindItemByText(this.GetText());
	
	return itemToSelect;
}

RadComboBox.prototype.OnMoreResultsImageOver = function()
{
	this.MoreResultsImageDomElement.style.cursor = "pointer";
	this.MoreResultsImageDomElement.src = this.ScrollDownImage;
	this.MoreResultsImageHovered = true;
}

RadComboBox.prototype.OnMoreResultsImageOut = function()
{
	this.MoreResultsImageDomElement.style.cursor = "default";
	this.MoreResultsImageDomElement.src = this.ScrollDownImageDisabled;
	this.MoreResultsImageHovered = false;
}

RadComboBox.prototype.OnMoreResultsImageClick = function()
{
	this.RequestItems(this.GetText(), true);
}

RadComboBox.prototype.OnDropDownOver = function(e)
{
	var target = this.GetEventTarget(e);
	var item = this.FindNearestItem(target);
	
	if (item)
	{
		item.Highlight();
	}
}

RadComboBox.prototype.OnDropDownOut = function(e)
{
    if (!e) e = event;
	var relatedTarget;
	try
	{
		relatedTarget = e.toElement ||e.relatedTarget || e.fromElement;	
		while (relatedTarget.nodeType !== 9)
	    {
		    if (relatedTarget.parentNode == this.DropDownDomElement)
		    {
			    return;
		    }
		    relatedTarget = relatedTarget.parentNode;
	    }
	}
	catch (e)
	{
	}

	
	if (this.HighlightedItem)
	{
		this.HighlightedItem.UnHighlight();
	}
}

RadComboBox.prototype.OnDropDownClick = function(e)
{
	var target = this.GetEventTarget(e);
	var item = this.FindNearestItem(target);
	
	if (!item ||!item.Enabled) return;
	
	if(item.DomElement == null)
	    item.GetDomElement();
	if(this.MultiComboSelection == true)
	{
	    if(item.DomElement.firstChild != null)
	    {
            this.PerformSelect(item);
   	        return;
	    }
	}
	
    this.HideDropDown();
    this.PerformSelect(item);
	 
}

RadComboBox.prototype.GetEventTarget = function (e)
{
	return e.target || e.srcElement;
}

RadComboBox.prototype.FindNearestItem = function(element)
{
	while (element.nodeType !== 9)
	{
		if (element.parentNode == this.DropDownDomElement)
		{
			return this.ItemMap[element.id];
		}
		element = element.parentNode;
	}
	
	return null;
}


RadComboBox.prototype.GetViewPortSize = function() 
{
	var width = 0;
	var height = 0;
	
	var canvas = document.body;
	
	if (window.innerWidth) 
	{
		width = window.innerWidth;
		height = window.innerHeight;
	} 
	else
	{
		if (document.compatMode && document.compatMode == "CSS1Compat")
		{
		    canvas = document.documentElement;
		}
		
		width = canvas.clientWidth;
		height = canvas.clientHeight;
	}
	width += canvas.scrollLeft;
	height += canvas.scrollTop;
	
	return { width : width - 6, height : height - 6 };
};
		
RadComboBox.prototype.GetElementPosition = function (el)
{
	var parent = null;
	var pos = {x: 0, y: 0};
	var box;

	if (el.getBoundingClientRect) 
	{ 
		// IE
		box = el.getBoundingClientRect();
		var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
		var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;

		pos.x = box.left + scrollLeft - 2;
		pos.y = box.top + scrollTop - 2;
	    
		return pos;
	}
	else if (document.getBoxObjectFor) 
	{ 
		// gecko
		box = document.getBoxObjectFor(el);
		pos.x = box.x - 1;
		pos.y = box.y - 1;
	}
	else 
	{ 
		// safari/opera
		pos.x = el.offsetLeft;
		pos.y = el.offsetTop;
		parent = el.offsetParent;
		if (parent != el)
		{
			while (parent) 
			{
				pos.x += parent.offsetLeft;
				pos.y += parent.offsetTop;
				parent = parent.offsetParent;
			}
		}
	}

	if (window.opera)
	{
		parent = el.offsetParent;
		
		while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') 
		{
			pos.x -= parent.scrollLeft;
			pos.y -= parent.scrollTop;
			parent = parent.offsetParent;
		}
	}
	else
	{
		parent = el.parentNode; 
		while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') 
		{
			pos.x -= parent.scrollLeft;
			pos.y -= parent.scrollTop;

			parent = parent.parentNode;
		}
	}

	return pos;
}

RadComboBox.prototype.Dispose = function()
{	
	if (this.Disposed) return;
	
 	if (this.RequestTimeoutID > 0)
	{
		window.clearTimeout(this.RequestTimeoutID);
		this.RequestTimeoutID = 0;
	}

	this.HideDropDown();
	
	if (this.Overlay && this.Overlay.parentNode)
	{
		this.Overlay.parentNode.removeChild(this.Overlay);
		this.Overlay = null;
	}
	
	if (this.LoadingDiv)
	{	
		if (this.LoadingDiv.parentNode)
			this.LoadingDiv.parentNode.removeChild(this.LoadingDiv);
			
		this.LoadingDiv = null;
	}
	
	if (this.DropDownPlaceholder != null && this.DropDownPlaceholder.parentNode != null)
	{
		
		try
        {
            this.DropDownPlaceholder.parentNode.removeChild(this.DropDownPlaceholder);
        }
        catch(e)
        {
            //Sometimes this fails for no particular reason
        }
	}
	
	this.DisposeDomEventHandlers();
	
	this.InputDomElement = null;
	this.ImageDomElement = null;
	this.DropDownPlaceholder = null;
	this.DropDownDomElement = null;
	this.MoreResultsImageDomElement = null;
	this.MoreResultsBoxMessageDomElement = null;
	this.DomElement = null;
	this.ValueHidden = null;;
	this.ClientWidthHidden = null;
	this.ClientHeightHidden = null;
	
    tlrkComboBoxes[this.ID] = null;
 	
 	this.Disposed = true;	
}


RadComboBox.prototype.LoadConfiguration = function (configObject)
{
    for (var property in configObject)
    {
        this[property] = configObject[property];
    } 
};

RadComboBox.prototype.InitCssNames = function()
{
	this.ItemCssClass =				 "ComboBoxItem_" + this.Skin;
	this.ItemCssClassHover =		 "ComboBoxItemHover_" + this.Skin;
	this.ItemCssClassDisabled =		 "ComboBoxItemDisabled_" + this.Skin;
	this.ImageCssClass =			 "ComboBoxImage_" + this.Skin;
	this.ImageCssClassHover =		 "ComboBoxImageHover_" + this.Skin;
	this.InputCssClass =			 "ComboBoxInput_" + this.Skin;
	this.InputCssClassHover =		 "ComboBoxInputHover_" + this.Skin;
	this.LoadingMessageCssClass =	 "ComboBoxLoadingMessage_" + this.Skin;
};



RadComboBox.prototype.FindParentForm = function()
{
	var currentElement = document.getElementById(this.TagID);	
	while (currentElement.tagName != "FORM")
	{
		currentElement = currentElement.parentNode;
	}
	
	return currentElement;
};

RadComboBox.prototype.DropDownRequiresForm = function()
{
	var inputTags = this.DropDownPlaceholder.getElementsByTagName("input");
	
	return inputTags.length > 0;
}

RadComboBox.prototype.DetachDropDown = function()
{
	if ( (!document.readyState || document.readyState == "complete") && (!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;
	}
};


RadComboBox.prototype.CreateItems = function(itemData)
{	
	for (var i=0; i<itemData.length; i++)
	{
		var item = new RadComboItem();
		item.ComboBox = this;		
		item.Index = this.Items.length;
		
		item.Initialize(itemData[i]);
		
		if (item.Selected)
		{
			this.SelectedItem = item;
		}
		
		this.ItemMap[item.ClientID] = item;
		this.Items[this.Items.length] = item;
	}	
};

RadComboBox.prototype.ShowOverlay = function(x, y)
{
	if (document.readyState && document.readyState != "complete")
	{
		return;
	}
	
	if (!document.all || window.opera)
	{
		return;	
	}
	
	if (this.Overlay == null)
	{
		this.Overlay = document.createElement("iframe");
		this.Overlay.src = "javascript:''";
		this.Overlay.id = this.ClientID + "_Overlay";
		this.Overlay.frameBorder = 0;
		this.Overlay.style.position = "absolute";
		this.Overlay.style.display = "none";
		this.DetachDropDown();
		this.DropDownPlaceholder.parentNode.insertBefore(this.Overlay, this.DropDownPlaceholder);
		this.Overlay.style.zIndex = this.DropDownPlaceholder.style.zIndex - 1;
	}
	
	this.Overlay.style.left = x;
	this.Overlay.style.top = y;
	this.Overlay.style.width = this.DropDownPlaceholder.offsetWidth + "px";
	this.Overlay.style.height = this.DropDownPlaceholder.offsetHeight + "px";    
	this.Overlay.style.display = "block";
};

RadComboBox.prototype.HideOverlay = function()
{
	if (!document.all || window.opera)
	{
		return;	
	}
	
	if (this.Overlay != null)
	{
		this.Overlay.style.display = "none";
	}
};

RadComboBox.prototype.DetermineDirection = function ()
{
    var el = document.getElementById(this.ClientID + "_wrapper");
    
    while (el.tagName.toLowerCase() != 'html')
    {
        if (el.dir)
        {
            this.RightToLeft = (el.dir.toLowerCase() == "rtl");
            return;
        }
        el = el.parentNode;
    }
    
    this.RightToLeft = false;
}

RadComboBox.prototype.PositionDropDown = function()
{
	this.DetachDropDown();
	
	var startElement = this.DomElement.firstChild;
	
	var position = this.GetElementPosition(startElement);
	
	if (this.ExpandEffectString != null && document.all)
	{		
		try
		{
		    this.DropDownPlaceholder.style.filter = this.ExpandEffectString;		
		    this.DropDownPlaceholder.filters[0].Apply();
		    this.DropDownPlaceholder.filters[0].Play();
		}
		catch(e)
		{
		}
	}
	
	this.DropDownPlaceholder.style.position = "absolute";
	this.DropDownPlaceholder.style.top = position.y + this.OffsetY + this.InputDomElement.offsetHeight + "px";
	this.DropDownPlaceholder.style.left = position.x + this.OffsetX + "px";
	this.DropDownPlaceholder.style.display = "block";
	var dropDownWidth = this.DomElement.offsetWidth;
	
	this.DropDownPlaceholder.style.width = dropDownWidth + "px";
	
	var difference = this.DropDownPlaceholder.offsetWidth - dropDownWidth;
	
	if (difference > 0 && difference < dropDownWidth)
	{
		this.DropDownPlaceholder.style.width = dropDownWidth - difference + "px";
	}
	
	if (this.RightToLeft)
	{
	    this.DropDownPlaceholder.dir = "rtl";
	}
	
	var screenSize = this.GetViewPortSize();
	
	if (this.ElementOverflowsBottom(screenSize, this.DropDownPlaceholder, this.InputDomElement))
	{
		var y = position.y - this.DropDownPlaceholder.offsetHeight;
		if (y >= 0)
		{
			this.DropDownPlaceholder.style.top = y + "px";
		}
		
	}
	this.ShowOverlay(this.DropDownPlaceholder.style.left, this.DropDownPlaceholder.style.top);
	
	this.DropDownVisible = true;
}
RadComboBox.prototype.ShowDropDown = function(skipLoadingItems)
{
    if (this.FireEvent(this.OnClientDropDownOpening, this) === false)
    {
		return;
    }
	
	this.PositionDropDown();
	this.InputDomElement.focus();
	
	if (this.EnableLoadOnDemand && this.Items.length == 0 && !skipLoadingItems)
	{
		this.RequestItems(this.GetText(), false);
	}
}

RadComboBox.prototype.ClearItems = function() 
{
    this.Items = [];
    this.ItemMap = new Object();
    this.DropDownDomElement.innerHTML = "";
};

RadComboBox.prototype.RequestItems = function (text, appendItems)
{
	if (this.Disposed) return;
	
	if (this.FireEvent(this.OnClientItemsRequesting, this,text, appendItems) == false) 
    {
	    return;		
    }
    
	if (!this.LoadingDiv)
	{
		this.LoadingDiv = document.createElement("div");
		this.LoadingDiv.className = this.LoadingMessageCssClass;
		this.LoadingDiv.id = this.ClientID + "_LoadingDiv";
		this.LoadingDiv.innerHTML = this.LoadingMessage;
		this.DropDownDomElement.insertBefore(this.LoadingDiv, this.DropDownDomElement.firstChild);
	}
	
	var ajaxUrl = this.GetAjaxUrl(text, this.GetText(), this.GetValue(), appendItems);
	var xmlHttp = this.CreateXmlHttpRequest();
	

	var me = this;
	
	xmlHttp.onreadystatechange = function ()
	{
		if (xmlHttp.readyState != 4) return;	
		
		if (!me.Disposed)
		{
			me.OnCallBackResponse(xmlHttp, appendItems, text, ajaxUrl);
		}
	}
	
	xmlHttp.open("GET", ajaxUrl, true);
	xmlHttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
	xmlHttp.send("");

}

RadComboBox.prototype.OnCallBackResponse = function (xmlHttp, appendItems, text, ajaxUrl)
{
	if (this.LoadingDiv)
	{	
		if (this.LoadingDiv.parentNode)
			this.LoadingDiv.parentNode.removeChild(this.LoadingDiv);
			
		this.LoadingDiv = null;
	}
		
	if (xmlHttp.status == 500)
	{
		if (this.FireEvent(this.AfterClientCallBackError, this)=== false)
	    {
	      return;
		}
	    alert("RadComboBox: Server error in the ItemsRequested event handler, press ok to view the result.");
	    var errorMessage;
	    this.Dispose();
	    if (this.ErrorMessage)
	    {
	      errorMessage = this.ErrorMessage;
	    }
	    else
	    {
	     errorMessage  = xmlHttp.responseText;
	    }
	    document.body.innerHTML = errorMessage;
		return;
	}	
	if (xmlHttp.status == 404)
	{
		if (this.FireEvent(this.AfterClientCallBackError, this)=== false)
	    {
	      return;
		}
		
        alert("RadComboBox: Load On Demand Page not found: " + ajaxUrl);
        this.Dispose();
	    var errorMessage;
	    if (this.ErrorMessage)
	    {
	      errorMessage = this.ErrorMessage;
	    }
	    else
	    {
	     errorMessage = "RadComboBox: Load On Demand Page not found: " + ajaxUrl + "<br/>";
	     errorMessage += "Please, try using ExternalCallBackPage to map to the exact location of the callbackpage you are using."
	    }
	    document.body.innerHTML = errorMessage;
		
		return;
	}
	
	try
	{
	    eval("var callBackData = " + xmlHttp.responseText + ";");	
	}
	catch(e)
	{
	    if (this.FireEvent(this.AfterClientCallBackError, this)=== false)
	    {
	      return;
		}
		
	    alert("RadComboBox: load on demand callback error. Press Enter for more information");
	    this.Dispose();
	    var errorMessage;
	    if (this.ErrorMessage)
	    {
	      errorMessage = this.ErrorMessage;
	    }
	    else
	    {
	        errorMessage = "If RadComboBox is not initially visible on your ASPX page, you may need to use streamers (the ExternallCallBackPage property)";
	        errorMessage += "<br/>Please, read our online documentation on this problem for details";
	        errorMessage += "<br/><a href='http://www.telerik.com/help/radcombobox/v2%5FNET2/?combo_externalcallbackpage.html'>http://www.telerik.com/help/radcombobox/v2%5FNET2/combo_externalcallbackpage.html</a>"
	    }
	    document.body.innerHTML = errorMessage;
		
		return;
	};
	
	if (this.GetText() != callBackData.Text)
	{  
	    this.RequestItems(this.GetText(), appendItems);
	    return;
	}
	
	if (!appendItems)
	{
		this.ClearItems();
	}
	
	this.SelectedItem = null;
	this.HighlightedItem = null;
	var oldLength = this.Items.length;	
	
	if (appendItems)
	{
		for (var i = 0; i < this.Items.length; i++)
		{
			this.Items[i].DomElement = null;
		}
	
	}
	
	this.CreateItems(callBackData.Items);
		
	
	if (appendItems)
	{
		
		this.DropDownDomElement.innerHTML += callBackData.DropDownHtml;
		if (this.Items[oldLength+1] != null)
		{				
			this.Items[oldLength+1].ScrollIntoView();
		}	
	}
	else
	{
		this.DropDownDomElement.innerHTML = callBackData.DropDownHtml;
	}
	
	if (this.ShowMoreResultsBox) 
	{		
		this.MoreResultsBoxMessageDomElement.innerHTML = callBackData.Message;
	}
	
	this.FireEvent(this.OnClientItemsRequested, this, callBackData.Text, appendItems);
	
	if (this.ShouldHighlight())
		this.HighlightMatches();
}

RadComboBox.prototype.CreateXmlHttpRequest = function()
{    
	if (typeof(XMLHttpRequest) != "undefined")
	{
		return new XMLHttpRequest();		
	}
	if (typeof(ActiveXObject) != "undefined")
	{
		return new ActiveXObject("Microsoft.XMLHTTP");		
	}
};

RadComboBox.prototype.ClearSelection = function()
{
	this.SetText("");
	this.SetValue("");
	this.SelectedItem = null;
	this.HighLightedItem = null;
};

RadComboBox.prototype.GetAjaxUrl = function(requestText, comboText, comboValue, appendItems)
{	
	requestText = requestText.replace(/'/g,"&squote");
	        
    var url = window.unescape(this.LoadOnDemandUrl) + "&text=" + this.EncodeURI(requestText);		

	url = url + "&comboText=" + this.EncodeURI(comboText);	
	url = url + "&comboValue=" + this.EncodeURI(comboValue);
	url = url + "&skin=" + this.EncodeURI(this.Skin);		
	
	if (appendItems)
	{
	    url = url + "&itemCount=" + this.Items.length;
	}
	if (this.ExternalCallBackPage != null)
	{
		url = url + "&external=true";
	}
	if (this.ClientDataString != null)
	{
		url += "&clientDataString=" + this.EncodeURI(this.ClientDataString);
	}
	url = url + "&timeStamp=" + encodeURIComponent((new Date()).getTime());   
	
	return url;
};

RadComboBox.prototype.EncodeURI = function(s)
{	
	if(typeof(encodeURIComponent)!="undefined")
	{
		return encodeURIComponent(this.EscapeQuotes(s));
	}
	if (escape)
	{
		return escape(this.EscapeQuotes(s));
	}	
};

RadComboBox.prototype.EscapeQuotes = function(text)
{	
	if (typeof(text) != "number")
	{
		return text.replace(/'/g,"&squote");
	}
};

RadComboBox.prototype.ToggleDropDown = function ()
{
	if (this.DropDownVisible)
	{
		this.HideDropDown();
	}
	else
	{
		this.ShowDropDown();
		if (this.HighlightedItem)
		{
			this.HighlightedItem.ScrollIntoView();
		}
	}
}

RadComboBox.prototype.HideDropDown = function ()
{  
   if (this.FireEvent(this.OnClientDropDownClosing, this) === false)
   {
	    return;
   }
   this.DropDownPlaceholder.style.display = "none";
   this.HideOverlay();
   this.DropDownVisible = false;
}

RadComboBox.prototype.SetText = function (text)
{  
    this.SuppressChange = true;
    this.InputDomElement.value = text;
    this.TextHidden.value = text;
    this.ValueHidden.value = "";
    
    if (this.InputDomElement.fireEvent) 
    {
        var eventObject = document.createEventObject();
        this.InputDomElement.fireEvent("onchange", eventObject);
    } 
    else if (this.InputDomElement.dispatchEvent)
    {
        var canBubble = true;
        var eventObject = document.createEvent("HTMLEvents");
        eventObject.initEvent("change", canBubble, true);
        this.InputDomElement.dispatchEvent(eventObject);
    }
    
    this.SuppressChange = false;
}

RadComboBox.prototype.SetValue = function (value)
{
    this.ValueHidden.value = value;
}

RadComboBox.prototype.GetValue = function ()
{
    return this.ValueHidden.value;
}

RadComboBox.prototype.PerformSelect = function (item)
{   
    
    if(item && (item != this.SelectedItem || this.MultiComboSelection == true) && !this.EnableLoadOnDemand)
    { 
        item.Select();
        return;
    }
    
    if (item && item == this.SelectedItem && this.GetText() != item.Text && this.AllowCustomText)
    {
		this.SetText(item.Text);
		return;
    }
    
    if (item && item == this.SelectedItem)
    {
		return;
    }
    
    if (item && this.OriginalText != item.Text)
	{
		item.Select();
		return;
	}
    
    //Required to support multiple items with the same text load on demand
    if (item && (!this.SelectedItem || this.SelectedItem.Value != item.Value))
	{
		item.Select();
		return;
	}
	
    if (this.OriginalText != this.GetText() )
    {
		if (this.HighlightedItem)
		{
			this.HighlightedItem.UnHighlight();
		}
		this.PostBack();	
    }
}

RadComboBox.prototype.OnKeyDown = function (e)
{  
    if (!e) e = event;
    
    this.Changed =true;
    
    this.FireEvent(this.OnClientKeyPressing, this, e);	
    
    var keyCode = e.keyCode || e.which;
    
    this.LastKeyCode = keyCode;
    
    if (keyCode == RadComboBox.Keys.Escape && this.DropDownVisible)
	{
		this.HideDropDown();
		return;
	}
    if (keyCode === RadComboBox.Keys.Enter)
    {
		this.HideDropDown();
       
        this.PerformSelect(this.HighlightedItem);
        
        e.returnValue = false;
        if (e.preventDefault)
        {
			e.preventDefault();
        }
        
        return;
    }
    else if (keyCode === RadComboBox.Keys.Down)
    {
        e.returnValue = false;
        
        if (e.altKey)
        {
			this.ToggleDropDown();
			return;
        }
        
        this.HighlightNextItem();
        return;
    }
    else if (keyCode === RadComboBox.Keys.Up)
    {
        e.returnValue = false;
        
        if (e.altKey)
        {
			this.ToggleDropDown();
			return;
        }
        
        this.HighlightPreviousItem();
        return;
    }
    else if (keyCode === RadComboBox.Keys.Tab)
    { 
        this.HideDropDown();
        this.RaiseClientBlur();
		this.SelectItemOnBlur();
        this.Focused = false;
        
        return;
    }
    
    if (keyCode == RadComboBox.Keys.Left || keyCode == RadComboBox.Keys.Right)
    {
		return;
    }
}

RadComboBox.prototype.GetLastWord = function(text)
{
	var lastSeparatorIndex = -1;
	if (this.AutoCompleteSeparator != null)
	{
		lastSeparatorIndex = this.GetLastSeparatorIndex(text);
	}		
	var lastWord = text.substring(lastSeparatorIndex+1, text.length);	
	return lastWord;
}

RadComboBox.prototype.GetLastSeparatorIndex = function(text)
{	
	var lastIndex = -1;	
	
	if (!this.AutoCompleteSeparator) return lastIndex;
	
	for (var i=0; i<this.AutoCompleteSeparator.length;i++)
	{
		var currentSeparator = this.AutoCompleteSeparator.charAt(i);		
		var currentIndex = text.lastIndexOf(currentSeparator);
		if (currentIndex > lastIndex)
		{			
			lastIndex = currentIndex;
		}
	}	
	return lastIndex;
}

RadComboBox.prototype.GetLastSeparator = function(text)
{		
    if (!this.AutoCompleteSeparator) return null
    
    var lastIndex = this.GetLastSeparatorIndex(text);
	return text.charAt(lastIndex);
}

RadComboBox.prototype.ShouldHighlight = function()
{
	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;
}
RadComboBox.prototype.HighlightMatches = function()
{
	if (!this.MarkFirstMatch) return;
	
	var text = this.GetText();
	var lastWord = this.GetLastWord(text);
	
	if (this.GetLastSeparator(text)== text.charAt(text.length - 1))
	{
	    return;
	}
	
	var matchingItem = this.FindFirstMatch(lastWord);
	
	if (this.HighlightedItem)
	{
		this.HighlightedItem.UnHighlight();
	}

	if (!matchingItem)
	{
		if (!this.AllowCustomText)
		{
			if (text)
			{
				var lastSeparatorIndex = this.GetLastSeparatorIndex(text);
				if (lastSeparatorIndex < text.length - 1)
				{
					this.SetText(text.substring(0, text.length - 1));
					
					this.HighlightMatches();
				}
			}
		}
		
		return;
	}
	matchingItem.Highlight();
	matchingItem.ScrollOnTop();
	
	var lastSeparatorIndex = this.GetLastSeparatorIndex(text);
	var newText = text.substring(0, lastSeparatorIndex + 1) + matchingItem.Text;
	
	if (text != newText)
	{
		this.SetText(newText);
	}
	
	this.SetValue(matchingItem.Value);
	
	var startIndex = lastSeparatorIndex + lastWord.length + 1;
	var endIndex = newText.length - startIndex;
				
	this.SelectText(startIndex, endIndex);
}

RadComboBox.prototype.FindFirstMatch = function (text)
{
	if (!text) return null;
	
	for (var i = 0; i < this.Items.length; i++)
	{
		if (this.Items[i].Text.length < text.length)
		{
			continue;
		}
		
		if(this.Items[i].Enabled == false)
		{
			continue;
		}
			    
		var match = this.Items[i].Text.substring(0, text.length);
		
		if (!this.IsCaseSensitive)
		{
			if (match.toLowerCase() == text.toLowerCase())
			{
				return this.Items[i];
			}
		}
		else
		{
			if (match == text)
			{
				return this.Items[i];
			}
		}
	}
		
	return	null;
}

RadComboBox.prototype.OnFocus = function (e)
{
	if (this.Focused)
		return;
		
    if (!e) e = event;
    
    this.Focused = true;
    this.FireEvent(this.OnClientFocus, this);    
};

RadComboBox.prototype.RaiseClientBlur = function ()
{
    if (this.Focused)
    {
		this.FireEvent(this.OnClientBlur, this);
	}
}

RadComboBox.prototype.FindNextAvailableIndex = function(index)
{
	for (var i = index; i < this.Items.length; i++)
	{
		if (this.Items[i].Enabled)
		{
			return i;
		}
	}
	
	return this.Items.length;
};

RadComboBox.prototype.FindPrevAvailableIndex = function(index)
{
	for (var i = index; i >= 0; i--)
	{
		if (this.Items[i].Enabled)
		{
			return i;
		}
	}
	
	return -1;
};


RadComboBox.prototype.HighlightNextItem = function ()
{
    var currentItem = this.HighlightedItem; 
    var proposedIndex = 0;
    
    if (currentItem)
    {
		proposedIndex = currentItem.Index + 1;
    }
    
    proposedIndex = this.FindNextAvailableIndex(proposedIndex);
    
    if (proposedIndex < this.Items.length)
    {
        this.Items[proposedIndex].Highlight();
        this.Items[proposedIndex].ScrollIntoView();
		this.Items[proposedIndex].Text;
		var lastSeparatorIndex = this.GetLastSeparatorIndex(this.GetText());
		 //Append the item text after the last separator
	    var textToSet = this.GetText().substring(0, lastSeparatorIndex + 1) + this.Items[proposedIndex].Text;
	   
        this.SetText(textToSet);
        this.SetValue(this.Items[proposedIndex].Value);
    }
}

RadComboBox.prototype.HighlightPreviousItem = function ()
{
    var currentItem = this.HighlightedItem;
    
    var proposedIndex = 0;
    
    if (currentItem)
    {
		proposedIndex = currentItem.Index - 1;
		
    }
    
    proposedIndex = this.FindPrevAvailableIndex(proposedIndex);
    
    if (proposedIndex >= 0)
    {
        this.Items[proposedIndex].Highlight();
        this.Items[proposedIndex].ScrollIntoView();
        this.Items[proposedIndex].Text;
    	var lastSeparatorIndex = this.GetLastSeparatorIndex(this.GetText());
        //Append the item text after the last separator
	    var textToSet = this.GetText().substring(0, lastSeparatorIndex + 1) + this.Items[proposedIndex].Text;
	     
	    this.SetText(textToSet);
        this.SetValue(this.Items[proposedIndex].Value);
    }
}


RadComboBox.prototype.ElementOverflowsBottom = function (screenSize, element, startingElement)
{
	var bottomEdge = this.GetElementPosition(startingElement).y + element.offsetHeight;		
	return bottomEdge > screenSize.height;
};

RadComboBox.prototype.FindItemByText = function(theText)
{
	for (var i=0; i<this.Items.length; i++)
	{
		if (this.Items[i].Text == theText)
		{
			return this.Items[i];
		}
	}
	
	return null;
};

RadComboBox.prototype.FindItemByValue = function(theValue)
{
	if (!theValue) return null;
	
	for (var i=0; i<this.Items.length; i++)
	{
		if (this.Items[i].Value == theValue)
		{
			return this.Items[i];
		}
	}
	
	return null;
};

RadComboBox.prototype.CancelPropagation = function(eventArgs)
{	
	if (eventArgs.stopPropagation)
	{
		eventArgs.stopPropagation();
	}
	else
	{
		eventArgs.cancelBubble = true;
	}	
};

RadComboBox.prototype.PreventDefault = function(eventArgs)
{
	if (eventArgs.preventDefault)
	{
		eventArgs.preventDefault();
	}
	else
	{
		eventArgs.returnValue = false;
	}
};

RadComboBox.prototype.GetText = function()
{
	return this.InputDomElement.value;
}

RadComboBox.prototype.Enable = function()
{	
	this.EnableDomEventHandling();
	this.InputDomElement.disabled = false;			
	this.Enabled = true;
}

RadComboBox.prototype.Disable = function()
{	
	this.Enabled = false;
	this.TextHidden.value = this.GetText();
	this.InputDomElement.disabled = "disabled";
	this.DisableDomEventHandling();
}

RadComboBox.prototype.FixUp = function(elem, shouldRunAgain)
{
	//if (document.compatMode && document.compatMode == "CSS1Compat")
	{
		if ((this.ClientWidthHidden.value != "") && (this.ClientHeightHidden.value != ""))
		{
			if (elem.style.width != this.ClientWidthHidden.value)
				elem.style.width = this.ClientWidthHidden.value;
			
			if (elem.style.height != this.ClientHeightHidden.value)	
				elem.style.height = this.ClientHeightHidden.value;

			this.ShowWrapperElement();
			return;
		}
		var image = elem.parentNode.getElementsByTagName("img")[0];
		if (shouldRunAgain && image && (image.offsetWidth == 0))
		{
			var comboInstance = this;
			if (document.attachEvent)
			{
				if (document.readyState == "complete")
					window.setTimeout(function() { comboInstance.FixUp(elem, false); }, 100);
				else
					window.attachEvent("onload", function () { comboInstance.FixUp(elem, false); });
			}
			else
			{
				window.addEventListener("load", function () { comboInstance.FixUp(elem, false); }, false);
			}
			return;
		}

		var computedStyle = null;
		if (elem.currentStyle)
		{
			computedStyle = elem.currentStyle;
		}
		else if (document.defaultView && document.defaultView.getComputedStyle)
		{
			computedStyle = document.defaultView.getComputedStyle(elem, null);
		}
		
		if (computedStyle == null)
		{
			this.ShowWrapperElement();
			return;
		}

		var height = parseInt(computedStyle.height);
		var width = parseInt(elem.offsetWidth);
		
		var paddingTop = parseInt(computedStyle.paddingTop);
		var paddingBottom = parseInt(computedStyle.paddingBottom);
        

		var paddingLeft = parseInt(computedStyle.paddingLeft);

		var paddingRight = parseInt(computedStyle.paddingRight);
		
		var borderTop = parseInt(computedStyle.borderTopWidth);
		if (isNaN(borderTop))
		{
			borderTop = 0;
		}
		var borderBottom = parseInt(computedStyle.borderBottomWidth);
		if (isNaN(borderBottom))
		{
			borderBottom = 0;
		}
		var borderLeft = parseInt(computedStyle.borderLeftWidth);
		if (isNaN(borderLeft))
		{
			borderLeft = 0;
		}
		
		var borderRight = parseInt(computedStyle.borderRightWidth);
		if (isNaN(borderRight))
		{
			borderRight = 0;
		}
		if (document.compatMode && document.compatMode == "CSS1Compat")
		{
		    if (!isNaN(height) && (this.ClientHeightHidden.value == ""))
		    {
			    elem.style.height = height - paddingTop - paddingBottom - borderTop - borderBottom + "px";
			    this.ClientHeightHidden.value = elem.style.height;
		    }
		}

		if (!isNaN(width) && width && (this.ClientWidthHidden.value == ""))
		{
			var imageWidth = 0;
			if (image)
			{
			    imageWidth = image.offsetWidth;
			}
			
			if (document.compatMode && document.compatMode == "CSS1Compat")
			{
				// Fix. Gemini ID: RCOM-7501
				var newElemWidth = width - imageWidth - paddingLeft - paddingRight - borderLeft - borderRight;
//				var tempWidth = "0px";

//				if (newElemWidth >= 0)
//					elem.style.width = newElemWidth + "px";

//			    if (parseInt(elem.style.width) != elem.offsetWidth)
//			    {
//			    	newElemWidth = parseInt(elem.style.width) + parseInt(elem.style.width) - parseInt(elem.offsetWidth);
//					if (newElemWidth >= 0)
//						elem.style.width = newElemWidth + "px";
//			    }

				if (newElemWidth >= 0)
					elem.style.width = newElemWidth + "px";
					
			    this.ClientWidthHidden.value = elem.style.width;
			}
			else
			{
			    elem.style.width = width - imageWidth;
			}
		}
		this.ShowWrapperElement();
	}
};

RadComboBox.prototype.ShowWrapperElement = function()
{
	if (!this.ShowWhileLoading)
		document.getElementById(this.ClientID + "_wrapper").style.visibility = "visible";	
};


//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
	if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
	{
		Sys.Application.notifyScriptLoaded();
	}
}
//END_ATLAS_NOTIFY
