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;
	}
}

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
	if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
	{
		Sys.Application.notifyScriptLoaded();
	}
}
//END_ATLAS_NOTIFY

var RadGridNamespace = {};

RadGridNamespace.Prefix = "grid_"

RadGridNamespace.InitializeClient = function(clientID)
{
    var script = document.getElementById(clientID + "AtlasCreation");

    if(!script)
        return;

    var newScript = document.createElement("script");
    if (navigator.userAgent.indexOf("Safari") != -1)
    {
        newScript.innerHTML = script.innerHTML;
    }
    else
    {
        newScript.text = script.innerHTML;
    }

    document.body.appendChild(newScript);
    document.body.removeChild(newScript);


    script.parentNode.removeChild(script);
};

RadGridNamespace.AsyncRequest = function(eventTarget, eventArgument, clientID)
{
	var instance = window[clientID];
	if(instance != null && typeof(instance.AsyncRequest) == "function")
	{
	    instance.AsyncRequest(eventTarget, eventArgument);
	}
};

RadGridNamespace.AsyncRequestWithOptions = function(options, clientID)
{
	var instance = window[clientID];
	if(instance != null && typeof(instance.AsyncRequestWithOptions) == "function")
	{
	    instance.AsyncRequestWithOptions(options);
	}
   //RadAjaxNamespace.AsyncRequestWithOptions(options, clientID, RadGridNamespace.Prefix);
};

RadGridNamespace.GetWidth = function(element)
{
    var width;
    if(window.getComputedStyle)
    {
        width = window.getComputedStyle(element, "").getPropertyValue("width");
    }
    else if (element.currentStyle)
    {
        width = element.currentStyle.width;
    }
    else
    {
	    width = element.offsetWidth;
	}
	
	if(width.toString().indexOf("%") != -1)
	{
	    width = element.offsetWidth;
	}
	
	if(width.toString().indexOf("px") != -1)
	{
	    width = parseInt(width);
	}

	
	return width;
};

RadGridNamespace.GetScrollBarWidth = function()
{
	try
	{
	    if(typeof(RadGridNamespace.scrollbarWidth) == "undefined")
	    {
            var offsetWidth, clientWidth = 0;

            var div1 = document.createElement('div');
            div1.style.position = 'absolute';
            div1.style.top = '-1000px';
            div1.style.left = '-1000px';
            div1.style.width = '100px';
            div1.style.overflow = 'auto';

            var div2 = document.createElement('div');
            div2.style.width = '1000px';

            div1.appendChild(div2);
            document.body.appendChild(div1);

            offsetWidth = div1.offsetWidth;

            clientWidth = div1.clientWidth;

            document.body.removeChild(document.body.lastChild);

            RadGridNamespace.scrollbarWidth = offsetWidth - clientWidth;
            
            if(RadGridNamespace.scrollbarWidth <= 0 || clientWidth == 0)
            {
                RadGridNamespace.scrollbarWidth = 16;
            }
	    }
		return RadGridNamespace.scrollbarWidth;
	}
	catch(error)
	{
		return false;
	}
};

RadGridNamespace.GetTableColGroup = function(table)
{
	try
	{
		return table.getElementsByTagName("colgroup")[0];
	}
	catch(error)
	{
		return false;
	}
};

RadGridNamespace.GetTableColGroupCols = function(colGroup)
{
	try
	{
		var cols = new Array();

		var node = colGroup.childNodes[0];

		for(var i=0;i<colGroup.childNodes.length;i++)
		{
			if ((colGroup.childNodes[i].tagName) &&
				(colGroup.childNodes[i].tagName.toLowerCase() == "col"))
			{
				cols[cols.length] = colGroup.childNodes[i];
			}
		}

		return cols;
	}
	catch(error)
	{
		return false;
	}
};

RadGridNamespace.Confirm = function(message, e)
{
	if(!confirm(message))
	{
		e.cancelBubble = true;
		e.returnValue = false;
		return false;
	}
};

RadGridNamespace.SynchronizeWithWindow = function()
{
};

RadGridNamespace.IsParentRightToLeft = function(node)
{
	try
	{
		while (node)
		{
			node = node.parentNode;
			
			if(node.currentStyle && node.currentStyle.direction.toLowerCase() == "rtl")
			{
			    return true;
			}
			else if(getComputedStyle && getComputedStyle(node, "").getPropertyValue("direction").toLowerCase() == "rtl")
			{
		        return true;
			}
            else if (node.dir.toLowerCase() == "rtl")
			{
				return true;
			}
		}

		return false;

	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError, this.OnError);
	}
};

RadGridNamespace.FireEvent = function (sender, eventHandler, eventArguments)
{	
	try
	{
		var returnValue = true;
		if (typeof(sender[eventHandler]) == "string")
		{
			eval(sender[eventHandler]);
		}
		else if (typeof(sender[eventHandler]) == "function")
		{
			if (eventArguments)
			{
				switch(eventArguments.length)
				{
					case 1:
					{
						returnValue = sender[eventHandler](eventArguments[0]);
						break;
					}
					case 2:
					{
						returnValue = sender[eventHandler](eventArguments[0], eventArguments[1]);
						break;
					}
				}
			}
			else
			{
				returnValue = sender[eventHandler]();
			}
		}
		
		if (typeof(returnValue) != "boolean")
		{
			return true;
		}
		else
		{
			return returnValue;
		}
	}
	catch(error)
	{
	    throw error;
	}
};

RadGridNamespace.CheckParentNodesFor = function (node, nodeToFind)
{
	while (node)
	{
		if (node == nodeToFind)
		{
			return true;
		}
		node = node.parentNode;
	}
	return false;
};

RadGridNamespace.GetCurrentElement = function (e)
{
	if (!e)
		var e = window.event;

	var currentElement;

	if (e.srcElement)
	{
		currentElement = e.srcElement;
	}
	else
	{
		currentElement = e.target;
	}

	return currentElement;
};

RadGridNamespace.GetEventPosX = function(e)
{
	var x = e.clientX;

	var currentElement = RadGridNamespace.GetCurrentElement(e);

	while (currentElement.parentNode)
	{
		if (typeof(currentElement.parentNode.scrollLeft) == "number")
		{
			x += currentElement.parentNode.scrollLeft;
		}
		currentElement = currentElement.parentNode;
	}

	if (document.body.leftMargin != null)
	{
		//x = parseInt(x) - parseInt(document.body.leftMargin);
		//alert(x);
	}

	return x;
};

RadGridNamespace.GetEventPosY = function (e)
{
	var y = e.clientY;

	var currentElement = RadGridNamespace.GetCurrentElement(e);

	while (currentElement.parentNode)
	{
		if (typeof(currentElement.parentNode.scrollTop) == "number")
		{
			y += currentElement.parentNode.scrollTop;
		}
		currentElement = currentElement.parentNode;
	}

	if (document.body.topMargin != null)
	{
		//y = parseInt(y) - parseInt(document.body.topMargin);
	}

	return y;
};

RadGridNamespace.IsChildOf = function (node, parentNode)
{
	while (node.parentNode)
	{
		if (node.parentNode == parentNode)
		{
			return true;
		}
		node = node.parentNode;
	}
	return false;
};

RadGridNamespace.GetFirstParentByTagName = function (node, tagName)
{
	while (node.parentNode)
	{
		if (node.tagName.toLowerCase() == tagName.toLowerCase())
		{
			return node;
		}
		node = node.parentNode;
	}
	return null;
};


RadGridNamespace.FindScrollPosX = function(node)
{
	var x = 0;
	while (node.parentNode)
	{
		if (typeof(node.parentNode.scrollLeft) == "number")
		{
			x += node.parentNode.scrollLeft;
		}
		node = node.parentNode;
	}
	return x;
};

RadGridNamespace.FindScrollPosY = function(node)
{
	var y = 0;
	while (node.parentNode)
	{
		if (typeof(node.parentNode.scrollTop) == "number")
		{
			y += node.parentNode.scrollTop;
		}
		node = node.parentNode;
	}
	return y;
};

RadGridNamespace.FindPosX = function (node)
{
	try
	{
		var x = 0;
		if (node.offsetParent)
		{
			while (node.offsetParent)
			{
				x += node.offsetLeft
				node = node.offsetParent;
			}
		}
		else if (node.x)
			x += node.x;
		return x;
	}
	catch(error)
	{
		return x;
	}
};

RadGridNamespace.FindPosY = function (node)
{
	var y = 0;
	if (node.offsetParent)
	{
		while (node.offsetParent)
		{
			y += node.offsetTop
			node = node.offsetParent;
		}
	}
	else if (node.y)
		y += node.y;
	return y;
};

RadGridNamespace.GetNodeNextSiblingByTagName = function (node, nodeTagName)
{
	while ((node != null) && (node.tagName != nodeTagName))
	{
		node = node.nextSibling;
	}
	return node;
};

RadGridNamespace.GetNodeNextSibling = function (node)
{
	while (node != null)
	{
		if (node.nextSibling)
		{
			node = node.nextSibling;
		}
		else
		{
			node = null;
		}
		if(node)
		{
			if (node.nodeType == 1)
			{
				break;
			}
		}
	}
	return node;
};

RadGridNamespace.DeleteSubString = function (string, startIndex, endIndex)
{
	return 	string = string.substring(0, startIndex) + string.substring(endIndex + 1, string.length);

};

RadGridNamespace.ClearDocumentEvents = function ()
{
	if (document.onmousedown != this.mouseDownHandler)
	{
		this.documentOnMouseDown = document.onmousedown;
	}

	if (document.onselectstart != this.selectStartHandler)
	{
		this.documentOnSelectStart = document.onselectstart;
	}

	if (document.ondragstart != this.dragStartHandler)
	{
		this.documentOnDragStart = document.ondragstart;
	}

	this.mouseDownHandler = function(e){return false;};
	this.selectStartHandler = function(){return false;};
	this.dragStartHandler = function(){return false;};

	document.onmousedown = this.mouseDownHandler;
	document.onselectstart = this.selectStartHandler;
	document.ondragstart = this.dragStartHandler;
};

RadGridNamespace.RestoreDocumentEvents = function ()
{
	if ((typeof(this.documentOnMouseDown) == "function") &&
		(document.onmousedown != this.mouseDownHandler))
	{
		document.onmousedown = this.documentOnMouseDown;
	}
	else
	{
		document.onmousedown = "";
	}
	
	if ((typeof(this.documentOnSelectStart) == "function") &&
		(document.onselectstart != this.selectStartHandler))
	{
		document.onselectstart = this.documentOnSelectStart;
	}
	else
	{
		document.onselectstart = "";
	}
	
	if ((typeof(this.documentOnDragStart) == "function") &&
		(document.ondragstart != this.dragStartHandler))
	{
		document.ondragstart = this.documentOnDragStart;
	}
	else
	{
		document.ondragstart = "";
	}
};

// Add a new stylesheet to the document;
// since we can't remove it, we cache the new entry and reuse it to avoid memory leaks.
RadGridNamespace.AddStyleSheet = function (clientID)
{	
	if (RadGridNamespace.StyleSheets == null)
	{
		RadGridNamespace.StyleSheets = {};
	}
	
	var cachedStyleSheet = RadGridNamespace.StyleSheets[clientID];
	if (cachedStyleSheet != null)
	{
		return cachedStyleSheet;
	}
	
	if (window.opera != null)
	{
		return;
	}

	var css = null;
	var before = null
	var head = document.getElementsByTagName("head")[0];

	if (window.netscape)
	{
		css = document.createElement('style');
		css.media = 'all';
		css.type  = 'text/css';
		head.appendChild(css);
	}
	else
	{
		try
		{
			css = document.createStyleSheet();
		}
		catch(e)
		{
			return false;
		}
	}
			
	var styleSheet = document.styleSheets[document.styleSheets.length - 1]
	RadGridNamespace.StyleSheets[clientID] = css;
	return styleSheet;

};

RadGridNamespace.ClearStyleSheet = function(ss)
{
	if (ss.deleteRule && ss.cssRules)
	{
		var cnt = ss.cssRules.length;
		while(cnt--)
			ss.removeRule(cnt);
			
		return;
	}
	
	var bAccessDenied = false;

	// This variation works on IE6
	try 
	{
		var cnt = ss.rules.length;
		while(cnt--)
			ss.removeRule(cnt);
	}
	catch(e) 
	{
		if((e.number&0xffff) == 5)
		bAccessDenied = true;
	}

	// This variation works on IE7
	if (bAccessDenied)
	{
		try 
		{
			while(true)
			ss.removeRule(0);
		}
		catch(e) 
		{
			// alert("No more rules.");
		}
	}
	return ss;
};

// Cross-browser method for inserting a new rule into an existing stylesheet.
// ss       - The stylesheet to stick the new rule in
// selector - The string value to use for the rule selector
// styles   - The string styles to use with the rule
RadGridNamespace.AddRule = function (ss,selector,styles)
{
    try
    {
	    if (!ss)
	    {
		    return false;
	    }

	    if (ss.insertRule)
	    {
		    var rule = ss.insertRule(selector+' {'+styles+'}',ss.cssRules.length);
		    //alert(ss.cssRules[ss.cssRules.length - 1].cssText);
		    return ss.cssRules[ss.cssRules.length - 1];
	    }

	    if (ss.addRule)
	    {
		    ss.addRule(selector,styles);
		    return true;
	    }

	    return false;
	}
	catch(e)
	{
	    return false;
	}
};
// e.g. AddRule( document.styleSheets[0] , 'a:link' , 'color:blue; text-decoration:underline' );
// e.g. AddRule( AddStyleSheet() , 'hr' , 'display:none' );

RadGridNamespace.addClassName = function (node, sClassName)
{
	var s = node.className;
	var p = s.split(" ");
	if (p.length == 1 && p[0] == "")
	{
		p = [];
	}

	var l = p.length;
	for (var i = 0; i < l; i++)
	{
		if (p[i] == sClassName)
		{
			return;
		}
	}
	p[p.length] = sClassName;
	node.className = p.join(" ");
};

RadGridNamespace.removeClassName = function (node, className)
{
	//var className = sClassName.replace(/\s*$/g,'');
	//var stylesToExclude = className.split(" ");
	//debugger;
	
	if(node.className.replace(/^\s*|\s*$/g,'') == className)
	{
		node.className = "";
		return;
	}

	var currentStyles = node.className.split(" ");
	var styles = [];
	for (var i = 0, l = currentStyles.length; i < l; i++)
	{
		if(currentStyles[i] == "") continue;
		if (className.indexOf(currentStyles[i]) == -1)
		{
			styles[styles.length] = currentStyles[i];
		}
	}
	node.className = styles.join(" ");
	return;
	
	node.className = (node.className.toString() == className)? "" : node.className.replace(className, "").replace(/\s*$/g,'');
	return;
	
	var p = s.split(" ");
	var np = [];
	var l = p.length;
	var j = 0;
	for (var i = 0; i < l; i++)
	{
		if (p[i] != className)
		{
			np[j++] = p[i];
		}
	}
	node.className = np.join(" ");
};

RadGridNamespace.CheckIsParentDisplay = function (node)
{
	try
	{
		while (node)
		{

			if (node.style)
			{
				if(node.currentStyle)
				{
					if(node.currentStyle.display == "none")
					{
						return false;
					}
				}
				else
				{
					if(node.style.display == "none")
					{
						return false;
					}
				}
			}
			node = node.parentNode;
		}

		if (window.top)
		{
			if (window.top.location != window.location)
			{
				return false;
			}
		}

		return true;
	}
	catch(e)
	{
		return false;
	}
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY

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);
		}
	}
};
RadGridNamespace.RadGrid = function(objectData)
{
	var oldInstance = window[objectData.ClientID];
	if (oldInstance != null && typeof(oldInstance.Dispose) == "function")
	{
	    window.setTimeout(function()
	    {
		    oldInstance.Dispose();		    
	    }, 100);
	}
		
	RadControlsNamespace.DomEventMixin.Initialize(this);
	
	this.AttachDomEvent(window, "unload", "OnWindowUnload");
	
	window[objectData.ClientID] = this;
	window["grid_" + objectData.ClientID] = this;

	if (!document.readyState || document.readyState == "complete" || window.opera)
	{
		this._constructor(objectData);
	}
	else
	{
		this.objectData = objectData;
		this.AttachDomEvent(window, "load", "OnWindowLoad");	
	}
};

RadGridNamespace.RadGrid.prototype.OnWindowUnload = function(e)
{
	this.Dispose();
};

RadGridNamespace.RadGrid.prototype.OnWindowLoad = function(e)
{
	this._constructor(this.objectData);
	this.objectData = null;
};

RadGridNamespace.RadGrid.prototype._constructor = function (objectData)
{	
	this.Type = "RadGrid";

	// RadGrid events initialization
	this.InitializeEvents(objectData.ClientSettings.ClientEvents);

	// RadGrid creation begin hander
	RadGridNamespace.FireEvent(this, "OnGridCreating");

	// creation
	for (var member in objectData)
	{
		this[member] = objectData[member];
	}

	// RadGrid properties initialization 
	this.Initialize();

	// MasterTableView creation begin hander
	RadGridNamespace.FireEvent(this, "OnMasterTableViewCreating");

	this.GridStyleSheet = RadGridNamespace.AddStyleSheet(this.ClientID);


	// MasterTableView creation
	if (this.ClientSettings.Scrolling.AllowScroll && this.ClientSettings.Scrolling.UseStaticHeaders)
	{
		var ID = objectData.MasterTableView.ClientID;

		objectData.MasterTableView.ClientID = ID + "_Header";

		this.MasterTableViewHeader = new RadGridNamespace.RadGridTable(objectData.MasterTableView);
		this.MasterTableViewHeader._constructor(this);

		if (document.getElementById(ID + "_Footer"))
		{
			objectData.MasterTableView.ClientID = ID + "_Footer";

			this.MasterTableViewFooter = new RadGridNamespace.RadGridTable(objectData.MasterTableView);
			this.MasterTableViewFooter._constructor(this);
		}

		objectData.MasterTableView.ClientID = ID;
	}

	//alert(this.MasterTableView);
	this.MasterTableView._constructor(this);
	
	// MasterTableView creation end hander
	RadGridNamespace.FireEvent(this, "OnMasterTableViewCreated");

	// MasterTableView DetailTables initialization
	this.DetailTablesCollection = new Array();

	this.LoadDetailTablesCollection(this.MasterTableView,1);
	
	// HandleEvents
	this.AttachDomEvents();

	// RadGrid creation end hander
	RadGridNamespace.FireEvent(this, "OnGridCreated");

	// RadGrid features initialization 
	this.InitializeFeatures(objectData);
	
	//RadAjaxNamespace hack
	this.Url = this.ClientSettings.AJAXUrl;
	this.EnableOutsideScripts = this.ClientSettings.EnableOutsideScripts;
	
	// handles the RadGridNamespace.AsyncRequestWithOptions(..., event) call
	// there is no global event object in firefox and we declare it in order to avoid the "event is undefined" error.
	if (typeof(window.event) == "undefined")
    {
        window.event = null;
    }
};

RadGridNamespace.RadGrid.prototype.Dispose = function()
{
	try
	{
	    RadGridNamespace.FireEvent(this, "OnGridDestroying");
	
		this.DisposeDomEventHandlers();
		
		this.DisposeEvents();		
		
		RadGridNamespace.ClearStyleSheet(this.GridStyleSheet);
		this.GridStyleSheet = null;

		this.DisposeFeatures();
		
		this.DisposeDetailTablesCollection(this.MasterTableView,1);
		
		if (this.MasterTableViewHeader != null)
			this.MasterTableViewHeader.Dispose();
		if (this.MasterTableViewFooter != null)
			this.MasterTableViewFooter.Dispose();
		if (this.MasterTableView != null)
			this.MasterTableView.Dispose();
			
		this.DisposeProperties();
		
	}
	catch (error)
	{
	}
}

RadGridNamespace.RadGrid.ClientEventNames = 
	{
		OnGridCreating : true,
		OnGridCreated : true,
		OnGridDestroying : true,
		OnMasterTableViewCreating : true,
		OnMasterTableViewCreated : true,
		OnTableCreating : true,
		OnTableCreated : true,
		OnTableDestroying : true,
		OnScroll : true,
		OnKeyPress : true,
		OnRequestStart : true,
		OnRequestEnd : true,
		OnRequestError : true,
		OnError : true
	};

RadGridNamespace.RadGrid.prototype.IsClientEventName = function(eventName)
{
	return RadGridNamespace.RadGrid.ClientEventNames[eventName] == true;
}

RadGridNamespace.RadGrid.prototype.InitializeEvents = function (clientEvents)
{
	for (var clientEvent in clientEvents)
	{
        if (typeof(clientEvents[clientEvent]) != "string")
            continue;
		
		if (this.IsClientEventName(clientEvent))
		{
			if (clientEvents[clientEvent] != "")
			{
				var handlerString = clientEvents[clientEvent];

				if (handlerString.indexOf("(") != -1)
				{
					// function call
					this[clientEvent] = handlerString;
				}
				else
				{
					// function reference
					this[clientEvent] = eval(handlerString);
				}
			}
			else
			{
				this[clientEvent] = null;
			}
		}
	}
};

RadGridNamespace.RadGrid.prototype.DisposeEvents = function()
{
	for (var clientEvent in RadGridNamespace.RadGrid.ClientEventNames)
	{
		this[clientEvent] = null;
	}
};

RadGridNamespace.RadGrid.prototype.GetDetailTable = function (tableView, hierarchyIndex)
{
  if(tableView.HierarchyIndex == hierarchyIndex)
  {
	return tableView;
  }
  
  if (tableView.DetailTables)
  {
	for (var i = 0; i < tableView.DetailTables.length; i++)
	{		
		var res = this.GetDetailTable(tableView.DetailTables[i], hierarchyIndex);
		if ( res )
		{
		  return res;
		}
	}
  }
};

