/// JavaScript Document
var _startX = 0;           
var _startY = 0;
var _offsetX = 0;          
var _offsetY = 0;
var _dragElement;           
var _oldZIndex = 0;         
var opt=0.0;
var Pheight=0;
var Spage=1;
var Apage=0;
var DSpage=1;
var DBSpage=1;
var Sender=0;
var Browser=navigator.appName;
var X=0;
var Y=0;
var Xmin=PXmin=-180;
var Xmax=Pmax=180;
var Ymin=PYmin=-90;
var Ymax=PYmax=90;
var MouseB=0;
var MouseM=0;
var XFactor=0;
var YFactor=0;
var Stage=0;
var Wmax=0;
var Hmax=0;
var adjust=0;
var ScrollX=0;
var ScrollY=0;
var Pwidth=0;
var Pheight=0;
var Cwidth=0;
var Cheight=0;
var Coheight=0;
var Crop="";
var CropId=999;
var AccId=0;
var metaX=0;
var metaY=0;
var curDP=1;
var MoveResult=1;
var OverResult=0;
var QueryProgress=0;
var DownLoadProgress=0;
var Cats=new Array();
var Crops="";
var CropsList=new Array();
var SelectedAcc=new Array();
var CatsCount=0;
var otherCode=0;
var imageSlider=0.00;
var CropName="Accession Level";
var CropTotalCount=0; //Selected crop total number of accessions
var CropCurSelction=0; //Selected crop current selection number of accessions

function doAnimate(objc){
	x=document.getElementById(objc);
	//alert(objc+" "+x.style.opacity);
	if (opt<1.0) {
		opt=opt+0.10;
		if (opt>1.0) {
			opt=1.0;
		}
		x.style.opacity=opt;
		var alpha=opt*100;
		if (navigator.appName == "Microsoft Internet Explorer"){
		x.style.filter="alpha(Opacity="+alpha+",FinishedOpacity="+alpha+")";
		} 
		t=setTimeout("doAnimate(\"canvas\");",40);
	} else {
		if (navigator.appName == "Microsoft Internet Explorer"){
		x.style.filter="";
		} 
		return;
	}
}

function CropPanelAnimate(CropId)
{
	Pheight=Pheight+14;
	x=document.getElementById("C_"+CropId);
	if (Pheight <70)
	{
		x.innerHTML="<table width=\"100%\"><tr><td height=\""+Pheight+"\">&nbsp;</td></tr></table>";
		t=setTimeout("CropPanelAnimate("+CropId+");",30);
	}
	else
	{
		x.style.border=" 1px dotted #AE9F33 ";	
		return;
	}
}

function About(e) {
		Spage=5;
		resetMenu();		
		opt=0.0;
		document.title="GENESYS - Gateway to genetic resources - About Genesys";
		x=document.getElementById("canvas");
		x.style.opacity=opt;
		if (navigator.appName == "Microsoft Internet Explorer"){
		x.style.filter="alpha(opacity=0)";
		} 
		if (xmlHttp != null){
			xmlHttp.open("GET","About.php",true);
         xmlHttp.onreadystatechange=function() {
            if(xmlHttp.readyState==4)
               changeBodyPage(xmlHttp) // WORKAROUND FOR IE...
         }
			xmlHttp.send(null);
		}
	//doAnimate("canvas");
}

function Home(e) {
   Spage=1;
   resetMenu();
   opt=0.0;
   if (CropId==999) document.title="GENESYS - Gateway to genetic resources - Home page";
   else             document.title="GENESYS - Gateway to genetic resources - "+CropsList[CropId]+" - Home page";

   var x=document.getElementById("canvas");
   x.style.opacity=opt;
   if (navigator.appName == "Microsoft Internet Explorer")
      x.style.filter="alpha(opacity=0)";

   if (xmlHttp != null && Spage==1)
   {
      xmlHttp.open("GET","Home.php?CropName="+CropName,true);
	   xmlHttp.onreadystatechange=function() {
		   if(xmlHttp.readyState==4)
            changeBodyPage(xmlHttp) // WORKAROUND FOR IE...
      }
      xmlHttp.send(null);
   }

   //doAnimate("canvas");
}

function ChgActCrop(CropIdn) {
   if (document.getElementById("Tsearch"))
		document.getElementById("Tsearch").blur();

	if (document.getElementById("MapSpecies"))
		document.getElementById("MapSpecies").style.visibility="hidden";

	if (document.getElementById("Mapresult"))
		document.getElementById("Mapresult").innerHTML="";

   var cr = document.getElementById("Crop_"+CropId);
   cr.className = "CropList";
   cr.setAttribute("onMouseOver","ChgCropItm(event)");
   cr.setAttribute("onMouseOut","ResCropItm(event)");
   cr.setAttribute("onClick","ChgActCrop("+CropId+")");
   var x = document.getElementById("C_"+CropId);

   Pheight=0;

   var cc=1;
   var z;
   while (z=document.getElementById("C_"+cc)){
      z.innerHTML="";
      z.style.border="";
      cc++;
   }
   if (cropFunc != null)
   {
      CropId=CropIdn;
      d= new Date;
      cropFunc.open("GET","CropDetails.php?CropId="+CropIdn+"&D="+d.getTime(),true);
      cropFunc.onreadystatechange=function()
      {
         // response example:
         // 2;Barley;1,2,3,4,5,6,7,8,9,10;171603;171603
         if(cropFunc.readyState==4)
         {
            curDP=1;
            props=cropFunc.responseText.split(";");

            if (props[2] !="" )
            {
               catsT=props[2]; // 1,2,3,4,5,6,7,8,9,10 (categories)
               Cats=catsT.split(",");
               CatsCount=Cats.length;
            }
            h=document.getElementById("CropTitle");
            CropName=props[1];
            CropTotalCount=props[4]; //Selected crop total number of accessions
            CropCurSelction=props[3];

            // update "My result" box
            if (CropTotalCount == CropCurSelction)
               document.getElementById("myResultCell").innerHTML="<span style=\"cursor:pointer;\" onClick=\"ViewResultSet()\" id=\"myresult\">My results ("+CropCurSelction+")</span>";
            else
               document.getElementById("myResultCell").innerHTML="<span style=\"cursor:pointer;\" onClick=\"ViewResultSet()\" id=\"myresult\">My results ("+CropCurSelction+")</span><br><span style=\"float:right; font-size:7pt; margin-right:5px; position:relative; top:5px; text-decoration:underline; cursor:pointer;\" onClick=\"RemoveFilter3(-1)\">Reset</span>";

            if (props[0] != "999")
            {  //???  hidden text ??? when will this one be shown  ...?
               try {
                  h.innerText="Active Crop: "+props[1];
               } catch (err) {
                  h.textContent="Active Crop: "+props[1];
               }
            }
            else
            {
               try {
                  h.innerText=props[1];
               } catch (err) {
                  h.textContent=props[1];
               }
            }

            cr=document.getElementById("Crop_"+props[0]);
            cr.className="SelectedCrop";
            cr.removeAttribute("onMouseOver");
            cr.removeAttribute("onMouseOut");
            cr.removeAttribute("onClick");
            var t;
            switch (Spage)
            {
               case 1:
               case 5:
                  Spage=1;
                  t = setTimeout("Home(false);",30);
               break;
               case 2:
                  t = setTimeout("Summ(null);",30);
               break;
               case 3:
                  t = setTimeout("Browse(null);",30);
               break;
               case 6:
                  t = setTimeout("Map(null);",30);
               break;
            }
         }
      }
      cropFunc.send(null);
   }
}
function ChgMenItm(e,itm){
	if (itm != Spage) {	
		try {
			e.target.className="menueBGH";
		}
		catch (error) {
			event.toElement.className="menueBGH";
		}
	}
}

function ResMenItm(e,itm){
	if (itm != Spage) {
		try {
			e.target.className="menueBGO";
		}
		catch (error) {	
			event.srcElement.className="menueBGO";
		}
	}
}

function ChgCropItm(e){
	try {
		e.target.parentNode.className="CropListFcus";
	}
	catch (error) {
		event.toElement.parentElement.className="CropListFcus";
	}
}

function ResCropItm(e){
	try {
		e.target.parentNode.className="CropList";
	}
	catch (error) {	
		event.srcElement.parentElement.className="CropList";
	}
}

function Map(e)
{
	document.getElementById("MapSpecies").style.visibility="hidden";	
	Xmin    = -180;
	Xmax    = 180;
	Ymin    = -90;
	Ymax    = 90;
	XFactor = (Xmax-Xmin)/Wmax;
	YFactor = (Ymax-Ymin)/Hmax;
	Spage   = 6;
	resetMenu();
	opt     = 0.0;
	z = document.getElementById("Container");
	x = document.getElementById("canvas");
	W = z.clientWidth-43;
	H = W/2;
	Wmax = W;
	Hmax = H;
	XFactor = (Xmax-Xmin)/Wmax;
	YFactor = (Ymax-Ymin)/Hmax;
	x.style.opacity = opt;
	if (navigator.appName == "Microsoft Internet Explorer") {
		x.style.filter="alpha(opacity=0)";
	}
	if (xmlHttp != null)
	{
		var d = new Date();
		xmlHttp.open("GET","Mapv.php?Width="+W+"&Height="+H+"&d="+d.getMilliseconds(),true);
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4)
				changeBodyPage(xmlHttp) // WORKAROUND FOR IE...
		}
		xmlHttp.send(null);
	}
	// build map menus
	SM = document.getElementById("SubMenue");
	SM.innerHTML="<table align=\"left\" cellpadding=\"0\" cellspacing=\"0\"  ><tr><td width=\"10\" ></td><td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\" onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"FullExtent()\">Full extent</td><td width=\"18\"></td><td class=\"SHeaderBulits\"></td><td  class=\"SmenueBGO\" onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"Map(event)\">Reset map</td><td width=\"18\"><td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\" onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"PExtent(event)\">Previous extent</td><td width=\"18\"><td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\" onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"Google();\">Google earth file</td><td width=\"18\"><td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\" onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"ShapeFile();\">Shape file</td><td width=\"18\"><td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\" onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"DownMapImg();\">Download map image</td></tr></table>";
		
	t=setTimeout('getMapDetails()',1000);
	//	}
}

function Summ(e)
{
   Spage=2;
   SubMenus(Spage);
   opt=0.0;
   //q=document.getElementById("CropTitle").innerText;
   var z = document.getElementById("Container");
   var x = document.getElementById("canvas");
   var W = z.clientWidth-6;
   document.body.style.cursor="progress";
   x.style.cursor="wait";
   z.style.cursor="wait";
   x.style.opacity=opt;
   if (navigator.appName == "Microsoft Internet Explorer")
      x.style.filter="alpha(opacity=0)";

   if (xmlHttp != null)
   {
      D= new Date();
      switch (DSpage) // default DSpage when this one is initialized: 1
      {
         case 1:
            xmlHttp.open("GET","Countries.php?Width="+W+"&D="+D,true);
         break;
         case 2:
            xmlHttp.open("GET","Institutes.php?Width="+W+"&D="+D,true);
         break;
         case 3:
            xmlHttp.open("GET","Species.php?Width="+W+"&D="+D,true);
         break
         case 4:
            xmlHttp.open("GET","Status.php?Width="+W+"&D="+D,true);
         break
         case 5:
            xmlHttp.open("GET","MLS.php?Width="+W+"&D="+D,true);
         break
         case 7:
            xmlHttp.open("GET","Genus.php?Width="+W+"&D="+D,true);
         break
      }
      xmlHttp.onreadystatechange=function() {
         if(xmlHttp.readyState==4)
            changeBodyPage(xmlHttp) // WORKAROUND FOR IE...
      }      
      xmlHttp.send(null);
   }
}

function Browse(e){
		Spage=3;
		SubMenus(Spage);
		opt=0.0;
		q=document.getElementById("CropTitle").innerText;
		z=document.getElementById("Container");
		x=document.getElementById("canvas");
		W=z.clientWidth-8;
		x.style.opacity=opt;
		if (navigator.appName == "Microsoft Internet Explorer"){
		x.style.filter="alpha(opacity=0)";
		} 
		
		if (xmlHttp != null){
			D= new Date();
			xmlHttp.open("GET","DataBrowser.php?Crop="+q+"&newview="+DBSpage+"&Width="+W+"&D="+D.getMilliseconds(),true);
         xmlHttp.onreadystatechange=function() {
            if(xmlHttp.readyState==4)
               changeBodyPage(xmlHttp) // WORKAROUND FOR IE...
         }
			xmlHttp.send(null);
		}
}

function resetMenu()
{
	x=document.getElementById("menuraw");
	SM= document.getElementById("SubMenue");
	document.getElementById("MapSpecies").style.visibility="hidden";
	SM.innerHTML="";
	//alert(x.children.length);
	for (i=0; i<x.children.length; i++)
	{
		if (x.children[i].id.replace("M","") !=""+Spage)
		{
			if (x.children[i].id.substr(0,1)=='M')
			{
				x.children[i].className="menueBGO";
				x.children[i].onmouseover = "this.className='menueHover'";
				x.children[i].onmouseout  = "this.className='menueBGO'";		
				CurPage=x.children[i].id.substr(1,1);
				switch(CurPage)
				{
					case "1":
						x.children[i].setAttribute("onClick","Home(event)");
					break;
					case "2":
						x.children[i].setAttribute("onClick","Summ(event)");
					break;
					case "3":
						x.children[i].setAttribute("onClick","Browse(event)");
					break;
					case "4":
						x.children[i].setAttribute("onClick","Query()");
					break;
					case "5":
						x.children[i].setAttribute("onClick","About(event)");
					break;
				}
			}
		}
		else
		{
			x.children[i].className="menueSelItem";
			x.children[i].removeAttribute("onMouseOver");
			x.children[i].removeAttribute("onMouseOut");
			x.children[i].removeAttribute("onClick");
		}
	}	
}

