var chrono=null;
var temps=-1;
var couleur_actif2="#CD5C5C";
var couleur_texte2="#FFFFFF";
var couleur_actif='#CD5C5C';
var couleur_texte='#000000';
var couleur_select='#CD5C5C';
var couleur_select='#EEEEEE';


function heure() 
{ 
 temps++; base=temps;
 cs=base % 100;
 base=(temps-cs) / 100;
 s=base % 60;
 m=(base-s) / 60; 
 texte=""; 
 if (m<10) texte=texte+"0"; texte=texte+m+":"; 
 if (s<10) texte=texte+"0"; texte=texte+s;
 window.document.tab.cadran.value=texte; 
} 
function commence() { 
  heure();
 window.document.images['chrono1'].src='../images/interrompre.gif';
 window.document.images['chrono2'].src='../images/arreter.gif';
 window.document.images['chrono1'].onClick='javascript:pause();';
 chrono=setInterval("heure()",10); 
} 

function stoppe() {
 if (chrono!=null) clearInterval(chrono);
 chrono=null;
window.document.images['chrono1'].src='../images/lancer.gif';
window.document.images['chrono2'].src='../images/pixel.gif';
 temps=-1;
 }  
 
function clique() {
 if (chrono==null) commence(); else pause();
} 

function pause()
{
if (chrono!=null) {clearInterval(chrono)}
 window.document.tab.cadran.value=texte;
window.document.images['chrono1'].src='../images/reprendre.gif';
 window.document.images['chrono1'].onClick='javascript:commence();'; 
 chrono=null;
}

//Sauvegarde
    //  Cookie Functions -- "Night of the Living Cookie" Version (25-Jul-96)
    //  Written by:  Bill Dortch, hIdaho Design <bdortch@hidaho.com>
 
function getCookieVal (offset) {
      var endstr = document.cookie.indexOf (";", offset);
      if (endstr == -1)
        endstr = document.cookie.length;
      return unescape(document.cookie.substring(offset, endstr));
    }
    
 
function GetCookie (name) {
      var arg = name + "=";
      var alen = arg.length;
      var clen = document.cookie.length;
      var i = 0;
      while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
          return getCookieVal (j);
    	i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
      }
      return null;
    }

function SetCookie (name,value,expires,path,domain,secure) {
      document.cookie = name + "=" + value+
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
    }
 
 function DeleteCookie (name,path,domain) {
      if (GetCookie(name)) {
        document.cookie = name + "=" +
          ((path) ? "; path=" + path : "") +
          ((domain) ? "; domain=" + domain : "") +
          "; expires=Thu, 01-Jan-70 00:00:01 GMT";
      }
    }
    
    function definirCookie()
{
var coo=document.cookie;
var along=coo.split(";");
var eff=along[0].split("=");
if (along.length>19){ if (confirm('Vous ne pouvez pas enregistrer plus de 20 grilles !\nLa grille '+eff[0]+' sera effacée;'))
					{DeleteCookie (eff[0]);}
					else {return;}}

var maintenant = new Date();
var fin_cookie = new Date(maintenant.getTime() +(365*24*60*60*1000));

var gr=new String();
for(i=0; i<2*places_grille.length; i++){if (window.document.telegrille[i].value==''){gr+='?';}
					else {gr+=window.document.telegrille[i].value;}	

					}
					
SetCookie(num_cookie,gr,fin_cookie);
if (document.cookie) {alert('La grille a été sauvegardée');}
else {alert('Votre navigateur n\'accepte pas les cookies !\nAucune sauvegarde ne peut être réalisée.');}
}


function lireCookie()
{

	if (! GetCookie(num_cookie)) {return}
	
var lit=GetCookie(num_cookie);
for(i=0; i<2*places_grille.length; i++){if(lit.charAt(i)=='?') {window.document.telegrille[i].value='';} 					
					else {window.document.telegrille[i].value=lit.charAt(i);}	
				}
				

}
//D'autres scripts sur http://www.toutjavascript.com
//Si vous utilisez ce script, merci de m'avertir !  < webmaster@toutjavascript.com >
//Auteur original :Olivier Hondermarck  <webmaster@toutjavascript.com>
//Modifs compatibilité Netscape 6/Mozilla : Cédric Lamalle 09/2001 <cedric@cpac.embrapa.br>
//Correction Mac IE5 (Merci Fred)

