	var M_strFloaterColor = "";
	var M_nFloaterBorderWidth = 6;
	var m_bSwap = false;
	var m_bInsertTop = false;
	var m_bInsertLeft = false;
	var M_bDragging = false;

function M_HighlightDim(
	i_strBorder, // 't' for top, 'b' for bottom, 'l' for left, or 'r' for right, anything else for whole element.
	io_clDim // <TD> element representing the dimension
	)
{
	if (io_clDim != null) {
		switch (i_strBorder) {
			case "t":
				io_clDim.style.borderTopColor = M_strFloaterColor;
				io_clDim.style.borderTopWidth = M_nFloaterBorderWidth + "px";
				break;
			case "b":
				io_clDim.style.borderBottomColor = M_strFloaterColor;
				io_clDim.style.borderBottomWidth = M_nFloaterBorderWidth + "px";
				break;
			case "l":
				io_clDim.style.borderLeftColor = M_strFloaterColor;
				io_clDim.style.borderLeftWidth = M_nFloaterBorderWidth + "px";
				break;
			case "r":
				io_clDim.style.borderRightColor = M_strFloaterColor;
				io_clDim.style.borderRightWidth = M_nFloaterBorderWidth + "px";
				break;
			default:
				io_clDim.style.backgroundColor = M_strFloaterColor;
				var aParts=io_clDim.getElementsByTagName("a");
				if(aParts!=null) //the first cells in the Other bar have more than one part; the last one has none
					for(i=0;i<aParts.length;i++) {
						aParts[i].style.backgroundColor = M_strFloaterColor;
						aParts[i].style.color = "#000000";
					}
				aParts=io_clDim.getElementsByTagName("span");
				if(aParts!=null)
					for(i=0;i<aParts.length;i++) aParts[i].style.backgroundColor = M_strFloaterColor;
				break;
		}
	}
}

function M_ClearDimHighlight(
	io_clDim // <TD> element representing the dimension
	)
{
	var nRuleIndex;
	var clRule;

	if (io_clDim != null) {
		clRule = GetRuleByName(io_clDim.className);
		if (clRule != null) {
			io_clDim.style.borderLeftColor = clRule.style.borderLeftColor;
			io_clDim.style.borderLeftWidth = clRule.style.borderLeftWidth;
			io_clDim.style.borderRightColor = clRule.style.borderRightColor;
			io_clDim.style.borderRightWidth = clRule.style.borderRightWidth;
			io_clDim.style.borderTopColor = clRule.style.borderTopColor;
			io_clDim.style.borderTopWidth = clRule.style.borderTopWidth;
			io_clDim.style.borderBottomColor = clRule.style.borderBottomColor;
			io_clDim.style.borderBottomWidth = clRule.style.borderBottomWidth;
			io_clDim.style.backgroundColor = clRule.style.backgroundColor;
			var aParts=io_clDim.getElementsByTagName("a");
			if(aParts!=null)
				for(i=0;i<aParts.length;i++) {
					aParts[i].style.backgroundColor = clRule.style.backgroundColor;
					aParts[i].style.color = clRule.style.color;
				}	
			aParts=io_clDim.getElementsByTagName("span");
			if(aParts!=null)
				for(i=0;i<aParts.length;i++) aParts[i].style.backgroundColor = clRule.style.backgroundColor;
		}
	}
}

