





// below is the javascript code that verifies the exercises and lays out

// the screens. THERE'S NO EXERCISE DATA IN THIS FILE, so it should not 

// be edited. All layout customizations should be done in the exercise 

// templates. This code is the copyright of ARTFL.

//					-Leonid

// /// this code handles FILL-IN exercises ///



var gotitright = 0;



//this creates the array for the cleaning process below

var cleanQuestions = new Array ( numberofQ);



Responses      = new Array ( numberofBlanksTotal );

correctAnswers = new Array ( numberofBlanksTotal );





// the states of the process:



var init     =  0;

var verifier =  1;

var correct  =  2;



if (blankSize == null) {

	var blankSize = 10;

	}

	



var alphabet = new Array ( 26 );



alphabet[0]  = "a";

alphabet[1]  = "b";

alphabet[2]  = "c";

alphabet[3]  = "d";

alphabet[4]  = "e";

alphabet[5]  = "f";

alphabet[6]  = "g";

alphabet[7]  = "h";

alphabet[8]  = "i";

alphabet[9]  = "j";

alphabet[10] = "k";

alphabet[11] = "l";

alphabet[12] = "m";

alphabet[13] = "n";

alphabet[14] = "o";

alphabet[15] = "p";

alphabet[16] = "q";

alphabet[17] = "r";

alphabet[18] = "s";

alphabet[19] = "t";

alphabet[20] = "u";

alphabet[21] = "v";

alphabet[22] = "w";

alphabet[23] = "x";

alphabet[24] = "y";

alphabet[25] = "z";





// this sets the initial questions screen:



function setQuestionsFrame ( frame ) {





  frame.document.writeln( HTML_header1 );



  if ( ExerciseTitle != "" )

     frame.document.writeln( "<h1>" + ExerciseTitle + "</h1>" );



  frame.document.writeln( HTML_header2 );



  frame.document.writeln( ExerciseInstruction ); 



  frame.document.writeln( HTML_header3 );



  frame.document.writeln( "<FORM>");





  setFillinQ ( frame.document );





  frame.document.writeln( "</FORM>" );  



  frame.document.writeln( HTML_footer );  



  frame.document.close(); 





}





function setFillinQ ( document )

{



  var tempBuffer = "";

  var rep        = "";

  var c          = 0; 



  for ( var i = 0; i < numberofQ; i++ ) 

     {



	if ( HTML_objects[i] )

		document.writeln( HTML_objects[i] );

	

if	(ExerciseType == "Fill-in Exercise") { 

	document.writeln( (i + 1).toString() + ". " ); 

}	



	tempBuffer =  Questions[i];



	for ( var j = c; j < c + numberofBlanks[i]; j++ )

	   {



	      if ( Responses[j] )

		 rep = "<INPUT TYPE=\"text\" SIZE=\"" + blankSize + "\" VALUE=\"" + Responses[j] + "\">";

	      else

		 rep = "<INPUT TYPE=\"text\" SIZE=\"" + blankSize + "\">";



		  

	      tempBuffer = tempBuffer.replace (/<BLANK[0-9]*>/, rep );



	   }



	c += numberofBlanks[i];

	      



	document.writeln ( tempBuffer + "<P>" );





     }

}



// Stage 2: we verify responses, w/out showing them the correct answers:



function verifyResponses ( frame ) 

