

//<![CDATA[

<!--

// BrowserCheck Object

function BrowserCheck() {
	var b = navigator.appName;
	this.mac = (navigator.appVersion.indexOf('Mac') != -1);
	if (b=="Netscape") this.b = 'ns';
	else if (b=="Microsoft Internet Explorer") this.b = 'ie';
	else this.b = b;
	this.ns = (this.b == 'ns');
	this.ie = (this.b == 'ie');
	this.version = navigator.appVersion;
	if (this.b == 'ie'){
		var x = this.version.indexOf('MSIE ') + 5;
		var vnum = '';

		while ((this.version.charAt(x) > -1)&&(this.version.charAt(x) < 10)){
			vnum += this.version.charAt(x);
			x++;
		}
		this.v = parseInt(vnum);
	}
	else{
		this.v = parseInt(this.version);
	}
	if (this.ns&&(this.v == 5)){
		this.v = 6;
	}
	this.min = (this.v > 5);
}

is = new BrowserCheck();

if ((is.min == false)||(is.ie5mac)){
	alert('Your browser can\'t handle this page. You need NS6+ or IE6+ on Windows, or NS6+ on Mac.');
}

function PageDim(){
//Get the page width and height
	this.W = 600;
	this.H = 400;
	if (is.ns) this.W = window.innerWidth;
	if (is.ie) this.W = document.body.clientWidth;
	if (is.ns) this.H = window.innerHeight;
	if (is.ie) this.H = document.body.clientHeight;
}

var pg = null;

function SuppressBackspace(e){ 
	 if (is.ns) {
		thisKey = e.keyCode;
	}
	else {
		thisKey = window.event.keyCode;
	}

var Suppress = false;

	if (thisKey == 8) {
		Suppress = true;
	}

	if (Suppress == true){
		if (is.ie){
			window.event.returnValue = false;	
			window.event.cancelBubble = true;
		}
		else{
			e.preventDefault();
		}
	}
}

var NavLightColor = '#7fffbf';
var NavShadeColor = '#007f40';
var NavBarColor = '#00ff80';
var FuncLightColor = '#ffbf7f';
var FuncShadeColor = '#7f4000';
var ExBGColor = '#ff8000';

function NavBtnOver(Btn){
	Btn.style.padding = '1px 3px 3px 1px';
	Btn.style.borderLeftColor = NavLightColor;
	Btn.style.borderTopColor = NavLightColor;
	Btn.style.borderRightColor = NavShadeColor;
	Btn.style.borderBottomColor = NavShadeColor;
}

function NavBtnOut(Btn){
	Btn.style.borderColor = NavBarColor;
	Btn.style.padding = '2px 2px 2px 2px';
}

function NavBtnDown(Btn){
	Btn.style.borderLeftColor = NavShadeColor;
	Btn.style.borderTopColor = NavShadeColor;
	Btn.style.borderRightColor = NavLightColor;
	Btn.style.borderBottomColor = NavLightColor;
	Btn.style.padding = '3px 1px 1px 3px';
}

function FuncBtnOver(Btn){
	Btn.style.padding = '2px 7px 4px 5px';
	Btn.style.borderLeftColor = FuncLightColor;
	Btn.style.borderTopColor = FuncLightColor;
	Btn.style.borderRightColor = FuncShadeColor;
	Btn.style.borderBottomColor = FuncShadeColor;
}

function FuncBtnOut(Btn){
	Btn.style.borderColor = '#ff8000';
	Btn.style.padding = '3px 6px 3px 6px';
}

function FuncBtnDown(Btn){
	Btn.style.borderLeftColor = FuncShadeColor;
	Btn.style.borderTopColor = FuncShadeColor;
	Btn.style.borderRightColor = FuncLightColor;
	Btn.style.borderBottomColor = FuncLightColor;
	Btn.style.padding = '4px 5px 2px 7px';
}

var topZ = 100;

var Correct = 'Tr&#232;s bien!';
var Incorrect = 'Il y a des r&#233;ponses incorrectes. Les r&#233;ponses incorrectes sont rest&#233;es en blanc pour que tu puisses essayer &#224; nouveau. '; 
var GiveHint = 'lettre correcte ajout&#233;e';
var YourScoreIs = 'Ta note est: ';
var BuiltCloze = '';
var ReadingURL = '[ReadingURL]';
var TempReading = '';
var StartTime = (new Date()).toLocaleString();
var HPNStartTime = (new Date()).getTime();
var SubmissionTimeout = 30000;
var Score = 0;
var ExFinished = false;