function M_GJsdnd_HighLightTarget(
	)
{
	var clFloater;
	var clPrivate;
	var unElementLeft;
	var unElementTop;

	clPrivate = M_clDragNDrop;
	clFloater = clPrivate.m_clWindow.document.getElementById("DnDFltr");
	M_ClearDimHighlight(clPrivate.m_clFlyOverElement);
	clElement = clPrivate.GetTarget(clFloater);
	unElementTop = clPrivate.GetAbsPos(clElement, 'Top');
	unElementLeft = clPrivate.GetAbsPos(clElement, 'Left');
	
	if (clElement != null && (clElement.className == 'ActiveDimension' || clElement.className == 'TVActiveDimension'
		|| clElement.className == 'ChartActiveDimension' || clElement.className == 'DragNDropRow'
		|| clElement.className == 'TVDragNDropRow' || clElement.className == 'ChartDragNDropRow'
		|| clElement.className == 'DragNDropCol' || clElement.className == 'TVDragNDropCol'
		|| clElement.className == 'ChartDragNDropCol'|| clElement.className == 'DragNDropOther'
		|| clElement.className == 'TVDragNDropOther' || clElement.className == 'ChartDragNDropOther')
			&& clElement.id.indexOf("-1") == -1 
			&& (clPrivate.m_clSourceElement != null && clElement.id != clPrivate.m_clSourceElement.id))
	{
		clPrivate.m_clFlyOverElement = clElement;

		// As each table has at least one dimension along the row and one dimension along the
		// column. If the source dimension is the last one, the user should not be able to insert it.
		// This does not apply to the last dimension on Other, that one can be inserted elsewhere. 
		if (clPrivate.m_clSourceElement != null) {
			if (clPrivate.m_clSourceElement.getAttribute("Count") == 1 && clPrivate.m_clSourceElement.className != 'DragNDropOther') {
				M_HighlightDim("", clElement);
				m_bSwap = true;
			}
			else {
				// If the target dimension is along the column and in case of inserting, the top
				// or the bottom side should be highlighted.
				// Item selection: If the target dimension is along the "rows" or the "other" areas
				// and in case of inserting, the top or the bottom side should be highlighted.
				if (clPrivate.m_bIsDimView == true || clElement.id.indexOf("Col") != -1) {
					if (clFloater.offsetTop > (unElementTop - (clElement.offsetHeight / 2 ))
						&& (unElementTop + clElement.offsetHeight < clFloater.offsetTop + clFloater.offsetHeight))
					{
						M_HighlightDim("b", clElement);
						m_bSwap = false;
						m_bInsertTop = false;
						m_bInsertLeft = false;
					}
					else if (unElementTop >= (clFloater.offsetTop + clFloater.offsetHeight / 2)
						&& (clPrivate.m_clSourceElement.getAttribute("Count") != 1 || clPrivate.m_clSourceElement.className == 'DragNDropOther'))
					{
						M_HighlightDim("t", clElement);
						m_bSwap = false;
						m_bInsertTop = true;
					}
					else {
						M_HighlightDim("", clElement);
						m_bSwap = true;
					}
				}
				// Table view: If the target dimension is along the "rows" or the "other" areas
				// and in case of inserting, the left or the right side should be highlighted.
				else {
					var nTargetOffsetLeft;
					if (clElement.id.indexOf("Row") != -1) {
						nTargetOffsetLeft = GetOffSet(clElement, OFFSET_LEFT)
						if (clFloater.offsetLeft > (nTargetOffsetLeft + clElement.offsetWidth/2))
						{
							M_HighlightDim("r", clElement);
							m_bSwap = false;
							m_bInsertLeft = false;
							m_bInsertTop = false;
						}
						else if (nTargetOffsetLeft > clFloater.offsetLeft)
						{
							M_HighlightDim("l", clElement);
							m_bSwap = false;
							m_bInsertLeft = true;
						}
						else {
							M_HighlightDim("", clElement);
							m_bSwap = true;
						}
					}
					else if (clElement.id.indexOf("Oth") != -1) {
						nTargetOffsetLeft = GetOffSet(clElement, OFFSET_LEFT)
						if (nTargetOffsetLeft > clFloater.offsetLeft)
						{
							M_HighlightDim("l", clElement);
							m_bSwap = false;
							m_bInsertLeft = true;
						}
						else {
							M_HighlightDim("", clElement);
							m_bSwap = true;
						}
					}
				}
			}
		}
	}
	// If there is no "other" dimension, the source should be inserted to the right
	// of "Other:".
	else if ((clElement != null && clElement.id.indexOf("-1") != -1)
			&& (clPrivate.m_clSourceElement != null && clPrivate.m_clSourceElement.getAttribute("Count") != 1))
	{
		clPrivate.m_clFlyOverElement = clElement;
		M_HighlightDim("", clElement);
		m_bSwap = false;
	}
	
	clPrivate.m_bHighLightInProgress = null;
}

