////////////////////////////////
// Classe Compteur d'exercice //
function CompteurExo(txtmotscles,idcategorie)
{
	this.Texte=trim(txtmotscles);
	this.SQL='';
	this.Erreur='';

	if ( idcategorie != 0 && this.Texte != '' )
	{
		this.AddErreur('il ne peux y avoir des mots cles ET une categorie dans un compteur.');
	}
	
	var SQL='';
	if ( idcategorie == 0 && this.Texte != '' )
	{
		var MotEnCours='';
		var sousSQL='';
		var EstDansParenthese=0;
		
		for (var i=0;i<this.Texte.length;i++)
		{
			var car=this.Texte.charAt(i);
			
			if ( car != '(' && car != ')' && car != ' ' )
			{
				MotEnCours+=car;
			}
			if ( car == ' ' || i==(this.Texte.length-1) )
			{
				if ( MotEnCours != '' )
				{
					if ( EstDansParenthese == 0 )
					{
						if ( SQL != '' ) { SQL+='OR '; }
						SQL+='(exercices.keywords LIKE \'%,32,'+encodeperso2(MotEnCours)+',32,%\'    ) ';
						MotEnCours='';
					}
					else
					{
						if ( sousSQL != '' ) { sousSQL+='AND '; }
						sousSQL+='(exercices.keywords LIKE \'%,32,'+encodeperso2(MotEnCours)+',32,%\'     ) ';
						MotEnCours='';
					}
				}
			}
			if ( car == '(' )
			{
				if ( EstDansParenthese == 1 )
				{
					this.AddErreur('il ne peut y avoir deux parentheses imbriquees.');
				}
				else
				{
					EstDansParenthese = 1;
				}
			}
			if ( car == ')' )
			{
				if ( EstDansParenthese != 1 )
				{
					this.AddErreur('il y a une parenthese fermante sans ouvrante.');
				}
				else
				{
					if ( trim(MotEnCours) != '' )
					{
						if ( sousSQL != '' ) { sousSQL+='AND '; }
						sousSQL+='(exercices.keywords LIKE \'%,32,'+encodeperso2(MotEnCours)+',32,%\'   ) ';
					}
					MotEnCours='';
					if ( trim(sousSQL) != '' )
					{
						sousSQL='('+sousSQL+') ';
						if ( SQL != '' ) { SQL+='OR '; }
						SQL+=sousSQL;
					}
					sousSQL='';
					EstDansParenthese = 0;
				}
			}
		}
		if ( EstDansParenthese == 1 )
		{
			this.AddErreur('une parenthese est non fermee.');
		}
	}
	else
	{
		if ( idcategorie != 0 && this.Texte == '' )
		{
			SQL='exercices.id_categorie='+idcategorie+' ';
		} 
	}
	this.SQL=SQL;
}
CompteurExo.prototype.AddErreur=function(txt)
{
	if ( this.Erreur == '' ) { this.Erreur=txt; }
}


///////////////////////////////////
// Classe Test placement de mots //
function TestPlacementMots(tmp_texte)
{
	this.Texte = tmp_texte;
	this.NbMotsTrous = 0;
	this.Mot = new Array();
	this.NbMorceauxPhrase=1;
	this.MorceauPhrase = new Array();
	this.Erreur='';
	
	var EstDansReponse = 0;
	
	this.MorceauPhrase[this.NbMorceauxPhrase]='';
	
	for (var i=0;i<this.Texte.length;i++)
	{
		var car=this.Texte.charAt(i);
		
		if ( car == '$' )
		{
			if ( EstDansReponse == 1 )
			{
				EstDansReponse=0;
				this.NbMorceauxPhrase+=1;
				this.MorceauPhrase[this.NbMorceauxPhrase]='';
			}
			else
			{
				EstDansReponse = 1;
				this.NbMotsTrous+=1;
				this.Mot[this.NbMotsTrous]='';
			}
		}
		
		if ( car != '$' )
		{
			if ( EstDansReponse == 1 )
			{
				this.Mot[this.NbMotsTrous]+=car;
			}
			else
			{
				this.MorceauPhrase[this.NbMorceauxPhrase]+=car;
			}
		}
	}
	
	if ( this.NbMotsTrous == 0 )
	{
		this.AddErreur('Aucun trou/mot n\'a ete defini.');
	}

	if ( EstDansReponse == 1 )
	{
		this.AddErreur('Un tag de reponse ($) n\'est pas ferme.');
	}
	
}
TestPlacementMots.prototype.AddErreur=function(txt)
{
	if ( this.Erreur == '' ) { this.Erreur=txt; }
}
TestPlacementMots.prototype.RenvoiePHP=function()
{
	var PHP='';
	
	PHP+='$NbMotsTrous='+this.NbMotsTrous+';';
	PHP+='$Mot = array();';
	PHP+='$MorceauPhrase = array();';
	
	for ( var i=1; i<=this.NbMotsTrous; i++ )
	{
		PHP+='$Mot['+i+']=\\\''+encodeperso2(this.Mot[i])+'\\\';';
	}
	
	for ( var i=1; i<=(this.NbMotsTrous+1); i++ )
	{
		PHP+='$MorceauPhrase['+i+']=\\\''+encodeperso2(this.MorceauPhrase[i])+'\\\';';
	}

	return PHP;
}