{



//this looks for embed tags and chops them out. note that all "questions" array references

//had to be changed to cleanQuestions - rsh 2/7



for ( var i = 0; i < numberofQ; i++ ){

	cleanQuestions[i] = Questions[i];

	if (Questions[i].indexOf("<embed") > -1) {

		

		if (Questions[i].indexOf("<br><embed") > -1) {

		

			var cutFrom = Questions[i].indexOf("<br><embed") ;

			}

			else

			 {

			 var cutFrom = Questions[i].indexOf("<embed") ;

			 }

			 

			 

			if (Questions[i].indexOf("alse><br>") > -1) {

				var cutTo = Questions[i].lastIndexOf("alse><br>") + 27;

				}

				else

				{

				var cutTo = Questions[i].lastIndexOf("alse>") +6;

				}

		cleanQuestions[i] = Questions[i].substring(0,cutFrom) + Questions[i].substring(cutTo, Questions[i].length);

		}

	}

	

  var c = 0;

  var i, j, t;



  var gotitright = 0;



  var tc = 0;



  for ( i = 0; i < numberofQ; i++ ) 

     {

        for ( j = c; j < c + numberofBlanks[i]; j++ )

	{

	    while ( frame.document.forms[0].elements[tc].type != "text" )

	    {

	       tc++;

	    }

	    Responses[j] = frame.document.forms[0].elements[tc++].value;



        }



	c += numberofBlanks[i];



     }



 frame.document.writeln ( "<BODY BGCOLOR=#ffffff>" );

 frame.document.writeln ( "<BR>" );



 frame.document.writeln ( "<h1>R&eacute;ponses</h1>" )





 var tmpResponse, tmpCorrectAnswer, tmpBuffer, tmpRep;

 var tmpCorrectAnswers = new Array();



 c = 0;



 for ( i = 0; i < numberofQ; i++ ) 

    {



       tmpBuffer = cleanQuestions[i];



       frame.document.writeln( (i + 1).toString() + ". " ); 



       for ( var j = 0; j < numberofBlanks[i]; j++ )

	  {

	     if ( numberofBlanks[i] == 1 )

		tmpRep = " ________";

	     else

		tmpRep = "<font color = \"blue\"> " + alphabet[j] + ".</font> ________";



	     tmpBuffer = tmpBuffer.replace ( /<BLANK[0-9]*>/, tmpRep ); 

	  }



       frame.document.writeln( tmpBuffer + "<br>" );





       tmpBuffer = cleanQuestions[i];





       for ( j = c; j < c + numberofBlanks[i]; j++ )



	  {

	     frame.document.write ( "<FONT COLOR=\"blue\">" );



	     if ( numberofBlanks[i] > 1 )

		frame.document.write ( alphabet[j-c] + ". " );

       



	     // we have to take care of the accents: 

	     // note, that more work is necessary; they could've entered

             // it in MAC-Roman encoding!



	     Responses[j] = iso2html ( Responses[j] ); 







	     tmpResponse = stringFlatten ( Responses[j] );

             tmpCorrectAnswer = stringFlatten ( Answers[j] );





	     tmpCorrectAnswers = tmpCorrectAnswer.split ("|");





	     correctAnswers[j] = 0; 





	     for ( var l = 0; l < tmpCorrectAnswers.length; l++ )

		{

		   if ( tmpResponse == tmpCorrectAnswers[l] ) 

		       {

			   correctAnswers[j] = 1; 

		       }

		}



	     

	     if ( correctAnswers[j] == 1 )

		{	

		   tmpRep = "Vous avez &eacute;crit </FONT><b>" + Responses[j] + "<br><i><FONT COLOR=\"blue\"> F&eacute;licitations! </font></i></b>";



		   gotitright++;



		}

	     else 

		{

		   if (Responses[j] == "") 

		      {

			 tmpRep = "</FONT><FONT COLOR=\"red\"><i> Pas de r&eacute;ponse?</i></FONT>";

		      }

		   else 

		      {

			 tmpRep = "</FONT><FONT COLOR=\"red\">Vous avez &eacute;crit </FONT>" + Responses[j] + "</b><br><FONT COLOR=\"red\">Ce n'est pas la r&eacute;ponse correcte!</FONT>";

		      }

               }



	     frame.document.writeln( tmpRep + "<br>" );



	  }

frame.document.writeln("<p>");



       t = 1; 



       for ( var j = c; j < c + numberofBlanks[i]; j++ )

	  if ( correctAnswers [j] == 0 )

	     t = 0; 



       c += numberofBlanks[i]; 





     //  if ( t == 0 )

	  //removed 1/31/00 rsh

			//frame.document.writeln( "<b>Vous voulez r&eacute;essayer?</b>" );



       //frame.document.writeln( "<br>" );



	  

    }



  frame.document.writeln("<P></FONT></BODY></HTML>")  

  frame.document.close()  



  return gotitright;



}              





// the final screen that shows the correct answers and explanations, 

// when available



function correctResponses (frame) 

{



  var c = 0;





  frame.document.writeln ( "<BODY BGCOLOR=#ffffff>" );

  frame.document.writeln ( "<BR>" );



  frame.document.writeln ( "<h1>Les r&eacute;ponses correctes:</h1>" )





  for (var i = 0; i  < numberofQ; i++) 

    {



       var tmpRep, tmpBuffer = cleanQuestions[i];



       frame.document.writeln ( (i + 1).toString() + ". " );



       for ( var j = 0; j < numberofBlanks[i]; j++ )

	  {

	     if ( numberofBlanks[i] == 1 )

		tmpRep = " ________";

	     else

		tmpRep = " " + "<font color=\"blue\">" + alphabet[j] + "</font>. ________";



	     tmpBuffer = tmpBuffer.replace ( /<BLANK[0-9]*>/, tmpRep ); 

	  }



       frame.document.writeln( tmpBuffer + "<br>" );



       for ( var j = c; j < c + numberofBlanks[i]; j++ )



	  {

	     frame.document.write ( "<FONT COLOR=\"blue\">" );



	     if ( numberofBlanks[i] > 1 )

		frame.document.write ( "<font color =\"blue\">" + alphabet[j-c] + "</font>. " );

       

	     if ( correctAnswers[j] == 1) 

		{

		   tmpRep = "Vous avez &eacute;crit </FONT><b>" + Responses[j] + "<br><i><FONT COLOR=\"blue\"> F&eacute;licitations! </font></i></b>";

		}

	     else 

		{



		   var fixMult = Answers[j].replace (/\|/g, "</b> <font color = \"blue\"><i>ou</i></font> <b>");



		   if (Responses[j] == "") 



		      tmpRep = "</FONT><FONT COLOR=\"red\"><i> Pas de r&eacute;ponse?</i></font><FONT COLOR=\"blue\"><br>La r&eacute;ponse correcte est </font><b>" + fixMult + " </b>";



		   else 



		      tmpRep = "</FONT><FONT COLOR=\"red\">Vous avez &eacute;crit </FONT>" + Responses[j] + "<br><FONT COLOR=\"blue\">La r&eacute;ponse correcte est </FONT><b>" + fixMult + " </b>";



		}



	     frame.document.writeln( tmpRep + "<br>");



	  }



       //       frame.document.writeln( tmpBuffer );



       c += numberofBlanks [i];





       if ( Explanations[i] )

	  frame.document.writeln( Explanations[i] );

       

       frame.document.writeln("<p>");

    }

      

  frame.document.writeln("<p>");



  frame.document.writeln("<P></FONT></BODY></HTML>");

  frame.document.close();



}              





