var good;
var participles=new Array()
var match=false;
tobe=new Array()
tobe[tobe.length]="aller"
tobe[tobe.length]="venir"
tobe[tobe.length]="arriver"
tobe[tobe.length]="partir"
tobe[tobe.length]="entrer"
tobe[tobe.length]="sortir"
tobe[tobe.length]="monter"
tobe[tobe.length]="descendre"
tobe[tobe.length]="passer"
tobe[tobe.length]="revenir"
tobe[tobe.length]="retourner"
tobe[tobe.length]="rentrer"
tobe[tobe.length]="tomber"
tobe[tobe.length]="rester"
tobe[tobe.length]="devenir"
tobe[tobe.length]="naître"
tobe[tobe.length]="mourir"
tobe[tobe.length]="s'amuser"
tobe[tobe.length]="s'appeler"
tobe[tobe.length]="se blesser"
tobe[tobe.length]="se brosser"
tobe[tobe.length]="se coucher"
tobe[tobe.length]="se dépêcher"
tobe[tobe.length]="s'endormir"
tobe[tobe.length]="s'ennuyer"
tobe[tobe.length]="se fâcher"
tobe[tobe.length]="s'habiller"
tobe[tobe.length]="se laver"
tobe[tobe.length]="se lever"
tobe[tobe.length]="se porter"
tobe[tobe.length]="se promener"
tobe[tobe.length]="se reposer"
tobe[tobe.length]="se réveiller"
tobe[tobe.length]="se tromper"
tobe[tobe.length]="se trouver"

function setEtre() {
	etre=1;
}
function participle() {
	match=false;
	var thisVerb=document.conjugator.verb.value;
	for (i=0;i<tobe.length;i++) {
		if (thisVerb==tobe[i]) {
			match=true;
		}
	}
	return
}

function writeParticiple() {
	var p=document.conjugator.pronoun.value;
		if (p=="je or j'") {
		participles[0]=solution;
		participles[1]=solution+"e";
	}
	if (p=="tu"){
		participles[0]=solution;
		participles[1]=solution+"e";
	}
	if (p=="il") {
		participles[0]=solution;
	}
	if (p=="elle") {
		participles[0]=solution+"e";
	}
	if (p=="on") {
		participles[0]=solution;
		participles[1]=solution+"e";
	}
	if (p=="nous") {
		participles[0]=solution+"s";
		participles[1]=solution+"es";
	}
	if (p=="vous (plural)") {
		participles[0]=solution+"s";
		participles[1]=solution+"es";
	}
	if (p=="elles") {
		participles[0]=solution+"es";
	}
	if (p=="ils") {
		participles[0]=solution+"s";
	}
		checkParticiple();
}

function checkParticiple() {
	good=false;
	for (i=0;i<participles.length;i++) {
		if (response==participles[i]) {
		good=true;
		}
	}
	notifyParticiple();
}