////////////////////////////
// Classe Test Reecriture //
function TestReecriture(tmp_texte)
{
	this.Texte=tmp_texte;
	this.Phrase='';
	this.NbSolutions=0;
	this.Solution = new Array();
	this.SolutionLower = new Array();
	this.Erreur='';
	
	var EstDansLeTexte=0;
	var EstDansSolution=0;
	
	for (var i=0;i<this.Texte.length;i++)
	{
		var car=this.Texte.charAt(i);
		
		if ( car == '$' )
		{
			if ( EstDansLeTexte == 0 && EstDansSolution == 0)
			{
				EstDansLeTexte = 1;
			}
			else
			{
				if ( EstDansLeTexte == 1 && EstDansSolution == 0)
				{
					EstDansLeTexte=0;
				}
			}
		}
		
		if ( car == '#' )
		{
			if ( EstDansSolution == 0 && EstDansLeTexte == 0 )
			{
				this.NbSolutions+=1;
				this.Solution[this.NbSolutions]='';
				EstDansSolution=1;
			}
			else
			{
				if ( EstDansSolution == 1 && EstDansLeTexte == 0 )
				{
					EstDansSolution = 0;
				}
			}
		}
		
		if ( car != '$' && car != '#' )
		{
			if ( EstDansLeTexte == 1 && EstDansSolution == 0)
			{
				this.Phrase+=car;
			}
			if ( EstDansLeTexte == 0 && EstDansSolution == 1)
			{
				this.Solution[this.NbSolutions]+=car;
			}
		}

	}
	if ( EstDansLeTexte == 1 )
	{
		this.AddErreur('Le texte d\'aide n\'est pas termine.');
	}
	if ( EstDansSolution == 1 )
	{
		this.AddErreur('Une solution n\'est pas terminee.');
	}
	if ( this.NbSolutions < 1 )
	{
		this.AddErreur('Aucune solution definiee.');
	}
}
TestReecriture.prototype.AddErreur=function(txt)
{
	if ( this.Erreur == '' ) { this.Erreur=txt; }
}
TestReecriture.prototype.RenvoiePHP=function()
{
	var PHP='';
	PHP+='$Phrase=\\\''+encodeperso2(this.Phrase)+'\\\';';
	PHP+='$NbSolutions='+this.NbSolutions+';';
	PHP+='$Reponse = array();';
	PHP+='$Reponse_simplifiee = array();';
	for ( var i=1; i<=this.NbSolutions ; i++ )
	{
		PHP+='$Reponse['+i+']=\\\''+encodeperso2(this.Solution[i])+'\\\';';
		PHP+='$Reponse_simplifiee['+i+']=\\\''+encodeperso2(SupprimeLesPointsDeLaChaine(this.Solution[i].toLowerCase()))+'\\\';';
	}
	return PHP;
}







