var RadGridNamespace = {};

RadGridNamespace.Prefix = "grid_"

RadGridNamespace.EventManager =
{
	_registry: null,

    Initialise: function()
    {
        if (this._registry == null)
        {
           this._registry = [];
           RadGridNamespace.EventManager.Add(window, "unload", this.CleanUp);
        }
    },

    Add: function(element, eventName, eventHandler)
    {
        this.Initialise();

        if (element == null || eventHandler == null)
        {
            return false;
        }
        
        if (element.addEventListener && !window.opera)
        {
            window.setTimeout(function(){element.addEventListener(eventName, eventHandler, true);}, 1000);
            this._registry[this._registry.length] = {element: element, eventName: eventName, eventHandler: eventHandler};
            return true;
        }
        
        if (element.addEventListener && window.opera)
        {
            element.addEventListener(eventName, eventHandler, false);
            this._registry[this._registry.length] = {element: element, eventName: eventName, eventHandler: eventHandler};
            return true;
        }
        

        if (element.attachEvent && element.attachEvent("on" + eventName, eventHandler))
        {
            this._registry[this._registry.length] = {element: element, eventName: eventName, eventHandler: eventHandler};
            return true;
        }

        return false;
    },

    CleanUp: function()
    {
		try
		{
			if(RadGridNamespace != null)
			{
				if(RadGridNamespace.EventManager != null)
				{
					if (RadGridNamespace.EventManager._registry != null)
					{
						for (var i = 0; i < RadGridNamespace.EventManager._registry.length; i++)
						{
							with (RadGridNamespace.EventManager._registry[i])
							{
								if (element.removeEventListener)
									element.removeEventListener(eventName, eventHandler, false);
								else if (element.detachEvent)
									element.detachEvent("on" + eventName, eventHandler);
							}
						}

						RadGridNamespace.EventManager._registry = null;
					}
				}
			}
		}
		catch(error)
		{
			return false;
		}
    }
};

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.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.dir.toLowerCase() == "rtl")
			{
				return true;
			}
		}

		return false;

	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError, this.OnError);
	}
};

RadGridNamespace.AttachEvent = function (element, eventName, eventHandler)
{
	try
	{
		RadGridNamespace.EventManager.Add(element, eventName, eventHandler);
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError, this.OnError);
	}
};


RadGridNamespace.RemoveEvent = function (element, eventName, eventHandler)
{
	if (element == null || eventName == null || eventHandler == null)
		return;
		
	try
	{
		if (element.detachEvent)
		{
			element.detachEvent("on" + eventName, eventHandler);
		}
		else
		{
			element.removeEventListener(eventName, eventHandler, true);
		}
	}
	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;
// url [optional] A url to an external stylesheet to use
// idx [optional] The index in document.styleSheets to insert the new sheet before
RadGridNamespace.AddStyleSheet = function (url,idx)
{
	if (window.opera != null)
	{
		return;
	}

	var css,before=null,head=document.getElementsByTagName("head")[0];

	if (document.createElement)
	{
		if (url)
		{
			css = document.createElement('link');
			css.rel  = 'stylesheet';
			css.href = url;
		} 
		else 
		{
			if (window.netscape)
			{
				css = document.createElement('style');
				css.media = 'all';
				css.type  = 'text/css';
			}
			else
			{
				try
				{
					css = document.createStyleSheet();
				}
				catch(e)
				{
					return false;
				}
			}
		}

		if (idx>=0)
		{
			for (var i=0,ct=0,len=head.childNodes.length;i<len;i++)
			{
				var el = head.childNodes[i];
	
				if (!el.tagName)
				{
					continue;
				}

				var tagName = el.tagName.toLowerCase();

				if (ct==idx)
				{
					before = el;
					break;
				}

				if (tagName=='style' || tagName=='link' && 
						(el.rel && el.rel.toLowerCase()=='stylesheet' || el.type && el.type.toLowerCase()=='text/css') ) 
				{
					ct++;
				}
			}
		}
		
		
		if (window.netscape)
		{
			if(before)
			{
				head.insertBefore(css,before);
			}
			else
			{
				head.appendChild(css);
			}
		}

		return document.styleSheets[before?idx:document.styleSheets.length-1];
	} 
	else 
	{
		//
	}
};
// e.g. var newBlankSheetAfterAllOthers = AddStyleSheet(); 
// e.g. var newBlankSheetBeforeAllOthers = AddStyleSheet(null,0);
// e.g. var externalSheetAfterOthers = AddStyleSheet('http://phrogz.net/JS/Classes/docs.css');
// e.g. var externalSheetBeforeOthers = AddStyleSheet('http://phrogz.net/JS/Classes/docs.css',0);

// 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.GetFirstParentWithOverflow = function (node)
{
	while (node)
	{
		if ((node.style.overflow == "hidden") || 
			(node.style.overflow == "auto") ||
			(node.style.overflow == "scroll"))
		{
			break;
		}
		node = node.parentNode;
	}
	return node;
};

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);
	}

	var grid = this;
	grid._windowUnloadHandler = function()
		{
			grid.Dispose();
		};
	RadGridNamespace.AttachEvent(window, "unload", grid._windowUnloadHandler);
	
	window[objectData.ClientID] = this;
	window["grid_" + objectData.ClientID] = this;

	if (!document.readyState || document.readyState == "complete" || window.opera)
	{
		this._constructor(objectData);
	}
	else if (window.attachEvent)
	{
		var thisObject = this;
		var eventHandler = function()
		{
			window.detachEvent("onload", arguments.callee);
			thisObject._constructor(objectData);
		};
		
		window.attachEvent("onload", eventHandler);
		eventHandler = null;
	}
	else if (window.addEventListener && navigator.userAgent.indexOf("Safari") != -1)
	{
		var thisObject = this;
		var eventHandler = function()
		{
			window.removeEventListener("load", arguments.callee);
			thisObject._constructor(objectData);
		};
		
		window.addEventListener("load", eventHandler, true);
		eventHandler = 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.InitializeDimensions();

	// 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
	{
		this.DetachDomEvents();
		
		RadGridNamespace.RemoveEvent(window, "unload", this._windowUnloadHandler);
		this._windowUnloadHandler = null;
		
		this.DisposeEvents();		
		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,
		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;

	if (this.Control.style.width == "")
	{	
		this.Control.style.width = "100%";
	}

	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");
	if(this.LoadingTemplate)
	{
		this.LoadingTemplate.style.display = "none";
		if (this.GridDataDiv)
		{
			this.GridDataDiv.appendChild(this.LoadingTemplate);
		}
	}
	
	this.Form = this.PostDataValue.form;
};

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;
	this.Form = 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.InitializeScroll(objectData);
	}

	if (this.Control.align == "")
	{
		this.Control.align = "left";
	}

	if (this.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];
		}
		//debugger;
		this.SetActiveRow(this.ActiveRow)
	}
	
	this.FormID = this.ClientSettings.FormID;
};

RadGridNamespace.RadGrid.prototype.DisposeFeatures = function ()
{
	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)
	{
		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 clientID = this.ClientID;
	this.OnRequestEnd = function()
	{
	    RadGridNamespace.FireEvent(window[clientID], "OnRequestEnd");
	};

	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);
};

