// Revised from Gbrowse, by Jester, 2007/7/30
// Script configuration
var x_offset = 5;
var y_offset = 5;
var x_pos;
var y_pos;

// Function to get the mouse position
function get_mouse(e) { 
	x_pos = (!document.all) ? e.pageX : event.x+document.body.scrollLeft;
	// Adjust x_pos to prevent pop-up menu being displayed beyond right edge of window:
	if (window.innerWidth) {
		theWidth = window.innerWidth
		theHeight = window.innerHeight
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		theWidth = document.documentElement.clientWidth
		theHeight = document.documentElement.clientHeight
	}
	else if (document.body) {
		theWidth = document.body.clientWidth
		theHeight = document.body.clientHeight
	}
	if (x_pos > ((theWidth+document.body.scrollLeft)-300)){
		x_pos = (!document.all) ? (e.pageX-305) : ((theWidth+document.body.scrollLeft)-305);
	}	
	if (!document.all) { y_pos = e.pageY }
	else {
		if (document.documentElement && document.documentElement.scrollTop) { 
			y_pos = event.y + document.documentElement.scrollTop; }
		else if (document.body) { y_pos = event.y + document.body.scrollTop; }
		else { y_pos = event.y + window.pageYOffset; }
	}
}

if (document.getElementById) {
	if(navigator.appName.substring(0,3) == "Net")
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = get_mouse;
}

// Function to build the window and drawing it
function draw_window() {
	if (document.getElementById) {
		document.getElementById("selectgenomewindow").style.top = y_pos+y_offset+"px";
		document.getElementById("selectgenomewindow").style.left = x_pos+x_offset+"px"; 
		document.getElementById("selectgenomewindow").style.visibility = "visible";
	}
}

// Destroy the window
function hide_description() {
	if (document.getElementById) {
		document.getElementById("selectgenomewindow").style.visibility = "hidden";
	}
}

// Check all checkbox: mode - 1 (check all), 0 (clear all), 2 (invert selection)
function checkall(targetform, mode)
{
 var a=document.forms[targetform].elements.length;
    for (var i=0;i<a;i++)
         {
			 var e=document.forms[targetform].elements[i];
             if (e.type == "checkbox")
                    {
					 if(mode == 1)
					  {
                          e.checked= true;
						  }
						  else if(mode==0)
						  {
						   e.checked=false;
						   }
						   else
						   {
						    var myReg=/-/;
							if(myReg.test(e.name) == true)
						    {e.checked=!e.checked;}
							else
							{e.checked= false;}
						   }
            }
         }
}

// Check related checkbox
function synchronizeCheck(targetform, val, checkval)
{
 var a=document.forms[targetform].elements.length;
 var myReg = eval("/^"+val+"-/");
 for(var i=0;i<a;i++)
 {
  var e=document.forms[targetform].elements[i];
  if (e.type == "checkbox")
  {
   if(myReg.test(e.name)== true)
   {
    e.checked = checkval;
   }
  }
 }
}