///////////////////////////////
// Classe Test comprehension //
function TestComprehension(tmp_texte)
{
	this.Texte=tmp_texte;
	this.TextePrincipal='';
	this.NbQuestions=0;
	this.Question = new Array();
	this.NbReponses = new Array();
	this.Erreur='';
	
	var EstDansTextePrincipal=0;
	var EstDansQuestion=0;
	var EstDansTexteReponse=0;
	var EstDansBonneOuMauvaiseReponse=0;
	var parsingok=0;
	for (var i=0;i<this.Texte.length;i++)
	{
		var car=this.Texte.charAt(i);
		parsingok=0;
		
		
		if ( car == '$' && EstDansTextePrincipal == 0 && this.TextePrincipal == '' && parsingok==0 )
		{
			EstDansTextePrincipal = 1;
			parsingok=1;
		}
		if ( car == '$' && EstDansTextePrincipal == 1 && parsingok==0 )
		{
			EstDansTextePrincipal = 0;
			parsingok=1;
		}
		if ( car != '$' && EstDansTextePrincipal == 1 && parsingok==0 )
		{
			this.TextePrincipal+=car;
			parsingok=1;
		}

		
		if ( car == '@' && EstDansQuestion==0 && EstDansTextePrincipal==0 && EstDansTexteReponse == 0 && EstDansBonneOuMauvaiseReponse == 0 && parsingok==0 )
		{
			this.NbQuestions+=1;
			this.Question[this.NbQuestions]='';
			EstDansQuestion=1;
			parsingok=1;
		}
		if ( car == '@' && EstDansQuestion==1 && EstDansTextePrincipal==0 && EstDansTexteReponse == 0 && EstDansBonneOuMauvaiseReponse == 0 && parsingok==0 )
		{
			EstDansQuestion=0;
			this.NbReponses[this.NbQuestions]=0;
			eval('this.Reponse_question_'+this.NbQuestions+' = new Array();');
			eval('this.IsReponseCorrecte_question_'+this.NbQuestions+' = new Array();');
			parsingok=1;
		}
		if ( car != '@' && EstDansQuestion==1 && EstDansTextePrincipal==0 && EstDansTexteReponse == 0 && EstDansBonneOuMauvaiseReponse == 0 && parsingok==0 )
		{
			this.Question[this.NbQuestions]+=car;
			parsingok=1;
		}
		
		
		if ( car == '#' && EstDansTexteReponse == 0 && EstDansBonneOuMauvaiseReponse == 0 && EstDansTextePrincipal==0 && EstDansQuestion==0 && parsingok==0 )
		{
			EstDansTexteReponse = 1;
			this.NbReponses[this.NbQuestions]+=1;
			eval('this.Reponse_question_'+this.NbQuestions+'['+this.NbReponses[this.NbQuestions]+']=\'\';');
			eval('this.IsReponseCorrecte_question_'+this.NbQuestions+'['+this.NbReponses[this.NbQuestions]+']=\'\';');
			parsingok=1;
		}
		if ( car == '#' && EstDansTexteReponse == 1 && EstDansBonneOuMauvaiseReponse == 0 && EstDansTextePrincipal==0 && EstDansQuestion==0 && parsingok==0 )
		{
			EstDansTexteReponse = 0;
			EstDansBonneOuMauvaiseReponse = 1;
			parsingok=1;
		}		
		if ( car == '#' && EstDansTexteReponse == 0 && EstDansBonneOuMauvaiseReponse == 1 && EstDansTextePrincipal==0 && EstDansQuestion==0 && parsingok==0 )
		{
			EstDansTexteReponse = 0;
			EstDansBonneOuMauvaiseReponse = 0;
			parsingok=1;
		}
		if ( car !='#' && EstDansTexteReponse == 1 && EstDansBonneOuMauvaiseReponse == 0 && EstDansTextePrincipal==0 && EstDansQuestion==0 && parsingok==0 )
		{
			eval('this.Reponse_question_'+this.NbQuestions+'['+this.NbReponses[this.NbQuestions]+']+=car;');
			parsingok=1;
		}
		if ( car !='#' && EstDansTexteReponse == 0 && EstDansBonneOuMauvaiseReponse == 1 && EstDansTextePrincipal==0 && EstDansQuestion==0 && parsingok==0 )
		{
			eval('this.IsReponseCorrecte_question_'+this.NbQuestions+'['+this.NbReponses[this.NbQuestions]+']+=car;');
			parsingok=1;
		}		
	}
	
	if ( EstDansTextePrincipal == 1 )
	{
		this.AddErreur('Le tag de fin de texte principal est manquant.');
	}
	if ( EstDansQuestion == 1 )
	{
		this.AddErreur('Un tag de fin de texte de question est manquant.');
	}
	if ( EstDansTexteReponse == 1 )
	{
		this.AddErreur('Un tag de fin de reponse est manquant.');
	}
	if ( EstDansBonneOuMauvaiseReponse == 1 )
	{
		this.AddErreur('Un tag de bonne ou mauvaise reponse est manquant.');
	}
	
	if ( this.NbQuestions == 0 )
	{
		this.AddErreur('Aucune question n\'est definie.');
	}

	for ( var i=1;i<=this.NbQuestions;i++)
	{
		if ( this.NbReponses[i] < 2 )
		{
			this.AddErreur('Le nombre de reponses de la question '+i+' est inferieur a 2');
		}
		var tmpnbbonnerep=0;
		for ( var f=1;f<=this.NbReponses[i];f++ )
		{
			if ( eval('this.IsReponseCorrecte_question_'+i+'['+f+']') == '1' )
				{tmpnbbonnerep+=1;}
			if ( eval('this.IsReponseCorrecte_question_'+i+'['+f+']') != '0' && eval('this.IsReponseCorrecte_question_'+i+'['+f+']') != '1' )
			{
				this.AddErreur('Question '+i+' reponse '+f+' : le chiffre de bonne ou mauvaise reponse est different de 0 ou 1');
			}
		}
		if ( tmpnbbonnerep > 1 )
		{
			this.AddErreur('Question '+i+' : plus d\'une bonne reponse a ete definie');
		}
		if ( tmpnbbonnerep == 0 )
		{
			this.AddErreur('Question '+i+' : aucune bonne reponse n\'a ete definiee');
		}
	}	
	
}
TestComprehension.prototype.AddErreur=function(txt)
{
	if ( this.Erreur == '' ) { this.Erreur=txt; }
}
TestComprehension.prototype.RenvoiePHP=function()
{
	var PHP='';
	PHP+='$TextePrincipal=\\\''+encodeperso2(this.TextePrincipal)+'\\\';';
	PHP+='$NbQuestions='+this.NbQuestions+';';
	PHP+='$Question=array();';
	PHP+='$NbReponses=array();';
	for ( var i=1;i<=this.NbQuestions;i++)
	{
		PHP+='$Question['+i+']=\\\''+encodeperso2(this.Question[i])+'\\\';';
		PHP+='$NbReponses['+i+']='+this.NbReponses[i]+';';
		PHP+='$Reponse_question_'+i+' = array();';
		PHP+='$IsReponseCorrecte_question_'+i+' = array();';
		for ( var f=1;f<=this.NbReponses[i];f++ )
		{
			PHP+='$Reponse_question_'+i+'['+f+']=\\\''+encodeperso2(eval('this.Reponse_question_'+i+'['+f+']'))+'\\\';';
			PHP+='$IsReponseCorrecte_question_'+i+'['+f+']='+eval('this.IsReponseCorrecte_question_'+i+'['+f+']')+';';
		}
	}
	return PHP;
}


///////////////////////////////
// Classe Test Texte melange //
function TexteMelange(tmp_texte)
{
	this.Texte=tmp_texte;
	this.NbParagraphe=0;
	this.paragraphe = new Array();
	this.Erreur='';
	
	
	for (var i=0;i<this.Texte.length;i++)
	{
		var car=this.Texte.charAt(i);
		
		if ( car == '#' )
		{
			this.NbParagraphe+=1;
			this.paragraphe[this.NbParagraphe]='';
		}
		else
		{
			this.paragraphe[this.NbParagraphe]+=car;
		}
	}
	this.NbParagraphe-=1;
	if ( car != '#' )
	{
		this.AddErreur('Le dernier caractere doit etre un #.');
	}
	if ( this.NbParagraphe < 3 )
	{
		this.AddErreur('Le nombre de paragraphes doit etre au moins egal a 3.');
	}
}
TexteMelange.prototype.AddErreur=function(txt)
{
	if ( this.Erreur == '' ) { this.Erreur=txt; }
}
TexteMelange.prototype.RenvoiePHP=function()
{
	var PHP='';
	PHP+='$NbParagraphes='+this.NbParagraphe+';';
	PHP+='$Paragraphe=array();';
	for ( var i=1;i<=this.NbParagraphe;i++)
	{
		PHP+='$Paragraphe['+i+']=\\\''+encodeperso2(this.paragraphe[i])+'\\\';';
	}
	return PHP;
}