//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

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 += "r.a.d.grid 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 += "r.a.d.grid 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 += "r.a.d.grid 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.ExpandCollapseRow = function (cell)
{
	if ( cell.parentNode.style.display != "none" )
	{
		cell.parentNode.style.display = "none";			
	}
	else
	{
		if (window.netscape)
		{
			cell.parentNode.style.display = "table-row";
		}
		else
		{
			cell.parentNode.style.display = "block";
		}
	}
};

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, currentElement)
{
	try
	{
		var gridControl = this;
		if ((currentElement != null) && (currentElement.tagName.toLowerCase() == "th"))
		{
			var currentTable =  currentElement.parentNode.parentNode.parentNode;
			var definedTable =  this.GetTableObjectByID(currentTable.id);

			if ((definedTable != null) &&
				(definedTable.Columns.length > 0) &&
				(definedTable.Columns[currentElement.cellIndex] != null) &&
				((definedTable.Columns[currentElement.cellIndex].Reorderable) ||
				(definedTable.Owner.ClientSettings.AllowDragToGroup && definedTable.Columns[currentElement.cellIndex].Groupable)))
			{
				var positionX = RadGridNamespace.GetEventPosX(e);
				var startX = RadGridNamespace.FindPosX(currentElement);
				var endX = startX + currentElement.offsetWidth;

				this.ResizeTolerance = 5;

				var mouseDownHandler = function (e)
				{
					if (!e)
						var e = window.event;

					if (((window.netscape || window.opera) && (e.button == 0)) || (e.button == 1))
					{
						gridControl.CreateDragAndDrop(e, currentElement);
					}

					RadGridNamespace.ClearDocumentEvents();
				};
				
				var mouseUpHandler = function (e)
				{
					if (!e)
						var e = window.event;
						gridControl.FireDropAction(e);
						gridControl.DestroyDragAndDrop(e);
						RadGridNamespace.RestoreDocumentEvents();
				};

				var oldTitle = currentElement.title;
				var oldCursor = currentElement.style.cursor;

				if (!((positionX >= endX - this.ResizeTolerance) && 
					(positionX <= endX + this.ResizeTolerance)))
				{
					if (this.MoveHeaderDiv)
					{
						if (this.MoveHeaderDiv.innerHTML != currentElement.innerHTML)
						{
							currentElement.title = this.ClientSettings.ClientMessages.DropHereToReorder;
							currentElement.style.cursor = "default";
							
							if (currentElement.parentNode.parentNode.parentNode == this.MoveHeaderDivRefCell.parentNode.parentNode.parentNode)
							{
								this.MoveReorderIndicators(e, currentElement);
							}
							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
					{
						currentElement.title = this.ClientSettings.ClientMessages.DragToGroupOrReorder;
						currentElement.style.cursor = "move";
					}

					currentElement.onmousedown = mouseDownHandler;
					//RadGridNamespace.AttachEvent(document, "mousedown", mouseDownHandler);
					RadGridNamespace.AttachEvent(document, "mouseup", mouseUpHandler);

					if (this.GroupPanelControl != null)
					{
						RadGridNamespace.AttachEvent(this.GroupPanelControl, "mouseup", mouseUpHandler);
					}
				}
				else
				{
					currentElement.style.cursor = oldCursor;

					currentElement.title = "";

					currentElement.onmousedown = null;
					RadGridNamespace.RemoveEvent(document, "mouseup", mouseUpHandler);
					RadGridNamespace.RemoveEvent(this.GroupPanelControl, "mouseup", mouseUpHandler);
				}
			}
		}

		if (this.MoveHeaderDiv != null)
		{
			this.MoveHeaderDiv.style.visibility = "";
			this.MoveHeaderDiv.style.display = "";

			this.MoveHeaderDiv.style.top =  e.clientY + 
											document.documentElement.scrollTop + 
											document.body.scrollTop + 5 + "px";

			this.MoveHeaderDiv.style.left = e.clientX + 
											document.documentElement.scrollLeft + 
											document.body.scrollLeft + 5 + "px";

/*
			this.MoveHeaderDiv.style.top =  e.clientY + 
											document.documentElement.scrollTop + 
											document.body.scrollTop - this.CurrentElementMouseY + "px";

			this.MoveHeaderDiv.style.left = e.clientX + 
											document.documentElement.scrollLeft + 
											document.body.scrollLeft - this.CurrentElementMouseX + "px";
*/
		}

	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};

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, currentElement)
{
	this.MoveHeaderDivRefCell = currentElement;

	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 = currentElement.offsetHeight + "px";
	table.style.width = currentElement.offsetWidth + "px";

	var tHead = document.createElement("thead");
	var tr = document.createElement("tr");
	
	table.appendChild(tHead);
	tHead.appendChild(tr);
	tr.appendChild(currentElement.cloneNode(true));
	this.MoveHeaderDiv.appendChild(table);
	
	document.body.appendChild(this.MoveHeaderDiv);

	this.MoveHeaderDiv.style.height = currentElement.offsetHeight + "px";
	this.MoveHeaderDiv.style.width = currentElement.offsetWidth + "px";

	this.MoveHeaderDiv.style.position = "absolute";

			this.MoveHeaderDiv.style.top =  e.clientY + 
											document.documentElement.scrollTop + 
											document.body.scrollTop + 5 + "px";

			this.MoveHeaderDiv.style.left = e.clientX + 
											document.documentElement.scrollLeft + 
											document.body.scrollLeft + 5 + "px";
/*
		if(e.offsetX && e.offsetY)
		{
			this.CurrentElementMouseY = e.offsetY;
			this.CurrentElementMouseX = e.offsetX;
		}
		
		if(e.layerY && e.layerX)
		{
			this.CurrentElementMouseY = e.layerY;
			this.CurrentElementMouseX = e.layerX;
		}
		
			this.MoveHeaderDiv.style.top =  e.clientY + 
											document.documentElement.scrollTop + 
											document.body.scrollTop - this.CurrentElementMouseY + "px";

			this.MoveHeaderDiv.style.left = e.clientX + 
											document.documentElement.scrollLeft + 
											document.body.scrollLeft - this.CurrentElementMouseX + "px";
*/


	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(currentElement);
	}
};

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 currentElement = RadGridNamespace.GetCurrentElement(e);
		if ((currentElement != null) && (this.MoveHeaderDiv != null))
		{
			if (currentElement != this.MoveHeaderDivRefCell)
			{
				var parentTableObject = this.GetTableObjectByID(this.MoveHeaderDivRefCell.parentNode.parentNode.parentNode.id);
				var headerRow = parentTableObject.HeaderRow;

				if (RadGridNamespace.IsChildOf(currentElement, headerRow))
				{
					if (currentElement.tagName.toLowerCase() != "th")
					{
						currentElement = RadGridNamespace.GetFirstParentByTagName(currentElement, "th");
					}

					var currentTable =  currentElement.parentNode.parentNode.parentNode;
					var definedTable =  this.MoveHeaderDivRefCell.parentNode.parentNode.parentNode;

					if (currentTable.id == definedTable.id)
					{
						var currentTableObject =  this.GetTableObjectByID(currentTable.id);

                        var realCellIndex1 = currentElement.cellIndex;
                        if(window.attachEvent && !window.opera && !window.netscape)
                        {
                            realCellIndex1 = RadGridNamespace.GetRealCellIndex(currentTableObject, currentElement);
                        }

                        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;
						}

						if (this.MasterTableViewHeader)
						{
							currentTableObject.SwapColumns(realCellIndex1, realCellIndex2);
							this.MasterTableView.SwapColumns(realCellIndex1, realCellIndex2);
						}
						else
						{
							currentTableObject.SwapColumns(realCellIndex1, realCellIndex2);
						}
					}
				}
				else if (RadGridNamespace.CheckParentNodesFor(currentElement, 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 (currentElement)
{
	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(currentElement, 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(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.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, 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) - 
										RadGridNamespace.FindScrollPosY(currentElement) + 
										document.documentElement.scrollTop + 
										document.body.scrollTop - currentElement.offsetHeight + "px";

		this.ReorderIndicator1.style.left = RadGridNamespace.FindPosX(currentElement) - 
										RadGridNamespace.FindScrollPosX(currentElement) + 
										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) + currentElement.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
	{
		var gridControl = this;
		
		this._mouseMoveHandler = function(e){gridControl.MouseMove(e);};
		RadGridNamespace.AttachEvent(this.Control, "mousemove", this._mouseMoveHandler);
		
		this._keyDownHandler = function(e){gridControl.KeyDown(e);};
		RadGridNamespace.AttachEvent(document, "keydown", this._keyDownHandler);
		
		this._keyUpHandler = function(e){gridControl.KeyUp(e);};
		RadGridNamespace.AttachEvent(document, "keyup", this._keyUpHandler);
		
		this._clickHandler = function(e){gridControl.Click(e);};
		RadGridNamespace.AttachEvent(this.Control, "click", this._clickHandler);
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError, this.OnError);
	}
};

RadGridNamespace.RadGrid.prototype.DetachDomEvents = function()
{
	try
	{
		RadGridNamespace.RemoveEvent(this.Control, "mousemove", this._mouseMoveHandler);
		RadGridNamespace.RemoveEvent(document, "keydown", this._keyDownHandler);
		RadGridNamespace.RemoveEvent(document, "keyup", this._keyUpHandler);
		RadGridNamespace.RemoveEvent(this.Control, "click", this._clickHandler);
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError, this.OnError);
	}
};

RadGridNamespace.RadGrid.prototype.MouseMove = function(e)
{
	try
	{
		if (!e)
			var e = window.event;

		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.KeyDown = 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.Click = function (e)
{
	//this.HandleCellEdit(e);
};

RadGridNamespace.RadGrid.prototype.KeyUp = 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 mouseDownHandler = function (e)
					{
						if (!e)
							var e = window.event;
						gridControl.CreateRowResizer(e);
						RadGridNamespace.ClearDocumentEvents();
					};

					var mouseUpHandler = function (e)
					{
						if (!e)
							var e = window.event;
						gridControl.DestroyRowResizerAndResizeRow(e, true);
						RadGridNamespace.RestoreDocumentEvents();
					};

					var oldTitle = currentElement.title;

					if ((positionY > endY - this.ResizeTolerance) && 
						(positionY < endY + this.ResizeTolerance))
					{
						currentElement.style.cursor = "n-resize";
						
						currentElement.title = this.ClientSettings.ClientMessages.DragToResize;

						currentElement.onmousedown = mouseDownHandler;
						RadGridNamespace.AttachEvent(document, "mouseup", mouseUpHandler);
					}
					else
					{
						currentElement.style.cursor = "default";
						currentElement.title = "";
						currentElement.onmousedown = null;
						RadGridNamespace.RemoveEvent(document, "mouseup", mouseUpHandler);
					}
				}
			}
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};

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";
			}
		}
	}
};