var IB=new Object;
var posX=0;posY=0;
var xOffset=10;yOffset=10;
function AffBulle(texte) {
  contenu="<TABLE border=0 cellspacing=0 cellpadding="+IB.NbPixel+"><TR bgcolor='"+IB.ColContour+"'><TD><TABLE border=0 cellpadding=2 cellspacing=0 bgcolor='"+IB.ColFond+"'><TR><TD><FONT face='arial' color='"+IB.ColTexte+"'><span style='letter-spacing: 1pt; font-size: 16pt '>"+texte+"</span></FONT></TD></TR></TABLE></TD></TR></TABLE>&nbsp;";
  var finalPosX=posX-xOffset;
  if (finalPosX<0) finalPosX=0;
  if (document.layers) {
    document.layers["bulle"].document.write(contenu);
    document.layers["bulle"].document.close();
    document.layers["bulle"].top=posY+yOffset;
    document.layers["bulle"].left=finalPosX;
    document.layers["bulle"].visibility="show";}
  if (document.all) {
    //var f=window.event;
    //doc=document.body.scrollTop;
    bulle.innerHTML=contenu;
    document.all["bulle"].style.top=posY+yOffset;
    document.all["bulle"].style.left=finalPosX;//f.x-xOffset;
    document.all["bulle"].style.visibility="visible";
  }
  //modif CL 09/2001 - NS6 : celui-ci ne supporte plus document.layers mais document.getElementById
  else if (document.getElementById) {
    document.getElementById("bulle").innerHTML=contenu;
    document.getElementById("bulle").style.top=posY+yOffset;
    document.getElementById("bulle").style.left=finalPosX;
    document.getElementById("bulle").style.visibility="visible";
  }
}
function getMousePos(e) {
  if (document.all) {
  posX=event.x+document.body.scrollLeft; //modifs CL 09/2001 - IE : regrouper l'évènement
  posY=event.y+document.body.scrollTop;
  }
  else {
  posX=e.pageX; //modifs CL 09/2001 - NS6 : celui-ci ne supporte pas e.x et e.y
  posY=e.pageY; 
  }
}
function HideBulle() {
	if (document.layers) {document.layers["bulle"].visibility="hide";}
	if (document.all) {document.all["bulle"].style.visibility="hidden";}
	else if (document.getElementById){document.getElementById("bulle").style.visibility="hidden";}
}

function InitBulle(ColTexte,ColFond,ColContour,NbPixel) {
	IB.ColTexte=ColTexte;IB.ColFond=ColFond;IB.ColContour=ColContour;IB.NbPixel=NbPixel;
	if (document.layers) {
		window.captureEvents(Event.MOUSEMOVE);window.onMouseMove=getMousePos;
		document.write("<LAYER name='bulle' top=0 left=0 visibility='hide'></LAYER>");
	}
	if (document.all) {
		document.write("<DIV id='bulle' style='font-size: 52px ; font-family: arial, verdana, tomaho ; position:absolute;top:0;left:0;visibility:hidden'></DIV>");
		document.onmousemove=getMousePos;
	}
	//modif CL 09/2001 - NS6 : celui-ci ne supporte plus document.layers mais document.getElementById
	else if (document.getElementById) {
	        document.onmousemove=getMousePos;
	        document.write("<DIV id='bulle' style='font-size: 52px ; font-family: arial, verdana, tomaho ;position:absolute;top:0;left:0;visibility:hidden'></DIV>");
	}

}

// InitBulle(couleur de texte, couleur de fond, couleur de contour taille contour)

function aff_def(a)
{
AffBulle("<br>&nbsp;&nbsp;&nbsp;"+def_bulle[a]+"&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;");
}

	
function sol()
	{ 
	for(i=0; i<def.length; i++) {for (j=0; j<def[i].length; j++) {sol_def+=def[i].charAt(j);}}
	if (document.getElementById) 
						{document.getElementById('solution').style.visibility="visible";}
						
	else {alert("D&eacute;sol&eacute;, ce scritpt n&eacute;cessite un navigateur plus r&eacute;cent"); return;}
	
	
	
	for (i=0; i<places_grille.length; i++) {window.document.telegrille[i].value=sol_def.charAt(i);}
	
	}
var sol_def=new String();
function cree_sol_def()
{for (i=0; i<places_grille.length; i++){sol_def+=def[i];}
}
	
function valide()
	{
	var compte=0;
	
	for (i=0; i<places_grille.length; i++) {if (window.document.telegrille[i].value!=sol_def.charAt(i)) { var k=parseInt(places_grille[i])+places_grille.length; window.document.telegrille[k-1].value=''; window.document.telegrille[i].value=''; }
					  else {compte++;}
					}
	if (window.document.telegrille[4].value!='' && compte==places_grille.length) {alert('Bravo !'); }
	
	}
	
	
	
function efface()
	{ 
		 
	if (document.getElementById) 
						{document.getElementById('solution').style.visibility="hidden";}
						
	else {alert("D&eacute;sol&eacute;, ce scritpt n&eacute;cessite un navigateur plus r&eacute;cent"); return;}
	for (i=0; i<2*places_grille.length; i++) {window.document.telegrille[i].value='';}
	window.document.telegrille.A1.focus();
	
}


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 ordre_grille(a,b)
{	for(i=0; i<places_grille.length; i++) {window.document.telegrille[i].style.background=couleur_fond;}
	for(i=a-1; i<b; i++) {window.document.telegrille[i].style.background=couleur_select;}
}


function donner_sol()
{
for(i=0; i<a; i++){for (j=0; j<b; j++){window.document.change[b*i+j].style.background=couleur_case; var t=j+b*i; grille[i][j]=donnee.charAt(t);
if (grille[i][j]!='.') {window.document.change[b*i+j].value=grille[i][j]; window.document.change[b*i+j].style.color=couleur_texte_grille;}
}}
if (commentaires==1) {window.document.images['explic'].src="../images/expl.gif";}
}


