if (typeof window.RadControlsNamespace == "undefined")
{
	window.RadControlsNamespace = {};
}

if (
	typeof(window.RadControlsNamespace.DomEventMixin) == "undefined" ||
	typeof(window.RadControlsNamespace.DomEventMixin.Version) == null ||
	window.RadControlsNamespace.DomEventMixin.Version < 2
	)
{	
	
	RadControlsNamespace.DomEventMixin = 
	{
		Version : 2, // Change the version when make changes. Change the value in the IF also
		
		Initialize : function(obj)
		{
			obj.CreateEventHandler = this.CreateEventHandler;
			obj.AttachDomEvent = this.AttachDomEvent;
			obj.DetachDomEvent = this.DetachDomEvent;
			obj.DisposeDomEventHandlers = this.DisposeDomEventHandlers;
			obj._domEventHandlingEnabled = true;
			obj.EnableDomEventHandling = this.EnableDomEventHandling;
			obj.DisableDomEventHandling = this.DisableDomEventHandling;
			
			obj.RemoveHandlerRegister = this.RemoveHandlerRegister;
			obj.GetHandlerRegister	  = this.GetHandlerRegister;
			obj.AddHandlerRegister    = this.AddHandlerRegister;
			obj.handlerRegisters = [];
		},
		
		EnableDomEventHandling : function ()
		{
			this._domEventHandlingEnabled = true;
		},
		
		DisableDomEventHandling : function ()
		{
			this._domEventHandlingEnabled = false;
		},
	
		CreateEventHandler : function (methodName, fireIfDisabled)
		{
			var instance = this;
			return function (e)
			{
				if (!instance._domEventHandlingEnabled && !fireIfDisabled)
				{
					return false;
				}
				
				return instance[methodName](e || window.event);
			}
		},
		
		AttachDomEvent : function(element, eventName, eventHandlerName, fireIfDisabled)
		{
			var eventHandler = this.CreateEventHandler(eventHandlerName, fireIfDisabled);

			// if such entry exist already - detach it first
			var oldRegister = this.GetHandlerRegister(element, eventName, eventHandlerName);
			if (oldRegister != null)
			{
				this.DetachDomEvent(oldRegister.Element, oldRegister.EventName, eventHandlerName);
			}
			
			// register the new entry
			var eventRegister = { 
				"Element" : element, 
				"EventName" : eventName, 
				"HandlerName" : eventHandlerName, 
				"Handler" : eventHandler 
			};
			this.AddHandlerRegister(eventRegister);
			
			// now do the "real" job
			if (element.addEventListener)
			{
				element.addEventListener(eventName, eventHandler, false);
			}
			else if (element.attachEvent)
			{
				element.attachEvent("on" + eventName, eventHandler);
			}
		},
		
		
		DetachDomEvent : function(element, eventName, eventHandler)
		{
			var eventRegister = null;
			var eventHandlerName = "";

			if (typeof eventHandler == "string") 
			{
				eventHandlerName = eventHandler;
				eventRegister    = this.GetHandlerRegister(element, eventName, eventHandlerName);
				if(eventRegister == null)
					return;
				eventHandler     = eventRegister.Handler;
			}
			
			if (!element)
			{
			    return;
			}
			
			if (element.removeEventListener)
			{
				element.removeEventListener(eventName, eventHandler, false);
			}
			else if (element.detachEvent)
			{
				element.detachEvent("on" + eventName, eventHandler);
			}
			
			if (eventRegister != null && eventHandlerName != "")
			{
				this.RemoveHandlerRegister(eventRegister);
				eventRegister = null;
			}
		},
		
		DisposeDomEventHandlers : function()
		{
			for (var i=0; i < this.handlerRegisters.length; i ++)
			{
				var eventRegister = this.handlerRegisters[i];
				if (eventRegister != null)
				{
					this.DetachDomEvent(
						eventRegister.Element, 
						eventRegister.EventName, 
						eventRegister.Handler);
				}
			}
			
			this.handlerRegisters = [];
		},

		RemoveHandlerRegister : function(eventRegister)
		{
			try {
				var regIndex = eventRegister.index;
				for (var i in eventRegister)
				{
					eventRegister[i] = null;
				}
				this.handlerRegisters[regIndex] = null;
			} catch (e) {}
		},

		GetHandlerRegister : function(element, eventName, handlerName)
		{
			for (var i=0; i < this.handlerRegisters.length; i ++)
			{
				var eventRegister = this.handlerRegisters[i];
				if (eventRegister != null &&
					eventRegister.Element	  == element && 
					eventRegister.EventName	  == eventName &&
					eventRegister.HandlerName == handlerName 
				)
				{
					return this.handlerRegisters[i];
				}
			}
			
			return null;
		},
		
		AddHandlerRegister : function(props)
		{
			props.index = this.handlerRegisters.length;
			this.handlerRegisters[this.handlerRegisters.length] = props;
		}
	}
	
	RadControlsNamespace.DomEvent = {};
	
	RadControlsNamespace.DomEvent.PreventDefault = function (e)
	{
		if (!e) return true;
		
		if (e.preventDefault)
		{
			e.preventDefault();
		}
	
		e.returnValue = false;
		return false;
	}
	
	RadControlsNamespace.DomEvent.StopPropagation = function (e)
	{
		if (!e) return;
		
		if (e.stopPropagation)
		{
			e.stopPropagation();
		}
		else
		{
			e.cancelBubble = true;
		}
	}
	
	RadControlsNamespace.DomEvent.GetTarget = function (e)
	{
		if (!e) return null;
		
		return e.target || e.srcElement;
	}
	
	
	RadControlsNamespace.DomEvent.GetRelatedTarget = function (e)
	{
		if (!e) return null;
		
		return e.relatedTarget || (e.type == "mouseout" ? e.toElement : e.fromElement);
	}
	
	RadControlsNamespace.DomEvent.GetKeyCode = function (e)
	{
		if (!e) return 0;
		
		return e.which || e.keyCode;
	}
};if (typeof window.RadControlsNamespace == "undefined")
{
	window.RadControlsNamespace = {};
}

