// JavaScript Document


	var cr = "green";
	taxlist = new Array();
	charlist = new Array();
	chosen = new Array();
	pchose = new Array();

	// BLAINE EDIT BEGIN 4/18/2006
	var thispage = getCurrentPage();

	var DEFUALT_DATA_FILE = "data.js";
	var DATA_FOLDER = "";	// must be empty string ("") or end with slash (/)

	setDataFile();
	
	function urlMono(genus) {
		return thispage + "?genus=" + genus;
	}

	function setDataFile() {
		var paramDataFile = getParam("genus");
		var dataFile = paramDataFile ? paramDataFile + ".js" : DEFUALT_DATA_FILE;
		includeJS(DATA_FOLDER + dataFile);
		//alert(DATA_FOLDER + dataFile) //debug
		return false;
	}

	function getParam(paramKey) {
		var query = window.location.search.substring(1);
		var parms = query.split("&");
		for (var i=0; i<parms.length; i++) {
		   var pos = parms[i].indexOf("=");
		   if (pos > 0) {
		      var key = parms[i].substring(0, pos);
		      if (key == paramKey) {
			      return parms[i].substring(pos + 1);
			  }
		   }
		}
		return false;
	}

	function includeJS(filename) {
		var htmlHead = document.getElementsByTagName("head").item(0);
		var js = document.createElement("script");
		js.setAttribute("language", "javascript");
		js.setAttribute("type", "text/javascript");
		js.setAttribute("src", filename);
		htmlHead.appendChild(js);
		return false;
	}

	function getCurrentPage() {
		var path = document.location.href;
		path = path.substring(path.lastIndexOf("\/") + 1, path.length);
		var questionMark = path.lastIndexOf("?");
		if (questionMark > 0) path = path.substring(0, questionMark);
		return path;
	}
