// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page
xOffset = 0; // Vertical position of the window
yOffset = 0; // Horizontal position of the window
xWindow = 0; // Width of the window
yWindow = 0; // Height of the window

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xOffset = window.pageXOffset;
        yOffset = window.pageYOffset;
        xMousePosMax = window.innerWidth+xOffset;
        yMousePosMax = window.innerHeight+yOffset;
        xWindow = window.innerWidth;
        yWindow = window.innerHeight;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
    	// with IE 8 we must use body.scrollTop etc. 
        if ( document.body.scrollTop || (document.documentMode && document.documentMode == 8) ) {
	        xOffset = document.body.scrollLeft;
	        yOffset = document.body.scrollTop;
	        xWindow = document.body.clientWidth;
	        yWindow = document.body.clientHeight;
	    } else {
	        xOffset = document.documentElement.scrollLeft;
	        yOffset = document.documentElement.scrollTop;
	        xWindow = document.documentElement.clientWidth;
	        yWindow = document.documentElement.clientHeight;
	    }
        xMousePos = window.event.x+xOffset;
        yMousePos = window.event.y+yOffset;
        xMousePosMax = document.body.clientWidth+xOffset;
        yMousePosMax = document.body.clientHeight+yOffset;
        xWindow = window.innerWidth;
        yWindow = window.innerHeight;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xOffset = window.pageXOffset;
        yOffset = window.pageYOffset;
        xMousePosMax = window.innerWidth+xOffset;
        yMousePosMax = window.innerHeight+yOffset;
        xWindow = window.innerWidth;
        yWindow = window.innerHeight;
    }
}

function openVersionTool(type,id) {
	if ( document.getElementById('content_'+id) ) {
		document.getElementById('content_'+id).style.visibility = 'hidden';
	}
	id = type+id;
	document.getElementById(id).style.visibility = 'visible';
	document.getElementById(id).style.display = 'block';
	//document.getElementById(id).style.top = yMousePos+'px';
	//document.getElementById(id).style.left = (xMousePos-125)+'px';
	moveMyLayer(id,0);
}

function closeVersionTool(type,id) {
	if ( document.getElementById('content_'+id) ) {
		document.getElementById('content_'+id).style.visibility = 'visible';
	}
	id = type+id;
	document.getElementById(id).style.visibility = 'hidden';
	document.getElementById(id).style.display = 'none';
}

function selectAllForDeletion(element) {
	for ( i=0; i<element.elements.length; i++ ) {
		if ( element.elements[i].type == 'checkbox' ) {
			element.elements[i].checked = true;
		}
	}
}
var posX;
var posY;

function moveMyLayer(id, Ycorrection){
	posX = xMousePos;
	posY = yMousePos;
	var div = document.getElementById(id);
	winWidth = 0;
	// Works at least with NS
	if (typeof(window.innerWidth) != undefined) { 
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
	}
	if (typeof(document.body.offsetWidth) != undefined) {  // IE
		winWidth = document.body.offsetWidth;
		winHeight = document.body.offsetHeight;
	}
	if (winWidth)
		if ((posX+div.offsetWidth+20)>winWidth)
			posX=winWidth-div.offsetWidth-20;
	if ((posY+div.offsetHeight)>yWindow+yOffset){
		posY=yWindow+yOffset-div.offsetHeight-20;
	}
	div.style.left = posX+'px';
	div.style.top = (posY+Ycorrection)+'px';
}
function showSequenceButtons(name) {
	if(document.getElementById('sequence'+name).style.display == 'none') {
		document.getElementById('movebutton'+name).style.display = 'none';
		document.getElementById('sequence'+name).style.display = 'inline';
	} else {
		document.getElementById('sequence'+name).style.display = 'none';
		document.getElementById('movebutton'+name).style.display = 'inline';
	}	
}