if (
	typeof(window.RadControlsNamespace.EventMixin) == "undefined" ||
	typeof(window.RadControlsNamespace.EventMixin.Version) == null ||
	window.RadControlsNamespace.EventMixin.Version < 2
	)
{	
	
	RadControlsNamespace.EventMixin = 
	{
		Version : 2, // Change the version when make changes. Change the value in the IF also

		Initialize : function (obj)
		{
	
			obj._listeners = {};
			obj._eventsEnabled = true;
			obj.AttachEvent = this.AttachEvent;
		    
			obj.DetachEvent = this.DetachEvent;
			obj.RaiseEvent = this.RaiseEvent;
		    
			obj.EnableEvents = this.EnableEvents;
			obj.DisableEvents = this.DisableEvents;
			
			obj.DisposeEventHandlers = this.DisposeEventHandlers;
	
		},
	
		DisableEvents : function ()
		{
			this._eventsEnabled = false;
		},
	
		EnableEvents : function ()
		{
			this._eventsEnabled = true;
		},
	
		AttachEvent : function (eventName, handler)
		{
			if (!this._listeners[eventName]) 
			{
				this._listeners[eventName] = [];
			}
	
			this._listeners[eventName][this._listeners[eventName].length] = (RadControlsNamespace.EventMixin.ResolveFunction(handler));
		},
	
	
		DetachEvent : function (eventName, handler)
		{
			var listeners = this._listeners[eventName];
			if (!listeners) 
			{
				return false;
			}
		    
			var funcHandler = RadControlsNamespace.EventMixin.ResolveFunction(handler);
		    
			for (var i = 0; i < listeners.length; i ++)
			{
				if (funcHandler == listeners[i])
				{
					listeners.splice(i, 1);
					return true;
				}
			}
	
			return false;
		},
		
		DisposeEventHandlers : function()
		{
            for (var eventName in this._listeners)
            {
                var listeners = null;
                if (this._listeners.hasOwnProperty(eventName))
                {
                    listeners = this._listeners[eventName];
                    for (var i = 0; i < listeners.length; i++)
			        {
				        listeners[i] = null;
			        }
			        
			        listeners = null;
                }
            }
		},
	
		ResolveFunction : function (func)
		{
			if (typeof(func) == "function")
			{
				return func;
			}
			else if (typeof(window[func]) == "function")
			{
				return window[func];
			}
			else
			{
				return new Function("var Sender = arguments[0]; var Arguments = arguments[1];" + func);
			}
		},
	
	
		RaiseEvent : function (eventName, eventArgs)
		{
			if (!this._eventsEnabled)
			{
				return true;
			}
			var outcome = true;
		    
			if (this[eventName])
			{
		        
				var eventResult = RadControlsNamespace.EventMixin.ResolveFunction(this[eventName])(this, eventArgs);
				if (typeof(eventResult) == "undefined")
				{
					eventResult = true;
				}
				outcome = outcome && eventResult;        
			}
		    
			if (!this._listeners[eventName]) return outcome;
		    
			for (var i = 0; i < this._listeners[eventName].length; i ++)
			{
				var handler = this._listeners[eventName][i];
				var eventResult = handler(this, eventArgs);
				if (typeof(eventResult) == "undefined")
				{
					eventResult = true;
				}
				outcome = outcome && eventResult;
			}
		    
			return outcome;
		}
	}
};function RadTextBox(id, config, styles)
{
    this.DisposeOldInstance(id);
    this.Constructor(id);
    this.Initialize(config, styles);
}