/////////////////////////////////
// Classe Test phrase melangee //
function PhraseMelangee(tmp_texte)
{
	this.Texte=tmp_texte;
	this.NbMots=0;
	this.Mot = new Array();
	this.NbSolutions = 0;
	this.Erreur='';
	
	var EstDansMot=0;
	var EstDansSolution=0;
	var NoMotSolution=0;
	var parsingok = 0;
	
	for (var i=0;i<this.Texte.length;i++)
	{
		var car=this.Texte.charAt(i);
		parsingok = 0;
		
		if ( EstDansMot == 1 && car != '$' && parsingok==0 )
		{
			this.Mot[this.NbMots]+= car;
			parsingok = 1;
		}
		if ( EstDansMot == 1 && car == '$' && parsingok==0 )
		{
			EstDansMot=0;
			parsingok = 1;
		}
		if ( EstDansMot == 0 && car == '$' && parsingok==0 )
		{
			EstDansMot=1;
			this.NbMots+=1;
			this.Mot[this.NbMots]='';
			parsingok = 1;
		}
		if ( car == '@' && EstDansMot == 0 && EstDansSolution == 0 && parsingok==0 )
		{
			this.NbSolutions+=1;
			eval('this.Solution_'+this.NbSolutions+'=new Array();');
			NoMotSolution+=1;
			eval('this.Solution_'+this.NbSolutions+'['+NoMotSolution+']=\'\';');
			EstDansSolution = 1;
			parsingok = 1;
		}
		if ( car == '@' && EstDansSolution == 1 && parsingok==0 )
		{
			eval('this.Solution_'+this.NbSolutions+'[0]='+(NoMotSolution)+';');
			NoMotSolution=0;
			EstDansSolution = 0;
			parsingok = 1;
		}
		if ( car != '@' && EstDansSolution == 1 && parsingok==0 )
		{
			if ( car == ',' )
			{
				NoMotSolution+=1;
				eval('this.Solution_'+this.NbSolutions+'['+NoMotSolution+']=\'\';');
			}
			else
			{
				eval('this.Solution_'+this.NbSolutions+'['+NoMotSolution+']+=\''+car+'\';');
			}
			parsingok = 1;
		}
	}
	
	if ( EstDansMot == 1 )
	{
		this.AddErreur('Le tag du dernier mot n\'est pas ferme.');
	}
	if ( EstDansSolution == 1 )
	{
		this.AddErreur('Le tag de la derniere solution n\'est pas ferme.');
	}
	if ( this.NbMots <2 )
	{
		this.AddErreur('Pas assez de mots definis.');
	}
	if ( this.NbSolutions < 1 )
	{
		this.AddErreur('Aucune solution n\'a ete definie.');
	}
	for ( var i=1;i<=this.NbSolutions;i++)
	{
		if ( eval('this.Solution_'+i+'[0] != this.NbMots'))
		{
			this.AddErreur('Le nombre de mots dans la solution '+i+' ne correspond pas au nombre de mots total.');
		}
	}
}
PhraseMelangee.prototype.AddErreur=function(txt)
{
	if ( this.Erreur == '' ) { this.Erreur=txt; }
}
PhraseMelangee.prototype.RenvoiePHP=function()
{
	var PHP='';
	PHP+='$NbMots='+this.NbMots+';';
	PHP+='$NbSolutions='+this.NbSolutions+';';
	PHP+='$Mot=array();';
	for ( var i=1;i<=this.NbMots;i++)
	{
		PHP+='$Mot['+i+']=\\\''+encodeperso2(this.Mot[i])+'\\\';';
	}
	
	for ( var i=1;i<=this.NbSolutions;i++ )
	{
		PHP+='$Solution_'+i+' = array();';
		for ( var f=1;f<=this.NbMots;f++)
		{
			PHP+='$Solution_'+i+'['+f+']='+eval('this.Solution_'+i+'[f]')+';';
		}
	}
	return PHP;
}

////////////////////////
// Classe Test intrus //
function TestIntrus(tmp_texte)
{
	this.Texte=tmp_texte;
	this.NbMotsNormaux=0;
	this.NbMotsIntrus=0;
	this.MotNormal = new Array();
	this.MotIntrus = new Array();
	this.NbMaxChoix='';
	this.Erreur='';
	
	var EstDansMotNormal=0;
	var EstDansMotIntrus=0;
	var EstDansNbMaxChoix=0;
	
	for (var i=0;i<this.Texte.length;i++)
	{
		var car=this.Texte.charAt(i);
		
		if ( car != '$' && car != '#' && car !='@' )
		{
			if ( EstDansMotNormal == 1 )
			{
				this.MotNormal[this.NbMotsNormaux]+=car;
			}
			if ( EstDansMotIntrus == 1 )
			{
				this.MotIntrus[this.NbMotsIntrus]+=car;
			}
			if ( EstDansNbMaxChoix == 1 )
			{
				this.NbMaxChoix+=car;
			}
		}
		if ( car == '$' )
		{
			if ( EstDansMotIntrus == 1 )
			{
				this.AddErreur('Le tag du mot intrus no '+this.NbMotsIntrus+' n\'est pas ferme');
				break;
			}
			if ( EstDansNbMaxChoix == 1 )
			{
				this.AddErreur('Le tag du nb max de choix n\'est pas ferme');
				break;
			}
			if ( EstDansMotNormal == 0 )
			{
				EstDansMotNormal = 1;
				this.NbMotsNormaux+=1;
				this.MotNormal[this.NbMotsNormaux]='';
			}
			else
			{
				EstDansMotNormal = 0;
			}
		}
		if ( car == '#' )
		{
			if ( EstDansMotNormal == 1 )
			{
				this.AddErreur('Le tag du mot normal no '+this.NbMotsNormaux+' n\'est pas ferme');
				break;
			}
			if ( EstDansNbMaxChoix == 1 )
			{
				this.AddErreur('Le tag du nb max de choix n\'est pas ferme');
				break;
			}
			if ( EstDansMotIntrus == 0 )
			{
				EstDansMotIntrus = 1;
				this.NbMotsIntrus+=1;
				this.MotIntrus[this.NbMotsIntrus]='';
			}
			else
			{
				EstDansMotIntrus = 0;
			}
		}
		if ( car == '@' )
		{
			if ( EstDansMotNormal == 1 )
			{
				this.AddErreur('Le tag du mot normal no '+this.NbMotsNormaux+' n\'est pas ferme');
				break;
			}
			if ( EstDansMotIntrus == 1 )
			{
				this.AddErreur('Le tag du mot intrus no '+this.NbMotsIntrus+' n\'est pas ferme');
				break;
			}
			if ( EstDansNbMaxChoix == 0 )
			{
				EstDansNbMaxChoix = 1;
			}
			else
			{
				EstDansNbMaxChoix = 0;
			}
		}
	}
	if ( EstDansMotNormal == 1 )
	{
		this.AddErreur('Le tag du dernier mot normal n\'est pas ferme');
	}
	if ( EstDansMotIntrus == 1 )
	{
		this.AddErreur('Le tag du dernier mot intrus n\'est pas ferme');
	}
	if ( EstDansNbMaxChoix == 1 )
	{
		this.AddErreur('Le tag du nb max de choix n\'est pas ferme');
	}
	if ( this.NbMotsNormaux == 0 )
	{
		this.AddErreur('Aucun mot normal n\'a ete defini');
	}
	if ( this.NbMotsIntrus == 0 )
	{
		this.AddErreur('Aucun mot intrus n\'a ete defini');
	}
	if ( this.NbMaxChoix == '' )
	{
		this.AddErreur('Pas de nb max de choix defini');
	}
}
TestIntrus.prototype.AddErreur=function(txt)
{
	if ( this.Erreur == '' ) { this.Erreur=txt; }
}
TestIntrus.prototype.RenvoiePHP=function()
{
	var PHP='';
	PHP+='$NbMotsNormaux='+this.NbMotsNormaux+';';
	PHP+='$NbMotsIntrus='+this.NbMotsIntrus+';';
	PHP+='$NbMaxChoix='+this.NbMaxChoix+';';
	PHP+='$MotNormal=array();';
	PHP+='$MotIntrus=array();';
	for ( var i=1;i<=this.NbMotsNormaux;i++)
	{
		PHP+='$MotNormal['+i+']=\\\''+encodeperso2(this.MotNormal[i])+'\\\';';
	}
	for ( var i=1;i<=this.NbMotsIntrus;i++)
	{
		PHP+='$MotIntrus['+i+']=\\\''+encodeperso2(this.MotIntrus[i])+'\\\';';
	}
	return PHP;
}