function purge()
{
var nombre_justes=0;
for(i=0; i<a; i++){for (j=0; j<b; j++){ if (window.document.change[b*i+j].value==grille[i][j]) {nombre_justes+=1; }}}
if (nombre_justes==nombre_lettres) {init(); alert('Bravo !'); nombre_justes=0;  stoppe(); return}
for(i=0; i<a; i++){for (j=0; j<b; j++){window.document.change[b*i+j].style.background=couleur_case; var t=j+b*i; grille[i][j]=donnee.charAt(t);
if (window.document.change[b*i+j].value!=grille[i][j] && window.document.change[b*i+j].value!='') {window.document.change[b*i+j].value='';}
}}
window.document.change[b*curseur[0]+curseur[1]].value=window.document.change[b*curseur[0]+curseur[1]].value;
}



function efface_mot()
{if (ordre_tab==1) {
var avant=0; var apres=0;
for (k=1; k<curseur[1]+1; k++) {if(grille[curseur[0]][curseur[1]-k]!='.'){avant+=1; } else{break;}};
for (k=1; k<b-curseur[1]; k++) {if(grille[curseur[0]][curseur[1]+k]!='.'){apres+=1; } else{break;}};
for (i=1; i<avant+1; i++) {window.document.change[curseur[0]*b+curseur[1]-i].style.color=couleur_texte_grille;window.document.change[curseur[0]*b+curseur[1]-i].value='';}
for (i=1; i<apres+1; i++) {window.document.change[curseur[0]*b+curseur[1]+i].style.color=couleur_texte_grille;window.document.change[curseur[0]*b+curseur[1]+i].value='';}}

if (ordre_tab==0) {
var dessus=0; var dessous=0;
for (k=1; k<curseur[0]+1; k++) {if(grille[curseur[0]-k][curseur[1]]!='.'){dessus+=1; } else{break;}};
for (k=1; k<a-curseur[0]; k++) {if(grille[curseur[0]+k][curseur[1]]!='.'){dessous+=1; } else{break;}};
for (i=1; i<dessus+1; i++) {window.document.change[curseur[0]*b+curseur[1]-b*i].style.color=couleur_texte_grille;window.document.change[curseur[0]*b+curseur[1]-b*i].value='';}
for (i=1; i<dessous+1; i++) {window.document.change[curseur[0]*b+curseur[1]+i*b].style.color=couleur_texte_grille;window.document.change[curseur[0]*b+curseur[1]+i*b].value='';}}
window.document.change[curseur[0]*b+curseur[1]].style.color=couleur_texte_grille;window.document.change[curseur[0]*b+curseur[1]].value='';
}


var ordre_tab=1;
var nombre_lettres=0;
function ordre_tabulation()
{
if (ordre_tab==0) {ordre_tab=1; mot(); }
else {ordre_tab=0; mot(); }
window.document.change[(curseur[0]*b+curseur[1])%(a*b)].focus();
}



function donne_mot()
{
for(i=0; i<a; i++){for (j=0; j<b; j++){window.document.change[b*i+j].style.background=couleur_case;}}
window.document.change[curseur[0]*b+curseur[1]].style.background=couleur_curseur;
if (ordre_tab==1) {
var avant=0; var apres=0;
for (k=1; k<curseur[1]+1; k++) {if(grille[curseur[0]][curseur[1]-k]!='.'){avant+=1; } else{break;}};
for (k=1; k<b-curseur[1]; k++) {if(grille[curseur[0]][curseur[1]+k]!='.'){apres+=1; } else{break;}};

for (i=1; i<avant+1; i++) {window.document.change[curseur[0]*b+curseur[1]-i].style.background=couleur_mot; window.document.change[curseur[0]*b+curseur[1]-i].value=grille[curseur[0]][[curseur[1]-i]];}
for (i=1; i<apres+1; i++) {window.document.change[curseur[0]*b+curseur[1]+i].style.background=couleur_mot;window.document.change[curseur[0]*b+curseur[1]+i].value=grille[curseur[0]][[curseur[1]+i]];}
window.document.change[curseur[0]*b+curseur[1]].value=grille[curseur[0]][[curseur[1]]]}

if (ordre_tab==0) {
var dessus=0; var dessous=0;
for (k=1; k<curseur[0]+1; k++) {if(grille[curseur[0]-k][curseur[1]]!='.'){dessus+=1; } else{break;}};
for (k=1; k<a-curseur[0]; k++) {if(grille[curseur[0]+k][curseur[1]]!='.'){dessous+=1; } else{break;}};
for (i=1; i<dessus+1; i++) {window.document.change[curseur[0]*b+curseur[1]-b*i].style.background=couleur_mot;window.document.change[curseur[0]*b+curseur[1]-b*i].value=grille[curseur[0]-i][curseur[1]];}
for (i=1; i<dessous+1; i++) {window.document.change[curseur[0]*b+curseur[1]+i*b].style.background=couleur_mot;window.document.change[curseur[0]*b+curseur[1]+b*i].value=grille[curseur[0]+i][curseur[1]];}
window.document.change[curseur[0]*b+curseur[1]].value=grille[curseur[0]][[curseur[1]]];}
}