RadTextBox.Extend = function (descendant)
{
    for (var i in this.prototype)
    {
        if (descendant[i]) continue;
        descendant[i] = this.prototype[i];
    }
}

//error event reasons
RadInputErrorReason = {
	ParseError: 0,
	OutOfRange: 1
}


RadTextBox.prototype = 
{
    DisposeOldInstance : function(id)
    {
        try
        {
            var oldTextBox = window[id];
            if (oldTextBox != null)
            {
                oldTextBox.Dispose();
	            window[id] = null;
            }
        }
        catch(e)
        {}
    },

    Constructor : function (id)
    {
        this.ID = id;
        
        this.WrapperElementID = id + "_wrapper";
        this.TextBoxElement = document.getElementById(id + "_text");
        this.HiddenElement = document.getElementById(id);
        
        this.SelectionEnd = 0;
        this.SelectionStart = 0;
        
        
        // state flags
        this.Focused = false;
        this.Enabled = true;
        this.Hovered = false;
        this.Invalid = false;
        this.IsEmptyMessage = false;
        
        this.valueListener = new Telerik.TextInputEvents.ValueListener(this);
        
   	    RadControlsNamespace.EventMixin.Initialize(this);
	    RadControlsNamespace.DomEventMixin.Initialize(this);
    },

	Dispose : function ()
    {
		this.DisposeDomEventHandlers();
		this.DisposeEventHandlers();
		
		if (this.valueListener)
			this.valueListener.Dispose();

        if (this.valueChangedAction != null)
	        window.clearTimeout(this.valueChangedAction);
		
        var property;
        for (property in this)
        {
            property = null;
        }
    },

    CallBase : function (methodName, args)
    {
        //Opera and Safari do not support "arguments.callee.caller"//
        return RadTextBox.prototype[methodName].apply(this, args);
    },

    Initialize : function (config, styles)
    {
        this.Styles = styles;
        
        this.LoadCongfiguration(config);
        this.LoadClientEvents(config);
        
        this.AttachEventHandlers();
        
        this.UpdateDisplayValue();
        this.UpdateCssClass();
        
        this.InitializeButtons();
        
        var input = this;
        this.AttachDomEvent(window, "unload", "Dispose");
        
        this.RaiseEvent('OnLoad', null);
    },

    LoadCongfiguration : function (config)
    {
        for (var i in config)
        {
            if (i != "ClientEvents")
            {
                this[i] = config[i];
            }
        }
    },

    LoadClientEvents : function (config)
    {
        var eventHandler = null;
        for (var eventName in config.ClientEvents)
        {
            var eventHandler = eval(config.ClientEvents[eventName])
            if (typeof(eventHandler) == "function")
                this.AttachEvent(eventName, eventHandler);
        }    
    },

    AttachEventHandlers : function ()
    {
        this.AttachToTextBoxEvent("keypress", "TextBoxKeyPressHandler");
        this.AttachToTextBoxEvent("blur", "TextBoxBlurHandler");
        this.AttachToTextBoxEvent("focus", "TextBoxFocusHandler");
        this.AttachToTextBoxEvent("mouseout", "TextBoxMouseOutHandler");   
        this.AttachToTextBoxEvent("mouseover", "TextBoxMouseOverHandler");
        
        if (window.addEventListener)
		{
		    //Gecko, Opera?
		    this.AttachToTextBoxEvent("DOMMouseScroll", "TextBoxMouseWheelHandler");
		}
		else
		{
			//IE
		    this.AttachToTextBoxEvent("mousewheel", "TextBoxMouseWheelHandler");
		}
    },
    
    TextBoxKeyPressHandler : function (e)
    {
        var isIE = /MSIE/.test(navigator.userAgent);
        var keyCode =  isIE ? e.keyCode : e.which;
        
        if ((keyCode == 13) 
			&& (this.TextBoxElement.tagName.toUpperCase() != "TEXTAREA"))
        {
            this.Blur(); 
            return true;
        }
        
        this.UpdateHiddenValueOnKeyPress();
    },
    
    UpdateHiddenValueOnKeyPress: function()
    {
		var oldValue = this.GetTextBoxValue();
		var newValue = this.GetTextBoxValue();
		this.valueListener.AddChangeEventRequest(newValue, oldValue);
		this.UpdateHiddenValue();
    },

    AttachToTextBoxEvent : function (event, handler)
    {
        this.AttachDomEvent(this.TextBoxElement, event, handler);
    },

	TextBoxBlurHandler : function (e)
    {
        this.Focused = false;   
         
        this.SetValue(this.GetTextBoxValue());
    
        this.RaiseEvent('OnBlur', {"DomEvent" : e});
    },

    TextBoxFocusHandler : function (e)
    {
        this.Focused = true;
        this.UpdateDisplayValue();
        this.UpdateCssClass();
        this.UpdateSelectionOnFocus();
        this.RaiseEvent('OnFocus', {"DomEvent" : e});
    },


    TextBoxMouseOutHandler : function (e)
    {
        this.Hovered = false;
        this.UpdateCssClass();
        this.RaiseEvent('OnMouseOut', {"DomEvent" : e});
    },


    TextBoxMouseOverHandler : function (e)
    {
        this.Hovered = true;
        this.UpdateCssClass(); 
        this.RaiseEvent('OnMouseOver', {"DomEvent" : e});
    },
    
    //Handle Wheel
    TextBoxMouseWheelHandler : function(e)
	{
	    var delta;
	    if (this.Focused)
	    {
            this.MouseWheelActionInProgress = true;
            
            if (e.wheelDelta) 
            { 
                /* IE/Opera. */
                delta = e.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.*/
                if (window.opera)
                    delta = -delta;
            } 
            else if (e.detail) 
            {
                    /** Mozilla case. In Mozilla, sign of delta is different than in IE. Also, delta is multiple of 3.*/
                    delta = - e.detail/3;
            }
            
            if (delta > 0)
            {
                this.HandleWheel(false);
            }
            else
            {
                this.HandleWheel(true);
            }
            
            this.MouseWheelActionInProgress = false;
            
            return true;
        }
        return false;
	},
	
	DelayValueChangedEvent: function()
	{
		return this.MouseWheelActionInProgress == true;
	},
	
    HandleWheel : function(isNegativeWheel)
	{
	},



    //*******public methods*******
    Disable : function ()
    {
        this.Enabled = false;
        this.TextBoxElement.disabled = "disabled";
        this.UpdateCssClass();
        this.RaiseEvent('OnDisable', null);
    },

    Enable : function ()
    {
        this.Enabled = true;
        this.TextBoxElement.disabled = "";
        this.UpdateCssClass();
        this.RaiseEvent('OnEnable', null);
    },
    
    Focus : function ()
    {
        this.TextBoxElement.focus();
    },

    Blur : function ()
    {
        this.TextBoxElement.blur();
    },

    SetValue : function (newValue)
    {
        var oldValue = this.GetValue();
        var validValue = this.SetHiddenValue(newValue);
        if (validValue == false)
			return;
			
        if (oldValue != newValue)
        {
            this.valueListener.QueueChangeEventRequest(newValue, oldValue);
        }
			
        this.SetTextBoxValue(this.GetEditValue());
        this.UpdateDisplayValue();
        this.UpdateCssClass();
    },
    
    RaiseValueChangedEvent: function(newValue, oldValue)
    {
		var shouldPostBack = this.RaiseEvent('OnValueChanged', this.ValueChangedEventArgs(newValue, oldValue));
        if (this.AutoPostBack && shouldPostBack)
        {
            this.RaisePostBackEvent();
        }	
    },
    
    Clear : function ()
    {
        this.SetValue("");
    },

    SetTextBoxValue : function (value)
    {
        if (this.TextBoxElement.value != value)
        {
            this.TextBoxElement.value = value;
        }
    },

    GetTextBoxValue : function (value)
    {
        return this.TextBoxElement.value;
    },


    GetWrapperElement : function()
    {
        return document.getElementById(this.WrapperElementID);
    },

    UpdateDisplayValue : function()
    {
        if (this.Focused)
        {
            this.SetTextBoxValue(this.GetEditValue());
        }
        else
        {
            if (this.IsEmpty() && this.EmptyMessage)
            {
                this.IsEmptyMessage = true;
                this.SetTextBoxValue(this.EmptyMessage);
            }
            else
            {
                this.IsEmptyMessage = false;
                this.SetTextBoxValue(this.GetDisplayValue());
            }
        }
    },

    UpdateSelectionOnFocus : function()
    {
        switch (this.SelectionOnFocus)
        {
            case 0: //None
                break;
            case 1: //CaretToBeginning
                this.SetCaretPosition(0);
                break;
            case 2: //CaretToEnd
                if (this.TextBoxElement.value.length > 0)
                {
                    this.SetCaretPosition(this.TextBoxElement.value.length);
                }
                break;
            case 3: //SelectAll
                this.SelectAllText();
                break;            
            default : 
				this.SetCaretPosition(0); //CaretToBeginning
				break;
        }
    },

    RaiseErrorEvent : function(args)
    {
		if (this.InEventRaise)
			return;
			
		this.InEventRaise = true;
		
		var cancelErrorStyle = this.RaiseEvent('OnError', args);
		if (cancelErrorStyle != false)
		{
			this.Invalid = true;
			this.UpdateCssClass();
	    	
			var instance = this;
			var restore = function()
			{
				instance.Invalid = false
				instance.UpdateCssClass();
			}
			setTimeout(restore, 100);	        
        }
        
        this.InEventRaise = false;
    },

    RaisePostBackEvent : function()
    {
        eval(this.PostBackEventReferenceScript);
    },

    UpdateCssClass  : function ()
    {        
        if (this.Enabled && (!this.IsEmptyMessage) && (!this.IsNegative()))
        {
             this.TextBoxElement.style.cssText = this.Styles["EnabledStyle"][0];
             this.TextBoxElement.className = this.Styles["EnabledStyle"][1];
        }     
        
        if (this.Enabled && (!this.IsEmptyMessage) && this.IsNegative())
        {
             this.TextBoxElement.style.cssText = this.Styles["NegativeStyle"][0];
             this.TextBoxElement.className = this.Styles["NegativeStyle"][1];
        }  
        
        if (this.Enabled && this.IsEmptyMessage)
        {
             this.TextBoxElement.style.cssText = this.Styles["EmptyMessageStyle"][0];
             this.TextBoxElement.className = this.Styles["EmptyMessageStyle"][1];
        }   
        
        if (this.Hovered)
        {
            this.TextBoxElement.style.cssText = this.Styles["HoveredStyle"][0];
            this.TextBoxElement.className = this.Styles["HoveredStyle"][1];
        }
        
        if (this.Focused)
        {
            this.TextBoxElement.style.cssText = this.Styles["FocusedStyle"][0];
            this.TextBoxElement.className = this.Styles["FocusedStyle"][1];   
        }
        
        if (this.Invalid)
        {
            this.TextBoxElement.style.cssText = this.Styles["InvalidStyle"][0];
            this.TextBoxElement.className = this.Styles["InvalidStyle"][1];
        }   
        
        if (!this.Enabled)
        {
            this.TextBoxElement.style.cssText = this.Styles["DisabledStyle"][0];
            this.TextBoxElement.className = this.Styles["DisabledStyle"][1];        
        }
    },

    /* IE needs these */

    CalculateSelection : function ()
    {
        if (window.opera || !document.selection)
        {
            this.SelectionEnd = this.TextBoxElement.selectionEnd;
            this.SelectionStart = this.TextBoxElement.selectionStart;
            return;
        }
        
        var s1 = document.selection.createRange();
        if (s1.parentElement() != this.TextBoxElement) return;
        var s = s1.duplicate();

        s.move('character', -this.TextBoxElement.value.length);
        
        s.setEndPoint('EndToStart', s1);
        
        var sel1 = s.text.length;
        var sel2 = s.text.length +  s1.text.length;
        this.SelectionEnd = Math.max(sel1, sel2);
        this.SelectionStart = Math.min(sel1, sel2);
    },

    ApplySelection : function ()
    {
            if (window.opera || !document.selection)
            {
                this.TextBoxElement.selectionStart = this.SelectionStart;
                this.TextBoxElement.selectionEnd = this.SelectionEnd;
                return;
            }

            this.TextBoxElement.select();
            sel = document.selection.createRange();
            sel.collapse();
            sel.moveStart('character', this.SelectionStart);
            sel.collapse();
            sel.moveEnd('character', this.SelectionEnd - this.SelectionStart);
            sel.select();        
    },

    SelectText : function (start, end)
    {
        this.SelectionStart = start;
        this.SelectionEnd = end;
        this.ApplySelection();
    },

    SelectAllText : function ()
    {
        if (this.TextBoxElement.value.length > 0)
        {
             this.SelectText(0, this.TextBoxElement.value.length);
             return true;
        }
        return false;
    },

    SetCaretPosition : function (position)
    {   
        this.SelectionStart = position;
        this.SelectionEnd = position;
        this.ApplySelection();
    },

    UpdateHiddenValue : function()
    {
        return this.SetHiddenValue(this.TextBoxElement.value);
    },

    // InitializeButtons
    InitializeButtons : function()
    {
        this.Button = null;
		var domElement = document.getElementById(this.WrapperElementID);
        var spans = domElement.getElementsByTagName("span");
        
        for (i = 0; i < spans.length; i++)
        {
			if (spans[i].className.indexOf("radInpButtonCss") != (-1))
            {
                this.Button = spans[i];
                this.AttachDomEvent(this.Button, "click", "ButtonClickHandler");
            }            
        }   
    },

    ButtonClickHandler : function (e)
    {
        var args = { "ButtonName":"Button" };
        this.RaiseEvent('OnButtonClick', args);
    },


    // virtual methods

    SetHiddenValue : function(value)
    {
        if (this.HiddenElement.value != value)
        {
            this.HiddenElement.value = value;
        }
        return true;
    },
    
    ValueChangedEventArgs : function(newValue, oldValue)
    {
		if (oldValue == null)
			oldValue = this.HiddenElement.value;
			
		return { "NewValue": newValue, "OldValue": oldValue };
    },

    GetValue : function ()
    {
        return this.HiddenElement.value;
    },

    GetDisplayValue : function ()
    {
        return this.HiddenElement.value;
    },

    GetEditValue : function ()
    {
        return this.HiddenElement.value;
    },

    IsEmpty : function ()
    {
        return this.HiddenElement.value == "";
    }, 

    IsNegative : function ()
	{
		return false;
	}
};    
    

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;
	    var StyleSheetHolder = document.getElementById(clientID + "StyleSheetHolder");
	    if(StyleSheetHolder != null)
	    {
		    document.getElementById(clientID + "StyleSheetHolder").appendChild(linkObject);
	    }
    }
};



