var m_f;
var score = 1000;
var new_score = 0;
var which_hab;
var tries = 0;
var add_score = 0;
var which_bat;
var batArray;
which_bat = new Array (5);
  which_bat[0] = "myyu,Yuma Myotis";
  which_bat[1] = "myvo,Long-legged Myotis";
  which_bat[2] = "myev,Western Long-eared Myotis";
  which_bat[3] = "myca,California Myotis";
  which_bat[4] = "mylu,Little Brown Myotis";
batArray = new Array (5);

function openLocation() {
	var eagleName = window.document.eagle.src
	if (eagleName.substring(eagleName.length - 15, eagleName.length) !== "transparent.gif") {
		alert("This activity is difficult. Excellent work. Your seventh clue: enjoyment.");
		window.location = "../migration/birds01.htm";
	}
}

function chooseBat(which_hab){
  document.bats.last_try.value = "";
  if (which_hab !== 0) {
  	checkBat(which_hab);
	document.bats.last_try.value = Math.round(new_score * 100) + "%";
	var last_try = Math.round(new_score * 100)
  if (last_try > 50) alert('Excellent choice.');
  if (last_try <= 50 && last_try >= 40) alert('Good choice.');
  if (last_try <= 40 && last_try >= 20) alert('You better examine the data again.');
  if (last_try < 20) alert('Poor choice.');
  }
  var str1 = which_bat[Math.round(Math.random() * 4)];
  batArray = str1.split(",");
  document.bats.taxon.value = batArray[1];
  if (Math.round(Math.random() * 1) == 1) {
  	m_f = "M";
  }
  else {
	m_f = "F";
  }
  document.bats.score.value = score;
  document.bats.tries.value = tries;
  document.bats.taxon.value = batArray[1];
  document.bats.m_f.value = m_f;
  document.bat_image.src = "../../images/bats/habitat/" + batArray[0] + ".gif";
  if (tries == 10) {
  	if (score >= 500) {
		document.eagle.src = "../../elements/eagle_btn_ani.gif";
		alert('Excellent trend-seeking. Click the Eagle and you will be off to your next destination.');
	}
	if (score < 500) {
		score = 1000;
		new_score = 0;
		tries = 0;
		add_score = 0;
		alert('You better try again. Read the helpful hints below and examine the data once more.');
		document.bats.score.value = score;
		document.bats.tries.value = tries;
	}
  }
}
function checkBat(which_hab){
	tries ++;
	if (which_hab == 1 ) { //subalpine
		if (batArray[0] == "myyu") new_score = .13;
		if (batArray[0] == "myvo") new_score = .63;
		if (batArray[0] == "myev") new_score = .24;
		if (batArray[0] == "myca") new_score = 0;
		if (batArray[0] == "mylu") new_score = .54;
		if (m_f == "M") new_score = (new_score + .9)/2;
		if (m_f == "F") new_score = (new_score + .1)/2;
	}
	else if (which_hab == 2 ) { //forest
		if (batArray[0] == "myyu") new_score = .3;
		if (batArray[0] == "myvo") new_score = .36;
		if (batArray[0] == "myev") new_score = .48;
		if (batArray[0] == "myca") new_score = .39;
		if (batArray[0] == "mylu") new_score = .3;
		if (m_f == "M") new_score = (new_score + .45)/2;
		if (m_f == "F") new_score = (new_score + .55)/2;
	}
	else  { //riparian
		if (batArray[0] == "myyu") new_score = .57;
		if (batArray[0] == "myvo") new_score = .09;
		if (batArray[0] == "myev") new_score = .03;
		if (batArray[0] == "myca") new_score = .61;
		if (batArray[0] == "mylu") new_score = .16;
		if (m_f == "M") new_score = (new_score + .3)/2;
		if (m_f == "F") new_score = (new_score + .7)/2;
	}
	new_score = new_score * 1.04; //tweak factor
	add_score = add_score + (new_score*1000);
	score =  Math.ceil(add_score/tries);
}
function restartBat() {
	window.location = "bat_hab.htm";
}