function donne_lettre()
{window.document.change[curseur[0]*b+curseur[1]].value=grille[curseur[0]][[curseur[1]]];}

var nav;
function init()
{
if (document.layers){ nav="NE";}
if (document.getElementById){nav="NE6";}
if (document.all){nav="IE";}
return(nav);
}


function ordre()
{ 
window.document.change[curseur[0]*b+curseur[1]].value=window.document.change[curseur[0]*b+curseur[1]].value.toUpperCase();
if (ordre_tab==1) 
{
if (curseur[1]!=b-1) {
	if (grille[curseur[0]][(curseur[1]+1)%b]!='.' ){window.document.change[(curseur[0]*b+curseur[1]+1)%(a*b)].focus();}
	if (grille[curseur[0]][(curseur[1]+1)%b]=='.' ){window.document.change[curseur[0]*b+curseur[1]].value=window.document.change[curseur[0]*b+curseur[1]].value.toUpperCase();}
	}
}
if (ordre_tab==0) 
{
if (curseur[0]!=a-1) {
	if (grille[(curseur[0]+1)%a][curseur[1]]!='.' ){window.document.change[(curseur[0]*b+curseur[1]+b)%(a*b)].focus();}
	if (grille[(curseur[0]+1)%a][curseur[1]]=='.' ){window.document.change[curseur[0]*b+curseur[1]].value=window.document.change[curseur[0]*b+curseur[1]].value.toUpperCase();}
	}
}
}