function resetAmenu() // change menu attributes in according to user selection
{
	x=document.getElementById("Amenu");
//alert(x.children.length);
	for (i=0; i<x.children.length; i++)
	{
		sender=x.children[i].id.split(",");
		if (sender[0].replace("A_","") != ""+Apage)
		{
			//alert(sender[0]);
			if (x.children[i].id.substr(0,1)=='A')
			{
				x.children[i].className="SmenueBGO";
				// x.children[i].setAttribute("onMouseOver","this.className='SmenueHover'"); // Doesn't work in IE7
				// x.children[i].setAttribute("onMouseOut","this.className='SmenueBGO'");    // Doesn't work in IE7
				x.children[i].onmouseover = "this.className='SmenueHover'";
				x.children[i].onmouseout  = "this.className='SmenueBGO'";
				CurPage=sender[0].substr(2);

				switch(CurPage)
				{
					case "0":
						x.children[i].setAttribute("onClick","ShowPassport(this.id)");
					break;
					case "1":
						x.children[i].setAttribute("onClick","ShowEnv(this.id)");
					break;
					default:
						x.children[i].setAttribute("onClick","ShowCE(this.id)");
					break;
				}
			}
		}
		else
		{
			x.children[i].className="SmenueSelItem";
			x.children[i].removeAttribute("onMouseOver");
			x.children[i].removeAttribute("onMouseOut");
			//x.children[i].removeAttribute("onClick");
		}
	}	
	
}
/*function ChgCntItm(e){
		try {
			e.target.className="CountFlagH";
		}
		catch (error) {
			event.toElement.className="CountFlagH";
		}
}

function ResCntItm(e){
		try {
			e.target.className="CountFlag";
		}
		catch (error) {	
			event.srcElement.className="CountFlag";
		}
}*/

function regionS(e)
{            
	MouseB=1;
	MouseM=0;
	if (e == null) { e = window.event; }
	if (e.button == 2)
	{
		MouseB=0;
		document.getElementById("DMap").style.cursor = "move";
	}

	x  = document.getElementById("square");
	wm = document.getElementById("tw");
	//wm.width=0;
	//wm.height=0;
	x.innerHTML = "";
	//alert (Browser);
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		ScrollY = document.body.parentNode.scrollTop-2;
		ScrollX = document.body.parentNode.scrollLeft-2;
	}
	else
	{
		ScrollX = window.scrollX-2;
		ScrollY = window.scrollY-2;
	}

	try
	{
		x.style.left=ScrollX+event.clientX+"px";
		x.style.top=ScrollY+event.clientY+"px";
		X=event.offsetX;
		Y=event.offsetY;
	}
	catch (err)
	{
		x.style.left = scrollX+e.clientX+"px";
		x.style.top  = scrollY+e.clientY+"px";
		X = e.clientX-document.getElementById("FFC").offsetLeft-31;
		Y = e.clientY-document.getElementById("FFC").offsetTop-16;
	}
	x.style.color  = "#000000";
	x.style.border = "1px solid #000000";
	x.style.backgroundColor = "#F0C800";
	x.style.opacity = "0.70";
	if (navigator.appName == "Microsoft Internet Explorer")
		x.style.filter="alpha(opacity=70)";

	if (MouseB==1)
		x.style.visibility="visible";
}

function regionE(e)
{                    
	if (e == null) { e = window.event; }
	if (e.button ==2) { MouseB=2;	}
	
	document.getElementById("DMap").style.cursor = "crosshair";
	x  = document.getElementById("square");
	wm = document.getElementById("tw");

	try
	{
		X1=event.offsetX;
		Y1=event.offsetY;
	}
	catch (err)
	{
		X1=e.clientX-document.getElementById("FFC").offsetLeft-31;
		Y1=e.clientY-document.getElementById("FFC").offsetTop-16;
	}

	if (MouseB==2)
	{
		Xcoor=Xmin+((X-X1)*XFactor);
		Ycoor=Ymax-((Y-Y1)*YFactor);
		X1coor=Xmax+((Y-Y1)*XFactor);
		Y1coor=Ymin-((Y-Y1)*YFactor);
	}
	else
	{
		Xcoor=Xmin+(X*XFactor);
		Ycoor=Ymax-(Y*YFactor);
		X1coor=Xmin+(X1*XFactor);
		Y1coor=Ymax-(Y1*YFactor);
		PXmin=Xmin;
		PXmax=Xmax;
		PYmin=Ymin;
		PYmax=Ymax;
	}
	//alert(Xcoor+","+Ycoor+","+X1coor+","+Y1coor);
	NewW = X1coor-Xcoor;
	NewH = Ycoor-Y1coor;
	if (NewW > 0 && NewH >0)
	{
		if (NewH<(NewW/2))
		{
			adj    = ((NewW/2)-NewH)/2;
			Y1coor = Y1coor-adj
			Ycoor  = Ycoor+adj;
		}

		if (NewH>(NewW/2))
		{
			adj    = ((NewH*2)-NewW)/2;
			Xcoor  = Xcoor-adj
			X1coor = X1coor+adj;
		}
	}

	MM = document.getElementById("DMap");

	Xmin = Xcoor;
	Xmax = X1coor;
	Ymin = Y1coor;
	Ymax = Ycoor;
	if ((Xmax-Xmin)==0 || (Ymax-Ymin)==0)
	{
		Xmin = Xmin-0.5;
		Xmax = Xmax+0.5;
		Ymin = Ymin-0.25;
		Ymax = Ymax+0.25;
	}

	XFactor = (Xmax-Xmin)/Wmax;
	YFactor = (Ymax-Ymin)/Hmax;
	document.getElementById("square").style.visibility="hidden";
	document.getElementById("Mapresult").innerHTML="";

	AL = document.getElementById("instruction");
	if ((mapFunc != null) & XFactor<0.012)
	{
	//		AL.innerHTML='<span class="alert" style="float: right; margin-right: .3em;" Title="You can hover mouse on the red dots to dispaly list of accession collected from the site, and click on any of them to display it\'s full details including C&E data"></span>';
		document.getElementById("MSContent").innerHTML="";
		document.getElementById("MapSpecies").style.visibility="visible";
	//		mapFunc.open("GET","MapContent.php?Lon=0&Lat=0&XF="+XFactor+"&YF="+YFactor);
	/*		mapFunc.onreadystatechange=function() {
			 if(mapFunc.readyState==4) {
				 mapFunction();
			 }
		 }
	*/		
	///		mapFunc.send(null);
	}
	else
	{
		AL.innerHTML="&nbsp;";
		document.getElementById("MapSpecies").style.visibility="hidden";
	}

	MouseB = 0;
	var d = new Date();
	MapImage = new Image(Wmax,Hmax);
	MapImage.src = "Map.php?XXSmin="+Xmin+"&YYSmin="+Ymin+"&XXSmax="+Xmax+"&YYSmax="+Ymax+"&Stage="+Stage+"&WSmax="+Wmax+"&HSmax="+Hmax+"&d"+d.getMilliseconds();
	MM.src = MapImage.src;
	t = setTimeout('getMapDetails()',1000);
}




function regionM(e)
{        
	if (e == null) { e = window.event; }
	if (e.button ==2)
	{
		MouseB=0;
		return false;
	}

	x  = document.getElementById("square");
	wm = document.getElementById("tw");
	try
	{
		var chngX=event.offsetX-X-7;
		var chngY=event.offsetY-Y-7;
		curX=event.offsetX;
		curY=event.offsetY;
	}
	catch (err)
	{
		var chngX=e.clientX-document.getElementById("FFC").offsetLeft-31-X-7;
		var chngY=e.clientY-document.getElementById("FFC").offsetTop-16-Y-7;
		curX=e.clientX-document.getElementById("FFC").offsetLeft-31;
		curY=e.clientY-document.getElementById("FFC").offsetTop-16;
	}


	if (MouseB==1  && x.style.visibility !="hidden")
	{
		x.innerHTML="<table cellpadding=0 cellspacing=0 border=0><tr><td height="+(chngY)+" width="+(chngX)+"></td></tr></table>";
		//x.width=(chngX);
	}
	else
	{
		x.style.visibility="hidden";
		x.innerHTML="";
	}
		
	
	Xr = (Xmin+(curX*XFactor)).toFixed(6);
	Yr = (Ymax-(curY*YFactor)).toFixed(6);

	if (navigator.appName == "Microsoft Internet Explorer")
	{
		document.getElementById("Long").innerText="Longitude: "+Xr;
		document.getElementById("Lat").innerText="Latitude: "+Yr;
	}
	else
	{
		//alert ("start is ok "+curY);
		document.getElementById("Long").textContent="Longitude: "+Xr;
		document.getElementById("Lat").textContent="Latitude: "+Yr;
	}

	MapCL  = document.getElementById("MapCWE");
	DMapCL = document.getElementById("DMap");
	if (MapCL.style.visibility=="visible")
		t=setTimeout("HideMapContent();",800);
	
	if (MoveResult==1)
	{
		MapCL.style.left=(curX+175)+"px";
		MapCL.style.top=(curY+172)+"px";

		if (navigator.appName == "Microsoft Internet Explorer")
		{
			DMapCL.onmousedown = function() { regionS(event) };
			DMapCL.onmouseup   = function() { regionE(event) };
		}
		else
		{
			DMapCL.setAttribute("onMouseDown","regionS(event)");
			DMapCL.setAttribute("onMouseUp","regionE(event)");
		}

		if ((mapFunc != null) & XFactor<0.012 &  (MouseB!=1))
		{
			d= new Date;
			mapFunc.open("GET","MapContent.php?Lon="+Xr+"&Lat="+Yr+"&XF="+XFactor+"&YF="+YFactor+"&D="+d.getMilliseconds(),true);
			mapFunc.onreadystatechange=function() {
				 if(mapFunc.readyState==4) {
					 mapFunction();
				 }
			 }
			mapFunc.send(null);
			MoveResult=0;
		}
	}
}

function QueryInst(Code)
{
	Spage=3;
	resetMenu();	
	DBSpage=1;
	SubMenus();
	opt=0.0;
	q=document.getElementById("CropTitle").innerText;
	z=document.getElementById("Container");
	x=document.getElementById("canvas");
	W=z.clientWidth-6;
	x.style.opacity=opt;
	if (navigator.appName == "Microsoft Internet Explorer"){
		x.style.filter="alpha(opacity=0)";
	} 

	if (xmlHttp != null){
		D= new Date();
		xmlHttp.open("GET","DataBrowser.php?Crop="+q+"&Width="+W+"&func=3&Inst="+Code+"&D="+D.getMilliseconds(),true);
      xmlHttp.onreadystatechange=function() {
         if(xmlHttp.readyState==4)
            changeBodyPage(xmlHttp) // WORKAROUND FOR IE...
      }
		xmlHttp.send(null);
	}

}

function QueryTaxon(Code){
	Spage=3;
	resetMenu();	
	DBSpage=1;
	SubMenus(Spage);	
	opt=0.0;
	q=document.getElementById("CropTitle").innerText;
	z=document.getElementById("Container");
	x=document.getElementById("canvas");
	W=z.clientWidth-6;
	x.style.opacity=opt;
	if (navigator.appName == "Microsoft Internet Explorer"){
		x.style.filter="alpha(opacity=0)";
	} 
	if (xmlHttp != null){
		D= new Date();
		xmlHttp.open("GET","DataBrowser.php?Crop="+q+"&Width="+W+"&func=4&Taxon="+Code+"&D="+D.getMilliseconds(),true);
      xmlHttp.onreadystatechange=function() {
         if(xmlHttp.readyState==4)
            changeBodyPage(xmlHttp) // WORKAROUND FOR IE...
      }      
		xmlHttp.send(null);
	}

}

function QueryGenus(Code){
	Spage=3;
	resetMenu();	
	DBSpage=1;
	resetMenu();
	opt=0.0;
	q=document.getElementById("CropTitle").innerText;
	z=document.getElementById("Container");
	x=document.getElementById("canvas");
	W=z.clientWidth-6;
	x.style.opacity=opt;
	if (navigator.appName == "Microsoft Internet Explorer"){
		x.style.filter="alpha(opacity=0)";
	} 
	if (xmlHttp != null){
		D= new Date();
		xmlHttp.open("GET","DataBrowser.php?Crop="+q+"&Width="+W+"&func=8&Genus="+Code+"&D="+D.getMilliseconds(),true);
      xmlHttp.onreadystatechange=function() {
         if(xmlHttp.readyState==4)
            changeBodyPage(xmlHttp) // WORKAROUND FOR IE...
      }
		xmlHttp.send(null);
	}

}

function QueryStatus(Code){
	Spage=3;
	resetMenu();	
	DBSpage=1;
	SubMenus(Spage);	
	opt=0.0;
	q=document.getElementById("CropTitle").innerText;
	z=document.getElementById("Container");
	x=document.getElementById("canvas");
	W=z.clientWidth-6;
	x.style.opacity=opt;
	if (navigator.appName == "Microsoft Internet Explorer"){
		x.style.filter="alpha(opacity=0)";
	} 
	if (xmlHttp != null){
		D= new Date();
		xmlHttp.open("GET","DataBrowser.php?Crop="+q+"&Width="+W+"&func=7&Status="+Code+"&D="+D.getMilliseconds(),true);
      xmlHttp.onreadystatechange=function() {
         if(xmlHttp.readyState==4)
            changeBodyPage(xmlHttp) // WORKAROUND FOR IE...
      }
		xmlHttp.send(null);
	}

}

