var neg_responses_array = new Array(
  
  "Types of Ultraviolet Radiation (UVR).UV-A is the least dangerous, but it penetrates the skin much deeper than the other two types and it is not absorbed by atmospheric ozone. UV-A rays are the primary type of radiation emitted by tanning beds. UV-B contributes to 75 - 85 percent of sunburn, however; much of the sun's UV-B radiation is absorbed by stratospheric ozone. UV-C is completely absorbed by oxygen and stratospheric ozone. ",
  
  "Harmful UV rays are more intense in the summer, at higher altitude, and closer to the equator. For example, Florida receives 150 percent more UVR than Maine. ",
  
  "Harmful UV rays are more intense in the summer, at higher altitude, and closer to the equator. For example, Florida receives 150 percent more UVR than Maine. ",
  
  "Melanoma is a cancer that begins in melanocytes - the skin cells that produce the dark protective pigment called melanin.",
  
  "Melanoma is the least common type of skin cancer but the most dangerous. It is most likely to spread to other parts of the body and therefore it is important to diagnose and treat this disease at an early stage. ",
  
  "Basal Cell Carcinoma (cancer) - is the most common type of skin cancer. It usually appears on the face and ears. Basal cell carcinoma is slow growing and does not usually spread to distant parts of the body (metastasize). If left untreated, however, it can cause considerable disfigurement. ",
  
  "Patients at a high risk of developing melanoma have fair skin that burns and freckles easily, light blue/green eyes and either red or blond hair. ",
  
    "Another risk factor for skin cancer is history of severe sunburn. ",
	
	    "Use a broad-spectrum sunscreen, with a Sun Protection Factor of 15 or higher, which protects against UVA and UVB rays.  ",

    "Stay in the shade whenever possible. Trees, buildings and umbrellas provide shade. You can even burn in the shade when reflective surfaces are present. "
);

var inputs_array = new Array(false,false,false,true,false,true,false,false,false,false,true,false,true,false,false,false,false,false,false,true,false,false,true,false,true,false,false,false,false,false,true,false,false,false,false,true,true,false,false,false);

function showAnswers() {
  var n_inputs = document.form1.elements.length;
  var question_name;
  var prev_correct = false;
  var score = 0;
  var response = ''; 
  var question_n = 0;
  var checkmark = "images/feedback_check.gif";
  var redex = "images/redex.gif";
  var imagew = 14;
  var imageh = 13;
  var links = "http://newbreedmarketing.com";

  for (var answer_number = 0; answer_number < n_inputs; answer_number++) {
    var current_answer = document.form1.elements[answer_number];

    if (!(current_answer.name == question_name)) {
      var id = question_name+'response';
      if (prev_correct) {
        score++;
        showFeedback(id,checkmark,imagew,imageh,"#339933"," Correct.");
      } else if (answer_number > 0) {
        var index = question_n - 1;
        response = neg_responses_array[index]; // response for previous question
        showFeedback(id,redex,imagew,imageh,"#CC0000"," Incorrect. "+response);
      }
      question_name = current_answer.name;
      prev_correct = true;

      if (current_answer.name != "submit")
        question_n++;
    }

    if (current_answer.name == "submit") break;



    if (!(inputs_array[answer_number] == current_answer.checked)) 
      prev_correct = false;
  }

  showScore(score,question_n);
  return false;
}

function showScore(score,total) {
  var divNode = document.getElementById("score");


  while (divNode.hasChildNodes()) 
    divNode.removeChild(divNode.firstChild);

  if (score == total)
    var newTextNode = document.createTextNode(score+' out of ' +total+' were correct. Congratulations!');
  else 
    var newTextNode = document.createTextNode(score+' out of ' +total+' were correct. You need to review the quiz before continuing.');
  
  divNode.appendChild(newTextNode);
  
    if (score == total)
    window.location="http://www.sunguardman.org/treasure-hunt-form.php";
  else 
       var blah = "blah";
}

function showCheck(id,img,imagew,imageh) {
  var divNode = document.getElementById(id);

  while (divNode.hasChildNodes()) 
    divNode.removeChild(divNode.firstChild);

  var newImgNode = document.createElement("img");
  newImgNode.src = img;
  newImgNode.width = imagew;
  newImgNode.height = imageh;

  divNode.appendChild(newImgNode);
}

function showFeedback(id,image,imagew,imageh,fontcolor,feedback) {
  var divNode = document.getElementById(id);

  while (divNode.hasChildNodes()) 
    divNode.removeChild(divNode.firstChild);

  var newImgNode = document.createElement("img");
  newImgNode.src = image;

  var newFontNode = document.createElement("font");
  newFontNode.color = fontcolor;

  var newTextNode = document.createTextNode(feedback);

  newFontNode.appendChild(newTextNode);

  divNode.appendChild(newImgNode);
  divNode.appendChild(newFontNode);
}