function ecrit_impr()
{
var k=0;
var num=1;
window.document.writeln("");
window.document.writeln("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\">");
window.document.writeln("");
for (i=0; i<long_mot.length; i++)
	{window.document.write("<tr><td bgcolor=\"#C0C0C0\" width=\"20\" height=\"22\" align=\"center\" style=\"border-style: solid; border-width: 1;\"><font font face=\"Arial\" style=\"font-size: 9pt\">");
	window.document.write(alpha.charAt(i));
	window.document.writeln("</font></td>");
	 window.document.writeln("");
	window.document.writeln("<td height=\"22\" align=\"left\" style=\"border:1px solid #000000;\" bgcolor=\"#FFFFFF\"><p style=\"margin-left: 3; margin-right: 3\"><font face=\"Arial\" style=\"font-size: 9pt\">");
	 window.document.writeln(definitions[i]);
	 window.document.writeln("</font></td>");
	 for (j=0; j<parseInt(long_mot[i]); j++)
	
	 	{window.document.write("<td valign=\"top\" style=\"border:1px solid #000000; padding-left: 4; ;\" height=\"22\" width=\"30\"><p  align=\"right\" style=\"text-align: right; margin-right: 1; margin-top: 0pt;\"><font face=\"Arial\"  style=\"font-size: 7pt\">");
	 	window.document.write(places_grille[k]);
	 	window.document.writeln("</td>");
	 	k++;
	 	}
	for (t=parseInt(long_mot[i]); t<long_max; t++) 
		{window.document.writeln("<td bgcolor=\"#C0C0C0\" width=\"30\" height=\"22\" align=\"center\" style=\"border-style: solid; border-width: 1;\"><p style=\"margin-right: 1\">&nbsp;</td>");
		}
		}

window.document.writeln("");
window.document.writeln("</tr></table>");

window.document.writeln("<b><font face=\"Arial\" size=\"2\">");
if(places_grille.length<132) {window.document.write("<br><br>");}
else {window.document.write("<span style=\"vertical-align: +3\">");}
window.document.write("Extrait &agrave; d&eacute;couvrir :</font></b>");
if(places_grille.length<132) {window.document.write("<br><br>");}
window.document.writeln("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");

window.document.write("<td width=\"18\" valign=\"top\" style=\"padding-left: 4; border-color:#000000; ; border-left-style:solid; border-left-width:1px; border-top-style:solid; border-top-width:1px; border-bottom-style:solid; border-bottom-width:1px\" height=\"20\" align=\"left\">");
window.document.write("<span style=\"font-size: 7pt\">");
    window.document.write(echange[0].charAt(0));
    window.document.writeln("</span></td>");
    window.document.writeln("<td width=\"18\" valign=\"top\" style=\"padding-left: 4; border-color:#000000; ; border-right-style:solid; border-right-width:1px; border-top-style:solid; border-top-width:1px; border-bottom-style:solid; border-bottom-width:1px\" height=\"20\" align=\"left\">");
    window.document.write("<p align=\"right\" style=\"margin-left: 2; margin-right: 2\"><span style=\"font-size: 7pt\">");
    window.document.write(1);
	window.document.writeln("</span></td>");
window.document.writeln("");
for (i=0; i<texte1.length-2; i+=2)
	{
	if(num%12==0){
	if (texte1.charAt(i+1)=='.')
	{window.document.write("</tr><tr><td width=\"18\" valign=\"top\" style=\"padding-left: 4; ; border-left-style:solid; border-left-width:3px; border-top-style:solid; border-top-width:1px; border-color:#000000; border-bottom-style:solid; border-bottom-width:1px\" height=\"20\" align=\"left\">");
    window.document.write("<span style=\"font-size: 7pt\">");
    window.document.write(echange[num].charAt(0));
    window.document.writeln("</span></td>");
    window.document.writeln("");
	window.document.write("<td width=\"18\" valign=\"top\" style=\"padding-left: 4; ; border-right-style:solid; border-right-width:1px; border-top-style:solid; border-top-width:1px; border-bottom-style:solid; border-color:#000000; border-bottom-width:1px\" height=\"20\" align=\"left\">");
    window.document.writeln("<p align=\"right\" style=\"margin-left: 2; margin-right: 2\"><span style=\"font-size: 7pt\">");
    window.document.write(num+1);
	window.document.writeln("</span></td>"); num+=1;}
    else{window.document.write("</tr><tr><td width=\"18\" valign=\"top\" style=\"padding-left: 4; ; border-color:#000000; border-left-style:solid; border-left-width:1px; border-top-style:solid; border-top-width:1px; border-bottom-style:solid; border-bottom-width:1px\" height=\"20\" align=\"left\">");
    window.document.write("<span style=\"font-size: 7pt\">");
    window.document.write(echange[num].charAt(0));
    window.document.writeln("</span></td>");
    window.document.writeln("");
	window.document.write("<td width=\"18\" valign=\"top\" style=\"padding-left: 4; padding-right: 4; padding-top: 1; border-color:#000000; padding-bottom: 1; border-right-style:solid; border-right-width:1px; border-top-style:solid; border-top-width:1px; border-bottom-style:solid; border-bottom-width:1px\" height=\"20\" align=\"left\">");
    window.document.writeln("<p align=\"right\" style=\"margin-left: 2; margin-right: 2\"><span style=\"font-size: 7pt\">");
    window.document.write(num+1);
	window.document.writeln("</span></td>"); num+=1;}
	}
else {
	if (texte1.charAt(i+1)=='.')
	{window.document.write("<td width=\"18\" valign=\"top\" style=\"padding-left: 4; ; border-color:#000000; border-left-style:solid; border-left-width:3px; border-top-style:solid; border-top-width:1px; border-bottom-style:solid; border-bottom-width:1px\" height=\"20\" align=\"left\">");
    window.document.write("<span style=\"font-size: 7pt\">");
    window.document.write(echange[num].charAt(0));
    window.document.writeln("</span></td>");
    window.document.writeln("<td width=\"18\" valign=\"top\" style=\"padding-left: 4; ; border-color:#000000; border-right-style:solid; border-right-width:1px; border-top-style:solid; border-top-width:1px; border-bottom-style:solid; border-bottom-width:1px\" height=\"20\" align=\"left\">");
    window.document.write("<p align=\"right\" style=\"margin-left: 2; margin-right: 2\"><span style=\"font-size: 7pt\">");
    window.document.write(num+1);
	window.document.writeln("</span></td>"); num+=1;}
    else {window.document.write("<td width=\"18\" valign=\"top\" style=\"padding-left: 4; ; border-color:#000000; border-left-style:solid; border-left-width:1px; border-top-style:solid; border-top-width:1px; border-bottom-style:solid; border-bottom-width:1px\" height=\"20\" align=\"left\">");
    window.document.write("<span style=\"font-size: 7pt\">");
    window.document.write(echange[num].charAt(0));
    window.document.writeln("</span></td>");
    window.document.writeln("<td width=\"18\" valign=\"top\" style=\"padding-left: 4; ; border-color:#000000; border-right-style:solid; border-right-width:1px; border-top-style:solid; border-top-width:1px; border-bottom-style:solid; border-bottom-width:1px\" height=\"20\" align=\"left\">");
    window.document.write("<p align=\"right\" style=\"margin-left: 2; margin-right: 2\"><span style=\"font-size: 7pt\">");
    window.document.write(num+1);
	window.document.writeln("</span></td>"); num+=1;}}
	}
var z=places_grille.length; 

while(z%24!=0) {window.document.writeln("<td width=\"36\" colspan=\"2\" valign=\"top\" style=\"padding-left: 4; ; border-top-style:solid; border-top-width:0px; border-left-style:solid; border-left-width:0px;\" height=\"20\" align=\"left\" bordercolor=\"#FFFFFF\"><p style=\"margin-left: 2; margin-right: -5\">&nbsp;</td>"); z+=1;}
window.document.writeln("");
window.document.write("</tr>");
window.document.writeln("");
window.document.writeln("</table>");
}

function replace_couleur()
	{ 
		 
	for (i=0; i<2*places_grille.length; i++) {window.document.telegrille[i].style.background=couleur_fond; window.document.telegrille[i].style.color=couleur_texte;}
	
}