function QueryMLS(Code){
	Spage=3;
	resetMenu();
	DBSpage=1;
	SubMenus(Spage);	
	opt=0.0;
	q=document.getElementById("CropTitle").innerText;
	z=document.getElementById("Container");
	x=document.getElementById("canvas");
	W=z.clientWidth-6;
	x.style.opacity=opt;
	if (navigator.appName == "Microsoft Internet Explorer"){
		x.style.filter="alpha(opacity=0)";
	} 
	if (xmlHttp != null){
		D= new Date();
		xmlHttp.open("GET","DataBrowser.php?Crop="+q+"&Width="+W+"&func=9&Status="+Code+"&D="+D.getMilliseconds(),true);
      xmlHttp.onreadystatechange=function() {
         if(xmlHttp.readyState==4)
            changeBodyPage(xmlHttp) // WORKAROUND FOR IE...
      }
		xmlHttp.send(null);
	}

}

function MapQuery(){
	Spage=3;
	resetMenu();	
	DBSpage=1;
	SubMenus(Spage);	

	opt=0.0;
	x=document.getElementById("canvas");	
	q=document.getElementById("CropTitle").innerText;	
	W=z.clientWidth-6;
	x.style.opacity=opt;
	if (navigator.appName == "Microsoft Internet Explorer"){
		x.style.filter="alpha(opacity=0)";
	} 	
	var d = new Date();
	if (xmlHttp != null){
		xmlHttp.open("GET","DataBrowser.php?Crop="+q+"&Width="+W+"&func=5&page=0&Dummy="+d.getMilliseconds(),true);
      xmlHttp.onreadystatechange=function() {
         if(xmlHttp.readyState==4)
            changeBodyPage(xmlHttp) // WORKAROUND FOR IE...
      }
		xmlHttp.send(null);
	}	
}

function SelCountry(Code,Name){		
	Spage=3;
	resetMenu();	
	DBSpage=1;
	SubMenus();
	opt=0.0;
	q=document.getElementById("CropTitle").innerText;
	z=document.getElementById("Container");
	x=document.getElementById("canvas");
	W=z.clientWidth-6;
	x.style.opacity=opt;
	if (navigator.appName == "Microsoft Internet Explorer"){
		x.style.filter="alpha(opacity=0)";
	} 
	if (xmlHttp != null){
		D= new Date();
		xmlHttp.open("GET","DataBrowser.php?Crop="+q+"&Width="+W+"&func=1&Country="+Code+"&CName="+Name+"&D="+D.getMilliseconds(),true);
      xmlHttp.onreadystatechange=function() {
         if(xmlHttp.readyState==4)
            changeBodyPage(xmlHttp) // WORKAROUND FOR IE7...
      }      
		xmlHttp.send(null);
	}
	
}

function SelTaxa(Code){
	Spage=3;
	resetMenu();	
	opt=0.0;
	q=document.getElementById("CropTitle").innerText;
	z=document.getElementById("Container");
	x=document.getElementById("canvas");
	W=z.clientWidth-6;
	x.style.opacity=opt;
	if (navigator.appName == "Microsoft Internet Explorer"){
		x.style.filter="alpha(opacity=0)";
	} 
	if (xmlHttp != null){
		D= new Date();
		xmlHttp.open("GET","DataBrowser.php?Crop="+q+"&Width="+W+"&func=2&Taxon="+Code+"&D="+D.getMilliseconds(),true);
      xmlHttp.onreadystatechange=function() {
         if(xmlHttp.readyState==4)
            changeBodyPage(xmlHttp) // WORKAROUND FOR IE7...
      }
		xmlHttp.send(null);
	}
	
}

function Tsearch() {
	X=document.getElementById("Tsearch");
	R=document.getElementById("searchResult");
		if (searchFunc != null && X.value.replace(' ','') !=''){
			searchFunc.open("GET","Search.php?lookfor="+X.value,true);
			searchFunc.send(null);
			R.style.visibility="visible";
		} else {
			R=document.getElementById("searchResult");
			R.style.visibility="hidden";
			R.innerHTML="<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"></table>";			
		}
	
}

function SearchIn(){
	document.body.setAttribute("onKeyDown","");
	S=document.getElementById("Tsearch");
	S.value="";
	R=document.getElementById("searchResult");
    var curleft = 0;
    var curtop = 0;
	obj=S;
      if (obj.offsetParent) {
			do {
					curleft += obj.offsetLeft;
					curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
      }

	R.style.top=(S.offsetHeight+curtop+3)+"px";
	R.style.left=(curleft-39)+"px";
}

function SearchOut(){
	t=setTimeout("SearchHide();",250);
	document.body.setAttribute("onKeyDown","return false;");
	S=document.getElementById("Tsearch");
	S.value='Search for Taxonomy or Identifier(s)';	
}

function SearchHide(){
	R=document.getElementById("searchResult");
	R.innerHTML="<table width=\"100%\"><tr><td height=0></td><tr></table>";
	R.style.visibility="hidden";
//	R.style.top="-500px";
//	R.style.left="-500px";

}


function ShowAcc(Acc,e,chkboxElem) {
	try {
		if (event.srcElement.id.substr(0,1)=="L") return;
	}
	catch (err) {
		try {
			if (e.target.id.substr(0,1)=="L") return;
		}
		catch (err) { }
	}
	Sender=0;

	MoveResult=1;
	OverResult=0;
	otherCode=4;
	if (accFunc != null){
		accFunc.open("GET","Accession.php?lookfor="+Acc,true);
		accFunc.onreadystatechange=function() {
			if(accFunc.readyState==4) {
				x=document.getElementById("AccContent");
				x.innerHTML = accFunc.responseText;
				AccContent();
				//ContentAnimate();
			}
		}
		accFunc.send(null);
	}
}


function AccContent()
{
	DD = document.getElementById("AccContent");
	CC = document.getElementById("AccDetails");
	WW = document.getElementById("Ajxwiat");
	WW.style.visibility = "hidden";
	DD.style.visibility = "visible";
	CC.style.visibility = "visible";
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		Pwidth=document.body.clientWidth+26;
		Pheight=document.body.clientHeight;
	}
	else
	{
		Pwidth=document.documentElement.scrollWidth+17;
		Pheight=document.documentElement.scrollHeight;
	}

	CC.style.top    = "0px";
	CC.style.left   = "0px";
	CC.style.zIndex = "900";
	CC.style.width  = (Pwidth-17)+"px";
	CC.style.height = (Pheight)+"px"
	DD.height           = "600px";
	DD.style.zIndex     = "950";
	DD.style.visibility = "visible";
	DD.style.left       = ((Pwidth-800)/2)+"px";
//	CC.style.left=(((Pwidth-800)/2)+5)+"px";
//	WW.style.top="350px";
	DD.style.top = "125px";
}

function AccAnimate(){

	Q=document.getElementById("AccDetails");
	W=document.getElementById("AccCon");
//alert(Cheight+" "+Pheight+" "+Cwidth+" "+Pwidth);
	if (Cheight<Pheight || Cwidth<Pwidth) {
		if (Cheight<=Pheight) {
			Cheight =Cheight+Math.floor(Pheight/10);
			if (Cheight>Pheight) { Cheight=Pheight; }
			Q.style.height=Cheight+"px";
		}
/*		if (Cwidth<=Pwidth) {
			Cwidth = Cwidth+Math.floor(Pwidth/7);
			if (Cwidth>Pwidth) { Cwidth=Pwidth;}
			Q.style.width=(Cwidth-17)+"px";
		}*/
		t=setTimeout("AccAnimate();",20);
	} else {
	//Coheight=15;
	}
}

/*
function ContentAnimate(e){
	Q=document.getElementById("AccContent");
	Q.style.zIndex="1000";
	if (Coheight<600) {
		Coheight =Coheight+25;
		Q.style.height=Coheight+"px";
		t=setTimeout("ContentAnimate();",10);
	} else {
			Q.style.height="600px";
		//	x=document.getElementById("PanelContainer");
		//	x.style.visibility="visible";
			if (document.getElementById("Cat_P_-1")==null && Sender==1){
			WW=document.getElementById("Ajxwiat");
			WW.style.visibility="visible";
			}
	}
}*/

function CloseAcc() {
//	closeCE()
	Q=document.getElementById("AccDetails");
	W=document.getElementById("AccContent");
	Q.style.visibility="hidden";
	W.style.visibility="hidden";

}

function Google() {
	x=document.getElementById("download");
	x.src="./GoogleEarth.php?XXSmin="+Xmin+"&YYSmin="+Ymin+"&XXSmax="+Xmax+"&YYSmax="+Ymax+"&Stage="+Stage+"&WSmax="+Wmax+"&HSmax="+Hmax;
}

function ShapeFile() {
	x=document.getElementById("download");
	x.src="./MapToShapFile.php?XXSmin="+Xmin+"&YYSmin="+Ymin+"&XXSmax="+Xmax+"&YYSmax="+Ymax+"&Stage="+Stage+"&WSmax="+Wmax+"&HSmax="+Hmax;
}

function ShowCE(Cat)
{
	vars=Cat.split(",");
	lookfor=vars[1];
	otherCode=4;
	Apage=vars[0].replace("A_","");
	resetAmenu(); // reset submenu links (Accession | Morphology | etc..)
	D = new Date();
	if (otherFunc != null){
		otherFunc.open("GET","CE.php?lookfor="+lookfor+"&cat="+vars[3]+"&now="+D.getMilliseconds(),true);
		otherFunc.onreadystatechange=function() {
			if(otherFunc.readyState==4){
				otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
			}
		};
		otherFunc.send(null);
	}

/*	z=document.getElementById("CEContainer");
	z.innerHTML="";
	x=document.getElementById("CEDetails");	
	x.style.zIndex="1200";
	x.style.left=((Pwidth-803)/2)+"px";
	x.style.left="0px";
	x.style.top="0px";
	x.style.height="620px";
	z.style.zIndex="1500";
	x.style.width=(Pwidth-20)+"px";
	W=document.getElementById("CatHeader");
	W.innerText = W.textContent = "Query History";

	W.textContent=vars[2];
		if (CEFunc != null){
			CEFunc.open("GET","CE.php?lookfor="+lookfor+"&cat="+vars[3],true);
			CEFunc.send(null);
		}	*/
}

function closeCE(){
	document.getElementById("QueryContentCanvas").style.visibility="hidden";
	document.getElementById("QueryContentCanvas").innerHTML="";
	document.getElementById("AccDetails").style.visibility="hidden";
	document.getElementById("QueryContent").style.visibility="hidden";
	document.getElementById("Ajxwiat").style.visibility="hidden";
	document.body.setAttribute("onKeyDown","return false;");
	HideMeta();
}


function ShowMeta(metaId,e){
		z=window.event;
		var x=document.getElementById("meta");
		Pwidth=document.body.clientWidth+26;
		Pheight=document.body.clientHeight;
	if (navigator.appName == "Microsoft Internet Explorer"){
		var YO=e.clientY;
	} else {
		var YO=e.pageY;
	}		
		x.style.zIndex="1300";
		x.style.height="320px";	
		x.style.width="350px";					
		x.style.top=(YO-160)+"px";//((Pheight-320)/2)+"px";
		x.style.left=((Pwidth-350)/2)+"px";
			
	
		if (metaFunc != null){
			metaFunc.open("GET","Meta.php?lookfor="+metaId.replace("M_",""),true);
			metaFunc.send(null);
		}	
}

function HideMeta() {
	x=document.getElementById("meta");
	x.style.visibility="hidden";
	x.innerHTML="";
}

function ChangeSumm(sp) {
	DSpage=sp;
	Summ(null);
}

function ChangeView(sp) {
	DBSpage=sp;
	Browse(null);
}

function changePage(page)
{
	chglink=(""+curDP);
	chglink=chglink.substr((chglink.length)-1,1);
	if (chglink=="0") {chglink="10"}
	document.getElementById("c"+chglink).className="link";
	document.getElementById("c"+chglink).onclick = function() {changePage(this.textContent || this.innerText)}; // IE7 FIX // setAttribute("onClick","changePage(this.textContent || this.innerText)")
	curDP=parseInt(page);
	chglink=(""+curDP);
	chglink=chglink.substr((chglink.length)-1,1);

	if (chglink=="0") {chglink="10"}
	document.getElementById("c"+chglink).className="";
//document.getElementById("c"+chglink).removeAttribute("onClick") // IE7 FIX
	if (chgPFunc != null){
		D= new Date();
		chgPFunc.open("GET","DataBrowser.php?page="+(page)+"&D="+D.getMilliseconds(),true);
		chgPFunc.onreadystatechange=function() {
			if(chgPFunc.readyState==4) {
				p=document.getElementById("curPage");
				p.innerHTML=curDP;
				x=document.getElementById("DataTable");
				x.innerHTML=chgPFunc.responseText;
				ApplySelection();
			}
		}
		chgPFunc.send(null);
	}
}


