tabHeight=18;
topval=13;
leftval=260;
menunumber=208;
graytable='<TABLE cellspacing=1 cellpadding=1 border=0 bgcolor=#719AE3><tr><td valign=center align=center width=100%><TABLE cellpadding=1 cellspacing=0 id=submen';
sub_one=' onmouseout="detailLyr[12].visibility=\'hidden\';return true;"';
c_changer2='<td onmouseout=\'bgrChange(this);return true;\' onmouseover="bgrChange(this,1);';
c_changer1=c_changer2+'return true;" ';
speciestext=new Array();
speciesarray=new Array('A','B','C','E','F','G','I','J','K','L','M','O','P','R','S','T');
specnumber=16;
countrytext=new Array();

function notabene(val) {
	if (!mapstatus) {
		val>40?detailLyr[12].left=(mouse_x)-185:detailLyr[12].left=(mouse_x)-25;
		detailLyr[12].top=(mouse_y)-5;
		maintext='<table id="tricky1" cellspacing=0 cellpadding=6 bgcolor=oldlace border=1><tr><td>'+menunote[val]+tableend;
		magiccontents(detailHTML[12]);
		detailLyr[12].visibility='visible';
	}
}

function switchdetails() {
	if (zoomstatus) {close_zoom();}
	else
	{zoomstatus=true;simplefetch1(format,null,2);}
}

function simplefetch1(val,btn,swtch) {
	if (!swtch) {sorter(val);}
	if (val>5) {
		if (btn||(!btn&&!zoomstatus&&val!=8)) {extras=val;} 	//if selected independent of zoom status, 
											//or if sorted and no zoom status
	}
	if (swtch==1) { // full list - DEFAULT search for anything in column 1
		zoomstatus=true;
		if (!btn) {
			searchval='';
		}
	}
	newsearch(searchval); // starts chain to show results 
}

function individual_species() {
	for (var i=1;i<=specnumber;i++) {speciestext[i]='';}
	for (var i=0;i<40;i++) {
		var checkit2=carrier[i][1];
		for (var ii=1;ii<=specnumber;ii++) {	
			var checkletter=speciesarray[ii-1];
			if (checkit2.indexOf(checkletter)==0) {
				speciestext[ii]+='<TR>'+c_changer2+' by_number('+i+');return true;" onclick="hide_menu();simplefetch1(format,null,1);by_number('+i+');return false;">'+checkit2+'</TD></TR>';
			}
		}
	}
	for (var i=1;i<=specnumber;i++) {	
		maintext+='<div id="menu'+(i+9)+'" style="position: absolute;top:'+((topval+2)+(i*tabHeight))+'px; left: '+(leftval+119)+'px; width:200; visibility:hidden;">'+graytable+'left>'+speciestext[i]+'</TABLE>'+tableend+'</div>';
	}
}

//cats for individual countries
function cats_for_countries() {
	for (var i=1;i<158;i++) {countrytext[i]='';}
	for (var anum=1;anum<158;anum++) {
		for (var bnum=1;bnum<countryarray[anum].length;bnum++) {
			for (var cnum=0;cnum<40;cnum++) {
				if (carrier[cnum][20]==countryarray[anum][bnum]) {
					countrytext[anum]+='<TR>'+c_changer2+' by_number('+cnum+');return true;" onclick="hide_menu();simplefetch1(format,null,1);by_number('+cnum+');return false;">'+carrier[cnum][1]+'</TD></TR>';
				}
			}
		}
	}
	for (var i=1;i<158;i++) {	
		maintext+='<div id="menu'+(i+51)+'" style="position: absolute;top:0px; left: '+(leftval+265)+'px; width:200; visibility:hidden;">'+graytable+'left width=133>'+countrytext[i]+'</TABLE>'+tableend+'</div>';
	}
}