function ecrit_extrait()  // Extrait 
{
var num=1;
window.document.writeln("");
window.document.writeln("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#FFFFFF\"><tr>");
window.document.writeln("");
window.document.writeln("<td align=\"center\" colspan=\"10\" bgcolor=\"#FFFFFF\">");
window.document.writeln("<p align=\"left\" style=\"margin-left: 5; margin-bottom:20\"><font face=\"Arial\" size=\"2\" color=\"#000000\">Extrait &agrave; d&eacute;couvrir : </font></td></tr>");
window.document.writeln("");

for (i=0; i<texte1.length-2; i+=2) {
if (num%10==0){
	window.document.writeln("");
if(texte1.charAt(i+1)=='.'){
window.document.write("<td width=\"20\" height=\"20\" align=\"center\" style=\"border-left-style: solid; border-left-width: 1; border-right-style: solid; border-right-width: 3; border-top-style: solid; border-top-width: 1; border-bottom-style: solid; border-bottom-width: 1; border-color:black;  bgcolor=\"#FFFFFF\"><input type=\"text\" maxlength=\"1\" name=\"Tex");
window.document.write(i/2+1);
window.document.write("\" Id=\"Tex");
window.document.write(i/2+1);
window.document.write("\"style=\"font-family:arial; height:20px; width:20px; text-align:center; background:#FFFFFF; color:#000000;  border-style: solid; border-width: 0; font-size:9pt\" value=\"\" onChange=\"javascript:this.value=this.value.toUpperCase(); document.getElementById(echange_java[");
window.document.write(num-1);
window.document.write("]).value=this.value;\" onFocus=\"javascript:replace_couleur(); document.getElementById(echange_java[");
window.document.write(num-1);
window.document.write("]).style.background=couleur_actif; document.getElementById(echange_java[");
window.document.write(num-1);
window.document.write("]).style.color=couleur_texte2; this.style.background=couleur_actif2; this.style.color=couleur_texte2;\"onKeyup=\"javascript:window.document.telegrille.Tex");
window.document.write(i/2+2);
window.document.writeln(".focus();\"></td>"); 
window.document.write("</tr><tr>");
num+=1;}
else{
window.document.write("<td width=\"20\" height=\"20\" align=\"center\" style=\"border: 1px solid #000000; \" bgcolor=\"#FFFFFF\"><input type=\"text\" maxlength=\"1\" name=\"Tex");
window.document.write(i/2+1);
window.document.write("\" Id=\"Tex");
window.document.write(i/2+1);
window.document.write("\"style=\"font-family:arial; height:20px; width:20px; text-align:center; background:#FFFFFF; color:#000000;  border-style: solid; border-width: 0; font-size:9pt\" value=\"\" onChange=\"javascript:this.value=this.value.toUpperCase(); document.getElementById(echange_java[");
window.document.write(num-1);
window.document.write("]).value=this.value;\" onFocus=\"javascript:replace_couleur(); document.getElementById(echange_java[");
window.document.write(num-1);
window.document.write("]).style.background=couleur_actif; document.getElementById(echange_java[");
window.document.write(num-1);
window.document.write("]).style.color=couleur_texte2; this.style.background=couleur_actif2; this.style.color=couleur_texte2;\"onKeyup=\"javascript:window.document.telegrille.Tex");
window.document.write(i/2+2);
window.document.writeln(".focus();\"></td>");
window.document.write("</tr><tr>");
num+=1;
}
}
else {
	if(texte1.charAt(i+1)=='.'){
window.document.write("<td width=\"20\" height=\"20\" align=\"center\" style=\"border-left-style: solid; border-left-width: 1; border-right-style: solid; border-right-width: 3; border-top-style: solid; border-top-width: 1; border-bottom-style: solid; border-bottom-width: 1; border-color:black; border-right-color:black; bgcolor='#ffffff'\"><input type=\"text\" maxlength=\"1\" name=\"Tex");
window.document.write(i/2+1);
window.document.write("\" Id=\"Tex");
window.document.write(i/2+1);
window.document.write("\"style=\"font-family:arial; height:20px; width:20px; text-align:center; background:#FFFFFF; color:#000000;  border-style: solid; border-width: 0; font-size:9pt\" value=\"\" onChange=\"javascript:this.value=this.value.toUpperCase(); document.getElementById(echange_java[");
window.document.write(num-1);
window.document.write("]).value=this.value; \" onFocus=\"javascript:replace_couleur(); document.getElementById(echange_java[");
window.document.write(num-1);
window.document.write("]).style.background=couleur_actif; document.getElementById(echange_java[");
window.document.write(num-1);
window.document.write("]).style.color=couleur_texte2; this.style.background=couleur_actif2; this.style.color=couleur_texte2;\" onKeyup=\"javascript:this.style.background='#FFFFFF'; this.style.color='#000000'; replace_couleur(); window.document.telegrille.Tex");
window.document.write(i/2+2);
window.document.writeln(".focus();\"></td>"); 
num+=1;}
else{
window.document.writeln("");
window.document.write("<td width=\"20\" height=\"20\" align=\"center\" style=\"border: 1px solid #000000; \" bgcolor=\"#FFFFFF\"><input type=\"text\" maxlength=\"1\" name=\"Tex");
window.document.write(i/2+1);
window.document.write("\" Id=\"Tex");
window.document.write(i/2+1);
window.document.write("\"style=\"font-family:arial; height:20px; width:20px; text-align:center; background:#FFFFFF; color:#000000;  border-style: solid; border-width: 0; font-size:9pt\" value=\"\" onChange=\"javascript:this.value=this.value.toUpperCase(); document.getElementById(echange_java[");
window.document.write(num-1);
window.document.write("]).value=this.value;\" onFocus=\"javascript:replace_couleur(); document.getElementById(echange_java[");
window.document.write(num-1);
window.document.write("]).style.background=couleur_actif; document.getElementById(echange_java[");
window.document.write(num-1);
window.document.write("]).style.color=couleur_texte2; this.style.background=couleur_actif2; this.style.color=couleur_texte2;\"onKeyup=\"javascript:window.document.telegrille.Tex");
window.document.write(i/2+2);
window.document.writeln(".focus();\"></td>");
num+=1;}}
}
if ((texte1.length-2)/2%10!=0) {
window.document.write("<td width=\"20\" height=\"20\" align=\"center\" style=\"border: 1px solid #000000; \" bgcolor=\"#FFFFFF\"><input type=\"text\" maxlength=\"1\" name=\"Tex");
window.document.write(texte1.length/2);
window.document.write("\" Id=\"Tex");
window.document.write(texte1.length/2);
window.document.write("\"style=\"font-family:arial; height:20px; width:20px; text-align:center; background:#FFFFFF; color:#000000;  border-style: solid; border-width: 0; font-size:9pt\" value=\"\" onChange=\"javascript:this.value=this.value.toUpperCase(); document.getElementById(echange_java[");
window.document.write(texte1.length/2-1);
window.document.write("]).value=this.value;\" onFocus=\"javascript:replace_couleur(); document.getElementById(echange_java[");
window.document.write(num-1);
window.document.write("]).style.background=couleur_actif; document.getElementById(echange_java[");
window.document.write(num-1);
window.document.write("]).style.color=couleur_texte2; this.style.background=couleur_actif2; this.style.color=couleur_texte2;\"onKeyup=\"javascript:window.document.telegrille.Tex");
window.document.write(1);
window.document.writeln(".focus();\"></td>");}
else { window.document.write("</tr><tr><td width=\"20\" height=\"20\" align=\"center\" style=\"border: 1px solid #000000; \" bgcolor=\"#FFFFFF\"><input type=\"text\" maxlength=\"1\" name=\"Tex");
window.document.write(texte1.length/2);
window.document.write("\" Id=\"Tex");
window.document.write(texte1.length/2);
window.document.write("\"style=\"font-family:arial; height:20px; width:20px; text-align:center; background:#FFFFFF; color:#000000;  border-style: solid; border-width: 0; font-size:9pt\" value=\"\" onChange=\"javascript:this.value=this.value.toUpperCase(); document.getElementById(echange_java[");
window.document.write(texte1.length/2-1);
window.document.write("]).value=this.value;\" onKeyup=\"javascript:window.document.telegrille.Tex");
window.document.write(1);
window.document.writeln(".focus();\"></td>");}
	
var z=texte1.length; 
while(z/2%10!=0) {window.document.writeln("<td width=\"20\" valign=\"top\" style=\"; border-left-style:solid; border-left-width:0px; border-top-style:solid; border-top-width:1px;\" height=\"20\" align=\"left\" bordercolor=\"#FFFFFF\"><p style=\"margin-left: 2; margin-right: -5\">&nbsp;</td>"); z+=2;}
window.document.writeln("");
window.document.writeln("</tr></table>");
}