// BLAINE EDIT END

	function show5() {
		var b=0;
		var z=0;
		var i=0;
		var w=1;
		var p=0;
		taxlist2 = new Array();
		for (t=0; t < charlist.length; t++) {
			//m is the characteristics the program wants to show right now (could be modified from complete list by "applicable chars" button) -RJM
			var m = charlist[t];
// BLAINE EDIT	4/18/2006
//			for (z=1; z<chars[m].length; z++) {  //blaine starts probe 1 further out b/c link name is now at index 1
			for (z=2; z<chars[m].length; z++) {
				//go through all the options for each of the chars we care about (ones in charlist) -RJM
				var y = eval("top.menu.keyForm.svc"+m+"s"+z+".checked");
				if (y == true) {
					//if a characteristic is checked, 
// BLAINE EDIT 4/27/2006
//					chosen[i] = ("((items[w][" + m + "] == "+z+")|(items[w][" + m + "] == '?'))");
					//blaine added an index shift here because the link name pushes everything up by 1 -RJM
					chosen[i] = ("((items[w][" + m + "] == " + (z - 1) + ")|(items[w][" + m + "] == '?'))");
					i = (i+1);
				}
			}
		}

		bodyframe.document.write("<p>Taxa Matching Your Description:</p><id ='topofpage'>");
		chosenv = chosen.concat(pchose);
		var tchose = chosenv.join(" && ");
		for (w=1; w < items.length; w++) {
			var il = (items[w].length - 1);	
			var g = eval(tchose);
			var ifnew = "target = '_new'"; //RJM
			if (g) {
				//items.sort();
				if (items[w][il].indexOf('SLIKS') != -1) ifnew = "target = '_top'"; //detects if this is a monomimal by link type
				bodyframe.document.write("<p><i><input type='button' value='D' onclick = 'top.desc("+w+")'> <a href='" + items[w][il] + "' " + ifnew + ">" + items [w][0] + "</a></i></p>");
				//bodyframe.document.write("<input type='button' value='D' onclick = 'top.desc("+w+")'><i><b> <a href=' " + items[w][il] + "' target ='_new'>" + items [w][0] + "</a></i></b><br>");
				taxlist2[p] = (w);
				p = (p+1);
			}
		}	
		bodyframe.document.write("<p> End of Selection Set</p>");
		taxlist = taxlist2;	
		pchose = chosenv;
	}



		
	function about() {
		alert("Go to WWW.STINGERSPLACE.COM for more info. This program is free and cannot be sold. Please report any violations to STINGER@STINGERSPLACE.COM. SLIKS version 1.2, Copyright (C) 2005, Gerald F. Guala. SLIKS is distributed under the GNU Public License and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain very specific conditions. For details see the GPL.txt file that was distributed with this program or go to www.gnu.org");
	}

	function keymakeb() {
		//RJM - this is for binary data, not used for BBG
		charlist.length = 0;
		menu.document.write(dataset);
		
		menu.document.write("<FORM name=keyForm>");
		var z=1;
		var x=0;
		var p=0;
		for (x=1; x < chars.length; x++) {
			var r = (z+1);
			menu.document.write("<INPUT TYPE='checkbox' NAME='svc"+x+"s"+z+"'><INPUT TYPE='hidden' NAME='svc"+x+"s"+r+"'><font color =" + cr +"><b><i> " + x + ". " + chars [x][0] + "</i></b></font><br>");
			charlist[p] = (x);
			p = (p+1); 
		}
		menu.document.write("</FORM>");
	}

	function keymake() {
		charlist.length = 0;
		menu.document.write(dataset);
		menu.document.write("<FORM name=keyForm>");
		var z=1;
		var x=0;
		var p=0;

		for (x=1; x < chars.length; x++) {
// BLAINE EDIT
			//this change added the link to the image stored in cell 1 of the chars[x][] array, working OK -RJM
			menu.document.write("<br /><b><i>" + x + ". <a href='" + chars[x][1] + "' target='_new'>" + chars [x][0] + "</a>:</i></b><br />");
// 			menu.document.write("<br><font size = +1 color =" + cr +"><b><i>" + x + ". " + chars [x][0] + ":</i></b></font><br>");
			
			//to start, charlist is just every characteristic, could change if "applicable chars" button is pushed
			charlist[p] = (x);
			p = (p+1);

// BLAINE EDIT
			for (z=2; z<chars [x].length; z++) {
// 				for (z=1; z<chars [x].length; z++)
				menu.document.write("<INPUT TYPE='checkbox' NAME='svc"+x+"s"+z+"'> "+ chars[x][z] + "<br>");
			}
		}
		menu.document.write("</FORM>");
	}

	function keymakec() {
		if (binary == 1)
			keymakeb()
		else
			 keymake();
		// binary ? keymakeb() : keymake();
	}

	function desc(w) {
		var z=1;
		var x=1;
		var newnum = 0; //RJM
		bodyframe.document.write("<b><i>"+items[w][0]+"</i></b><br>");
		for (x=1; x < chars.length; x++) { //RJM change-- why was this 2?  bug; perhaps changed instead of lower change by mistake
		//for (x=2; x < chars.length; x++) {
			var q = items[w][x];
			//bodyframe.document.write("<br><b>"+ chars [x][0] + ": </b>"+ chars[x][q] );
			//RJM change: adapt display to blaine's new chars array structure

			if (q != "?") {  			//if it's known, increase by 1 to show correct value -RJM
				q = (parseInt(q)+1)
			} 

			bodyframe.document.write("<br><b>"+ chars [x][0] + ": </b>"+ chars[x][(q)] ); //now q is good
		}
	}

	function fullclear() {
		taxlist = new Array();
		charlist = new Array();
		chosen = new Array();
		pchose = new Array();
		top.menu.document.location.reload();
		top.keymakec();
		top.alltaxa();
	}

	function alltaxa() {
		var p=0;
		var w=1;
		bodyframe.document.write("<p>All Taxa:</p>");
	
		for (w=1; w < items.length; w++) {
			if (items[w] == null) alert('null found: ' + items[w-1][0]);
			var il = (items[w].length - 1);
			var ifnew = "target = '_new'";
			//items.sort();
			if (items[w][il].indexOf('SLIKS') != -1) ifnew = "target = '_top'"; //put thing here that detects if this is a monomimal (instead of true)
			bodyframe.document.write("<input type='button' value='D' onclick = 'top.desc("+w+")'><i><b> <a href='" + items[w][il] + "' " + ifnew + ">" + items [w][0] + "</a></i></b><br>");
			taxlist[p] = (w);
			p = (p+1); 
		}
	
		bodyframe.document.write("<p>End of All Taxa</p>");
	}