/////////////////////////////
// Classe Test association //
function TestAssociation(tmp_texte)
{
	this.Texte=tmp_texte;
	this.NbCouples=0;
	this.Mot1 = new Array();
	this.Mot2 = new Array();
	this.Erreur='';
	
	var EstDansMot1=0;
	var EstDansMot2=0;
	for (var i=0;i<this.Texte.length;i++)
	{
		var car=this.Texte.charAt(i);

		if ( car != '$' )
		{
			if ( EstDansMot1 == 1 )
			{
				this.Mot1[this.NbCouples]+=car;
			}
			if ( EstDansMot2 == 1 )
			{
				this.Mot2[this.NbCouples]+=car;
			}
		}
		if ( car == '$' )
		{
			if ( EstDansMot1 == 0 && EstDansMot2 == 0 )
			{
				EstDansMot1=1;
				this.NbCouples+=1;
				this.Mot1[this.NbCouples]='';
				this.Mot2[this.NbCouples]='';
			}
			else
			{
				if ( EstDansMot1 == 1 && EstDansMot2 == 0 )
				{
					EstDansMot1=0;
					EstDansMot2=1;
				}
				else
				{
					if ( EstDansMot1 == 0 && EstDansMot2 == 1 )
					{
						EstDansMot2=0;
					}
				}
			}
		}
	}
	if ( EstDansMot1 == 1 )
	{
		this.AddErreur('Le tag du premier mot du couple '+this.NbCouples+' n\'est pas ferme.');
	}
	if ( EstDansMot2 == 1 )
	{
		this.AddErreur('Le tag du deuxieme mot du couple '+this.NbCouples+' n\'est pas ferme.');
	}
	if ( this.NbCouples == 0 )
	{
		this.AddErreur('Aucun couple de mots n\'a ete defini.');
	}
}
TestAssociation.prototype.AddErreur=function(txt)
{
	if ( this.Erreur == '' ) { this.Erreur=txt; }
}
TestAssociation.prototype.RenvoiePHP=function()
{
	var PHP='';
	PHP+='$NbCouples='+this.NbCouples+';';
	PHP+='$Mot1=array();';
	PHP+='$Mot2=array();';
	for ( var i=1;i<=this.NbCouples;i++)
	{
		PHP+='$Mot1['+i+']=\\\''+encodeperso2(this.Mot1[i])+'\\\';';
		PHP+='$Mot2['+i+']=\\\''+encodeperso2(this.Mot2[i])+'\\\';';
	}
	return PHP;
}





