var isIE = false;
if ( navigator.appName == "Microsoft Internet Explorer" )
	isIE = true;

var bEnableRightClickBlock = false;
	
function getObject(obj) 
{
	var theObj;
	if (typeof obj == "string"){
		theObj = eval("document." + col1 + obj + styleObj );
		
		//eval("document." + col1 + obj + styleObj)
	} else {
		theObj = obj;
	}
	return theObj;
}

function setZIndex(obj, zOrder) 
{
	var theObj = getObject(obj);
	theObj.zIndex = zOrder;
}

function getBrowserWidth()
{
	if ( navigator.appName == "Netscape" )
		return window.innerWidth;
	if ( isIE && navigator.appVersion.indexOf("MSIE 6.0") && document.compatMode && document.compatMode != 'BackCompat' )
	{
		return document.documentElement.clientWidth;
	}
	else if (  isIE )
	{	   
		return document.body.clientWidth;
	}
	
}

function getBrowserHeight()
{
	if ( navigator.appName == "Netscape" )
		return window.innerHeight;
	if ( isIE && navigator.appVersion.indexOf("MSIE 6.0") && document.compatMode && document.compatMode != 'BackCompat')
		return document.documentElement.clientHeight;
	else if (  isIE )
		return document.body.clientHeight;
}

function findElement( obj, idstr )
{
	if ( obj )
	{
		if (obj.id.indexOf(idstr) != -1 )
		{
			return (obj);
		}
		else
			return(findElement(obj.parentElement, idstr));
	}
	else
		return (null);

}

function centerobj( obj, wd, hd, wfactp, hfactp, offp, offdp, lsub2, tsub2)
{   
     var w = getBrowserWidth();
     var h = getBrowserHeight();
     
     var fontsize = 13;
     var lineheight;                                                      
   

     if ( obj.style.fontSize )
     {
         fontsize = parseInt(obj.style.fontSize);
     }
        
     
 
     lineheight = fontsize;
     if ( obj.style.lineHeight )
     {
         lineheight = parseInt(obj.style.lineHeight); //worked in nn7
     }          
      
     width = wd;
     
	 if (width == -1 )
		width = parseInt(obj.style.width);
          
     var height = hd;
     if (height == -1)
		height = parseInt(obj.style.height);


    var wsubbefore = 0;
    var hsubbefore = 0;

     if (typeof(offp) != undefined && offp != null && offp != "")
     {
       var fobj = parent.document.getElementById(offp);   
        if (fobj)
        {      
              
            if ( typeof(fobj.style.left) != 'undefined'&& fobj.style.left)
            wsubbefore = wsubbefore +  parseInt(fobj.style.left);
			if ( typeof(fobj.style.top) != 'undefined' && fobj.style.top)
            hsubbefore = hsubbefore +  parseInt(fobj.style.top);  
          
        }
        	    
     }
 
     if (typeof(offdp) != 'undefined' && offdp && offdp != "")
     {
         var fobj = document.getElementById(offdp);   
        if (fobj)
        {        
            lsub2 = lsub2 +  parseInt(fobj.style.left);
            tsub2 = tsub2 +  parseInt(fobj.style.top);              
        }
     
     }
     var wfact = wfactp ? wfactp : 0.5;
     var hfact = hfactp ? hfactp : 0.5;
     

     var left = (w - width - wsubbefore)*wfact - lsub2;
     var top = (h - height - hsubbefore)*hfact - tsub2;
     var topend = 0,leftend = 0, botend = h - height;
    
      if (typeof(offdp) != 'undefined' && offdp && offdp != '')
     {
        leftend = leftend - lsub2;
        topend = topend - tsub2;
        botend =  botend - tsub2;
     }
     	
     if (top > botend ) top = botend;
     if ( left < leftend ) left = leftend;
     if (top < topend ) top = topend;
     
     obj.style.left = left;
     obj.style.top = top;
     obj.style.width = width;
     obj.style.height = height;
     
	;

}