RadGridNamespace.RadGrid.prototype.AdjustColumnWidthToContent = function (e)
{
return;
	try
	{
		var currentElement = RadGridNamespace.GetCurrentElement(e);

		if ((currentElement != null) && (currentElement.tagName.toLowerCase() == "th"))
		{
			var currentTable =  currentElement.parentNode.parentNode.parentNode;
			var definedTable =  this.GetTableObjectByID(currentTable.id);

			if (definedTable != null)
			{
				
				definedTable.ColGroup.Cols[currentElement.cellIndex].width = 2;
				//window.status = definedTable.ColGroup.Cols[currentElement.cellIndex].width;
/*
				definedTable.Control.tableLayout = "auto";

				for (var i=0;i<currentElement.cellIndex;i++)
				{
					definedTable.ColGroup.Cols[i].width = "";
				}

				if (window.netscape)
				{
					definedTable.ColGroup.Cols[currentElement.cellIndex].width = 0;
				}
				else
				{
					definedTable.ColGroup.Cols[currentElement.cellIndex].width = currentElement.scrollWidth;
				}

				for (var i=currentElement.cellIndex + 1;i<currentElement.parentNode.cells.length;i++)
				{
					definedTable.ColGroup.Cols[i].width = "";
				}

				definedTable.Control.tableLayout = "fixed";
				
				for (var i=0;i<currentElement.parentNode.cells.length;i++)
				{
					definedTable.ColGroup.Cols[i].width = currentElement.parentNode.cells[i].offsetWidth;
				}
*/
			}
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY
RadGridNamespace.RadGrid.prototype.SynchronizeColumnsWidths = function()
{
	try
	{
		if (this.MasterTableView && this.MasterTableViewHeader && this.MasterTableViewHeader.HeaderRow)
		{
			if (this.MasterTableView.ColGroup && this.MasterTableViewHeader.ColGroup)
			{
				for (var i = 0; i < this.MasterTableViewHeader.ColGroup.Cols.length; i++)
				{
					var width;
					if (this.MasterTableViewHeader.ColGroup.Cols[i].width != "")
					{
						width = this.MasterTableViewHeader.ColGroup.Cols[i].width;
					}
					else
					{
						width = this.MasterTableViewHeader.HeaderRow.cells[i].offsetWidth;
					}
					
					if(width.toString().indexOf("%") == -1)
					{
					    if(width > 0)
					    {
						    this.MasterTableViewHeader.ColGroup.Cols[i].width = width;
    						
						    this.MasterTableView.ColGroup.Cols[i].width = width;
    						
						    if (this.MasterTableViewFooter)
						    {
							    this.MasterTableViewFooter.ColGroup.Cols[i].width = width;
						    }
					    }
					    else
					    {
						    width = 100;
						    this.MasterTableViewHeader.ColGroup.Cols[i].width = width;
    						
						    this.MasterTableView.ColGroup.Cols[i].width = width;
    						
						    if (this.MasterTableViewFooter)
						    {
							    this.MasterTableViewFooter.ColGroup.Cols[i].width = width;
						    }
					    }
					}
					else
					{
					    this.MasterTableViewHeader.ColGroup.Cols[i].width = width;
						
					    this.MasterTableView.ColGroup.Cols[i].width = width;
						
					    if (this.MasterTableViewFooter)
					    {
						    this.MasterTableViewFooter.ColGroup.Cols[i].width = width;
					    }
					}
				}

				if (this.MasterTableViewHeader.Control.style.width.indexOf("%") == -1)
				{
					this.MasterTableView.Control.style.width = this.MasterTableViewHeader.Control.offsetWidth + "px";
				}
				else
				{
				    
					if (navigator.userAgent.toLowerCase().indexOf("msie") != -1)
					{
			            var scrollbarWidth = this.GridDataDiv.offsetWidth - this.GridDataDiv.clientWidth;
    			        
			            var newWidth =  parseInt(this.MasterTableViewHeader.Control.style.width.toString().replace("%","")) - 
			                ((scrollbarWidth / this.MasterTableViewHeader.Control.offsetWidth) * 100) + "%";
    			        
				        this.MasterTableView.Control.style.width = newWidth;
				    }
				    else
				    {
				       this.MasterTableViewHeader.Control.style.width = this.MasterTableView.Control.style.width;
				    }
				}

				if (this.MasterTableViewFooter)
				{
					if (this.MasterTableViewHeader.Control.style.width.indexOf("%") == -1)
					{
						this.MasterTableViewFooter.Control.style.width = this.MasterTableViewHeader.Control.offsetWidth + "px";
					}
				}

			}
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};

RadGridNamespace.RadGrid.prototype.InitializeDimensions = function()
{
	try
	{
		if(!RadGridNamespace.CheckIsParentDisplay(this.Control))
		{
			return;
		}

		if (this.ClientSettings.Scrolling.AllowScroll && this.ClientSettings.Scrolling.UseStaticHeaders)
		{
			var scrollbarWidth = this.GridDataDiv.offsetWidth - this.GridDataDiv.clientWidth;
			
			RadGridNamespace.scrollbarWidth = scrollbarWidth;

			if (this.GridHeaderDiv)
			{
				if (this.GridHeaderDiv.style.width == "")
				{
					if (navigator.userAgent.toLowerCase().indexOf("msie") == -1)
					{
						this.GridHeaderDiv.style.width = this.GridDataDiv.clientWidth + "px";
					}
					else
					{
						this.GridHeaderDiv.style.width = this.Control.clientWidth - scrollbarWidth + "px";
					}
				}

				if(this.GridHeaderDiv.style.width == this.Control.style.width)
				{
					this.GridHeaderDiv.style.width = this.Control.clientWidth - scrollbarWidth + "px";
				}
			}

			if (this.GridDataDiv)
			{
				if (this.GridDataDiv.style.width == "")
				{
					this.GridDataDiv.style.width = this.GridDataDiv.offsetWidth + "px";
				}
			}
			
			if (this.GridFooterDiv)
			{
				if (this.GridFooterDiv.style.width == "")
				{
					if (navigator.userAgent.toLowerCase().indexOf("msie") == -1)
					{
						this.GridFooterDiv.style.width = this.GridDataDiv.clientWidth + "px";
					}
					else
					{
						this.GridFooterDiv.style.width = this.Control.clientWidth - scrollbarWidth + "px";
					}
				}

				if(this.GridFooterDiv.style.width == this.Control.style.width)
				{
					this.GridFooterDiv.style.width = this.Control.clientWidth - scrollbarWidth + "px";
				}
			}

			if (this.PagerControl)
			{
				this.PagerControl.style.width = this.Control.clientWidth + "px";
			}

			if (this.ClientSettings.Scrolling.ScrollWidth == "")
			{
				this.SavePostData("ResizedScrollArea", this.GridDataDiv.style.width);
			}

			if (this.Control.style.width == "")
			{
				this.SavePostData("ResizedGrid", this.Control.clientWidth);
			}
			else if (this.Control.style.width.indexOf("%") != -1)
			{
				var thisObject = this;
				RadGridNamespace.SynchronizeWithWindow = function()
				{
					try
					{
						if(thisObject.Control.style.width.indexOf("%") != -1)
						{
							thisObject.GridDataDiv.style.width = 100 + "%";
							if (navigator.userAgent.toLowerCase().indexOf("msie") == -1)
							{
								thisObject.GridHeaderDiv.style.width = thisObject.GridDataDiv.clientWidth + "px";
							}
							else
							{
								//removing the ...style.width property get makes IE fall into an endless
								//window resize event firing loop
								var dummy = thisObject.Control.style.width;
								thisObject.GridHeaderDiv.style.width = thisObject.Control.clientWidth - scrollbarWidth + "px";
							}
						}

						if(thisObject.ClientSettings.Scrolling.ScrollHeight.indexOf("%") != -1)
						{
							var height = 0;
							if (thisObject.GroupPanelObject)
							{
								height += thisObject.GroupPanelObject.Control.offsetHeight;
							}

							if (thisObject.GridHeaderDiv)
							{
								height += thisObject.GridHeaderDiv.offsetHeight;
							}

							if (thisObject.GridFooterDiv)
							{
								height += thisObject.GridFooterDiv.offsetHeight;
							}

							var percent = parseInt(thisObject.ClientSettings.Scrolling.ScrollHeight.replace("%","")) - ((height / thisObject.Control.clientHeight) * 100);
							thisObject.GridDataDiv.style.height = percent + "%";
						}
						
						thisObject.SynchronizeColumnsWidths();
					}
					catch(error)
					{
						new RadGridNamespace.Error(error, this, this.OnError);
					}
				};
				RadGridNamespace.EventManager.Add(window, "resize", function(e){if(!e)var e=window.event;RadGridNamespace.SynchronizeWithWindow();});
				
				RadGridNamespace.SynchronizeWithWindow();
			}
			
			if (this.ClientSettings.Scrolling.ScrollBarWidth == "" || this.ClientSettings.Scrolling.ScrollBarWidth != (scrollbarWidth + "px"))
			{
				this.SavePostData("ScrollBarWidth", scrollbarWidth);
			}
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};


RadGridNamespace.RadGrid.prototype.InitializeScroll = function (objectData)
{
	this.SynchronizeColumnsWidths();

	var gridControl = this;

	try
	{
		if (this.ClientSettings.Scrolling.SaveScrollPosition)
		{
			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;
			}
		}

		if(this.ClientSettings.Scrolling.EnableAJAXScrollPaging)
		{
			this.ScrollCounter = 0;
			this.CurrentAJAXScrollTop = 0;

			if (this.ClientSettings.Scrolling.AJAXScrollTop != "")
			{
				this.CurrentAJAXScrollTop = this.ClientSettings.Scrolling.AJAXScrollTop;
			}

			this.GridDataDiv.onscroll = function(e){if(!e)var e=window.event; gridControl.AJAXScroll(e);};

			this.MasterTableView.Control.style.marginBottom = (this.MasterTableView.PageCount * this.MasterTableView.PageSize * 20) + "px";
			
		var scrollTop = this.CurrentAJAXScrollTop;
		var MasterTable = document.getElementById(this.MasterTableView.ClientID);
		if(MasterTable && scrollTop)
		{
			MasterTable.style.marginTop = scrollTop + "px";
			if(parseInt(MasterTable.style.marginBottom) > parseInt(MasterTable.style.marginTop))
			{
				MasterTable.style.marginBottom = parseInt(MasterTable.style.marginBottom) - parseInt(MasterTable.style.marginTop) + "px";
			}
			else
			{
				MasterTable.style.marginBottom = "0px";
			}
		}

			
		
			if(this.CurrentAJAXScrollTop)
			{
				this.GridDataDiv.scrollTop = this.CurrentAJAXScrollTop;
			}

			if(this.LastScrollTop)
			{
				this.GridDataDiv.scrollTop = this.LastScrollTop;
			}
			
			var scrollerToolTip = document.getElementById(gridControl.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.AttachEvent(this.GridDataDiv, "scroll", function(e){if(!e)var e=window.event; gridControl.Scroll(e);});
		
            var scrollArea = document.getElementById(this.ClientID + "_GridData");
            var headerDiv = document.getElementById(this.ClientID + "_GridHeader");
            var footerDiv = document.getElementById(this.ClientID + "_GridFooter");
            var headerTable = document.getElementById(this.MasterTableView.ClientID + "_Header");
            var pagerTable = document.getElementById(this.MasterTableView.ClientID + "_Pager");
            var thisObject = this;
            scrollArea.onresize = function()
            {
				if(headerDiv)
					headerDiv.style.width = scrollArea.offsetWidth + "px";
				if(footerDiv)
					footerDiv.style.width = scrollArea.offsetWidth + "px";
				if(headerTable)
					headerTable.style.width = thisObject.MasterTableView.Control.offsetWidth + "px";
				if(pagerTable)
	                pagerTable.style.width = scrollArea.offsetWidth + "px";
            };
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.OnError);
	}
};

RadGridNamespace.RadGrid.prototype.Scroll = 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.AJAXScroll = function(e)
{
	if (!e)
		var e = window.event;

	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);
			gridControl.AjaxRequest(gridControl.UniqueID, "");
			/*
			var scrollTop;
			gridControl.OnResponseReceived = function()
			{
				scrollTop = document.getElementById(clientID + "_GridData").scrollTop;
			};
			
			gridControl.OnRequestEnd = function()
			{
			};*/
		}

		gridControl.ScrollCounter = 0;
		
		setTimeout(function(){
			var scrollerToolTip = document.getElementById(gridControl.ClientID + "ScrollerToolTip");
			if (scrollerToolTip && scrollerToolTip.parentNode)
			{
				scrollerToolTip.style.display = "none";
			}
		}, 200);
	};

	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 percent = this.GridDataDiv.scrollTop / (this.GridDataDiv.scrollHeight - this.GridDataDiv.offsetHeight + 16);
	var newPageIndex = Math.round((this.MasterTableView.PageCount - 1) * percent);

	setTimeout("RadGridNamespace.AJAXScrollHanlder(" + this.ScrollCounter + ")", 500);

	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 * percent) + 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>" + Math.round(this.MasterTableView.PageCount * percent) + "</b> out of <b>" + this.MasterTableView.PageCount + "</b> pages";
	}
};

RadGridNamespace.RadGrid.prototype.SynchronizeColumnsWidths2 = function()
{
	if (this.MasterTableViewHeader)
	{
	  if (this.MasterTableViewHeader.ColGroup)
	  {
		for(var i=0;i<this.MasterTableViewHeader.ColGroup.Cols.length;i++)
		{
			if (this.MasterTableViewHeader.ColGroup.Cols[i].width != "")
			{
				var width = this.MasterTableViewHeader.ColGroup.Cols[i].width;
				if (width.toString().indexOf("%") == -1)
				{
					width = width + "px";
				}

				this.MasterTableView.ColGroup.Cols[i].width = width;
				
				if (this.MasterTableViewHeader.HeaderRow)
				{
					if (this.MasterTableViewHeader.HeaderRow.cells[i])
					{
						this.MasterTableViewHeader.HeaderRow.cells[i].style.width = width;
					}
				}
				
				if (this.MasterTableViewFooter)
				{
					this.MasterTableViewFooter.ColGroup.Cols[i].width = width;
					if (this.MasterTableViewFooter.Control.rows[0])
					{
						if (this.MasterTableViewFooter.Control.rows[0].cells[i])
						{
							this.MasterTableViewFooter.Control.rows[0].cells[i].style.width = width;
						}
					}
				}
			}
			else
			{
				if (this.MasterTableViewHeader.HeaderRow)
				{
					if (this.MasterTableViewHeader.HeaderRow.cells[i])
					{
						var calcWidth = this.MasterTableViewHeader.HeaderRow.cells[i].offsetWidth + "px";
						this.MasterTableViewHeader.HeaderRow.cells[i].style.width = calcWidth;
						this.MasterTableViewHeader.ColGroup.Cols[i].width = calcWidth;
						this.MasterTableView.ColGroup.Cols[i].width = calcWidth;
					}
				}

				if (this.MasterTableViewFooter)
				{
					this.MasterTableViewFooter.ColGroup.Cols[i].width = calcWidth;
					if (this.MasterTableViewFooter.Control.rows[0])
					{
						if (this.MasterTableViewFooter.Control.rows[0].cells[i])
						{
							this.MasterTableViewFooter.Control.rows[0].cells[i].style.width = calcWidth;
						}
					}
				}
			}
		}
/*
		this.MasterTableView.Control.style.width = this.MasterTableViewHeader.Control.offsetWidth + "px";
		if (this.MasterTableViewFooter)
		{
			this.MasterTableViewFooter.Control.style.width = this.MasterTableViewHeader.Control.offsetWidth + "px";
		}
*/
      }
      
      
      
 
	  if (this.MasterTableView.ColGroup)
	  {
		for(var i=0;i<this.MasterTableView.ColGroup.Cols.length;i++)
		{
			if (this.MasterTableView.ColGroup.Cols[i].width != "")
			{
				var width = this.MasterTableViewHeader.ColGroup.Cols[i].width;
				if (width.toString().indexOf("%") == -1)
				{
					width = width + "px";
				}

				this.MasterTableViewHeader.ColGroup.Cols[i].width = width;
				
				if (this.MasterTableViewHeader.HeaderRow)
				{
					if (this.MasterTableViewHeader.HeaderRow.cells[i])
					{
						this.MasterTableViewHeader.HeaderRow.cells[i].style.width = width;
					}
				}
				
				if (this.MasterTableViewFooter)
				{
					this.MasterTableViewFooter.ColGroup.Cols[i].width = width;
					if (this.MasterTableViewFooter.Control.rows[0])
					{
						if (this.MasterTableViewFooter.Control.rows[0].cells[i])
						{
							this.MasterTableViewFooter.Control.rows[0].cells[i].style.width = width;
						}
					}
				}
			}
		}
/*
		this.MasterTableViewHeader.Control.style.width = this.MasterTableView.Control.offsetWidth + "px";
		if (this.MasterTableViewFooter)
		{
			this.MasterTableViewFooter.Control.style.width = this.MasterTableViewHeader.Control.offsetWidth + "px";
		}
*/
      }

      //alert(this.MasterTableViewHeader.Control.style.width + ", " + this.MasterTableView.Control.style.width);
     // alert(this.GridHeaderDiv.style.width + ", " + this.GridDataDiv.style.width);
	}
};


//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 (this.Control.style.tableLayout == "fixed" && this.Control.style.width == "")
	{
		//this.Control.style.tableLayout = "";
		//this.Control.style.width = this.Control.clientWidth;
		//this.Control.style.tableLayout = "fixed";
		var totalBorderWidth = this.Control.offsetWidth - this.Control.clientWidth;
		this.Control.style.width = this.Control.clientWidth - totalBorderWidth * 2 + "px";
	}
	
	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.Rows = this.GetTableRows(this.Control, this.Controls[0].Rows);
		this.InitializeRows(this.Controls[0].Rows);
		//this.Rows = this.Controls[0].Rows;
		//alert(this.Rows[0]);
	}
};