function notifyParticiple() {
	if (good==true) {
		alert("CORRECT.");
		correct++;
		participles=new Array()		
		howToSelectVerbs();
		return;
	}
	else {
		var notes=new Array();
		for (i=0;i<participles.length;i++) {
			notes[i]=participles[i].toUpperCase();
		}
		if (participles.length>0) {
			note=notes.join(" or ");
  		}
 	else {
 		note=notes[0];
	}
		alert("INCORRECT.\nThe answer is: " + note +"\n\nHaving problems with accents?\nSee the HELP section for instructions.");
		document.conjugator.answer.value="";
		document.conjugator.answer.focus();
	}
}
function randomizeSelectedVerbs() {
	document.conjugator.answer.value="";
	document.conjugator.answer.focus();
 	pronoun=document.conjugator.pronouns.selectedIndex;
    	verb=Math.floor(Math.random()*selectedinfinitive.length);  		document.conjugator.verb.value=selectedinfinitive[verb];
	if (document.conjugator.pronouns.selectedIndex==0) {
		pronoun=Math.floor(Math.random()*20);
	}
	if (pronoun==1 || pronoun==12 || pronoun==14 || pronoun==16) {
		solution=selectedyo[verb];
		document.conjugator.pronoun.value="je or j'";
		}
	if (pronoun==2 || pronoun==13 || pronoun==15 || pronoun==17) {
		solution=selectedtu[verb];
		document.conjugator.pronoun.value="tu";
		}
	if (pronoun==3 || pronoun==11) {
		solution=selectedella[verb];
		document.conjugator.pronoun.value="il";
		}
	if (pronoun==4) {
		solution=selectedella[verb];
		document.conjugator.pronoun.value="elle";
		}
	if (pronoun==5) {
		solution=selectedella[verb];
		document.conjugator.pronoun.value="on";
		}
	if (pronoun==6 || pronoun==18 || pronoun==0) {
		solution=selectednosotros[verb];
		document.conjugator.pronoun.value="nous";
		}
	if (pronoun==7 || pronoun==19 || pronoun==10) {
		solution=selectedvosotros[verb];
		document.conjugator.pronoun.value="vous (plural)";
		}
	if (pronoun==8) {
		solution=selectedellas[verb];
		document.conjugator.pronoun.value="elles";
		}
	if (pronoun==9) {
		solution=selectedellas[verb];
		document.conjugator.pronoun.value="ils";
		}
	if (etre==1) {
		participle();
		}
	return;
}
function randomizeSelectedCommands() {
        document.conjugator.answer.value="";
       	document.conjugator.answer.focus();
        pronoun=document.conjugator.pronouns.selectedIndex;
        verb=Math.floor(Math.random()*selectedinfinitive.length);        	document.conjugator.verb.value=selectedinfinitive[verb];
        if (document.conjugator.pronouns.selectedIndex==0) {
               pronoun=Math.floor(Math.random()*2);
                if (pronoun==0) {
                	solution=selectedpositive[verb];
                	document.conjugator.pronoun.value="positive command";
	                }
                if (pronoun==1) {
                	solution=selectednegative[verb];					document.conjugator.pronoun.value="negative command";
	                }
        	}
                if (document.conjugator.pronouns.selectedIndex==1){
                	solution=selectedpositive[verb];
                	document.conjugator.pronoun.value="positive command";
        	}
        	if (document.conjugator.pronouns.selectedIndex==2) {
                	solution=selectednegative[verb];
                	document.conjugator.pronoun.value="negative command";
        	}
                	return;
}
function randomizeAllVerbs() {
       	document.conjugator.answer.value="";
	document.conjugator.answer.focus();
    	pronoun=document.conjugator.pronouns.selectedIndex;
    	verb=Math.floor(Math.random()*infinitive.length);
	document.conjugator.verb.value=infinitive[verb];
	if (document.conjugator.pronouns.selectedIndex==0) {
		pronoun=Math.floor(Math.random()*20);
	}
	if (pronoun==1 || pronoun==12 || pronoun==14 || pronoun==16) {
		solution=yo[verb];
		document.conjugator.pronoun.value="je or j'";
		}
	if (pronoun==2 || pronoun==13 || pronoun==15 || pronoun==17) {
		solution=tu[verb];
		document.conjugator.pronoun.value="tu";
		}
	if (pronoun==3 || pronoun==11) {
		solution=ella[verb];
		document.conjugator.pronoun.value="il";
		}
	if (pronoun==4) {
		solution=ella[verb];
		document.conjugator.pronoun.value="elle";
		}
	if (pronoun==5) {
		solution=ella[verb];
		document.conjugator.pronoun.value="on";
		}
	if (pronoun==6 || pronoun==18 || pronoun==0) {
		solution=nosotros[verb];
		document.conjugator.pronoun.value="nous";
		}
	if (pronoun==7 || pronoun==19 || pronoun==10) {
		solution=vosotros[verb];
		document.conjugator.pronoun.value="vous (plural)";
		}
	if (pronoun==8) {
		solution=ellas[verb];
		document.conjugator.pronoun.value="elles";
		}
	if (pronoun==9) {
		solution=ellas[verb];
		document.conjugator.pronoun.value="ils";
		}
	if (etre==1) {
		participle();
	}
	return;
}
function randomizeAllCommands() {
        document.conjugator.answer.value="";
        document.conjugator.answer.focus();
         pronoun=document.conjugator.pronouns.selectedIndex;
        verb=Math.floor(Math.random()*infinitive.length);
        document.conjugator.verb.value=infinitive[verb];
            if (document.conjugator.pronouns.selectedIndex==0) {
                pronoun=Math.floor(Math.random()*2);
              if (pronoun==0) {
                solution=positive[verb];
                document.conjugator.pronoun.value="positive command";
                }
                if (pronoun==1) {
                	solution=negative[verb];
                	document.conjugator.pronoun.value="negative command";
   	             }
        	}
              	if (document.conjugator.pronouns.selectedIndex==1){
                	solution=positive[verb];
                	document.conjugator.pronoun.value="positive command";
        		}
        	if (document.conjugator.pronouns.selectedIndex==2) {
                	solution=negative[verb];
                	document.conjugator.pronoun.value="negative command";
        		}
                return;
}

