//=========================================================
//   
//	Global Variables
//		
//=========================================================

var elDragged = null    // Element to drag.


function wfRenavigateNSTrim()
{
	if(document.layers!=null)
	{
		var strCurrent = document.location.href;
		
		// Strip off the .htm and add _WFO.htm
		var nLen = strCurrent.length;
		var strNewURL = strCurrent.substring(0, nLen-4) + '_WFO.htm';
		var tmpWindow = window;
		
		while(tmpWindow.name.toUpperCase().indexOf('WFDIGEST', 0) == -1)
		{
			if(top == tmpWindow)
			{
				bFoundFrame = false;
				break;
			}
			tmpWindow = tmpWindow.parent;
		}
		tmpWindow.document.location = strNewURL;
	}
}

/**********************************************************************
	Function: trimLoad
	Args: Ref
	Ret: None
	
	Description: Called by a trim icon on the content page this will
  detect if the digest frame exists and load the document into it
  otherwise it will load to the top
************************************************************************/
function trimLoad(ref)
{
	if(document.layers!=null)
	{
		alert('This functionality requires Internet Explorer 4.0+');
		return;
	}
	
	var bFoundFrame = true;
	var tmpWindow = window;
    
	while(tmpWindow.name.toUpperCase().indexOf('WFDIGEST', 0) == -1)
	{
		if(top == tmpWindow)
		{
			bFoundFrame = false;
			break;
		}
		tmpWindow = tmpWindow.parent;
	}
     
	if(bFoundFrame)
	{
		tmpWindow.location = ref;
	}
	else
	{
		top.location = ref;
	}
}
  




///////////////////////////////////////////////////////////
// Note moving stuff below
///////////////////////////////////////////////////////////


/**********************************************************************
	Function: doMouseMove
	Args: None
	Ret: None
	
	Description: Deals with dragging on the mouse move
************************************************************************/

function wfOnMouseMove() 
{
	if(null!=document.layers)
	{
		return;
	}

	// Check whether mouse button is down and whether
	// an element is being dragged.

	if ((1 == event.button) && (elDragged != null)) 
	{
		// Move the element.
		// Save mouse's position in the document
		var intTop = event.clientY + document.body.scrollTop;
		var intLeft = event.clientX + document.body.scrollLeft;
    
		// Determine what element the mouse is really over.
		var intLessTop  = 0;
		var intLessLeft = 0;
		var elCurrent = elDragged.offsetParent;
		while (elCurrent.offsetParent != null) 
		{
			intLessTop += elCurrent.offsetTop;
			intLessLeft += elCurrent.offsetLeft;
			elCurrent = elCurrent.offsetParent;
		}
   
		// Set new position.
		elDragged.style.pixelTop =
		intTop  - intLessTop - elDragged.y;
		elDragged.style.pixelLeft =
		intLeft - intLessLeft  - elDragged.x;

		event.returnValue = false;
		nullClick=true;
	}
}
    
/**********************************************************************
	Function: checkDrag
	Args: None
	Ret: None
	
	Description: Checks whether the mouse is over a draggable item
************************************************************************/
              
function checkDrag(elCheck) 
{
	// Check whether the mouse is over an element
	// that supports dragging.
	while (elCheck != null) 
	{
		if (null != elCheck.getAttribute("wfDragEnabled")) 
		{
			return elCheck;
		}
		elCheck = elCheck.parentElement;
	}      
	return null;
}

/**********************************************************************
	Function: doMouseDown
	Args: None
	Ret: None
	
	Description: This will prepare a draggable element for dragging
************************************************************************/

function wfOnMouseDown() 
{
	if(null!=document.layers)
	{
		return;
	}
  
	// Store element to be dragged.
	var elCurrent = checkDrag(event.srcElement);

	if (null != elCurrent) 
	{
		elCurrent.style.border = 'red double thin';
		elCurrent.setAttribute("wfHasFocus","true");

		elDragged = elCurrent;
    
		// Determine where the mouse is in the element.
		elDragged.x = event.offsetX;
		elDragged.y = event.offsetY;
    
		var op = event.srcElement;
    
		// Find real location with respect to element being
		// dragged.
		if ((elDragged != op.offsetParent) &&
			(elDragged != event.srcElement)) 
		{
			while (op != elDragged)
			{
				//alert(op + ',' + elDragged);
				elDragged.x += op.offsetLeft;
				elDragged.y += op.offsetTop;
				op = op.offsetParent;
			}
		}
    
		oldPosX = elDragged.style.pixelLeft;
		oldPosY = elDragged.style.pixelTop;
	}
}


/**********************************************************************
	Function: releaseElement
	Args: None
	Ret: None
	
	Description: Releases an element after dragging
************************************************************************/

function releaseElement(){
  
	if(null!=document.layers)
	{
		return;
	}

	if(elDragged != null)
	{
		if ( -1 != elDragged.getAttribute("wfHasfocus") )
		{
			elDragged.style.border = '';
			elDragged.removeAttribute("wfHasFocus");
		}	
		elDragged = null;
	}
}



// Hook up mouse event handlers.
document.onmousedown = wfOnMouseDown;
document.onmousemove = wfOnMouseMove;
document.onmouseup =   releaseElement;