function Pslider(dir) {
 switch (dir) {
	 case 1:
	 	LastPage=document.getElementById("numPages");
		LstPageT=LastPage.textContent;
		lastpage=parseInt(LstPageT);		
		 for (i=1; i<=10; i++){
			itm=document.getElementById("c"+i)
			num=itm.textContent;
			 newnum=parseInt(num)+10;
			 if (newnum<=lastpage) {
			 	itm.textContent=""+newnum;
				itm.onclick=function() {changePage(this.textContent || this.innerText)};
			 } else {
				itm.textContent="";
				itm.onclick=null;
			 }
			 if (newnum==lastpage){
				 document.getElementById("next").src="./images/empty.png";
				 document.getElementById("next").onclick=null;
			 }
			 if (i==1 && newnum>10){
				 document.getElementById("prior").onclick=function() {Pslider(2);}
				 document.getElementById("prior").src="./images/prior.png";
			 }
			 if (curDP==newnum) {
				 itm.className="";
			 } else {
				 itm.className="link";
			 }
		 }
	 break;
	 case 2:
	 	FirstPage=document.getElementById("c1");
		FstPageT=FirstPage.textContent;
		firstpage=parseInt(FstPageT)-10;
			 if (firstpage<=1){
				 document.getElementById("prior").src="./images/empty.png";
				 document.getElementById("prior").onclick=null;
			 }		
		 for (i=1; i<=10; i++){
			itm=document.getElementById("c"+i)
			num=itm.textContent;
			newnum=firstpage+i-1;
			itm.textContent=newnum;
			itm.onclick=function() {changePage(this.textContent || this.innerText)};
			 if (curDP==newnum) {
				 itm.className="";
			 } else {
				 itm.className="link";
			 }
		 }
				 document.getElementById("next").src="./images/next.png";
				 document.getElementById("next").onclick=function() {Pslider(1)};
	 
	 break;
 }
}

function HideMapContent(){
		if(OverResult==0){
			MapCL.style.visibility="hidden";
			MapCL.innerHTML="";			
			MoveResult=1;
		} else {
			t=setTimeout("HideMapContent();",800);
		}
}

function FullExtent()
{
	document.getElementById("MapSpecies").style.visibility="hidden";
	document.getElementById("Mapresult").innerHTML="";
	Xmin=-180;
	Xmax=180;
	Ymin=-90;
	Ymax=90;
	XFactor=(Xmax-Xmin)/Wmax;
	YFactor=(Ymax-Ymin)/Hmax;	
	MM=document.getElementById("DMap");
	var d = new Date();
	MapImage= new Image(Wmax,Hmax);
	MapImage.src="Map.php?XXSmin=-180&YYSmin=-90&XXSmax=180&YYSmax=90&Stage="+Stage+"&WSmax="+Wmax+"&HSmax="+Hmax+"&climiter="+d.getMilliseconds();
	MM.src=MapImage.src;
	document.getElementById("instruction").innerHTML="";
	t=setTimeout('getMapDetails()',4000);
}

function PExtent()
{
	document.getElementById("Mapresult").innerHTML="";
	Xmin=PXmin;
	Xmax=PXmax;
	Ymin=PYmin;
	Ymax=PYmax;
	if ((Xmax-Xmin)==0 || (Ymax-Ymin)==0)
	{
		Xmin=Xmin-0.5;
		Xmax=Xmax+0.5;
		Ymin=Ymin-0.25;
		Ymax=Ymax+0.25;		
	}
	XFactor=(Xmax-Xmin)/Wmax;
	YFactor=(Ymax-Ymin)/Hmax;	
	MM=document.getElementById("DMap");
	var d = new Date();
	MapImage= new Image(Wmax,Hmax);
	MapImage.src="Map.php?XXSmin="+Xmin+"&YYSmin="+Ymin+"&XXSmax="+Xmax+"&YYSmax="+Ymax+"&Stage="+Stage+"&WSmax="+Wmax+"&HSmax="+Hmax+"&climiter="+d.getMilliseconds();
	MM.src=MapImage.src;
	if ((mapFunc != null) & XFactor<0.012)
	{
		mapFunc.open("GET","MapContent.php?Lon="+Xr+"&Lat="+Yr+"&XF="+XFactor+"&YF="+YFactor,true);
		mapFunc.onreadystatechange=function() {
			 if(mapFunc.readyState==4) {
				 mapFunction();
			 }
		 }
		mapFunc.send(null);
		MoveResult=0;
	}
	else
	{
		document.getElementById("instruction").innerHTML="";
		document.getElementById("MapSpecies").style.visibility="hidden";
	}
	t=setTimeout('getMapDetails()',4000);
	
}


function Query()
{
	Sender=1;
	document.title="GENESYS - Gateway to genetic resources - Traits queries";
	document.body.setAttribute("onKeyDown","");
	var Z  = document.getElementById("AccDetails");
	var CC = document.getElementById("QueryContent");	
	document.getElementById("Ajxwiat").style.visibility="visible";
	var x = document.getElementById("QueryContentSubHeader");
	x.innerHTML = "";

	//	Q.setAttribute("onMouseDown",null);
	//con.setAttribute("onMouseDown",null);
	QueryProgress=-2;
	if (queryFunc != null){
		queryFunc.open("GET","CatPage.php?Cat="+QueryProgress,true);
		queryFunc.onreadystatechange = function() {
			if(queryFunc.readyState==4) {
				queryFunction();
			}
		}
		queryFunc.send(null);
	}

	if (navigator.appName == "Microsoft Internet Explorer") {
		Pwidth=document.body.clientWidth+26;
		Pheight=document.body.clientHeight+200;
	} else {
		Pwidth=document.documentElement.scrollWidth+17;
		Pheight=document.documentElement.scrollHeight;
	}

	Z.style.top="0px";
	Z.style.left="0px";
	Z.style.zIndex="900";
	Z.style.width=(Pwidth-17)+"px";
	Z.style.height="100%"; //(Pheight)+"px"
	Z.style.visibility="visible";
	CC.height="600px";
	CC.style.zIndex="950";
	CC.style.visibility="visible";   // set to visible "Trait query" div
	CC.style.left=((Pwidth-800)/2)+"px";
	CC.style.top="125px";
}



function ShowCatQuery(CatNum)
{
	con=document.getElementById("QuerycatsHeader");
	for (i=0; i<con.childNodes.length; i++)
	{
		if(con.childNodes[i].id !=null)
		{
			nodeName=con.childNodes[i].id;

			if (nodeName.substr(0,4)=="Cat_")
			{
				document.getElementById("Cat_P_"+nodeName.substr(4)).style.visibility="hidden";
				var z=document.getElementById("Cat_"+nodeName.substr(4));

				z.className   = "SmenueBGO"; // IE7 fix
				z.setAttribute("class","SmenueBGO");
				z.setAttribute("onMouseOver","this.className='SmenueHover'");
				z.setAttribute("onMouseOut","this.className='SmenueBGO'");
				z.setAttribute("onClick","ShowCatQuery(this.id)");
			}
		}
	}
	
	x=document.getElementById("Cat_P_"+CatNum.substr(4));
	x.style.visibility="visible";
	z=document.getElementById(CatNum);
	z.className="SmenueSelItem";	
	z.removeAttribute("onMouseOver");
	z.removeAttribute("onMouseOut");
	z.removeAttribute("onClick");
}

function CloseCatQuery(){
	con=document.getElementById("QueryContent");
	document.getElementById("control").style.visibility="hidden";
	document.getElementById("Ajxwiat").style.visibility="hidden";
	document.body.setAttribute("onKeyDown","return false;");

	//con.setAttribute("onmousedown","return false;");
	for (i=-1; i<15; i++){
		try {
		x=document.getElementById("Cat_P_"+i);
		con.removeChild(x);
		} catch (err){}
	}
}


function ExecQuery(qType)
{
	//locat="Qprocessor.php/?qtype="+qType;
	var locat  = "Qprocessor.php";
	var params = "qtype="+qType+"&query=";
	var z = document.getElementById("varForm");

	for (var i=0; i<z.elements.length; i++)
	{
		if (z.elements[i].value !="")
		{
			var t  = z.elements[i].id;
			var s  = t.length-3;
			var e  = t.length;
			var m  = t.substr(s,e);
			var ts = t.substr(0,s);
			switch(m)
			{
				case "_F`": // built a URL to indicate to the Qprocessor.php file that the field has to be >= value
					params = params+"_SEPARATOR_"+ts+"`>="+z.elements[i].value+","+z.elements[i].name;
				break;

				case "_T`": // built a URL to indicate to the Qprocessor.php file that the field has to be <= value
					params = params+"_SEPARATOR_"+ts+"`<="+z.elements[i].value+","+z.elements[i].name;
				break;

				case "_R`": // built a URL to indicate to the Qprocessor.php file that the field has to be LIKE '%value%'
					params = params+"_SEPARATOR_"+ts+"` LIKE '% "+z.elements[i].value+"%',"+z.elements[i].name;
				break;

				case "_M`": // built a URL to indicate to the Qprocessor.php file that all fields have to be inserted with OR condition (Passport fields)
					var qq = "(";
					var eq = "";
					var count=0;

					for (s=0; s<z.elements[i].options.length; s++)
					{
						if (z.elements[i].options[s].selected)
						{
							var elm=z.elements[i].options[s].value.split(",");
							//alert (z.elements[i].options[s].text);
							if  (qq=="(")
							{
								//z.elements[i].options[s].value.split(",",1)
								qq += ts +"` = "+elm[0];
								eq += z.elements[i].options[s].text;
							}
							else
							{
								qq += " OR "+ts +"` = "+elm[0];
								eq += " OR "+z.elements[i].options[s].text;
							}
						}
					}
					qq += ")";
					eq  = elm[2].split("=",1) +" = "+eq;
					//alert (eq);
					params = params+"_SEPARATOR_"+qq+",0,"+eq+","+elm[3];
				break;

				case "_W`": // built a URL to indicate to the Qprocessor.php file that all fields have to be inserted with OR condition
					var qq="(";
					var eq="";
					var count=0;
					for (s=0; s<z.elements[i].options.length; s++)
					{
						if (z.elements[i].options[s].selected)
						{
							elm=z.elements[i].options[s].value.split(",");
							if  (qq=="(")
							{
								//z.elements[i].options[s].value.split(",",1)
								qq += ts +"` = "+elm[0];
								eq += z.elements[i].options[s].text.substr(9);
							}
							else
							{
								qq += " OR "+ts +"` = "+elm[0];
								eq += " OR "+z.elements[i].options[s].text.substr(9);
							}

						}

					}
					qq += ")";
					eq  = elm[2].split("=",1) +" = "+eq;
					//alert (eq);
					params = params+"_SEPARATOR_"+qq+",0,"+eq+","+elm[3];
				break;
				
				default:
					params = params+"_SEPARATOR_"+z.elements[i].id+"="+z.elements[i].value // built a URL to indicate to the Qprocessor.php file that the field has to be == value
				break;
			}
		}
	}

//return false;
	if (execQueryFunc != null)
	{
		execQueryFunc.open("POST", locat, true); // BUGFIX: send ajax request in POST method. IE doesn't support a URL > 2048 characters

		//Send the proper header information along with the request
		execQueryFunc.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		execQueryFunc.setRequestHeader("Content-length", params.length);
		execQueryFunc.setRequestHeader("Connection", "close");

		execQueryFunc.onreadystatechange=function() {
			if(execQueryFunc.readyState==4) {
				if (execQueryFunc.responseText =="0")
				{
					//alert(execQueryFunc.responseText);
				}
				else
				{
					document.getElementById("myResultCell").innerHTML="<span style=\"cursor:pointer;\" onClick=\"ViewResultSet()\" id=\"myresult\">My results ("+execQueryFunc.responseText+")</span><br><span style=\"float:right; font-size:7pt; margin-right:5px; position:relative; top:5px; text-decoration:underline; cursor:pointer;\" onClick=\"RemoveFilter3(-1)\">Reset</span>";
					//"My results ("+execQueryFunc.responseText+")";
					refreshAcvPage();
					closeCE();
				}
			}
		}
		execQueryFunc.send(params); // BUGFIX: send ajax request in POST method. IE doesn't support a URL > 2048 characters
	}
}

function ExecDownLoad(){	
locat="DownLoadProcessor.php/?fields=";
z=document.getElementById("FieldsForm");
	for (var i=0; i<z.elements.length; i++){
		if (z.elements[i].checked==true){
			locat =locat+z.elements[i].id+",";
		}
	}

//return false;
//alert(locat);
x=document.getElementById("download");
x.src=locat;
ProgressTxt();
}

function refreshAcvPage() {
	//CloseAcc();	
	switch (Spage) {
		case 1:
		case 2:	
		Spage=2;
		Summ(null);
		break;
		case 3:
		DBSpage=1;
		Browse(null);
		break;			
		case 6:
		Map(null);
		break;		
	}
}

function getMapDetails() {
	var d = new Date();
	otherCode=1;
	otherFunc.open("GET","MapDetails.php?anything="+d.getTime(),true);
   otherFunc.onreadystatechange=function() {
      if(otherFunc.readyState==4){
         otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
      }
   };
	otherFunc.send(null);
}


function OnMouseDown(e)
{
    if (e == null) 
        e = window.event; 
    
    var target = e.target != null // ? e.target.parentElement.parentElement.parentElement.parentElement : e.srcElement.parentElement.parentElement.parentElement.parentElement;
//    alert (target.tagName);
    if ((e.button == 1 && e != null || 
        e.button == 0) && target.tagName =="DIV" && (target.id=="MapSpecies" || target.id =="meta"))
    {
        _startX = e.clientX;
        _startY = e.clientY;
        _offsetX = ExtractNumber(target.style.left);
        _offsetY = ExtractNumber(target.style.top);
        _oldZIndex = target.style.zIndex;
        target.style.zIndex = 10000;
        _dragElement = target;
        document.onmousemove = OnMouseMove;
        document.body.focus();
        document.onselectstart = function () { return false; };
        target.ondragstart = function() { return false; };
        return false;
    }
}


