//==============================================================================
// CONSTANTS

   var MszFloaterColor = 'yellow'; 
   var MszFloaterWidth = 50;
   var MszFloaterHeight = 20;
   var MszBorderWidth = 6;

//==============================================================================
// VARIABLES

   var m_bSwap = false;
   var m_bInsertTop = false;
   var m_bInsertLeft = false;
   var m_bLeftButton = false;

//==============================================================================
// FUNCTIONS

//------------------------------------------------------------------------------
function M_UpdateBackGroundColor(
   )
{
   var clPrivate;
   var strActiveDimColor = ".ActiveDimension";
   var strOtherDimColor = ".DimensionOther";
   var strDDRowDimColor = ".DragNDropRow";
   var strDDOtherDimColor = ".DragNDropOther";
   var strDDColDimColor = ".DragNDropCol";

   clPrivate = M_clDragNDrop;
   if (clPrivate.m_clFlyOverElement)
   {
	if (clPrivate.m_bIsDimView != true) {
		if (typeof(ObjWdsForm.IF_ReportType) != 'undefined') {
			if (ObjWdsForm.IF_ReportType.value == REPORT_TYPE_TABLE){
				strActiveDimColor = ".TVActiveDimension";
				strOtherDimColor = ".TVOtherDimension";
				strDDRowDimColor = ".TVDragNDropRow";
				strDDOtherDimColor = ".TVDragNDropOther";
				strDDColDimColor = ".TVDragNDropCol";
			} else {
				   strActiveDimColor = ".ChartActiveDimension";
				strOtherDimColor = ".ChartOtherDimension";
				strDDRowDimColor = ".ChartDragNDropRow";
				strDDOtherDimColor = ".ChartDragNDropOther";
				strDDColDimColor = ".ChartDragNDropCol";
			}
		}
		}
         
      if (clPrivate.m_clFlyOverElement.id.indexOf("-1") == -1) {
         clPrivate.m_clFlyOverElement.style.borderLeftColor = 'black';
         clPrivate.m_clFlyOverElement.style.borderLeftWidth = 1;
         clPrivate.m_clFlyOverElement.style.borderRightColor = 'black';
         clPrivate.m_clFlyOverElement.style.borderRightWidth = 1;
         clPrivate.m_clFlyOverElement.style.borderTopColor = 'black';
         clPrivate.m_clFlyOverElement.style.borderTopWidth = 1;
         clPrivate.m_clFlyOverElement.style.borderBottomColor = 'black';
         clPrivate.m_clFlyOverElement.style.borderBottomWidth = 1;
         
         if (typeof(M_nActiveDimension) != 'undefined' && clPrivate.m_clFlyOverElement.id.indexOf(M_nActiveDimension) != -1) {
            clPrivate.m_clFlyOverElement.style.backgroundColor = getBackGroundColor(strActiveDimColor);
         }
         else if (clPrivate.m_clFlyOverElement.id.indexOf("Row") != -1) {
            clPrivate.m_clFlyOverElement.style.backgroundColor = getBackGroundColor(strDDRowDimColor);
         }
         else if (clPrivate.m_clFlyOverElement.id.indexOf("Oth") != -1) {
               clPrivate.m_clFlyOverElement.style.backgroundColor = getBackGroundColor(strDDOtherDimColor);
         }
         else if (clPrivate.m_clFlyOverElement.id.indexOf("Col") != -1) {
            clPrivate.m_clFlyOverElement.style.backgroundColor = getBackGroundColor(strDDColDimColor);  
         }
      }
      else {
         clPrivate.m_clFlyOverElement.style.backgroundColor = getBackGroundColor(strOtherDimColor);
      }
   }
}

