var increment = 0;
var currentAttempt = 1;

function gradeMe(thisform){
	
    var userSelection = false;
    var selected = '';
       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){
                      
                      if (selected != ""){
                                  selected = selected + "[,]";
                           }
                            selected = selected + (ii+1);
                           
                     userSelection = true;
              }
       }
       
    isCorrect = false;
	//alert(answersArr.length);
    if(answersArr.length == 2){
                     currentAttempt = 2;
    }
    var theChosen = new Array();
       
       if(tempCOL)
              currentAttempt++;
       else
              currentAttempt = 2;
       
       
       if(!tempCOL)
              questionCounter++;
              
       //var currentPage = cPage;
       var currentGrade = 0;
       var numberTrue = 0;
       
       for (x in answersArr)
       {
              if(answersArr[x]==true)
              {
                     numberTrue++;
                     theChosen.push(parseInt(x)+1);
              }
       }
       var userSelection = false;

       for(var ii=0;ii<thisform.elements.length-1;ii++)
       {
              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 answersArr)
              {
                     if(answersArr[x]==true && thisform.elements[x].checked == answersArr[x])
                     {
                           currentGrade++;
                           isCorrect = true;
                     }
                     else if (answersArr[x]==false && thisform.elements[x].checked != answersArr[x])
                     {
                           currentGrade--;
                     }
              }
              
           if(!tempCOL)
                     questionCounter++;
       }
       
       if(currentAttempt>=2)
       {
              for (x in answersArr)
              {
                     var y = (parseInt(x)+1).toString();
                     
                     if(answersArr[x]==true && thisform.elements[x].checked == answersArr[x])
                     {
                           isCorrect = true;
                           currentGrade++;
                     }
                     else if (answersArr[x]==true && thisform.elements[x].checked != answersArr[x])
                     {
                           currentGrade--;
                     }
                     else if (answersArr[x]==false && thisform.elements[x].checked != answersArr[x])
                     {
                           currentGrade--;
                     }
                     else
                     {
                           document.getElementById("option" + y + "_label").style.color = "black";
                     }
                     
                     thisform.elements[x].disabled=true;
              }
              
              thisform.elements[(thisform.elements.length-1)].disabled=true;
              move_on = true;
       }
       
       var width = "500px"
       var height= "400px"
    var y;
    var foundFeedback = false;
    
       if(currentGrade == numberTrue)
       {          
              //if(tempCOL)
                    // document.getElementById("next").style.visibility="visible";
                     
					//move_on = true;
              
              for (x in answersArr)
              {
                     y = (parseInt(x)+1).toString();
                     if(answersArr[x]==true && thisform.elements[x].checked == answersArr[x] && currentAttempt<=2)
                     {
                           if(currentAttempt<2){ }
                           
                           if(tempCOL)
                                  displayFeedback(eval("answerfeed_" + y));
                         
                         if(eval("answerfeed_" + y)!="" && foundFeedback != true)
                           {
                                         if(tempCOL)
                                                displayFeedback(eval("answerfeed_" + y));
                                                
                          foundFeedback = true;
                                         if(!tempCOL)
                                                correctCounter++;
                }
                     }
                     thisform.elements[x].disabled=true;
              }
              
              if(foundFeedback!=true){
                     if(tempCOL)
                           displayFeedback(eval("correctfeedback"));
                     if(!tempCOL)
                           correctCounter++;
       }
              thisform.elements[(thisform.elements.length-1)].disabled=true;
              currentAttempt=2;
       } 
       else if (currentAttempt<2 && currentGrade!=numberTrue)
       {
              for (x in answersArr)
              {
                      if(thisform.elements[x].checked == true)
                           {
                          thisform.elements[x].checked = false;
                      
                          if(eval("answerfeed_" + (parseInt(x)+1))!="" && foundFeedback != true){
                          foundFeedback = true;
                       }
                   }
              }
              
              if(foundFeedback!=true){
                     if(tempCOL)
                           displayFeedback(eval("incfeedback1"));
       }
       }else
       {
              for (x in answersArr)
              {
                      if(thisform.elements[x].checked == true){
                                  if(remPageLoc){

                                         }
                      }
              }
              
              if(tempCOL)
                     displayFeedback(eval("incfeedback2"));        
             
       }
       
	   var correctAnswers = "";
	   //Check if question is multiple choice.  
	   if(moreThanOne)
	   {
			//Get the correct answers from the form.		
			for(x in answersArr)
			{				
				//Create pipe delimited string.
				if(answersArr[x])					
					correctAnswers += (+x + 1) + "|";				
			}				
			//Remove last "|" from the string.
			correctAnswers = correctAnswers.substring(0,correctAnswers.length - 1);			
			//Submit the question.
			//submitQuestion(selected, correctAnswers);			
	   }
	   else
	   {			
			//submitQuestion(selected, parent.content.comparisonOperator);			
	   }     
    
       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 = "darkblue";
	}*/
}

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;font-family:Arial;background-color:#2389B9;color:#FFFFFF;width:505px;height:25px;font-size:20px;font-weight:bold;\">Feedback</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:40px;\">" + feedback + "</div>");
    wh.document.writeln("</body>");
    wh.document.writeln("</html>");
	wh.document.close();
	wh.focus();
}