function ecrit2()   // Grille
{
var k=0;
var amplitude=0;
window.document.writeln("");
window.document.writeln("<table width=\"100%\"border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; border-color:black\">");  
window.document.writeln("");
for (i=0; i<long_mot.length; i++)
	{window.document.writeln("");
	window.document.writeln("<tr><td bgcolor='#CD5C5C'  width=\"20\" height=\"22\" align=\"center\" style=\"border-style: solid; border-width: 1;\"><font font face=\"Arial\" style=\"font-size: 9pt; color:#eeeeee; \">");
	window.document.writeln(alpha.charAt(i));
	window.document.writeln("</font></td>");
	 window.document.writeln("<td height=\"20\" align=\"left\" style=\"border:1px solid #000000;\" bgcolor=\"#FFFFFF\"><p style=\"margin-left: 3; margin-right: 3\"><font face=\"Arial\" style=\"font-size: 9pt\">");
	 window.document.write("<a class=\"blanc\" href=\"javascript:aff_def(");
	 window.document.write(i);
	
	 window.document.writeln(");\" onMouseOut=\"HideBulle()\">");
	 window.document.writeln(definitions[i]);
	 window.document.writeln("</a></td></font></td>");
	 window.document.writeln("");
	 for (j=0; j<parseInt(long_mot[i]); j++)
	
	 	{window.document.write("<td width=\"20\" height=\"20\" align=\"center\" style=\"border:1px solid #000000; \" bgcolor=\"#FFFFFF\">");
		window.document.write("<font color=\"#FFFFFF\" style=\"font-size: 9pt\" face=\"Arial\">");
	 	window.document.write("<input type=\"text\" maxlength=\"1\" name=\"");
	 	window.document.write(alpha.charAt(i));
		window.document.write(j+1);
	 	window.document.write("\" Id=\"");
	 	window.document.write(alpha.charAt(i));
		window.document.write(j+1);
	 	window.document.write("\" style=\"height:21px; width:21px; text-align:center; color:#FFFFFF; background:#FFFFFF; color:#000000;  font-size:9pt; border-style: solid; border-width: 0; \" value=\"\"  onFocus=\"javascript:replace_couleur(); ordre_grille(");
	 	window.document.write(amplitude+1);
	 	window.document.write(",");
	 	window.document.write(amplitude+parseInt(long_mot[i]));
	 	window.document.write("); this.style.background=couleur_actif; this.style.color=couleur_texte2; document.getElementById(echange_java2[");
	 	window.document.write(k);
		window.document.write("]).style.background=couleur_actif2; document.getElementById(echange_java2[");
	 	window.document.write(k);
		window.document.write("]).style.color=couleur_texte2;\" onChange=\"javascript:this.value=this.value.toUpperCase(); document.getElementById(echange_java2[");
	 	window.document.write(k);
		window.document.write("]).value=this.value;\" onKeyup=\"javascript:window.document.telegrille[");
	 	window.document.write(k+1);
	 	window.document.writeln("].focus();\" size=\"20\"></td>");
	 	k++;}
	 	amplitude+=parseInt(long_mot[i]);
	 	
	for (t=parseInt(long_mot[i]); t<long_max; t++) 
		{window.document.writeln("<td bgcolor=\"#C0C0C0\" width=\"19\" height=\"19\" align=\"center\" style=\"border-style: solid; border-width: 1;\"><p style=\"margin-right: 1\">&nbsp;</td>");
		}
		window.document.writeln("<td width=\"19\" height=\"19\" align=\"center\">&nbsp;</td>");
}
window.document.writeln("");
window.document.writeln("</tr></table>");
}