function formsetup() {
	maintext='<form id="searchform"><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD width=290 align=right valign=top><table id=distribn3 cellpadding=0 cellspacing=0 border=0><tr><td align=right valign=center><br><sup>SEARCH:&nbsp;<input TYPE = "text"  size=13 id = "boxone" CLASS="mediumbox" onfocus="this.select();">&nbsp;</sup><a href=# onmouseover="notabene(32);return true;" '+sub_one+' onclick="subform();return false;"><img src='+gobutton.src+' border=0 alt=""></a></td><td width=50><div STYLE="position:absolute; z-index: -150; left:-1195px; top:-115px; visibility:hidden;"><input TYPE = "text"  size=1 name = "boxtwo"></div>'+tableend+tableend+'</form>';

//main menu
	maintext+='<div id="menu0" style="position:absolute; top:'+(topval)+'px; left:250px;width:346;">'+graytable+'top><TR>'+c_changer2+'notabene(33);hide_menu();extraLyr.visibility=\'hidden\';return true;" onclick="extras=0;close_zoom();format=1;newsearch(\'\',1);return false;">home</td>'+c_changer2+' menucontrol(2);return true;">select</td>'+c_changer2+' menucontrol(4);return true;">species</TD>'+c_changer2+' menucontrol(3);return true;">show / list</TD>'+c_changer2+' menucontrol(1);return true;">sort</TD>'+c_changer2+'notabene(42);hide_menu();return true;" onclick="extraLyr.visibility=\'visible\';return false;">extras'+tableend+tableend+'</div>';

//select
	maintext+='<div id="menu2" style="position: absolute;top:'+(topval+20)+'px; left: '+(leftval+42)+'px; width:200; visibility:hidden;">'+graytable+'><TR>'+c_changer2+' notabene(48);menucontrol(26);return true;">country</TD></TR><TR>'+c_changer2+' notabene(46);menucontrol(5);return true;">subfamily</TD></TR><TR>'+c_changer2+' notabene(47);menucontrol(6);return true;">genera</TD></TR><TR>'+c_changer2+' notabene(43);menucontrol(7);return true;">CITES</TD></TR><TR>'+c_changer2+' notabene(44);menucontrol(8);return true;">IUCN</TD></TR><TR>'+c_changer2+' notabene(45);menucontrol(9);return true;">USFWS'+tableend+tableend+'</div>';

//species letter list
	maintext+='<div id="menu4" style="position: absolute;top:'+(topval+20)+'px; left: '+(leftval+94)+'px; width:50; visibility:hidden;">'+graytable+'>';
	for (i=1;i<=specnumber;i++) {
		maintext+='<TR>'+c_changer2+' menucontrol('+(i+9)+');return true;">'+speciesarray[i-1]+'</TD></TR>';
	}
	maintext+='</table>'+tableend+'</div>';

//list / show
	maintext+='<div id="menu3" style="position: absolute;top:'+(topval+20)+'px; left: '+(leftval+158)+'px; width:200; visibility:hidden;">'+graytable+'><TR>'+c_changer1+' onclick="simpleswap(1);return false;">show common names</TD></TR><TR>'+c_changer1+' onclick="simpleswap(2);return false;">show scientific names</a></TD></TR><TR>'+c_changer2+' notabene(34);return true;" onclick="simplefetch1(format,null,1);return false;">full list</TD></TR><TR>'+c_changer1+' onclick="simplefetch1(7,4,1);return false;">list average lengths</TD></TR><TR>'+c_changer1+' onclick="simplefetch1(6,4,1);return false;">list average weights</TD></TR><TR>'+c_changer2+'notabene(39);return true" onclick="simplefetch1(9,4,1);return false;">list classifiers</TD></TR><TR>'+c_changer1+' onclick="simplefetch1(14,4,1);return false;">list populations</TD></TR><TR>'+c_changer2+'notabene(21);return true;" onclick="simplefetch1(11,4,1);return false;">threatened status'+tableend+tableend+'</div>';

//sort
	maintext+='<div id="menu1" STYLE="position: absolute;top:'+(topval+20)+'px; left: '+(leftval+233)+'px; width:200;visibility:hidden;">'+graytable+'><TR>'+c_changer2+' notabene(22);return true;" onclick="simplefetch1(format,1);return false;">alpha</TD></TR><TR>'+c_changer2+' notabene(35); return true;" onclick="simplefetch1(8,null);return false;">subfamily</TD></TR><TR>'+c_changer2+'notabene(20);return true;" onclick="format=2;simplefetch1(2);return false;">genera</TD></TR><TR>'+c_changer2+'notabene(7);return true" onclick="simplefetch1(7);return false;">length</TD></TR><TR>'+c_changer2+' notabene(6);return true" onclick="simplefetch1(6);return false;">weight</TD></TR><TR>'+c_changer2+' notabene(14);return true" onclick="simplefetch1(14);return false;">population</TD></TR><TR>'+c_changer2+' notabene(25);return true" onclick="simplefetch1(11);return false;">threatened status'+tableend+tableend+'</div>';

//country letter list - nb no countries begin with an 'X'
	countryletter = new Array();
	for (i=1;i<24;i++) {
		countryletter[i]=String.fromCharCode(i+64);
	}
	countryletter[24]='Y';
	countryletter[25]='Z';
	maintext+='<div id="menu26" style="position: absolute;top:'+(topval+20)+'px; left: '+(leftval+104)+'px; width:50; visibility:hidden;">'+graytable+'>';

	for (i=1;i<=25;i++) {
		maintext+='<TR>'+c_changer2+' menucontrol('+(i+26)+');return true;">'+countryletter[i]+'</TD></TR>';
	}
	maintext+='</table>'+tableend+'</div>';

//individual countries
	for (var i=1;i<=25;i++) {countrytext[i]='';}
	for (var i=1;i<158;i++) {
		var checkit2=countryarray[i][0];
		for (var ii=1;ii<=25;ii++) {	
			var checkletter=countryletter[ii];
			if (checkit2.indexOf(checkletter)==0) {
				countrytext[ii]+='<TR>'+c_changer2+' menucontrol('+(i+51)+');return true;">'+checkit2+'</TD></TR>';
			}
		}
	}
	for (var i=1;i<=25;i++) {	
		maintext+='<div id="menu'+(i+26)+'" style="position: absolute;top:'+((topval+3)+(i*tabHeight))+'px; left: '+(leftval+131)+'px; width:300; visibility:hidden;">'+graytable+'left width=216>'+countrytext[i]+'</TABLE>'+tableend+'</div>';
	}

	individual_species();
	cats_for_countries();

//subfamily
	maintext+='<div id="menu5" style="position: absolute;top:'+(topval+20)+'px; left:'+(leftval+104)+'px; width:200; visibility:hidden;">'+graytable+'left><TR>'+c_changer1+' onclick="newsearch(\'a\',8);return false;">Acinonychinae</TD></tr><TR>'+c_changer1+' onclick="newsearch(\'f\',8);return false;">Felinae</TD></TR><TR>'+c_changer1+' onclick="newsearch(\'p\',8);return false;">Pantherinae'+tableend+tableend+'</div>';

//genera
	maintext+='<div id="menu6" style="position: absolute;top:'+(topval+39)+'px; left:'+(leftval+104)+'px; width:200; visibility:hidden;">'+graytable+'left>'+process_table('Acinonyx')+process_table('Caracal')+process_table('Catopuma')+'<TR>'+c_changer1+' onclick="newsearch(\'<!fel\',1); return false;">Felis</TD></TR>'+process_table('Herpailurus')+process_table('Leopardus')+process_table('Leptailurus')+process_table('Lynx')+process_table('Mayailurus')+process_table('Neofelis')+process_table('Oncifelis')+process_table('Oreailurus')+process_table('Otocolobus')+process_table('Panthera')+process_table('Pardofelis')+process_table('Prionailurus')+process_table('Puma')+process_table('Uncia')+'</table>'+tableend+'</div>';

//cites
	maintext+='<div id="menu7" style="position: absolute;top:'+(topval+67)+'px; left:'+(leftval+104)+'px; width:200; visibility:hidden;">'+graytable+'left><TR>'+c_changer1+' onclick="newsearch(\'!I12\',12);return false;">Appendix I</TD></tr><TR>'+c_changer1+' onclick="newsearch(\'!II12\',12);return false;">Appendix II'+tableend+tableend+'</div>';

//iucn
	maintext+='<div id="menu8" style="position: absolute;top:'+(topval+49)+'px; left:'+(leftval+104)+'px; width:200; visibility:hidden;">'+graytable+'left><TR>'+c_changer1+' onclick="newsearch(\'!EX11\',11);return false;">EX - Extinct</TD></TR><TR>'+c_changer1+' onclick="newsearch(\'!CR11\',11);return false;">CR - Critically Endangered</TD></tr><TR>'+c_changer1+' onclick="newsearch(\'!EN11\',11);return false;">EN - Endangered</TD></TR>'+c_changer1+' onclick="newsearch(\'!NT11\',11);return false;">NT - Near Threatened</TD></tr><TR>'+c_changer1+' onclick="newsearch(\'!VU11\',11);return false;">VU - Vulnerable</TD></TR>'+c_changer1+' onclick="newsearch(\'!LC11\',11);return false;">LC - Least Concern'+tableend+tableend+'</div>';

//usfws
	maintext+='<div id="menu9" style="position: absolute;top:'+(topval+94)+'px; left:'+(leftval+104)+'px; width:200; visibility:hidden;">'+graytable+'left><TR>'+c_changer1+' onclick="newsearch(\'!EN13\',13);return false;">EN - Endangered</TD></tr><TR>'+c_changer1+' onclick="newsearch(\'!T13\',13);return false;">T - Threatened</TD></TR><TR>'+c_changer1+' onclick="newsearch(\'unlisted\',13);return false;">UN - Unlisted'+tableend+tableend+'</div>';

	var extratext=eval('extraHTML.innerHTML');
	extratext='<br><br><table cellspacing=0 cellpadding=5 width=' +(available_width) + ' height=' +(available_height) + ' bgcolor=#719AE3 border=1><tr><td valign=top ><table cellspacing=0 cellpadding=0 width=' +(available_width-8) + ' height=' +(available_height-10) + '><tr><td valign=top ><font color=white>'+extratext+'</td></tr><tr><td valign=bottom align=right><table cellspacing=0 cellpadding=2 bgcolor=black id=extramenu><tr><td><a href=# onclick="extraLyr.visibility=\'hidden\';return false;"><font size=-3>back to the main screen »</font></a>'+tableend+tableend+tableend;

	maintext+='<div id="extra" style="position: absolute; width:'+(available_width*0.98)+'; visibility:hidden;">'+extratext+'</div>';
	magiccontents(detailHTML[10]);

	maintext='<div style="position:absolute;z-index:999;top:0px;left:0px;"><a href=http://donovan.au.com/testing/random.php?linker=portfolio target=blank onmouseout="detailLyr[12].visibility=\'hidden\';window.status=\'\';return true;" onmouseover="notabene(49);window.status=&quot;digsby wyscher&#39;s portfolio&quot;;return true;"><img src='+blankimg.src+' border=0 width=80 height=71 ></a></div><table cellpadding=0 cellspacing=0 width=80 height=71><tr><td id=ping3 background='+chiselimg.src+' border=0 >'+tableend;
	magiccontents(detailHTML[15]);
	if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer") {alphaBackgrounds(3);}

	menuLyr= new Array();
	for (i=0;i<=menunumber;i++) {
		menuLyr[i] = eval(doc + 'menu'+i+ sty);
		menuLyr[i].zIndex=601;
	}
	menuLyr[45].top=parseInt(menuLyr[45].top)-190; //bleedin sss
	extraLyr=lyrsetup('extra',-(available_width-850),-40);
	extraLyr.zIndex=258; //extras 
	formverifer('searchform');
}

