
//<![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){
	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 = '#99b3b3';
var NavShadeColor = '#1a3333';
var NavBarColor = '#346767';
var FuncLightColor = '#ffffff';
var FuncShadeColor = '#7f7f7f';
var ExBGColor = '#ffffff';

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 = '#ffffff';
	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 = 'D&#233;sol&#233;! essaie &#224; nouveau!'; 
var AllErrorsFound = 'Tr&#232;s bien!';
var YourScoreIs = 'il te reste';
var BuiltCloze = '';
var ReadingURL = '[ReadingURL]';
var TempReading = '';
var StartTime = (new Date()).toLocaleString();
var HPNStartTime = (new Date()).getTime();
var Finished = false;
var SubmissionTimeout = 30000;
var Score = 0;

var TotWrongChoices = 0;
var ExerciseFinished = false;



var ClozeOpener = '<div class="ExerciseText">';
ClozeOpener += '<form name="Cloze" onsubmit="return false"><p>';

var ClozeCloser = '</p></form></div>';

var ButtonRestart = '';

var ButtonSolution = '';



// FIND-IT ROUTINES :

function BuildExercise(){
	var ClozeStuff = '';

	for (var i=0; i<I.length; i++){
//Add the text
		if (ExerciseFinished){ClozeStuff += Text[i];}
		else{ClozeStuff += '<span style="cursor:default;" onClick="CheckText(false,-1)">' + Text[i] + '</span>';}

//Create and add the gapped text
//If it's already found, then add it in bold/italics:
		if (State[i][0] == 1){
			if (I[i][2].length > 0){ClozeStuff += '<a href="#" onClick="ShowExplanation('+i+')"><span class="CorrectAnswer">' + I[i][1][0][0] + '</span></a>';}
			else{ClozeStuff += '<span class="CorrectAnswer">' + I[i][1][0][0] + '</span>';}
			}
//otherwise get an incorrect item and print it out:		
			else{
				ClozeStuff += '<span style="cursor:default;" onClick="CheckText(true,'+i+')">' + State[i][1] + '</span>';
				}
			}

//Add the last bit
	if (Text.length > I.length){
		if (ExerciseFinished){ClozeStuff += Text[Text.length-1];}
		else{ClozeStuff += '<span style="cursor:default;" onClick="CheckText(false,-1)">' + Text[Text.length-1] + '</span>';}
		}

// crate Button row
	var Buttons = '';
	if (ExerciseFinished){Buttons += ButtonRestart;}else{Buttons += ButtonSolution;}	
	
//Put the final pieces together
	BuiltCloze = ClozeOpener + ClozeStuff + ClozeCloser + Buttons;
}

function ShowExplanation(item){
	WriteFeedback(I[item][2]);
}

function GetWrongItem(Item){
	var RetVal = '';	
	var Tmp = new Array();
	
	for (var x=0; x<(I[Item][1].length-1); x++){
		Tmp[x] = I[Item][1][x+1][0];
		}
	
	var y = Math.floor(Math.random()*Tmp.length);	
	RetVal += Tmp[y];
	return RetVal;
}

// Feedback arrays
CFb = new Array();
IFb = new Array();

function SplitFeedback(){
// the feedback bits should look like feedb1## feedb2## feedb3 etc.
//'Correct' Feedback
	var Tmp = Correct.split('##');
	var y = -1;
	for (var x=0; x<Tmp.length; x++){
		if (TrimString(Tmp[x]) != ''){
			y++;
			CFb[y] = TrimString(Tmp[x]);
			}
		}

//'Incorrect' Feedback
	Tmp = Incorrect.split('##');
	y = -1;
	for (var x=0; x<Tmp.length; x++){
		if (TrimString(Tmp[x]) != ''){
			y++;
			IFb[y] = TrimString(Tmp[x]);
			}
		}
}

function CheckText(bool,item){
// chosen text is wrong:
	if (bool==false){WrongChoice();}
// chosen text is right:
	else{CorrectChoice(item);}
}

function WrongChoice(){
	var Output = GetRandomFeedback(false);
	WriteFeedback(Output);
// penalty
	TotWrongChoices++;
}

function CorrectChoice(item){
// set the state to 'found':
	State[item][0] = 1;

	var Output = '';
// check whether exercise is finished:
// if all errors are found, show final feedback and finish exercise:
	if (CheckExStatus()==true){
		Output += AllErrorsFound;
		ExerciseFinished = true;
		
		CalculateScore();

		Finished = true;
		setTimeout('Finish()', SubmissionTimeout);
		}
// else show number of missing errors:
		else{
			Output += GetRandomFeedback(true) + '<br />' + YourScoreIs + ' ' + GetNumMissingErr();
			}

// build exercise:
	BuildExercise();
	DisplayExercise();
			
// show Feedback:	
	WriteFeedback(Output);
}

function CheckExStatus(){
// checks if all errors have been found or not
	var ExFin = true;
	for (var x=0; x<State.length; x++){
		if (State[x][0] == 0){
			ExFin = false;
			}
		}
	return ExFin; 
}