////////////////////////////
// Classe Test multichoix //
function TestMultichoix(tmp_texte)
{
	this.Texte=tmp_texte;
	this.UserTexte='';
	this.NbReponses=0;
	this.Reponses = new Array();
	this.BonneReponse = new Array();
	this.NbMaxReponses='';
	this.Erreur ='';
	
	var EstDansProposition=0;
	var EstDansReponse=0;
	var EstDansNbMaxDeReponses=0;
	
	for (var i=0;i<this.Texte.length;i++)
	{
		var car=this.Texte.charAt(i);
		
		if ( car != '$' && car != '@')
		{
			if ( EstDansProposition == 1 )
			{
				this.Reponses[this.NbReponses]+=car;
			}
			if ( EstDansReponse == 1 )
			{
				if ( car == '0' )
				{
					this.BonneReponse[this.NbReponses]=0;
				}
				else
				{
					if ( car == '1' )
					{
						this.BonneReponse[this.NbReponses]=1;
					}
					else
					{
						this.AddErreur('La reponse de la proposition '+this.NbReponses+' est constituee d\'un caractere different de 0 ou 1.');
					}
				}
			}
			if ( EstDansNbMaxDeReponses == 1 )
			{
				this.NbMaxReponses+=car;
			}
			if ( EstDansProposition == 0 && EstDansReponse == 0 && EstDansNbMaxDeReponses == 0 )
			{
				this.UserTexte+=car;
			}
		}

		if ( car == '@' )
		{
			if ( EstDansNbMaxDeReponses == 1 )
			{
				EstDansNbMaxDeReponses = 0;
			}
			else
			{
				EstDansNbMaxDeReponses = 1;
			}
		}

		if ( car == '$' )
		{
			if ( EstDansProposition == 0 && EstDansReponse == 0 )
			{
				EstDansProposition=1;
				this.NbReponses+=1;
				this.Reponses[this.NbReponses]='';
			}
			else
			{
				if ( EstDansProposition == 1 )
				{
					EstDansProposition = 0;
					EstDansReponse = 1;
				}
				else
				{
					if ( EstDansReponse == 1 )
					{
						EstDansReponse = 0;
					}
				}
			}
		}
	}
	if ( EstDansProposition == 1 )
	{
		this.AddErreur('Une proposition n\'est pas fermee et ne dispose pas de reponse.');
	}
	if ( EstDansReponse == 1 )
	{
		this.AddErreur('Une reponse n\'est pas fermee.');
	}
	if ( EstDansNbMaxDeReponses == 1 )
	{
		this.AddErreur('Le tag du nombre maximum de reponses n\'est pas ferme.');
	}
	if ( this.NbReponses == 0 )
	{
		this.AddErreur('Aucune proposition de reponse n\'a ete saisie.');
	}
	if ( this.NbMaxReponses == '' )
	{
		this.AddErreur('Aucun nombre maximum de reponse n\'a ete saisi.');
	}
	
}
TestMultichoix.prototype.AddErreur=function(txt)
{
	if ( this.Erreur == '' ) { this.Erreur=txt; }
}
TestMultichoix.prototype.RenvoiePHP=function()
{
	var PHP='';
	PHP+='$UserTexte=\\\''+encodeperso2(this.UserTexte)+'\\\';';
	PHP+='$NbReponses='+this.NbReponses+';';
	PHP+='$Reponses=array();';
	PHP+='$BonneReponse=array();';
	PHP+='$NbMaxChoix='+this.NbMaxReponses+';';
	for ( var i=1;i<=this.NbReponses;i++)
	{
		PHP+='$Reponses['+i+']=\\\''+encodeperso2(this.Reponses[i])+'\\\';';
		PHP+='$BonneReponse['+i+']='+this.BonneReponse[i]+';';
	}
	return PHP;
}




////////////////////////
// Classe Test a trou //
function TestATrou(tmp_texte)
{
	this.Texte=tmp_texte;
	this.NbTrous=0;
	this.Aide = new Array();
	this.Reponse = new Array();
	this.NbReponses = new Array();
	this.NbElements=0;
	this.TypeElement = new Array();
	this.Element = new Array();
	this.Erreur = '';

	var NoTrou=0;
	var EstDansHelper=0;
	var EstDansReponse=0;
	var EstDansTexteStatique=0;
	for (var i=0;i<this.Texte.length;i++)
	{
		var car=this.Texte.charAt(i);
		
		if ( car != '#' && car != '$' )
		{
			if ( EstDansHelper == 1 )
			{
				this.Aide[this.NbTrous]+=car;
			}
			if ( EstDansReponse == 1 )
			{
				this.Reponse[this.NbTrous][this.NbReponses[this.NbTrous]]+=car;
			}
			if ( EstDansHelper !=1 && EstDansReponse !=1 )
			{
				if ( EstDansTexteStatique != 1 )
				{
					EstDansTexteStatique=1;
					this.NbElements+=1;
					this.TypeElement[this.NbElements]='static';
					this.Element[this.NbElements]='';
				}
				this.Element[this.NbElements]+=car;
			}
		}
		
		if ( car == '$' )
		{
			if ( EstDansHelper == 1 )
			{
				this.AddErreur('Une reponse ($) est imbriquee dans un texte d\'aide (#).');
				break;
			}
			if ( this.NbTrous == 0 )
			{
				this.AddErreur('Une reponse ($) existe mais pas de trou correspondant.');
				break;
			}
			if ( EstDansReponse == 1 )
			{
				EstDansReponse = 0;
			}
			else
			{
				EstDansReponse = 1;
				if ( typeof(this.NbReponses[this.NbTrous]) == 'undefined' ) {this.NbReponses[this.NbTrous]=0; this.Reponse[this.NbTrous] = new Array(); }
				this.NbReponses[this.NbTrous]+=1;
				this.Reponse[this.NbTrous][this.NbReponses[this.NbTrous]]='';
			}
		}
		
		if ( car == '#' )
		{
			if ( EstDansReponse == 1 )
			{
				this.AddErreur('Un texte d\'aide (#) est imbrique dans une reponse ($).');
				break;
			}
			if ( EstDansHelper == 1 )
			{
				EstDansHelper = 0;
			}
			else
			{
				EstDansHelper = 1;
				this.NbTrous+=1;
				this.Aide[this.NbTrous]='';
				EstDansTexteStatique=0;this.NbElements+=1;this.TypeElement[this.NbElements]='trou';this.Element[this.NbElements]=this.NbTrous;
			}
		}
	}
	
	if ( this.Erreur == '' )
	{
		if (EstDansReponse == 1) {this.AddErreur('Une reponse($) n\'est pas finie.');}
		if (EstDansHelper == 1) {this.AddErreur('Un texte d\'aide(#) n\'est pas fini.');}
		if (this.NbTrous == 0) {this.AddErreur('Il n\'y a aucun trou.');}
		
		for ( var i=1;i<=this.NbTrous;i++)
		{
			if ( typeof(this.NbReponses[i]) == 'undefined' )
			{
				this.AddErreur('Le trou no '+i+' n\'a pas de reponse.');
				break;
			}
		}
	}

}
TestATrou.prototype.AddErreur=function(txt)
{
	if ( this.Erreur == '' ) { this.Erreur=txt; }
}
TestATrou.prototype.RenvoiePHP=function()
{
	var PHP='';
	PHP+='$NbTrous='+this.NbTrous+';';
	PHP+='$Aide=array();';
	PHP+='$Reponse=array();';
	PHP+='$Reponse_lower=array();';
	for (var i=1;i<=this.NbTrous;i++)
	{
		PHP+='$Aide['+i+']=\\\''+encodeperso2(this.Aide[i])+'\\\';';
		PHP+='$NbReponses['+i+']='+this.NbReponses[i]+';';
		for(var f=1;f<=this.NbReponses[i];f++)
		{
			PHP+= '$Reponse[' + i + '][' + f + ']=\\\'' + encodeperso2(this.Reponse[i][f]) + '\\\';';
			PHP+= '$Reponse_lower[' + i + '][' + f + ']=\\\'' + encodeperso2(this.Reponse[i][f].toLowerCase()) + '\\\';';
		}
	}
	PHP+='$NbElements='+this.NbElements+';';
	PHP+='$TypeElement=array();';
	PHP+='$Element=array();';
	for (var i=1;i<=this.NbElements;i++)
	{
		PHP+='$TypeElement['+i+']=\\\''+this.TypeElement[i]+'\\\';';
		if ( this.TypeElement[i] == 'static' )
		{
			PHP+='$Element['+i+']=\\\''+encodeperso2(this.Element[i])+'\\\';';
		}
		else
		{
			PHP+='$Element['+i+']=\\\''+this.Element[i]+'\\\';';
		}
	}
	return PHP;
}