// this lays out the "control panel" -- the bottom frame with the

// navigation buttons for each of the 3 states of the exercise:



function setControlPanel ( state, frame, gr ) {



  frame.document.writeln("<BODY BGCOLOR=#ffffff><CENTER><FORM>");



  if ( state == init )

     {

        frame.document.writeln("<INPUT TYPE='button' VALUE='V&eacute;rifier' onClick='parent.checkIt(parent.verifier, parent)'> <INPUT TYPE='button' VALUE='Annuler' onClick='parent.annuler();parent.checkIt(parent.init, parent)'>");

     }

  else if ( state == verifier )

     {

        frame.document.writeln ( "<b>" + getTally(gr) + "</b>" );

        frame.document.writeln("<INPUT TYPE='button' VALUE='Refaire' onClick='parent.checkIt(parent.init, parent)'> <INPUT TYPE='button' VALUE='Les r&eacute;ponses correctes' onClick='parent.checkIt(parent.correct, parent)'>");

     }

  else if ( state == correct )

     {

        frame.document.writeln ( "<b>" + getTally(gr) + "</b>" );

	frame.document.writeln("<INPUT TYPE='button' VALUE='Refaire' onClick='parent.checkIt(parent.init, parent)'>");

     }



  frame.document.writeln("</FORM></CENTER></BODY>");  

  frame.document.close(); 



}





function initScreen () {



  setQuestionsFrame ( frames[0] );

  setControlPanel ( init, frames[1] );



}





// the function below is called when one of the navigation buttons

// is pressed. 



function checkIt ( state, p ) 

{



  // first, we need to set up the main exercise frame:



  if ( state == init )

     setQuestionsFrame ( p.frames[0] );



  else if ( state == verifier )

     gotitright = verifyResponses ( p.frames[0] );



  else if ( state == correct )

     correctResponses ( p.frames[0] );





  // and now the control panel: 

     

  setControlPanel ( state, p.frames[1], gotitright );





}



//

// below are some auxilary functions:

//



function getTally ( gotitright )

{



   var tally = 0;

   var out = "";



   total = numberofBlanksTotal;



   tally = parseInt(gotitright / total * 100);



   out = "Vous avez r&eacute;pondu correctement &agrave; ";

   out = out + gotitright.toString() + " question(s) sur ";

   out = out + total.toString() + " (" + tally.toString() + "%).<br>";



   //took out as a test to make the bottom frame smaller -rsh 2/7

   //if ( gotitright == total )

     // {

	// out = out + "<FONT COLOR=\"blue\"> F&eacute;licitations!</FONT>";

      //}

   //else

     // {

	// out = out + "<FONT COLOR=\"red\">Vous voulez r&eacute;essayer?</FONT>";

      //}



   return out;

}





function annuler ()

{

   var i; 



   for ( i = 0; i < numberofBlanksTotal; i++ )

      Responses[i] = "";



}









function stringFlatten ( string )

{



   var tempBuffer = string;



   tempBuffer = tempBuffer.replace (/^ */, "");

   tempBuffer = tempBuffer.replace (/[\,\.\!\?\-]/g, "");

   tempBuffer = tempBuffer.replace (/[ \t]+/g, " ");

   //takes away string-final whitespace

   tempBuffer = tempBuffer.replace (/\s$/, "");



   tempBuffer = tempBuffer.toLowerCase ();



   return tempBuffer;

}





function iso2html ( string )

{

  var temp;



  temp = string; 





  temp = temp.replace ( /\340/g, "&agrave;" );

  temp = temp.replace ( /\342/g, "&acirc;" );





  temp = temp.replace ( /\347/g, "&ccedil;" );





  temp = temp.replace ( /\350/g, "&egrave;" );

  temp = temp.replace ( /\351/g, "&eacute;" );

  temp = temp.replace ( /\352/g, "&ecirc;" );

  temp = temp.replace ( /\353/g, "&euml;" );





  temp = temp.replace ( /\356/g, "&icirc;" );

  temp = temp.replace ( /\357/g, "&iuml;" );





  temp = temp.replace ( /\364/g, "&ocirc;" );





  temp = temp.replace ( /\374/g, "&uuml;" );

  temp = temp.replace ( /\371/g, "&ugrave;" );

  temp = temp.replace ( /\373/g, "&ucirc;" );





  return temp;



}



function verifyType ()

{



    if ( ExerciseType == "fillin" )

       return 1;



    return 0; 



}



// end -->



