function M_RebuildOtherColRow(
	i_strDim,
	i_strVar,
	i_nReportType
	)
{
	var unDim = parseInt(i_strDim.substr(3));
	// Convert from Dim codes to view postions.
	unDim = GetViewDim(unDim);

	return i_strVar + "+='" + unDim.toString() + "'+','";
}

function GJsdnd(
	)
{
	this.m_clPrivate = new PJsdnd();
}

function GJsdnd_Initialize(
	i_clWindow,
	i_bIsDimView
	)
{
	var aTempArray;
	var clDoc;
	var clFloater = null;
	var clPrivate;
	var unIndex;
	var unTempIndex;
	var unTarget = 0;

	clPrivate = this.m_clPrivate;
	clPrivate.m_clWindow = i_clWindow;
	clPrivate.m_bIsDimView = i_bIsDimView;
	clFloater = document.getElementById("DnDFltr");
	if (clFloater != null) {
		M_strFloaterColor = GetRuleStyle(clFloater.className, "backgroundColor");
	
		M_clDragNDrop = clPrivate;
		clDoc = i_clWindow.document;
		clDoc.onmousedown = this.StartDrag;
		clDoc.onmouseup = this.EndDrag;
		clDoc.onmousemove = this.DragOver;
		aTempArray = new Array();
		if (!PWdsapp_bIsIE) {
			aTempArray[ 0 ] = clDoc.getElementsByTagName("TD");
			aTempArray[ 1 ] = clDoc.getElementsByTagName("TH");
		}
		else {
			aTempArray[ 0 ] = clDoc.all;
		}

		clPrivate.m_clTargets = new Array();
		for( unTempIndex = 0; unTempIndex < aTempArray.length; unTempIndex++ )
		{
			var aTemp = aTempArray[ unTempIndex ];
			for (unIndex=0; unIndex < aTemp.length; unIndex++) {
				if (aTemp[unIndex].className == 'ActiveDimension'
				|| aTemp[unIndex].className == 'TVActiveDimension'
				|| aTemp[unIndex].className == 'ChartActiveDimension'
				|| aTemp[unIndex].className == 'DragNDropRow'
				|| aTemp[unIndex].className == 'TVDragNDropRow'
				|| aTemp[unIndex].className == 'ChartDragNDropRow'
				|| aTemp[unIndex].className == 'DragNDropCol'
				|| aTemp[unIndex].className == 'TVDragNDropCol'
				|| aTemp[unIndex].className == 'ChartDragNDropCol'
				|| aTemp[unIndex].className == 'DragNDropOther'
				|| aTemp[unIndex].className == 'TVDragNDropOther'
				|| aTemp[unIndex].className == 'ChartDragNDropOther'
				|| (aTemp[unIndex].id.indexOf("-1") != -1))
				{
				clPrivate.m_clTargets[unTarget++] = aTemp[unIndex];
				}
			}
		}
	}
}
GJsdnd.prototype.Initialize = GJsdnd_Initialize;

