

// 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 TRANSFORMATION exercises ///



//this creates the array for the cleaning process below

var cleanQuestions = new Array ( numberofQ);



var gotitright = 0;



var Responses      = new Array (numberofQ);

var correctAnswers = new Array (numberofQ);



// the states of the process:



var init =      0;

var verifier =  1;

var correct =   2;





// 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>");





   setTransformQ ( frame.document );



  

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



   frame.document.writeln( HTML_footer );  



   frame.document.close(); 





}



function setTransformQ ( document )

{



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

     {

        document.writeln( HTML_objects[i] );

        document.writeln( "<p>" + (i + 1).toString() + ". " + Questions[i] + "<br>" );

	document.writeln( "<INPUT TYPE='text' SIZE='50' " );



	if ( Responses[i] )

	   {

              document.writeln( "VALUE=\"" + Responses[i] + "\" " );

           }



	document.writeln ( ">" );

     }

}





// this verifies the responses and sets up the 2nd screen:



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) {

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

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

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

		}

	}

	

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

     {

        Responses[i] = frame.document.forms[0].elements[i].value;

     }



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

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



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





 var tmpResponse, tmpCorrectAnswer;

 var tmpCorrectAnswers = new Array();



 var gotitright = 0;



 



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

    {





       frame.document.writeln( (i + 1).toString() + ". " + cleanQuestions[i].toString() + "<br>" );



       tmpResponse = stringFlatten ( Responses[i] );

       tmpCorrectAnswer = stringFlatten ( Answers[i] );



       // we have to take care of the accents: 

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

       // it in MAC encoding!



       tmpResponse = iso2html ( tmpResponse ); 



       tmpCorrectAnswers = tmpCorrectAnswer.split ("|");



       correctAnswers[i] = 0; 



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

	  {

             if ( tmpResponse == tmpCorrectAnswers[l] ) 

		{

		   correctAnswers[i] = 1;

		}

	  }



       if ( correctAnswers[i] == 1 ) 

         {

            frame.document.writeln( "<FONT COLOR=\"blue\">Vous avez &eacute;crit </FONT><b>" + Responses[i] );

            frame. document.writeln( "</b><br><FONT COLOR=\"blue\"><i><b>F&eacute;licitations!</b></i></font> " );

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



	    gotitright++;

         }

        else 

         {

            if (Responses[i] == "") 

               {

                   frame.document.writeln("<FONT COLOR=\"red\"><i>Pas de r&eacute;ponse?</i> </FONT><p>");

               }

            else 

               {

                   frame.document.writeln( "<font color=\"red\">Vous avez &eacute;crit </font><b>" + Responses[i] + "</b>" );

                   frame.document.writeln( "<br><FONT COLOR=\"red\">Ce n'est pas la r&eacute;ponse correcte!</FONT><p>" );



               }



//rem rsh 1/31            frame.document.writeln("Vous voulez r&eacute;essayer?<p>");

         }

    } 

      

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



  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) 

{



  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 tmpBuffer = Answers[i];



	frame.document.writeln( (i + 1).toString() + ". " + cleanQuestions[i] + "<br>");



	if ( correctAnswers[i] == 1) 

	   {



	      frame.document.writeln("<FONT COLOR=\"blue\">Vous avez &eacute;crit </FONT><b>" + Responses[i].toString());

	      frame. document.writeln("<i><FONT COLOR=\"blue\"><br> F&eacute;licitations!</font></i></b>");

	      

	   }

	else 

	   {

	      if (Responses[i] == "") 

		 {

		    frame.document.writeln( "<FONT COLOR=\"red\">Pas de r&eacute;ponse? </FONT>" );

		 }

	      else 

		 {

		    frame.document.writeln( "<FONT COLOR=\"red\">Vous avez &eacute;crit </FONT><b>" + Responses[i] + "</b>");

		 }



	      tmpBuffer = tmpBuffer.replace ( /\|/g, "\" </b><font color=\"blue\"><i>ou</i></font><b> \"" );



	      frame.document.writeln( "<br><FONT COLOR=\"blue\">La r&eacute;ponse correcte est </font> \"<b>" + tmpBuffer + "\"</b>" );



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



	   }



	if ( Explanations[i] )

	   frame.document.writeln("<br>" + 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 = numberofQ;



   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>";



//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, " ");



   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 == "transformation" )

       return 1;



    return 0; 



}



// end -->





