var ParentOffDivObj = null;

 function setSelectedElem(evt) 
 { 
	if (document.layers) {        
		// Declare local var for use in upcoming loop 
		var testObj; 
		// Make copies of event coords for use in upcoming loop 
		var clickX = evt.pageX; 
		var clickY = evt.pageY; 
	     
		// Loop through all layers (starting with frontmost layer) 
		// to find if the event coordinates are in the layer 
		for (var i = document.layers.length - 1; i >= 0; i--) { 
			testObj = document.layers[i]; 
	         
			if ((clickX > testObj.left) && 
			(clickX < testObj.left + testObj.clip.width) && 
			(clickY > testObj.top) && 
			(clickY < testObj.top + testObj.clip.height)) { 
				// If so, then set the global to the layer, bring it 
				// forward, and get outa here 
				selectedObj = testObj; 
	             
				setZIndex(selectedObj, 100); 
				return; 
			} 
		} 
	} 
	else
	{ 
		// Use IE event model to get the targeted element 
	     
	     
		var imgObj;
	    
		if ( isIE )
			evt = window.event;
	   

			imgObj  = evt.srcElement; 
	        

		//  selectedObj = imgObj.parentElement.style 
		// Make sure it's one of our fish 
		//  alert(imgObj.id);
	    
		tempobj = null;
	      
	      if ( imgObj.id.indexOf("BT") != -1)
				return
			if ( imgObj.id.indexOf("Close") != -1)
				return;
			if ( imgObj.id.indexOf("HelpIcon") != -1)
				tempobj = imgObj;
			else if ( findElement( imgObj, "DialogTitleBar")  )
				tempobj = findElement( imgObj, "DialogDiv");
			else if ( findElement( imgObj, "DialogTD")  )			
				tempobj = findElement( imgObj, "DialogTable");          
			else
			{		  
	     
			selectedObj = null; 
				return; 
			}               
	                     
			if (tempobj) { 
				// Set the global to the style property of the element, 
				// bring it forward, and say adios 
	           
	          
				setZIndex(tempobj,100); 
				selectedObj = tempobj; 
	            
			// setDebugValue(selectedObj.style.left);
				return; 
			} 
	     
	} // The user probably clicked on the background 
	selectedObj = null; 
	return ;
} 

function engage(evt) 
{ 
	if (bEnableRightClickBlock)
	{
		if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
			return false;
		else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) 
		{
			alert("^_^");
		return false;
		} 
	}
	setSelectedElem(evt); 
	if (selectedObj) { 
	   
	        
		// Set globals that remember where the mouseDown is in relation to the 
		// top left corner of the element so we can keep the element-to-cursor 
		// relationship constant throughout the drag 
		if (document.layers) { 
			offsetX = evt.pageX ;
			offsetY = evt.pageY ;
	         
			return true;
		} else { 
			if ( isIE )
				evt = window.event;
	       	      			
				var yadd = document.body.scrollTop;
				
				var xadd = document.body.scrollLeft;
	        	
				if (ParentOffDivObj != null)
				{               
					xadd -= parseInt(ParentOffDivObj.style.left);
					yadd -= parseInt(ParentOffDivObj.style.top);
				}
			offsetX = evt.offsetX - xadd;
				//  setDebugValue2(offsetX);
			offsetY = evt.offsetY - yadd;
           	        
			return true;
	         
		} 
	} 
	// Block mouseDown event from forcing Mac to display 
	// contextual menu 
	if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 5)
		return true;
	return false; 
	} 

function shiftTo(obj, x, y) 
{
	var theObj = getObject(obj);
	
	if (document.layers) 
	{
		theObj.moveTo(x,y);
	} 
	else 
	{
		theObj.style.left = x;
		theObj.style.top = y;
		
		var yend = 0;
          
		if (ParentOffDivObj != null)
			yend = -1*parseInt(ParentOffDivObj.style.top);
         
         
		if (y < yend)
		{
			theObj.style.top  = yend;
		}
	}
}

var selectedObj = null; 
var offsetX = 0, offsetY = 0; 

function drag(evt) 
{ 
// Operate only if a fish is selected 
	if (selectedObj) 
	{ 		    
		if (document.layers) 
		{
			shiftTo(selectedObj, (evt.pageX - offsetX), (evt.pageY - offsetY)) ;
		} 
		else 
		{ 
			if ( isIE )
				evt = window.event;
	            
			var x; 
			var y; 
	            
			x = evt.clientX - offsetX;
			y = evt.clientY - offsetY;
	         
			//setDebugValue(y);
			shiftTo(selectedObj, x, y) ;
	         
			// Prevent further system response to dragging in IE 
			return false ;
		} 
	} 
} 

function release(evt) 
{ 
	if (selectedObj) 
	{ 
		setZIndex(selectedObj, 0) ;
		selectedObj = null ;
	} 
} 

 
	

function dd_init() 
{ 
	if ( document.layers) 
		setNavEventCapture() ;

	// assign functions to each of the events (works for both Navigator and IE) 
	document.onmousedown = engage ;
	document.onmousemove = drag;
	document.onmouseup = release ;
	   
	if (typeof(ParentOffDivID) != 'undefined')
	{
		ParentOffDivObj = document.getElementById(ParentOffDivID);   
	}
}  
	
	
