//jm 2007
//if error check if elements below (e.g., img tags) are missing name attributes

var earthpic = new Array(4);
  earthpic[0] = new Image(65, 65); earthpic[0].src = "http://www.epa.gov/earthday/images/earth_non.gif";
  earthpic[2] = new Image(65, 65); earthpic[2].src = "http://www.epa.gov/earthday/images/earth_yes.gif";
  earthpic[1] = new Image(65, 65); earthpic[1].src = "http://www.epa.gov/earthday/images/earth_noo.gif";
  earthpic[3] = new Image(65, 65); earthpic[3].src = "http://www.epa.gov/earthday/images/earth_glo.gif";
	
var theScore=parseInt(0);
var score1=parseInt(0);
var score2=parseInt(0);
var score3=parseInt(0);
var score4=parseInt(0);
var score5=parseInt(0);
var score6=parseInt(0);
var score7=parseInt(0);
var gotseven="no";

function fwhenwas(xx){  //1
  xx = parseInt(xx);
  stwhenwas0.style.display="none"; 
  stwhenwas1.style.display="none";
  stwhenwas2.style.display="none";
  stwhenwas3.style.display="none";
  stwhenwas4.style.display="none";
  switch( xx ){
    case 1 : stwhenwas1.style.display="inline"; document.whenwasimg.src=earthpic[1].src; score1=0;  break;
    case 2 : stwhenwas2.style.display="inline"; document.whenwasimg.src=earthpic[2].src; score1=1;  break;
    case 3 : stwhenwas3.style.display="inline"; document.whenwasimg.src=earthpic[1].src; score1=0;  break;
    case 4 : stwhenwas4.style.display="inline"; document.whenwasimg.src=earthpic[1].src; score1=0;  break;
  }
  updateScore();
}

function frecycling(xx){  //2
  xx = parseInt(xx);
  strecycling0.style.display="none";
  strecycling1.style.display="none";
  strecycling2.style.display="none";
  strecycling3.style.display="none";
  strecycling4.style.display="none";
  switch( xx ){
    case 1 : strecycling1.style.display="inline"; document.recyclingimg.src=earthpic[1].src;  score2=0;  break;
    case 2 : strecycling2.style.display="inline"; document.recyclingimg.src=earthpic[1].src;  score2=0;  break;
    case 3 : strecycling3.style.display="inline"; document.recyclingimg.src=earthpic[2].src;  score2=1;  break;
    case 4 : strecycling4.style.display="inline"; document.recyclingimg.src=earthpic[1].src;  score2=0;  break;
  }
  updateScore();
}

function fwhichmore(xx){  //3
  xx = parseInt(xx);
  stwhichmore0.style.display="none";
  stwhichmore1.style.display="none";
  stwhichmore2.style.display="none";
  stwhichmore3.style.display="none";
  switch( xx ){
    case 1 : stwhichmore1.style.display="inline"; document.whichmoreimg.src=earthpic[2].src;  score3=1;  break;
    case 2 : stwhichmore2.style.display="inline"; document.whichmoreimg.src=earthpic[1].src;  score3=0;  break;
    case 3 : stwhichmore3.style.display="inline"; document.whichmoreimg.src=earthpic[1].src;  score3=0;  break;
  }
  updateScore();
}

function fclimatechange(xx){  //4
  xx = parseInt(xx);
  stclimatechange0.style.display="none";
  stclimatechange1.style.display="none";
  stclimatechange2.style.display="none";
  stclimatechange3.style.display="none";
  stclimatechange4.style.display="none";
  switch( xx ){
    case 1 : stclimatechange1.style.display="inline"; document.climatechangeimg.src=earthpic[1].src;  score4=0;  break;
    case 2 : stclimatechange2.style.display="inline"; document.climatechangeimg.src=earthpic[1].src;  score4=0;  break;
    case 3 : stclimatechange3.style.display="inline"; document.climatechangeimg.src=earthpic[1].src;  score4=0;  break;
    case 4 : stclimatechange4.style.display="inline"; document.climatechangeimg.src=earthpic[2].src;  score4=1; break;
  }
  updateScore();
}