/////////////////////////////
// Classe exercice ecoute  //
function ExerciceEcoute(tmp_texte)
{
	this.Texte = tmp_texte;
}
ExerciceEcoute.prototype.RenvoiePHP=function()
{
	var PHP='';
	PHP+='$TexteEcoute=\\\''+encodeperso2(this.Texte)+'\\\';';
	return PHP;
}























function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"").replace(/^　*|　*$/g,"");
}

function TrimInto(str)
{
	var prev_car='';
	var str_return='';
	for (var i=0;i<str.length;i++)
	{
		if ( ( prev_car != ' ' && prev_car != '　' ) || ( str.charAt(i) != ' ' && str.charAt(i) != '　' ) )
		{
			str_return += str.charAt(i);
		}
		prev_car=str.charAt(i);
	}
	return str_return;
}

function RenvoieNoteSurCent(NbRepCorrectes,NbRepTotal)
{
	return Math.floor((100/NbRepTotal)*NbRepCorrectes);
}

function alphaNumericCheck(chaine,ChiffresOk,MinusculesOk,MajusculesOk,UnderscoreOk,PointAutorise)
{
	var ok=true;
	var i=0;
	if ( chaine == '' ) { ok=false; }
	for (i=0;i<chaine.length;i++)
	{
		if (alphaNumCheck(chaine.charCodeAt(i),ChiffresOk,MinusculesOk,MajusculesOk,UnderscoreOk,PointAutorise) == false )
		{
			ok=false;
		}
	}
	return ok;
}
	function alphaNumCheck(theChar,ChiffresOk,MinusculesOk,MajusculesOk,UnderscoreOk,PointAutorise)
	{
		if (
		    (((theChar > 47) && (theChar < 58 )) && ( ChiffresOk == 1 )) ||
		    (((theChar > 96) && (theChar < 123)) && ( MinusculesOk == 1 )) ||
		    (((theChar > 64) && (theChar < 91 )) && ( MajusculesOk == 1 )) ||
		    ( theChar == 95 && UnderscoreOk == 1) ||
		    ( theChar == 46 && PointAutorise == 1 )
		   )
		{return true;}else{return false;}
	}




function encodeperso(LeTexte)
{
	return escape(encodeURI(LeTexte));
}
function decodeperso(LeTexte)
{
	return decodeURI(unescape(LeTexte));
}

function encodeperso2(LeTexte)
{
	var istr=LeTexte;
	var istr2='';
	for (var i=0;i<istr.length;i++)
	{
		if ( i>0 ) { istr2+=','; }
		var thecode=istr.charCodeAt(i);
		// conversion des romanjis minuscules et majuscule de l'alphabet japonais en romanjis courants
		if ( thecode >= 65345 && thecode <= 65370 ) { thecode-=65248; }
		if ( thecode >= 65313 && thecode <= 65370 ) { thecode-=65216; }
		// espace jap
		if ( thecode == 12288 ) { thecode=32; }
		// autres caracteres
		if ( thecode == 12443 ) { thecode=34; }
		if ( thecode == 8217  ) { thecode=39; }
		if ( thecode == 65288 ) { thecode=40; }
		if ( thecode == 65289 ) { thecode=41; }
		if ( thecode == 65285 ) { thecode=37; }
		if ( thecode == 65284 ) { thecode=36; }
		if ( thecode == 65281 ) { thecode=33; }
		if ( thecode == 65306 ) { thecode=58; }
		if ( thecode == 65307 ) { thecode=59; }
		if ( thecode == 12290 ) { thecode=46; }
		if ( thecode == 12289 ) { thecode=44; }
		if ( thecode == 65311 ) { thecode=63; }
		//
		istr2+=thecode;
	}
	istr2=','+istr2+',';
	istr2=istr2.replace(/,13,/g, ',');
	istr2=StrRight(StrLeft(istr2,(istr2.length-1)),istr2.length-2);
	// ci dessus, code residu d'IE6 lors des retours chariots de textaray
	return istr2;
}

function decodeperso2(LeTexte)
{
	if (trim(LeTexte) != '')
	{
		eval('var toto = String.fromCharCode('+LeTexte+');');
	}
	else
	{
		var toto='';
	}
	//toto=toto.replace(/"/g, '&quot;');
	//toto=toto.replace(/"/g, '&acute;');
	//toto=toto.replace(/</g, '&lt;');
	//toto=toto.replace(/>/g, '&gt;');
	//toto=toto.replace(/&/g, '&amp;');
	return toto;
}

