var debug;
var KCcheat;

if(debug == 'true')
	{NextEnabled = 1;}
else
	{NextEnabled = 0;}	


function showCorrect()
{
	if(KCcheat == 'true')
		{
			vShowID = (vCorrectAnswer -1);	
			document.form1.Quiz[vShowID].style.backgroundColor = '#F8F7C7';
		}
}

function Clicked()
{	
	var form = document.form1
	var vResponse = ""
	
	//returns the checked item
	for (var i=0; i < form.Quiz.length; i++) 
		{
			if(form.Quiz[i].checked) 
				{
 				vResponse = form.Quiz[i].value;
				}
		}
		
		if (vResponse=="")			
			{alert("\nYou need to answer the question to continue.")}
		else
			{
					if (vAttempt < vTriesAllowed)
						{
						 //they got it right
						 if (vResponse == vCorrectAnswer) 
							{DisplayFeedback('Correct',Feedback); vAttempt = vTriesAllowed}
							
						 //they got it wrong, and it's not the last available try
						 if (vResponse != vCorrectAnswer && vAttempt <= vTriesAllowed)
							{
							        
									if(vResponse==1){
									var Numval = FeedbackA
									} else if(vResponse==2){
									var Numval = FeedbackB
									}else if(vResponse==3){
									var Numval = FeedbackC
									}else if(vResponse==4){
									var Numval = FeedbackD
									}
									//tell them to try again
									//alert("FeedbackWrong:::"+FeedbackWrong1)
									var FeedbackWrong = FeedbackWrong1+Numval	
									{DisplayFeedback('Incorrect',FeedbackWrong)}
									

							}		
						 }
						 
						 //they still got it wrong on their last try	
					else
						{
						 if (vResponse != vCorrectAnswer)		
							{
								//tell them the correct answer
								{DisplayFeedback('Incorrect',FeedbackWrong2)}
							}	
						 if (vResponse == vCorrectAnswer) 		{DisplayFeedback('Correct',Feedback)}
						}	
				
					//make the unchecked items unavailable
					for (var i=0; i < form.Quiz.length; i++) 
					{
						if(!form.Quiz[i].checked) 
							{
							   form.Quiz[i].disabled=true;
							}
					}
			}
				
			
}

function Navigate()
{	
	//alert("A: " + vAttempt + " TA: " + vTriesAllowed);
	if (vAttempt == vTriesAllowed)
		{
				//wh.opener.moveNext();
			document.getElementById('next').focus();	
		}		
	if (vAttempt < vTriesAllowed)
		{
			document.getElementById('feedbackDiv').style.display = 'none';
			//document.getElementById('maincontent').style.display = 'block';	
			//document.getElementById('instruction').focus();	
			//vTriesAllowed = vTriesAllowed - 1; 
			//document.getElementById('tries').innerHTML = " (Tries remaining: " + vTriesAllowed + ")"
			
				//make the unchecked items unavailable
			vTriesAllowed = vTriesAllowed - 1; 
				
				for (var i=0; i < document.form1.Quiz.length; i++) 
				{					
					 document.form1.Quiz[i].disabled=false;
				}
		}
}



function DisplayFeedback(Response,Feedback)
{
	//document.getElementById('maincontent').style.display = 'none';
	document.getElementById('feedbackDiv').style.display = 'block';	
	document.getElementById('feedbackDiv').focus();	
		
		
	if(Response == "Correct") {Answer = '<span style="color:#6e9017; font-weight:bold;">Correct.</span> Review the feedback below. When you are ready to proceed, click the Next button.'}; //<img src="images/NextBtn.jpg" alt="">
	if(Response == "Incorrect") {Answer = '<span style="color:#6e9017; font-weight:bold;">Incorrect.</span> Review the feedback below. When you are ready to proceed, click the Next button.'};
		
		FeedBackText = ''
		
		FeedBackText = FeedBackText + '<div id="FBtext" style="background-color:#FFFFFF; overflow:auto; padding:0px;" >';
		
		if ((vAttempt == vTriesAllowed  && Response == "Incorrect") || Response == "Correct"){FeedBackText = FeedBackText + '<p>' + Answer + '</p>'; setNextActive()}
		
		FeedBackText = FeedBackText + '<p>';
		FeedBackText = FeedBackText + Feedback;
		FeedBackText = FeedBackText + '</p></div>';
		
		if ((vAttempt != vTriesAllowed  && Response == "Incorrect"))
			{FeedBackText = FeedBackText + '<p align=center style="margin-top:10px;"><div id="btnTABorder" style="width:98px; height:25px; text-align:center;"><a href="#" onfocus="javascript:document.getElementById(\'btnTABorder\').style.border=\'3px solid yellow\';" onblur="javascript:document.getElementById(\'btnTABorder\').style.border=\'none\';" onclick="window.close();" onmouseover="document.tryagain.src=\'../../images/tryAgainHi.gif\';" onmousedown="document.tryagain.src=\'../../images/tryAgainDn.gif\';" onmouseout="document.tryagain.src=\'../../images/tryAgain.gif\';"><img src="../../images/tryAgain.gif" alt="Try Again" title="Try Again" border=0 name="tryagain"></a></div>';}
	
		//document.getElementById('feedbackDiv').innerHTML=FeedBackText;
		openFeedbackWindow(FeedBackText);
}


function setNextActive()
{
	if(document.getElementById("next"))
		document.getElementById("next").style.visibility = "visible";
}

function openFeedbackWindow(feedback){

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

	wh.document.open();
	wh.document.writeln("<html><head><title>Question Feedback</title>");
	wh.document.writeln("<link rel=\"stylesheet\" type=\"text/css\" href=\"../../naracui.css\" />");
    wh.document.writeln("</head>");
    wh.document.writeln("<body class=\"popup\" onbeforeunload=\"window.opener.Navigate();\">");        
    wh.document.writeln("<div id=\"content\" style=\"position:absolute;top:0px;overflow:auto;\">" + feedback + "</div>");
    wh.document.writeln("</body>");
    wh.document.writeln("</html>");
	wh.document.close();
	wh.focus();
}