RadGridNamespace.RadGridTable.prototype.Dispose = function()
{
	this.Control = null;
	
	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.SelectedRows = null;
	this.ExpandCollapseColumns = null;
	
	this.DetailTables = null;
	this.DetailTablesCollection = 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.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
	{
		var lastWidth = this.Control.clientWidth;
		var lastGridWidth = this.Owner.Control.clientWidth;
	
		var deltaWidth = this.HeaderRow.cells[index].scrollWidth - width;
		if (this.HeaderRow)
		{
			if (this.HeaderRow.cells[index])
			{
				this.HeaderRow.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.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.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";
				this.Owner.SynchronizeColumnsWidths();
				
				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
		{
			if (!this.Owner.ClientSettings.Scrolling.UseStaticHeaders)
			{
				//this.Control.style.width = lastWidth + "px";
			}
			else
			{
				//alert(lastWidth);
				//this.Owner.MasterTableViewHeader.Control.style.width = "100%";
				//this.Owner.MasterTableView.Control.style.width = "100%";
				//this.Owner.SynchronizeColumnsWidths();
			}
		}

		RadGridNamespace.FireEvent(this, "OnColumnResized", [index, width]);
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.OnError);
	}
};

RadGridNamespace.RadGridTable.prototype.SwapColumns = 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;

	try
	{
		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;
		var oldWidth2 = this.ColGroup.Cols[columnIndex2].width;

		if (this != this.Owner.MasterTableViewHeader)
		{
			this.Owner.SavePostData("ReorderedColumns", this.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 (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 (oldWidth2 != "")
		{
			this.ColGroup.Cols[columnIndex1].width = oldWidth2 + "px";
		}
		
		if (oldWidth1 != "")
		{
			this.ColGroup.Cols[columnIndex2].width = oldWidth1 + "px";
		}

		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 ((!this.Owner.ClientSettings.ReorderColumnsOnClient) &&
			(this.Owner.ClientSettings.PostBackReferences.PostBackColumnsReorder != ""))
		{
				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]]))
			return;

		this.SelectedRows[i].Selected = false;
		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 (!RadGridNamespace.FireEvent(this, "OnRowDeselecting", [this.SelectedRows[i]]))
				{
					continue;
				}
		        try
		        {
		            this.SelectedRows.splice(i,1);
		            i--;
		        }
		        catch(ex)
		        {
		            //
		        }
				RadGridNamespace.FireEvent(this, "OnRowDeselected", [last]);
			}
		}
		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;

	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;

	var thisObject = this;

	this._clickHandler = function(e){if(!e)var e = window.event;thisObject.Click(e);};
	RadGridNamespace.AttachEvent(this.Control, "click", this._clickHandler);
	this._dblclickHandler = function(e){if(!e)var e = window.event;thisObject.DblClick(e);};
	RadGridNamespace.AttachEvent(this.Control, "dblclick", this._dblclickHandler);
	this._mousemoveHandler = function(e){if(!e)var e = window.event; thisObject.MouseMove(e);};
	RadGridNamespace.AttachEvent(this.Control, "mousemove", this._mousemoveHandler);
	this._mousedownHandler = function(e){if(!e)var e = window.event;thisObject.MouseDown(e);}
	RadGridNamespace.AttachEvent(this.Control, "mousedown", this._mousedownHandler);
	this._mouseupHandler = function(e){if(!e)var e = window.event;thisObject.MouseUp(e);};
	RadGridNamespace.AttachEvent(this.Control, "mouseup", this._mouseupHandler);
	this._mouseoverHandler = function(e){if(!e)var e = window.event;thisObject.MouseOver(e);};
	RadGridNamespace.AttachEvent(this.Control, "mouseover", this._mouseoverHandler);
	this._mouseoutHandler = function(e){if(!e)var e = window.event;thisObject.MouseOut(e);}
	RadGridNamespace.AttachEvent(this.Control, "mouseout", this._mouseoutHandler);
	this._contextmenuHandler = function(e){if(!e)var e = window.event;thisObject.ContextMenu(e);};
	RadGridNamespace.AttachEvent(this.Control, "contextmenu", this._contextmenuHandler);
};