function GJsdnd_StartDrag(
	i_clEvent
	)
{
	var clElement;
	var clEvent;
	var clFloater;
	var clPrivate;
	var clRightArrow;
	var bInDND    = false;
	var bInDNDTmp = false;
	var strDimensionName;

	clPrivate = M_clDragNDrop;
	if (!PWdsapp_bIsIE) {

		clEvent = i_clEvent;
		// Now we have the target, but a problem is that Netscape 6 considers the text node
		// (and not the containing) to be the target. 
		// Therefore we go up through the DOM tree as long as the current node is not a tag 
		// (as long as its nodeType is not 1).
		if (clEvent) {
			clElement = clEvent.target;
			while (clElement && clElement.tagName != 'TD'&& clElement.tagName != 'TH' && clElement.tagName != 'A') {
				clElement = clElement.parentNode;
			}
			if (clEvent.button == 0) {
				M_bDragging = true;
			}
		}
	}
	else {
		clEvent = clPrivate.m_clWindow.event;
		clElement = clEvent.srcElement;
		if (clEvent.button == 1) {
			M_bDragging = true;
		}
	}
	
	clFloater = clPrivate.m_clWindow.document.getElementById("DnDFltr");
	if (clElement && (clElement.className == 'ActiveDimension'
		|| clElement.className == 'TVActiveDimension'
		|| clElement.className == 'ChartActiveDimension'
		|| clElement.className == 'DragNDropRow'
		|| clElement.className == 'TVDragNDropRow'
		|| clElement.className == 'ChartDragNDropRow'
		|| clElement.className == 'DragNDropCol'
		|| clElement.className == 'TVDragNDropCol'
		|| clElement.className == 'ChartDragNDropCol'
		|| clElement.className == 'DragNDropOther'
		|| clElement.className == 'TVDragNDropOther'
		|| clElement.className == 'ChartDragNDropOther'))
	{
		bInDND = true;
	}

	if (clElement && (clElement.id == "DnDTmp")) {
		bInDNDTmp = true;
		if (PWdsapp_bIsIE) {
			clElement = clElement.parentElement;
		}
	}

	if (bInDND || bInDNDTmp) {
		// Save the position of the scrollbar
		if (typeof(vScroll) != 'undefined') {
			ObjWdsForm.sWD_VPos.value = vScroll.getTop();
		}

		// Need to hide the arrow if the active dimension is dragged.
		if (typeof(M_nActiveDimension) != 'undefined' && clElement.id.indexOf(M_nActiveDimension) != -1) {
			clRightArrow = document.getElementById("RightArrow");
			if (clRightArrow != null) {
				clRightArrow.style.visibility = 'hidden';
			}
		}

		clPrivate.m_clSourceElement = clElement;
		strDimensionName = GetDimensionNameFromCell(clElement);
		clFloater.innerHTML = "<nobr>&nbsp;" + strDimensionName + "&nbsp;</nobr>";

		SetFloaterPosition(clEvent, clFloater);
		clElement.style.visibility = 'hidden';
		clFloater.style.visibility = 'visible';
		setTimeout('M_GJsdnd_HighLightTarget()',1);
		
		return false;
	}

	return true;
}
GJsdnd.prototype.StartDrag = GJsdnd_StartDrag;