function GetNumMissingErr(){
// retrieves the number of still 
// missing errors in the text
	var i = 0;
	for (var x=0; x<State.length; x++){
		if (State[x][0] == 0){
			i++;
			}
		}
	return i;
}

function GetRandomFeedback(FType){
	var Stuff = '';
// positive feedback
	if (FType==true){
		var x = Math.floor(Math.random()*CFb.length);
		Stuff = CFb[x];	
		}
// negative feedback
		else{	
 			var x = Math.floor(Math.random()*IFb.length);
			Stuff = IFb[x];
			}
	return Stuff;
}

function CalculateScore(){
	var x = State.length;
	Score = Math.floor((x * 100)/(x + TotWrongChoices));
}




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';
	}
	FDiv.style.display = 'block';
	document.getElementById('FeedbackOKButton').focus();


	RefreshImages();

}

function HideFeedback(){
	document.getElementById('FeedbackContent').innerHTML = '';
	document.getElementById('FeedbackDiv').style.display='none';
	FocusAButton();
	if (Finished == true){
		Finish();
	}
}

function FocusAButton(){
	if (document.getElementById('BtnRestart') != null){
		document.getElementById('BtnRestart').focus();
	}
	else{
		if (document.getElementById('BtnSolution') != null){
			document.getElementById('BtnSolution').focus();
		}
	}
}

function WriteToInstructions(Feedback) {
	Feedback = '<span class="FeedbackText">' + Feedback + '</span>';
	document.getElementById('InstructionsDiv').innerHTML = Feedback;

	RefreshImages();

}


Imgs = new Array();

function PreloadImages(){
	var a = PreloadImages.arguments;
	for (var i=0; i<a.length; i++){
		Imgs[i] = new Image();
		Imgs[i].src = a[i];
	}
}

function RefreshImages(){
	for (var i=0; i<document.images.length; i++){
		if (document.images[i].name.substring(0,6) != 'NavBar'){
			document.images[i].src = document.images[i].src;
		}
	}
}


I = new Array();

I[0] = new Array();
I[0][1] = new Array();
I[0][1][0] = new Array();
I[0][1][0][0]='rentre';
I[0][1][1] = new Array();
I[0][1][1][0]='reviens';
I[0][2]='';

I[1] = new Array();
I[1][1] = new Array();
I[1][1][0] = new Array();
I[1][1][0][0]='\u00E9teins';
I[1][1][1] = new Array();
I[1][1][1][0]='\u00E9veille';
I[1][2]='';

I[2] = new Array();
I[2][1] = new Array();
I[2][1][0] = new Array();
I[2][1][0][0]='m\'apaise';
I[2][1][1] = new Array();
I[2][1][1][0]='me peine';
I[2][2]='';

I[3] = new Array();
I[3][1] = new Array();
I[3][1][0] = new Array();
I[3][1][0][0]='\u00E9loigne';
I[3][1][1] = new Array();
I[3][1][1][0]='approche';
I[3][2]='';

I[4] = new Array();
I[4][1] = new Array();
I[4][1][0] = new Array();
I[4][1][0][0]='entra\u00EEne';
I[4][1][1] = new Array();
I[4][1][1][0]='attire';
I[4][2]='';

I[5] = new Array();
I[5][1] = new Array();
I[5][1][0] = new Array();
I[5][1][0][0]='noie';
I[5][1][1] = new Array();
I[5][1][1][0]='voit';
I[5][2]='';

I[6] = new Array();
I[6][1] = new Array();
I[6][1][0] = new Array();
I[6][1][0][0]='face';
I[6][1][1] = new Array();
I[6][1][1][0]='c\u00F4t\u00E9';
I[6][2]='';

I[7] = new Array();
I[7][1] = new Array();
I[7][1][0] = new Array();
I[7][1][0][0]='descend';
I[7][1][1] = new Array();
I[7][1][1][0]='redescend';
I[7][2]='';

I[8] = new Array();
I[8][1] = new Array();
I[8][1][0] = new Array();
I[8][1][0][0]='fuient';
I[8][1][1] = new Array();
I[8][1][1][0]='quittent';
I[8][2]='';

I[9] = new Array();
I[9][1] = new Array();
I[9][1][0] = new Array();
I[9][1][0][0]='deviens';
I[9][1][1] = new Array();
I[9][1][1][0]='suis';
I[9][2]='';

I[10] = new Array();
I[10][1] = new Array();
I[10][1][0] = new Array();
I[10][1][0][0]='m\'\u00E9loigne';
I[10][1][1] = new Array();
I[10][1][1][0]='me s\u00E9pare';
I[10][2]='';

I[11] = new Array();
I[11][1] = new Array();
I[11][1][0] = new Array();
I[11][1][0][0]='noie';
I[11][1][1] = new Array();
I[11][1][1][0]='voit';
I[11][2]='';

I[12] = new Array();
I[12][1] = new Array();
I[12][1][0] = new Array();
I[12][1][0][0]='fois';
I[12][1][1] = new Array();
I[12][1][1][0]='jour';
I[12][2]='';