//test
if (typeof(console) == "undefined")
{
   console = {
        log : function (msg)
        {
            if (!this.logElement)
            {
                this.logElement = document.createElement("div");
                this.logElement.style.cssText = "border:2px inset buttonface;font:10px tahoma;padding:20px;height:200px;overflow:scroll;position:absolute;bottom:0;";
                document.body.insertBefore(this.logElement, document.body.firstChild);
            }
            
           
            var msgNode = document.createTextNode((new Date().toString()) + ": " + msg);
            this.logElement.appendChild(msgNode);
            this.logElement.appendChild(document.createElement("hr"));
        }            
    }
};if (typeof (Telerik) == "undefined")
{
	Telerik = {};
}
if (Telerik.TextInputEvents == null)
{
	Telerik.TextInputEvents = {};
}

Telerik.TextInputEvents.ValueListener = function(ownerControl)
{
	this.Owner = ownerControl;
	this.EventRequest = null;
};

Telerik.TextInputEvents.ValueListener.prototype =
{
	AddChangeEventRequest: function(newValue, oldValue)
	{
		if (this.EventRequest == null)
		{
			this.EventRequest = {New: newValue, Old: oldValue};
		}
		else
		{
			this.EventRequest.New = newValue;
		}
	},
	
	QueueChangeEventRequest: function(newValue, oldValue)
	{
		this.CancelPreviousRequest();
		this.AddChangeEventRequest(newValue, oldValue);
            
        var listener = this;    
        var processAction = function()
            {
            	listener.ValueChangedAction = null;	
                listener.ProcessEvents();
            };
        
        if (this.Owner.DelayValueChangedEvent())
        {
            this.ValueChangedAction = window.setTimeout(processAction, 300);
        }
        else
        {
            processAction();
        }
	},
	
	CancelPreviousRequest: function()
	{
		if (this.ValueChangedAction != null)
		{
			window.clearTimeout(this.ValueChangedAction);
			this.ValueChangedAction = null;
		}
	},
	
	Dispose: function()
	{
		this.CancelPreviousRequest();
	},
	
	ProcessEvents: function()
	{	
		if (this.EventRequest != null)
		{
			this.Owner.RaiseValueChangedEvent(this.EventRequest.New, this.EventRequest.Old);
			this.EventRequest = null;
		}
	}
};