var ClozeOpener = '<div class="ExerciseText">';
ClozeOpener += '<form name="Cloze" onsubmit="return false"><p>';

var ClozeCloser = '</p></form></div>';

var Buttons = '<button id="[strCheckButtonId]" class="FunctionButton" onfocus="FuncBtnOver(this)" onmouseover="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseout="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOver(this)" onclick="CheckAnswer()">V&#233;rifier</button>';



var ClueButton = '';

ClueButton = '<button style="line-height: 1.0" class="FunctionButton" onfocus="FuncBtnOver(this)" onmouseover="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseout="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOver(this)" onclick="ShowClue([strItemNum])">[?]</button>';



function WriteFeedback(Feedback){
	var Output = Feedback + '<br /><br />';
	document.getElementById('FeedbackContent').innerHTML = Output;
	var FDiv = document.getElementById('FeedbackDiv');
//Calculate and set its left setting
	topZ++;
	FDiv.style.zIndex = topZ;

//Position the feedback div
	pg = new PageDim();
	FDiv.style.left = Math.floor(pg.W/3) + 'px';
	FDiv.style.width = Math.floor(pg.W/3) + 'px';
//Set the top again in case the window has been resized
	if (is.ns){
		FDiv.style.top = Math.floor(pg.H/3) + window.pageYOffset + 'px';
	}
	else{
		FDiv.style.top = Math.floor(pg.H/3) + document.body.scrollTop + 'px';
	}

// IE bug - hide all selectors
	if (is.ie){
		for (var x=0; x<document.getElementsByTagName('select').length; x++){
			document.getElementsByTagName('select')[x].style.display = 'none';
			} 
		}

	FDiv.style.display = 'block';
	document.getElementById('FeedbackOKButton').focus();
	

}

function HideFeedback(){
	document.getElementById('FeedbackContent').innerHTML = '';
	document.getElementById('FeedbackDiv').style.display='none';
	FocusAButton();

// IE bug - show all selectors again
	if (is.ie){
		for (var x=0; x<document.getElementsByTagName('select').length; x++){
			document.getElementsByTagName('select')[x].style.display = 'inline';
			} 
		}
	
	if (ExFinished == true){
		Finish();
	}
}

function FocusAButton(){
	if (document.getElementById('CheckButton1') != null){
		document.getElementById('CheckButton1').focus();
	}
	else{
		if (document.getElementById('CheckButton2') != null){
			document.getElementById('CheckButton2').focus();
		}
/*		else{
			if (document.getElementsByTagName('button')[0] != null){
				document.getElementsByTagName('button')[0].focus();
				}
		}*/
	}
}

function WriteToInstructions(Feedback) {
	Feedback = '<span class="FeedbackText">' + Feedback + '</span>';
	document.getElementById('InstructionsDiv').innerHTML = Feedback;

}

function WriteScore(Feedback) {
	Feedback = '<span class="FeedbackText">' + Feedback + '</span>';
	document.getElementById('ScoreDiv').innerHTML = Feedback;

}



L = new Array();
G = new Array();

I = new Array();

I[0] = new Array();
I[0][1] = new Array();
I[0][1][0] = new Array();
I[0][1][0][0]='sais';
I[0][2]='';

I[1] = new Array();
I[1][1] = new Array();
I[1][1][0] = new Array();
I[1][1][0][0]='sait';
I[1][2]='';

I[2] = new Array();
I[2][1] = new Array();
I[2][1][0] = new Array();
I[2][1][0][0]='savons';
I[2][2]='';

I[3] = new Array();
I[3][1] = new Array();
I[3][1][0] = new Array();
I[3][1][0][0]='Connaissez';
I[3][1][1] = new Array();
I[3][1][1][0]='Savez';
I[3][2]='';

I[4] = new Array();
I[4][1] = new Array();
I[4][1][0] = new Array();
I[4][1][0][0]='savent';
I[4][2]='';