function GJsdnd_EndDrag(
	)
{
	var bKeepSort = true;
	var clDest;
	var clElement; 
	var clFloater;
	var clPrivate;
	var clSrce;
	var clForm;
	var nReportType;
	var strCol = "";
	var strRow = "";
	var strOth = "";
	var strVarDest;
	var strVarSource;
	var unTempDim;

	try {
		nReportType = parseInt(ObjWdsForm.IF_ReportType.value);
		clPrivate = M_clDragNDrop;
		clFloater = clPrivate.m_clWindow.document.getElementById("DnDFltr");
		M_ClearDimHighlight(clPrivate.m_clFlyOverElement);
		if (clPrivate.m_clSourceElement != null) {
			clSrce = clPrivate.m_clSourceElement.id;
		}
		if (clPrivate.GetTarget(clFloater) != null) {
			clDest = clPrivate.GetTarget(clFloater).id;
		}
		if ((clSrce != null) && (clDest != null)) {
			strVarSource = 'str' + clSrce.substr(0,3);
			strVarDest = 'str' + clDest.substr(0,3);
			unSourceDim = eval(clSrce.substr(3));
			unTargetDim = eval(clDest.substr(3));

			if ((unSourceDim != null) && (unTargetDim != null)
					&& (unTargetDim != unSourceDim)
					&& (clPrivate.m_clSourceElement.getAttribute("Count") != 1 || clDest.substr(3) != "-1"))
			{
				// Loop through all the dimensions from the left along the "other", then
				// from the top along the column, and from the left along the row.
				for(unTarget = 0; unTarget < clPrivate.m_clTargets.length; unTarget++) {
					clElement = clPrivate.m_clTargets[unTarget].id;

					if (clElement.substr(3) != "-1") {
						// If the element is the deferent to the target and the source, just leave it
						// in the same position.
						if ((clElement != clDest) && (clElement != clSrce)) {
							strVarName = 'str' + clElement.substr(0,3);
							eval(M_RebuildOtherColRow(clElement, strVarName, nReportType));
						}
						else {
							// Insert a dimension
							if (!m_bSwap) {

								// In this case of inserting a dimension on the left or on the top of the
								// target, the source should be inserted first.
								// Otherwise, the target should be inserted first.
								if ((clElement == clDest) && (clDest.substr(3) != "-1")) {
									if (m_bInsertTop || m_bInsertLeft) {
										eval(M_RebuildOtherColRow(clSrce, strVarDest, nReportType));
										eval(M_RebuildOtherColRow(clDest, strVarDest, nReportType));
									}
									else {
										eval(M_RebuildOtherColRow(clDest, strVarDest, nReportType));
										eval(M_RebuildOtherColRow(clSrce, strVarDest, nReportType));
									}
								}
								// In this case the "other" area is empty and we are dragging another dimension
								// to it.
								else if (clDest.substr(3) == "-1") {
									eval(M_RebuildOtherColRow(clSrce, strVarDest, nReportType));
								}
							}
							// Swap dimensions
							else {

								// In case of swaping dimensions and the element:
								// If the element equal to the target, the source should be inserted in
								// the target position.
								// If the element equal to the source, the target should be inserted in
								// the source position.
								if (clElement == clDest) {
									eval(M_RebuildOtherColRow(clSrce, strVarDest, nReportType));
								}
								else if (clElement == clSrce){
									eval(M_RebuildOtherColRow(clDest, strVarSource, nReportType));
								}
							}
						}
					}

					// Record the last Col Dimension's DimNum, it will be used for checking
					// if the inner most column is dragged.
					strVarTemp = 'str' + clElement.substr(0,3);
					if (strVarTemp == "strCol") {
						unTempDim = eval(clElement.substr(3));
					}
				}

				if (strVarSource == "strCol" && unSourceDim == unTempDim) {
					bKeepSort = false;
				}
				// When dragging and dropping dimensions from other dimensions to a Row or
				// column dimension (not to other dimension) or vice versa (from row/column to
				// other dimensions), the sorting order should be reset and also other dimension's
				// active item id should be reset as well.
				if ( (strVarSource == "strOth" || strVarDest == "strOth")
					&& strVarDest != strVarSource) {
					bKeepSort = false;
					clForm = clPrivate.m_clWindow.ObjWdsForm;
					if (strVarSource == "strOth") {
						var astrActiveItemIds = clForm.oWD_DimActiveItemId.value.split(",");
						astrActiveItemIds[unSourceDim] = "0";
						clForm.oWD_DimActiveItemId.value = astrActiveItemIds.join(",");
					}
				}
				if (strCol.charAt(strCol.length - 1) == ',') {
					strCol = strCol.substr(0, strCol.length - 1);
				}
				if (strRow.charAt(strRow.length - 1) == ',') {
					strRow = strRow.substr(0, strRow.length - 1);
				}
				if (strOth.charAt(strOth.length - 1) == ',') {
					strOth = strOth.substr(0, strOth.length - 1);
				}
				
				if (strVarSource == "strOth" && clDest == "Oth-1")	{
					//adjust strOth so that strMoving is now last instead of where it already was. E.g 4,3,6,5 becomes 4,6,5,3 if dim 3 is dragged to the end
					var strMoving = clSrce.substr(3).toString(); //"0","1","2",etc.
					var astrTmp = strOth.split(",");
					
					//no effect unless the other bar contains at least two dimensions
					if(astrTmp.length>=2) { 

						//find the original position of the dragged dimension in strOth
						var nOriginalPos=-1;
						for(var i=0; i<astrTmp.length; i++) {
							if(astrTmp[i] == strMoving) {
								nOriginalPos = i;
								break;
							}
						}
						
						//if found and not already last, shift the dimensions after the one of interest to the left and put the dragged one last
						if(nOriginalPos >= 0 && nOriginalPos < astrTmp.length-1) {
							for(var i=nOriginalPos; i<astrTmp.length-1; i++)	{
								astrTmp[i] = astrTmp[i+1];
							}
							astrTmp[astrTmp.length-1] = strMoving;
							strOth = astrTmp.join(",");
						}
					}
				}	
				
				// The column(s) have changed. Reset the sort.
				if (clPrivate.m_clWindow.ObjWdsForm.sWD_Cols.value != strCol) {
					bKeepSort = false;
				}
				CreateHiddenFormField(ObjWdsForm, "WD_Command", "SetDimOrder");
				CreateHiddenFormField(ObjWdsForm, "WD_RowDims", strRow);
				CreateHiddenFormField(ObjWdsForm, "WD_ColDims", strCol);
				CreateHiddenFormField(ObjWdsForm, "WD_OtherDims", strOth);
				clPrivate.m_clWindow.ObjWdsForm.action = clPrivate.m_clWindow.document.location.pathname;
				executeWait(clPrivate.m_clWindow.ObjWdsForm);
			}
		}
		if (clSrce != null) {
			// Need to show the arrow if the active dimension is dropped back to its position.
			if (typeof(M_nActiveDimension) != 'undefined' && clPrivate.m_clSourceElement.id.indexOf(M_nActiveDimension) != -1) {
				clRightArrow = document.getElementById("RightArrow");
				if (clRightArrow != null) {
					clRightArrow.style.visibility = 'visible';
				}
			}

			clFloater.style.visibility = 'hidden';
			clPrivate.m_clSourceElement.style.visibility = 'visible';
			clPrivate.m_clSourceElement = null;
		}
	}
	catch(ex) {
	}

	M_bDragging = false;

	return false;
}
GJsdnd.prototype.EndDrag = GJsdnd_EndDrag;