I[13] = new Array();
I[13][1] = new Array();
I[13][1][0] = new Array();
I[13][1][0][0]='se moque';
I[13][1][1] = new Array();
I[13][1][1][0]='se fiche';
I[13][2]='';

I[14] = new Array();
I[14][1] = new Array();
I[14][1][0] = new Array();
I[14][1][0][0]='sa loi';
I[14][1][1] = new Array();
I[14][1][1][0]='ses normes';
I[14][2]='';

I[15] = new Array();
I[15][1] = new Array();
I[15][1][0] = new Array();
I[15][1][0][0]='bras';
I[15][1][1] = new Array();
I[15][1][1][0]='mains';
I[15][2]='';

I[16] = new Array();
I[16][1] = new Array();
I[16][1][0] = new Array();
I[16][1][0][0]='retiens';
I[16][1][1] = new Array();
I[16][1][1][0]='arr\u00EAte';
I[16][2]='';


Text = new Array();
Text[0]='Le matin est l\u00E0, je ';
Text[1]=' chez nous<br />Les rayons du soleil quand moi je m\'';
Text[2]=' <br />C\'est comme chaque fois, fatigue et d\u00E9go\u00FBt<br />Et la lumi\u00E8re ';
Text[3]=' enfin<br />C\'est toujours pareil, aucun souvenir<br />La m\u00EAme impression, cette honte de soi<br />Oh toujours pareil, mais \u00E0 chaque fois<br />C\'est la nuit, c\'est la nuit, c\'est la nuit qui m\'';
Text[4]=' de toi<br />C\'est la nuit bien plus forte que moi<br />C\'est la nuit, c\'est la nuit, c\'est la nuit qui m\'';
Text[5]=' et me <br />';
Text[6]=' <br />La nuit c\'est l\'autre ';
Text[7]=' de moi<br />Je voudrais tellement, jurer, te promettre<br />D\'\u00EAtre ce que je suis quand le jour est l\u00E0<br />Un p\u00E8re, un amant mais je cesse de l\'\u00EAtre<br />Quand l\'ombre ';
Text[8]=', j\'oublie ma foi<br />Et je la sens qui vient tout pr\u00E8s me <a href="javascript:alert(\'braver avec un m&eacute;pris moqueur\')">narguer</a><br />Sans la lumi\u00E8re toutes mes forces me ';
Text[9]=' <br />Tes larmes et tes mains ne pourront m\'aider<br />Et je ';
Text[10]=' mon pire ennemi<br />C\'est la nuit, c\'est la nuit, c\'est la nuit qui ';
Text[11]=' de toi<br />C\'est la nuit bien plus forte que moi<br />C\'est la nuit, c\'est la nuit, c\'est la nuit qui m\'entra\u00EEne et me<br />';
Text[12]=' <br />Ma face noire un autre que moi<br />C\'est la nuit, c\'est la nuit, c\'est la nuit qui me prend chaque<br />';
Text[13]=' <br />La nuit qui ';
Text[14]=' bien de moi<br />C\'est la nuit, c\'est la nuit, c\'est la nuit qui m\'impose ';
Text[15]=' <br />Qui nous vole \u00E0 nous, me vole \u00E0 toi<br />C\'est la vie, c\'est l\'envie, c\'est la vie<br />C\'est l\'envie qui m\'arrache \u00E0 tes ';
Text[16]=' <br />La nuit qui m\'attire tant, dis pourquoi?<br />C\'est la nuit, c\'est l\'envie<br />C\'est la nuit qui ne me l\u00E2che pas<br />La nuit qui m\'entra\u00EEne oh ';
Text[17]='-moi';


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);
	}




	PreloadImages('images/khaled.jpg');


	SplitFeedback();
	ExerciseFinished = false;
	TotWrongChoices = 0;

	State.length = 0;
	for (var x=0; x<I.length; x++){
		State[x] = new Array();
		State[x][0] = 0; 				// not found;
		State[x][1] = GetWrongItem(x); 	// word used for that particular gap
		}
	BuildExercise();
	DisplayExercise();




}

// UTILITY ROUTINES:
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 TrimString(InString){
	if (InString.length == 0){return InString;}
		
	var Spaces = '\u0020\u000A\u000D';
	var x = 0;
	
	while (Spaces.indexOf(InString.charAt(0)) > -1){
		InString = InString.substring(1, InString.length);
		}

	while (Spaces.indexOf(InString.charAt(InString.length-1)) > -1){
		InString = InString.substring(0, InString.length-1);
		}

	while (InString.indexOf('  ') > -1){
		x = InString.indexOf('  ');
		InString = InString.substring(0, x) + InString.substring(x+1, InString.length);
		}
		
	return InString;
}


function DisplayExercise(){
	document.getElementById('MainDiv').innerHTML = BuiltCloze;

	RefreshImages();

}


function ShowReading(){
	document.getElementById('ReadingDiv').innerHTML = TempReading;

	RefreshImages();

}







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();
	}
}

//-->

//]]>



