// popup code
function openWindow(url, name) {
  var l = openWindow.arguments.length;
  var w = "";
  var h = "";
  var features = "";

  for (i=2; i<l; i++) {
    var param = openWindow.arguments[i];
    if ( (parseInt(param) == 0) ||
      (isNaN(parseInt(param))) ) {
      features += param + ',';
    } else {
      (w == "") ? w = "width=" + param + "," :
       h = "height=" + param;
    }
  }

  features += w + h;
  var code = "popupWin = window.open(url, name";
  if (l > 2) code += ", '" + features;
  code += "')";
  eval(code);
  }
  
// drop down menu
function gotosite(site) {            
        if (site != "") {                    
                self.location=site; 
        }
}

/*
 * This function parses ampersand-separated name=value argument pairs from
 * the query string of the URL. It stores the name=value pairs in 
 * properties of an object and returns that object.
 */
function getArgs() {
    var args = new Object();
    var query = location.search.substring(1);  // Get query string.
    var pairs = query.split("&");              // Break at ampersand.
    for(var i = 0; i < pairs.length; i++) {
	var pos = pairs[i].indexOf('=');       // Look for "name=value".
	if (pos == -1) continue;               // If not found, skip.
	var argname = pairs[i].substring(0,pos);  // Extract the name.
	var value = pairs[i].substring(pos+1); // Extract the value.
	args[argname] = unescape(value);          // Store as a property.
    }
    return args;                               // Return the object.
}

function getScore(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
  var score = 0;
  if (a1 == 'c') { score++; }
  if (a2 == 'a') { score++; }
  if (a3 == 'a') { score++; }
  if (a4 == 'd') { score++; }
  if (a5 == 'a') { score++; }
  if (a6 == 'd') { score++; }
  if (a7 == 'b') { score++; }
  if (a8 == 'c') { score++; }
  if (a9 == 'b') { score++; }

  var message = 'Uh-oh. You have a lot more studying to do!';
  if (score == 9) {
    message = "Awesome! You've aced the quiz! Now it's time to tackle the world's biggest water clean-up jobs!";
  } else if (score > 5) {
    message = "Nice work! You're on your way to become a water whiz!";
  } else if (score > 2) {
    message = 'Not bad, but your water problem-solving skills are a bit rusty.';
  }
  var table = '<table border="0" cellpadding="7" cellspacing="0"><tr>';
  table += '<td class="score"><b>' + score + '</b></td>';
  table += '<td class="blue2"><b>' + message + '</b></td></tr></table>';
  return table;
}

function getAnswer(q, a) {
  if (q == 'q1') {
    if (a == 'a') {
      return 'Paraguay, Brazil, Peru, and Argentina';
    } else if (a == 'b') {
      return 'Brazil, Uruguay, Argentina, and Chile';
    } else if (a == 'c') {
      return 'Paraguay, Brazil, Argentina, and Uruguay';
    } else if (a == 'd') {
      return 'Argentina, Bolivia, Uruguay, and Brazil';
    }
  } else if (q == 'q2') {
    if (a == 'a') {
      return 'dusty, salty, chemical-laden air blowing off the shrinking sea';
    } else if (a == 'b') {
      return 'eating fish contaminated with mercury';
    } else if (a == 'c') {
      return 'drinking polluted water';
    } else if (a == 'd') {
      return 'none of the above';
    }
  } else if (q == 'q3') {
    if (a == 'a') {
      return '80 percent';
    } else if (a == 'b') {
      return '20 percent';
    } else if (a == 'c') {
      return '40 percent';
    } else if (a == 'd') {
      return '60 percent';
    }
  } else if (q == 'q4') {
    if (a == 'a') {
      return 'water-saving gardens';
    } else if (a == 'b') {
      return 'water-efficient schools';
    } else if (a == 'c') {
      return 'eductional programs to increase awareness of water issues';
    } else if (a == 'd') {
      return 'all of the above';
    }
  } else if (q == 'q5') {
    if (a == 'a') {
      return 'began reflooding the wetlands';
    } else if (a == 'b') {
      return 'started a low-income housing project';
    } else if (a == 'c') {
      return 'planted seed crops';
    } else if (a == 'd') {
      return 'excavated the land for a larger lake';
    }
  } else if (q == 'q6') {
    if (a == 'a') {
      return 'industrial toxins';
    } else if (a == 'b') {
      return 'untreated sewage';
    } else if (a == 'c') {
      return 'oil, gasoline, and other petroleum products';
    } else if (a == 'd') {
      return 'all of the above';
    }
  } else if (q == 'q7') {
    if (a == 'a') {
      return 'a chemical factory';
    } else if (a == 'b') {
      return 'a paper and pulp mill';
    } else if (a == 'c') {
      return 'radioactive fallout from nuclear testing';
    } else if (a == 'd') {
      return 'untreated sewage from nearby towns';
    }
  } else if (q == 'q8') {
    if (a == 'a') {
      return 'increasing urban run-off';
    } else if (a == 'b') {
      return 'introducing new foreign species';
    } else if (a == 'c') {
      return "preserving and repairing the lakes' wetlands and tributaries";
    } else if (a == 'd') {
      return 'increasing fishing';
    }
  } else if (q == 'q9') {
    if (a == 'a') {
      return 'in the ocean';
    } else if (a == 'b') {
      return 'in vegetation at the bottom of Chesapeake Bay';
    } else if (a == 'c') {
      return 'they float along the surface of the bay';
    } else if (a == 'd') {
      return 'on land';
    }
  }
  return '';
}