function process_table(items) {
	items='<TR>'+c_changer1+' onclick="newsearch(\''+items+'\',2); return false;">'+items+'</TD></tr>';
	return(items);
}
function menucontrol(val) {
	extraLyr.visibility="hidden";
	detailLyr[11].visibility="visible";
	clearTimeout(menutimer);
	if (val>51) {menuLyr[val].top=(mouse_y-5);}
	menuLyr[val].visibility='visible';
	for (var i=1;i<=menunumber;i++) {
		if (i!=val&&(val<5||i>51||(i>26&&i<52&&val<52)||(i>4&&i<27&&val<27))) {menuLyr[i].visibility='hidden';}

//		if (i!=val&&val<5) {menuLyr[i].visibility='hidden';}
//		if (i!=val&&i>51) {menuLyr[i].visibility='hidden';}
//		if (i!=val&&i>26&&i<52&&val<52) {menuLyr[i].visibility='hidden';}
//		if (i!=val&&i>4&&i<27&&val<27) {menuLyr[i].visibility='hidden';}
 
	}
}

function hide_menu() {
	clearTimeout(menutimer);
	if (!zoomstatus) {detailLyr[11].visibility="hidden";}
	for (var i=1;i<=menunumber;i++) {menuLyr[i].visibility='hidden';}
}

function formverifer(val) { //DOM stuff for NS6+ unbelievable clunky - must rewrite sometime
	if (document.all) {}
	else  
	if (document.getElementById) {val = eval(doc + val + htm);}
	if (!document.all) {searchform = val;}
	searchform.boxone.focus();
}

function subform() {submission('searchform'); return false;}

function submission(formname) {
	FIELD1 = eval(formname+'.boxone.value');
	if (FIELD1!= "") {
		FIELD1=FIELD1.toLowerCase();
		newsearch(FIELD1,format);
	}
	else {
		formverifer('searchform');
	}
}

function showerror(val) {}

function entsub(e) { 
	if (document.all) {var key_press=window.event.keyCode; }
	else
	if (document.layers || document.getElementById) {var key_press=e.which ; }
	if (key_press==13){subform();return false;}
	else
	return true;
} 
