//if(debug == 'true' || parent.ISDBSenrolled == 1)
//	{NextEnabled = 1;}
//else
//	{NextEnabled = 0;}
var KCcheat = 'true';
function showCorrect()
{
	if(KCcheat == 'true')
	{
		//alert( "showCorrect" );
		var form = document.form1
		var vAnswered = 0
		var vResponse = ""
		var vCorrectCount = 0
		var vNumOfColumns = form.Quiz1.length
		var vNumOfRows = form.length/vNumOfColumns
			
		//highlights the correct answers
		k = 0  //beginning number for loop
		m = (vNumOfColumns) //ending number for loop
		
		for (var i=0; i < vNumOfRows; i++)  //this should count from 1 to 3 for each row
		{
			vAnswer = 0
			vLoopCount = 1
			for (var j=k; j < m; j++)  
			{
				if(form.elements[j].value == vCorrectAnswer.charAt(i)) 
				{form.elements[j].checked = 1; vAnswer = vLoopCount; vResponse = vResponse + vAnswer; vCorrectCount = vCorrectCount + 1	}
				else
				{}
				vLoopCount = vLoopCount + 1
			}
			m = (m + vNumOfColumns) //set new ending number for loop
			k = (m - vNumOfColumns)  //set new beginning number for loop
		}	
	}
}



function Clicked()
{	
		//alert('this is the attempts: ' + vAttempt + ' and here are the max allowed tries: ' +  vTriesAllowed)
	//alert("here");
	var form = document.form1
	var vAnswered = 0
	var vResponse = ""
	var vCorrectCount = 0
	var vNumOfColumns = form.Quiz1.length
	var vNumOfRows = form.length/vNumOfColumns
	
	//alert("Rows: " + vNumOfRows + "  Cols: " + vNumOfColumns);	
	
	//checks to see if the question has been attempted or not
	k = 0  //beginning number for loop
	m = (vNumOfColumns) //ending number for loop
	
	for (var i=0; i < vNumOfRows; i++)  //this should count from 1 to 3 for each row
	{
		//alert('here is row ' + i)
		vAnswer = 0
		vLoopCount = 1
		for (var j=k; j < m; j++)  
		{
			//alert(form.elements[j].checked)
			if(form.elements[j].checked) 
			{
				vAnswer = vLoopCount; 
				vResponse = vResponse + vAnswer;	
			}
			//vResponse = vResponse + form.elements[j].checked*1	
			vLoopCount = vLoopCount + 1
		}
		m = (m + vNumOfColumns) //set new ending number for loop
		k = (m - vNumOfColumns)  //set new beginning number for loop
	}
	//alert("Response: " + vResponse.length);
	//alert("Correct Length: " + vCorrectAnswer.length);
	//alert(vResponse)
		
	if (vResponse.length != vCorrectAnswer.length){
		alert("\nYou need to answer the question to continue.");
	}		
	else //there is a response	
	{
		if (vAttempt < vTriesAllowed)
		{
		  //they got it right
		  if (vResponse == vCorrectAnswer){
			 DisplayFeedback('Correct',Feedback); 
			 vAttempt = vTriesAllowed;
			 disableSubmitBtn();
		  }
			
		  //they got it wrong, and it's not the last available try
		  if (vResponse != vCorrectAnswer && vAttempt <= vTriesAllowed)
			{
				//alert(vResponse);
					k = 0  //beginning number for loop
					m = (vNumOfColumns) //ending number for loop
					
					for (var i=0; i < vNumOfRows; i++)  //this should count from 1 to 3 for each row
						{
						//alert('here is row ' + i)
						vAnswer = 0
						vLoopCount = 1
						for (var j=k; j < m; j++)  
							{
								//alert(form.elements[j].checked)
								if(form.elements[j].checked && vResponse.charAt(i) == vCorrectAnswer.charAt(i)) 
								{vAnswer = vLoopCount; vResponse = vResponse + vAnswer; vCorrectCount = vCorrectCount + 1	}
								else
								{form.elements[j].checked=0}
								//vResponse = vResponse + form.elements[j].checked*1	
								vLoopCount = vLoopCount + 1
							}
							m = (m + vNumOfColumns) //set new ending number for loop
							k = (m - vNumOfColumns)  //set new beginning number for loop
						}
						
					//tell them to try again and how many they got right
					if(vCorrectCount == 0)
						{DisplayFeedback('Incorrect','You did not answer any item correctly.  <p><strong>Please review the question and begin again.</strong> ')}
					else
						{DisplayFeedback('Incorrect','You answered ' + vCorrectCount + '</strong> of the items correctly.  Your wrong answers are erased to allow you to try again.</p> <p><strong>Please click on Try Again and then select a new response for each "unanswered" item.  Remember, the remaining selected answers are correct! </strong>')}
					
					
			}		
			
			//disable the radio buttons
			var form = document.form1
			var vAnswered = 0
			var vResponse = ""
			var vCorrectCount = 0
			var vNumOfColumns = form.Quiz1.length
			var vNumOfRows = form.length/vNumOfColumns						
			k = 0
			m = (vNumOfColumns)					
			for (var i=0; i < vNumOfRows; i++)  //this should count from 1 to 3 for each row
			{
				vAnswer = 0
				//vLoopCount = 1
				for (var j=k; j < m; j++)  
				{
					form.elements[j].disabled=true;						
					//vLoopCount = vLoopCount + 1
				}
				m = (m + vNumOfColumns) //set new ending number for loop
				k = (m - vNumOfColumns)  //set new beginning number for loop
			}			
		}			 
		//they still got it wrong on their last try	
		else
		{
		  if (vResponse != vCorrectAnswer)		
		  {
			k = 0  //beginning number for loop
			m = (vNumOfColumns) //ending number for loop
			
			for (var i=0; i < vNumOfRows; i++)  //this should count from 1 to 3 for each row
				{
				//alert('here is row ' + i)
				vAnswer = 0
				vLoopCount = 1
				for (var j=k; j < m; j++)  
					{
						//alert(form.elements[j].checked)
						if(form.elements[j].checked && vResponse.charAt(i) == vCorrectAnswer.charAt(i)) 
						{vAnswer = vLoopCount; vResponse = vResponse + vAnswer; vCorrectCount = vCorrectCount + 1	}
						else
						//{form.elements[j].checked=0}
						//vResponse = vResponse + form.elements[j].checked*1	
						vLoopCount = vLoopCount + 1
					}
					m = (m + vNumOfColumns) //set new ending number for loop
					k = (m - vNumOfColumns)  //set new beginning number for loop
				}
					
			//tell them to try again and how many they got right
			if(vCorrectCount == 0)
				{DisplayFeedback('Incorrect','You did not answer any item correctly.   <p>' + Feedback)}
			else
				{DisplayFeedback('Incorrect','You answered ' + vCorrectCount + '  of the items correctly. </strong></p><p>' + Feedback)}
						
			showCorrect();
			//Disable the submit button
			disableSubmitBtn();
		  }	
		  if (vResponse == vCorrectAnswer){
			DisplayFeedback('Correct',Feedback);
		  }
		}				
	}	
}