//------------------------------------------------------------------------------
function M_GJsdnd_HighLightTarget(
   )
{
   var clFloater;
   var clPrivate;
   var unElementLeft;
   var unElementTop;

   clPrivate = M_clDragNDrop;
   clFloater = clPrivate.m_clWindow.document.getElementById("DnDFltr");
   M_UpdateBackGroundColor();
   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;
      clFloater.style.backgroundColor = MszFloaterColor;
         
      // 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.
      if (clPrivate.m_clSourceElement != null) {
         if (clPrivate.m_clSourceElement.getAttribute("Count") == 1) {
            clElement.style.backgroundColor = MszFloaterColor;
            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)) 
               {
                  clElement.style.borderBottomColor = MszFloaterColor;
                  clElement.style.borderBottomWidth = MszBorderWidth;
                  m_bSwap = false;
                  m_bInsertTop = false;
                  m_bInsertLeft = false;
               }
               else if (unElementTop >= (clFloater.offsetTop + clFloater.offsetHeight / 2) 
                  && (clPrivate.m_clSourceElement.getAttribute("Count") != 1))
               {
                  clElement.style.borderTopColor = MszFloaterColor;
                  clElement.style.borderTopWidth = MszBorderWidth;
                  m_bSwap = false;
                  m_bInsertTop = true;
               }
               else {
                  clElement.style.backgroundColor = MszFloaterColor;
                  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 {
               if (clElement.id.indexOf("Row") != -1) {
                  if (clFloater.offsetLeft > (clElement.offsetLeft + clElement.offsetWidth/2))
                  {
                     clElement.style.borderRightColor = MszFloaterColor;
                     clElement.style.borderRightWidth = MszBorderWidth;
                     m_bSwap = false;
                     m_bInsertLeft = false;
                     m_bInsertTop = false;
                  }
                  else if (clElement.offsetLeft > clFloater.offsetLeft)
                  {
                     clElement.style.borderLeftColor = MszFloaterColor;
                     clElement.style.borderLeftWidth = MszBorderWidth;
                     m_bSwap = false;
                     m_bInsertLeft = true;
                  }
                  else {
                     clElement.style.backgroundColor = MszFloaterColor;
                     m_bSwap = true;
                  }
               }
               else if (clElement.id.indexOf("Oth") != -1) {
                  if (clElement.offsetLeft > clFloater.offsetLeft)
                  {
                     clElement.style.borderLeftColor = MszFloaterColor;
                     clElement.style.borderLeftWidth = MszBorderWidth;
                     m_bSwap = false;
                     m_bInsertLeft = true;
                  }
                  else {
                     clElement.style.backgroundColor = MszFloaterColor;
                     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;
      clFloater.style.backgroundColor = MszFloaterColor;
      clElement.style.backgroundColor = MszFloaterColor;
      m_bSwap = false;
   }
   
   clPrivate.m_bHighLightInProgress = null;
}

//------------------------------------------------------------------------------
function M_RebuildOtherColRow(
   i_szDim,
   i_szVar,
   i_nReportType
   )
{
   var unDim = parseInt(i_szDim.substr(3));
   // Convert from Dim codes to view postions.
   unDim = GetViewDim(unDim);

   return i_szVar + "+='" + unDim.toString() + "'+','";
}

//------------------------------------------------------------------------------
function GJsdnd(
   )
{
   this.m_clPrivate = new PJsdnd();
}

//------------------------------------------------------------------------------
function GJsdnd_Initialize(
   i_clWindow,
   i_bIsDimView
   )
{
   var aTempArray;
   var clDoc;
   var clPrivate;
   var unIndex;
   var unTempIndex;
   var unTarget = 0;
   
   clPrivate = this.m_clPrivate;
   clPrivate.m_clWindow = i_clWindow;
   clPrivate.m_bIsDimView = i_bIsDimView;
   if (i_clWindow.document.getElementById("DnDFltr") != null) {
      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 = clElement.parentNode;
         }
         if (clEvent.button == 0)
            m_bLeftButton = true;
      }
   }
   else {
      clEvent = clPrivate.m_clWindow.event;
      clElement = clEvent.srcElement;
		if (clEvent.button == 1)
			m_bLeftButton = 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)   
   {
      // Any changes made to any item should be save to the hidden fields
	   if (typeof(SaveSelectionState) != 'undefined') {
         SaveSelectionState();
      }
      // Save the position of the scrollbar
      if (typeof(vScroll) != 'undefined') {
         ObjWdsForm.WD_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>";
		if (PWdsapp_bIsIE) {
         clFloater.style.posWidth = MszFloaterWidth;
         clFloater.style.posHeight = MszFloaterHeight;
         clFloater.style.posTop = clPrivate.GetAbsPos(clElement, 'Top');
         clFloater.style.posLeft = clPrivate.GetAbsPos(clElement, 'Left');
      }
      else {
         clFloater.style.width = MszFloaterWidth;
         clFloater.style.height = MszFloaterHeight;
         clFloater.style.top = clPrivate.GetAbsPos(clElement, 'Top');
         clFloater.style.left = clPrivate.GetAbsPos(clElement, 'Left');
      }
      
      if (clEvent != null) {
         if (PWdsapp_bIsIE) {
            clFloater.offsetX = clEvent.clientX - clFloater.style.posLeft;
            clFloater.offsetY = clEvent.clientY - clFloater.style.posTop;
         }
         else {
            var strLeft = clFloater.style.left;
            var strTop = clFloater.style.top;
            clFloater.offsetX = clEvent.clientX - strLeft.substr(0, strLeft.length - 2);
            clFloater.offsetY = clEvent.clientY - strTop.substr(0, strTop.length - 2);
         }   
      }

		if (PWdsapp_bIsIE) {
         // When the floater is created, the mouse should be in the middle of the floater.
         clFloater.style.pixelLeft = clEvent.clientX - (clFloater.style.posWidth / 2);
         clFloater.style.pixelTop  = clEvent.clientY - (clFloater.style.posHeight / 2);
      }
      else {
         // When the floater is created, the mouse should be in the middle of the floater.
         var strWidth = clFloater.style.width;
         var strHeight = clFloater.style.height;
         clFloater.style.left = clEvent.pageX - (strWidth.substr(0, strWidth.length - 2) / 2);
         clFloater.style.top  = clEvent.pageY - (strHeight.substr(0, strHeight.length - 2) / 2);
      }         
      clFloater.style.backgroundColor = MszFloaterColor;         
      clElement.style.visibility = 'hidden';
      clFloater.style.visibility = 'visible';
      clFloater.style.overflow = 'hidden';
      clFloater.style.textOverflow = 'ellipsis';
      setTimeout('M_GJsdnd_HighLightTarget()',1);
   }

   return false;
}
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 szCol = "";
   var szRow = "";
   var szOth = "";
   var szVarDest;
   var szVarSrce;
   var unTempDim;

   nReportType = parseInt(ObjWdsForm.IF_ReportType.value);
   clPrivate = M_clDragNDrop;
   clFloater = clPrivate.m_clWindow.document.getElementById("DnDFltr");
   M_UpdateBackGroundColor();
   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)) {
      szVarSrce = 'sz' + clSrce.substr(0,3);
      szVarDest = 'sz' + 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)) {
                  szVarName = 'sz' + clElement.substr(0,3);
                  eval(M_RebuildOtherColRow(clElement, szVarName, 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 insert first.
                     // Otherwise, the target should be insert first.
                     if ((clElement == clDest) && (clDest.substr(3) != "-1")) {
                        if (m_bInsertTop || m_bInsertLeft) {
                           eval(M_RebuildOtherColRow(clSrce, szVarDest, nReportType));
                           eval(M_RebuildOtherColRow(clDest, szVarDest, nReportType));
                        }
                        else {
                           eval(M_RebuildOtherColRow(clDest, szVarDest, nReportType));
                           eval(M_RebuildOtherColRow(clSrce, szVarDest, 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, szVarDest, 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, szVarDest, nReportType));
                     }
                     else if (clElement == clSrce){
                        eval(M_RebuildOtherColRow(clDest, szVarSrce, nReportType));
                     }
                  }
               }
            }

            // Record the last Col Dimension's DimNum, it will be used for checking
            // if the inner most column is dragged.
            szVarTemp = 'sz' + clElement.substr(0,3);
            if (szVarTemp == "szCol") {
               unTempDim = eval(clElement.substr(3));
            }
         }

         if (szVarSrce == "szCol" && 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 ( (szVarSrce == "szOth" || szVarDest == "szOth")
            && szVarDest != szVarSrce) {
            bKeepSort = false;
            clForm = clPrivate.m_clWindow.ObjWdsForm;
            if (szVarSrce == "szOth") {
               eval("clForm.oWD_DimActiveItemId" + unSourceDim + ".value = -1");
            }
         }
         if (szCol.charAt(szCol.length - 1) == ',') {
            szCol = szCol.substr(0, szCol.length - 1);
         }
         if (szRow.charAt(szRow.length - 1) == ',') {
            szRow = szRow.substr(0, szRow.length - 1);
         }
         if (szOth.charAt(szOth.length - 1) == ',') {
            szOth = szOth.substr(0, szOth.length - 1);
         }
         // The column(s) have changed.  Reset the sort.
         if (clPrivate.m_clWindow.ObjWdsForm.sWD_Cols.value != szCol) {
            bKeepSort = false;
         }
         clPrivate.m_clWindow.ObjWdsForm.sWD_Cols.value = szCol;
         clPrivate.m_clWindow.ObjWdsForm.sWD_Rows.value = szRow;
         clPrivate.m_clWindow.ObjWdsForm.sWD_Others.value = szOth;
         clPrivate.m_clWindow.ObjWdsForm.sWD_FirstRow.value = 0;
         clPrivate.m_clWindow.ObjWdsForm.sWD_FirstCol.value = 0;
         clPrivate.m_clWindow.ObjWdsForm.sWD_ChartRow.value = 0;
         clPrivate.m_clWindow.ObjWdsForm.sWD_ChartCol.value = 0;
         if (!bKeepSort) {
            clPrivate.m_clWindow.ObjWdsForm.sWD_viewsortcode.value = "";
         }
         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;
   }
   
   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;
      
	// Spr 008800: When you drag a dimension tile and then release the mouse outside the 
	// Table area nothing will happened.
		if (!m_bLeftButton && clPrivate.m_clSourceElement != null) {
		M_UpdateBackGroundColor();
		clFloater.style.visibility = 'hidden';
		clPrivate.m_clSourceElement.style.visibility = 'visible';
		clPrivate.m_clSourceElement = null;

		return false;
	}		
   if (clPrivate.m_clSourceElement != null && clEvent != null)  {
      if (PWdsapp_bIsIE) {
         // When we start moving the floater, the mouse should be in the middle of the floater.
         clFloater.style.pixelLeft = clEvent.clientX - (clFloater.style.posWidth / 2);
         clFloater.style.pixelTop  = clEvent.clientY - (clFloater.style.posHeight / 2);
      }
      else {
         // When we start moving the floater, the mouse should be in the middle of the floater.
         var strWidth = clFloater.style.width;
         var strHeight = clFloater.style.height;
         clFloater.style.left = clEvent.pageX - (strWidth.substr(0, strWidth.length - 2) / 2);
         clFloater.style.top  = clEvent.pageY - (strHeight.substr(0, strHeight.length - 2) / 2);
      }
      
      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_szPos
   ) 
{
   var unPos = 0;

   while (i_clElement != null) {
      unPos += i_clElement["offset" + i_szPos];
      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;
}