function TransformeRetourChariotEnBR(LeTexte)
{
	return LeTexte.replace(/\n/g, '<br>');
}
function TransformeBREnRetourChariot(LeTexte)
{
	return LeTexte.replace(/<br>/g, '\n');
}
function SupprimeRetourChariot(LeTexte)
{
	return LeTexte.replace(/\n/g, ' ');
}

function CheckRadioButton(NomFormulaire,NomRadioButton,Valeur)
{
	for ( var i=0;i<eval('document.'+NomFormulaire+'.' + NomRadioButton + '.length');i++)
	{
		if ( eval('document.'+NomFormulaire+'.' + NomRadioButton + '[' + i + '].value == \'' + Valeur + '\'' ) )
		{
			eval('document.'+NomFormulaire+'.' + NomRadioButton + '[\'' + i + '\'].checked = true;');
		}
	}
}
	
function RetourneValeurRadioButton(NomFormulaire,NomRadioButton)
{
	eval('NbCases=document.'+NomFormulaire+'.' + NomRadioButton + '.length;');
	var ValeurRetournee="";
	for (var i=0;i<=(NbCases-1);i++)
	{
		if (eval('document.'+NomFormulaire+'.' + NomRadioButton + '[i].checked')==true)
		{
			ValeurRetournee=eval('document.'+NomFormulaire+'.' + NomRadioButton + '[i].value');
		}
	}
	return ValeurRetournee;
}

function VideFckEditor(NomInstance)
{
	FCKeditorAPI.GetInstance(NomInstance).SetHTML('');
}

function TrueFalseVersInt(valeur)
{
	if ( valeur == true || valeur == 'true' )
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

function IntVersTrueFalse(valeur)
{
	if ( valeur == 1 || valeur == '1' ){return true;} else {return false;}
}

function AfficheCours(IdCours)
{
	var HtmlStr='';
	HtmlStr+='<form id="form_general" name="form_general" method="post" action="cours.php">';
	HtmlStr+='<input type="hidden" id="OperationPhp" name="OperationPhp" value="LireCours">';
	HtmlStr+='<input type="hidden" id="IdCours" name="IdCours" value="'+IdCours+'">';
	HtmlStr+='</form>';
	document.getElementById('div_de_form').innerHTML=HtmlStr;
	document.getElementById('form_general').submit();
}

function SupprimeLesPointsDeLaChaine(lachaine)
{
	var chainefinale='';
	for (var i=0;i<lachaine.length;i++)
	{
		var car=lachaine.charAt(i);
		if ( car != '.' && car != ',' && car != '。' && car != '、' )
		{
			chainefinale+=car;
		}
		else
		{
			chainefinale+=' ';
		}
	}
	return chainefinale;
}

function verif_validite_mail(email) { // vérif validité email par STRING
   var arobase = email.indexOf("@")
   var point = email.lastIndexOf(".")
   if((arobase < 3)||(point + 2 > email.length)
      ||(point < arobase+3)) return false
   return true
}

function ClicSurModule(IdModule)
{
	var HtmlStr='';
	HtmlStr+='<form id="form_general" name="form_general" method="post" action="module.php">';
	HtmlStr+='<input type="hidden" id="IdModule" name="IdModule" value="'+IdModule+'">';
	HtmlStr+='</form>';
	document.getElementById('div_de_form').innerHTML=HtmlStr;
	document.getElementById('form_general').submit();
}

function StrLeft(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function StrRight(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function ecritcookie(nom,texte,jours)
{
	var datecourante=new Date();
	var expires=new Date();
	expires.setTime(datecourante.getTime()+1000*60*60*24*jours);
	if ( jours != 0 )
	{
		document.cookie=nom+'='+escape(texte)+'; expires='+expires.toGMTString();
	}
	else
	{
		document.cookie=nom+'='+escape(texte);
	}
}

function donnecookie(nom)
{
	var recherche=nom+'=';
	if (document.cookie.length>0)
	{
		position=document.cookie.indexOf(recherche);
		if (position!=-1)
		{
			position=position+recherche.length;
			fin=document.cookie.indexOf(';',position);
			if (fin==-1)
			{
				fin=document.cookie.length;
			}
			return unescape(document.cookie.substring(position,fin));
		}
		else {return '';}
	}
	else {return '';}
}

function DissocieTitresExos(iletitre,iisencode,ilanguearetourner,iretournedecode)
{
	if ( iisencode == 1 )
	{
		var tempnom=decodeperso2(iletitre);
	}
	else
	{
		var tempnom=iletitre;
	}
	
	if ( tempnom.indexOf('/') != -1 && tempnom.indexOf('/') != Boolean(false) )
	{
		var tempnomfr=tempnom.substr(0,tempnom.indexOf('/'));
		var tempnomjp=tempnom.substr(tempnom.indexOf('/')+1,tempnom.length-tempnom.indexOf('/'));
	}
	else
	{
		var tempnomfr=tempnom;
		var tempnomjp=tempnom;
	}
	var toreturn = ''
	if ( ilanguearetourner == 'fr' )
	{
		toreturn = tempnomfr;
	}
	if ( ilanguearetourner == 'jp' )
	{
		toreturn = tempnomjp;
	}
	if ( iretournedecode != 1 )
	{
		toreturn=encodeperso2(toreturn);
	}
	return toreturn;
}

function ReturnTimeUid()
{
	var Stamp = new Date();
	var ii = Stamp.getYear() + '_' + Stamp.getMonth() + '_' + Stamp.getDate() + '_' + Stamp.getHours() + '_' + Stamp.getMinutes();
	return ii;
}

function GetDeltaXResize()
{
	if (document.body)
	{
		var window_width = (document.body.clientWidth);
	} 
	else
	{
		var window_width = (window.innerWidth);
	}
	var posx=0;
	if ( window_width > 1024 )
	{
		posx=(window_width-1024)/2;
	}
	return posx;
}