I[5] = new Array();
I[5][1] = new Array();
I[5][1][0] = new Array();
I[5][1][0][0]='connais';
I[5][2]='';

I[6] = new Array();
I[6][1] = new Array();
I[6][1][0] = new Array();
I[6][1][0][0]='conna\u00EEt';
I[6][2]='';

I[7] = new Array();
I[7][1] = new Array();
I[7][1][0] = new Array();
I[7][1][0][0]='connaissons';
I[7][2]='';


Text = new Array();
Text[0]='Je ';
Text[1]=' nager.<br /><br />Il ';
Text[2]=' que deux et deux font trois.<br /><br />Nous ne ';
Text[3]=' pas o\u00F9 il habite.<br /><br />';
Text[4]='-vous la r\u00E9ponse correcte?<br /><br />Ils ne ';
Text[5]=' pas quand leur ami arrivera.<br /><br />Je ';
Text[6]=' un bon restaurant.<br /><br />Il ';
Text[7]=' la France.<br /><br />Nous ';
Text[8]=' son oncle.';


State = new Array();

function StartUp(){
//IE bug avoidance -- remove bottom navbar
	if (is.ie){
		if (document.getElementById('BottomNavBar') != null){
			document.getElementById('TheBody').removeChild(document.getElementById('BottomNavBar'));
		}
	}

	if (is.ie){
		document.attachEvent('onkeydown',SuppressBackspace);
		window.attachEvent('onkeydown',SuppressBackspace);
	}
	else if (is.ns){
		window.addEventListener('keypress',SuppressBackspace,false);
	}





	State.length = 0;
	for (var i=0; i<I.length; i++){
		State[i] = new Array();
		State[i][0] = 0; // already answered correctly		
		State[i][1] = 0; // clue asked for or not
		State[i][2] = 0; // number of wrong answers/tries
		State[i][3] = 0; // score for this item
		}
	
	BuildArrays();
	BuildExercise();
	DisplayExercise();



//Hide the reading stuff
	TempReading = document.getElementById('ReadingDiv').innerHTML;
	document.getElementById('ReadingDiv').innerHTML = '';


}

function BuildExercise(){
	var OutString = '';
	var ClozeStuff = '';

	for (var i=0; i<I.length; i++){
//Add the text
		ClozeStuff += Text[i];

//Create and add the gap
//If it's already right, then add it in bold:
		if (State[i][0] == 1){
			ClozeStuff += '<span class="CorrectAnswer">' + L[i] + '</span>';
			}		
			else{  
				Gap = '<select id="[strGapName]"><option value="">[gaptitle]</option>';
			
				for (var s=0; s<G.length; s++){
					Gap += '<option value="' + EscapeDoubleQuotes(G[s]) + '">' + G[s] + '</option>'; 
					}


				Gap += '</select>';
			
				Gap = ReplaceStuff('[strGapName]', 'Gap' + i, Gap);
				Gap = ReplaceStuff('[gaptitle]', ' ', Gap);
				ClozeStuff += Gap;

//Create and add the clue button
				if (I[i][2].length > 0){
					Btn = ReplaceStuff('[strItemNum]', i + '', ClueButton);
					ClozeStuff += Btn;
					}
				}
		}

//Add the last bit
	if (Text.length > I.length){
		ClozeStuff += Text[Text.length-1];
		}

//Put the final pieces together
	OutString = ClozeOpener + ClozeStuff + ClozeCloser;
	if (ExFinished==false){
		OutString += Buttons;
		}
	BuiltCloze = OutString;
}

function BuildArrays(){
	for (var i=0; i<I.length; i++){
		L[i] = I[i][1][0][0];
		G[i] = I[i][1][0][0];
		}
	Shuffle(G);

}

function Shuffle(InArray){
	Temp = new Array();
	var Len = InArray.length;
	var j = Len;

	for (var i=0; i<Len; i++){
		Temp[i] = InArray[i];
	}

	for (i=0; i<Len; i++){
		Num = Math.floor(j  *  Math.random());
		InArray[i] = Temp[Num];

		for (var k=Num; k < j; k++) {
			Temp[k] = Temp[k+1];
		}
		j--;
	}
	return InArray;
}