var mots2=new String();
var echange2=new String();
var echange4=new String();
var bulle2=new String();

function sauver()
{
mots2='';

for(i=0; i<def_bulle.length-1; i++) {bulle2+='\''+def_bulle[i]+'\',';}
bulle2+='\''+def_bulle[def_bulle.length-1]+'\');'
window.document.telegrille.T9.value='';


var vide=0;
for (i=0; i<208; i++) {if(window.document.telegrille[i+212].value.length!=0){vide+=1;}}
if (vide==0) {alert('Veuillez placer au moins une lettre'); vide=0; return}
for (i=0; i<208; i++) {etat2[i]=''; etat2[i]=window.document.telegrille[i+212].value;}
var sauve_texte=new String();
for(i=0; i<208;i++) {sauve_texte+=window.document.telegrille[i+4].value;}
var etat3=new String();
for (i=0; i<207; i++) {etat3+='\''+etat2[i]+'\',';}
etat3+='\''+etat2[207]+'\'';
for(i=0; i<417; i++) {echange2+='\''+echange[i]+'\',';}
echange2+='\''+echange[373]+'\'';
var k=0;
var echange3=new Array();
for (i=209; i<417; i++) {if (echange[i].length!=0){echange3[k]=echange[i]; k++;}}

for (i=0; i<echange3.length-1; i++) {echange4+='\''+echange3[i]+'\',';}
echange4+='\''+echange3[echange3.length-1]+'\'';
var t=0;
var mots1=new Array();
for (i=0; i<etat2.length;) {var temporaire=new String(); for(j=0;j<8;j++) {if(etat2[i+j].length!=0) {temporaire+=etat2[i+j].charAt(0);}}
							if(temporaire!=''){mots1[t]+=temporaire; t++; i+=8;}
							else {i+=8;}}

for (i=0; i<mots1.length-1; i++) {var temp=new String(); for (j=9; j<mots1[i].length; j++) {temp+=mots1[i].charAt(j);}
								if (temp!='') {mots2+='\''+temp+'\',';}}
mots2+='\'';
for (j=9; j<mots1[mots1.length-1].length; j++) {mots2+=mots1[mots1.length-1].charAt(j);}
mots2+='\');';

window.document.telegrille.T9.value='texte3+=\"'+sauve_texte+'\";\nvar echange=new Array('+echange2+');\nvar etat=new Array('+etat3+');';
window.document.telegrille.T9.value+='\nvar places_grille=new Array('+echange4+');\nvar def=new Array('+mots2+'\nvar definitions=new Array('+mots2+'\nvar def_bulle=new Array('+mots2+'\n';
return(mots2);}
