

function displayFeedback(feedback){

    wh = window.open("","feedback","height=300px,width=400px,status=1");

	wh.document.open();
	wh.document.writeln("<html><head><title>Question Feedback</title>");
    wh.document.writeln("    <title>Question Feedback</title>");
    wh.document.writeln("</head>");
    wh.document.writeln("<body>");
    //wh.document.writeln("<div id=\"header\" style=\"position:absolute;top:0px;left:0px;\"><img src=\"../../images/popup_banner.jpg\" alt=\"Popup banner for United States Forest Service courseware.\" /></div>");
    wh.document.writeln("<div id=\"close_link\" style=\"position:absolute;top:150px;left:195px;\"><a href='javascript:window.close()'>Close</a></div>");
    wh.document.writeln("<div id=\"content\" style=\"position:absolute;top:0px;\">" + feedback + "</div>");
    wh.document.writeln("</body>");
    wh.document.writeln("</html>");
	wh.document.close();
	wh.focus();
}


var currentAttempt = 0;

function gradeMe(thisform){
    //parent.content.document.getElementById("feedback_content").innerText = "";
    isCorrect = false;
    if(parent.content.answersArr.length == 2){
			currentAttempt = 2;
        //questionCounter++;
    }
    var theChosen = new Array();
	
	if(parent.content.tempCOL)
		currentAttempt++;
	else
		currentAttempt = 2;
	//remove later?
	if(!parent.content.tempCOL)
		questionCounter++;
		
	var currentPage = parent.content.cPage;
	var currentGrade = 0;
	var numberTrue = 0;
	
	for (x in parent.content.answersArr){
		if(parent.content.answersArr[x]==true){
			numberTrue++;
			theChosen.push(parseInt(x)+1);
		}
	}
	var userSelection = false;

	for(var ii=0;ii<thisform.elements.length-1;ii++){
		//alert(thisform.elements[ii].type);
		if((thisform.elements[ii].type=="checkbox" || thisform.elements[ii].type=="radio") && thisform.elements[ii].checked==true){
			userSelection = true;
		}
	}
	if(userSelection == false){
		alert("Please make a selection.");
		currentAttempt--;
		return false;
	}
	
	if (currentAttempt<2){
		for (x in parent.content.answersArr){
			if(parent.content.answersArr[x]==true && thisform.elements[x].checked == parent.content.answersArr[x]){
				currentGrade++;
				isCorrect = true;
			}else if (parent.content.answersArr[x]==false && thisform.elements[x].checked != parent.content.answersArr[x]){
				currentGrade--;
				//thisform.elements[x].checked = false;
			}
		}
	    if(!parent.content.tempCOL)
			questionCounter++;
	}
	
	if(currentAttempt>=2){
		for (x in parent.content.answersArr){
			var y = (parseInt(x)+1).toString();
			if(parent.content.answersArr[x]==true && thisform.elements[x].checked == parent.content.answersArr[x]){
				//parent.content.document.getElementById("option" + y + "_label").style.color = "green";
				//parent.content.document.getElementById("option" + y + "_label").innerText += " (correct answer)";
				isCorrect = true;
				currentGrade++;
			}else if (parent.content.answersArr[x]==true && thisform.elements[x].checked != parent.content.answersArr[x]){
				//parent.content.document.getElementById("option" + y + "_label").style.color = "green";
				//parent.content.document.getElementById("option" + y + "_label").innerText += " (correct answer)";
				currentGrade--;
			}else if (parent.content.answersArr[x]==false && thisform.elements[x].checked != parent.content.answersArr[x]){
				//parent.content.document.getElementById("option" + y + "_label").style.color = "red";
				currentGrade--;
			}
			else{
				parent.content.document.getElementById("option" + y + "_label").style.color = "black";
			}
			thisform.elements[x].disabled=true;
		}
		thisform.elements[(thisform.elements.length-1)].disabled=true;
		parent.content.move_on = true;
	}
	var width = "500px"
	var height= "400px"
    var y;
    var foundFeedback = false;
    //alert(currentGrade + " -- " + numberTrue);
	if(currentGrade==numberTrue){	    
		//parent.content.popup_feedback (parent.content.correctfeedback, width, height);
		//Added by JR
		//content.location.href = parent.content.nextPageLoc;
		//parent.content.document.getElementById("question_feedback").style.visibility="visible";
		//parent.content.document.getElementById("feedback_content").innerText = eval("parent.content.answerfeed_" + theChosen);
		if(parent.content.tempCOL)
			parent.content.document.getElementById("next").style.visibility="visible";
		//parent.content.document.a1.src = '../../images/next_0.jpg';
        parent.content.move_on = true;
		//parent.content.document.getElementById("prompt").style.visibility="visible";
		for (x in parent.content.answersArr){
			y = (parseInt(x)+1).toString();
			if(parent.content.answersArr[x]==true && thisform.elements[x].checked == parent.content.answersArr[x] && currentAttempt<=2){
				//parent.content.document.getElementById("option" + y + "_label").style.color = "green";
				if(currentAttempt<2){
				    //parent.content.document.getElementById("option" + y + "_label").innerText += " (correct answer)";
				}
				
				if(parent.content.tempCOL)
					displayFeedback(eval("parent.content.answerfeed_" + y));
			    //parent.content.document.getElementById("feedback_content").innerText = eval("parent.content.answerfeed_" + y);
			    if(eval("parent.content.answerfeed_" + y)!="" && foundFeedback != true){
						if(parent.content.tempCOL)
							displayFeedback(eval("parent.content.answerfeed_" + y));
    		            foundFeedback = true;
						if(!parent.content.tempCOL)
							correctCounter++;
    		            
    		            //alert(correctCounter + "feedback");
                }
			}
			thisform.elements[x].disabled=true;
		}
		if(foundFeedback!=true){
			if(parent.content.tempCOL)
				displayFeedback(eval("parent.content.correctfeedback"));
			if(!parent.content.tempCOL)
				correctCounter++;
    		//alert(correctCounter);
    	}
		thisform.elements[(thisform.elements.length-1)].disabled=true;
		currentAttempt=2;
	} else if (currentAttempt<2 && currentGrade!=numberTrue){
		//parent.content.popup_feedback (parent.content.incfeedback1, width, height);
		//parent.content.document.getElementById("question_feedback").style.visibility="visible";
		//parent.content.document.getElementById("feedback_content").innerText = eval("parent.content.answerfeed_" + theChosen);
		//alert(eval("parent.content.answerfeed_" + theChosen[0]));
		for (x in parent.content.answersArr){
		        if(thisform.elements[x].checked == true){
		            thisform.elements[x].checked = false;
    		        
		            if(eval("parent.content.answerfeed_" + (parseInt(x)+1))!="" && foundFeedback != true){
    		            //displayFeedback(eval("parent.content.answerfeed_" + (parseInt(x)+1)));
    		            foundFeedback = true;
	                }
	            }
		}
		if(foundFeedback!=true){
			if(parent.content.tempCOL)
				displayFeedback(eval("parent.content.incfeedback1"));
    	}
	}else{
		//parent.content.popup_feedback (parent.content.incfeedback2, width, height);
		//parent.content.document.getElementById("question_feedback").style.visibility="visible";
		for (x in parent.content.answersArr){
		        if(thisform.elements[x].checked == true){
		            //thisform.elements[x].checked = false;
if(parent.content.remPageLoc){
						//parent.content.document.getElementById("feedback_content").innerHTML += "<br /><br />Click <a href=\'" + parent.content.remPageLoc + "'>here</a> to review this information.";	   
		                
		                //displayFeedback(eval("parent.content.incfeedback2") + "<br /><br />Click <a href=\'" + parent.content.remPageLoc + "'>here</a> to review this information.");	  
		                
						}
		        }
		}
		if(parent.content.tempCOL)
			displayFeedback(eval("parent.content.incfeedback2"));
			
		if(parent.content.tempCOL)
			parent.content.document.getElementById("next").style.visibility="visible";
        //parent.content.document.NEXT.src = '../../images/next_0.jpg';
        //parent.content.move_on = true;	
		//parent.content.document.getElementById("prompt").style.visibility="visible";
	}
	//alert(currentGrade);
	//question added to array here
	addQuestion();
	
	foundFeedback = false;
		
	return false;
}

function unhighlightAnswer(currentAnswer){
	if(currentAttempt<2){
		parent.content.document.getElementById("p"+currentAnswer).style.color = "black";
	}	
}

function highlightAnswer(currentAnswer){
	if(currentAttempt<2){
		parent.content.document.getElementById("p"+currentAnswer).style.color = "blue";
	}
}