function etreConjugation() {
	match=false;
	lc_endings=new Array('(e)','(e)','(e)','(e)s','(e)s','(e)s');
	
	if (allverbs==0) {
		lc=new Array(yo[verb],tu[verb],ella[verb],nosotros[verb],vosotros[verb],ellas[verb]);
										for(m=0;m<tobe.length;m++) {
		if (infinitive[verb]==tobe[m]) {
			match=true;
		}
	}
	if (match==true) {
		for (j=0;j<lc.length;j++) {
			lc[j]=lc[j]+" "+lc_endings[j];
		}
	}
	alert("je: "+lc[0]+"\n tu: "+lc[1]+"\n il/elle: "+lc[2]+"\n nous: "+lc[3]+"\n vous: "+lc[4]+"\n ils/elles: "+lc[5]);			
document.conjugator.answer.focus();
					}
		else {
lc=new Array(selectedyo[verb],selectedtu[verb],selectedella[verb],selectednosotros[verb],selectedvosotros[verb],selectedellas[verb]);
	for (m=0;m<tobe.length;m++) {
		if (selectedinfinitive[verb]==tobe[m]) {
			match=true;
		}
	}
	
			
	if (match==true) {
		for (j=0;j<lc.length;j++) {
			lc[j]=lc[j]+" "+lc_endings[j];
		}
	}
			alert("je: "+lc[0]+"\n tu: "+lc[1]+"\n il/elle: "+lc[2]+"\n nous: "+lc[3]+"\n vous: "+lc[4]+"\n ils/elles: "+lc[5]);			document.conjugator.answer.focus();
				}
}

function frenchConjugation() {
	if (start==0) {
		alert("You must first press START to begin the practice.");
		}
	else {
		conjugations++;
		if (etre==1) {
			etreConjugation();
			return		}
		if (commands=="yes") {
			frenchConjugationCommands();
												return		
		}
		if (allverbs==0) {
			alert("je: "+yo[verb]+"\n tu: "+tu[verb]+"\n elle: "+ella[verb]+"\n nous: "+nosotros[verb]+"\n vous: "+vosotros[verb]+"\n ils/elles: "+ellas[verb]);		
			document.conjugator.answer.focus();
		}
		else {
		alert("je: " + selectedyo[verb]+ "\n tu: "+selectedtu[verb]+"\n elle: "+selectedella[verb]+"\n nous: "+selectednosotros[verb]+"\n vous: "+selectedvosotros[verb]+"\n ils/elles: "+selectedellas[verb]);		
		document.conjugator.answer.focus();
		}
	}
}
function frenchConjugationCommands() {
        	if (start==0) {
                alert("You must first press START to begin the practice.");
                	}
        	else {
                if (allverbs==0) {
                alert("positive: "+positive[verb]+"\n negative: "+negative[verb]);
	           document.conjugator.answer.focus();
       	         }
                else {
                alert("positive: "+selectedpositive[verb]+"\n negative: "+selectednegative[verb]);
	        document.conjugator.answer.focus();
               			 }
        	}
}

function frenchAccent() {
	warning();
	text=document.conjugator.answer.value;
	if (text.charAt(text.length-1)=="" || text.charAt(text.length-1)==" ") {
		return	
	}
	if (text.charAt(text.length-1)=="a" || text.charAt(text.length-1)=="é" || text.charAt(text.length-1)=="e" || text.charAt(text.length-1)=="ê" || text.charAt(text.length-1)=="è" || text.charAt(text.length-1)=="i" || text.charAt(text.length-1)=="c" || text.charAt(text.length-1)=="u") {
		if (text.charAt(text.length-1)=="a") {
		text=text.substring(0,text.length-1);
		document.conjugator.answer.value=text+"â";
		document.conjugator.answer.focus();
		return		}
		if (text.charAt(text.length-1)=="e") {
		text=text.substring(0,text.length-1);
		document.conjugator.answer.value=text+"é";
		document.conjugator.answer.focus();
		return		}
		if (text.charAt(text.length-1)=="i") {
		text=text.substring(0,text.length-1);
		document.conjugator.answer.value=text+"î";
		document.conjugator.answer.focus();
		return		}
		if (text.charAt(text.length-1)=="c") {
		text=text.substring(0,text.length-1);
		document.conjugator.answer.value=text+"ç";
		document.conjugator.answer.focus();
		return		}
		if (text.charAt(text.length-1)=="u") {
		text=text.substring(0,text.length-1);
		document.conjugator.answer.value=text+"û";
		document.conjugator.answer.focus();
		return		}
		if (text.charAt(text.length-1)=="é") {
		text=text.substring(0,text.length-1);
		document.conjugator.answer.value=text+"è";
		document.conjugator.answer.focus();
		return		}
		if (text.charAt(text.length-1)=="è") {
		text=text.substring(0,text.length-1);
		document.conjugator.answer.value=text+"ê";
		document.conjugator.answer.focus();
		return		}
		if (text.charAt(text.length-1)=="ê") {
		text=text.substring(0,text.length-1);
		document.conjugator.answer.value=text+"é";
		document.conjugator.answer.focus();
		return		}
	}
		else {
		var wrongLetter2=text.charAt(text.length-1);
		var wrongLetter=wrongLetter2.toUpperCase();
		alert("OOPS!\n You tried to put an accent on the letter \""+wrongLetter+"\".");
		document.conjugator.answer.focus();
	}
}
	
	//reset to be if it's a private activity
	if (privateToBe) {
		tobe = new Array();
		for (i=0;i<privateToBe.length;i++) tobe[i] = privateToBe[i];
	}
	