function disableSubmitBtn()					
{
	if(document.getElementById("lnkSubmit")){
		document.getElementById("lnkSubmit").href = "#";		
	}
}

var wh;

function Navigate()
{		
	if (vAttempt == vTriesAllowed)
	{		
		document.getElementById('next').focus();	
	}		
	if (vAttempt < vTriesAllowed)
	{		
		wh.close();		
		document.getElementById('instruction').focus();			
		
		//make the unchecked items unavailable
		vTriesAllowed = vTriesAllowed - 1; 
			
		//enable the radio buttons
		var form = document.form1
		var vAnswered = 0
		var vResponse = ""
		var vCorrectCount = 0
		var vNumOfColumns = form.Quiz1.length
		var vNumOfRows = form.length/vNumOfColumns						
		k = 0
		m = (vNumOfColumns)					
		for (var i=0; i < vNumOfRows; i++)  //this should count from 1 to 3 for each row
		{
			vAnswer = 0
			vLoopCount = 1
			for (var j=k; j < m; j++)  
			{
				 form.elements[j].disabled=false;								
				vLoopCount = vLoopCount + 1
			}
			m = (m + vNumOfColumns) //set new ending number for loop
			k = (m - vNumOfColumns)  //set new beginning number for loop
		}
	}
}


function DisplayFeedback(Response,Feedback)
{
	if(Response == "Correct") {Answer = '<span style="color:#6e9017; font-weight:bold;">Correct.</span> Review the feedback below.  When you are ready to proceed, select the Next button.'}; //<img src="images/NextBtn.jpg" alt="">
	if(Response == "Incorrect") {Answer = '<span style="font-weight:bold;">Incorrect.</span> The correct answers are now shown. Review the feedback below.  When you are ready to proceed, click on 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>';}
		else
{FeedBackText = FeedBackText + '<p align=center style="margin-top:10px;"><a href="#" onclick="window.close();" onfocus="this.style.border=\'3px solid yellow\';" onblur="this.style.border=\'none\';">Close</a>';}	
		
		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\" onunload=\"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();
}