function GJsdnd_DragOver(
	i_clEvent
	)
{
	var clEvent;
	var clFloater;
	var clPrivate;

	clPrivate = M_clDragNDrop;
	clFloater = clPrivate.m_clWindow.document.getElementById("DnDFltr");

	if (!PWdsapp_bIsIE) {
		clEvent = i_clEvent;
	}
	else {
		clEvent = clPrivate.m_clWindow.event;
		// With IE, for some reason if the left button is released outside the Browser window,
		// the onmouseup event is not received.  [Note that if the body of this GJsdnd_DragOver
		// function is returns true instead of false, the onmouseup event is received but as the
		// mouse is moved the text on the screen appears 'selected'.]  So when the mouse is moved,
		// we check if we are in dragging mode and if we are we check if the mouse button is still down.  If it isn't, we end dragging.
		if (M_bDragging) {
			if (clEvent && clEvent.button != 1) {
				return GJsdnd_EndDrag(i_clEvent);
			}
		}
	}
	if (clPrivate.m_clSourceElement != null && clEvent != null)  {
		SetFloaterPosition(clEvent, clFloater);
		if (!clPrivate.m_bHighLightInProgress) {
			clPrivate.m_bHighLightInProgress = true;
			// setTimeout to create a new thread;
			setTimeout('M_GJsdnd_HighLightTarget()',1);
		}
	}

	return false;
}
GJsdnd.prototype.DragOver = GJsdnd_DragOver;

function PJsdnd(
	)
{
	this.m_clSourceElement = null;
	this.m_clWindow = null;
	this.m_bIsDimView = false;
	this.m_clTargets = null;
}

function PJsdndGetAbsPos(
	i_clElement,
	i_strPos
	)
{
	var unPos = 0;

	while (i_clElement != null) {
		unPos += i_clElement["offset" + i_strPos];
		i_clElement = i_clElement.offsetParent;
	}

	return unPos;
}
PJsdnd.prototype.GetAbsPos = PJsdndGetAbsPos;