RadGridNamespace.RadGridTableColumn.prototype.Dispose = function()
{
	if (this.ColumnResizer)
	{
		this.ColumnResizer.Dispose();
	}
	
	RadGridNamespace.RemoveEvent(this.Control, "click", this._clickHandler);
	this._clickHandler = null;
	RadGridNamespace.RemoveEvent(this.Control, "dblclick", this._dblclickHandler);
	this._dblclickHandler = null;
	RadGridNamespace.RemoveEvent(this.Control, "mousemove", this._mousemoveHandler);
	this._mousemoveHandler = null;
	RadGridNamespace.RemoveEvent(this.Control, "mousedown", this._mousedownHandler);
	this._mousedownHandler = null;
	RadGridNamespace.RemoveEvent(this.Control, "mouseup", this._mouseupHandler);
	this._mouseupHandler = null;
	RadGridNamespace.RemoveEvent(this.Control, "mouseover", this._mouseoverHandler);
	this._mouseoverHandler = null;
	RadGridNamespace.RemoveEvent(this.Control, "mouseout", this._mouseoutHandler);
	this._mouseoutHandler = null;	
	RadGridNamespace.RemoveEvent(this.Control, "contextmenu", this._contextmenuHandler);
	this._contextmenuHandler = null;
	
	this.Control = null;
	this.Owner = null;
	this.Index = null;
}

