var cent=0 
var sec=0 
var min=0 
var compte=0;
function lance_chrono()
{
cent++; 
if (cent>9){cent=0;sec++} 
if (sec>59){sec=0;min++} 

if (min<10 && sec<10) {document.getElementById('cadran').innerHTML="0"+min+":0"+sec;}
if (min<10 && sec>=10) {document.getElementById('cadran').innerHTML="0"+min+":"+sec;}
if (min>=10 && sec>=10) {document.getElementById('cadran').innerHTML=""+min+":"+sec;}
compte=setTimeout('lance_chrono()',100) //la fonction est relancée tous les 10° de secondes
}

function stoppe_chrono()
{ 
clearTimeout(compte) 
cent=0;
sec=0;
min=0;
if (min<10 && sec<10) {document.getElementById('cadran').innerHTML="0"+min+":0"+sec;}
if (min<10 && sec>=10) {document.getElementById('cadran').innerHTML="0"+min+":"+sec;}
if (min>=10 && sec>=10) {document.getElementById('cadran').innerHTML=""+min+":"+sec;}
}

var dep=0;
var t=0;

var couleur_mot='#006600';
var couleur_base='#EEEEFF';
var couleur_selec='#C0C0C0';
var couleur_fond='#FFFFFF';
var couleur_def;
var couleur_texte_base='#EEEEff';
var couleur_texte_selec='#EEEEFF';
var nbre_coul=new Array();
var ordre=new Array(); 
var bloque=new Array(n*n);
for (i=0; i<n*n; i++) {bloque[i]=0;}
var felicite='C\'est la bonne solution.  Bravo !';
var felicite2="Non ! Ce n\'est pas le bon mot.";   

var mots=new Array();
var mots2=new Array();
var mots_base2=new Array();
for (i=0; i<mots_base.length; i++) {mots2[i]=new String(); for (j=0; j<mots_base[i].length; j++) {if (mots_base[i].charAt(j)!="-") {mots2[i]+=mots_base[i].charAt(j);}}}

var controle=new Array();
for (i=0; i<mots2.length; i++) {controle[i]=0; mots[i]=new String(); for (j=0; j<mots2[i].length-1; j++){mots[i]+=mots2[i].charAt(j);}
									nbre_coul[i]=mots2[i].charAt(mots2[i].length-1);}

for (i=0; i<mots_base.length; i++) {mots_base2[i]=new String(); for (j=0; j<mots_base[i].length-1; j++){mots_base2[i]+=mots_base[i].charAt(j);}}


function donne_calque(a)
	{ var tampon=new String();
		 tampon+=a;
	if (document.getElementById) 
						{document.getElementById(tampon).style.visibility="visible";}
						
	else {alert("D&eacute;sol&eacute;, ce scritpt n&eacute;cessite un navigateur plus r&eacute;cent"); return;}
	}


function enleve_calque(a)
	{ var tampon=new String();
		 tampon+=a;
	if (document.getElementById) 
						{document.getElementById(tampon).style.visibility="hidden";}
						
	else {alert("D&eacute;sol&eacute;, ce scritpt n&eacute;cessite un navigateur plus r&eacute;cent"); return;}
}


function FondCell(a,b){
var nom=new String();
nom+='A'+a+b;
document.getElementById(nom).style.background=couleur_selec;
}



function attribue_coul(a)
{if (nbre_coul[a]==0) {couleur_def='#A9A9A9';}
if (nbre_coul[a]==1) {couleur_def='#E9967A';}
if (nbre_coul[a]==2) {couleur_def='#B0C4DE';}
if (nbre_coul[a]==3) {couleur_def='#778899';}

}