RadGridNamespace.RadGrid.prototype.LoadDetailTablesCollection = function (tableView, count )
{
	try
	{
		if (tableView.Controls[0] != null && tableView.Controls[0].Rows != null)
		{
			for (var i=0;i<tableView.Controls[0].Rows.length;i++ )
			{
				var itemType = tableView.Controls[0].Rows[i].ItemType
				if (itemType == "NestedView")
				{
					var currentTableViews = tableView.Controls[0].Rows[i].NestedTableViews;

					for (var j=0; j < currentTableViews.length; j++)
					{
						var currentTableView = currentTableViews[j];
						if ( currentTableView.Visible )
						{
							var detailTable = this.GetDetailTable(this.MasterTableView, currentTableView.HierarchyIndex);

							currentTableView.RenderColumns = detailTable.RenderColumns;

							RadGridNamespace.FireEvent(this, "OnTableCreating", [detailTable]);

							currentTableView._constructor(this);
							this.DetailTablesCollection[this.DetailTablesCollection.length] = currentTableView;

							if (currentTableView.AllowFilteringByColumn)
							{
								this.InitializeFilterMenu(currentTableView);
							}

							RadGridNamespace.FireEvent(this, "OnTableCreated", [currentTableView]);

						}
						this.LoadDetailTablesCollection(currentTableView,count + 1);
					}
				}
			}
		}

	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};

RadGridNamespace.RadGrid.prototype.DisposeDetailTablesCollection = function (tableView, count )
{	
	if (tableView.Controls[0] != null && tableView.Controls[0].Rows != null)
	{	
		for (var i=0;i<tableView.Controls[0].Rows.length;i++ )
		{
			var itemType = tableView.Controls[0].Rows[i].ItemType
			if (itemType == "NestedView")
			{
				var currentTableViews = tableView.Controls[0].Rows[i].NestedTableViews;
				for (var j=0; j < currentTableViews.length; j++)
				{
					var currentTableView = currentTableViews[j];
					currentTableView.Dispose();
				}
			}
		}
	}
};

RadGridNamespace.RadGrid.prototype.Initialize = function ()
{
	this.Control = document.getElementById(this.ClientID);
	
	if(this.Control == null)
		return;

	this.GridDataDiv = document.getElementById(this.ClientID + "_GridData");
	this.GroupPanelControl = document.getElementById(this.GroupPanel.ClientID + "_GroupPanel");
	this.GridHeaderDiv = document.getElementById(this.ClientID + "_GridHeader");
	this.GridFooterDiv = document.getElementById(this.ClientID + "_GridFooter");
	this.PostDataValue = document.getElementById(this.ClientID + "PostDataValue");
	this.LoadingTemplate = document.getElementById(this.ClientID + "_LoadingTemplate");
	this.PagerControl = document.getElementById(this.MasterTableView.ClientID + "_Pager");
	this.TopPagerControl = document.getElementById(this.MasterTableView.ClientID + "_TopPager");

	if(this.LoadingTemplate)
	{
		this.LoadingTemplate.style.display = "none";
		if (this.GridDataDiv)
		{
			this.GridDataDiv.appendChild(this.LoadingTemplate);
		}
	}
	
	this.FormID = this.ClientSettings.FormID;
};

RadGridNamespace.RadGrid.prototype.DisposeProperties = function()
{
	this.Control = null;
	this.GridDataDiv = null;
	this.GroupPanelControl = null;
	this.GridHeaderDiv = null;
	this.GridFooterDiv = null;
	this.PostDataValue = null;
	this.LoadingTemplate = null;
	this.PagerControl = null;
}

RadGridNamespace.RadGrid.prototype.InitializeFeatures = function (objectData)
{
	if (!this.MasterTableView.Control)
		return;

	if (this.GroupPanelControl != null)
	{
		this.GroupPanelObject = new RadGridNamespace.RadGridGroupPanel(this.GroupPanelControl, this)
	}

	if (this.ClientSettings.Scrolling.AllowScroll)
	{
		this.InitializeDimensions();

		this.InitializeScroll();
	}

	if (this.Control.align == "")
	{
	    var isRtl = RadGridNamespace.IsParentRightToLeft(this.GridHeaderDiv);
	    if(!isRtl)
	    {
		    this.Control.align = "left";
		}
		else
		{
		    this.Control.align = "right";
		}
	}

	if (this.AllowFilteringByColumn || this.MasterTableView.AllowFilteringByColumn)
	{
		var tableView = (this.MasterTableViewHeader)? this.MasterTableViewHeader : this.MasterTableView;
		this.InitializeFilterMenu(tableView);
	}

	if(this.ClientSettings.AllowKeyboardNavigation && this.MasterTableView.Rows)
	{
		if (!this.MasterTableView.RenderActiveItemStyleClass || this.MasterTableView.RenderActiveItemStyleClass == "")
		{
			if (this.MasterTableView.RenderActiveItemStyle && this.MasterTableView.RenderActiveItemStyle != "")
			{
				RadGridNamespace.AddRule(this.GridStyleSheet,".ActiveItemStyle" + this.MasterTableView.ClientID + "1 td",this.MasterTableView.RenderActiveItemStyle);
			}
			else
			{
				RadGridNamespace.AddRule(this.GridStyleSheet,".ActiveItemStyle" + this.MasterTableView.ClientID + "2 td","background-color:#FFA07A;");
			}
		}

		if(this.ActiveRow == null)
		{
			this.ActiveRow = this.MasterTableView.Rows[0];
		}
		
		this.SetActiveRow(this.ActiveRow)
	}
		
	if(window[this.ClientID + "_Slider"])
	{
		this.Slider = new RadGridNamespace.Slider(window[this.ClientID + "_Slider"]);
	}

};

RadGridNamespace.RadGrid.prototype.DisposeFeatures = function ()
{
	if (this.Slider != null)
	{
		this.Slider.Dispose();
		this.Slider = null;
	}
	
	if (this.GroupPanelControl != null)
	{
		this.GroupPanelObject.Dispose();
		this.GroupPanelControl = null;
	}

//TODO: deep dispose scroll objects
//	if (this.ClientSettings.Scrolling.AllowScroll)
//	{
//		this.InitializeScroll(objectData);
//	}


	if (this.AllowFilteringByColumn || this.MasterTableView.AllowFilteringByColumn)
	{
		var tableView = (this.MasterTableViewHeader)? this.MasterTableViewHeader : this.MasterTableView;
		this.DisposeFilterMenu(tableView);
	}
	
	this.Control = null;
};

RadGridNamespace.RadGrid.prototype.AsyncRequest = function(eventTarget, eventArgument)
{/*
	var evt = {};
	evt.eventTarget = eventTarget;
	evt.eventArgument = eventArgument;

	if (!RadGridNamespace.FireEvent(this, "OnRequestStart",[evt]))
	{
		return;
	}
*/
	var statusLabelOldHTML;
	if(this.StatusBarSettings != null && this.StatusBarSettings.StatusLabelID != null && this.StatusBarSettings.StatusLabelID != "")
	{
		var statusLabel = document.getElementById(this.StatusBarSettings.StatusLabelID);
		if(statusLabel != null)
		{
			statusLabelOldHTML = statusLabel.innerHTML;
			statusLabel.innerHTML = this.StatusBarSettings.LoadingText;
		}
	}

	var clientID = this.ClientID;
	this.OnRequestEndInternal = function()
	{
	    RadGridNamespace.FireEvent(window[clientID], "OnRequestEnd");
	    if(statusLabel)
			statusLabel.innerHTML = statusLabelOldHTML;
	};

	RadAjaxNamespace.AsyncRequest(eventTarget, eventArgument, clientID);
};

RadGridNamespace.RadGrid.prototype.AjaxRequest = function (eventTarget, eventArgument)
{
	this.AsyncRequest(eventTarget, eventArgument);
};

RadGridNamespace.RadGrid.prototype.ClearSelectedRows = function()
{
	for(var i = 0; i < this.DetailTablesCollection.length; i++)
	{
		var detailTable = this.DetailTablesCollection[i];
		detailTable.ClearSelectedRows();
	}
	
	this.MasterTableView.ClearSelectedRows();
};

RadGridNamespace.RadGrid.prototype.AsyncRequestWithOptions = function(options)
{
	RadAjaxNamespace.AsyncRequestWithOptions(options, this.ClientID);
};

RadGridNamespace.RadGrid.prototype.DeleteRow = function(tableViewUniqueID, itemIndex, e)
{
	var button = (e.srcElement)? e.srcElement : e.target;
	if(!button)
	    return;

    var row = button.parentNode.parentNode;
    var table = row.parentNode.parentNode;

    var index = row.rowIndex;
    var cellsLength = row.cells.length;
    table.deleteRow(row.rowIndex);

	for(var i = index; i < table.rows.length; i++)
	{
		if(table.rows[i].cells.length != cellsLength && table.rows[i].style.display != "none")
		{
			table.deleteRow(i);
			i--;
		}
		else
		{
			break;
		}
	}

    if(table.tBodies[0].rows.length == 1 && table.tBodies[0].rows[0].style.display == "none")
    {
		table.tBodies[0].rows[0].style.display = "";
    }
    
    this.PostDataValue.value += "DeletedRows," + tableViewUniqueID + "," + itemIndex + ";";
};

RadGridNamespace.RadGrid.prototype.SelectRow = function(tableViewUniqueID, itemIndex, e)
{
	var button = (e.srcElement)? e.srcElement : e.target;
	if(!button)
	    return;

    var row = button.parentNode.parentNode;
    var table = row.parentNode.parentNode;

    var index = row.rowIndex;
    
    var tableView;

    if(tableViewUniqueID == this.MasterTableView.UID)
    {
		tableView = this.MasterTableView;
    }
    else
    {
		for (var i = 0; i < this.DetailTablesCollection.length; i++)
		{
			if(this.DetailTablesCollection[i].ClientID == table.id)
			{
				tableView = this.DetailTablesCollection[i];
				break;
			}
		}
    }
    
    
    if(tableView != null)
    {
		if(this.AllowMultiRowSelection)
		{
			tableView.SelectRow(row, false);
		}
		else
		{
			tableView.SelectRow(row, true);
		}
    }
};

RadGridNamespace.RadGrid.prototype.SelectAllRows = function(tableViewUniqueID, itemIndex, e)
{
	var button = (e.srcElement)? e.srcElement : e.target;
	if(!button)
	    return;

    var row = button.parentNode.parentNode;
    var table = row.parentNode.parentNode;

    var index = row.rowIndex;
    
    var tableView;

    if(tableViewUniqueID == this.MasterTableView.UID)
    {
		tableView = this.MasterTableView;
    }
    else
    {
		for (var i = 0; i < this.DetailTablesCollection.length; i++)
		{
			if(this.DetailTablesCollection[i].UID == tableViewUniqueID)
			{
				tableView = this.DetailTablesCollection[i];
				break;
			}
		}
    }
    
    if(tableView != null)
    {
		if(this.AllowMultiRowSelection)
		{
			if(tableView == this.MasterTableViewHeader)
			{
				tableView = this.MasterTableView;
			}
			
			tableView.ClearSelectedRows();

			if (button.checked)
			{
				for (var i = 0; i < tableView.Control.tBodies[0].rows.length; i++)
				{
					var row = tableView.Control.tBodies[0].rows[i];
					tableView.SelectRow(row, false);
				}
			}
			else
			{
				for (var i = 0; i < tableView.Control.tBodies[0].rows.length; i++)
				{
					var row = tableView.Control.tBodies[0].rows[i];
					tableView.DeselectRow(row);
				}
				
				this.SavePostData("SelectedRows", tableView.ClientID, "");

			}
	    }
    }
};


//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY

RadGridNamespace.RadGrid.prototype.HandleActiveRow = function (e)
{
	if ((this.AllowRowResize) || (this.AllowRowSelect))
	{
		var cell = this.GetCellFromPoint(e);
		
		if ((cell != null) && (cell.parentNode.id != "") && (cell.parentNode.id != -1)
					&& (cell.cellIndex == 0))
		{
			var table = cell.parentNode.parentNode.parentNode;
			this.SetActiveRow(table, cell.parentNode.rowIndex);
		}
	}
};

RadGridNamespace.RadGrid.prototype.SetActiveRow = function (rowObject)
{
	//debugger;
	if(rowObject == null)
		return;

	if (rowObject.Owner.RenderActiveItemStyle)
	{
		RadGridNamespace.removeClassName(this.ActiveRow.Control, "ActiveItemStyle" + rowObject.Owner.ClientID + "1");
	}
	else
	{
		RadGridNamespace.removeClassName(this.ActiveRow.Control, "ActiveItemStyle" + rowObject.Owner.ClientID + "2");
	}

	RadGridNamespace.removeClassName(this.ActiveRow.Control, rowObject.Owner.RenderActiveItemStyleClass);

	if (this.ActiveRow.Control.style.cssText == rowObject.Owner.RenderActiveItemStyle)
	{
		this.ActiveRow.Control.style.cssText = "";
	}
	
	this.ActiveRow = rowObject;
	
	if(!this.ActiveRow.Owner.RenderActiveItemStyleClass || this.ActiveRow.Owner.RenderActiveItemStyleClass == "")
	{
		if (this.ActiveRow.Owner.RenderActiveItemStyle && this.ActiveRow.Owner.RenderActiveItemStyle != "")
		{
			RadGridNamespace.addClassName(this.ActiveRow.Control, "ActiveItemStyle" + this.ActiveRow.Owner.ClientID + "1");
		}
		else
		{
			RadGridNamespace.addClassName(this.ActiveRow.Control, "ActiveItemStyle" + this.ActiveRow.Owner.ClientID + "2");
		}
	}
	else
	{
		RadGridNamespace.addClassName(this.ActiveRow.Control, this.ActiveRow.Owner.RenderActiveItemStyleClass);
	}

	this.SavePostData("ActiveRow", this.ActiveRow.Owner.ClientID, this.ActiveRow.RealIndex);


};

RadGridNamespace.RadGrid.prototype.GetNextRow = function (table, rowIndex)
{
	if (table != null)
	{
		if (table.tBodies[0].rows[rowIndex] != null)
		{
			while (table.tBodies[0].rows[rowIndex] != null)
			{
				rowIndex++;
				if (rowIndex <= (table.tBodies[0].rows.length-1))
				{
						return table.tBodies[0].rows[rowIndex];
				}
				else
				{
					return null;
				}
			}
		}
	}
};

RadGridNamespace.RadGrid.prototype.GetPreviousRow = function (table, rowIndex)
{
	if (table != null)
	{
		if (table.tBodies[0].rows[rowIndex] != null)
		{
			while (table.tBodies[0].rows[rowIndex] != null)
			{
				rowIndex--;
				if (rowIndex >= 0)
				{
						return table.tBodies[0].rows[rowIndex];
				}
				else
				{
					return null;
				}
			}
		}
	}
};

RadGridNamespace.RadGrid.prototype.GetNextHierarchicalRow = function (table, rowIndex)
{
	if (table != null)
	{
		if (table.tBodies[0].rows[rowIndex] != null)
		{
			rowIndex++;
			var row = table.tBodies[0].rows[rowIndex];
			
			if (table.tBodies[0].rows[rowIndex] != null)
			{
				if ((row.cells[1] != null) && (row.cells[2] != null))
				{
				
					if ((row.cells[1].getElementsByTagName("table").length > 0) ||
							(row.cells[2].getElementsByTagName("table").length > 0))
					{
						var nextRow = this.GetNextRow(row.cells[2].firstChild, 0);
						return nextRow;
					}
					else
					{
						return null;
					}
				}
			}
		}
	}
};

RadGridNamespace.RadGrid.prototype.GetPreviousHierarchicalRow = function (table, rowIndex)
{
	if (table != null)
	{
		if (table.parentNode != null)
		{
			if (table.parentNode.tagName.toLowerCase() == "td")
			{
				
				var previousTable = table.parentNode.parentNode.parentNode.parentNode;
				var previousRowIndex = table.parentNode.parentNode.rowIndex;
				return this.GetPreviousRow(previousTable, previousRowIndex);
			}
			else
			{
				return null;
			}
		}
		else
		{
			return this.GetPreviousRow(table, rowIndex);
		}
	}
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY

RadGridNamespace.RadGrid.prototype.HandleCellEdit = function(e)
{
	var currentElement = RadGridNamespace.GetCurrentElement(e);
	var newElement = RadGridNamespace.GetFirstParentByTagName(currentElement,"td");
	if (newElement != null)
	{
		currentElement = newElement;

		var currentTable =  currentElement.parentNode.parentNode.parentNode;
		var definedTable =  this.GetTableObjectByID(currentTable.id);

		if ((definedTable != null) &&
			(definedTable.Columns.length > 0) &&
			(definedTable.Columns[currentElement.cellIndex] != null))
		{
			if(definedTable.Columns[currentElement.cellIndex].ColumnType != "GridBoundColumn")
				return;

			this.EditedCell = definedTable.Control.rows[currentElement.parentNode.rowIndex].cells[currentElement.cellIndex];

			this.CellEditor = new RadGridNamespace.RadGridCellEditor(this.EditedCell, definedTable.Columns[currentElement.cellIndex], this);

		}
	}
};

RadGridNamespace.RadGridCellEditor = function(cell, column, owner)
{
	if (owner.CellEditor)
		return;

	this.Control = document.createElement("input");
	this.Control.style.border = "1px groove";
	this.Control.style.width = "100%";
	
	this.Control.value = cell.innerHTML;
	this.OldValue = this.Control.value;
	cell.innerHTML = "";
	
	var thisObject = this;
	this.Control.onblur = function(e)
	{
		if (!e)
			var e = window.event;
		cell.removeChild(this);
		cell.innerHTML = this.value;
		if(this.value != thisObject.OldValue)
		{
		    alert(1);
		}
		owner.CellEditor = null;
	};
	
	cell.appendChild(this.Control);
	if(this.Control.focus)
	    this.Control.focus();
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY

if (!("console" in window) || !("firebug" in console))
{
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}
}

RadGridNamespace.Error = function (error, owner, customErrorHandler)
{
	if ((!error) || (!owner) || (!customErrorHandler))
	{
		//alert(error);
		//throw error;
		return false;
	}

	this.Message = error.message;

	if (customErrorHandler != null)
	{
		if ("string" == typeof(customErrorHandler))
		{
			try
			{
				eval(customErrorHandler);
			}
			catch(e)
			{
				var message = "";
				message = "";
				message += "Telerik RadGrid Error:\r\n" ;
				message += "-----------------\r\n";
				message += "Message: \"" + e.message + "\"\r\n";
				message += "Raised by: " + owner.Type + "\r\n";
				alert(message);
			}
		}
		else if ("function" == typeof(customErrorHandler))
		{
			try
			{
				customErrorHandler(this);
			}
			catch(e)
			{
				var message = "";
				message = "";
				message += "Telerik RadGrid Error:\r\n" ;
				message += "-----------------\r\n";
				message += "Message: \"" + e.message + "\"\r\n";
				message += "Raised by: " + owner.Type + "\r\n";
				alert(message);
			}
		}
	}
	else
	{
		this.Owner = owner;

		for (var member in error)
		{
			this[member] = error[member];
		}

		this.Message = "";
		this.Message += "Telerik RadGrid Error:\r\n" ;
		this.Message += "-----------------\r\n";
		this.Message += "Message: \"" + error.message + "\"\r\n";
		this.Message += "Raised by: " + owner.Type + "\r\n";

		alert(this.Message);
	}

};

RadGridNamespace.RadGrid.prototype.GetTableObjectByID = function (id)
{
	if (this.MasterTableView.ClientID == id)
	{
		return this.MasterTableView;
	}
	else
	{
		for (var i=0;i<this.DetailTablesCollection.length;i++)
		{
			if (this.DetailTablesCollection[i].ClientID == id)
			{
				return this.DetailTablesCollection[i];
			}
		}
	}

	if (this.MasterTableViewHeader != null)
	{
		if (this.MasterTableViewHeader.ClientID == id)
		{
			return table = this.MasterTableViewHeader;
		}
	}
};

RadGridNamespace.RadGrid.prototype.GetRowObjectByRealRow = function (tableObject, row)
{
	if(tableObject.Rows != null)
	{
		for (var i=0;i<tableObject.Rows.length;i++)
		{
			if (tableObject.Rows[i].Control == row)
			{
				return tableObject.Rows[i];
			}
		}
	}
};

RadGridNamespace.RadGrid.prototype.SavePostData = function ()
{
	try
	{
		var postDataValue = new String();

		for(var i=0;i<arguments.length;i++)
		{
			postDataValue += arguments[i] + ",";
		}

		postDataValue = postDataValue.substring(0,postDataValue.length-1);

		if (this.PostDataValue != null)
		{

			switch (arguments[0])
			{

				case "ReorderedColumns":
				{
					this.PostDataValue.value += postDataValue + ";";
					break;
				}

				case "HidedColumns":
				{
					var searchValue = arguments[0] + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					searchValue = "ShowedColumns" + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					break;
				}

				case "ShowedColumns":
				{
					var searchValue = arguments[0] + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					searchValue = "HidedColumns" + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					break;
				}

				case "HidedRows":
				{
					var searchValue = arguments[0] + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					searchValue = "ShowedRows" + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					break;
				}

				case "ShowedRows":
				{
					var searchValue = arguments[0] + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					searchValue = "HidedRows" + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					break;
				}

				case "ResizedColumns":
				{
					var searchValue = arguments[0] + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					break;
				}
				case "ResizedRows":
				{
					var searchValue = arguments[0] + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					break;
				}
				case "ResizedControl":
				{
					var searchValue = arguments[0] + "," + arguments[1];
					this.UpdatePostData(postDataValue, searchValue);
					break;
				}
				case "ClientCreated":
				{
					var searchValue = arguments[0] + "," + arguments[1];
					this.UpdatePostData(postDataValue, searchValue);
					break;
				}
				case "ScrolledControl":
				{
					var searchValue = arguments[0] + "," + arguments[1];
					this.UpdatePostData(postDataValue, searchValue);
					break;
				}
				case "AJAXScrolledControl":
				{
					var searchValue = arguments[0] + "," + arguments[1];
					this.UpdatePostData(postDataValue, searchValue);
					//alert(this.PostDataValue.value);
					break;
				}
				case "SelectedRows":
				{
					var searchValue = arguments[0] + "," + arguments[1];
					this.UpdatePostData(postDataValue, searchValue);
					//alert(this.PostDataValue.value);
					break;
				}
				case "EditRow":
				{
					var searchValue = arguments[0] + "," + arguments[1];
					this.UpdatePostData(postDataValue, searchValue);
					//alert(this.PostDataValue.value);
					break;
				}
				case "ActiveRow":
				{
					var searchValue = arguments[0] + "," + arguments[1];
					this.UpdatePostData(postDataValue, searchValue);
					//alert(this.PostDataValue.value);
					break;
				}
				case "CollapsedRows":
				{
					var searchValue = arguments[0] + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					searchValue = "ExpandedRows" + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					break;
				}

				case "ExpandedRows":
				{
					var searchValue = arguments[0] + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					searchValue = "CollapsedRows" + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					break;
				}
				case "CollapsedGroupRows":
				{
					var searchValue = arguments[0] + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					searchValue = "ExpandedGroupRows" + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					break;
				}

				case "ExpandedGroupRows":
				{
					var searchValue = arguments[0] + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					searchValue = "CollapsedGroupRows" + "," + arguments[1] + "," + arguments[2];
					this.UpdatePostData(postDataValue, searchValue);
					break;
				}
				default:
				{
					this.UpdatePostData(postDataValue, postDataValue);
					break;
				}
			}
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};

RadGridNamespace.RadGrid.prototype.UpdatePostData = function (newValue, searchValue)
{
	var searchArray, newArray = new Array();
	searchArray = this.PostDataValue.value.split(";");

	for (var i=0;i<searchArray.length;i++)
	{
		if (searchArray[i].indexOf(searchValue) == -1)
		{
			newArray[newArray.length] = searchArray[i];
		}
	}

	this.PostDataValue.value = newArray.join(";");
	this.PostDataValue.value += newValue + ";";
};

RadGridNamespace.RadGrid.prototype.DeletePostData = function (newValue, searchValue)
{
	var searchArray, newArray = new Array();
	searchArray = this.PostDataValue.value.split(";");

	for (var i=0;i<searchArray.length;i++)
	{
		if (searchArray[i].indexOf(searchValue) == -1)
		{
			newArray[newArray.length] = searchArray[i];
		}
	}

	this.PostDataValue.value = newArray.join(";");
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY

RadGridNamespace.RadGrid.prototype.HandleDragAndDrop = function (e, currentDragElement)
{
	try
	{
		var gridControl = this;
		if ((currentDragElement != null) && (currentDragElement.tagName.toLowerCase() == "th"))
		{
			var currentTable =  currentDragElement.parentNode.parentNode.parentNode;
			var definedTable =  this.GetTableObjectByID(currentTable.id);

			if ((definedTable != null) &&
				(definedTable.Columns.length > 0) &&
				(definedTable.Columns[currentDragElement.cellIndex] != null) &&
				((definedTable.Columns[currentDragElement.cellIndex].Reorderable) ||
				(definedTable.Owner.ClientSettings.AllowDragToGroup && definedTable.Columns[currentDragElement.cellIndex].Groupable)))
			{
				var positionX = RadGridNamespace.GetEventPosX(e);
				var startX = RadGridNamespace.FindPosX(currentDragElement);
				var endX = startX + currentDragElement.offsetWidth;

				this.ResizeTolerance = 5;

				var oldTitle = currentDragElement.title;
				var oldCursor = currentDragElement.style.cursor;

				if (!((positionX >= endX - this.ResizeTolerance) && 
					(positionX <= endX + this.ResizeTolerance)))
				{
					if (this.MoveHeaderDiv)
					{
						if (this.MoveHeaderDiv.innerHTML != currentDragElement.innerHTML)
						{
							currentDragElement.title = this.ClientSettings.ClientMessages.DropHereToReorder;
							currentDragElement.style.cursor = "default";
							
							if (currentDragElement.parentNode.parentNode.parentNode == this.MoveHeaderDivRefCell.parentNode.parentNode.parentNode)
							{
								this.MoveReorderIndicators(e, currentDragElement);
							}
							else
							{
								if (this.ReorderIndicator1 != null)
								{
									this.ReorderIndicator1.style.visibility = "hidden";
									this.ReorderIndicator1.style.display = "none";
									this.ReorderIndicator1.style.position = "absolute";
								}

								if (this.ReorderIndicator2 != null)
								{
									this.ReorderIndicator2.style.visibility = this.ReorderIndicator1.style.visibility;
									this.ReorderIndicator2.style.display = this.ReorderIndicator1.style.display;
									this.ReorderIndicator2.style.position = this.ReorderIndicator1.style.position;
								}
							}
						}
					}
					else
					{
						currentDragElement.title = this.ClientSettings.ClientMessages.DragToGroupOrReorder;
						currentDragElement.style.cursor = "move";
					}

					this.AttachDomEvent(currentDragElement, "mousedown", "OnDragDropMouseDown");
				}
				else
				{
					currentDragElement.style.cursor = oldCursor;
					currentDragElement.title = "";					
				}
			}
		}

		//are we in the middle of a drag?
		if (this.MoveHeaderDiv != null)
		{
			this.MoveHeaderDiv.style.visibility = "";
			this.MoveHeaderDiv.style.display = "";

			RadGridNamespace.RadGrid.PositionDragElement(this.MoveHeaderDiv, e);
		}

	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};

RadGridNamespace.RadGrid.PositionDragElement = function(element, mouseEvent)
{
	element.style.top =  mouseEvent.clientY + 
							document.documentElement.scrollTop + 
							document.body.scrollTop + 1 + "px";

	element.style.left = mouseEvent.clientX + 
							document.documentElement.scrollLeft + 
							document.body.scrollLeft + 1 + "px";
}

RadGridNamespace.RadGrid.prototype.OnDragDropMouseDown = function (e)
{
	var currentDragElement = RadGridNamespace.GetCurrentElement(e);
	var postBackInProgress = false;
    var form = document.getElementById(this.FormID);
    if (form != null && form["__EVENTTARGET"] != null && form["__EVENTTARGET"].value != "")
    {
        postBackInProgress = true;
    }

    if((currentDragElement.tagName.toLowerCase() == "input" 
        && currentDragElement.type.toLowerCase() == "text")
        ||
        (currentDragElement.tagName.toLowerCase() == "textarea"))
        return;

	currentDragElement = RadGridNamespace.GetFirstParentByTagName(currentDragElement, "th");

	if(currentDragElement.tagName.toLowerCase() == "th" && !this.IsResize)
	{
		if (((window.netscape || window.opera) && (e.button == 0)) || (e.button == 1))
		{
			this.CreateDragAndDrop(e, currentDragElement);
		}

		RadGridNamespace.ClearDocumentEvents();

		this.DetachDomEvent(currentDragElement, "mousedown", "OnDragDropMouseDown");
		
		this.AttachDomEvent(document, "mouseup", "OnDragDropMouseUp");
		if (this.GroupPanelControl != null)
		{
			this.AttachDomEvent(this.GroupPanelControl, "mouseup", "OnDragDropMouseUp");
		}
	}
};

RadGridNamespace.RadGrid.prototype.OnDragDropMouseUp = function (e)
{
	this.DetachDomEvent(document, "mouseup", "OnDragDropMouseUp");
	if (this.GroupPanelControl != null)
	{
		this.DetachDomEvent(this.GroupPanelControl, "mouseup", "OnDragDropMouseUp");
	}
	
	this.FireDropAction(e);
	this.DestroyDragAndDrop(e);
	RadGridNamespace.RestoreDocumentEvents();
};

RadGridNamespace.CopyAttributes = function (target, source)
{
	for(var i = 0; i < source.attributes.length; i++)
	{
		try
		{
			if (source.attributes[i].name.toLowerCase() == "id")
				continue;
				
			if (source.attributes[i].value != null && source.attributes[i].value != "null" && source.attributes[i].value != "")
			{
				target.setAttribute(source.attributes[i].name, source.attributes[i].value);
			}
		}
		catch(e)
		{
			continue;
		}
	}
};

RadGridNamespace.RadGrid.prototype.CreateDragAndDrop = function (e, currentDragElement)
{
	this.MoveHeaderDivRefCell = currentDragElement;

	this.MoveHeaderDiv = document.createElement("div");

	var table = document.createElement("table");
	
	if (this.MoveHeaderDiv.mergeAttributes)
	{
		this.MoveHeaderDiv.mergeAttributes(this.Control);
	}
	else
	{
		RadGridNamespace.CopyAttributes(this.MoveHeaderDiv, this.Control);
	}

	if (table.mergeAttributes)
	{
		table.mergeAttributes(this.MasterTableView.Control);
	}
	else
	{
		RadGridNamespace.CopyAttributes(table, this.MasterTableView.Control);
	}

	table.style.margin = "0px";
	table.style.height = currentDragElement.offsetHeight + "px";
	table.style.width = currentDragElement.offsetWidth + "px";

	var tHead = document.createElement("thead");
	var tr = document.createElement("tr");
	
	table.appendChild(tHead);
	tHead.appendChild(tr);
	tr.appendChild(currentDragElement.cloneNode(true));
	this.MoveHeaderDiv.appendChild(table);
	
	document.body.appendChild(this.MoveHeaderDiv);

	this.MoveHeaderDiv.style.height = currentDragElement.offsetHeight + "px";
	this.MoveHeaderDiv.style.width = currentDragElement.offsetWidth + "px";

	this.MoveHeaderDiv.style.position = "absolute";

	RadGridNamespace.RadGrid.PositionDragElement(this.MoveHeaderDiv, e);

	if (window.netscape)
	{
		this.MoveHeaderDiv.style.MozOpacity = 3/4;
	}
	else
	{
		this.MoveHeaderDiv.style.filter = "alpha(opacity=75);";
		
	}

	this.MoveHeaderDiv.style.cursor = "move";
	
	this.MoveHeaderDiv.style.visibility = "hidden";

	this.MoveHeaderDiv.style.display = "none";
	
	this.MoveHeaderDiv.style.fontWeight = "bold";

	this.MoveHeaderDiv.onmousedown = null;
	
	RadGridNamespace.ClearDocumentEvents();
	
	if (this.ClientSettings.AllowColumnsReorder)
	{
		this.CreateReorderIndicators(currentDragElement);
	}
};

RadGridNamespace.RadGrid.prototype.DestroyDragAndDrop = function ()
{
	if (this.MoveHeaderDiv != null)
	{
		var parentNode = this.MoveHeaderDiv.parentNode;
		parentNode.removeChild(this.MoveHeaderDiv);
		this.MoveHeaderDiv.onmouseup = null;
		this.MoveHeaderDiv.onmousemove = null;
		this.MoveHeaderDiv = null;
		this.MoveHeaderDivRefCell = null;
		this.DragCellIndex = null;
		RadGridNamespace.RestoreDocumentEvents();
		
		this.DestroyReorderIndicators();
	}
};

RadGridNamespace.RadGrid.prototype.FireDropAction = function (e)
{
	if ((this.MoveHeaderDiv != null) && (this.MoveHeaderDiv.style.display != "none"))
	{
		var currentDragElement = RadGridNamespace.GetCurrentElement(e);
		if ((currentDragElement != null) && (this.MoveHeaderDiv != null))
		{
			if (currentDragElement != this.MoveHeaderDivRefCell)
			{
				var parentTableObject = this.GetTableObjectByID(this.MoveHeaderDivRefCell.parentNode.parentNode.parentNode.id);
				var headerRow = parentTableObject.HeaderRow;

				if (RadGridNamespace.IsChildOf(currentDragElement, headerRow))
				{
					if (currentDragElement.tagName.toLowerCase() != "th")
					{
						currentDragElement = RadGridNamespace.GetFirstParentByTagName(currentDragElement, "th");
					}

					var currentTable =  currentDragElement.parentNode.parentNode.parentNode;
					var definedTable =  this.MoveHeaderDivRefCell.parentNode.parentNode.parentNode;

					if (currentTable.id == definedTable.id)
					{
						var currentTableObject =  this.GetTableObjectByID(currentTable.id);

                        var realCellIndex1 = currentDragElement.cellIndex;
                        if(window.attachEvent && !window.opera && !window.netscape)
                        {
                            realCellIndex1 = RadGridNamespace.GetRealCellIndex(currentTableObject, currentDragElement);
                        }

                        var realCellIndex2 = this.MoveHeaderDivRefCell.cellIndex;
                        if(window.attachEvent && !window.opera && !window.netscape)
                        {
                            realCellIndex2 = RadGridNamespace.GetRealCellIndex(currentTableObject, this.MoveHeaderDivRefCell);
                        }

						if (!currentTableObject || !currentTableObject.Columns[realCellIndex1])
							return;

						if (!currentTableObject.Columns[realCellIndex1].Reorderable)
						{
							return;
						}

                        
						currentTableObject.SwapColumns(realCellIndex1, realCellIndex2, (this.ClientSettings.ColumnsReorderMethod != "Reorder"));
						
	                    if(this.ClientSettings.ColumnsReorderMethod == "Reorder")
	                    {
		                    if ((!this.ClientSettings.ReorderColumnsOnClient) &&
			                    (this.ClientSettings.PostBackReferences.PostBackColumnsReorder != ""))
		                    {
			                    eval(this.ClientSettings.PostBackReferences.PostBackColumnsReorder);
		                    }
                        }
					}
				}
				else if (RadGridNamespace.CheckParentNodesFor(currentDragElement, this.GroupPanelControl))
				{
					if ((this.ClientSettings.PostBackReferences.PostBackGroupByColumn != "") &&
						(this.ClientSettings.AllowDragToGroup))
					{
						var currentTableObject =  this.GetTableObjectByID(this.MoveHeaderDivRefCell.parentNode.parentNode.parentNode.id);

                        var realCellIndex = this.MoveHeaderDivRefCell.cellIndex;
                        if(window.attachEvent && !window.opera && !window.netscape)
                        {
                            realCellIndex = RadGridNamespace.GetRealCellIndex(currentTableObject, this.MoveHeaderDivRefCell);
                        }

						var realColumnIndex = currentTableObject.Columns[realCellIndex].RealIndex;
						
						if (currentTableObject.Columns[realCellIndex].Groupable)
						{
							if (currentTableObject == this.MasterTableViewHeader)
							{
								this.SavePostData("GroupByColumn", this.MasterTableView.ClientID, realColumnIndex);
							}
							else
							{
								this.SavePostData("GroupByColumn", currentTableObject.ClientID, realColumnIndex);
							}

							
							eval(this.ClientSettings.PostBackReferences.PostBackGroupByColumn);
						}
					}
				}
			}
		}
	}
	
};

RadGridNamespace.GetRealCellIndex = function(tableView, cell)
{
    for(var i = 0; i < tableView.Columns.length; i++)
    {
        if(tableView.Columns[i].Control == cell)
        {
            return i;
        }
    }
};

RadGridNamespace.RadGrid.prototype.CreateReorderIndicators = function (currentDragElement)
{
	if ((this.ReorderIndicator1 == null) && (this.ReorderIndicator2 == null))
	{
		var currentTable = this.MoveHeaderDivRefCell.parentNode.parentNode.parentNode;
		var currentTableObject = this.GetTableObjectByID(currentTable.id);
		var headerRow = currentTableObject.HeaderRow;

		if (!RadGridNamespace.IsChildOf(currentDragElement, headerRow))
			return;

		this.ReorderIndicator1 = document.createElement("span"); 
		this.ReorderIndicator2 = document.createElement("span"); 

		this.ReorderIndicator1.innerHTML = "&darr;"; 
		this.ReorderIndicator2.innerHTML = "&uarr;"; 

		this.ReorderIndicator1.style.backgroundColor = "transparent";
		this.ReorderIndicator1.style.color = "darkblue";
		this.ReorderIndicator1.style.font = "bold 18px Arial";

		this.ReorderIndicator2.style.backgroundColor = this.ReorderIndicator1.style.backgroundColor;
		this.ReorderIndicator2.style.color = this.ReorderIndicator1.style.color;
		this.ReorderIndicator2.style.font = this.ReorderIndicator1.style.font;

		this.ReorderIndicator1.style.top = RadGridNamespace.FindPosY(currentDragElement) - this.ReorderIndicator1.offsetHeight + "px";
		this.ReorderIndicator1.style.left = RadGridNamespace.FindPosX(currentDragElement) + "px";

		this.ReorderIndicator2.style.top = RadGridNamespace.FindPosY(currentDragElement) + currentDragElement.offsetHeight + "px";
		this.ReorderIndicator2.style.left = this.ReorderIndicator1.style.left;

		this.ReorderIndicator1.style.visibility = "hidden";
		this.ReorderIndicator1.style.display = "none";
		this.ReorderIndicator1.style.position = "absolute";

		this.ReorderIndicator2.style.visibility = this.ReorderIndicator1.style.visibility;
		this.ReorderIndicator2.style.display = this.ReorderIndicator1.style.display;
		this.ReorderIndicator2.style.position = this.ReorderIndicator1.style.position;

		document.body.appendChild(this.ReorderIndicator1);
		document.body.appendChild(this.ReorderIndicator2);
	}
};

RadGridNamespace.RadGrid.prototype.DestroyReorderIndicators = function ()
{
	if ((this.ReorderIndicator1 != null) && (this.ReorderIndicator2 != null))
	{
		document.body.removeChild(this.ReorderIndicator1);
		document.body.removeChild(this.ReorderIndicator2);

		this.ReorderIndicator1 = null; 
		this.ReorderIndicator2 = null; 
	}
};

RadGridNamespace.RadGrid.prototype.MoveReorderIndicators = function (e, currentDragElement)
{
	if ((this.ReorderIndicator1 != null) && (this.ReorderIndicator2 != null))
	{
		this.ReorderIndicator1.style.visibility = "visible";
		this.ReorderIndicator1.style.display = "";

		this.ReorderIndicator2.style.visibility = "visible";
		this.ReorderIndicator2.style.display = "";
		
		this.ReorderIndicator1.style.top = RadGridNamespace.FindPosY(currentDragElement) - 
										RadGridNamespace.FindScrollPosY(currentDragElement) + 
										document.documentElement.scrollTop + 
										document.body.scrollTop - currentDragElement.offsetHeight + "px";

		this.ReorderIndicator1.style.left = RadGridNamespace.FindPosX(currentDragElement) - 
										RadGridNamespace.FindScrollPosX(currentDragElement) + 
										document.documentElement.scrollLeft + 
										document.body.scrollLeft + "px";

		if (parseInt(this.ReorderIndicator1.style.left) < RadGridNamespace.FindPosX(this.Control))
		{
			this.ReorderIndicator1.style.left = RadGridNamespace.FindPosX(this.Control) + 5;
		}

		this.ReorderIndicator2.style.top = parseInt(this.ReorderIndicator1.style.top) + currentDragElement.offsetHeight * 2 + "px";
		this.ReorderIndicator2.style.left = this.ReorderIndicator1.style.left;
	}	
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY

RadGridNamespace.RadGrid.prototype.AttachDomEvents = function()
{
	try
	{
		this.AttachDomEvent(this.Control, "mousemove", "OnMouseMove");
		this.AttachDomEvent(document, "keydown", "OnKeyDown");
		this.AttachDomEvent(document, "keyup", "OnKeyUp");
		this.AttachDomEvent(this.Control, "click", "OnClick");
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError, this.OnError);
	}
};

RadGridNamespace.RadGrid.prototype.OnMouseMove = function(e)
{
	try
	{
		var currentElement = RadGridNamespace.GetCurrentElement(e);

		if (this.ClientSettings.Resizing.AllowRowResize)
		{
			this.DetectResizeCursorsOnRows(e,currentElement);
			this.MoveRowResizer(e);
		}
		
		if ((this.ClientSettings.AllowDragToGroup) || 
			(this.ClientSettings.AllowColumnsReorder))
		{
			this.HandleDragAndDrop(e,currentElement);
		}
	}
	catch(error)
	{
		return false;
		//new RadGridNamespace.Error(error, this, this.OnError, this.OnError);
	}
};

RadGridNamespace.RadGrid.prototype.OnKeyDown = function(e)
{
	var MyEvent = 
	{
		KeyCode			: e.keyCode,
		IsShiftPressed	: e.shiftKey,
		IsCtrlPressed	: e.ctrlKey, 
		IsAltPressed	: e.altKey, 
		Event			: e
	}

	if (!RadGridNamespace.FireEvent(this, "OnKeyPress", [MyEvent]))
		return;

	if (e.keyCode == 16) 
	{
		this.IsShiftPressed = true;
	}

	if (e.keyCode == 17) 
	{
		this.IsCtrlPressed = true;
	}

	if(this.ClientSettings.AllowKeyboardNavigation)
	{
		this.ActiveRow.HandleActiveRow(e);
	}
};

RadGridNamespace.RadGrid.prototype.OnClick = function (e)
{
};

RadGridNamespace.RadGrid.prototype.OnKeyUp = function (e)
{
	if (e.keyCode == 16) 
	{
		this.IsShiftPressed = false;
	}

	if (e.keyCode == 17) 
	{
		this.IsCtrlPressed = false;
	}
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY


// Row Resize
RadGridNamespace.RadGrid.prototype.DetectResizeCursorsOnRows = function (e, currentElement)
{
	try
	{
		var gridControl = this;

		if ((currentElement != null) && 
			(currentElement.tagName.toLowerCase() == "td"))
		{
			var currentTable =  currentElement.parentNode.parentNode.parentNode;
			var definedTable =  this.GetTableObjectByID(currentTable.id);

			if (definedTable != null)
			{

				if (definedTable.Columns != null)
				{
					if (definedTable.Columns[currentElement.cellIndex].ColumnType != "GridRowIndicatorColumn")
						return;
				}

				if (!definedTable.Control.tBodies[0])
					return;

				var currentRow = this.GetRowObjectByRealRow(definedTable,currentElement.parentNode);

				if (currentRow != null)
				{
					var positionY = RadGridNamespace.GetEventPosY(e);
					var startY = RadGridNamespace.FindPosY(currentElement);
					var endY = startY + currentElement.offsetHeight;

					this.ResizeTolerance = 5;

					var oldTitle = currentElement.title;

					if ((positionY > endY - this.ResizeTolerance) && 
						(positionY < endY + this.ResizeTolerance))
					{
						currentElement.style.cursor = "n-resize";
						
						currentElement.title = this.ClientSettings.ClientMessages.DragToResize;

						this.AttachDomEvent(currentElement, "mousedown", "OnResizeMouseDown");
					}
					else
					{
						currentElement.style.cursor = "default";
						currentElement.title = "";
						
						this.DetachDomEvent(currentElement, "mousedown", "OnResizeMouseDown");
					}
				}
			}
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};

RadGridNamespace.RadGrid.prototype.OnResizeMouseDown = function (e)
{
	this.CreateRowResizer(e);
	RadGridNamespace.ClearDocumentEvents();
	
	this.AttachDomEvent(document, "mouseup", "OnResizeMouseUp");
};

RadGridNamespace.RadGrid.prototype.OnResizeMouseUp = function (e)
{
	this.DetachDomEvent(document, "mouseup", "OnResizeMouseUp");
	
	this.DestroyRowResizerAndResizeRow(e, true);
	RadGridNamespace.RestoreDocumentEvents();
};

RadGridNamespace.RadGrid.prototype.CreateRowResizer = function (e)
{
	try
	{
		this.DestroyRowResizer();

		var currentElement = RadGridNamespace.GetCurrentElement(e);

		if ((currentElement != null) && (currentElement.tagName.toLowerCase() == "td"))
		{
			if (currentElement.cellIndex > 0)
			{
				var rowIndex = currentElement.parentNode.rowIndex;
				currentElement = currentElement.parentNode.parentNode.parentNode.rows[rowIndex].cells[0];
			}
			
			this.RowResizer = null;
			this.CellToResize = currentElement;

			var currentTable =  currentElement.parentNode.parentNode.parentNode;
			var definedTable =  this.GetTableObjectByID(currentTable.id);

			this.RowResizer = document.createElement("div");
			this.RowResizer.style.backgroundColor = "navy";
			this.RowResizer.style.height = "1px";
			this.RowResizer.style.fontSize = "1";
			this.RowResizer.style.position = "absolute";
			this.RowResizer.style.cursor = "n-resize";

			if (definedTable != null)
			{
				this.RowResizerRefTable = definedTable;

				if (this.GridDataDiv)
				{
					this.RowResizer.style.left = RadGridNamespace.FindPosX(this.GridDataDiv) + "px";

					var tmpWidth = (RadGridNamespace.FindPosX(this.GridDataDiv) + 
						this.GridDataDiv.offsetWidth) - parseInt(this.RowResizer.style.left);

					if (tmpWidth > definedTable.Control.offsetWidth)
					{
						this.RowResizer.style.width = definedTable.Control.offsetWidth + "px";
					}
					else
					{
						this.RowResizer.style.width = tmpWidth + "px";
					}

					if (parseInt(this.RowResizer.style.width) > this.GridDataDiv.offsetWidth)
					{
						this.RowResizer.style.width = this.GridDataDiv.offsetWidth + "px";
					}
				}
				else
				{
					this.RowResizer.style.width = definedTable.Control.offsetWidth + "px";
					this.RowResizer.style.left = RadGridNamespace.FindPosX(currentElement) + "px";
				}
				
			}

			this.RowResizer.style.top = RadGridNamespace.GetEventPosY(e) - 
						(RadGridNamespace.GetEventPosY(e) - e.clientY) + 
						document.body.scrollTop + 
						document.documentElement.scrollTop + "px";


			var parentElem = document.body;
			parentElem.appendChild(this.RowResizer);
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};

RadGridNamespace.RadGrid.prototype.DestroyRowResizerAndResizeRow = function (e, shouldDestroy)
{
	try
	{
		if ((this.CellToResize != "undefined") &&
			(this.CellToResize != null) &&
			(this.CellToResize.tagName.toLowerCase() == "td") &&
			(this.RowResizer != "undefined") && 
			(this.RowResizer != null))
		{
			var newHeight;
			if (this.GridDataDiv)
			{
				newHeight = parseInt(this.RowResizer.style.top) + this.GridDataDiv.scrollTop - (RadGridNamespace.FindPosY(this.CellToResize));
			}
			else
			{
				newHeight = parseInt(this.RowResizer.style.top) - (RadGridNamespace.FindPosY(this.CellToResize));
			}

			if (newHeight > 0)
			{
				var currentTable =  this.CellToResize.parentNode.parentNode.parentNode;
				var definedTable =  this.GetTableObjectByID(currentTable.id);

				if (definedTable != null)
				{
					
					definedTable.ResizeRow(this.CellToResize.parentNode.rowIndex, newHeight);
				}
			}
		}
		
		if (shouldDestroy)
		{
			this.DestroyRowResizer();
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};

RadGridNamespace.RadGrid.prototype.DestroyRowResizer = function ()
{
	try
	{
		if ((this.RowResizer != "undefined") && 
			(this.RowResizer != null) &&
			(this.RowResizer.parentNode != null))
		{
			var parentElem = this.RowResizer.parentNode;
			parentElem.removeChild(this.RowResizer);
			this.RowResizer = null;
			this.RowResizerRefTable = null;
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};

RadGridNamespace.RadGrid.prototype.MoveRowResizer = function (e)
{
	try
	{
		if ((this.RowResizer != "undefined") &&
			(this.RowResizer != null) &&
			(this.RowResizer.parentNode != null))
		{		
			this.RowResizer.style.top = RadGridNamespace.GetEventPosY(e) - 
						(RadGridNamespace.GetEventPosY(e) - e.clientY) + 
						document.body.scrollTop + 
						document.documentElement.scrollTop + "px";
						
			if (this.ClientSettings.Resizing.EnableRealTimeResize)
			{
				this.DestroyRowResizerAndResizeRow(e, false);
				this.UpdateRowResizerWidth(e);
			}
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};

RadGridNamespace.RadGrid.prototype.UpdateRowResizerWidth = function (e)
{
	var currentElement = RadGridNamespace.GetCurrentElement(e);

	if ((currentElement != null) && (currentElement.tagName.toLowerCase() == "td"))
	{
		var definedTable =  this.RowResizerRefTable;

		if (definedTable != null)
		{
			if (this.GridDataDiv)
			{
				var tmpWidth = (RadGridNamespace.FindPosX(this.GridDataDiv) + 
					this.GridDataDiv.offsetWidth) - parseInt(this.RowResizer.style.left);

				if (tmpWidth > definedTable.Control.offsetWidth)
				{
					this.RowResizer.style.width = definedTable.Control.offsetWidth + "px";
				}
				else
				{
					this.RowResizer.style.width = tmpWidth + "px";
				}

				if (parseInt(this.RowResizer.style.width) > this.GridDataDiv.offsetWidth)
				{
					this.RowResizer.style.width = this.GridDataDiv.offsetWidth + "px";
				}
			}
			else
			{
				this.RowResizer.style.width = definedTable.Control.offsetWidth + "px";
			}
		}
	}
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY
RadGridNamespace.RadGrid.prototype.SetHeaderAndFooterDivsWidth = function()
{
    if((document.compatMode == "BackCompat" && navigator.userAgent.toLowerCase().indexOf("msie") != -1)
		||
		(navigator.userAgent.toLowerCase().indexOf("msie") != -1 && navigator.userAgent.toLowerCase().indexOf("6.0") != -1))
    {
		if (this.ClientSettings.Scrolling.UseStaticHeaders)
		{
			if (this.GridHeaderDiv != null && this.GridDataDiv != null && this.GridHeaderDiv != null)
			{
				this.GridHeaderDiv.style.width = "100%";
				if(this.GridHeaderDiv && this.GridDataDiv)
				{
					if(this.GridDataDiv.offsetWidth > 0)
					{
						this.GridHeaderDiv.style.width = this.GridDataDiv.offsetWidth - RadGridNamespace.GetScrollBarWidth() + "px";
					}
				}
				if(this.GridHeaderDiv && this.GridFooterDiv)
				{
					this.GridFooterDiv.style.width = this.GridHeaderDiv.style.width;
				}
			}
        }
    }

	if (this.ClientSettings.Scrolling.AllowScroll && this.ClientSettings.Scrolling.UseStaticHeaders)
	{
        var isRtl = RadGridNamespace.IsParentRightToLeft(this.GridHeaderDiv);
        
        if((!isRtl && this.GridHeaderDiv && 
            parseInt(this.GridHeaderDiv.style.marginRight) != RadGridNamespace.GetScrollBarWidth()) 
            ||
            (isRtl && this.GridHeaderDiv && 
            parseInt(this.GridHeaderDiv.style.marginLeft) != RadGridNamespace.GetScrollBarWidth()))
        {
            if(!isRtl)
            {
                this.GridHeaderDiv.style.marginRight = RadGridNamespace.GetScrollBarWidth() + "px";
                this.GridHeaderDiv.style.marginLeft = "";
            }
            else
            {
                this.GridHeaderDiv.style.marginLeft = RadGridNamespace.GetScrollBarWidth() + "px";
                this.GridHeaderDiv.style.marginRight = "";
            }
	    }
	    
	    if(this.GridHeaderDiv && this.GridDataDiv)
	    {
	        if(this.GridDataDiv.clientWidth > 0 && (this.GridDataDiv.clientWidth == this.GridDataDiv.offsetWidth))
	        {
	            this.GridHeaderDiv.style.width = "100%";
                if(!isRtl)
                {
                    this.GridHeaderDiv.style.marginRight = "";
                }
                else
                {
                    this.GridHeaderDiv.style.marginLeft = "";
                }
	        }
	    }

	    if(this.GroupPanelObject && this.GroupPanelObject.Items.length > 0 && navigator.userAgent.toLowerCase().indexOf("msie") != -1)
	    {
	        if(this.MasterTableView && this.MasterTableViewHeader)
	        {
	            this.MasterTableView.Control.style.width = this.MasterTableViewHeader.Control.offsetWidth + "px";
	        }
	    }
	    
	    if(this.GridFooterDiv)
	    {
	        this.GridFooterDiv.style.marginRight = this.GridHeaderDiv.style.marginRight;
	        this.GridFooterDiv.style.marginLeft = this.GridHeaderDiv.style.marginLeft;
	        this.GridFooterDiv.style.width = this.GridHeaderDiv.style.width;
	    }
    }
};

RadGridNamespace.RadGrid.prototype.SetDataDivHeight = function()
{
    if(this.GridDataDiv && this.Control.style.height != "")
    {
        var height = 0;
        if (this.GroupPanelObject)
        {
	        height += this.GroupPanelObject.Control.offsetHeight;
        }

        if (this.GridHeaderDiv)
        {
	        height += this.GridHeaderDiv.offsetHeight;
        }

        if (this.GridFooterDiv)
        {
	        height += this.GridFooterDiv.offsetHeight;
        }
        
        if (this.PagerControl)
        {
	        height += this.PagerControl.offsetHeight;
        }
 
        if (this.TopPagerControl)
        {
	        height += this.TopPagerControl.offsetHeight;
        }
       
        var newHeight = this.Control.clientHeight - height;
        
        if(newHeight > 0)
        {
            var oldPosition = this.Control.style.position;
            if(window.netscape)
            {
                this.Control.style.position = "absolute";
            }
            
            this.GridDataDiv.style.height = this.Control.clientHeight - height + "px";
            
            if(window.netscape)
            {
                this.Control.style.position = oldPosition;
            }
        }
    }
};

RadGridNamespace.RadGrid.prototype.InitializeDimensions = function()
{
	try
	{
        var thisObject = this;

	    this.InitializeAutoLayout();
	    
	    if(!this.EnableAJAX)
	    {
            this.OnWindowResize();
        }
        else
        {
            var resizeAction = function(){
                thisObject.OnWindowResize();
            };
            
            if (window.netscape && !window.opera)
				resizeAction();
			else
				setTimeout(resizeAction, 0);
        }
        
        //if(window.netscape || (navigator.userAgent.toLowerCase().indexOf("msie") != -1 && navigator.userAgent.toLowerCase().indexOf("6.0") != -1))
        {
            this.Control.RadResize = function(){thisObject.OnWindowResize();};
        }

        if(navigator.userAgent.toLowerCase().indexOf("msie") != -1)
        {
            setTimeout(function(){
                thisObject.AttachDomEvent(window, "resize", "OnWindowResize");
            }, 0);
        }
        else
        {
            this.AttachDomEvent(window, "resize", "OnWindowResize");
        }
        
        this.Control.RadShow = function(){thisObject.OnWindowResize();};
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};

RadGridNamespace.RadGrid.prototype.OnWindowResize = function(e)
{
    this.SetHeaderAndFooterDivsWidth();
    this.SetDataDivHeight();
};

RadGridNamespace.RadGrid.prototype.InitializeAutoLayout = function()
{
	if (this.ClientSettings.Scrolling.AllowScroll && this.ClientSettings.Scrolling.UseStaticHeaders)
	{
	    if(this.MasterTableView && this.MasterTableViewHeader)
        {
            if(this.MasterTableView.TableLayout != "Auto" || window.netscape || window.opera)
                return;

            this.MasterTableView.Control.style.tableLayout = this.MasterTableViewHeader.Control.style.tableLayout = "";
            
            var firstDataRow = this.MasterTableView.Control.tBodies[0].rows[this.ClientSettings.FirstDataRowClientRowIndex];

            for (var i = 0; i < this.MasterTableViewHeader.HeaderRow.cells.length; i++)
            {
                var col = this.MasterTableViewHeader.ColGroup.Cols[i];

                if(col.width != "")
                    continue;

                var width1 = this.MasterTableViewHeader.HeaderRow.cells[i].offsetWidth;
                
                var width2 = firstDataRow.cells[i].offsetWidth;
                
                var width = (width1 > width2)? width1 : width2;
                
 		        if (this.MasterTableViewFooter && this.MasterTableViewFooter.Control)
		        {
			        if (this.MasterTableViewFooter.Control.tBodies[0].rows[0] &&
			            this.MasterTableViewFooter.Control.tBodies[0].rows[0].cells[i])
			        {
			           if(this.MasterTableViewFooter.Control.tBodies[0].rows[0].cells[i].offsetWidth > width)
			           {
					        width = this.MasterTableViewFooter.Control.tBodies[0].rows[0].cells[i].offsetWidth;
					   }
			        }
		        }

                if(width <= 0)
                    continue;

                this.MasterTableViewHeader.HeaderRow.cells[i].style.width = 
                firstDataRow.cells[i].style.width = 
                this.MasterTableView.ColGroup.Cols[i].width = 
                col.width = width;
                
		        if (this.MasterTableViewFooter && this.MasterTableViewFooter.Control)
		        {
			        if (this.MasterTableViewFooter.Control.tBodies[0].rows[0] &&
			            this.MasterTableViewFooter.Control.tBodies[0].rows[0].cells[i])
			        {
					   this.MasterTableViewFooter.Control.tBodies[0].rows[0].cells[i].style.width = width;
			        }
		        }
            }

            this.MasterTableView.Control.style.tableLayout =  this.MasterTableViewHeader.Control.style.tableLayout = "fixed";

            if (this.MasterTableViewFooter && this.MasterTableViewFooter.Control)
	        {
                this.MasterTableViewFooter.Control.style.tableLayout = "fixed";
	        }

            if(window.netscape)
            {
                this.OnWindowResize();;
            }
        }
	}
};

RadGridNamespace.RadGrid.prototype.InitializeSaveScrollPosition = function()
{
	if (!this.ClientSettings.Scrolling.SaveScrollPosition || 
			this.ClientSettings.Scrolling.EnableAJAXScrollPaging)
		return;
	
	if (this.ClientSettings.Scrolling.ScrollTop != "")
	{
		this.GridDataDiv.scrollTop = this.ClientSettings.Scrolling.ScrollTop;
	}

	if (this.ClientSettings.Scrolling.ScrollLeft != "")
	{
		if(this.GridHeaderDiv)
		{
			this.GridHeaderDiv.scrollLeft = this.ClientSettings.Scrolling.ScrollLeft;
		}
		
		if(this.GridFooterDiv)
		{
			this.GridFooterDiv.scrollLeft = this.ClientSettings.Scrolling.ScrollLeft;
		}

		this.GridDataDiv.scrollLeft = this.ClientSettings.Scrolling.ScrollLeft;
	}
}

RadGridNamespace.RadGrid.prototype.InitializeAjaxScrollPaging = function()
{
	if(!this.ClientSettings.Scrolling.EnableAJAXScrollPaging)
		return;
	
	this.ScrollCounter = 0;
	this.CurrentAJAXScrollTop = 0;

	if (this.ClientSettings.Scrolling.AJAXScrollTop != "")
	{
		this.CurrentAJAXScrollTop = this.ClientSettings.Scrolling.AJAXScrollTop;
	}

	var pixelsBefore = this.CurrentPageIndex * this.MasterTableView.PageSize * 20;
	var totalPixels = this.MasterTableView.PageCount * this.MasterTableView.PageSize * 20;
	
	var masterTable = this.MasterTableView.Control;
	var tableHeight = masterTable.offsetHeight;
		
	if (!window.opera)
	{
		masterTable.style.marginTop = pixelsBefore + "px";
		masterTable.style.marginBottom = totalPixels - pixelsBefore - tableHeight + "px";
	}
	else
	{
		//opera does not posisition the table properly when you set marginTop
		//the current code still has problems -- the scroll position is incorrect, 
		//but you can still scroll to the desired page and the tooltip shows correct data.
		masterTable.style.position = "relative";
		masterTable.style.top = pixelsBefore + "px";
		masterTable.style.marginBottom = totalPixels - tableHeight + "px";
	}
	
	this.CurrentAJAXScrollTop = pixelsBefore;
	this.GridDataDiv.scrollTop = pixelsBefore;
	
	this.CreateScrollerToolTip();
	this.AttachDomEvent(this.GridDataDiv, "scroll", "OnAJAXScroll");
}

RadGridNamespace.RadGrid.prototype.CreateScrollerToolTip = function()
{
	var scrollerToolTip = document.getElementById(this.ClientID + "ScrollerToolTip");
	if (!scrollerToolTip)
	{
		this.ScrollerToolTip = document.createElement("span");
		this.ScrollerToolTip.id = this.ClientID + "ScrollerToolTip";
		this.ScrollerToolTip.style.backgroundColor = "#F5F5DC";
		this.ScrollerToolTip.style.border = "1px solid";
		this.ScrollerToolTip.style.position = "absolute";
		this.ScrollerToolTip.style.display = "none";
		this.ScrollerToolTip.style.font = "icon";
		this.ScrollerToolTip.style.padding = "2";
		document.body.appendChild(this.ScrollerToolTip);
	}
}

RadGridNamespace.RadGrid.prototype.HideScrollerToolTip = function()
{
	var gridControl = this;
	setTimeout(function(){
		var scrollerToolTip = document.getElementById(gridControl.ClientID + "ScrollerToolTip");
		if (scrollerToolTip && scrollerToolTip.parentNode)
		{
			scrollerToolTip.style.display = "none";
		}
	}, 200);
}

RadGridNamespace.RadGrid.prototype.ShowScrollerTooltip = function(scrollFraction, newPageIndex)
{
	var scrollerToolTip = document.getElementById(this.ClientID + "ScrollerToolTip");
	if (scrollerToolTip)
	{
		scrollerToolTip.style.display = "";
		scrollerToolTip.style.top =  parseInt(RadGridNamespace.FindPosY(this.GridDataDiv)) + Math.round(this.GridDataDiv.offsetHeight * scrollFraction) + document.documentElement.scrollTop + document.body.scrollTop - 25 + "px";
		scrollerToolTip.style.left = parseInt(RadGridNamespace.FindPosX(this.GridDataDiv)) + this.GridDataDiv.offsetWidth - (this.GridDataDiv.offsetWidth - this.GridDataDiv.clientWidth) - scrollerToolTip.offsetWidth + "px";
		scrollerToolTip.innerHTML = "Page: <b>" + ((newPageIndex == 0)? 1 : newPageIndex + 1) + "</b> out of <b>" + this.MasterTableView.PageCount + "</b> pages";
	}
}

RadGridNamespace.RadGrid.prototype.InitializeScroll = function ()
{
	var gridControl = this;

	var grid = this;
	var setupScroll = function()
	{
		grid.InitializeSaveScrollPosition();
	}
	
	if (window.netscape && !window.opera)
	{
		//something's resetting our scroll position after we set it up
		//solving the issue by delaying the operation a bit
		window.setTimeout(setupScroll, 0);
	}
	else
	{
		setupScroll();
	}
	
	this.InitializeAjaxScrollPaging();

	this.AttachDomEvent(this.GridDataDiv, "scroll", "OnGridScroll");
};

RadGridNamespace.RadGrid.prototype.OnGridScroll = function(e)
{
	if (this.ClientSettings.Scrolling.UseStaticHeaders)
	{
		if (this.GridHeaderDiv)
		{
			this.GridHeaderDiv.scrollLeft = this.GridDataDiv.scrollLeft;
		}

		if (this.GridFooterDiv)
		{
			this.GridFooterDiv.scrollLeft = this.GridDataDiv.scrollLeft;
		}
	}

	this.SavePostData("ScrolledControl", this.ClientID, this.GridDataDiv.scrollTop, this.GridDataDiv.scrollLeft);	

	var evt = {};
	evt.ScrollTop = this.GridDataDiv.scrollTop;
	evt.ScrollLeft = this.GridDataDiv.scrollLeft;
	evt.ScrollControl = this.GridDataDiv;
	evt.IsOnTop = (this.GridDataDiv.scrollTop == 0)? true : false;
	evt.IsOnBottom = ((this.GridDataDiv.scrollHeight - this.GridDataDiv.offsetHeight + 16) == this.GridDataDiv.scrollTop)? true : false;

	RadGridNamespace.FireEvent(this, "OnScroll", [evt]);
};

RadGridNamespace.RadGrid.prototype.OnAJAXScroll = function(e)
{
	if (this.GridDataDiv)
	{
		this.CurrentScrollTop = this.GridDataDiv.scrollTop;
	}

	this.ScrollCounter++;

	var gridControl = this;
	RadGridNamespace.AJAXScrollHanlder = function(count)
	{
		if (gridControl.ScrollCounter != count)
			return;

		if (gridControl.CurrentAJAXScrollTop != gridControl.GridDataDiv.scrollTop)
		{
			if(gridControl.CurrentPageIndex == newPageIndex)
				return;
			var clientID = gridControl.ClientID;
			var masterClientID = gridControl.MasterTableView.ClientID;
			gridControl.SavePostData("AJAXScrolledControl", gridControl.GridDataDiv.scrollLeft, gridControl.LastScrollTop, gridControl.GridDataDiv.scrollTop, newPageIndex);

			var postBackFunc = gridControl.ClientSettings.PostBackFunction;
			
			postBackFunc = postBackFunc.replace("{0}", gridControl.UniqueID);
			eval(postBackFunc);
		}

		gridControl.ScrollCounter = 0;
		
		gridControl.HideScrollerToolTip();
	};

	var evt = {};
	evt.ScrollTop = this.GridDataDiv.scrollTop;
	evt.ScrollLeft = this.GridDataDiv.scrollLeft;
	evt.ScrollControl = this.GridDataDiv;
	evt.IsOnTop = (this.GridDataDiv.scrollTop == 0)? true : false;
	evt.IsOnBottom = ((this.GridDataDiv.scrollHeight - this.GridDataDiv.offsetHeight + 16) == this.GridDataDiv.scrollTop)? true : false;

	RadGridNamespace.FireEvent(this, "OnScroll", [evt]);

	var scrollFraction = this.GridDataDiv.scrollTop / (this.GridDataDiv.scrollHeight - this.GridDataDiv.offsetHeight + 16);
	var newPageIndex = Math.round((this.MasterTableView.PageCount - 1) * scrollFraction);
	
	setTimeout("RadGridNamespace.AJAXScrollHanlder(" + this.ScrollCounter + ")", 500);
	this.ShowScrollerTooltip(scrollFraction, newPageIndex);
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY
RadGridNamespace.RadGridTable = function(object)
{
	if ((!object) || typeof(object) != "object")
		return;

	//properties initialization
	for (var member in object)
	{
		this[member] = object[member];
	}

	this.Type = "RadGridTable";
	this.ServerID = this.ID;
	//this.ID = this.ClientID;

	//collections
	this.SelectedRows = new Array();
	this.SelectedCells = new Array();
	this.SelectedColumns = new Array();
	this.ExpandCollapseColumns = new Array();
	this.GroupSplitterColumns = new Array();

	this.HeaderRow = null;
};

RadGridNamespace.RadGridTable.prototype._constructor = function(owner)
{
	if ((!owner) || typeof(owner) != "object")
		return;

	this.Control = document.getElementById(this.ClientID);
	
	if (!this.Control)
		return;
	
	this.ColGroup = RadGridNamespace.GetTableColGroup(this.Control);

	if (!this.ColGroup)
		return;

	this.ColGroup.Cols = RadGridNamespace.GetTableColGroupCols(this.ColGroup);

	//additional properties
	this.Owner = owner;
	
	//events initialization
	this.InitializeEvents(this.Owner.ClientSettings.ClientEvents);


	//this.Control.style.tableLayout = ((this.Owner.ClientSettings.Resizing.ClipCellContentOnResize && ((this.Owner.ClientSettings.Resizing.AllowColumnResize)||(this.Owner.ClientSettings.Resizing.AllowRowResize))) || (this.Owner.ClientSettings.Scrolling.AllowScroll && this.Owner.ClientSettings.Scrolling.UseStaticHeaders))? "fixed" : "auto";
	this.Control.style.overflow = ((this.Owner.ClientSettings.Resizing.ClipCellContentOnResize && ((this.Owner.ClientSettings.Resizing.AllowColumnResize)||(this.Owner.ClientSettings.Resizing.AllowRowResize))) || (this.Owner.ClientSettings.Scrolling.AllowScroll && this.Owner.ClientSettings.Scrolling.UseStaticHeaders))? "hidden" : "";
    
    if(navigator.userAgent.toLowerCase().indexOf("msie") != -1 && this.Control.style.tableLayout == "fixed" && this.Control.style.width.indexOf("%") != -1)
    {
        this.Control.style.width = "";
    }

	this.CreateStyles();

	if (this.Owner.ClientSettings.Scrolling.AllowScroll && this.Owner.ClientSettings.Scrolling.UseStaticHeaders)
	{
		if(this.ClientID.indexOf("_Header") != -1 || this.ClientID.indexOf("_Detail") != -1)
		{
			this.Columns = this.GetTableColumns(this.Control, this.RenderColumns);
		}
		else
		{
			this.Columns = this.Owner.MasterTableViewHeader.Columns;
			this.ExpandCollapseColumns =  this.Owner.MasterTableViewHeader.ExpandCollapseColumns;
			this.GroupSplitterColumns = this.Owner.MasterTableViewHeader.GroupSplitterColumns;
		}
	}
	else
	{
		this.Columns = this.GetTableColumns(this.Control, this.RenderColumns);
	}

	if (this.Owner.ClientSettings.ShouldCreateRows)
	{
		this.InitializeRows(this.Controls[0].Rows);
	}
};

RadGridNamespace.RadGridTable.prototype.Dispose = function()
{	
	if(this.ColGroup && this.ColGroup.Cols)
	{
    	this.ColGroup.Cols = null;
    	this.ColGroup = null;
    }

	this.Owner = null;
	
	this.DisposeEvents();

	this.ExpandCollapseColumns =  null;
	this.GroupSplitterColumns = null;
	
	this.DisposeRows();
	this.DisposeColumns();
	this.RenderColumns = null;
	
	this.SelectedRows = null;
	this.ExpandCollapseColumns = null;
	
	this.DetailTables = null;
	this.DetailTablesCollection = null;
	
	this.Control = null;
	this.HeaderRow = null;
}

RadGridNamespace.RadGridTable.prototype.CreateStyles = function()
{
	if (!this.SelectedItemStyleClass || this.SelectedItemStyleClass == "")
	{
		if (this.SelectedItemStyle && this.SelectedItemStyle != "")
		{
			RadGridNamespace.AddRule(this.Owner.GridStyleSheet,".SelectedItemStyle" + this.ClientID + "1 td",this.SelectedItemStyle);
		}
		else
		{
			RadGridNamespace.AddRule(this.Owner.GridStyleSheet,".SelectedItemStyle" + this.ClientID + "2 td","background-color:Navy;color:White;");
		}
	}
	
	var overflow = ((this.Owner.ClientSettings.Resizing.ClipCellContentOnResize && ((this.Owner.ClientSettings.Resizing.AllowColumnResize)||(this.Owner.ClientSettings.Resizing.AllowRowResize))) || (this.Owner.ClientSettings.Scrolling.AllowScroll && this.Owner.ClientSettings.Scrolling.UseStaticHeaders))? "hidden" : ""
	if (overflow == "hidden")
	{
		RadGridNamespace.addClassName(this.Control, "grid" + this.ClientID);

		if (window.netscape)
		{
			RadGridNamespace.AddRule(this.Owner.GridStyleSheet , ".grid" + this.ClientID + " td", "overflow: hidden;-moz-user-select:none;" );
			//if(this == this.Owner.MasterTableViewHeader)
			{
				//alert(this.ClientID);
				RadGridNamespace.AddRule(this.Owner.GridStyleSheet , ".grid" + this.ClientID + " th", "overflow: hidden;-moz-user-select:none;" );
			}
		}
		else
		{
			RadGridNamespace.AddRule(this.Owner.GridStyleSheet , ".grid" + this.ClientID + " td", "overflow: hidden; text-overflow: ellipsis;" );
			RadGridNamespace.AddRule(this.Owner.GridStyleSheet , ".grid" + this.ClientID + " th", "overflow: hidden; text-overflow: ellipsis;" );
		}
	}
};

RadGridNamespace.RadGridTable.prototype.InitializeEvents = function(clientEvents)
{
	for (clientEvent in clientEvents)
	{
        if (typeof(clientEvents[clientEvent]) != "string")
            continue;
		if (!this.Owner.IsClientEventName(clientEvent))
		{
			if (clientEvents[clientEvent] != "")
			{
				var handlerString = clientEvents[clientEvent];

				if (handlerString.indexOf("(") != -1)
				{
					// function call
					this[clientEvent] = handlerString;
				}
				else
				{
					// function reference
					this[clientEvent] = eval(handlerString);
				}
			}
			else
			{
				this[clientEvent] = null;
			}
		}
	}
};

RadGridNamespace.RadGridTable.prototype.DisposeEvents = function()
{
	for (var clientEvent in RadGridNamespace.RadGridTable.ClientEventNames)
	{				
		this[clientEvent] = null;
	}
}

RadGridNamespace.RadGridTable.prototype.InitializeRows = function(rows)
{
	if(this.ClientID.indexOf("_Header") != -1 || this.ClientID.indexOf("_Footer") != -1)
		return;

	try
	{
		var rowCollection = [];
		for (var i = 0; i < rows.length; i++)
		{
			if(!rows[i].Visible || rows[i].ClientRowIndex < 0)
				continue;

			if(rows[i].ItemType == "THead" || rows[i].ItemType == "TFoot")
				continue;

			RadGridNamespace.FireEvent(this, "OnRowCreating");

		    rows[i]._constructor(this);
		    
		    rowCollection[rowCollection.length] = rows[i];

			RadGridNamespace.FireEvent(this, "OnRowCreated",[rows[i]]);
		}
		
		this.Rows = rowCollection;
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.DisposeRows = function()
{
	if (this.Rows != null)
	{
		for (var i = 0; i < this.Rows.length; i++)
		{
			var row = this.Rows[i];
			row.Dispose();
		}
		
		this.Rows = null;
	}
}

RadGridNamespace.RadGridTable.prototype.DisposeColumns = function()
{
	if (this.Columns != null)
	{
		for (var i = 0; i < this.Columns.length; i++)
		{
			var column = this.Columns[i];
			column.Dispose();
		}
		
		this.Columns = null;	
	}
}

RadGridNamespace.RadGridTable.prototype.GetTableRows = function(table, tableItems)
{
	if(this.ClientID.indexOf("_Header") != -1 || this.ClientID.indexOf("_Footer") != -1)
		return;

	try
	{
		var tableRows = new Array();
		var j = 0;

		for (var i = 0; i < tableItems.length; i++)
		{
			if ((tableItems[i].ItemType == "THead") ||
				(tableItems[i].ItemType == "TFoot"))
				continue;

			if ((tableItems[i]) && (tableItems[i].Visible))
			{
				RadGridNamespace.FireEvent(this, "OnRowCreating");

				tableRows[tableRows.length] = tableItems[i]._constructor(this);

				//tableRows[j].RealIndex = i;

				RadGridNamespace.FireEvent(this, "OnRowCreated",[tableRows[j]]);

				j++;
			}
		}

		return tableRows;

	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.GetTableHeaderRow = function()
{
	try
	{
		if (this.Control.tHead)
		{
			for(var i=0;i<this.Control.tHead.rows.length;i++)
			{
				if (this.Control.tHead.rows[i] != null)
				{
					if (this.Control.tHead.rows[i].cells[0] != null)
					{
						if (this.Control.tHead.rows[i].cells[0].tagName != null)
						{
							if (this.Control.tHead.rows[i].cells[0].tagName.toLowerCase() == "th")
							{
								this.HeaderRow = this.Control.tHead.rows[i];
								break;
							}
						}
					}
				}
			}
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.GetTableColumns = function(table, columns)
{
	try
	{	
		this.GetTableHeaderRow();
		var tableColumns = new Array();

		if (!this.HeaderRow)
			return;

		if (!this.HeaderRow.cells[0])
			return;

		var j = 0;
		for (var i=0;i<columns.length;i++)
		{
			if(columns[i].Visible)
			{
				RadGridNamespace.FireEvent(this, "OnColumnCreating");

				tableColumns[tableColumns.length] = new RadGridNamespace.RadGridTableColumn(columns[i]);
				
				tableColumns[j]._constructor(this.HeaderRow.cells[j], this);

				tableColumns[j].RealIndex = i;

				if (columns[i].ColumnType == "GridExpandColumn")
				{
					this.ExpandCollapseColumns[this.ExpandCollapseColumns.length] = tableColumns[j];
				}

				if (columns[i].ColumnType == "GridGroupSplitterColumn")
				{
					this.GroupSplitterColumns[this.GroupSplitterColumns.length] = tableColumns[j];
				}

				RadGridNamespace.FireEvent(this, "OnColumnCreated", tableColumns[j]);

				j++;
			}
		}		
		return tableColumns; 
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.RemoveTableLayOut = function()
{
	this.masterTableLayOut = this.Owner.MasterTableView.Control.style.tableLayout;
	this.detailTablesTableLayOut = new Array();

	for(var i=0;i<this.Owner.DetailTablesCollection.length;i++)
	{
		this.detailTablesTableLayOut[this.detailTablesTableLayOut.length] =
			this.Owner.DetailTablesCollection[i].Control.style.tableLayout;
		this.Owner.DetailTablesCollection[i].Control.style.tableLayout = "";
	}
};

RadGridNamespace.RadGridTable.prototype.RestoreTableLayOut = function()
{
	this.Owner.MasterTableView.Control.style.tableLayout = this.masterTableLayOut;

	for(var i=0;i<this.Owner.DetailTablesCollection.length;i++)
	{
		this.Owner.DetailTablesCollection[i].Control.style.tableLayout = 
				this.detailTablesTableLayOut[i];
	}
};

/// FOR FUTURE VERSIONS
/*
RadGridNamespace.RadGridTable.prototype.MoveRow = function(sourceRowIndex, targetRowIndex)
{
	try
	{
		RadGridNamespace.FireEvent(this, "OnRowMoving");

		var table = this.Control;
		table.tBodies[0].moveRow(sourceRowIndex, targetRowIndex);

		RadGridNamespace.FireEvent(this, "OnRowMoved");
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.MoveRowUp = function(rowIndex)
{
	try
	{
		RadGridNamespace.FireEvent(this, "OnRowMoveingUp");

		var table = this.Control;
		var row = table.tBodies[0].rows[rowIndex];
		table.tBodies[0].rows[row.sectionRowIndex].swapNode(table.tBodies[0].rows[row.sectionRowIndex-1]); 

		RadGridNamespace.FireEvent(this, "OnRowMovedUp");
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.MoveRowDown = function(rowIndex)
{
	try
	{
		RadGridNamespace.FireEvent(this, "OnRowMovingDown");

		var table = this.Control;
		var row = table.tBodies[0].rows[rowIndex];
		table.tBodies[0].rows[row.sectionRowIndex].swapNode(table.tBodies[0].rows[row.sectionRowIndex+1]); 

		RadGridNamespace.FireEvent(this, "OnRowMovedDown");
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.SwapRows = function(sourceRowIndex, targetRowIndex)
{
	try
	{
		RadGridNamespace.FireEvent(this, "OnRowSwapping");

		var table = this.Control;
		var row1 = table.tBodies[0].rows[sourceRowIndex];
		var row2 = table.tBodies[0].rows[targetRowIndex];
		row1.swapNode(row2);

		RadGridNamespace.FireEvent(this, "OnRowSwapped");
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.DuplicateRow = function(rowIndex)
{
	try
	{
		RadGridNamespace.FireEvent(this, "OnRowDuplicating");

		var table = this.Control;
		var row = table.tBodies[0].rows[rowIndex];
		var parent = row.parentNode;
		parent.appendChild(row.cloneNode(true));
		
		RadGridNamespace.FireEvent(this, "OnRowDuplicated");
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};
*/
////////////////////////////////////////////////////////////////////////////////

RadGridNamespace.RadGridTable.prototype.SelectRow = function(row, singleSelect)
{
	try
	{
		if (!this.Owner.ClientSettings.Selecting.AllowRowSelect)
		return;

		var currentRow = this.Owner.GetRowObjectByRealRow(this, row);

		if (currentRow != null)
		{
			if(currentRow.ItemType == "Item" || currentRow.ItemType == "AlternatingItem")
			{
				currentRow.SetSelected(singleSelect);
			}
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.DeselectRow = function(row)
{
	try
	{
		if (!this.Owner.ClientSettings.Selecting.AllowRowSelect)
		return;

		var currentRow = this.Owner.GetRowObjectByRealRow(this, row);

		if (currentRow != null)
		{
			if(currentRow.ItemType == "Item" || currentRow.ItemType == "AlternatingItem")
			{
				this.RemoveFromSelectedRows(currentRow);
				currentRow.RemoveSelectedRowStyle();
				currentRow.Selected = false;
			}
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.ResizeRow = function(index, height, isDataRow)
{
	try
	{
		if (!this.Owner.ClientSettings.Resizing.AllowRowResize)
		return;

		if (!RadGridNamespace.FireEvent(this, "OnRowResizing", [index, height]))
			return;

		this.RemoveTableLayOut();
		var controlLayOut = this.Control.style.tableLayout;
		this.Control.style.tableLayout = "";

		var parentTable = this.Control.parentNode.parentNode.parentNode.parentNode;
		var definedTable = this.Owner.GetTableObjectByID(parentTable.id);

		var parentTableLayOut;
		if (definedTable != null)
		{
			parentTableLayOut = definedTable.Control.style.tableLayout;
			definedTable.Control.style.tableLayout = "";
		}

		if(!isDataRow)
		{
			if (this.Control)
			{
				if (this.Control.rows[index])
				{
					if (this.Control.rows[index].cells[0])
					{
						this.Control.rows[index].cells[0].style.height = height + "px";
						this.Control.rows[index].style.height = height + "px";
					}
				}
			}
		}
		else
		{
			if (this.Control)
			{
				if (this.Control.tBodies[0])
				{
					if (this.Control.tBodies[0].rows[index])
					{
						if (this.Control.tBodies[0].rows[index].cells[0])
						{
							this.Control.tBodies[0].rows[index].cells[0].style.height = height + "px";
							this.Control.tBodies[0].rows[index].style.height = height + "px";
						}
					}
				}
			}
		}

		this.Control.style.tableLayout = controlLayOut;

		if (definedTable != null)
		{
			definedTable.Control.style.tableLayout = parentTableLayOut;
		}

		this.RestoreTableLayOut();

		var currentRow = this.Owner.GetRowObjectByRealRow(this,this.Control.rows[index]);
		this.Owner.SavePostData("ResizedRows", this.Control.id, currentRow.RealIndex, height + "px");
		
		RadGridNamespace.FireEvent(this, "OnRowResized", [index, height]);

	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};


RadGridNamespace.RadGridTable.prototype.ResizeColumn = function(index, width)
{
	if (isNaN(parseInt(index)))
	{
		var message = "Column index must be of type \"Number\"!";
		alert(message);
		return;
	}
	
	if (isNaN(parseInt(width)))
	{
		var message = "Column width must be of type \"Number\"!";
		alert(message);
		return;			
	}

	if (index < 0)
	{
		var message = "Column index must be non-negative!";
		alert(message);
		return;
	}

	if (width < 0)
	{
		var message = "Column width must be non-negative!";
		alert(message);
		return;
	}

	if (index > (this.Columns.length - 1))
	{
		var message = "Column index must be less than columns count!";
		alert(message);
		return;
	}

	if (!this.Owner.ClientSettings.Resizing.AllowColumnResize)
		return;
	
	if (!this.Columns)
		return;

	if (!this.Columns[index].Resizable)
		return;


	if (!RadGridNamespace.FireEvent(this, "OnColumnResizing", [index, width]))
		return;

	try
	{
	    if(this == this.Owner.MasterTableView && this.Owner.MasterTableViewHeader)
		{
		    this.Owner.MasterTableViewHeader.ResizeColumn(index, width);
        }
        
		var lastWidth = this.Control.clientWidth;
		var lastGridWidth = this.Owner.Control.clientWidth;
	
	    if(this.HeaderRow)
		    var deltaWidth = this.HeaderRow.cells[index].scrollWidth - width;
		
		if(window.netscape || window.opera)
		{
		    if (this.HeaderRow)
		    {
			    if (this.HeaderRow.cells[index])
			    {
				    this.HeaderRow.cells[index].style.width = width + "px";
			    }
		    }
    		
		    if(this == this.Owner.MasterTableViewHeader)
		    {
		        var firstDataRow = this.Owner.MasterTableView.Control.tBodies[0].rows[this.Owner.ClientSettings.FirstDataRowClientRowIndex];
		        if (firstDataRow)
		        {
			        if (firstDataRow.cells[index])
			        {
				        firstDataRow.cells[index].style.width = width + "px";
			        }
		        }
		        
		        
		        if (this.Owner.MasterTableViewFooter && this.Owner.MasterTableViewFooter.Control)
		        {
			        if (this.Owner.MasterTableViewFooter.Control.tBodies[0].rows[0] &&
			            this.Owner.MasterTableViewFooter.Control.tBodies[0].rows[0].cells[index])
			        {
				        if (width > 0)
				        {
					        this.Owner.MasterTableViewFooter.Control.tBodies[0].rows[0].cells[index].style.width = width + "px";
				        }
			        }
		        }
	        }
	    }

		if (this.ColGroup)
		{
			if (this.ColGroup.Cols[index])
			{
				if (width > 0)
				{
					this.ColGroup.Cols[index].width	= width + "px";
				}
			}
		}
		
		if(this == this.Owner.MasterTableViewHeader)
		{
		    if (this.Owner.MasterTableView.ColGroup)
		    {
			    if (this.Owner.MasterTableView.ColGroup.Cols[index])
			    {
				    if (width > 0)
				    {
					    this.Owner.MasterTableView.ColGroup.Cols[index].width = width + "px";
				    }
			    }
		    }
		    
		    if (this.Owner.MasterTableViewFooter && this.Owner.MasterTableViewFooter.ColGroup)
		    {
			    if (this.Owner.MasterTableViewFooter.ColGroup.Cols[index])
			    {
				    if (width > 0)
				    {
					    this.Owner.MasterTableViewFooter.ColGroup.Cols[index].width = width + "px";
				    }
			    }
		    }
		}
		
		if (this == this.Owner.MasterTableView || this == this.Owner.MasterTableViewHeader)
		{
			this.Owner.SavePostData("ResizedColumns", this.Owner.MasterTableView.ClientID, this.Columns[index].RealIndex, width + "px");
		}
		else
		{
			this.Owner.SavePostData("ResizedColumns", this.ClientID, this.Columns[index].RealIndex, width + "px");		
		}

		if (this.Owner.ClientSettings.Resizing.ResizeGridOnColumnResize)
		{
		    if(this == this.Owner.MasterTableViewHeader)
		    {
		        for(var i = 0; i < this.ColGroup.Cols.length; i++)
		        {
		            if(i != index && this.ColGroup.Cols[i].width == "")
		            {
		                this.ColGroup.Cols[i].width = this.HeaderRow.cells[i].scrollWidth + "px";
		                this.Owner.MasterTableView.ColGroup.Cols[i].width = this.ColGroup.Cols[i].width;
		                if(this.Owner.MasterTableViewFooter && this.Owner.MasterTableViewFooter.ColGroup)
		                {
		                    this.Owner.MasterTableViewFooter.ColGroup.Cols[i].width = this.ColGroup.Cols[i].width;
		                }
		            }
		        }
		        
				this.Control.style.width = (this.Control.offsetWidth - deltaWidth) + "px";
				this.Owner.MasterTableView.Control.style.width = this.Control.style.width;
				
				if(this.Owner.MasterTableViewFooter && this.Owner.MasterTableViewFooter.Control)
				{
				    this.Owner.MasterTableViewFooter.Control.style.width = this.Control.style.width;
				}
				
				var controlWidth = (this.Control.scrollWidth > this.Control.offsetWidth)? this.Control.scrollWidth : this.Control.offsetWidth;
				var scrollWidth = this.Owner.GridDataDiv.offsetWidth;
				this.Owner.SavePostData("ResizedControl", this.ClientID, controlWidth + "px", scrollWidth + "px", this.Owner.Control.offsetHeight + "px");
		    }
		    else
		    {
				this.Control.style.width = (this.Control.offsetWidth - deltaWidth) + "px";
		        this.Owner.Control.style.width = this.Control.style.width;
		    	var controlWidth = (this.Control.scrollWidth > this.Control.offsetWidth)? this.Control.scrollWidth : this.Control.offsetWidth;
				this.Owner.SavePostData("ResizedControl", this.ClientID, controlWidth + "px", this.Owner.Control.offsetWidth + "px", this.Owner.Control.offsetHeight + "px");
		    }
		/*
			if (!this.Owner.ClientSettings.Scrolling.UseStaticHeaders)
			{
				if (!this.Owner.GridDataDiv)
				{
					this.Control.style.width = (this.Owner.Control.offsetWidth - deltaWidth) + "px";
					this.Owner.Control.style.width = (this.Owner.Control.offsetWidth - deltaWidth) + "px";
					
					var controlWidth = (this.Control.scrollWidth > this.Control.offsetWidth)? this.Control.scrollWidth : this.Control.offsetWidth;
					this.Owner.SavePostData("ResizedControl", this.ClientID, controlWidth + "px", this.Owner.Control.offsetWidth + "px", this.Owner.Control.offsetHeight + "px");
				}
				else
				{
					//this.Control.style.width = (this.Owner.Control.offsetWidth - deltaWidth) + "px";
					//alert(this.Owner.Control.style.width);
					var controlWidth = (this.Control.scrollWidth > this.Control.offsetWidth)? this.Control.scrollWidth : this.Control.offsetWidth;
					this.Owner.SavePostData("ResizedControl", this.ClientID, controlWidth + "px", lastGridWidth + "px", this.Owner.Control.offsetHeight + "px");
				}
			}
			else
			{
				this.Owner.MasterTableViewHeader.Control.style.width = (this.Control.offsetWidth - deltaWidth) + "px";
				this.Owner.MasterTableView.Control.style.width = (this.Control.offsetWidth - deltaWidth) + "px";
				
				var controlWidth = (this.Control.scrollWidth > this.Control.offsetWidth)? this.Control.scrollWidth : this.Control.offsetWidth;
				var scrollWidth = this.Owner.GridDataDiv.offsetWidth;
				this.Owner.SavePostData("ResizedControl", this.ClientID, controlWidth + "px", scrollWidth + "px", this.Owner.Control.offsetHeight + "px");
			}*/
		}
		
		if(this.Owner.GroupPanelObject && this.Owner.GroupPanelObject.Items.length > 0 && navigator.userAgent.toLowerCase().indexOf("msie") != -1)
	    {
	        if(this.Owner.MasterTableView && this.Owner.MasterTableViewHeader)
	        {
	            this.Owner.MasterTableView.Control.style.width = this.Owner.MasterTableViewHeader.Control.offsetWidth + "px";
	        }
	    }

		RadGridNamespace.FireEvent(this, "OnColumnResized", [index, width]);
		if(window.netscape)
		{
		    this.Control.style.cssText = this.Control.style.cssText;
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.ReorderColumns = function(columnIndex1, columnIndex2)
{
	if (isNaN(parseInt(columnIndex1)))
	{
		var message = "First column index must be of type \"Number\"!";
		alert(message);
		return;
	}
	
	if (isNaN(parseInt(columnIndex2)))
	{
		var message = "Second column index must be of type \"Number\"!";
		alert(message);
		return;			
	}

	if (columnIndex1 < 0)
	{
		var message = "First column index must be non-negative!";
		alert(message);
		return;
	}

	if (columnIndex2 < 0)
	{
		var message = "Second column index must be non-negative!";
		alert(message);
		return;
	}

	if (columnIndex1 > (this.Columns.length - 1))
	{
		var message = "First column index must be less than columns count!";
		alert(message);
		return;
	}

	if (columnIndex2 > (this.Columns.length - 1))
	{
		var message = "Second column index must be less than columns count!";
		alert(message);
		return;
	}

	if (!this.Owner.ClientSettings.AllowColumnsReorder)
		return;
		
	if (!this.Columns)
		return;

	if (!this.Columns[columnIndex1].Reorderable)
		return;

	if (!this.Columns[columnIndex2].Reorderable)
		return;

    this.SwapColumns(columnIndex1, columnIndex2);

	if ((!this.Owner.ClientSettings.ReorderColumnsOnClient) &&
		(this.Owner.ClientSettings.PostBackReferences.PostBackColumnsReorder != ""))
	{
	    if(this == this.Owner.MasterTableView)
	    {
			eval(this.Owner.ClientSettings.PostBackReferences.PostBackColumnsReorder);
		}
	}

};

RadGridNamespace.RadGridTable.prototype.SwapColumns = function(columnIndex1, columnIndex2, shouldPostBack)
{
	if (isNaN(parseInt(columnIndex1)))
	{
		var message = "First column index must be of type \"Number\"!";
		alert(message);
		return;
	}
	
	if (isNaN(parseInt(columnIndex2)))
	{
		var message = "Second column index must be of type \"Number\"!";
		alert(message);
		return;			
	}

	if (columnIndex1 < 0)
	{
		var message = "First column index must be non-negative!";
		alert(message);
		return;
	}

	if (columnIndex2 < 0)
	{
		var message = "Second column index must be non-negative!";
		alert(message);
		return;
	}

	if (columnIndex1 > (this.Columns.length - 1))
	{
		var message = "First column index must be less than columns count!";
		alert(message);
		return;
	}

	if (columnIndex2 > (this.Columns.length - 1))
	{
		var message = "Second column index must be less than columns count!";
		alert(message);
		return;
	}

	if (!this.Owner.ClientSettings.AllowColumnsReorder)
		return;
		
	if (!this.Columns)
		return;

	if (!this.Columns[columnIndex1].Reorderable)
		return;

	if (!this.Columns[columnIndex2].Reorderable)
		return;

	try
	{
	    if(this == this.Owner.MasterTableView && this.Owner.MasterTableViewHeader)
	    {
	        this.Owner.MasterTableViewHeader.SwapColumns(columnIndex1, columnIndex2, !this.Owner.ClientSettings.ReorderColumnsOnClient);
	        return;
	    }
	
	    if(typeof(shouldPostBack) == "undefined")
	    {
	        shouldPostBack = true;
	    }
	
	    if(this.Owner.ClientSettings.ColumnsReorderMethod == "Reorder")
	    {
	        if(columnIndex2 > columnIndex1)
	        {
	            while(columnIndex1 + 1 < columnIndex2)
		        {
		            this.SwapColumns(columnIndex2-1, columnIndex2, false);
		            columnIndex2--;
		        }
	        }
	        else
	        {
	            while(columnIndex2 < columnIndex1 - 1)
		        {
			        this.SwapColumns(columnIndex2+1, columnIndex2, false);
			        columnIndex2++;
		        }
	        }
	    }
		
		if (!RadGridNamespace.FireEvent(this, "OnColumnSwapping", [columnIndex1, columnIndex2]))
			return;

		var table = this.Control;

		var oldColumn1 = this.Columns[columnIndex1];
		var oldColumn2 = this.Columns[columnIndex2];
		
		this.Columns[columnIndex1] = oldColumn2;
		this.Columns[columnIndex2] = oldColumn1;
        
		var oldWidth1 = this.ColGroup.Cols[columnIndex1].width;
		
		if(oldWidth1 == "" && this.HeaderRow)
		{
		    oldWidth1 = this.HeaderRow.cells[columnIndex1].offsetWidth;
		}
		
		var oldWidth2 = this.ColGroup.Cols[columnIndex2].width;

		if(oldWidth2 == "" && this.HeaderRow)
		{
		    oldWidth2 = this.HeaderRow.cells[columnIndex2].offsetWidth;
		}

        var allowColumnResize = this.Owner.ClientSettings.Resizing.AllowColumnResize;
        var resizable1 = (typeof(this.Columns[columnIndex1].Resizable) == "boolean")? this.Columns[columnIndex1].Resizable : false;
        var resizable2 = (typeof(this.Columns[columnIndex2].Resizable) == "boolean")? this.Columns[columnIndex2].Resizable : false;
        
        this.Owner.ClientSettings.Resizing.AllowColumnResize = true;
        this.Columns[columnIndex1].Resizable = true;
        this.Columns[columnIndex2].Resizable = true;
        
		this.ResizeColumn(columnIndex1, oldWidth2);
		this.ResizeColumn(columnIndex2, oldWidth1);
		
		this.Owner.ClientSettings.Resizing.AllowColumnResize = allowColumnResize;
		this.Columns[columnIndex1].Resizable = resizable1;
		this.Columns[columnIndex2].Resizable = resizable2;
		
		//alert(this == this.Owner.MasterTableViewHeader);
		
		var clientID = (this == this.Owner.MasterTableViewHeader)? this.Owner.MasterTableView.ClientID : this.ClientID;
		this.Owner.SavePostData("ReorderedColumns", clientID, this.Columns[columnIndex1].UniqueName, this.Columns[columnIndex2].UniqueName);

		for (var i=0;i<table.rows.length;i++) 
		{
			if (table.rows[i] != null)
			{
				if ((table.rows[i].cells[columnIndex1] != null) &&
					(table.rows[i].cells[columnIndex2] != null))
				{
				
					if (!table.rows[i].cells[columnIndex2].swapNode)
					{
						if (table.rows[i].cells[columnIndex1].innerHTML != null)
						{
							var cellContent1 = table.rows[i].cells[columnIndex1].innerHTML;
							var cellContent2 = table.rows[i].cells[columnIndex2].innerHTML;

							table.rows[i].cells[columnIndex1].innerHTML = cellContent2;
							table.rows[i].cells[columnIndex2].innerHTML = cellContent1;
						}
					}
					else
					{
						table.rows[i].cells[columnIndex2].swapNode(table.rows[i].cells[columnIndex1]);
					}
					
				}
			}
		}
		
		if (this.Owner.MasterTableViewHeader == this)
		{
			var table = this.Owner.MasterTableView.Control;
			for (var i=0;i<table.rows.length;i++) 
			{
				if (table.rows[i] != null)
				{
					if ((table.rows[i].cells[columnIndex1] != null) &&
						(table.rows[i].cells[columnIndex2] != null))
					{
					
						if (window.netscape || window.opera)
						{
							if (table.rows[i].cells[columnIndex1].innerHTML != null)
							{
								var cellContent1 = table.rows[i].cells[columnIndex1].innerHTML;
								var cellContent2 = table.rows[i].cells[columnIndex2].innerHTML;

								table.rows[i].cells[columnIndex1].innerHTML = cellContent2;
								table.rows[i].cells[columnIndex2].innerHTML = cellContent1;
							}
						}
						else
						{
							table.rows[i].cells[columnIndex2].swapNode(table.rows[i].cells[columnIndex1]);
						}
						
					}
				}
			}
		}
		/*
        if(navigator.userAgent.toLowerCase().indexOf("msie") != -1)
        {    		
		    var cellIndex1 = this.Columns[columnIndex1].Control.cellIndex
		    var cellIndex2 = this.Columns[columnIndex2].Control.cellIndex
		    this.Columns[columnIndex1].Control.cellIndex = cellIndex2;
		    this.Columns[columnIndex2].Control.cellIndex = cellIndex1;
        }*/

		
		/*

		//if (oldWidth2 != "")
		{
			this.ColGroup.Cols[columnIndex1].width = oldWidth2;
		}
		
		//if (oldWidth1 != "")
		{
			this.ColGroup.Cols[columnIndex2].width = oldWidth1;
		}

		if (this.Owner.MasterTableViewHeader != null)
		{
			var table = this.Owner.MasterTableViewHeader.Control;
			for (var i=0;i<table.rows.length;i++) 
			{
				if (table.rows[i] != null)
				{
					if ((table.rows[i].cells[columnIndex1] != null) &&
						(table.rows[i].cells[columnIndex2] != null))
					{
					
						if (window.netscape || window.opera)
						{
							if (table.rows[i].cells[columnIndex1].innerHTML != null)
							{
								var cellContent1 = table.rows[i].cells[columnIndex1].innerHTML;
								var cellContent2 = table.rows[i].cells[columnIndex2].innerHTML;

								table.rows[i].cells[columnIndex1].innerHTML = cellContent2;
								table.rows[i].cells[columnIndex2].innerHTML = cellContent1;
							}
						}
						else
						{
							table.rows[i].cells[columnIndex2].swapNode(table.rows[i].cells[columnIndex1]);
						}
						
					}
				}
			}


			var headerRow1 = this.Owner.MasterTableViewHeader.HeaderRow;

			this.Owner.MasterTableViewHeader.ColGroup.Cols[columnIndex1].width = oldWidth2;
			this.Owner.MasterTableViewHeader.ColGroup.Cols[columnIndex2].width = oldWidth1;

			if (headerRow1 != null)
			{
				if ((headerRow1.cells[columnIndex1] != null) &&
					(headerRow1.cells[columnIndex2] != null))
				{
					if (oldWidth2 != "")
					{
						headerRow1.cells[columnIndex1].style.width = oldWidth2 + "px";
					}
					
					if (oldWidth1 != "")
					{
						headerRow1.cells[columnIndex2].style.width = oldWidth1 + "px";
					}
				}
			}
			
			if (this == this.Owner.MasterTableView)
			{
				//if (oldWidth2 != "")
				{
					this.Owner.MasterTableView.ColGroup.Cols[columnIndex1].width = oldWidth2;
				}
				
				//if (oldWidth1 != "")
				{
					this.Owner.MasterTableView.ColGroup.Cols[columnIndex2].width = oldWidth1;
				}
				
				var headerRow2 = null;
				if (this.Owner.MasterTableView.Control.tBodies[0])
				{
					headerRow2 = this.Owner.MasterTableView.Control.tBodies[0].rows[1];				
				}
				
				if (headerRow2 != null)
				{
					if ((headerRow2.cells[columnIndex1] != null) &&
						(headerRow2.cells[columnIndex2] != null))
					{
						if (oldWidth2 != "")
						{
							headerRow2.cells[columnIndex1].style.width = oldWidth2 + "px";
						}
						
						if (oldWidth1 != "")
						{
							headerRow2.cells[columnIndex2].style.width = oldWidth1 + "px";
						}
					}
				}
			}
		}*/

		if (shouldPostBack && (!this.Owner.ClientSettings.ReorderColumnsOnClient) &&
			(this.Owner.ClientSettings.PostBackReferences.PostBackColumnsReorder != ""))
		{
		    //if(this == this.Owner.MasterTableView)
		    {
				eval(this.Owner.ClientSettings.PostBackReferences.PostBackColumnsReorder);
			}
		}	

		RadGridNamespace.FireEvent(this, "OnColumnSwapped", [columnIndex1, columnIndex2]);
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.MoveColumnToLeft = function(index)
{
	if (isNaN(parseInt(index)))
	{
		var message = "Column index must be of type \"Number\"!";
		alert(message);
		return;			
	}

	if (index < 0)
	{
		var message = "Column index must be non-negative!";
		alert(message);
		return;
	}

	if (index > (this.Columns.length - 1))
	{
		var message = "Column index must be less than columns count!";
		alert(message);
		return;
	}

	if (!this.Owner.ClientSettings.AllowColumnsReorder)
		return;

	try
	{
		if (!RadGridNamespace.FireEvent(this, "OnColumnMovingToLeft", [index]))
			return;

		var newIndex = index--;
		this.SwapColumns(index, newIndex);

		RadGridNamespace.FireEvent(this, "OnColumnMovedToLeft", [index]);
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}

};

RadGridNamespace.RadGridTable.prototype.MoveColumnToRight = function(index)
{

	if (isNaN(parseInt(index)))
	{
		var message = "Column index must be of type \"Number\"!";
		alert(message);
		return;			
	}

	if (index < 0)
	{
		var message = "Column index must be non-negative!";
		alert(message);
		return;
	}

	if (index > (this.Columns.length - 1))
	{
		var message = "Column index must be less than columns count!";
		alert(message);
		return;
	}

	if (!this.Owner.ClientSettings.AllowColumnsReorder)
		return;

	try
	{
		if (!RadGridNamespace.FireEvent(this, "OnColumnMovingToRight", [index]))
			return;

		var newIndex = index++;
		this.SwapColumns(index, newIndex);

		RadGridNamespace.FireEvent(this, "OnColumnMovedToRight", [index]);
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}

};

RadGridNamespace.RadGridTable.prototype.HideColumn = function(index)
{
	if(!this.Owner.ClientSettings.AllowColumnHide)
		return;

	if (isNaN(parseInt(index)))
	{
		var message = "Column index must be of type \"Number\"!";
		alert(message);
		return;			
	}

	if (index < 0)
	{
		var message = "Column index must be non-negative!";
		alert(message);
		return;
	}

	if (index > (this.Columns.length - 1))
	{
		var message = "Column index must be less than columns count!";
		alert(message);
		return;
	}

	try
	{
		if (!RadGridNamespace.FireEvent(this, "OnColumnHiding", [index]))
			return;

		for (var i=0;i<this.Control.rows.length;i++)
		{
			if(this.Control.rows[i].cells[index] != null)
			{
				if (this.Control.rows[i].cells[index].colSpan == 1)
					this.Control.rows[i].cells[index].style.display = "none";
			}
		}

		this.Columns[index].Display = false;

		if (this.Owner.FooterControl)
		{
			for (var i=0;i<this.Owner.FooterControl.rows.length;i++)
			{
				if(this.Owner.FooterControl.rows[i].cells[index] != null)
				{
					if (this.Owner.FooterControl.rows[i].cells[index].colSpan == 1)
						this.Owner.FooterControl.rows[i].cells[index].style.display = "none";				
				}
			}
		}

		if (this.Owner.HeaderControl)
		{
		
			for (var i=0;i<this.Owner.MasterTableViewHeader.Control.rows.length;i++)
			{
				if(this.Owner.MasterTableViewHeader.Control.rows[i].cells[index] != null)
				{
					if (this.Owner.MasterTableViewHeader.Control.rows[i].cells[index].colSpan == 1)
						this.Owner.MasterTableViewHeader.Control.rows[i].cells[index].style.display = "none";
				}
			}
		}

		if (this == this.Owner.MasterTableViewHeader)
		{
			for (var i=0;i<this.Owner.MasterTableView.Control.rows.length;i++)
			{
				if(this.Owner.MasterTableView.Control.rows[i].cells[index] != null)
				{
					if (this.Owner.MasterTableView.Control.rows[i].cells[index].colSpan == 1)
						this.Owner.MasterTableView.Control.rows[i].cells[index].style.display = "none";
				}
			}
		}

		if(this.Owner.ClientSettings.Scrolling.AllowScroll && this.Owner.ClientSettings.Scrolling.UseStaticHeaders && this == this.Owner.MasterTableView)
		{
			for (var i=0;i<this.Owner.MasterTableViewHeader.Control.rows.length;i++)
			{
				if(this.Owner.MasterTableViewHeader.Control.rows[i].cells[index] != null)
				{
				    if(this.Owner.MasterTableViewHeader.Control.rows[i].cells[index].colSpan == 1)
					this.Owner.MasterTableViewHeader.Control.rows[i].cells[index].style.display = "none";
				}
			}
		}
				
		if (this != this.Owner.MasterTableViewHeader)
		{
			this.Owner.SavePostData("HidedColumns", this.ClientID, this.Columns[index].RealIndex);
		}

		RadGridNamespace.FireEvent(this, "OnColumnHidden", [index]);
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}

};

RadGridNamespace.RadGridTable.prototype.ShowColumn = function(index)
{
	if(!this.Owner.ClientSettings.AllowColumnHide)
		return;

	if (isNaN(parseInt(index)))
	{
		var message = "Column index must be of type \"Number\"!";
		alert(message);
		return;			
	}

	if (index < 0)
	{
		var message = "Column index must be non-negative!";
		alert(message);
		return;
	}

	if (index > (this.Columns.length - 1))
	{
		var message = "Column index must be less than columns count!";
		alert(message);
		return;
	}

	try
	{
	
	//debugger;
		if (!RadGridNamespace.FireEvent(this, "OnColumnShowing", [index]))
			return;

        if(this.Control.tHead)
        {
		    for (var i=0;i<this.Control.tHead.rows.length;i++)
		    {
			    if(this.Control.tHead.rows[i].cells[index] != null)
			    {
				    if (window.netscape)
				    {
					    this.Control.tHead.rows[i].cells[index].style.display = "table-cell";
				    }
				    else
				    {
					    this.Control.tHead.rows[i].cells[index].style.display = "";
				    }
			    }
		    }
		}

		if (this.Control.tBodies[0])
		{
			for (var i=0;i<this.Control.tBodies[0].rows.length;i++)
			{
				if(this.Control.tBodies[0].rows[i].cells[index] != null)
				{
					if (window.netscape)
					{
						this.Control.tBodies[0].rows[i].cells[index].style.display = "table-cell";
					}
					else
					{
						this.Control.tBodies[0].rows[i].cells[index].style.display = "";
					}
				}
			}
		}


		if (this.Owner.FooterControl)
		{
			for (var i=0;i<this.Owner.FooterControl.rows.length;i++)
			{
				if(this.Owner.FooterControl.rows[i].cells[index] != null)
				{
					if (window.netscape)
					{
						this.Owner.FooterControl.rows[i].cells[index].style.display = "table-cell";
					}
					else
					{
						this.Owner.FooterControl.rows[i].cells[index].style.display = "";
					}
				}
			}
		}
		//debugger;
		if (this == this.Owner.MasterTableViewHeader)
		{
			for (var i=0;i<this.Owner.MasterTableView.Control.rows.length;i++)
			{
				if(this.Owner.MasterTableView.Control.rows[i].cells[index] != null)
				{
					if (window.netscape)
					{
						this.Owner.MasterTableView.Control.rows[i].cells[index].style.display = "table-cell";
					}
					else
					{
						this.Owner.MasterTableView.Control.rows[i].cells[index].style.display = "";
					}
				}
			}
		}
		
		if(this.Owner.ClientSettings.Scrolling.AllowScroll && this.Owner.ClientSettings.Scrolling.UseStaticHeaders && this == this.Owner.MasterTableView)
		{
			for (var i=0;i<this.Owner.MasterTableViewHeader.Control.rows.length;i++)
			{
				if(this.Owner.MasterTableViewHeader.Control.rows[i].cells[index] != null)
				{
					if (window.netscape)
					{
						this.Owner.MasterTableViewHeader.Control.rows[i].cells[index].style.display = "table-cell";
					}
					else
					{
						this.Owner.MasterTableViewHeader.Control.rows[i].cells[index].style.display = "";
					}
				}
			}
		}
		
		
		//if(this.Columns.)

		if (this != this.Owner.MasterTableViewHeader)
		{
			this.Owner.SavePostData("ShowedColumns", this.ClientID, this.Columns[index].RealIndex);
		}

		this.Columns[index].Display = true;

		RadGridNamespace.FireEvent(this, "OnColumnShowed", [index]);
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.HideRow = function(index)
{
	if(!this.Owner.ClientSettings.AllowRowHide)
		return;

	if (isNaN(parseInt(index)))
	{
		var message = "Row index must be of type \"Number\"!";
		alert(message);
		return;			
	}

	if (index < 0)
	{
		var message = "Row index must be non-negative!";
		alert(message);
		return;
	}

	if (index > (this.Rows.length - 1))
	{
		var message = "Row index must be less than rows count!";
		alert(message);
		return;
	}

	try
	{
		if (!RadGridNamespace.FireEvent(this, "OnRowHiding", [index]))
			return;

		if (this.Rows)
		{
			if (this.Rows[index])
			{
				if (this.Rows[index].Control)
				{
					this.Rows[index].Control.style.display = "none";
					this.Rows[index].Display = false;
				}
			}
		}

		if (this != this.Owner.MasterTableViewHeader)
		{
			this.Owner.SavePostData("HidedRows", this.ClientID, this.Rows[index].RealIndex);
		}

		RadGridNamespace.FireEvent(this, "OnRowHidden", [index]);
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}

};

RadGridNamespace.RadGridTable.prototype.ShowRow = function(index)
{
	if(!this.Owner.ClientSettings.AllowRowHide)
		return;

	if (isNaN(parseInt(index)))
	{
		var message = "Row index must be of type \"Number\"!";
		alert(message);
		return;			
	}

	if (index < 0)
	{
		var message = "Row index must be non-negative!";
		alert(message);
		return;
	}

	if (index > this.Rows.length)
	{
		var message = "Row index must be less than rows count!";
		alert(message);
		return;
	}

	try
	{
		if (!RadGridNamespace.FireEvent(this, "OnRowShowing", [index]))
			return;

		if (this.Rows)
		{
			if (this.Rows[index])
			{
				if (this.Rows[index].Control)
				{
					if (this.Rows[index].ItemType != "NestedView")
					{
						if (window.netscape)
						{
							this.Rows[index].Control.style.display = "table-row";
						}
						else
						{
							this.Rows[index].Control.style.display = "";
						}
						this.Rows[index].Display = true;
					}
				}
			}
		}

		if (this != this.Owner.MasterTableViewHeader)
		{
			this.Owner.SavePostData("ShowedRows", this.ClientID, this.Rows[index].RealIndex);
		}

		RadGridNamespace.FireEvent(this, "OnRowShowed", [index]);
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.ExportToExcel = function(fileName)
{
	try
	{
		if (this.Owner.ClientSettings.PostBackReferences.PostBackExportToExcel != "")
		{
			this.Owner.SavePostData("ExportToExcel", this.ClientID, fileName);
			eval(this.Owner.ClientSettings.PostBackReferences.PostBackExportToExcel);
		}
	}
	catch(e)
	{
		throw e;
	}
};

RadGridNamespace.RadGridTable.prototype.ExportToWord = function(fileName)
{
	try
	{
		if (this.Owner.ClientSettings.PostBackReferences.PostBackExportToWord != "")
		{
			this.Owner.SavePostData("ExportToWord", this.ClientID, fileName);
			eval(this.Owner.ClientSettings.PostBackReferences.PostBackExportToWord);
		}
	}
	catch(e)
	{
		throw e;
	}
};

RadGridNamespace.RadGridTable.prototype.AddToSelectedRows = function(rowObject)
{
	try
	{
		this.SelectedRows[this.SelectedRows.length] = rowObject;
	}
	catch(e)
	{
		throw e;
	}
};

RadGridNamespace.RadGridTable.prototype.IsInSelectedRows = function(rowObject)
{
	try
	{
		for (var i = 0; i < this.SelectedRows.length; i++)
		{
			if (this.SelectedRows[i] != rowObject)
			{
				return true;
			}
		}
		return false;
	}
	catch(e)
	{
		throw e;
	}
};

RadGridNamespace.RadGridTable.prototype.ClearSelectedRows = function()
{
    var selectedRows = this.SelectedRows;
	for (var i = 0; i < this.SelectedRows.length; i++)
	{
		if (!RadGridNamespace.FireEvent(this, "OnRowDeselecting", [this.SelectedRows[i]]))
			continue;

		this.SelectedRows[i].Selected = false;
		this.SelectedRows[i].CheckClientSelectColumns();
		this.SelectedRows[i].RemoveSelectedRowStyle();
		
		var last = this.SelectedRows[i];
		
		try
		{
		    this.SelectedRows.splice(i,1);
		    i--;
		}
		catch(ex)
		{
		    //
		}
		
		RadGridNamespace.FireEvent(this, "OnRowDeselected", [last]);
	}
	this.SelectedRows = new Array();
};

RadGridNamespace.RadGridTable.prototype.RemoveFromSelectedRows = function(rowObject)
{
	try
	{
		var selectedRows = new Array();
		for (var i = 0; i < this.SelectedRows.length; i++)
		{
			//if (!RadGridNamespace.FireEvent(this, "OnRowDeselecting", [this.SelectedRows[i]]))
			//	return;

			//if (!RadGridNamespace.FireEvent(this, "OnRowDeselected", [this.SelectedRows[i]]))
			//	return;

		    var last = this.SelectedRows[i];

			if (this.SelectedRows[i] != rowObject)
			{
				selectedRows[selectedRows.length] = this.SelectedRows[i];				
			}
			else
			{
			    if(!this.Owner.AllowMultiRowSelection)
			    {
				    if (!RadGridNamespace.FireEvent(this, "OnRowDeselecting", [this.SelectedRows[i]]))
				    {
					    continue;
				    }
				}
				
		        try
		        {
		            this.SelectedRows.splice(i,1);
		            i--;
		        }
		        catch(ex)
		        {
		            //
		        }

		        rowObject.CheckClientSelectColumns();
		        
		        setTimeout(function(){
				    RadGridNamespace.FireEvent(rowObject.Owner, "OnRowDeselected", [last]);
				}, 100);
			}
		}
		this.SelectedRows = selectedRows;
	}
	catch(e)
	{
		throw e;
	}
};

RadGridNamespace.RadGridTable.prototype.GetSelectedRowsIndexes = function()
{
	try
	{
		var selectedRowsIndexes = new Array();
		for (var i = 0; i < this.SelectedRows.length; i++)
		{
			selectedRowsIndexes[selectedRowsIndexes.length] = this.SelectedRows[i].RealIndex;
		}
		return selectedRowsIndexes.join(",");
	}
	catch(e)
	{
		throw e;
	}
};

RadGridNamespace.RadGridTable.prototype.GetCellByColumnUniqueName = function(rowObject, uniqueName)
{
	if(this.ClientID.indexOf("_Header") != -1)
		return;
	if ((!rowObject) || (!uniqueName))
		return;
    if(!this.Columns)
		return;

	for(var i = 0; i < this.Columns.length; i++)
	{
		if ( this.Columns[i].UniqueName.toUpperCase() == uniqueName.toUpperCase() )
		{
			return rowObject.Control.cells[i];
		}
	}

	return null;
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY
RadGridNamespace.RadGridTableColumn = function(object)
{
	if ((!object) || typeof(object) != "object")
		return;

	RadControlsNamespace.DomEventMixin.Initialize(this);
	
	for (var member in object)
	{
		this[member] = object[member];
	}

	this.Type = "RadGridTableColumn";
	this.ResizeTolerance = 5;
	this.CanResize = false;
};

RadGridNamespace.RadGridTableColumn.prototype._constructor = function(control, owner)
{
	this.Control = control;
	this.Owner = owner;
	this.Index = control.cellIndex;
	
	if(window.opera && typeof(control.cellIndex) == "undefined")
	{
	    this.Index = 0;
	}
	
	this.AttachDomEvent(this.Control, "click", "OnClick");
	this.AttachDomEvent(this.Control, "dblclick", "OnDblClick");
	this.AttachDomEvent(this.Control, "mousemove", "OnMouseMove");
	this.AttachDomEvent(this.Control, "mousedown", "OnMouseDown");
	this.AttachDomEvent(this.Control, "mouseup", "OnMouseUp");
	this.AttachDomEvent(this.Control, "mouseover", "OnMouseOver");
	this.AttachDomEvent(this.Control, "mouseout", "OnMouseOut");
	this.AttachDomEvent(this.Control, "contextmenu", "OnContextMenu");
};

RadGridNamespace.RadGridTableColumn.prototype.Dispose = function()
{
	this.DisposeDomEventHandlers();
	
	if (this.ColumnResizer)
	{
		this.ColumnResizer.Dispose();
	}
	
	this.Control = null;
	this.Owner = null;
	this.Index = null;
}

RadGridNamespace.RadGridTableColumn.prototype.OnContextMenu = function(e)
{
	try
	{
		if (!RadGridNamespace.FireEvent(this.Owner, "OnColumnContextMenu", [this.Index, e]))
			return;
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.Owner.OnError);
	}
};

RadGridNamespace.RadGridTableColumn.prototype.OnClick = function(e)
{
	try
	{
		if (!RadGridNamespace.FireEvent(this.Owner, "OnColumnClick", [this.Index]))
			return;
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.Owner.OnError);
	}
};

RadGridNamespace.RadGridTableColumn.prototype.OnDblClick = function(e)
{
	try
	{
		if (!RadGridNamespace.FireEvent(this.Owner, "OnColumnDblClick", [this.Index]))
			return;
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.Owner.OnError);
	}
};

RadGridNamespace.RadGridTableColumn.prototype.OnMouseMove = function(e)
{
	if (this.Owner.Owner.ClientSettings.Resizing.AllowColumnResize && this.Resizable && this.Control.tagName.toLowerCase() == "th")
	{
		var positionX = RadGridNamespace.GetEventPosX(e);
		var startX = RadGridNamespace.FindPosX(this.Control);
		var endX = startX + this.Control.offsetWidth;
		
		var currentElement = RadGridNamespace.GetCurrentElement(e);

		if ((positionX >= endX - this.ResizeTolerance) && 
			(positionX <= endX + this.ResizeTolerance))
		{
			this.Control.style.cursor = "e-resize";
			
			this.Control.title = this.Owner.Owner.ClientSettings.ClientMessages.DragToResize;

			this.CanResize = true;
			currentElement.style.cursor = "e-resize";
			this.Owner.Owner.IsResize = true;
		}
		else
		{
			this.Control.style.cursor = "";
			this.Control.title = "";
			this.CanResize = false;

			currentElement.style.cursor = "";
			this.Owner.Owner.IsResize = false;
		}
	}
};

RadGridNamespace.RadGridTableColumn.prototype.OnMouseDown = function(e)
{
	if (this.CanResize)
	{
		if (((window.netscape || window.opera) && (e.button == 0)) || (e.button == 1))
		{
			var positionX = RadGridNamespace.GetEventPosX(e);
			var startX = RadGridNamespace.FindPosX(this.Control);
			var endX = startX + this.Control.offsetWidth;

			if ((positionX >= endX - this.ResizeTolerance) && 
				(positionX <= endX + this.ResizeTolerance))
			{
				this.ColumnResizer = new RadGridNamespace.RadGridColumnResizer(this, this.Owner.Owner.ClientSettings.Resizing.EnableRealTimeResize);
				this.ColumnResizer.Position(e);
			}
		}

		RadGridNamespace.ClearDocumentEvents();
	}
};

RadGridNamespace.RadGridTableColumn.prototype.OnMouseUp = function(e)
{
	RadGridNamespace.RestoreDocumentEvents();
};

RadGridNamespace.RadGridTableColumn.prototype.OnMouseOver = function(e)
{
	if (!RadGridNamespace.FireEvent(this.Owner, "OnColumnMouseOver", [this.Index]))
		return;
};

RadGridNamespace.RadGridTableColumn.prototype.OnMouseOut = function(e)
{
	if (!RadGridNamespace.FireEvent(this.Owner, "OnColumnMouseOut", [this.Index]))
		return;
};

RadGridNamespace.RadGridColumnResizer = function(column, isRealTimeResize)
{
	if(!column)
		return;
		
	RadControlsNamespace.DomEventMixin.Initialize(this);

	this.Column = column;
	this.IsRealTimeResize = isRealTimeResize;
	
	this.CurrentWidth = null;

	this.LeftResizer = document.createElement("span");
	this.LeftResizer.style.backgroundColor = "navy";
	this.LeftResizer.style.width = "1" + "px";
	this.LeftResizer.style.position = "absolute";
	this.LeftResizer.style.cursor = "e-resize";

	this.RightResizer = document.createElement("span");
	this.RightResizer.style.backgroundColor = "navy";
	this.RightResizer.style.width = "1" + "px";
	this.RightResizer.style.position = "absolute";
	this.RightResizer.style.cursor = "e-resize";

	this.ResizerToolTip = document.createElement("span");
	this.ResizerToolTip.style.backgroundColor = "#F5F5DC";
	this.ResizerToolTip.style.border = "1px solid";
	this.ResizerToolTip.style.position = "absolute";
	this.ResizerToolTip.style.font = "icon";
	this.ResizerToolTip.style.padding = "2";
	this.ResizerToolTip.innerHTML = "Width: <b>" + this.Column.Control.offsetWidth + "</b> <em>pixels</em>";

	document.body.appendChild(this.LeftResizer);
	document.body.appendChild(this.RightResizer);
	document.body.appendChild(this.ResizerToolTip);
	
	this.CanDestroy = true;

	this.AttachDomEvent(document, "mouseup", "OnMouseUp");
	this.AttachDomEvent(this.Column.Owner.Owner.Control, "mousemove", "OnMouseMove");
};

RadGridNamespace.RadGridColumnResizer.prototype.OnMouseUp = function(e)
{
	this.Destroy(e);
};

RadGridNamespace.RadGridColumnResizer.prototype.OnMouseMove = function(e)
{
	this.Move(e);
};

RadGridNamespace.RadGridColumnResizer.prototype.Position = function(e)
{
	this.LeftResizer.style.top = RadGridNamespace.FindPosY(this.Column.Control) - 
									RadGridNamespace.FindScrollPosY(this.Column.Control) + 
									document.documentElement.scrollTop + 
									document.body.scrollTop + "px";

	this.LeftResizer.style.left = RadGridNamespace.FindPosX(this.Column.Control) - 
									RadGridNamespace.FindScrollPosX(this.Column.Control) + 
									document.documentElement.scrollLeft + 
									document.body.scrollLeft + "px";
    
	this.RightResizer.style.top = this.LeftResizer.style.top;
	this.RightResizer.style.left = parseInt(this.LeftResizer.style.left) +	this.Column.Control.offsetWidth + "px";

	this.ResizerToolTip.style.top = parseInt(this.RightResizer.style.top) - 20 + "px";

	this.ResizerToolTip.style.left = parseInt(this.RightResizer.style.left) - 5 + "px";

	if (parseInt(this.LeftResizer.style.left) < RadGridNamespace.FindPosX(this.Column.Owner.Control))
	{
		this.LeftResizer.style.display = "none";
	}
	
	this.LeftResizer.style.height = this.Column.Control.offsetHeight + "px";
	this.RightResizer.style.height = this.Column.Control.offsetHeight + "px";
};

RadGridNamespace.RadGridColumnResizer.prototype.Destroy = function(e)
{
	if (this.CanDestroy)
	{
		this.DetachDomEvent(document, "mouseup", "OnMouseUp");
		this.DetachDomEvent(this.Column.Owner.Owner.Control, "mousemove", "OnMouseMove");
		
		if (this.CurrentWidth != null)
		{
			if (this.CurrentWidth > 0)
			{
				this.Column.Owner.ResizeColumn(RadGridNamespace.GetRealCellIndex(this.Column.Owner, this.Column.Control), this.CurrentWidth);
				this.CurrentWidth = null;
			}
		}

		document.body.removeChild(this.LeftResizer);
		document.body.removeChild(this.RightResizer);
		document.body.removeChild(this.ResizerToolTip);
	
		this.CanDestroy = false;
	}
};

RadGridNamespace.RadGridColumnResizer.prototype.Dispose = function()
{
	try
	{
		this.Destroy();
	}
	catch (error)
	{
	}
	
	this.DisposeDomEventHandlers();
	
	this.MouseUpHandler = null;
	this.MouseMoveHandler = null;
	
	this.LeftResizer = null;
	this.RightResizer = null;
	this.ResizerToolTip = null;
}

RadGridNamespace.RadGridColumnResizer.prototype.Move = function(e)
{
	this.LeftResizer.style.left = RadGridNamespace.FindPosX(this.Column.Control) - 
									RadGridNamespace.FindScrollPosX(this.Column.Control) + 
									document.documentElement.scrollLeft + 
									document.body.scrollLeft + "px";
									
	this.RightResizer.style.left = parseInt(this.LeftResizer.style.left) + (RadGridNamespace.GetEventPosX(e) - RadGridNamespace.FindPosX(this.Column.Control))+ "px";

	this.ResizerToolTip.style.left = parseInt(this.RightResizer.style.left) - 5 + "px";

	var width = parseInt(this.RightResizer.style.left) - parseInt(this.LeftResizer.style.left);
	
	var deltaWidth = this.Column.Control.scrollWidth - width;
	
	this.ResizerToolTip.innerHTML = "Width: <b>" + width + "</b> <em>pixels</em>";

	if (!RadGridNamespace.FireEvent(this.Column.Owner, "OnColumnResizing", [this.Column.Index, width]))
		return;

	if (width <= 0)
	{
		this.RightResizer.style.left = this.RightResizer.style.left;
		this.Destroy(e);
		return;
	}

	this.CurrentWidth = width;

	if (this.IsRealTimeResize)
	{	
	    this.Column.Owner.ResizeColumn(RadGridNamespace.GetRealCellIndex(this.Column.Owner, this.Column.Control), width);
	}
	else
	{
		this.CurrentWidth = width;
		return;
	}

	if(RadGridNamespace.FindPosX(this.LeftResizer) != RadGridNamespace.FindPosX(this.Column.Control))
	{
		this.LeftResizer.style.left =  RadGridNamespace.FindPosX(this.Column.Control) + "px";
	}

	if(RadGridNamespace.FindPosX(this.RightResizer) != (RadGridNamespace.FindPosX(this.Column.Control) + this.Column.Control.offsetWidth))
	{
		this.RightResizer.style.left =  RadGridNamespace.FindPosX(this.Column.Control) + this.Column.Control.offsetWidth + "px";
	}

	if(RadGridNamespace.FindPosY(this.LeftResizer) != RadGridNamespace.FindPosY(this.Column.Control))
	{
		this.LeftResizer.style.top =  RadGridNamespace.FindPosY(this.Column.Control) + "px";
		this.RightResizer.style.top =  RadGridNamespace.FindPosY(this.Column.Control) + "px";
	}

	if(this.LeftResizer.offsetHeight != this.Column.Control.offsetHeight)
	{
		this.LeftResizer.style.height = this.Column.Control.offsetHeight + "px";
		this.RightResizer.style.height = this.Column.Control.offsetHeight + "px";
	}
	
	if( this.Column.Owner.Owner.GridDataDiv)
	{
		 this.LeftResizer.style.left = parseInt(this.LeftResizer.style.left.replace("px","")) - this.Column.Owner.Owner.GridDataDiv.scrollLeft + "px";
		 this.RightResizer.style.left = parseInt(this.LeftResizer.style.left.replace("px","")) + this.Column.Control.offsetWidth + "px";
		 this.ResizerToolTip.style.left = parseInt(this.RightResizer.style.left) - 5 + "px";
	}
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY
RadGridNamespace.RadGridTableRow = function(object)
{
	if ((!object) || typeof(object) != "object")
		return;

	RadControlsNamespace.DomEventMixin.Initialize(this);
	
	for (var member in object)
	{
		this[member] = object[member];
	}

	this.Type = "RadGridTableRow";
	
	var table = document.getElementById(this.OwnerID);
	this.Control = table.tBodies[0].rows[this.ClientRowIndex];
	
	if(!this.Control)
	    return;

	this.Index = this.Control.sectionRowIndex;
	this.RealIndex = this.RowIndex;
};

RadGridNamespace.RadGridTableRow.prototype._constructor = function(owner)
{
	this.Owner = owner;

	this.CreateStyles();

	if (this.Selected)
	{
		this.LoadSelected();
	}
	
	if (this.Owner.HierarchyLoadMode == "Client")
	{
		if (this.Owner.Owner.ClientSettings.AllowExpandCollapse)
		{
					//alert(this.Owner.ExpandCollapseColumns.length);
			for(var i = 0; i < this.Owner.ExpandCollapseColumns.length; i++)
			{
				var index = this.Owner.ExpandCollapseColumns[i].Control.cellIndex;

				var control = this.Control.cells[index];

				if (!control)
					continue;

				var expandCollapseButton;

				for (var j = 0; j < control.childNodes.length; j++)
				{
					if (!control.childNodes[j].tagName)
						continue;

                    var tagName;
                    if(this.Owner.ExpandCollapseColumns[i].ButtonType == "ImageButton")
                    {
                        tagName = "img";
					}
					else if(this.Owner.ExpandCollapseColumns[i].ButtonType == "LinkButton")
					{
                        tagName = "a";
					}
					else if(this.Owner.ExpandCollapseColumns[i].ButtonType == "PushButton")
					{
					    tagName = "button";
					}

				    if (control.childNodes[j].tagName.toLowerCase() == tagName)
				    {
					    expandCollapseButton = control.childNodes[j];
					    break;
				    }
				}
				if (expandCollapseButton)
				{
					var thisObject = this;
					var expandCollapseButtonHandler = function()
					{
						thisObject.OnHierarchyExpandButtonClick(this);
					}
					
					expandCollapseButton.onclick = expandCollapseButtonHandler;
					expandCollapseButton.ondblclick = null;
					expandCollapseButtonHandler = null;
				}
				expandCollapseButton = null;
			}
		}
	}

	if (this.Owner.GroupLoadMode == "Client")
	{
		if (this.Owner.Owner.ClientSettings.AllowGroupExpandCollapse)
		{
			for(var i = 0; i < this.Owner.GroupSplitterColumns.length; i++)
			{
				var index = this.Owner.GroupSplitterColumns[i].Control.cellIndex;

				var control = this.Control.cells[index];

				if (!control)
					continue;

				var expandCollapseButton;

				for (var j = 0; j < control.childNodes.length; j++)
				{
					if (!control.childNodes[j].tagName)
						continue;
					if (control.childNodes[j].tagName.toLowerCase() == "img")
					{
						expandCollapseButton = control.childNodes[j];
						break;
					}
				}
				
				if (expandCollapseButton)
				{
					var thisObject = this;
					var expandCollapseButtonHandler = function()
					{
						thisObject.OnGroupExpandButtonClick(this);
					}

					expandCollapseButton.onclick = expandCollapseButtonHandler;
					expandCollapseButton.ondblclick = null;
					expandCollapseButtonHandler = null;
				}
				expandCollapseButton = null;
			}
		}
	}
	
	this.AttachDomEvent(this.Control, "click", "OnClick");
	this.AttachDomEvent(this.Control, "dblclick", "OnDblClick");
	this.AttachDomEvent(document, "mousedown", "OnMouseDown");
	this.AttachDomEvent(document, "mouseup", "OnMouseUp");
	this.AttachDomEvent(document, "mousemove", "OnMouseMove");
	this.AttachDomEvent(this.Control, "mouseover", "OnMouseOver");
	this.AttachDomEvent(this.Control, "mouseout", "OnMouseOut");
	this.AttachDomEvent(this.Control, "contextmenu", "OnContextMenu");
	
	if(this.Owner.Owner.ClientSettings.ActiveRowData && this.Owner.Owner.ClientSettings.ActiveRowData != "")
	{
		var data = this.Owner.Owner.ClientSettings.ActiveRowData.split(";")[0].split(",");
		if(data[0] == this.Owner.ClientID && data[1] == this.RealIndex)
		{
			this.Owner.Owner.ActiveRow = this;
		}
	}
};

RadGridNamespace.GroupRowExpander = function(startRow)
{
	this.startRow = startRow;
}

RadGridNamespace.GroupRowExpander.prototype.NotFinished = function(firstGroupHeader)
{
	var rowFound = (this.currentGridRow != null);
	if (!rowFound)
		return false;
		
	var rowHasNoGroup = (this.currentGridRow.GroupIndex == "");
	var rowIsInFirstGroup = (this.currentGridRow.GroupIndex == firstGroupHeader.GroupIndex);
	var rowIsSubgroupOfFirst = (this.currentGridRow.GroupIndex.indexOf(firstGroupHeader.GroupIndex + "_") == 0);
	
	return (rowHasNoGroup || rowIsInFirstGroup || rowIsSubgroupOfFirst);
}
RadGridNamespace.GroupRowExpander.prototype.ToggleExpandCollapse = function(expandCollapseButton)
{
	var startRow = this.startRow;
	var tableView = startRow.Owner;
	var groupHeaderRowIndex = expandCollapseButton.parentNode.parentNode.sectionRowIndex;
	var firstGroupHeader = tableView.Rows[groupHeaderRowIndex];

	if(firstGroupHeader.Expanded)
	{
        if (!RadGridNamespace.FireEvent(firstGroupHeader.Owner, "OnGroupCollapsing", [firstGroupHeader]))
		    return;
	}
	else
	{
        if (!RadGridNamespace.FireEvent(firstGroupHeader.Owner, "OnGroupExpanding", [firstGroupHeader]))
		    return;
	}
	
	
	var firstGroupChildRow = tableView.Control.rows[groupHeaderRowIndex + 1];

	if (!firstGroupChildRow)
		return;


	this.currentRowIndex = firstGroupChildRow.rowIndex;

	this.lastGroupIndex = null;
	while (true)
	{	
		this.currentGridRow = tableView.Rows[this.currentRowIndex];
		
		var notFinished = this.NotFinished(firstGroupHeader);
		if (!notFinished)
			break;
					
		var nestedOrLastGroup = (this.lastGroupIndex != null) && (this.currentGridRow.GroupIndex.indexOf(this.lastGroupIndex) != -1);
		var invisibleGroupHeader = (this.currentGridRow.ItemType != "GroupHeader") && (!this.currentGridRow.IsVisible());
		var invisibleSubGroup = nestedOrLastGroup && invisibleGroupHeader
							
		if(this.currentGridRow.ItemType == "GroupHeader" && !this.currentGridRow.Expanded)
		{
			if (this.currentGridRow.IsVisible())
			{
				this.currentGridRow.Hide();
				expandCollapseButton.src = tableView.GroupSplitterColumns[0].ExpandImageUrl;
				if (tableView.Rows[this.currentRowIndex+1] == null ||
					tableView.Rows[this.currentRowIndex+1].ItemType == "GroupHeader")
				{
					this.currentGridRow.Expanded = false;
				}
				
			}
			else
			{
				expandCollapseButton.src = tableView.GroupSplitterColumns[0].CollapseImageUrl;
				this.currentGridRow.Show();
				if (tableView.Rows[this.currentRowIndex+1] == null ||
					tableView.Rows[this.currentRowIndex+1].ItemType == "GroupHeader")
				{
					this.currentGridRow.Expanded = true;
				}
			}
			this.lastGroupIndex = this.currentGridRow.GroupIndex;
		}
		else if(!invisibleSubGroup)
		{
			if (this.currentGridRow.ItemType == "NestedView")
			{
				if (this.currentGridRow.Expanded)
				{
					if (this.currentGridRow.IsVisible())
						this.currentGridRow.Hide();
					else
						this.currentGridRow.Show();
				}
			}
			else
			{
				if (this.currentGridRow.IsVisible())
				{
					this.currentGridRow.Hide();
					expandCollapseButton.src = tableView.GroupSplitterColumns[0].ExpandImageUrl;
					firstGroupHeader.Expanded = false;
					
				}
				else
				{
					expandCollapseButton.src = tableView.GroupSplitterColumns[0].CollapseImageUrl;
					this.currentGridRow.Show();
					
					firstGroupHeader.Expanded = true;
				}
			}
		}
		
		this.currentRowIndex++;
	}
	
	if (firstGroupHeader.Expanded != null)
	{
		if (firstGroupHeader.Expanded)
		{
			tableView.Owner.SavePostData("ExpandedGroupRows", tableView.ClientID, firstGroupHeader.RealIndex);
			startRow.title = tableView.Owner.GroupingSettings.CollapseTooltip;
		}
		else
		{
			tableView.Owner.SavePostData("CollapsedGroupRows", tableView.ClientID, firstGroupHeader.RealIndex);
			startRow.title = tableView.Owner.GroupingSettings.ExpandTooltip;
		}
	}
	
	if(firstGroupHeader.Expanded)
	{
        if (!RadGridNamespace.FireEvent(firstGroupHeader.Owner, "OnGroupExpanded", [firstGroupHeader]))
		    return;
	}
	else
	{
        if (!RadGridNamespace.FireEvent(firstGroupHeader.Owner, "OnGroupCollapsed", [firstGroupHeader]))
		    return;
	}

}

RadGridNamespace.RadGridTableRow.prototype.OnGroupExpandButtonClick = function(expandCollapseButton)
{
	var expander = new RadGridNamespace.GroupRowExpander(this);
	expander.ToggleExpandCollapse(expandCollapseButton);
}

RadGridNamespace.RadGridTableRow.prototype.OnHierarchyExpandButtonClick = function(expandCollapseButton)
{
	var nestedViewRow = this.Owner.Control.rows[expandCollapseButton.parentNode.parentNode.rowIndex+1];
	var nestedViewObject = this.Owner.Rows[expandCollapseButton.parentNode.parentNode.sectionRowIndex];

	if (!nestedViewRow)
		return;

	if (this.TableRowIsVisible(nestedViewRow))
	{
	    if (!RadGridNamespace.FireEvent(this.Owner, "OnHierarchyCollapsing", [this]))
			return;

		this.HideTableRow(nestedViewRow);
		nestedViewObject.Expanded = false;
		
		if(this.Owner.ExpandCollapseColumns[0].ButtonType == "ImageButton")
		{
		    expandCollapseButton.src = this.Owner.ExpandCollapseColumns[0].ExpandImageUrl;
		}
		else
		{
		    expandCollapseButton.innerHTML = "+";
		}
		    expandCollapseButton.title = this.Owner.Owner.HierarchySettings.ExpandTooltip;
		
		this.Owner.Owner.SavePostData("CollapsedRows", this.Owner.ClientID, this.RealIndex);
		
	    if (!RadGridNamespace.FireEvent(this.Owner, "OnHierarchyCollapsed", [this]))
			return;
	}
	else
	{
	    if (!RadGridNamespace.FireEvent(this.Owner, "OnHierarchyExpanding", [this]))
			return;
	
		if(this.Owner.ExpandCollapseColumns[0].ButtonType == "ImageButton")
		{
			expandCollapseButton.src = this.Owner.ExpandCollapseColumns[0].CollapseImageUrl;
		}
		else
		{
		    expandCollapseButton.innerHTML = "-";
		}
			expandCollapseButton.title = this.Owner.Owner.HierarchySettings.CollapseTooltip;

		this.ShowTableRow(nestedViewRow);
		nestedViewObject.Expanded = true;
		this.Owner.Owner.SavePostData("ExpandedRows", this.Owner.ClientID, this.RealIndex);
		
		if (!RadGridNamespace.FireEvent(this.Owner, "OnHierarchyExpanded", [this]))
			return;
	}
};

RadGridNamespace.RadGridTableRow.prototype.TableRowIsVisible = function(rowElement)
{
	return rowElement.style.display != "none";
}

RadGridNamespace.RadGridTableRow.prototype.IsVisible = function()
{
	return this.TableRowIsVisible(this.Control);
}

RadGridNamespace.RadGridTableRow.prototype.HideTableRow = function(rowElement)
{
	if (this.TableRowIsVisible(rowElement))
	{
		rowElement.style.display = "none";
	}
}

RadGridNamespace.RadGridTableRow.prototype.Hide = function()
{
	this.HideTableRow(this.Control);
}

RadGridNamespace.RadGridTableRow.prototype.ShowTableRow = function(rowElement)
{
	if (window.netscape || window.opera)
	{
		rowElement.style.display = "table-row";
	}
	else
	{
		rowElement.style.display = "block";
	}
}

RadGridNamespace.RadGridTableRow.prototype.Show = function()
{
	this.ShowTableRow(this.Control);
}

RadGridNamespace.RadGridTableRow.prototype.Dispose = function()
{
	this.DisposeDomEventHandlers();

	this.Control = null;
	this.Owner = null;
}

RadGridNamespace.RadGridTableRow.prototype.CreateStyles = function()
{
	if (!this.Owner.Owner.ClientSettings.ApplyStylesOnClient)
		return;
//debugger;
	switch(this.ItemType)
	{
		case "GroupHeader":
		{
			//for (var i = 0; i < this.Control.cells.length; i++)
				//this.Control.cells[i].style.cssText = this.Owner.RenderGroupHeaderItemStyle;
			//	this.Control.cells[0].style.cssText = this.Owner.RenderGroupHeaderItemStyle;
			break;
		}
		case "EditFormItem":
		{
			this.Control.className += " " +  this.Owner.RenderEditItemStyleClass;
			this.Control.style.cssText += " " +  this.Owner.RenderEditItemStyle;
			break;
		}
		default:
		{
		    var styleClass = eval("this.Owner.Render" + this.ItemType + "StyleClass");
		    if(typeof(styleClass) != "undefined")
		    {
			    this.Control.className += " " + styleClass;
			}
		    var style = eval("this.Owner.Render" + this.ItemType + "Style");
		    if(typeof(style) != "undefined")
		    {
			    this.Control.style.cssText += " " + style;
			}
			break;
		}
	}
	
	if (!this.Display)
	{
		if (this.Control.style.cssText != "")
		{
			if (this.Control.style.cssText.lastIndexOf(";") == this.Control.style.cssText.length - 1)
			{
				this.Control.style.cssText += "display:none;"
			
			}
			else
			{
				this.Control.style.cssText += ";display:none;"
			}
		}
		else
		{
			this.Control.style.cssText += "display:none;"
		}
	}
};

RadGridNamespace.RadGridTableRow.prototype.OnContextMenu = function(e)
{
	try
	{
		if (!RadGridNamespace.FireEvent(this.Owner, "OnRowContextMenu", [this.Index, e]))
			return;

		if(this.Owner.Owner.ClientSettings.ClientEvents.OnRowContextMenu != "")
		{
			if(e.preventDefault)
			{
				e.preventDefault();
			}
			else
			{
				e.returnValue = false;
				return false;
			}
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.Owner.OnError);
	}
};

RadGridNamespace.RadGridTableRow.prototype.OnClick = function(e)
{
	try
	{
		if (this.Owner.Owner.RowResizer)
			return;

		if (!RadGridNamespace.FireEvent(this.Owner, "OnRowClick", [this.Control.sectionRowIndex, e]))
			return;

		if(e.shiftKey && this.Owner.SelectedRows[0])
		{
		    if(this.Owner.SelectedRows[0].Control.rowIndex > this.Control.rowIndex)
		    {
			    for (var i=this.Control.rowIndex; i < this.Owner.SelectedRows[0].Control.rowIndex + 1; i++)
			    {
				    var currentRow = this.Owner.Owner.GetRowObjectByRealRow(this.Owner, this.Owner.Control.rows[i]);
				    if (currentRow)
				    {
				        if (!currentRow.Selected)
					        this.Owner.SelectRow(this.Owner.Control.rows[i], false);
				    }
			    }
		    }

		    if(this.Owner.SelectedRows[0].Control.rowIndex < this.Control.rowIndex)
		    {
			    for (var i=this.Owner.SelectedRows[0].Control.rowIndex; i < this.Control.rowIndex + 1; i++)
			    {
				    var currentRow = this.Owner.Owner.GetRowObjectByRealRow(this.Owner, this.Owner.Control.rows[i]);
				    if (currentRow)
				    {
				        if (!currentRow.Selected)
					        this.Owner.SelectRow(this.Owner.Control.rows[i], false);
				    }
			    }
		    }
		}
		
		if(!e.shiftKey)
		{
			this.HandleRowSelection(e);
		}


		var currentElement = RadGridNamespace.GetCurrentElement(e);
		
		if(!currentElement)
		    return;
		
		if(!currentElement.tagName)
		    return;

		if(currentElement.tagName.toLowerCase() == "input" 
		    && currentElement.tagName.toLowerCase() == "select"
		    && currentElement.tagName.toLowerCase() == "option"
		    && currentElement.tagName.toLowerCase() == "button"
		    && currentElement.tagName.toLowerCase() == "a"
		    && currentElement.tagName.toLowerCase() == "textarea"
		    )
		    return;

		if(this.ItemType == "Item" || this.ItemType == "AlternatingItem")
		{
		    if(this.Owner.Owner.ClientSettings.EnablePostBackOnRowClick)
		    {
		      	var postBackFunc = this.Owner.Owner.ClientSettings.PostBackFunction;
		        postBackFunc = postBackFunc.replace("{0}", this.Owner.Owner.UniqueID).replace("{1}","RowClick;" + this.ItemIndexHierarchical);

                //do we already have a __doPostBack-originated postback in progress?
                var form = document.getElementById(this.Owner.Owner.FormID);
                if (form != null && form["__EVENTTARGET"] != null && form["__EVENTTARGET"].value == "")
                {
                    eval(postBackFunc);
                }

		    }
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.Owner.OnError);
	}
};

RadGridNamespace.RadGridTableRow.prototype.HandleActiveRow = function(e)
{
	var currentElement = RadGridNamespace.GetCurrentElement(e);
	if(currentElement != null && currentElement.tagName && (currentElement.tagName.toLowerCase() == "input" || currentElement.tagName.toLowerCase() == "textarea"))
	{
		return;
	}

	if(this.Owner.Owner.ActiveRow != null)
	{
		if (!RadGridNamespace.FireEvent(this.Owner, "OnActiveRowChanging", [this.Owner.Owner.ActiveRow]))
			return;

		if (e.keyCode==13)
		{
			this.Owner.Owner.SavePostData("EditRow", this.Owner.ClientID, this.Owner.Owner.ActiveRow.RealIndex);
			//alert(1);
			eval(this.Owner.Owner.ClientSettings.PostBackReferences.PostBackEditRow);
		}

		if (e.keyCode==40)
		{
			var nextRow = this.Owner.Rows[this.Owner.Owner.ActiveRow.Control.sectionRowIndex + 1];
			if (nextRow != null)
			{
				this.Owner.Owner.SetActiveRow(nextRow);
				this.ScrollIntoView(nextRow);
			}
		}

		if (e.keyCode==39)
		{return;
			var nextRow = this.Owner.Owner.GetNextHierarchicalRow(table, this.Owner.Owner.ActiveRow.Control.sectionRowIndex);

			if (nextRow != null)
			{
				table = nextRow.parentNode.parentNode;
				this.Owner.Owner.SetActiveRow(table, nextRow.sectionRowIndex);
				this.ScrollIntoView(nextRow);
			}
		}

		if (e.keyCode==38)
		{
			var prevRow = this.Owner.Rows[this.Owner.Owner.ActiveRow.Control.sectionRowIndex - 1];
			
			if (prevRow != null)
			{
				this.Owner.Owner.SetActiveRow(prevRow);
				this.ScrollIntoView(prevRow);
			}
		}

		if (e.keyCode==37)
		{return;
			var prevRow = this.Owner.Owner.GetPreviousHierarchicalRow(table, this.Owner.Owner.ActiveRow.Control.sectionRowIndex);
			
			if (prevRow != null) 
			{
				var table = prevRow.parentNode.parentNode;
				
				this.Owner.Owner.SetActiveRow(table, prevRow.sectionRowIndex);
				this.ScrollIntoView(prevRow);
			}
		}

		if (e.keyCode==32)
		{
			if(this.Owner.Owner.ClientSettings.Selecting.AllowRowSelect)
			{
				this.Owner.Owner.ActiveRow.Owner.SelectRow(this.Owner.Owner.ActiveRow.Control, !this.Owner.Owner.AllowMultiRowSelection);
			}
		}
		
	}
	
	if (window.netscape)
	{
		e.preventDefault();
		return false;
	}
	else
	{	
		e.returnValue = false;
	}
	
	RadGridNamespace.FireEvent(this.Owner, "OnActiveRowChanged", [this.Owner.Owner.ActiveRow])
};

RadGridNamespace.RadGridTableRow.prototype.ScrollIntoView = function(row)
{
	if(row.Control && row.Control.focus)
	{
		row.Control.scrollIntoView(false);
		try
		{
	        row.Control.focus();
		}
		catch(e)
		{
		    //
		}
	}
};

RadGridNamespace.RadGridTableRow.prototype.HandleExpandCollapse = function()
{

};

RadGridNamespace.RadGridTableRow.prototype.HandleGroupExpandCollapse = function()
{

};

RadGridNamespace.RadGridTableRow.prototype.HandleRowSelection = function(e)
{
	var currentElement = RadGridNamespace.GetCurrentElement(e);

	if (currentElement.onclick)
	{
		return;
	}

	if (currentElement.tagName.toLowerCase() == "a" && currentElement.tagName.toLowerCase() == "img" || currentElement.tagName.toLowerCase() == "input")
	{
		return;
	}

	this.SetSelected(!e.ctrlKey);
};

RadGridNamespace.RadGridTableRow.prototype.CheckClientSelectColumns = function()
{
    if(!this.Owner.Columns)
        return;

	for (var i = 0; i < this.Owner.Columns.length; i++)
	{
		if (this.Owner.Columns[i].ColumnType == "GridClientSelectColumn")
		{
			var cell = this.Owner.GetCellByColumnUniqueName(this, this.Owner.Columns[i].UniqueName);
			if(cell != null)
			{
				var checkBox = cell.getElementsByTagName("input")[0];
				if(checkBox != null)
				{
					checkBox.checked = this.Selected;
					//checkBox.click();
				}
			}
		}
	}
};

RadGridNamespace.RadGridTableRow.prototype.SetSelected = function(singleSelection)
{
	if(!this.Selected)
	{
		if (!RadGridNamespace.FireEvent(this.Owner, "OnRowSelecting", [this]))
			return;
	}
	
	if ((this.ItemType == "Item") || (this.ItemType == "AlternatingItem"))
	{
		if (singleSelection)
		{
			this.SingleSelect();
		}
		else
		{
			this.MultiSelect();
		}
		
	}

	this.CheckClientSelectColumns();

	if(this.Selected)
	{
		if (!RadGridNamespace.FireEvent(this.Owner, "OnRowSelected", [this]))
			return;
	}
};

RadGridNamespace.RadGridTableRow.prototype.SingleSelect = function()
{
	if (!this.Owner.Owner.ClientSettings.Selecting.AllowRowSelect)
		return;

	this.Owner.ClearSelectedRows();
	this.Owner.Owner.ClearSelectedRows();
	this.Selected = true;
	this.ApplySelectedRowStyle();
	this.Owner.AddToSelectedRows(this);
	var selectedIndexes = this.Owner.GetSelectedRowsIndexes();
	this.Owner.Owner.SavePostData("SelectedRows", this.Owner.ClientID, selectedIndexes);
};

RadGridNamespace.RadGridTableRow.prototype.SingleDeselect = function()
{
	if (!this.Owner.Owner.ClientSettings.Selecting.AllowRowSelect)
		return;

	this.Owner.ClearSelectedRows();
	this.Owner.Owner.ClearSelectedRows();
	this.Selected = false;
	this.RemoveSelectedRowStyle();
	this.Owner.RemoveFromSelectedRows(this);
	var selectedIndexes = this.Owner.GetSelectedRowsIndexes();
	this.Owner.Owner.SavePostData("SelectedRows", this.Owner.ClientID, selectedIndexes);
};

RadGridNamespace.RadGridTableRow.prototype.MultiSelect = function()
{
	if ((!this.Owner.Owner.ClientSettings.Selecting.AllowRowSelect) ||
		(!this.Owner.Owner.AllowMultiRowSelection))
		return;

	if (this.Selected)
	{
		    if (!RadGridNamespace.FireEvent(this.Owner, "OnRowDeselecting", [this]))
		    {
			    return;
		    }

			this.Selected = false;
			this.RemoveSelectedRowStyle();
			this.Owner.RemoveFromSelectedRows(this);
			var selectedIndexes = this.Owner.GetSelectedRowsIndexes();
			this.Owner.Owner.SavePostData("SelectedRows", this.Owner.ClientID, selectedIndexes);
	}
	else
	{
			this.Selected = true;
			this.ApplySelectedRowStyle();
			this.Owner.AddToSelectedRows(this);
			var selectedIndexes = this.Owner.GetSelectedRowsIndexes();
			this.Owner.Owner.SavePostData("SelectedRows", this.Owner.ClientID, selectedIndexes);
	}
};

RadGridNamespace.RadGridTableRow.prototype.LoadSelected = function()
{
	this.ApplySelectedRowStyle();
	this.Owner.AddToSelectedRows(this);
};

RadGridNamespace.RadGridTableRow.prototype.ApplySelectedRowStyle = function()
{
	if(!this.Owner.SelectedItemStyleClass || this.Owner.SelectedItemStyleClass == "")
	{
		if (this.Owner.SelectedItemStyle && this.Owner.SelectedItemStyle != "")
		{
			RadGridNamespace.addClassName(this.Control, "SelectedItemStyle" + this.Owner.ClientID + "1");
		}
		else
		{
			RadGridNamespace.addClassName(this.Control, "SelectedItemStyle" + this.Owner.ClientID + "2");
		}
	}
	else
	{
		RadGridNamespace.addClassName(this.Control, this.Owner.SelectedItemStyleClass);
	}
};


RadGridNamespace.RadGridTableRow.prototype.RemoveSelectedRowStyle = function()
{
	if (this.Owner.SelectedItemStyle)
	{
		RadGridNamespace.removeClassName(this.Control, "SelectedItemStyle" + this.Owner.ClientID + "1");
	}
	else
	{
		RadGridNamespace.removeClassName(this.Control, "SelectedItemStyle" + this.Owner.ClientID + "2");
	}

	RadGridNamespace.removeClassName(this.Control, this.Owner.SelectedItemStyleClass);

	if (this.Control.style.cssText == this.Owner.SelectedItemStyle)
	{
		this.Control.style.cssText = "";
	}
};

RadGridNamespace.RadGridTableRow.prototype.OnDblClick = function(e)
{
	try
	{
		if (!RadGridNamespace.FireEvent(this.Owner, "OnRowDblClick", [this.Control.sectionRowIndex, e]))
			return;
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.Owner.OnError);
	}
};

RadGridNamespace.RadGridTableRow.prototype.CreateRowSelectorArea = function(e)
{
	if ((this.Owner.Owner.RowResizer) || (e.ctrlKey))
		return;

	var clickedObject = null;
	if (e.srcElement)
	{
		clickedObject = e.srcElement;
	}
	else if (e.target)
	{
		clickedObject = e.target;
	}
	
	if (!clickedObject.tagName)
		return;

	if (clickedObject.tagName.toLowerCase() == "input")
		return;

	if ((!this.Owner.Owner.ClientSettings.Selecting.AllowRowSelect) ||
		(!this.Owner.Owner.AllowMultiRowSelection))
		return;
		
	var currentElement = RadGridNamespace.GetCurrentElement(e);

	if ((!currentElement) || 
		(!RadGridNamespace.IsChildOf(currentElement, this.Control)))
		return;

	if (!this.RowSelectorArea)
	{
		this.RowSelectorArea = document.createElement("span"); 
		this.RowSelectorArea.style.backgroundColor = "navy";
		this.RowSelectorArea.style.border = "indigo 1px solid";
		this.RowSelectorArea.style.position = "absolute";
		this.RowSelectorArea.style.font = "icon";

		if (window.netscape && !window.opera)
		{
			this.RowSelectorArea.style.MozOpacity = 1/10;
		}
		else if(window.opera || navigator.userAgent.indexOf("Safari") > -1)
		{
			this.RowSelectorArea.style.opacity  = 0.1;
		}
		else
		{
			this.RowSelectorArea.style.filter = "alpha(opacity=10);";
		}

		if (this.Owner.Owner.GridDataDiv)
		{
			this.RowSelectorArea.style.top = RadGridNamespace.FindPosY(this.Control) - 
				this.Owner.Owner.GridDataDiv.scrollTop + "px";
			this.RowSelectorArea.style.left = RadGridNamespace.FindPosX(this.Control) - 
				this.Owner.Owner.GridDataDiv.scrollLeft  + "px";
				
			if (parseInt(this.RowSelectorArea.style.left) < RadGridNamespace.FindPosX(this.Owner.Owner.Control))
			{
				this.RowSelectorArea.style.left = RadGridNamespace.FindPosX(this.Owner.Owner.Control)  + "px";
			}
		}
		else
		{
			this.RowSelectorArea.style.top = RadGridNamespace.FindPosY(this.Control)  + "px";
			this.RowSelectorArea.style.left = RadGridNamespace.FindPosX(this.Control)  + "px";
		}

		document.body.appendChild(this.RowSelectorArea);

		this.FirstRow = this.Control;

		RadGridNamespace.ClearDocumentEvents();
	}
};

RadGridNamespace.RadGridTableRow.prototype.DestroyRowSelectorArea = function(e)
{
	if (this.RowSelectorArea)
	{
	    var height = this.RowSelectorArea.style.height;
		document.body.removeChild(this.RowSelectorArea);
		this.RowSelectorArea = null;
		RadGridNamespace.RestoreDocumentEvents();

		var currentElement = RadGridNamespace.GetCurrentElement(e);
		var lastRow;

		if ((!currentElement) || 
			(!RadGridNamespace.IsChildOf(currentElement, this.Owner.Control)))
			return;

		if ((currentElement.tagName.toLowerCase() == "td") || 
			(currentElement.tagName.toLowerCase() == "tr"))
		{
			if (currentElement.tagName.toLowerCase() == "td")
			{
				lastRow = currentElement.parentNode;
			}
			else if(currentElement.tagName.toLowerCase() == "tr")
			{
				lastRow = currentElement;
			}

			for (var i=this.FirstRow.rowIndex;i<lastRow.rowIndex+1;i++)
			{
				var currentRow = this.Owner.Owner.GetRowObjectByRealRow(this.Owner, this.Owner.Control.rows[i]);
				if (currentRow)
				{
				    if(height != "")
				    {
					    if (!currentRow.Selected)
						    this.Owner.SelectRow(this.Owner.Control.rows[i], false);
					}
				}
			}
		}
	}
};

RadGridNamespace.RadGridTableRow.prototype.ResizeRowSelectorArea = function(e)
{
	if ((this.RowSelectorArea) && (this.RowSelectorArea.parentNode))
	{
		var currentElement = RadGridNamespace.GetCurrentElement(e);

		if ((!currentElement) || 
			(!RadGridNamespace.IsChildOf(currentElement, this.Owner.Control)))
			return;

		var oldPosX = parseInt(this.RowSelectorArea.style.left);
		
		if (this.Owner.Owner.GridDataDiv)
		{
			var newPosX = RadGridNamespace.GetEventPosX(e) - 
				this.Owner.Owner.GridDataDiv.scrollLeft;
		}
		else
		{
			var newPosX = RadGridNamespace.GetEventPosX(e);
		}

		var oldPosY = parseInt(this.RowSelectorArea.style.top);

		if (this.Owner.Owner.GridDataDiv)
		{
			var newPosY = RadGridNamespace.GetEventPosY(e) -
				this.Owner.Owner.GridDataDiv.scrollTop;
		}
		else
		{
			var newPosY = RadGridNamespace.GetEventPosY(e);
		}
		

		if ((newPosX - oldPosX - 5) > 0)
			this.RowSelectorArea.style.width = newPosX - oldPosX - 5 + "px";
		if ((newPosY - oldPosY - 5) > 0)
			this.RowSelectorArea.style.height = newPosY - oldPosY - 5 + "px";

		if (this.RowSelectorArea.offsetWidth > this.Owner.Control.offsetWidth)
		{
			this.RowSelectorArea.style.width = this.Owner.Control.offsetWidth + "px";
		}

		var maxHeight = (RadGridNamespace.FindPosX(this.Owner.Control) + this.Owner.Control.offsetHeight) - 
						parseInt(this.RowSelectorArea.style.top); 

		if (this.RowSelectorArea.offsetHeight > maxHeight)
		{
			if (maxHeight > 0)
			{
				this.RowSelectorArea.style.height = maxHeight + "px";
			}
		}
	}
};

RadGridNamespace.RadGridTableRow.prototype.OnMouseDown = function(e)
{	
	if (this.Owner.Owner.ClientSettings.Selecting.EnableDragToSelectRows
		&& this.Owner.Owner.AllowMultiRowSelection)
	{
		if (!this.Owner.Owner.RowResizer)
			this.CreateRowSelectorArea(e);
	}
};

RadGridNamespace.RadGridTableRow.prototype.OnMouseUp = function(e)
{
	//if (!this.Owner.Owner.RowResizer)
		this.DestroyRowSelectorArea(e);
};

RadGridNamespace.RadGridTableRow.prototype.OnMouseMove = function(e)
{
	//if (!this.Owner.Owner.RowResizer)
		this.ResizeRowSelectorArea(e);
};

RadGridNamespace.RadGridTableRow.prototype.OnMouseOver = function(e)
{	
	if (!RadGridNamespace.FireEvent(this.Owner, "OnRowMouseOver", [this.Control.sectionRowIndex, e]))
		return;
};

RadGridNamespace.RadGridTableRow.prototype.OnMouseOut = function(e)
{
	if (!RadGridNamespace.FireEvent(this.Owner, "OnRowMouseOut", [this.Control.sectionRowIndex, e]))
		return;
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY
RadGridNamespace.RadGridGroupPanel = function (htmlElement, owner)
{
	this.Control = htmlElement;

	this.Owner = owner;

	this.Items = new Array();

	this.groupPanelItemCounter = 0;
	this.getGroupPanelItems(this.Control, 0);

	var thisObject = this;
};

RadGridNamespace.RadGridGroupPanel.prototype.Dispose = function()
{
	this.UnLoadHandler = null;
	this.Control = null;
	this.Owner = null;
	
	this.DisposeItems();
	
	for (var member in this)
	{
		this[member] = null;
	}
}

RadGridNamespace.RadGridGroupPanel.prototype.DisposeItems = function()
{
	if (this.Items != null)
	{
		for (var i = 0; i < this.Items.length; i++)
		{
			var item = this.Items[i];
			item.Dispose();
		}
	}
}


RadGridNamespace.RadGridGroupPanel.prototype.groupPanelItemCounter = 0;

RadGridNamespace.RadGridGroupPanel.prototype.getGroupPanelItems = function (table)
{
	for(var i = 0; i < table.rows.length; i++)
	{
		var foundItemsOnThisRow = false;
		var row = table.rows[i];

		for(var j = 0; j < row.cells.length; j++)
		{
			var cell = row.cells[j];

			if (cell.tagName.toLowerCase() == "th")
			{
				var hierarchicalIndex;
				if (this.Owner.GroupPanel.GroupPanelItems[this.groupPanelItemCounter])
				{
					hierarchicalIndex = this.Owner.GroupPanel.GroupPanelItems[this.groupPanelItemCounter].HierarchicalIndex;
				}
				
				if (hierarchicalIndex)
				{
					this.Items[this.Items.length] = new RadGridNamespace.RadGridGroupPanelItem(cell, this, hierarchicalIndex);
					foundItemsOnThisRow = true;
					this.groupPanelItemCounter++;
				}
			}

			if ((cell.firstChild) && (cell.firstChild.tagName))
			{
				if (cell.firstChild.tagName.toLowerCase() == "table")
				{
					this.getGroupPanelItems(cell.firstChild);
				}
			}
		}		
	}
};

RadGridNamespace.RadGridGroupPanel.prototype.IsItem = function (element)
{
	for (var i = 0; i < this.Items.length; i++)
	{
		if (this.Items[i].Control == element)
			return this.Items[i];
	}
	return null;
};

RadGridNamespace.RadGridGroupPanelItem = function (htmlElement, owner, hierarchicalIndex)
{
	RadControlsNamespace.DomEventMixin.Initialize(this);
	
	this.Control = htmlElement;

	this.Owner = owner;

	this.HierarchicalIndex = hierarchicalIndex;

	this.Control.style.cursor = "move";

	this.AttachDomEvent(this.Control, "mousedown", "OnMouseDown");
};

RadGridNamespace.RadGridGroupPanelItem.prototype.Dispose = function()
{
	this.DisposeDomEventHandlers();
	
	for (var member in this)
	{
		this[member] = null;
	}
	
	this.Control = null;
	this.Owner = null;
}

RadGridNamespace.RadGridGroupPanelItem.prototype.OnMouseDown = function (e)
{
	if (((window.netscape || window.opera) && (e.button == 0)) || (e.button == 1))
	{
		this.CreateDragDrop(e);
		this.CreateReorderIndicators(this.Control);
		this.AttachDomEvent(document, "mouseup", "OnMouseUp");
		this.AttachDomEvent(document, "mousemove", "OnMouseMove");
	}
};

RadGridNamespace.RadGridGroupPanelItem.prototype.OnMouseUp = function (e)
{
	this.FireDropAction(e);
	this.DestroyDragDrop(e);
	this.DestroyReorderIndicators();
	
	this.DetachDomEvent(document, "mouseup", "OnMouseUp");
	this.DetachDomEvent(document, "mousemove", "OnMouseMove");
};

RadGridNamespace.RadGridGroupPanelItem.prototype.OnMouseMove = function (e)
{
	this.MoveDragDrop(e);
};

RadGridNamespace.RadGridGroupPanelItem.prototype.FireDropAction = function (e)
{
	var currentElement = RadGridNamespace.GetCurrentElement(e);
	if (currentElement != null)
	{
		if (!RadGridNamespace.IsChildOf(currentElement,this.Owner.Control))
		{
			this.Owner.Owner.SavePostData("UnGroupByExpression", this.HierarchicalIndex);
			eval(this.Owner.Owner.ClientSettings.PostBackReferences.PostBackUnGroupByExpression);
		}
		else
		{
			var item = this.Owner.IsItem(currentElement);
			if ((currentElement != this.Control) &&
				(item != null) &&
				(currentElement.parentNode == this.Control.parentNode))
			{
				this.Owner.Owner.SavePostData("ReorderGroupByExpression", this.HierarchicalIndex, item.HierarchicalIndex);
				eval(this.Owner.Owner.ClientSettings.PostBackReferences.PostBackReorderGroupByExpression);
			}

			if (window.netscape)
			{
				this.Control.style.MozOpacity = 4/4;
			}
			else
			{
				this.Control.style.filter = "alpha(opacity=100);";
				
			}
		}
	}
};

RadGridNamespace.RadGridGroupPanelItem.prototype.CreateDragDrop = function (e)
{
	this.MoveHeaderDiv = document.createElement("div");

	var table = document.createElement("table");

	if (this.MoveHeaderDiv.mergeAttributes)
	{
		this.MoveHeaderDiv.mergeAttributes(this.Owner.Owner.Control);
	}
	else
	{
		RadGridNamespace.CopyAttributes(this.MoveHeaderDiv, this.Control);
	}

	if (table.mergeAttributes)
	{
		table.mergeAttributes(this.Owner.Control);
	}
	else
	{
		RadGridNamespace.CopyAttributes(table, this.Owner.Control);
	}

	table.style.margin = "0px";
	table.style.height = this.Control.offsetHeight + "px";
	table.style.width = this.Control.offsetWidth + "px";
	
	table.style.border = "0px";
	table.style.borderCollapse = "collapse";
	table.style.padding = "0px";
	
	var tHead = document.createElement("thead");
	var tr = document.createElement("tr");
	
	table.appendChild(tHead);
	tHead.appendChild(tr);
	tr.appendChild(this.Control.cloneNode(true));
	this.MoveHeaderDiv.appendChild(table);
	
	document.body.appendChild(this.MoveHeaderDiv);

	this.MoveHeaderDiv.style.height = table.style.height;
	this.MoveHeaderDiv.style.width = table.style.width;
	
	this.MoveHeaderDiv.style.position = "absolute";

	RadGridNamespace.RadGrid.PositionDragElement(this.MoveHeaderDiv, e);

	if (window.netscape)
	{
		this.MoveHeaderDiv.style.MozOpacity = 3/4;
	}
	else
	{
		this.MoveHeaderDiv.style.filter = "alpha(opacity=75);";
		
	}
	
	this.MoveHeaderDiv.style.cursor = "move";
	
	this.MoveHeaderDiv.style.display = "none";
	
	this.MoveHeaderDiv.onmousedown = null;
	
	RadGridNamespace.ClearDocumentEvents();
};

RadGridNamespace.RadGridGroupPanelItem.prototype.DestroyDragDrop = function (e)
{
	if (this.MoveHeaderDiv != null)
	{
		var parentNode = this.MoveHeaderDiv.parentNode;
		parentNode.removeChild(this.MoveHeaderDiv);
		this.MoveHeaderDiv.onmouseup = null;
		this.MoveHeaderDiv.onmousemove = null;
		this.MoveHeaderDiv = null;
		RadGridNamespace.RestoreDocumentEvents();
	}
};

RadGridNamespace.RadGridGroupPanelItem.prototype.MoveDragDrop = function (e)
{
	if (this.MoveHeaderDiv != null)
	{
		if (window.netscape)
		{
			this.Control.style.MozOpacity = 1/4;
		}
		else
		{
			this.Control.style.filter = "alpha(opacity=25);";
		}
		
		this.MoveHeaderDiv.style.visibility = "";
		this.MoveHeaderDiv.style.display = "";

		RadGridNamespace.RadGrid.PositionDragElement(this.MoveHeaderDiv, e);

		var currentElement = RadGridNamespace.GetCurrentElement(e);

		if (currentElement != null)
		{
			if (RadGridNamespace.IsChildOf(currentElement,this.Owner.Control))
			{
				var item = this.Owner.IsItem(currentElement);
				if ((currentElement != this.Control) &&
					(item != null) &&
					(currentElement.parentNode == this.Control.parentNode))
				{
					this.MoveReorderIndicators(e, currentElement);
				}
				else
				{
					this.ReorderIndicator1.style.visibility = "hidden";
					this.ReorderIndicator1.style.display = "none";
					this.ReorderIndicator1.style.position = "absolute";

					this.ReorderIndicator2.style.visibility = this.ReorderIndicator1.style.visibility;
					this.ReorderIndicator2.style.display = this.ReorderIndicator1.style.display;
					this.ReorderIndicator2.style.position = this.ReorderIndicator1.style.position;
				}

			}
		}
	
	}
};


RadGridNamespace.RadGridGroupPanelItem.prototype.CreateReorderIndicators = function (currentElement)
{
	if ((this.ReorderIndicator1 == null) && (this.ReorderIndicator2 == null))
	{
		this.ReorderIndicator1 = document.createElement("span"); 
		this.ReorderIndicator2 = document.createElement("span"); 

		this.ReorderIndicator1.innerHTML = "&darr;"; 
		this.ReorderIndicator2.innerHTML = "&uarr;"; 

		this.ReorderIndicator1.style.backgroundColor = "transparent";
		this.ReorderIndicator1.style.color = "darkblue";
		this.ReorderIndicator1.style.font = "bold 18px Arial";

		this.ReorderIndicator2.style.backgroundColor = this.ReorderIndicator1.style.backgroundColor;
		this.ReorderIndicator2.style.color = this.ReorderIndicator1.style.color;
		this.ReorderIndicator2.style.font = this.ReorderIndicator1.style.font;

		this.ReorderIndicator1.style.top = RadGridNamespace.FindPosY(currentElement) - this.ReorderIndicator1.offsetHeight + "px";
		this.ReorderIndicator1.style.left = RadGridNamespace.FindPosX(currentElement) + "px";

		this.ReorderIndicator2.style.top = RadGridNamespace.FindPosY(currentElement) + currentElement.offsetHeight + "px";
		this.ReorderIndicator2.style.left = this.ReorderIndicator1.style.left;

		this.ReorderIndicator1.style.visibility = "hidden";
		this.ReorderIndicator1.style.display = "none";
		this.ReorderIndicator1.style.position = "absolute";

		this.ReorderIndicator2.style.visibility = this.ReorderIndicator1.style.visibility;
		this.ReorderIndicator2.style.display = this.ReorderIndicator1.style.display;
		this.ReorderIndicator2.style.position = this.ReorderIndicator1.style.position;

		document.body.appendChild(this.ReorderIndicator1);
		document.body.appendChild(this.ReorderIndicator2);
	}
};

RadGridNamespace.RadGridGroupPanelItem.prototype.DestroyReorderIndicators = function()
{
	if ((this.ReorderIndicator1 != null) && (this.ReorderIndicator2 != null))
	{
		document.body.removeChild(this.ReorderIndicator1);
		document.body.removeChild(this.ReorderIndicator2);

		this.ReorderIndicator1 = null; 
		this.ReorderIndicator2 = null; 
	}
};

RadGridNamespace.RadGridGroupPanelItem.prototype.MoveReorderIndicators = function (e, currentElement)
{
	if ((this.ReorderIndicator1 != null) && (this.ReorderIndicator2 != null))
	{
		this.ReorderIndicator1.style.visibility = "visible";
		this.ReorderIndicator1.style.display = "";

		this.ReorderIndicator2.style.visibility = "visible";
		this.ReorderIndicator2.style.display = "";
		
		this.ReorderIndicator1.style.top = RadGridNamespace.FindPosY(currentElement) - this.ReorderIndicator1.offsetHeight + "px";
		this.ReorderIndicator1.style.left = RadGridNamespace.FindPosX(currentElement) + "px";

		this.ReorderIndicator2.style.top = RadGridNamespace.FindPosY(currentElement) + currentElement.offsetHeight + "px";
		this.ReorderIndicator2.style.left = this.ReorderIndicator1.style.left;
	}	
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY

RadGridNamespace.RadGridMenu = function(objectData, owner, column)
{
	if (!objectData || !owner)
		return;
		
	RadControlsNamespace.DomEventMixin.Initialize(this);

	for (var member in objectData)
	{
		this[member] = objectData[member];
	}

	this.Owner = owner;
	this.ItemData = objectData.Items;
	this.Items = [];
};

RadGridNamespace.RadGridMenu.prototype.Initialize = function()
{
	if (this.Control != null)
		return;
	
	this.Control = document.createElement("table");	
	this.Control.style.backgroundColor = this.SelectColumnBackColor;
	this.Control.style.border = "outset 1px";
	this.Control.style.fontSize = "small";
	this.Control.style.textAlign = "left";
	this.Control.cellPadding = "0";
	this.Control.style.borderCollapse = "collapse";
	this.Control.style.zIndex = 998;

	this.Items = this.CreateItems(this.ItemData);

	this.Control.style.position = "absolute";
	this.Control.style.display = "none";
	document.body.appendChild(this.Control);
	
	var image1 = document.createElement("img");
	image1.src = this.SelectedImageUrl;
	image1.src = this.NotSelectedImageUrl;
	
	this.Control.className = this.CssClass;
}

RadGridNamespace.RadGridMenu.prototype.Dispose = function()
{
	this.DisposeDomEventHandlers();
	
	this.DisposeItems();
	this.ItemData = null;
	
	this.Owner = null;
	this.Control = null;
};

RadGridNamespace.RadGridMenu.prototype.CreateItems = function(items)
{
	var menuItems = [];
	for(var i = 0; i < items.length; i++)
	{
		menuItems[menuItems.length] = new RadGridNamespace.RadGridMenuItem(items[i], this);
	}
	return menuItems;
};

RadGridNamespace.RadGridMenu.prototype.DisposeItems = function()
{
	for(var i = 0; i < this.Items.length; i++)
	{
		var item = this.Items[i];
		item.Dispose();
	}
	
	this.Items = null;
};

RadGridNamespace.RadGridMenu.prototype.HideItem = function(value)
{
	for(var i = 0; i < this.Items.length; i++)
	{
		if (this.Items[i].Value == value)
		{
			this.Items[i].Control.style.display = "none";
		}
	}
};

RadGridNamespace.RadGridMenu.prototype.ShowItem = function(value)
{
	for(var i = 0; i < this.Items.length; i++)
	{
		if (this.Items[i].Value == value)
		{
			this.Items[i].Control.style.display = "";
		}
	}
};

RadGridNamespace.RadGridMenu.prototype.SelectItem = function(value)
{
	for(var i = 0; i < this.Items.length; i++)
	{
		if (this.Items[i].Value == value)
		{
			this.Items[i].Selected = true;
			this.Items[i].SelectImage.src = this.SelectedImageUrl;
		}
		else
		{
			this.Items[i].Selected = false;
			this.Items[i].SelectImage.src = this.NotSelectedImageUrl;
		}
	}
};

RadGridNamespace.RadGridMenu.prototype.Show = function(dataType, options, e)
{	
	this.Initialize();
	
	this.Control.style.display = "";
	this.Control.style.top = e.clientY + document.documentElement.scrollTop + document.body.scrollTop + 5 + "px";
	this.Control.style.left = e.clientX + document.documentElement.scrollLeft + document.body.scrollLeft + 5 + "px";

	this.AttachHideEvents();
};

RadGridNamespace.RadGridMenu.prototype.OnKeyPress = function(e)
{
	if (e.keyCode == 27)
	{
		this.DetachHideEvents();
		this.Hide();
	}
}

RadGridNamespace.RadGridMenu.prototype.OnClick = function(e)
{
	if (!e.cancelBubble)
	{
		this.DetachHideEvents();
		this.Hide();
	}
}

RadGridNamespace.RadGridMenu.prototype.AttachHideEvents = function()
{
	this.AttachDomEvent(document, "keypress", "OnKeyPress");
	this.AttachDomEvent(document, "click", "OnClick");
}

RadGridNamespace.RadGridMenu.prototype.DetachHideEvents = function()
{
	
	this.DetachDomEvent(document, "keypress", "OnKeyPress");
	this.DetachDomEvent(document, "click", "OnClick");
}

RadGridNamespace.RadGridMenu.prototype.Hide = function()
{
	if (this.Control.style.display == "")
	{
		this.Control.style.display = "none";
	}
};

RadGridNamespace.RadGridMenuItem = function(objectData, owner)
{
	for (var member in objectData)
	{
		this[member] = objectData[member];
	}

	this.Owner = owner;

	this.Control = this.Owner.Control.insertRow(-1);
	this.Control.insertCell(-1);

	var table = document.createElement("table");
	table.style.width = "100%";
	table.cellPadding = "0";
	table.cellSpacing = "0";

	table.insertRow(-1);
	var td1 = table.rows[0].insertCell(-1);
	var td2 = table.rows[0].insertCell(-1);
	
	td1.style.borderTop = "solid 1px " + this.Owner.SelectColumnBackColor;
	td1.style.borderLeft = "solid 1px " + this.Owner.SelectColumnBackColor;
	td1.style.borderRight = "none 0px";
	td1.style.borderBottom = "solid 1px " + this.Owner.SelectColumnBackColor;

	td1.style.padding = "2px";
	td1.style.textAlign = "center";
	td1.style.width = "16px";
	td1.appendChild(document.createElement("img"));
	td1.childNodes[0].src = this.Owner.NotSelectedImageUrl;
	
	this.SelectImage = td1.childNodes[0];

	td2.style.borderTop = "solid 1px " + this.Owner.TextColumnBackColor;
	td2.style.borderLeft = "none 0px";
	td2.style.borderRight = "solid 1px " + this.Owner.TextColumnBackColor;
	td2.style.borderBottom = "solid 1px " + this.Owner.TextColumnBackColor;
	td2.style.padding = "2px";
	td2.innerHTML = this.Text;
	td2.style.backgroundColor = this.Owner.TextColumnBackColor;
	td2.style.cursor = "hand";

	this.Control.cells[0].appendChild(table);

	var thisObject = this;
	this.Control.onclick = function()
	{
		if (thisObject.Owner.Owner.Owner.EnableAJAX)
		{
			if(thisObject.Owner.Owner == thisObject.Owner.Owner.Owner.MasterTableViewHeader)
			{
				RadGridNamespace.AsyncRequest(thisObject.UID, thisObject.Owner.Owner.Owner.MasterTableView.UID + "!" + thisObject.Owner.Column.UniqueName, thisObject.Owner.Owner.Owner.ClientID );
			}
			else
			{
				RadGridNamespace.AsyncRequest(thisObject.UID, thisObject.Owner.Owner.UID + "!" + thisObject.Owner.Column.UniqueName, thisObject.Owner.Owner.Owner.ClientID);
			}
		}
		else
		{
			var postBackFunc = thisObject.Owner.Owner.Owner.ClientSettings.PostBackFunction;
			
			if(thisObject.Owner.Owner == thisObject.Owner.Owner.Owner.MasterTableViewHeader)
			{
				postBackFunc = postBackFunc.replace("{0}", thisObject.UID).replace("{1}", thisObject.Owner.Owner.Owner.MasterTableView.UID + "!" + thisObject.Owner.Column.UniqueName);
			}
			else
			{
				postBackFunc = postBackFunc.replace("{0}", thisObject.UID).replace("{1}", thisObject.Owner.Owner.UID + "!" + thisObject.Owner.Column.UniqueName);
			}
			eval(postBackFunc);
		}
	};
	
	this.Control.onmouseover = function(e)
	{
		this.cells[0].childNodes[0].rows[0].cells[0].style.backgroundColor = thisObject.Owner.HoverBackColor;
		this.cells[0].childNodes[0].rows[0].cells[0].style.borderTop = "solid 1px " + thisObject.Owner.HoverBorderColor;
		this.cells[0].childNodes[0].rows[0].cells[0].style.borderLeft = "solid 1px " + thisObject.Owner.HoverBorderColor;
		this.cells[0].childNodes[0].rows[0].cells[0].style.borderBottom = "solid 1px " + thisObject.Owner.HoverBorderColor;
		this.cells[0].childNodes[0].rows[0].cells[1].style.backgroundColor = thisObject.Owner.HoverBackColor;
		this.cells[0].childNodes[0].rows[0].cells[1].style.borderTop = "solid 1px " + thisObject.Owner.HoverBorderColor;
		this.cells[0].childNodes[0].rows[0].cells[1].style.borderRight = "solid 1px " + thisObject.Owner.HoverBorderColor;
		this.cells[0].childNodes[0].rows[0].cells[1].style.borderBottom = "solid 1px " + thisObject.Owner.HoverBorderColor;
	};
	
	this.Control.onmouseout= function(e)
	{
		this.cells[0].childNodes[0].rows[0].cells[0].style.borderTop = "solid 1px " + thisObject.Owner.SelectColumnBackColor;
		this.cells[0].childNodes[0].rows[0].cells[0].style.borderLeft = "solid 1px " + thisObject.Owner.SelectColumnBackColor;
		this.cells[0].childNodes[0].rows[0].cells[0].style.borderBottom = "solid 1px " + thisObject.Owner.SelectColumnBackColor;
		this.cells[0].childNodes[0].rows[0].cells[0].style.backgroundColor = "";

		this.cells[0].childNodes[0].rows[0].cells[1].style.borderTop = "solid 1px " + thisObject.Owner.TextColumnBackColor;
		this.cells[0].childNodes[0].rows[0].cells[1].style.borderRight = "solid 1px " + thisObject.Owner.TextColumnBackColor;
		this.cells[0].childNodes[0].rows[0].cells[1].style.borderBottom = "solid 1px " + thisObject.Owner.TextColumnBackColor;
		this.cells[0].childNodes[0].rows[0].cells[1].style.backgroundColor = thisObject.Owner.TextColumnBackColor;
	};
};

RadGridNamespace.RadGridMenuItem.prototype.Dispose = function()
{
	this.Control.onclick = null;
	this.Control.onmouseover = null;
	this.Control.onmouseout = null;
	
	var tables = this.Control.getElementsByTagName("table");
	while (tables.length > 0)
	{
		var table = tables[0];
		if (table.parentNode != null)
			table.parentNode.removeChild(table);
	}
	
	this.Control = null;
	this.Owner = null;
}

RadGridNamespace.RadGridFilterMenu = function(objectData, owner)
{
	RadGridNamespace.RadGridMenu.call(this, objectData, owner);
};

RadGridNamespace.RadGridFilterMenu.prototype = new RadGridNamespace.RadGridMenu;

RadGridNamespace.RadGridFilterMenu.prototype.Show = function(column, e)
{
	this.Initialize();
	
    if(!column)return;
	this.Owner = column.Owner;
	
	this.Column = column;
	for(var i = 0; i < this.Items.length; i++)
	{
		if (column.DataTypeName != "System.String")
		{
			if((this.Items[i].Value == "StartsWith") || 
				(this.Items[i].Value == "EndsWith") || 
				(this.Items[i].Value == "Contains") || 
				(this.Items[i].Value == "DoesNotContain") || 
				(this.Items[i].Value == "IsEmpty") ||
				(this.Items[i].Value == "NotIsEmpty") )
			{
				this.Items[i].Control.style.display = "none";
				continue;
			}
		}

		if (column.FilterListOptions == "VaryByDataType")
		{
			if(this.Items[i].Value == "Custom")
			{
				this.Items[i].Control.style.display = "none";
				continue;
			}
		}

		this.Items[i].Control.style.display = "";
	}

	this.SelectItem(column.CurrentFilterFunction);

	this.Control.style.display = "";
	this.Control.style.top = e.clientY + document.documentElement.scrollTop + document.body.scrollTop + 5 + "px";
	this.Control.style.left = e.clientX + document.documentElement.scrollLeft + document.body.scrollLeft + 5 + "px";

	this.AttachHideEvents();
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY

RadGridNamespace.RadGrid.prototype.InitializeFilterMenu = function(tableView)
{
	if (this.AllowFilteringByColumn || tableView.AllowFilteringByColumn)
	{
	    if(!tableView || !tableView.Control)
	        return;

	    if(!tableView.Control.tHead)
	        return;

		if(!tableView.IsItemInserted)
		{
			var filterRow = tableView.Control.tHead.rows[tableView.Control.tHead.rows.length - 1];
		}
		else
		{
			var filterRow = tableView.Control.tHead.rows[tableView.Control.tHead.rows.length - 2];
		}

	    if(!filterRow)
	        return;

		var images = filterRow.getElementsByTagName("img");
		var thisObject = this;
		
		if(!tableView.Columns)
		     return;
		        
		if(!tableView.Columns[0])
		     return;
	
		var filterImageUrl = tableView.Columns[0].FilterImageUrl;
		
		for (var i = 0; i < images.length ; i++)
		{
		    if(images[i].getAttribute("src").indexOf(filterImageUrl) == -1)
		        continue;
			images[i].onclick = function(e)
			{
				if (!e)
					var e = window.event;
					
				e.cancelBubble = true;
				
                var realCellIndex = this.parentNode.cellIndex;
                if(window.attachEvent && !window.opera && !window.netscape)
                {
                    realCellIndex = RadGridNamespace.GetRealCellIndexFormCells(this.parentNode.parentNode.cells, this.parentNode);
                }
					
				thisObject.FilteringMenu.Show(tableView.Columns[realCellIndex], e);
				
				if(e.preventDefault)
				{
					e.preventDefault();
				}
				else
				{
					e.returnValue = false;
					return false;
				}
			};
		}

		this.FilteringMenu = new RadGridNamespace.RadGridFilterMenu(this.FilterMenu, tableView);
	}
};
RadGridNamespace.RadGrid.prototype.DisposeFilterMenu = function(tableView)
{
	if (this.FilteringMenu != null)
	{
		this.FilteringMenu.Dispose();
		this.FilteringMenu = null;
	}
};

RadGridNamespace.GetRealCellIndexFormCells = function(cells, cell)
{
    for(var i = 0; i < cells.length; i++)
    {
        if(cells[i] == cell)
        {
            return i;
        }
    }
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY

if (typeof(window.RadGridNamespace) == "undefined")
{
	window.RadGridNamespace = new Object();
};

RadGridNamespace.Slider = function (objectData)
{
	RadControlsNamespace.DomEventMixin.Initialize(this);

	if (!document.readyState || document.readyState == "complete" || window.opera)
	{
		this._constructor(objectData);
	}
	else
	{
		this.objectData = objectData;
		this.AttachDomEvent(window, "load", "OnWindowLoad");	
	}
};

RadGridNamespace.Slider.prototype.OnWindowLoad = function(e)
{
	this.DetachDomEvent(window, "load", "OnWindowLoad");
	
	this._constructor(this.objectData);
	this.objectData = null;
};

RadGridNamespace.Slider.prototype._constructor = function(objectData)
{
	var thisObject = this;
	for (var member in objectData)
	{
		this[member] = objectData[member];
	}
	//debugger;
	this.Owner = window[this.OwnerID];
	this.OwnerGrid = window[this.OwnerGridID];

	this.Control = document.getElementById(this.ClientID);
	this.Control.unselectable = "on";
	
	this.Control.parentNode.style.padding = "10px";
	
	this.ToolTip = document.createElement("div");
	this.ToolTip.unselectable = "on";
	this.ToolTip.style.backgroundColor = "#F5F5DC";
	this.ToolTip.style.border = "1px outset";
	this.ToolTip.style.font = "icon";
	this.ToolTip.style.padding = "2px";
	this.ToolTip.style.marginTop = "5px";
	this.ToolTip.style.marginBottom = "15px"
	this.Control.appendChild(this.ToolTip);

	this.Line = document.createElement("hr");
	this.Line.unselectable = "on";
	this.Line.style.width = "100%";
	this.Line.style.height = "2px";
	this.Line.style.backgroundColor = "buttonface";
	this.Line.style.border = "1px outset threedshadow";
	this.Control.appendChild(this.Line);
	
	this.Thumb = document.createElement("div");
	this.Thumb.unselectable = "on";
	this.Thumb.style.position = "relative";
	this.Thumb.style.width = "8px";
	this.Thumb.style.marginTop = "-15px";
	this.Thumb.style.height = "16px";
	this.Thumb.style.backgroundColor = "buttonface";
	this.Thumb.style.border = "1px outset threedshadow";
	this.Control.appendChild(this.Thumb);
	
	
	this.Link = document.createElement("a");
	this.Link.unselectable = "on";
	this.Link.style.width = "100%";
	this.Link.style.height = "100%";
	this.Link.style.display = "block";
	this.Link.href = "javascript:void(0);";
	this.Thumb.appendChild(this.Link);

	this.LineX = RadGridNamespace.FindPosX(this.Line);
	
	this.AttachDomEvent(this.Control, "mousedown", "OnMouseDown");
	this.AttachDomEvent(this.Link, "keydown", "OnKeyDown");

	var pageIndex = this.OwnerGrid.CurrentPageIndex / this.OwnerGrid.MasterTableView.PageCount;
	this.SetPosition(pageIndex * this.Line.offsetWidth)

	var percent = parseInt(this.Thumb.style.left) / this.Line.offsetWidth;
	var newPageIndex = Math.round((this.OwnerGrid.MasterTableView.PageCount - 1) * percent);

	this.ToolTip.innerHTML = "Page: <b>" + (this.OwnerGrid.CurrentPageIndex + 1) + "</b> out of <b>" + this.OwnerGrid.MasterTableView.PageCount + "</b> pages";
};

RadGridNamespace.Slider.prototype.Dispose = function()
{
	this.DisposeDomEventHandlers();
	
	for (var member in this)
	{
		this[member] = null;
	}
	
	this.Control = null;
	this.Line = null;
	this.Thumb = null;
	this.ToolTip = null;
}

RadGridNamespace.Slider.prototype.OnKeyDown = function(e)
{
	this.AttachDomEvent(this.Link, "keyup", "OnKeyUp");
	if (e.keyCode == 39)
	{
		this.SetPosition(parseInt(this.Thumb.style.left) + this.Thumb.offsetWidth)
	}
	
	if (e.keyCode == 37)
	{
		this.SetPosition(parseInt(this.Thumb.style.left) - this.Thumb.offsetWidth)
	}
	
	if (e.keyCode == 39 || e.keyCode == 37)
	{
		var percent = parseInt(this.Thumb.style.left) / this.Line.offsetWidth;
		var newPageIndex = Math.round((this.OwnerGrid.MasterTableView.PageCount - 1) * percent);

		this.ToolTip.innerHTML = "Page: <b>" + ((newPageIndex == 0)? 1 : newPageIndex + 1) + "</b> out of <b>" + this.OwnerGrid.MasterTableView.PageCount + "</b> pages";
	}
};

RadGridNamespace.Slider.prototype.OnKeyUp = function(e)
{
	this.DetachDomEvent(this.Link, "keyup", "OnKeyUp");

	if (e.keyCode == 39 || e.keyCode == 37)
	{
		var thisObject = this;
		setTimeout(function(){
			thisObject.ChangePage();
		}, 100);
	}
};

RadGridNamespace.Slider.prototype.OnMouseDown = function(e)
{
	this.DetachDomEvent(this.Control, "mousedown", "OnMouseDown");

	if (((window.netscape || window.opera) && (e.button == 0)) || (e.button == 1))
	{
		this.SetPosition(RadGridNamespace.GetEventPosX(e) - this.LineX)
		
		this.AttachDomEvent(document, "mousemove", "OnMouseMove");
		this.AttachDomEvent(document, "mouseup", "OnMouseUp");
	}
};

RadGridNamespace.Slider.prototype.OnMouseUp = function(e)
{
	this.DetachDomEvent(document, "mousemove", "OnMouseMove");
	this.DetachDomEvent(document, "mouseup", "OnMouseUp");

	var percent = parseInt(this.Thumb.style.left) / this.Line.offsetWidth;
	var newPageIndex = Math.round((this.OwnerGrid.MasterTableView.PageCount - 1) * percent);

	this.ToolTip.innerHTML = "Page: <b>" + ((newPageIndex == 0)? 1 : newPageIndex + 1) + "</b> out of <b>" + this.OwnerGrid.MasterTableView.PageCount + "</b> pages";

	var thisObject = this;
	setTimeout(function(){
		thisObject.ChangePage();
	}, 100);
};

RadGridNamespace.Slider.prototype.OnMouseMove = function(e)
{
	this.SetPosition(RadGridNamespace.GetEventPosX(e) - this.LineX)
	var percent = parseInt(this.Thumb.style.left) / this.Line.offsetWidth;
	var newPageIndex = Math.round((this.OwnerGrid.MasterTableView.PageCount - 1) * percent);

	this.ToolTip.innerHTML = "Page: <b>" + ((newPageIndex == 0)? 1 : newPageIndex + 1) + "</b> out of <b>" + this.OwnerGrid.MasterTableView.PageCount + "</b> pages";
};

RadGridNamespace.Slider.prototype.GetPosition = function(e)
{
	this.SetPosition(RadGridNamespace.GetEventPosX(e) - this.LineX)
};

RadGridNamespace.Slider.prototype.SetPosition = function(value)
{
	if(value >= 0 && value <= this.Line.offsetWidth)
	{
		this.Thumb.style.left = value + "px";
	}
};

RadGridNamespace.Slider.prototype.ChangePage = function()
{
	var percent = parseInt(this.Thumb.style.left) / this.Line.offsetWidth;
	var newPageIndex = Math.round((this.OwnerGrid.MasterTableView.PageCount - 1) * percent);

	if(this.OwnerGrid.CurrentPageIndex == newPageIndex)
	{
	    this.AttachDomEvent(this.Control, "mousedown", "OnMouseDown");
		return;
    }

	this.OwnerGrid.SavePostData("AJAXScrolledControl", (this.OwnerGrid.GridDataDiv)? this.OwnerGrid.GridDataDiv.scrollLeft : "", (this.OwnerGrid.GridDataDiv)? this.OwnerGrid.LastScrollTop : "", (this.OwnerGrid.GridDataDiv)? this.OwnerGrid.GridDataDiv.scrollTop : "", newPageIndex);

	var postBackFunc = this.OwnerGrid.ClientSettings.PostBackFunction;
	
	postBackFunc = postBackFunc.replace("{0}", this.OwnerGrid.UniqueID);
	eval(postBackFunc);
};