RadGridNamespace.RadGridTableColumn.prototype.ContextMenu = 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.Click = 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.DblClick = 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.MouseMove = 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.MouseDown = 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.MouseUp = function(e)
{
	//
};

RadGridNamespace.RadGridTableColumn.prototype.MouseOver = function(e)
{
	if (!RadGridNamespace.FireEvent(this.Owner, "OnColumnMouseOver", [this.Index]))
		return;
};

RadGridNamespace.RadGridTableColumn.prototype.MouseOut = function(e)
{
	if (!RadGridNamespace.FireEvent(this.Owner, "OnColumnMouseOut", [this.Index]))
		return;
};

RadGridNamespace.RadGridColumnResizer = function(column, isRealTimeResize)
{
	if(!column)
		return;

	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;

	var thisObject = this;
	this.MouseUpHandler = function(e){if(!e)var e = window.event;thisObject.Destroy(e);};
	this.MouseMoveHandler = function(e){if(!e)var e = window.event;thisObject.Move(e);};
	
	RadGridNamespace.AttachEvent(document, "mouseup", this.MouseUpHandler);
	RadGridNamespace.AttachEvent(this.Column.Owner.Owner.Control, "mousemove", this.MouseMoveHandler);
};

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)
	{
		RadGridNamespace.RemoveEvent(document, "mouseup", this.MouseUpHandler);
		RadGridNamespace.RemoveEvent(this.Column.Owner.Owner.Control, "mousemove", this.MouseMoveHandler);	
		
		if (this.CurrentWidth != null)
		{
			if (this.CurrentWidth > 0)
			{
				this.Column.Owner.ResizeColumn(this.Column.Index, this.CurrentWidth);
				this.Column.Owner.Owner.SynchronizeColumnsWidths();
				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.MouseUpHandler = null;
	this.MouseMoveHandler = null;
	
	this.LeftResizer = null;
	this.RightResizer = null;
	this.ResizerToolTip = null;
}

RadGridNamespace.RadGridColumnResizer.prototype.Move = function(e)
{
	if (this.Column.Owner.Owner.ClientSettings.Scrolling.UseStaticHeaders)
	{
		this.RightResizer.style.left = RadGridNamespace.GetEventPosX(e) - (RadGridNamespace.GetEventPosX(e) - e.clientX) + this.Column.Owner.Owner.GridDataDiv.scrollLeft + "px";
	}
	else
	{
		this.RightResizer.style.left = RadGridNamespace.GetEventPosX(e) + "px";
	}

	this.LeftResizer.style.left = 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.ColGroup.Cols[this.Column.Control.cellIndex].width = width + "px";
		this.Column.Control.style.width = width + "px";

		if (this.Column.Owner.Owner.MasterTableViewHeader == this.Column.Owner)
		{
			if (this.Column.Owner.Owner.MasterTableView)
			{
				this.Column.Owner.Owner.MasterTableView.ColGroup.Cols[this.Column.Control.cellIndex].width = width + "px";
			}

			if (this.Column.Owner.Owner.MasterTableViewHeader)
			{
				this.Column.Owner.Owner.MasterTableViewHeader.ColGroup.Cols[this.Column.Control.cellIndex].width = width + "px";
			}

			if (this.Column.Owner.Owner.MasterTableViewFooter)
			{
				this.Column.Owner.Owner.MasterTableViewFooter.ColGroup.Cols[this.Column.Control.cellIndex].width = width + "px";
			}
			
			this.Column.Owner.Owner.MasterTableView.Control.style.width = this.Column.Owner.Owner.MasterTableViewHeader.Control.offsetWidth + "px";
			if (this.Column.Owner.Owner.MasterTableViewFooter)
			{
				this.Column.Owner.Owner.MasterTableViewFooter.Control.style.width = this.Column.Owner.Owner.MasterTableViewHeader.Control.offsetWidth + "px";
			}

		}
		
		if (this.Column.Owner.Owner.ClientSettings.Resizing.ResizeGridOnColumnResize)
		{
			if (!this.Column.Owner.Owner.ClientSettings.Scrolling.UseStaticHeaders)
			{
				this.Column.Owner.Control.style.width = (this.Column.Owner.Control.offsetWidth - deltaWidth) + "px";
				if (!this.Column.Owner.Owner.GridDataDiv)
				{
					this.Column.Owner.Owner.Control.style.width = (this.Column.Owner.Control.offsetWidth - deltaWidth) + "px";
				}
				else
				{
					this.Column.Owner.Control.style.width = (this.Column.Owner.Control.offsetWidth - deltaWidth) + "px";
				}
			}
			else
			{
				this.Column.Owner.Control.style.width = this.Column.Owner.Control.clientWidth;
				this.Column.Owner.Control.style.width = (this.Column.Owner.Control.offsetWidth - deltaWidth) + "px";
				this.Column.Owner.Owner.MasterTableView.Control.style.width = (this.Column.Owner.Control.offsetWidth - deltaWidth) + "px";
				
				if (this.Column.Owner.Owner.MasterTableViewHeader)
				{
					this.Column.Owner.Owner.MasterTableViewHeader.Control.style.width = this.Column.Owner.Owner.MasterTableView.Control.style.width;
				}
				if (this.Column.Owner.Owner.MasterTableViewFooter)
				{
					this.Column.Owner.Owner.MasterTableViewFooter.Control.style.width = this.Column.Owner.Owner.MasterTableView.Control.style.width;
				}
				
				this.Column.Owner.Owner.SynchronizeColumnsWidths();
			}
		}
		else
		{
			
			//this.Column.Owner.Owner.SynchronizeColumnsWidths();
		}
	}
	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;

	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;
	var thisObject = this;
};

RadGridNamespace.RadGridTableRow.prototype._constructor = function(owner)
{
	this.Owner = owner;

	this.CreateStyles();

	if (this.Selected)
	{
		this.LoadSelected();
	}
	//alert(this.Owner.HierarchyLoadMode);
	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()
					{
						var nestedViewRow = thisObject.Owner.Control.rows[this.parentNode.parentNode.rowIndex+1];

						if (!nestedViewRow)
							return;

						if (nestedViewRow.style.display != "none")
						{
							nestedViewRow.style.display = "none";
							
							if(thisObject.Owner.ExpandCollapseColumns[0].ButtonType == "ImageButton")
							{
							    this.src = thisObject.Owner.ExpandCollapseColumns[0].ExpandImageUrl;
							}
							else
							{
							    this.innerHTML = "+";
							}
							
							thisObject.Owner.Owner.SavePostData("CollapsedRows", thisObject.Owner.ClientID, thisObject.RealIndex);
						}
						else
						{
							if(thisObject.Owner.ExpandCollapseColumns[0].ButtonType == "ImageButton")
							{
    							this.src = thisObject.Owner.ExpandCollapseColumns[0].CollapseImageUrl;
							}
							else
							{
							    this.innerHTML = "-";
							}

							if (window.netscape || window.opera)
							{
								nestedViewRow.style.display = "table-row";
							}
							else
							{
								nestedViewRow.style.display = "block";
							}
							
							thisObject.Owner.Owner.SavePostData("ExpandedRows", thisObject.Owner.ClientID, thisObject.RealIndex);
						}
					}
					
					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()
					{
						var firstGroupHeader = thisObject.Owner.Rows[this.parentNode.parentNode.sectionRowIndex];
						var firstGroupChildRow = thisObject.Owner.Control.rows[this.parentNode.parentNode.sectionRowIndex + 1];

						if (!firstGroupChildRow)
							return;

						var path, imageName = new String();
						path = this.src;
						path = path.substr(0,path.lastIndexOf("/") + 1);

						var k = firstGroupChildRow.rowIndex;
						while (thisObject.Owner.Rows[k] != null && (thisObject.Owner.Rows[k].GroupIndex == firstGroupHeader.GroupIndex || thisObject.Owner.Rows[k].GroupIndex.indexOf(firstGroupHeader.GroupIndex + "_") == 0))
						{
							var groupChildRow = thisObject.Owner.Rows[k].Control;

							if (groupChildRow.style.display != "none")
							{
								groupChildRow.style.display = "none";
								this.src = thisObject.Owner.GroupSplitterColumns[0].ExpandImageUrl;
								firstGroupHeader.Expanded = false;
								
							}
							else
							{
								this.src = thisObject.Owner.GroupSplitterColumns[0].CollapseImageUrl;
								if (window.netscape || window.opera)
								{
									groupChildRow.style.display = "table-row";
								}
								else
								{
									groupChildRow.style.display = "block";
								}
								
								firstGroupHeader.Expanded = true;
								
							}
							k++;
						}
						
						if (firstGroupHeader.Expanded != null)
						{
							if (firstGroupHeader.Expanded)
							{
								thisObject.Owner.Owner.SavePostData("ExpandedGroupRows", thisObject.Owner.ClientID, firstGroupHeader.RealIndex);
								
							}
							else
							{
								thisObject.Owner.Owner.SavePostData("CollapsedGroupRows", thisObject.Owner.ClientID, firstGroupHeader.RealIndex);
							}
						}

					}

					expandCollapseButton.onclick = expandCollapseButtonHandler;
					expandCollapseButton.ondblclick = null;
					expandCollapseButtonHandler = null;
				}
				expandCollapseButton = null;
			}
		}
	}


	var thisObject = this;
	
	this._mousedownHandler = function(e){if (!e)var e = window.event;thisObject.MouseDown(e);};
	RadGridNamespace.AttachEvent(document, "mousedown", this._mousedownHandler);
	this._mouseupHandler = function(e){if(!e)var e = window.event;thisObject.MouseUp(e);};
	RadGridNamespace.AttachEvent(document, "mouseup", this._mouseupHandler);
	this._mousemoveHandler = function(e){if(!e)var e = window.event;thisObject.MouseMove(e);};
	RadGridNamespace.AttachEvent(document, "mousemove", this._mousemoveHandler);
	this._clickHandler = function(e){if(!e)var e = window.event;thisObject.Click(e);};
	RadGridNamespace.AttachEvent(this.Control, "click", this._clickHandler);
	this._dblclickHandler = function(e){if(!e)var e = window.event;thisObject.DblClick(e);};
	RadGridNamespace.AttachEvent(this.Control, "dblclick", this._dblclickHandler);
	this._mouseoverHandler = function(e){if (!e)var e = window.event;thisObject.MouseOver(e);};
	RadGridNamespace.AttachEvent(this.Control, "mouseover", this._mouseoverHandler);
	this._mouseoutHandler = function(e){if(!e)var e = window.event;thisObject.MouseOut(e);};
	RadGridNamespace.AttachEvent(this.Control, "mouseout", this._mouseoutHandler);
	this._contextmenuHandler = function(e){if(!e)var e = window.event;thisObject.ContextMenu(e);};
	RadGridNamespace.AttachEvent(this.Control, "contextmenu", this._contextmenuHandler);


	//RadGridNamespace.AttachEvent(this.Control, "keydown", function(e){if(!e)var e = window.event;thisObject.KeyDown(e);});

	//return this;
	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.RadGridTableRow.prototype.Dispose = function()
{
	RadGridNamespace.RemoveEvent(document, "mousedown", this._mousedownHandler);
	this._mousedownHandler = null;
	RadGridNamespace.RemoveEvent(document, "mouseup", this._mouseupHandler);
	this._mouseupHandler = null;
	RadGridNamespace.RemoveEvent(document, "mousemove", this._mousemoveHandler);
	this._mousemoveHandler = null;
	RadGridNamespace.RemoveEvent(this.Control, "click", this._clickHandler);
	this._clickHandler = null;
	RadGridNamespace.RemoveEvent(this.Control, "dblclick", this._dblclickHandler);
	this._dblclickHandler = null;
	RadGridNamespace.RemoveEvent(this.Control, "mouseover", this._mouseoverHandler);
	this._mouseoverHandler = null;
	RadGridNamespace.RemoveEvent(this.Control, "mouseout", this._mouseoutHandler);
	this._mouseoutHandler = null;
	RadGridNamespace.RemoveEvent(this.Control, "contextmenu", this._contextmenuHandler);
	this._contextmenuHandler = null;

	this.Control = null;
	this.Owner = null;
}