function OnMouseMove(e)
{
    if (e == null) 
        var e = window.event; 
    _dragElement.style.left = (_offsetX + e.clientX - _startX) + 'px';
    _dragElement.style.top = (_offsetY + e.clientY - _startY) + 'px';
}


function OnMouseUp(e)
{
    if (_dragElement != null)
    {
        _dragElement.style.zIndex = _oldZIndex;
        document.onmousemove = null;
        document.onselectstart = null;
        _dragElement.ondragstart = null;
        _dragElement = null;
    }
}

function ExtractNumber(value)
{
    var n = parseInt(value);
	
    return n == null || isNaN(n) ? 0 : n;
}
function $(id)
{
    return document.getElementById(id);
}


function CloseSpecies() {
		document.getElementById("MapSpecies").style.visibility="hidden";
}

function showMapSpecies(taxon)
{  
	var x = document.getElementById("SpeciesContent");
	var d = new Date();
	x.innerHTML='<img src="MapSpecContent.php?taxa='+taxon+'&d='+d.getMilliseconds()+'" />';

	obj=document.getElementById("DMap");
	var curleft = 5;
	var curtop  = 5;

	if (obj.offsetParent)
	{
		do {
			curleft += obj.offsetLeft;
			curtop  += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	
	x.style.top  = (curtop+1)+"px";
	x.style.left = (curleft+1)+"px";
	x.style.visibility = "visible";
}

function hideMapSpecies(){
	x=document.getElementById("SpeciesContent");
	x.style.visibility="visible";
	x.innerHTML='';	
}

function ShowHistory()
{
	var z=document.getElementById("HistoryCan");
	var w=document.getElementById("HistoryContent");
	z.innerHTML="";
	z.style.zIndex="1600";
	w.style.zIndex="1610";
	if (navigator.appName == "Microsoft Internet Explorer"){
		Pwidth=document.body.clientWidth+26;
		Pheight=document.body.clientHeight;
	} else {
		Pwidth=document.documentElement.scrollWidth;
		Pheight=document.documentElement.scrollHeight;
	}
	z.style.left="0px";
	z.style.top="0px";
	z.style.width=Pwidth+"px";
	z.style.height=Pheight+"px";
	z.style.visibility="visible";
	document.getElementById("Ajxwiat").style.visibility="visible";
	w.style.height="470px";
	w.style.width="800px";
	w.style.left=((Pwidth-800+16)/2)+"px";
	w.style.top="190px";
	
	otherCode=3;
	D = new Date();
		if (otherFunc != null){
			otherFunc.open("GET","History.php?now="+D.getMilliseconds(),true);
         otherFunc.onreadystatechange=function() {
            if(otherFunc.readyState==4){
               otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
            }
         };
			otherFunc.send(null);
		}	
	
}

function ShowEnv(sender) {
	data=sender.split(",");
	lookfor=data[1];
	otherCode=4;
	Apage=1;
	resetAmenu();
	D = new Date();
		if (otherFunc != null){
			otherFunc.open("GET","Environment.php?lookfor="+lookfor+"&now="+D.getMilliseconds(),true);
         otherFunc.onreadystatechange=function() {
            if(otherFunc.readyState==4){
               otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
            }
         };
			otherFunc.send(null);
		}	
	
}

function ShowPassport(sender) {
	data=sender.split(",");
	lookfor=data[1];
	otherCode=4;
	Apage=0;
	resetAmenu();
	D = new Date();
		if (otherFunc != null){
			otherFunc.open("GET","Passport.php?lookfor="+lookfor+"&now="+D.getMilliseconds(),true);
         otherFunc.onreadystatechange=function() {
            if(otherFunc.readyState==4){
               otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
            }
         };
			otherFunc.send(null);
		}	

}

function flick(s) {
   if (document.getElementById("CropNameL"))
   {
      if (Spage==1 && CropId ==999) // true if user has selected "all accessions"(999, homepage)
      {
         s = (s<=21)? s+1 : 1;
         CropT= document.getElementById("CropNameL");
         CropT.innerHTML=CropsList[s]; // change the crop name dynamically in homepage
         otherCode=10;
         document.getElementById("cropImage").style.width="480px";
         animateCropImage(s-1);
         t = setTimeout("flick("+(s)+");",5000);
         //alert(CropsList[s]+" - "+s);   // DEBUG
         D = new Date();
         if (otherFunc != null ){
            otherFunc.open("GET","CropText.php?CropId="+s+"&now="+D.getTime(),true);
            otherFunc.onreadystatechange=function() {
               if(otherFunc.readyState==4){
                  otherFunctions(otherFunc);  // WORKAROUND FOR IE7...
               }
            };
            otherFunc.send(null);
         }
      }
   }
}

function animateCropImage(w) {
	CR=document.getElementById("cropImage");
	if (imageSlider<=1.0 && Spage==1){
      //alert('w='+w+' - imgSlider='+imageSlider+' - bgPosition='+(-(w*480)-(480*imageSlider)));
		CR.style.backgroundPosition=(-(w*480)-(480*imageSlider))+"px 0px";
      imageSlider=imageSlider+0.1;
		t=setTimeout("animateCropImage("+w+");",33.5);		
	} else {
		imageSlider=0.00;
	}
}

function CloseHistory(){
	z=document.getElementById("HistoryCan");
	w=document.getElementById("HistoryContent");
	document.getElementById("Ajxwiat").style.visibility="hidden";
	z.style.visibility="hidden";
	w.style.visibility="hidden";
	w.innerHTML="";	
}

function RemoveFilter(filteridx){
		otherCode=6;
		D = new Date();
		if (otherFunc != null){
			otherFunc.open("GET","removefilter.php?filter="+filteridx+"&now="+D.getMilliseconds(),true);
         otherFunc.onreadystatechange=function() {
            if(otherFunc.readyState==4){
               otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
            }
         };
			otherFunc.send(null);
		}	
}

function RemoveFilter2(filteridx2){
		otherCode=9;
		D = new Date();
		if (otherFunc != null){
			otherFunc.open("GET","removefilter.php?filter="+filteridx2+"&now="+D.getMilliseconds(),true);
         otherFunc.onreadystatechange=function() {
            if(otherFunc.readyState==4){
               otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
            }
         };
			otherFunc.send(null);
		}	
}

function RemoveFilter3(filteridx){
		otherCode=12;
		D = new Date();
		if (otherFunc != null){
			otherFunc.open("GET","removefilter.php?filter="+filteridx+"&now="+D.getMilliseconds(),true);
         otherFunc.onreadystatechange=function() {
            if(otherFunc.readyState==4){
               otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
            }
         };
			otherFunc.send(null);
		}	
}

function ShowNews(newsID){
	//var Gnews=news.substr(2,(news.length)-1);
	otherCode=7;
	D = new Date();
	if (otherFunc != null){
		otherFunc.open("GET","getnews.php?news="+newsID+"&now="+D.getMilliseconds(),true);
		otherFunc.onreadystatechange=function() {
			if(otherFunc.readyState==4){
				otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
			}
		};
		otherFunc.send(null);
	}
}

function HideNews(){
	x=document.getElementById("newsViewer");
	x.style.visibility="hidden";
}

function ViewResultSet(){
	z=document.getElementById("HistoryCan");
	w=document.getElementById("MyResultSet");
	z.innerHTML="";
	z.style.zIndex="1600";
	w.style.zIndex="1610";
		if (navigator.appName == "Microsoft Internet Explorer"){
		Pwidth=document.body.clientWidth+26;
		Pheight=document.body.clientHeight;
	} else {
		Pwidth=document.documentElement.scrollWidth;
		Pheight=document.documentElement.scrollHeight;
	}
	z.style.left="0px";
	z.style.top="0px";
	z.style.width=Pwidth+"px";
	z.style.height=Pheight+"px";
	z.style.visibility="visible";
	//document.getElementById("Ajxwiat").style.visibility="visible";
	w.style.height="570px";
	w.style.width="800px";
	w.style.left=((Pwidth-800+16)/2)+"px";
	w.style.top="90px";
	otherCode=8;
	D = new Date();
   if (otherFunc != null){
      otherFunc.open("GET","MyResultSet.php?now="+D.getMilliseconds(),true);
      otherFunc.onreadystatechange=function() {
         if(otherFunc.readyState==4){
            otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
         }
      };
      otherFunc.send(null);
   }
	
}

function CloseResultSet(){
	z=document.getElementById("HistoryCan");
	w=document.getElementById("MyResultSet");
	document.getElementById("Ajxwiat").style.visibility="hidden";
	z.style.visibility="hidden";
	w.style.visibility="hidden";
	w.innerHTML="";	
}

function SummRep(){
x=document.getElementById("download");
x.src="./SummeryReport.php";
}

function DownMapImg() {
	x=document.getElementById("download");
	x.src="./MapImage.php";
}

function SubMenus()  // build submenus in according to Spage variable 
{
	switch (Spage)
   {
		case 3:
         document.title="GENESYS - Gateway to genetic resources - Data browser";
         Links="<table align=\"left\" cellpadding=\"0\" cellspacing=\"0\"  ><tr> <td width=\"10\" ></td>";
         if (DBSpage ==1) {
            Links =Links+" <td class=\"SHeaderBulits\"></td><td class=\"SmenueSelItem\">Passport view</td><td width=\"18\">";
         } else {
            Links=Links+"<td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\"  onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"ChangeView(1)\">Passport view</td><td width=\"18\">";
         }

         if (DBSpage ==2) {
            Links =Links+" <td class=\"SHeaderBulits\"></td><td class=\"SmenueSelItem\">Pedigree view</td><td width=\"18\">";
         } else {
            Links=Links+"<td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\"  onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"ChangeView(2)\">Pedigree view</td><td width=\"18\">";
         }

            Links=Links+"<td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\"  onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"DownloadData()\">Data Download</td><td width=\"18\">";

         resetMenu();
         Links=Links+"</tr></table>";
         SM= document.getElementById("SubMenue");
         SM.innerHTML=Links;
		break;
		case 2:
		   document.title="GENESYS - Gateway to genetic resources - Data summaries";
         resetMenu();
         SM= document.getElementById("SubMenue");
         Links="<table align=\"left\" cellpadding=\"0\" cellspacing=\"0\"  ><tr> <td width=\"10\" ></td>";
         if (DSpage ==1) {
            Links =Links+" <td class=\"SHeaderBulits\"></td><td class=\"SmenueSelItem\">By Source Countries</td><td width=\"18\">";
         } else {
            Links=Links+"<td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\"  onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"ChangeSumm(1)\">By Source Countries</td><td width=\"18\">";
         }

         if (DSpage ==2) {
            Links =Links+" <td class=\"SHeaderBulits\"></td><td class=\"SmenueSelItem\">By Holding Institutes</td><td width=\"18\">";
         } else {
            Links=Links+"<td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\"  onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"ChangeSumm(2)\">By Holding Institutes</td><td width=\"18\">";
         }

         if (DSpage ==7) {
            Links =Links+" <td class=\"SHeaderBulits\"></td><td class=\"SmenueSelItem\">By Genus</td><td width=\"18\">";
         } else {
            Links=Links+"<td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\"  onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"ChangeSumm(7)\">By Genus</td><td width=\"18\">";
         }

         if (DSpage ==3) {
            Links =Links+" <td class=\"SHeaderBulits\"></td><td class=\"SmenueSelItem\">By Genus / Species</td><td width=\"18\">";
         } else {
            Links=Links+"<td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\"  onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"ChangeSumm(3)\">By Genus / Species</td><td width=\"18\">";
         }

         if (DSpage ==4) {
         Links =Links+" <td class=\"SHeaderBulits\"></td><td class=\"SmenueSelItem\">By Biological Status</td><td width=\"18\">";
         } else {
            Links=Links+"<td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\"  onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"ChangeSumm(4)\">By Biological Status</td><td width=\"18\">";
         }

         if (DSpage ==5) {
         Links =Links+" <td class=\"SHeaderBulits\"></td><td class=\"SmenueSelItem\">By MLS Status</td><td width=\"18\">";
         } else {
            Links=Links+"<td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\"  onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"ChangeSumm(5)\">By MLS Status</td><td width=\"18\">";
         }

         if (DSpage ==6) {
         Links =Links+" <td class=\"SHeaderBulits\"></td><td class=\"SmenueSelItem\">Data summary Report</td>";
         } else {
            Links=Links+"<td class=\"SHeaderBulits\"></td><td class=\"SmenueBGO\"  onMouseOver=\"this.className='SmenueHover'\" onMouseOut=\"this.className='SmenueBGO'\" onClick=\"SummRep()\">Data summary Report</td>";
         }

         Links=Links+"</tr></table>";
         SM.innerHTML=Links;
		break;
	}
}

function doResize() {
	z=document.getElementById("HistoryCan");
		if (z.style.visibility=="visible"){
			if (navigator.appName == "Microsoft Internet Explorer"){
			Pwidth=document.body.clientWidth+26;
			Pheight=document.body.clientHeight;
		} else {
			Pwidth=document.documentElement.scrollWidth;
			Pheight=document.documentElement.scrollHeight;
		}
		z.style.left="0px";
		z.style.top="0px";
		z.style.width=Pwidth+"px";
		z.style.height=Pheight+"px";
	}

}

function Selall(){
	chks=document.getElementsByTagName("input");
	x=document.getElementById("Selall");
	CurSelection=SelectedAcc.toString();
	NewSelection="";
	CurCount=SelectedAcc.length;
	for (var i=0; i<chks.length; i++){
		if ((CurCount+i)>251 && x.checked==true){
		chks[i].checked=false;
		alert("You have reached the maximum number of accession per request");
		SelectedAcc = NewSelection.split(",");
			if (NewSelection !=""){
				document.getElementById("selection").innerHTML="<span onClick=\"ViewMySelection()\">My selection ("+SelectedAcc.length+")</span><br><span style=\"float:right; font-size:7pt; margin-right:5px; position:relative; top:5px; text-decoration:underline; cursor:pointer;\" onClick=\"RestSel()\"><img src='./images/reset1.png' border='0'/></span>";
			} else {
				document.getElementById("selection").innerHTML="<span>My selection (0)</span>";
			}		
		return false;
		break;
	}
			accNo=chks[i].id.substr(1,chks[i].id.length);
			CurSelection=CurSelection.replace(accNo,"");
			CurSelection=CurSelection.replace(",,",",");
			if (CurSelection.substr(CurSelection.length-1,CurSelection.length) ==","){
				CurSelection=CurSelection.substr(0,CurSelection.length-1);
			}
			if (CurSelection.substr(0,1) ==","){
				CurSelection=CurSelection.substr(1,CurSelection.length);
			}
			
			NewSelection= CurSelection;		
		if ( chks[i].type=="checkbox" && chks[i].id.substr(0,1)=="L" && chks[i].disabled!=true ) {			
			chks[i].checked=x.checked;
			
			if (chks[i].checked==true){
				
			if (CurSelection=="") {
				NewSelection= accNo; 
			} else {
				NewSelection= CurSelection+","+accNo;
			}	
		} else {

		}
		CurSelection=NewSelection;
/*			var accNo=chks[i].id.substr(1,chks[i].id.length-1);
			if (CurSelection.search(accNo) !=0 && chks[i].checked==true){
				NewSelection +=  accNo+","
			}*/
		}
	}

	//NewSelection = NewSelection.substr(0,NewSelection.length-1);
	SelectedAcc = NewSelection.split(",");
	//alert (NewSelection);
	if (NewSelection !="") {
		document.getElementById("selection").innerHTML="<span onClick=\"ViewMySelection()\">My selection ("+SelectedAcc.length+")</span><br><span style=\"float:right; font-size:7pt; margin-right:5px; position:relative; top:5px; text-decoration:underline; cursor:pointer;\" onClick=\"RestSel()\"><img src='./images/reset1.png' border='0'/></span>";
	} else {
		document.getElementById("selection").innerHTML="<span>My selection (0)</span>";
	}
}

function SelAcc(e)
{
	CurSelection = SelectedAcc.toString();
	NewSelection = "";
	x = document.getElementById(e);
	if (SelectedAcc.length >= 250 && x.checked==true) {
		x.checked=false;
		alert("You have reached the maximum number of accession per request");
		return false;
	}
	accNo=e.substr(1,e.length);
//	if (CurSelection.search(accNo) ==-1 ){
		if (x.checked==true)
         NewSelection = CurSelection==""? accNo : CurSelection+","+accNo;
      else
      {
			CurSelection = CurSelection.replace(accNo,"").replace(",,",",");

			if (CurSelection.substr(CurSelection.length-1,CurSelection.length) == ",") // delete last comma from string
				CurSelection = CurSelection.substr(0,CurSelection.length-1);

			if (CurSelection.substr(0,1) == ",")
				CurSelection = CurSelection.substr(1,CurSelection.length);

			NewSelection = CurSelection;
		}
//	}
	SelectedAcc = NewSelection.split(",");
	if (NewSelection !="")
		document.getElementById("selection").innerHTML="<span onClick=\"ViewMySelection()\">My selection ("+SelectedAcc.length+")</span><br><span style=\"float:right; font-size:7pt; margin-right:5px; position:relative; top:5px; text-decoration:underline; cursor:pointer;\" onClick=\"RestSel()\"><img src='./images/reset1.png' border='0'/></span>";
	else
		document.getElementById("selection").innerHTML="<span>My selection (0)</span>";
}

function add2MySelection(alisId)
{
   if (SelectedAcc.length >= 250)
      alert("You have reached the maximum number of accession per request");
   else
   {
      x = document.getElementById(alisId);
      if(x) // from passport or pedigree menus
      {
         if(x.checked)
         {
            alert('Sorry\nThis accession has already been added.');
            return; // do nothing
         }
         else x.checked = true;

         CloseAcc(); // close accession details window
         SelAcc(alisId); // add accession to "My Selection"
      }
      else
      {
         // try to add this accession to "My Selection" (this function can be also called from the map)
         alisId = alisId.substr(1, alisId.length); // remove first char to obtain the correct alis id
         var foundIt = false;
         for(i=0; i<SelectedAcc.length; i++)
            if(SelectedAcc[i]==alisId) foundIt=true;

         if(!foundIt)
         {
            // alis id not found in SelectedAcc variable. Add it to the end of array.
            SelectedAcc.splice(SelectedAcc.length, 0, alisId);
            document.getElementById("selection").innerHTML="<span onClick=\"ViewMySelection()\">My selection ("+SelectedAcc.length+")</span><br><span style=\"float:right; font-size:7pt; margin-right:5px; position:relative; top:5px; text-decoration:underline; cursor:pointer;\" onClick=\"RestSel()\"><img src='./images/reset1.png' border='0'/></span>";
         }
         else alert('Sorry\nThis accession has already been added.');
      }
   }

   CloseAcc(); // close accession details window
}

function addAllAccs2MySelection()
{
   if(CropCurSelction > 250)
   {
      alert("Sorry, the results exceed the maximum number of accessions per request");
		return false;
   }

   if (otherFunc != null) {
      otherFunc.open("GET","getAllAvailableAccs.php?now="+D.getMilliseconds(),true);
      otherFunc.onreadystatechange=function() {
         if(otherFunc.readyState==4) {
            var accessionsCommaSeparated = otherFunc.responseText;
            SelectedAcc = accessionsCommaSeparated.split(",");
            if(accessionsCommaSeparated != "")
               document.getElementById("selection").innerHTML="<span onClick=\"ViewMySelection()\">My selection ("+SelectedAcc.length+")</span><br><span style=\"float:right; font-size:7pt; margin-right:5px; position:relative; top:5px; text-decoration:underline; cursor:pointer;\" onClick=\"RestSel()\"><img src='./images/reset1.png' border='0'/></span>";
            else
               document.getElementById("selection").innerHTML="<span>My selection (0)</span>";

            if(Spage==3 && (DBSpage==1 || DBSpage==2)) // check if the current body page is showing an accession list and the checkbox associated ("passport view" and "pedigree view" menus). If true, select all available accessions.
               ChangeView(DBSpage);
         }
      };
      otherFunc.send(null);
   }

   CloseResultSet();
}

function ApplySelection (){
	CurSelection=SelectedAcc.toString();
	chks=document.getElementsByTagName("input");
	for (var i=0; i<chks.length; i++){
		if ( chks[i].type=="checkbox" && chks[i].id.substr(0,1)=="L" ) {
			accNo=chks[i].id.substr(1,chks[i].id.length);
			if (CurSelection.search(accNo) !=-1){
				chks[i].checked=true;
			} else {
				chks[i].checked=false;
			}
		}
	}
}


function ViewMySelection(){
	z=document.getElementById("HistoryCan");
	w=document.getElementById("MySelection");
	z.innerHTML="";
	z.style.zIndex="1600";
	w.style.zIndex="1610";
		if (navigator.appName == "Microsoft Internet Explorer"){
		Pwidth=document.body.clientWidth+26;
		Pheight=document.body.clientHeight;
	} else {
		Pwidth=document.documentElement.scrollWidth;
		Pheight=document.documentElement.scrollHeight;
	}
	z.style.left="0px";
	z.style.top="0px";
	z.style.width=Pwidth+"px";
	z.style.height=Pheight+"px";
	z.style.visibility="visible";
	w.style.height="602px";
	w.style.width="800px";
	w.style.left=((Pwidth-800+16)/2)+"px";
	w.style.top="90px";	
	otherCode=16;
	D = new Date();
   if (otherFunc != null){
      otherFunc.open("GET","MySelection.php?step=1&now="+D.getMilliseconds(),true);
      otherFunc.onreadystatechange=function() {
         if(otherFunc.readyState==4){
            otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
         }
      };
      otherFunc.send(null);
   }
}

function CloseMySelection() {
	Q=document.getElementById("MySelection");
	W=document.getElementById("HistoryCan");
	if (document.getElementById("DownLoadContentCanvas")){
	}
	Q.style.visibility="hidden";
	W.style.visibility="hidden";

}

function DownloadData(){
	z=document.getElementById("HistoryCan");
	w=document.getElementById("DownloadData");
	z.innerHTML="";
	z.style.zIndex="1600";
	w.style.zIndex="1610";
		if (navigator.appName == "Microsoft Internet Explorer"){
		Pwidth=document.body.clientWidth+26;
		Pheight=document.body.clientHeight;
	} else {
		Pwidth=document.documentElement.scrollWidth;
		Pheight=document.documentElement.scrollHeight;
	}
	z.style.left="0px";
	z.style.top="0px";
	z.style.width=Pwidth+"px";
	z.style.height=Pheight+"px";
	z.style.visibility="visible";
	w.style.height="602px";
	w.style.width="800px";
	w.style.left=((Pwidth-800+16)/2)+"px";
	w.style.top="90px";	
	otherCode=11;
	D = new Date();
		if (otherFunc != null){
			otherFunc.open("GET","DataDownloader.php?step=1&now="+D.getMilliseconds(),true);
         otherFunc.onreadystatechange=function() {
            if(otherFunc.readyState==4){
               otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
            }
         };         
			otherFunc.send(null);
		}	
}


function CloseDownload() {
	Q=document.getElementById("DownloadData");
	W=document.getElementById("HistoryCan");
	if (document.getElementById("DownLoadContentCanvas")){
	document.getElementById("DownLoadContentCanvas").style.visibility="hidden";
	document.getElementById("DownLoadContentCanvas").innerHTML="";
	}
	Q.style.visibility="hidden";
	W.style.visibility="hidden";
	CloseResultSet();
}

function Accept(){
	Q=document.getElementById("Agree");
	if (Q.checked==false){
		alert ("Please click on the checkbox to indicate that you read and understood the condition of use");
	} else {
		otherCode=11;
		D = new Date();
		DownLoadProgress=-3;
		if (otherFunc != null){
			otherFunc.open("GET","DataDownloader.php?step=2&now="+D.getMilliseconds(),true);
         otherFunc.onreadystatechange=function() {
            if(otherFunc.readyState==4){
               otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
            }
         };         
			otherFunc.send(null);
		}		
	}
}

function AcceptDisc(){
	Q=document.getElementById("Agree");
	if (Q.checked==false){
		alert ("Please click on the checkbox to indicate that you read, understood, and agree to the Disclaimer");
	} else {
		otherCode=16;
		D = new Date();
		if (otherFunc != null){
			otherFunc.open("GET","MySelection.php?step=2&selection="+SelectedAcc.toString()+"&now="+D.getMilliseconds(),true);
         otherFunc.onreadystatechange=function() {
            if(otherFunc.readyState==4){
               otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
            }
         };         
			otherFunc.send(null);
		}		
	}
}

function StartDownload() {
	otherCode=14;
	if (otherFunc != null){
		otherFunc.open("GET","DataDownloader.php?step=3&now="+D.getMilliseconds(),true);
      otherFunc.onreadystatechange=function() {
         if(otherFunc.readyState==4){
            otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
         }
      };
		otherFunc.send(null);
	}	
	ExecDownLoad();
}

function Back(){
		otherCode=11;
		D = new Date();
		DownLoadProgress=-3;
		if (otherFunc != null){
			otherFunc.open("GET","DataDownloader.php?step=2&now="+D.getMilliseconds(),true);
         otherFunc.onreadystatechange=function() {
            if(otherFunc.readyState==4){
               otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
            }
         };         
			otherFunc.send(null);
		}	
}

function ProgressTxt(){
		if (DownLoadpro != null){
			DownLoadpro.open("GET","GetProgress.php",true);
			DownLoadpro.send(null);
		}	
}

function RestSel(){
		SelectedAcc=new Array();
		//document.getElementById("selection").innerText="My selection (0)";
        document.getElementById("selection").innerHTML="My selection (0)";
		if (document.getElementById("Selall")){
			document.getElementById("Selall").checked=false;
		}
		ApplySelection();
		
}

function Proceed(){
		otherCode=16;
		D = new Date();
		if (otherFunc != null){
			otherFunc.open("GET","MySelection.php?step=3&now="+D.getMilliseconds(),true);
         otherFunc.onreadystatechange=function() {
            if(otherFunc.readyState==4){
               otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
            }
         };         
			otherFunc.send(null);
		}	
}

function SubmitSelection(){
		otherCode=17;
		pass=document.getElementById("pass").value;
		user=document.getElementById("user").value;		
		document.getElementById("error").innerHTML="<span style=\"color:#F00; font-size:8pt; font-weight:bold;\">Please wait while checking your username and password...</span>"	
		D = new Date();
		if (otherFunc != null){
			otherFunc.open("GET","CheckPass.php?user="+user+"&pass="+pass+"&now="+D.getMilliseconds(),true);
         otherFunc.onreadystatechange=function() {
            if(otherFunc.readyState==4){
               otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
            }
         };         
			otherFunc.send(null);
		}	
}

/*
*************************************************
******************** INIT() *********************
*************************************************
*/

function init(e,Crop,Acc) {
	browser = navigator.appName;
	document.onmousedown = OnMouseDown;
	document.onmouseup = OnMouseUp;
	document.cookie = "test=0 expiredays==null" ;
	loc=document.cookie.indexOf("test=");
		if ( loc != -1 ) {
			cookie_set = true;
			document.cookie ="test=0 expiredays==-1";
		} else {
			cookie_set = false;
			document.write("");
			alert ("cookies must be anabled to run GENESYS");
		}

   try
   {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      cropFunc=new XMLHttpRequest();
      searchFunc=new XMLHttpRequest();
      accFunc=new XMLHttpRequest();
      metaFunc=new XMLHttpRequest();
      chgPFunc=new XMLHttpRequest();
      mapFunc=new XMLHttpRequest();
      queryFunc=new XMLHttpRequest();
      execQueryFunc=new XMLHttpRequest();
      DownLoadFunc=new XMLHttpRequest();
      DownLoadpro=new XMLHttpRequest();
      otherFunc=new XMLHttpRequest();
   }
   catch (e)
   {
      // Internet Explorer
      try
      {
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
         cropFunc=new ActiveXObject("Msxml2.XMLHTTP");
         searchFunc=new ActiveXObject("Msxml2.XMLHTTP");
         accFunc=new ActiveXObject("Msxml2.XMLHTTP");
         metaFunc=new ActiveXObject("Msxml2.XMLHTTP");
         chgPFunc=new ActiveXObject("Msxml2.XMLHTTP");
         mapFunc=new ActiveXObject("Msxml2.XMLHTTP");
         queryFunc=new ActiveXObject("Msxml2.XMLHTTP");
         execQueryFunc==new ActiveXObject("Msxml2.XMLHTTP");
         DownLoadFunc=new ActiveXObject("Msxml2.XMLHTTP");
         DownLoadpro=new ActiveXObject("Msxml2.XMLHTTP");
         otherFunc==new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
         try
         {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            cropFunc=new ActiveXObject("Microsoft.XMLHTTP");
            searchFunc=new ActiveXObject("Microsoft.XMLHTTP");
            accFunc=new ActiveXObject("Microsoft.XMLHTTP");
            metaFunc=new ActiveXObject("Microsoft.XMLHTTP");
            chgPFunc=new ActiveXObject("Microsoft.XMLHTTP");
            mapFunc=new ActiveXObject("Microsoft.XMLHTTP");
            queryFunc=new ActiveXObject("Microsoft.XMLHTTP");
            execQueryFunc==new ActiveXObject("Microsoft.XMLHTTP");
            DownLoadFunc=new ActiveXObject("Microsoft.XMLHTTP");
            DownLoadpro=new ActiveXObject("Microsoft.XMLHTTP");
            otherFunc==new ActiveXObject("Microsoft.XMLHTTP");
         }
         catch (e)
         {
            alert("Your browser does not support AJAX!");
            return false;
         }
      }
   }

    DownLoadpro.onreadystatechange=function(){
		if(DownLoadpro.readyState==4){
			if (document.getElementById("progress")) {
					document.getElementById("progress").innerHTML=DownLoadpro.responseText;
			} else {
				t=setTimeout("ProgressTxt();",500);
			}
		}
	}


   	metaFunc.onreadystatechange=function(){
		if(metaFunc.readyState==4){
			x=document.getElementById("meta");
			x.innerHTML=metaFunc.responseText;
			x.style.visibility="visible";

		}
	}

  	searchFunc.onreadystatechange=function(){
		if(searchFunc.readyState==4){
			x=document.getElementById("searchResult");
			x.innerHTML=searchFunc.responseText;
		}
	}

   /* ie has many problems to recall this ajax function */
	/*xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
         alert('xmlHttp.onreadystatechange');
         changeBodyPage(xmlHttp)
			x=document.getElementById("canvas");
			z=document.getElementById("Container");
			x.innerHTML=xmlHttp.responseText;
			document.body.style.cursor="default";
			x.style.cursor="default";
			z.style.cursor="default";
			if (Spage==6)
         {
				DM=document.getElementById("DMap").name;
				srt=DM.indexOf("?");
				DM=DM.substr(srt+1);
				coor=DM.split("&");
				val=coor[1].split("=");
				Xmin=parseFloat(val[1]);
				val=coor[2].split("=");
				Ymin=parseFloat(val[1]);
				val=coor[3].split("=");
				Xmax=parseFloat(val[1]);
				val=coor[4].split("=");
				Ymax=parseFloat(val[1]);
				val=coor[5].split("=");
				Stage=parseFloat(val[1]);
				val=coor[6].split("=");
				Wmax=parseFloat(val[1]);
				val=coor[7].split("=");
				Hmax=parseFloat(val[1]);
            if ((Xmax-Xmin)==0 || (Ymax-Ymin)==0) {
               Xmin=Xmin-0.5;
               Xmax=Xmax+0.5;
               Ymin=Ymin-0.25;
               Ymax=Ymax+0.25;
            }
				XFactor=(Xmax-Xmin)/Wmax;
				YFactor=(Ymax-Ymin)/Hmax;
				MM=document.getElementById("DMap");
            var d = new Date();
            MapImage= new Image(Wmax,Hmax);
            MapImage.src="Map.php?XXSmin="+Xmin+"&YYSmin="+Ymin+"&XXSmax="+Xmax+"&YYSmax="+Ymax+"&Stage="+Stage+"&WSmax="+Wmax+"&HSmax="+Hmax+"&d="+d.getTime();
            MM.src=MapImage.src;
            t=setTimeout("doAnimate(\"canvas\");",100);
			}
         else
         {
				if (Spage==1)
            {
					if (CropId !=999) {
						CR=document.getElementById("cropImage");
						CR.style.backgroundPosition=((CropId)*-480)+"px 0px";
					} else {
						CR=document.getElementById("cropImage");
						CR.style.backgroundPosition="0px 0px";
						imageSlider=0.00;
						t=setTimeout("flick(0);",5000);
					}
				}
				doResize();
				if (Spage==3)
            {
					var Count = document.getInnerText("AccNum").replace("Number of accessions in the result set: ","");
					CropCurSelction=Count;
						if (CropTotalCount==CropCurSelction) {
							document.getElementById("myResultCell").innerHTML="<span style=\"cursor:pointer;\" onClick=\"ViewResultSet()\" id=\"myresult\">My results ("+CropCurSelction+")</span>";
						} else {
							document.getElementById("myResultCell").innerHTML="<span style=\"cursor:pointer;\" onClick=\"ViewResultSet()\" id=\"myresult\">My results ("+CropCurSelction+")</span><br><span style=\"float:right; font-size:7pt; margin-right:5px; position:relative; top:5px; text-decoration:underline; cursor:pointer;\" onClick=\"RemoveFilter3(-1)\"><img src='./images/reset1.png' border='0'/></span>";
						}
					ApplySelection();
				}
				t=setTimeout("doAnimate(\"canvas\");",100);
			}
			//doAnimate("canvas");
		}
	}*/

   document.getInnerText = function(elemId)
   {
	   var theElem = document.getElementById(elemId);
	   if(theElem==null)
		   return "";
	   else if (navigator.appName == "Microsoft Internet Explorer")
			return theElem.innerText;
	   else
	      return theElem.textContent;
   }



	if (Crop !=0)
	{
		ChgActCrop(Crop);
		if (Acc !=0) ShowAcc(Acc);
		t = setTimeout("Home(false);",50);
	}
   else t = setTimeout("Home(false);",50);
}

/* Functions to recall after ajax request... */

function mapFunction()
{
	var x = document.getElementById("MapCWE");
	OverResult = 0;
	if (mapFunc.responseText!="")
	{
		x.innerHTML=mapFunc.responseText;
		mm = mapFunc.responseText.split('</tr>');
		x.style.top=(parseInt(x.style.top)-((mm.length-1)*7))+"px";
		if (parseInt(x.style.top)<10)
			x.style.top="10px";

		x.style.visibility="visible";
		DMapCL=document.getElementById("DMap");
		DMapCL.setAttribute("onmousedown",null);
		DMapCL.setAttribute("onmouseup",null);
	}
	else
	{
		MoveResult=1;
		OverResult=0;
	}
}

function otherFunctions(otherFuncObj)
{  
   switch (otherCode)
   {
      case 1:
         document.getElementById("Mapresult").innerHTML=otherFuncObj.responseText;
         if (XFactor<0.012) {
            otherCode=2;
            var d = new Date();
            otherFunc.open("GET","MapSpecies.php?crop="+Crop+"&n="+d.getMilliseconds(),true);
            otherFunc.onreadystatechange=function() {
               if(otherFunc.readyState==4){
                  otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
               }
            };
            otherFunc.send(null);
         }
      break;

      case 2:
         document.getElementById("MSContent").innerHTML=otherFuncObj.responseText;
      break;

      case 3:
         z=document.getElementById("HistoryCan");
         w=document.getElementById("HistoryContent");
         doResize();
         w.innerHTML=otherFuncObj.responseText;
         z.style.visibility="visible";
         w.style.visibility="visible";

	      var accNum2Elem = document.getElementById("AccNum2"); // BUGFIX DB  
	      var Count       = accNum2Elem? document.getElementById("AccNum2").innerText.replace("Number of accessions in the result set: ","") : '0'; // BUGFIX DB  
         CropCurSelction = Count;
         if (CropTotalCount==CropCurSelction)
				document.getElementById("myResultCell").innerHTML="<span style=\"cursor:pointer;\" onClick=\"ViewResultSet()\" id=\"myresult\">My results ("+CropCurSelction+")</span>";
         else
				document.getElementById("myResultCell").innerHTML="<span style=\"cursor:pointer;\" onClick=\"ViewResultSet()\" id=\"myresult\">My results ("+props[3]+")</span><br><span style=\"float:right; font-size:7pt; margin-right:5px; position:relative; top:5px; text-decoration:underline; cursor:pointer;\" onClick=\"RemoveFilter3(-1)\"><img src='./images/reset1.png' border='0'/></span>";
      break;

      case 4:
         //document.getElementById("AccContentCanvas").innerHTML="<div id=\"CEDisplay\" class=\"CEDContent\">"+otherFuncObj.responseText+"</div>";
		   document.getElementById("AccContentCanvas").innerHTML = otherFuncObj.responseText;
      break;

      case 5:
         x=document.getElementById("QueryContentSubHeader");
         x.innerHTML=otherFuncObj.responseText;
      break;

      case 6:
         refreshAcvPage();
         otherCode=3;
         D = new Date();
            if (otherFunc != null){
               otherFunc.open("GET","History.php?now="+D.getMilliseconds(),true);
               otherFunc.onreadystatechange=function() {
                  if(otherFunc.readyState==4){
                     otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
                  }
               };
               otherFunc.send(null);
            }
      break;

      case 7:
         if (navigator.appName == "Microsoft Internet Explorer")
         {
            Pwidth=document.body.clientWidth+26;
            Pheight=document.body.clientHeight;
         }
         else
         {
            Pwidth=document.documentElement.scrollWidth+17;
            Pheight=document.documentElement.scrollHeight;
         }
         var text  = otherFuncObj.responseText;
         var items = Array(2);
             items = text.split("~@", 2);
         document.getElementById("NewsTitle").innerHTML = items[0];
         document.getElementById("NewText").innerHTML   = "<br />"+items[1];
         var x = document.getElementById("newsViewer");
         x.style.top="348px";
		   if (navigator.appName == "Microsoft Internet Explorer")
            x.style.left=(Pwidth-450-168+13)+"px";
		   else
            x.style.left=(Pwidth-450-168)+"px";		   

         x.style.visibility="visible";
      break;

      case 8:
         z=document.getElementById("HistoryCan");
         w=document.getElementById("MyResultSet");
         w.innerHTML=otherFuncObj.responseText;
         z.style.visibility="visible";
         w.style.visibility="visible";
         var Count=document.getElementById("AccNum2").innerText.replace("Number of accessions in the result set: ","");
         CropCurSelction=Count;

         if (CropTotalCount==CropCurSelction){
            document.getElementById("myResultCell").innerHTML="<span style=\"cursor:pointer;\" onClick=\"ViewResultSet()\" id=\"myresult\">My results ("+CropCurSelction+")</span>";
         } else {
            document.getElementById("myResultCell").innerHTML="<span style=\"cursor:pointer;\" onClick=\"ViewResultSet()\" id=\"myresult\">My results ("+CropCurSelction+")</span><br><span style=\"float:right; font-size:7pt; margin-right:5px; position:relative; top:5px; text-decoration:underline; cursor:pointer;\" onClick=\"RemoveFilter3(-1)\"><img src='./images/reset1.png' border='0'/></span>";
         }
      break;

      case 9:
         refreshAcvPage();
         otherCode=8;
         D = new Date();
         if (otherFunc != null)
         {
            otherFunc.open("GET","MyResultSet.php?now="+D.getMilliseconds(),true);
            otherFunc.onreadystatechange=function() {
               if(otherFunc.readyState==4){
                  otherFunctions(otherFunc);  // WORKAROUND FOR IE7...
               }
            };            
            otherFunc.send(null);
         }
      break;

      case 10:
         /* x=document.getElementById("CropText");
         x.innerHTML=otherFunc.responseText; */
      break;

      case 11:
      case 14:
         x=document.getElementById("DownloadData");
         x.innerHTML=otherFuncObj.responseText;
         x.style.visibility="visible";
         if (DownLoadProgress==-3)
         {
            DownLoadProgress=-2;
	         if (DownLoadFunc != null)
				{
					DownLoadFunc.open("GET","DownLoadCatPage.php?Cat="+DownLoadProgress,true);
					DownLoadFunc.onreadystatechange=function(){
						if(DownLoadFunc.readyState==4) {
							downloadFunc();   // WORKAROUND FOR IE7...
						}
					}
					DownLoadFunc.send(null);
				}
         }
      break;

      case 12:
         CropCurSelction=CropTotalCount;
         document.getElementById("myResultCell").innerHTML="<span style=\"cursor:pointer;\" onClick=\"ViewResultSet()\" id=\"myresult\">My results ("+CropCurSelction+")</span>";
         refreshAcvPage();
      break;

      case 13:
         x=document.getElementById("DataContentSubHeader");
         x.innerHTML=otherFuncObj.responseText;
         break;
         case 16:
         x=document.getElementById("MySelection");
         x.innerHTML=otherFuncObj.responseText;
         x.style.visibility="visible";
      break;

      case 17:
//		        alert(otherFuncObj.responseText);
         if (otherFuncObj.responseText=="OK")
         {
            otherCode=16;
            txt=document.getElementById("comment").value;
            if (document.getElementById("smtaType1").checked==true){
               typ=1;
            } else {
               typ=0;
            }

            txt=txt.replace(new RegExp( "\\n", "g" ),"<br>");
            D = new Date();
            if (otherFunc != null){
               otherFunc.open("GET","MySelection.php?step=4&comment="+txt+"&type="+typ+"&now="+D.getMilliseconds(),true);
               otherFunc.onreadystatechange=function() {
                  if(otherFunc.readyState==4){
                     otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
                  }
               };
               otherFunc.send(null);
            }
         }
         else
         {
            document.getElementById("error").innerHTML="<span style=\"color:#F00; font-size:8pt;\">Invalid username or password</span>"
            //alert(otherFuncObj.responseText);
         }
      break;
   }
}

/* =========================================================================== */

function changeBodyPage(xmlHttpObj)
{
   x=document.getElementById("canvas");
   z=document.getElementById("Container");
   x.innerHTML=xmlHttpObj.responseText;
   document.body.style.cursor="default";
   x.style.cursor="default";
   z.style.cursor="default";
   if (Spage==6)
   {
      DM    = document.getElementById("DMap").name;
      srt   = DM.indexOf("?");
      DM    = DM.substr(srt+1);
      coor  = DM.split("&");
      val   = coor[1].split("=");
      Xmin  = parseFloat(val[1]);
      val   = coor[2].split("=");
      Ymin  = parseFloat(val[1]);
      val   = coor[3].split("=");
      Xmax  = parseFloat(val[1]);
      val   = coor[4].split("=");
      Ymax  = parseFloat(val[1]);
      val   = coor[5].split("=");
      Stage = parseFloat(val[1]);
      val   = coor[6].split("=");
      Wmax  = parseFloat(val[1]);
      val   = coor[7].split("=");
      Hmax  = parseFloat(val[1]);
      if ((Xmax-Xmin)==0 || (Ymax-Ymin)==0)
      {
         Xmin=Xmin-0.5;
         Xmax=Xmax+0.5;
         Ymin=Ymin-0.25;
         Ymax=Ymax+0.25;
      }
      XFactor = (Xmax-Xmin)/Wmax;
      YFactor = (Ymax-Ymin)/Hmax;
      MM = document.getElementById("DMap");
      var d = new Date();
      MapImage= new Image(Wmax,Hmax);
      MapImage.src="Map.php?XXSmin="+Xmin+"&YYSmin="+Ymin+"&XXSmax="+Xmax+"&YYSmax="+Ymax+"&Stage="+Stage+"&WSmax="+Wmax+"&HSmax="+Hmax+"&d="+d.getTime();
      MM.src=MapImage.src;
      t=setTimeout("doAnimate(\"canvas\");",100);
   }
   else
   {
      if (Spage==1)
      {
         if (CropId !=999) {
            CR=document.getElementById("cropImage");
            CR.style.backgroundPosition=((CropId)*-480)+"px 0px";
         } else {
            CR=document.getElementById("cropImage");
            CR.style.backgroundPosition="0px 0px";
            imageSlider=0.00;
            t=setTimeout("flick(0);",5000);
         }
      }
      doResize();
      if (Spage==3)
      {
	      if(document.getInnerText("AccNum") != "") // IE FIX
	      {
				var Count = document.getInnerText("AccNum").replace("Number of accessions in the result set: ","");
				CropCurSelction=Count;
				if (CropTotalCount==CropCurSelction)
					document.getElementById("myResultCell").innerHTML="<span style=\"cursor:pointer;\" onClick=\"ViewResultSet()\" id=\"myresult\">My results ("+CropCurSelction+")</span>";
				else
					document.getElementById("myResultCell").innerHTML="<span style=\"cursor:pointer;\" onClick=\"ViewResultSet()\" id=\"myresult\">My results ("+CropCurSelction+")</span><br><span style=\"float:right; font-size:7pt; margin-right:5px; position:relative; top:5px; text-decoration:underline; cursor:pointer;\" onClick=\"RemoveFilter3(-1)\"><img src='./images/reset1.png' border='0'/></span>";
	      }
         ApplySelection(); // it retrieves and applies last user selection
      }
      var t=setTimeout("doAnimate(\"canvas\");",100);
   }
}

function queryFunction()
{
	switch (QueryProgress){
		case -2:
//				x=document.getElementById("QueryContentSubHeader");
//				x.innerHTML=queryFunc.responseText;
		QueryProgress++;
		queryFunc.open("GET","CatPage.php?Cat="+QueryProgress,true);
		queryFunc.onreadystatechange = function() {
			if(queryFunc.readyState==4) {
				queryFunction();
			}
		}		  
		queryFunc.send(null);

		break;
		case -1:
		case 0:
			if (document.getElementById("QueryContent").style.visibility !="hidden"){
				var newdiv = document.createElement('div');
				//newdiv.setAttribute('id',"Cat_P_"+QueryProgress);

				newdiv.id = "Cat_P_"+QueryProgress;

//						newdiv.setAttribute('style',"top:65px; left:5px; width:100%;  visibility:hidden");
				//newdiv.setAttribute('class',"PanelContainer");
				newdiv.className = "PanelContainer";

				document.getElementById("QueryContentCanvas").appendChild(newdiv);
				var ch=document.getElementById("Cat_P_"+QueryProgress);
				ch.innerHTML=queryFunc.responseText;
/*						cur=document.getElementById("Cat_"+QueryProgress);

						if (QueryProgress==-1) {
							cur.setAttribute('class','SmenueSelItem');
						} else {
							cur.setAttribute('class','SmenueBGO');
						}*/


				QueryProgress++;
				queryFunc.open("GET","CatPage.php?Cat="+QueryProgress,true);
				queryFunc.onreadystatechange = function() {
					if(queryFunc.readyState==4) {
						queryFunction();
					}
				}
				queryFunc.send(null);
			}
		break;
		default:
/*				if (Cats.length==0){
						if (document.getElementById("QueryContent").style.visibility !="hidden"){
							document.getElementById("control").style.visibility="visible";
						}
				}*/
		var found=false;
		for (i=0; i<Cats.length; i++){
			if(Cats[i]==QueryProgress){
				found = true;
				break;
			}

		}
		if (found) {
			if (document.getElementById("QueryContent").style.visibility !="hidden"){
				var newdiv = document.createElement('div');
				// newdiv.setAttribute('id',"Cat_P_"+QueryProgress);
				newdiv.id = "Cat_P_"+QueryProgress;

//						newdiv.setAttribute('style',"position: absolute; top:65px; left:5px; width:100%;  visibility:hidden");
				//newdiv.setAttribute('class',"PanelContainer");
				newdiv.className = "PanelContainer";
				document.getElementById("QueryContentCanvas").appendChild(newdiv);
				var ch=document.getElementById("Cat_P_"+QueryProgress);
				ch.innerHTML=queryFunc.responseText;
				if (cur=document.getElementById("Cat_"+QueryProgress))
				{
					// cur.setAttribute('class','SmenueBGO');
					cur.className = 'SmenueBGO';
					cur.setAttribute('onMouseOver',"this.className='SmenueHover'");
					cur.setAttribute('onMouseOut',"this.className='SmenueBGO'");
					cur.setAttribute('onClick',"ShowCatQuery(this.id)");
				}
			}
		}
			QueryProgress++;
			if (QueryProgress<15) {
				queryFunc.open("GET","CatPage.php?Cat="+QueryProgress,true);
				queryFunc.onreadystatechange = function() {
					if(queryFunc.readyState==4) {
						queryFunction();
					}
				}
				queryFunc.send(null);
			} else {
				if (document.getElementById("QueryContent").style.visibility !="hidden"){
				//	document.getElementById("control").style.visibility="visible";
					otherCode=5;
					if (otherFunc != null){
						otherFunc.open("GET","QueryCats.php",true);
                  otherFunc.onreadystatechange=function() {
                     if(otherFunc.readyState==4){
                        otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
                     }
                  };
						otherFunc.send(null);
					}
				WW=document.getElementById("Ajxwiat");
				WW.style.visibility="hidden";
				//document.getElementById("Cat_P_-1").setAttribute('class',"PanelContainer");
				document.getElementById("Cat_P_-1").style.visibility="visible";
				}
			}
		break;
	}
}

function downloadFunc()
{
	switch (DownLoadProgress)
	{
		case -2:
//				x=document.getElementById("QueryContentSubHeader");
//				x.innerHTML=queryFunc.responseText;
			DownLoadProgress++; // from -2 to -1 (to call passList.php)
			DownLoadFunc.open("GET","DownLoadCatPage.php?Cat="+DownLoadProgress,false); // call passList.php...
			DownLoadFunc.onreadystatechange=function() {
				if(DownLoadFunc.readyState==4) {
					downloadFunc();   // WORKAROUND FOR IE7...
				}
			}
			DownLoadFunc.send(null);
		break;

		case -1:
		case 0:
			if (document.getElementById("DownloadData").style.visibility != "hidden")
			{
				var newdiv = document.createElement('div');
				newdiv.id = "Cat_P_"+DownLoadProgress;
				newdiv.className = "PanelContainer2";
				document.getElementById("DownLoadContentCanvas").appendChild(newdiv);
				var ch = document.getElementById("Cat_P_"+DownLoadProgress);
				ch.innerHTML=DownLoadFunc.responseText;
/*						cur=document.getElementById("Cat_"+QueryProgress);

				if (QueryProgress==-1) {
					cur.setAttribute('class','SmenueSelItem');
				} else {
					cur.setAttribute('class','SmenueBGO');
				}*/


				DownLoadProgress++;
				DownLoadFunc.open("GET","DownLoadCatPage.php?Cat="+DownLoadProgress,false);
				DownLoadFunc.onreadystatechange=function(){
					if(DownLoadFunc.readyState==4) {
						downloadFunc();   // WORKAROUND FOR IE7...
					}
				}
				DownLoadFunc.send(null);
			}
		break;

		default:
			var found=false;
			for (i=0; i<Cats.length; i++)
			{
				if(Cats[i]==DownLoadProgress)
				{
					found = true;
					break;
				}
			}

			if (found && document.getElementById("DownloadData").style.visibility !="hidden")
			{
				var newdiv = document.createElement('div');
				newdiv.id = "Cat_P_"+DownLoadProgress;
				newdiv.className = "PanelContainer2";

				document.getElementById("DownLoadContentCanvas").appendChild(newdiv);
				ch = document.getElementById("Cat_P_"+DownLoadProgress);
				ch.innerHTML=DownLoadFunc.responseText;
				if (cur = document.getElementById("Cat_"+DownLoadProgress))
				{
					cur.className   = 'SmenueBGO';
					cur.onmouseover = "this.className='SmenueHover'";
					cur.onmouseout  = "this.className='SmenueBGO'";
					cur.onclick     = "ShowCatQuery(this.id)";
				}
			}
				  
			DownLoadProgress++;
			if (DownLoadProgress<15)
			{
				DownLoadFunc.open("GET","DownLoadCatPage.php?Cat="+DownLoadProgress,true);
				DownLoadFunc.onreadystatechange=function() {
					if(DownLoadFunc.readyState==4) {
						downloadFunc();   // WORKAROUND FOR IE7...
					}
				}
				DownLoadFunc.send(null);
			}
			else
			{
				if (document.getElementById("DownloadData").style.visibility !="hidden")
				{
					otherCode=13;
					if (otherFunc != null) {
						otherFunc.open("GET","QueryCats.php",true);
						otherFunc.onreadystatechange=function() {
							if(otherFunc.readyState==4){
								otherFunctions(otherFunc)  // WORKAROUND FOR IE7...
							}
						};
						otherFunc.send(null);
					}
					
					var WW=document.getElementById("Ajxwiat");
					WW.style.visibility="hidden";
					document.getElementById("Cat_P_-1").style.visibility="visible";
				}
			}
		break;
	}
}