function EscapeDoubleQuotes(InString){
	var Result = '';
	for (var i=0; i<InString.length; i++){
		if (InString.charAt(i) == '"'){
			Result += '&quot;';
		}
		else{
			Result += InString.charAt(i);
		}
	}
	return Result;
}

function DisplayExercise(){
	document.getElementById('MainDiv').innerHTML = BuiltCloze;

}

function ShowClue(ItemNum){
	WriteFeedback(I[ItemNum][2]);
}

function ReplaceStuff(Token, Replacement, InString){
	var i = InString.indexOf(Token);
	var FirstBit = '';
	var LastBit = '';
	while (i>-1){
		FirstBit = InString.substring(0, i);
		LastBit = InString.substring(i + Token.length, InString.length);	
		InString = FirstBit + Replacement + LastBit;
		i = InString.indexOf(Token);
	}
	return InString;
}

function CheckAnswer(){
	if (ExFinished==true){return;}
	
	var Output = '';
// check answers	
	for (var i=0; i<I.length; i++){		
		if (State[i][0] != 1){
 			if ((eval('document.Cloze.Gap' + i).value) == L[i]){State[i][0] = 1;}
			else{if ((eval('document.Cloze.Gap' + i).value) != ''){State[i][2]++;}}
			}
		}
// calculate score		
	CalculateScore();
// create feedback	
	ExFinished = CheckExFinished();
	if (ExFinished==true){
		Output = Correct + '<br />' + YourScoreIs + ' ' + Score + ' %';
		}
		else{
			Output = Incorrect + '<br />' + YourScoreIs + ' ' + Score + ' %';
			}	
// compile output		
	BuildExercise();	
	DisplayExercise();
	WriteFeedback(Output);

	if (ExFinished==true){		

		setTimeout('Finish()', SubmissionTimeout);
		}
}



function CalculateScore(){
	var ThisScore = 0;
	for (var x=0; x<State.length; x++){
		if (State[x][0]==1){
			// exercise type 1
			State[x][3] = (1 - (State[x][2] / I[x][1].length));
			
			
			if (State[x][3]<0){State[x][3]=0;}	
			}
		ThisScore += State[x][3];
		}
	Score = Math.floor((ThisScore * 100) / I.length);
}

function CheckExFinished(){
	var Result = true;
	for (var x=0; x<State.length; x++){
		if (State[x][0]==0){Result = false;}
		}
	return Result;
}


function ShowReading(){
	document.getElementById('ReadingDiv').innerHTML = TempReading;

}


//Reading text/timer code
var min
var sec
var ShowReadingAgain = 'Afficher le texte &#224; nouveau';

function DownTime(mm,ss){
	min = mm;
	sec = ss;

	if (sec==0) {
		sec = 60;
		min--;
	}

	sec--;
	if (sec<10){
		sec="0" + sec;
	}

	if (document.TimerForm.face == null){
		return;
	}

	document.TimerForm.face.value= min+":"+sec;
	if ((min==0) && (sec==0)){
		TimesUp()
	}
	else{
		setTimeout('DownTime(min,sec)',1000)
	}
}

function StartReading(){
	Stuff='<form name="TimerForm">Temps restant:';
	Stuff+=' <input type="text" name="face" size="6" value="2:00"></input></form>';
	WriteToTimer(Stuff);
	ShowReading();
	timeoutID=setTimeout('DownTime(2,0)',1000);
}

function TimesUp() {
	if (ShowReadingAgain.length > 0) {
		Stuff='<button class="FunctionButton" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOver(this)" onclick="StartReading(); return false;">Afficher le texte &#224; nouveau</button>';
		WriteToTimer(Stuff);
	}
	WriteToReading('Temps &#233;coul&#233;!');
}

function WriteToReading(Stuff) {
	document.getElementById('ReadingDiv').innerHTML = Stuff;

}

function WriteToTimer(Stuff){
	document.getElementById('TimerDiv').innerHTML = Stuff;
	FocusAButton();

}







function Finish(){
//If there's a form, fill it out and submit it
	if (document.store != null){
		Frm = document.store;
		Frm.starttime.value = HPNStartTime;
		Frm.endtime.value = (new Date()).getTime();
		Frm.mark.value = Score;
		Frm.submit();
	}
}

//-->

//]]>