function fwaterquality(xx){  //5
  xx = parseInt(xx);
  stwaterquality0.style.display="none";
  stwaterquality1.style.display="none";
  stwaterquality2.style.display="none";
  stwaterquality3.style.display="none";
  stwaterquality4.style.display="none";
  switch( xx ){
    case 1 : stwaterquality1.style.display="inline"; document.waterqualityimg.src=earthpic[1].src;  score5=0;  break;
    case 2 : stwaterquality2.style.display="inline"; document.waterqualityimg.src=earthpic[1].src;  score5=0;  break;
    case 3 : stwaterquality3.style.display="inline"; document.waterqualityimg.src=earthpic[2].src;  score5=1;  break;
    case 4 : stwaterquality4.style.display="inline"; document.waterqualityimg.src=earthpic[1].src;  score5=0;  break;
  }
  updateScore();
}

function faqimeans(xx){  //6
  xx = parseInt(xx);
  staqimeans0.style.display="none";
  staqimeans1.style.display="none";
  staqimeans2.style.display="none";
  staqimeans3.style.display="none";
  staqimeans4.style.display="none";
  switch( xx ){
    case 1 : staqimeans1.style.display="inline"; document.aqimeansimg.src=earthpic[1].src;  score6=0;  break;
    case 2 : staqimeans2.style.display="inline"; document.aqimeansimg.src=earthpic[1].src;  score6=0;  break;
    case 3 : staqimeans3.style.display="inline"; document.aqimeansimg.src=earthpic[1].src;  score6=0;  break;
    case 4 : staqimeans4.style.display="inline"; document.aqimeansimg.src=earthpic[2].src;  score6=1;  break;
  }
  updateScore();
}

function fextracredit(xx){  //7
  xx = parseInt(xx);
  stextracredit0.style.display="none";
  stextracredit1.style.display="none";
  stextracredit2.style.display="none";
  stextracredit3.style.display="none";
  stextracredit4.style.display="none";
  switch( xx ){
    case 1 : stextracredit1.style.display="inline"; document.extracreditimg.src=earthpic[2].src;  score7=1;  break;
    case 2 : stextracredit2.style.display="inline"; document.extracreditimg.src=earthpic[2].src;  score7=1;  break;
    case 3 : stextracredit3.style.display="inline"; document.extracreditimg.src=earthpic[2].src;  score7=1;  break;
    case 4 : stextracredit4.style.display="inline"; document.extracreditimg.src=earthpic[2].src;  score7=1;  break;
  }
  updateScore();
}

function updateScore(){
  var theScore=(score1+score2+score3+score4+score5+score6+score7);
  scoretxtbegin.style.display="none";
  scoretxt0.style.display="none";
  scoretxt1.style.display="none";
  scoretxt2.style.display="none";
  scoretxt3.style.display="none";
  scoretxt4.style.display="none";
  scoretxt5.style.display="none";
  scoretxt6.style.display="none";
  scoretxt7.style.display="none";
  switch( theScore ){
    case 0 : scoretxt0.style.display="inline";  break;
    case 1 : scoretxt1.style.display="inline";  break;
    case 2 : scoretxt2.style.display="inline";  break;
    case 3 : scoretxt3.style.display="inline";  break;
    case 4 : scoretxt4.style.display="inline";  break;
    case 5 : scoretxt5.style.display="inline";  break;
    case 6 : scoretxt6.style.display="inline";  break;
    case 7 : scoretxt7.style.display="inline";  break;
  } 
  if (theScore == 7){ makeglow(); }
} 

function makeglow(){
  document.whenwasimg.src=earthpic[3].src;
  document.recyclingimg.src=earthpic[3].src;
  document.whichmoreimg.src=earthpic[3].src;
  document.climatechangeimg.src=earthpic[3].src;
  document.waterqualityimg.src=earthpic[3].src;
  document.aqimeansimg.src=earthpic[3].src;
  document.extracreditimg.src=earthpic[3].src;
  if (gotseven=="no"){
    alert("You got all seven answers!");
    gotseven="yes";
  }
}

function whichanswer(filename){
  var whichEarth=filename.substring((filename.length - 7 ),filename.length);
  if (whichEarth=="non.gif"){theText="This one is not answered yet.";}
  if (whichEarth=="noo.gif"){theText="That's not the right answer.";}
  if (whichEarth=="yes.gif"){theText="That's the right answer!";}
  if (whichEarth=="glo.gif"){theText="Green glow means all seven were correctly answered!";}
  alert(theText);
}