function constr(a)
{

if (dep==0) {return;}
var nom=new String();
nom+='A'+a;
if (bloque[a]==1) {return;}

if (ordre[t-2]==a) {var nom2=new String(); nom2+='A'+ordre[t-1]; document.getElementById(nom2).style.background=couleur_fond; var ordre2=new Array(); for (k=0; k<t-1; k++) {ordre2[k]=ordre[k];}
			ordre=new Array(); for (k=0; k<t-1; k++) {ordre[k]=ordre2[k];} t=t-1; 
			var encoursnew=new String(); for (k=0; k<t; k++) {encoursnew+=texte.charAt(ordre[k]);}
			document.getElementById('encours').innerHTML=encoursnew; return;}

if (t!=0 && !(ordre[t-1]==a-1 || ordre[t-1]==a+1 || ordre[t-1]==a-n || ordre[t-1]==a+n)) {return;}
for (i=0; i<ordre.length; i++) {if (a==ordre[i]) {return;}}
ordre[t]=a;

document.getElementById(nom).style.background=couleur_selec;
document.getElementById(nom).style.color=couleur_texte_selec;

document.getElementById('encours').innerHTML+=texte.charAt(a);;


t+=1;
precede=a;
return t



}
function conversion(a)
{	

	var converti=new String();
	
	switch(a) {
	 case 'â': converti+='A'; break;
	 case 'Â': converti+='A'; break;
	 case 'á': converti+='A'; break;
	 case 'Á': converti+='A'; break;
	 case 'à': converti+='A'; break;
	 case 'À': converti+='A'; break;
	 case 'ã': converti+='A'; break;
	 case 'Ã': converti+='A'; break;
	 case 'é': converti+='E'; break;
	 case 'É': converti+='E'; break;
	 case 'è': converti+='E'; break;
	 case 'È': converti+='E'; break;
	 case 'ê': converti+='E'; break;
	 case 'Ê': converti+='E'; break;
	 case 'ë': converti+='E'; break;
	 case 'Ë': converti+='E'; break;
	 case 'ç': converti+='C'; break;
	 case 'Ç': converti+='C'; break;
	 case 'í': converti+='I;'; break;
	 case 'Í': converti+='I'; break;
	 case 'ì': converti+='I'; break;
	 case 'Ì': converti+='I'; break;
	 case 'î': converti+='I'; break;
	 case 'Î': converti+='I'; break;
	 case 'ï': converti+='I'; break;
	 case 'Ï': converti+='I'; break;
	 case 'ô': converti+='O'; break;
	 case 'Ô': converti+='O'; break;
	 case 'ö': converti+='O'; break;
	 case 'Ö': converti+='O'; break;
	 case 'ù': converti+='U'; break;
	 case 'Ù': converti+='U'; break;
	 case 'û': converti+='U'; break;
	 case 'Û': converti+='U'; break;
	 case 'ü': converti+='U'; break;
	 case 'Ü': converti+='O'; break;
	 
	default: converti+=a; break;}
	
return converti;
}


function valide(a)
{
	if (bloque[a]==1) {return;}
if (dep==0){document.getElementById('encours').innerHTML=''; dep=1; constr(a); return}
var k=0;
var mot=new String();
for (i=0; i<ordre.length; i++) {mot+=texte.charAt(ordre[i]); }
for (i=0; i<mots.length; i++) {if (mot==mots[i]) {attribue_coul(i);  controle[i]=1; var nom2=new String(); nom2+='B'+i; document.getElementById(nom2).style.background=couleur_def;  for (j=0; j<ordre.length; j++) {nom2=new String(); nom2+='A'+ordre[j]; document.getElementById(nom2).style.color=couleur_texte_base; document.getElementById(nom2).style.background=couleur_def; bloque[ordre[j]]=1; k=1;}} }
if (k==0) {for (j=0; j<ordre.length; j++) {var nom2=new String(); nom2+='A'+ordre[j]; document.getElementById(nom2).style.color=couleur_texte_base; document.getElementById(nom2).style.background=couleur_fond;}}

ordre=new Array;
t=0;
dep=0;


}

function valide2()
{
	if (window.document.jeu.mys.value=='') {return;}
	
	var test=window.document.jeu.mys.value;
	var test2=new String();
	for (i=0; i<test.length; i++) {if(test.charAt(i)!=' '){test2+=conversion(test.charAt(i)).toUpperCase();}}
	if (test2==mot_mys) {document.getElementById('encours').innerHTML=felicite;}
else {document.getElementById('encours').innerHTML=felicite2;}

}
	
function efface()
{
for (i=0; i<n*n; i++) {document.getElementById('A'+i).style.background=couleur_fond; bloque[i]=0;}
for (i=0; i<mots.length; i++) {controle[i]=0; document.getElementById('B'+i).style.background=couleur_mot;}
dep=0; t=0;
document.getElementById('encours').innerHTML='';
}

function grille()