function PJsdndGetTarget(
	i_clFloater
	)
{
	var clTargetElement;
	var clPrivate;
	var unArea;
	var unElementLeft;
	var unElementTop;
	var unFloaterLeft;
	var unFloaterTop;
	var unBiggestArea;
	var unTarget;

	unFloaterLeft = i_clFloater.offsetLeft;
	unFloaterTop = i_clFloater.offsetTop;
	unFloaterRight = unFloaterLeft + i_clFloater.offsetWidth;
	unFloaterBottom = unFloaterTop + i_clFloater.offsetHeight;
	unBiggestArea = 0;
	clTargetElement = null;
	clPrivate = M_clDragNDrop;

	for(unTarget = 0; unTarget < clPrivate.m_clTargets.length; unTarget++) {
		clElement = clPrivate.m_clTargets[unTarget];
		if ( clElement.className == 'ActiveDimension' || clElement.className == 'TVActiveDimension'
			|| clElement.className == 'ChartActiveDimension' || clElement.className == 'DragNDropRow'
			|| clElement.className == 'TVDragNDropRow' || clElement.className == 'ChartDragNDropRow'
			|| clElement.className == 'DragNDropCol' || clElement.className == 'TVDragNDropCol'
			|| clElement.className == 'ChartDragNDropCol'|| clElement.className == 'DragNDropOther'
			|| clElement.className == 'TVDragNDropOther' || clElement.className == 'ChartDragNDropOther'
			|| (clElement.id.indexOf("-1") != -1))
		{
			unElementLeft = this.GetAbsPos(clElement, "Left");
			unElementTop = this.GetAbsPos(clElement, "Top");

			unElementRight = unElementLeft + clElement.offsetWidth;
			unElementBottom = unElementTop + clElement.offsetHeight;
			unRectLeft = Math.max(unFloaterLeft, unElementLeft);
			unRectRight = Math.min(unFloaterRight, unElementRight);
			unRectTop = Math.max(unFloaterTop, unElementTop);
			unRectBottom = Math.min(unFloaterBottom, unElementBottom);
			unRectWidth = unRectRight - unRectLeft;
			unRectHeight = unRectBottom - unRectTop;
			if (unRectWidth > 0 && unRectHeight > 0) {
				unArea = unRectWidth * unRectHeight;
				if (unArea > unBiggestArea)
				{
					unBiggestArea = unArea;
					clTargetElement = clElement;
				}
			}
		}
	}

	return clTargetElement;
}
PJsdnd.prototype.GetTarget = PJsdndGetTarget;

function GetDimensionNameFromCell(
	i_clCell
	)
{
	var clInnerMostElement;
	var strDimName;

	// This is a row or column dimension
	clInnerMostElement = i_clCell.getElementsByTagName("span")[0];
	while (clInnerMostElement && clInnerMostElement.childNodes && clInnerMostElement.childNodes.length > 0)
	{
		clInnerMostElement = clInnerMostElement.childNodes[0];
	}
	if (clInnerMostElement) {
		strDimName = clInnerMostElement.data;
	}
	else {
		strDimName = " ";
	}

	return strDimName;
}

// The floater is positioned so that the mouse is in the middle of it.
function SetFloaterPosition(i_clEvent,	io_clFloater)
{
	var nMousePosX;
	var nMousePosY;
		
	if (i_clEvent != null && io_clFloater != null) {
		if (i_clEvent.clientX) {
			nMousePosX = i_clEvent.clientX;
			nMousePosY = i_clEvent.clientY;
		}
		else {
			nMousePosX = i_clEvent.pageX;
			nMousePosY = i_clEvent.pageY;
		}
		if (typeof(window.scrollX) != "undefined") {
			nMousePosX = nMousePosX + window.scrollX;
			nMousePosY = nMousePosY + window.scrollY;
		}
		else {
			nMousePosX = nMousePosX + document.body.scrollLeft;
			nMousePosY = nMousePosY + document.body.scrollTop;
		}
		if (!isNaN(nMousePosX)) {
			io_clFloater.style.left = (nMousePosX - (io_clFloater.offsetWidth / 2)) + "px";
		}
		if (!isNaN(nMousePosY)) {
			io_clFloater.style.top = (nMousePosY - (io_clFloater.offsetHeight / 2)) + "px";
		}
	}
}