RadGridNamespace.RadGridTableRow.prototype.CreateStyles = function()
{
	if (!this.Owner.Owner.ClientSettings.ApplyStylesOnClient)
		return;

	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:
		{
			this.Control.className += " " + eval("this.Owner.Render" + this.ItemType + "StyleClass");
			this.Control.style.cssText += " " + eval("this.Owner.Render" + this.ItemType + "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.KeyDown = function(e)
{
	try
	{
		if(this.Owner.Owner.ClientSettings.AllowKeyboardNavigation)
		{
		    this.HandleActiveRow(e);
		}
	}
	catch(error)
	{
		new RadGridNamespace.Error(error, this, this.Owner.Owner.OnError);
	}
};

RadGridNamespace.RadGridTableRow.prototype.ContextMenu = 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.Click = function(e)
{
	try
	{
		if (this.Owner.Owner.RowResizer)
			return;

		if (!RadGridNamespace.FireEvent(this.Owner, "OnRowClick", [this.Control.sectionRowIndex]))
			return;

		this.HandleRowSelection(e);
	}
	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 (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.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.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();
		}
	}

	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)
	{
			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.DblClick = function(e)
{
	try
	{
		if (!RadGridNamespace.FireEvent(this.Owner, "OnRowDblClick", [this.Control.sectionRowIndex]))
			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();

		//this.RowSelectorArea.onmousedown = this.OnMouseDown;
		//this.RowSelectorArea.onmouseup = this.OnMouseUp;
		//this.RowSelectorArea.onmousemove = this.OnMouseMove;
	}
};

RadGridNamespace.RadGridTableRow.prototype.DestroyRowSelectorArea = function(e)
{
	if (this.RowSelectorArea)
	{
		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 (!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.MouseDown = function(e)
{
	if (this.Owner.Owner.ClientSettings.Selecting.EnableDragToSelectRows
		&& this.Owner.Owner.AllowMultiRowSelection)
	{
		if (!this.Owner.Owner.RowResizer)
			this.CreateRowSelectorArea(e);
	}
};

RadGridNamespace.RadGridTableRow.prototype.MouseUp = function(e)
{
	//if (!this.Owner.Owner.RowResizer)
		this.DestroyRowSelectorArea(e);
};

RadGridNamespace.RadGridTableRow.prototype.MouseMove = function(e)
{
	//if (!this.Owner.Owner.RowResizer)
		this.ResizeRowSelectorArea(e);
};

RadGridNamespace.RadGridTableRow.prototype.MouseOver = function(e)
{
	if (!RadGridNamespace.FireEvent(this.Owner, "OnRowMouseOver", [this.Control.sectionRowIndex]))
		return;
};

RadGridNamespace.RadGridTableRow.prototype.MouseOut = function(e)
{
	if (!RadGridNamespace.FireEvent(this.Owner, "OnRowMouseOut", [this.Control.sectionRowIndex]))
		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)
{
	this.Control = htmlElement;

	this.Owner = owner;

	this.HierarchicalIndex = hierarchicalIndex;

	this.Control.style.cursor = "move";

	var thisObject = this;

	this.OnMouseDown = function (e){if(!e)var e = window.event;thisObject.MouseDown(e);};
	this.OnMouseUp = function (e){if(!e)var e = window.event;thisObject.MouseUp(e);};
	this.OnMouseMove = function (e){if(!e)var e = window.event;thisObject.MouseMove(e);};

	RadGridNamespace.AttachEvent(this.Control, "mousedown", this.OnMouseDown);
};

RadGridNamespace.RadGridGroupPanelItem.prototype.Dispose = function()
{
	RadGridNamespace.RemoveEvent(this.Control, "mousedown", this.OnMouseDown);
	RadGridNamespace.RemoveEvent(this.Control, "mousedown", this.OnMouseUp);
	RadGridNamespace.RemoveEvent(this.Control, "mousedown", this.OnMouseMove);
	
	for (var member in this)
	{
		this[member] = null;
	}
	
	this.Control = null;
	this.Owner = null;
}

RadGridNamespace.RadGridGroupPanelItem.prototype.MouseDown = function (e)
{
	if (((window.netscape || window.opera) && (e.button == 0)) || (e.button == 1))
	{
		this.CreateDragDrop(e);
		this.CreateReorderIndicators(this.Control);
		RadGridNamespace.AttachEvent(document, "mouseup", this.OnMouseUp);
		RadGridNamespace.AttachEvent(document, "mousemove", this.OnMouseMove);
	}
};

RadGridNamespace.RadGridGroupPanelItem.prototype.MouseUp = function (e)
{
	this.FireDropAction(e);
	this.DestroyDragDrop(e);
	this.DestroyReorderIndicators();
	RadGridNamespace.RemoveEvent(document, "mouseup", this.OnMouseUp);
	RadGridNamespace.RemoveEvent(document, "mousemove", this.OnMouseMove);
};

RadGridNamespace.RadGridGroupPanelItem.prototype.MouseMove = 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.height = this.Control.clientHeight + "px";
	//table.style.width = this.Control.clientWidth + "px";

	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 = document.createElement("div");

	document.body.appendChild(this.MoveHeaderDiv);

	this.MoveHeaderDiv.innerHTML = this.Control.innerHTML;

	this.MoveHeaderDiv.align = "center";
	this.MoveHeaderDiv.valign = "middle";
*/
	this.MoveHeaderDiv.style.height = this.Control.clientHeight + "px";
	this.MoveHeaderDiv.style.width = this.Control.clientWidth + "px";
	
	this.MoveHeaderDiv.style.position = "absolute";

	this.MoveHeaderDiv.style.top =  e.clientY + 
									document.documentElement.scrollTop + 
									document.body.scrollTop + 5 + "px";

	this.MoveHeaderDiv.style.left = e.clientX + 
									document.documentElement.scrollLeft + 
									document.body.scrollLeft + 5 + "px";

	if (window.netscape)
	{
		this.MoveHeaderDiv.style.MozOpacity = 3/4;
	}
	else
	{
		this.MoveHeaderDiv.style.filter = "alpha(opacity=75);";
		
	}
/*
	if (this.Control.style.backgroundColor == "")
	{
		this.MoveHeaderDiv.style.backgroundColor = "scrollbar";
	}
	else
	{
		this.MoveHeaderDiv.style.backgroundColor = this.Control.style.backgroundColor;
	}

	if ((this.Control.className == "") || (this.Control.parentNode.parentNode.parentNode.className == ""))
	{
		this.MoveHeaderDiv.style.border = "1px solid";
	}

	this.MoveHeaderDiv.className += this.Control.className + " " + this.Control.parentNode.parentNode.parentNode.className;
*/
	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 = "";

		this.MoveHeaderDiv.style.top =  e.clientY + 
										document.documentElement.scrollTop + 
										document.body.scrollTop + 5 + "px";

		this.MoveHeaderDiv.style.left = e.clientX + 
										document.documentElement.scrollLeft + 
										document.body.scrollLeft + 5 + "px";

		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;

	for (var member in objectData)
	{
		this[member] = objectData[member];
	}

	this.Owner = owner;

	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.Items = this.CreateItems(objectData.Items);

	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()
{
	RadGridNamespace.RemoveEvent(document, "keypress", this._keyPressEventHandler);
	RadGridNamespace.RemoveEvent(document, "click", this._clickHandler);
	
	this.DisposeItems();
	
	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.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.AttachHideEvents = function()
{
	var thisObject = this;
	
	this._keyPressEventHandler = function(e)
		{
			if(!e)
			{
				var e = window.event;
			}
			if (e.keyCode == 27)
			{
				RadGridNamespace.RemoveEvent(document, "keypress", thisObject._keyPressEventHandler);
				thisObject._keyPressEventHandler = null;
				
				thisObject.Hide();
			}
		};
		
	RadGridNamespace.AttachEvent(document, "keypress", this._keyPressEventHandler);
	
	this._clickHandler = function(e)
		{
			if(!e)
			{
				var e = window.event;
			}
			if (!e.cancelBubble)
			{
				RadGridNamespace.RemoveEvent(document, "click", thisObject._clickHandler);
				thisObject._clickHandler = null;
			
				thisObject.Hide();
			}
		};
	RadGridNamespace.AttachEvent(document, "click", this._clickHandler);
}

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)
{
    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)
	{
	    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;
		for (var i = 0; i < images.length ; i++)
		{
			images[i].onclick = function(e)
			{
				if (!e)
					var e = window.event;
					
				e.cancelBubble = true;
				//debugger;
				
                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