{	
	
	if (navigator.appName=="Microsoft Internet Explorer")
	
	{for (i=0; i<n; i++) {	window.document.write("<tr>");
    						
    			for (j=0; j<n; j++) 
    					{
    					
    					 window.document.write("<a class=\"case\" href=\"javascript:{};\"> ");
    					window.document.write("<td id=\"A");
    					 window.document.write(n*i+j);
    					 window.document.write("\" onmouseover=\"javascript:constr(");
    					 window.document.write(n*i+j);
    					  window.document.write("); \"onClick=\"javascript:valide(");
						 window.document.write(n*i+j);
    					 window.document.write(");\" align=\"center\"  width=\"20\" height=\"22\" style=\"font-family:arial; font-size:12px; border: 1px solid #111111;\" style=\" color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write("; padding-left:2; padding-right:2; padding-top:4; padding-bottom:1; background-color:");
    					 window.document.write(couleur_base);
    					 window.document.write("\" ><font color=\"#111111\">");
    					 
    					 window.document.write(texte.charAt(n*i+j));
    					 window.document.write("</td></a>");
    					 }
    					 window.document.writeln("</tr>");
    					 }

}
	
else {	for (i=0; i<n; i++) {	window.document.write("<tr>");
    						
    			for (j=0; j<n; j++) 
    					{
    					
    					 window.document.write("<a class=\"case\" href=\"javascript:{};\"> ");
    					window.document.write("<td id=\"A");
    					 window.document.write(n*i+j);
    					 window.document.write("\" onmouseover=\"javascript:constr(");
    					 window.document.write(n*i+j);
    					  window.document.write("); \"onClick=\"javascript:valide(");
						 window.document.write(n*i+j);
    					 window.document.write(");\" align=\"center\"  width=\"24\" height=\"26\" style=\"font-family:arial; font-size:12px; border: 1px solid #111111;\" style=\" color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write("; padding-left: 4; padding-right: 4; padding-top:4; padding-bottom:1; background-color:");
    					 window.document.write(couleur_base);
    					 window.document.write("\" ><font color=\"#111111\">");
    					 
    					 window.document.write(texte.charAt(n*i+j));
    					 window.document.write("</td></a>");
    					 }
    					 window.document.writeln("</tr>");
    					 }

}
}



function mots_sol()
{window.document.write("</font><font color=\"#EEEEFF\">");
window.document.write(sujet);
	window.document.write("</font></td></tr><tr><td style=\"background-color:#7D3085; border-style: solid; border-width: 1px; padding-left:0px; border-color:#EEEEFF;padding-right:0px; padding-top: 1px; padding-bottom: 1px\"><table cellspacing=\"0\">");
  if (mots.length%2==0) {for (i=0; i<mots.length; ) { 
  					window.document.write("<td style=\"border:0px  height:17; width:17; solid #eeeeff; color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write("; background-color:#7D3085\" width=\"8\">&nbsp;</td><td><td id=\"B");
  					window.document.write(i);
  					window.document.write("\" style=\"border:0px  height:17; width:17; solid #eeeeff; color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write("; font-size:14px; background-color:#7D3085\"><a class=\"case\" href=\"javascript:{};\">");
  					window.document.write(mots_base2[i]);
  					window.document.write("</a></td><td style=\"border:0px  height:17; width:17; solid #eeeeff; color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write("; background-color:#7D3085\" width=\"8\">&nbsp;</td><td  id=\"B");
  					window.document.write(i+1);
  					window.document.write("\" style=\"border:0px  height:17; width:17; solid #eeeeff; color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write("; background-color:#7D3085\"><a class=\"case\"  href=\"javascript:{};\">");
  					window.document.write(mots_base2[i+1]);
  					
					window.document.write("</a></td><td style=\"border:0px  height:17; width:17; solid #eeeeff; color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write(";\" width=\"8\">&nbsp;</td></tr>");
  					i+=2;}}
  else              {for (i=0; i<mots.length-1; ) { 
  					window.document.write("<td style=\"border:0px  height:17; width:17; solid #eeeeff; color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write("; background-color:#7D3085\" width=\"8\">&nbsp;</td><td><td id=\"B");
  					window.document.write(i);
  					window.document.write("\" style=\"border:0px  height:17; width:17; solid #eeeeff; color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write("; font-size:14px; background-color:#7D3085\"><a class=\"case\" href=\"javascript:{};\">");
  					window.document.write(mots_base2[i]);
  					window.document.write("</a></td><td style=\"border:0px  height:17; width:17; solid #eeeeff; color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write("; background-color:#7D3085\" width=\"8\">&nbsp;</td><td  id=\"B");
  					window.document.write(i+1);
  					window.document.write("\" style=\"border:0px  height:17; width:17; solid #eeeeff; color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write("; background-color:#7D3085\"><a class=\"case\"  href=\"javascript:{};\">");
  					window.document.write(mots_base2[i+1]);
  					
					window.document.write("</a></td><td style=\"border:0px  height:17; width:17; solid #eeeeff; color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write(";\" width=\"8\">&nbsp;</td></tr>");
  					i+=2;}
  					window.document.write("<td style=\"border:0px  height:17; width:17; solid #eeeeff; color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write("; background-color:#7D3085\" width=\"8\">&nbsp;</td><td><td id=\"B");
  					window.document.write(mots.length-1);
  					window.document.write("\" style=\"border:0px  height:17; width:17; solid #eeeeff; color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write("; font-size:14px; background-color:#7D3085\"><a class=\"case\" href=\"javascript:{};\">");

  					window.document.write(mots_base2[mots.length-1]);
  					window.document.write("&nbsp;&nbsp;</a></td><td colspan=\"3\" style=\"border:0px  height:17; width:17; solid #eeeeff; color:");
    					 window.document.write(couleur_texte_base);
    					 window.document.write("; background-color:#7D3085\">&nbsp;</td></tr>");
  					}
					window.document.write("</table></td></tr></table>");
					
  
  }
