l=0
img="a"
coups=0


function suivante(){

lettre=new Array()
l++
if(l==3){l=0}

lettre[0]="a"
lettre[1]="b"
lettre[2]="c"

img=lettre[l]
trier()
coups=0
document.taquin.coup.value=coups
alert("image n° : "+(l+1))

coups=0
document.taquin.coup.value=coups

}

function redir(num){
if (num==1){
 but1()}
if (num==2){
 but2()}
if (num==3){
 but3()}
if (num==4){
 but4()}
if (num==5){
 but5()}
if (num==6){
 but6()}
if (num==7){
 but7()}
if (num==8){
 but8()}
if (num==9){
 but9()}
coups++
document.taquin.coup.value=coups

}


function but1(){
if(bt2.value==" 0 "){
  bt2.value=bt1.value
  bt1.value=" 0 "
  bt2.src=bt1.src
  bt1.src="rien.gif"
}  
if(bt4.value==" 0 "){
  bt4.value=bt1.value
  bt1.value=" 0 "
  bt4.src=bt1.src
  bt1.src="rien.gif"
}  
verif()
}

function but2(){
if(bt1.value==" 0 "){
  bt1.value=bt2.value
  bt2.value=" 0 "
  bt1.src=bt2.src
  bt2.src="rien.gif"
}  
if(bt3.value==" 0 "){
  bt3.value=bt2.value
  bt2.value=" 0 "
  bt3.src=bt2.src
  bt2.src="rien.gif"
}  
if(bt5.value==" 0 "){
  bt5.value=bt2.value
  bt2.value=" 0 "
  bt5.src=bt2.src
  bt2.src="rien.gif"
}  
verif()
}

function but3(){
if(bt2.value==" 0 "){
  bt2.value=bt3.value
  bt3.value=" 0 "
  bt2.src=bt3.src
  bt3.src="rien.gif"
}  
if(bt6.value==" 0 "){
  bt6.value=bt3.value
  bt3.value=" 0 "
  bt6.src=bt3.src
  bt3.src="rien.gif"
}  
verif()
}

function but4(){
if(bt1.value==" 0 "){
  bt1.value=bt4.value
  bt4.value=" 0 "
  bt1.src=bt4.src
  bt4.src="rien.gif"
}  
if(bt5.value==" 0 "){
  bt5.value=bt4.value
  bt4.value=" 0 "
  bt5.src=bt4.src
  bt4.src="rien.gif"
} 
if(bt7.value==" 0 "){
  bt7.value=bt4.value
  bt4.value=" 0 "
  bt7.src=bt4.src
  bt4.src="rien.gif"
}  
verif()
}

function but5(){
if(bt2.value==" 0 "){
  bt2.value=bt5.value
  bt5.value=" 0 "
  bt2.src=bt5.src
  bt5.src="rien.gif"
}  
if(bt4.value==" 0 "){
  bt4.value=bt5.value
  bt5.value=" 0 "
  bt4.src=bt5.src
  bt5.src="rien.gif"
}  
if(bt6.value==" 0 "){
  bt6.value=bt5.value
  bt5.value=" 0 "
  bt6.src=bt5.src
  bt5.src="rien.gif"
}  
if(bt8.value==" 0 "){
  bt8.value=bt5.value
  bt5.value=" 0 "
  bt8.src=bt5.src
  bt5.src="rien.gif"
}  
verif()
}

function but6(){
if(bt9.value==" 0 "){
  bt9.value=bt6.value
  bt6.value=" 0 "
  bt9.src=bt6.src
  bt6.src="rien.gif"
}  
if(bt3.value==" 0 "){
  bt3.value=bt6.value
  bt6.value=" 0 "
  bt3.src=bt6.src
  bt6.src="rien.gif"
}  
if(bt5.value==" 0 "){
  bt5.value=bt6.value
  bt6.value=" 0 "
  bt5.src=bt6.src
  bt6.src="rien.gif"
}  
verif()
}

function but7(){
if(bt4.value==" 0 "){
  bt4.value=bt7.value
  bt7.value=" 0 "
  bt4.src=bt7.src
  bt7.src="rien.gif"
}  
if(bt8.value==" 0 "){
  bt8.value=bt7.value
  bt7.value=" 0 "
  bt8.src=bt7.src
  bt7.src="rien.gif"
}  
verif()
}

function but8(){
if(bt5.value==" 0 "){
  bt5.value=bt8.value
  bt8.value=" 0 "
  bt5.src=bt8.src
  bt8.src="rien.gif"
}  
if(bt7.value==" 0 "){
  bt7.value=bt8.value
  bt8.value=" 0 "
  bt7.src=bt8.src
  bt8.src="rien.gif"
}  
if(bt9.value==" 0 "){
  bt9.value=bt8.value
  bt8.value=" 0 "
  bt9.src=bt8.src
  bt8.src="rien.gif"
}  
verif()
}

function but9(){
if(bt6.value==" 0 "){
  bt6.value=bt9.value
  bt9.value=" 0 "
  bt6.src=bt9.src
  bt9.src="rien.gif"
}  
if(bt8.value==" 0 "){
  bt8.value=bt9.value
  bt9.value=" 0 "
  bt8.src=bt9.src
  bt9.src="rien.gif"
}  
verif()
}

function verif(){
if((bt1.value==1)&&(bt2.value==2)&&(bt3.value==3)&&(bt4.value==4)&&(bt5.value==5)&&(bt6.value==6)&&(bt7.value==7)&&(bt8.value==8)&&(bt9.value==0)){

coups++
document.taquin.coup.value=coups
coups--

alert('Vous avez gagné en '+(coups+1)+' coups ! Bravo ! ')

if(Math.min(coups,coupgag)==coups){
alert('C\'est le meilleur score')
creercookie()
}

}
}

function melanger(){
nom1=10
nom2=10
nom3=10
nom4=10
nom5=10
nom6=10
nom7=10
nom8=10
nom9=0

while ((nom1==nom2)||(nom1==nom3)||(nom1==nom4)||(nom1==nom5)||(nom1==nom6)||(nom1==nom7)||(nom1==nom8)||(nom1==nom9)||(nom2==nom3)||(nom2==nom4)||(nom2==nom5)||(nom2==nom6)||(nom2==nom7)||(nom2==nom8)||(nom2==nom9)||(nom3==nom4)||(nom3==nom5)||(nom3==nom6)||(nom3==nom7)||(nom3==nom8)||(nom3==nom9)||(nom5==nom6)||(nom5==nom7)||(nom5==nom8)||(nom5==nom9)||(nom6==nom7)||(nom6==nom8)||(nom6==nom9)||(nom7==nom8)||(nom7==nom9)||(nom8==nom9)||(nom1>8)||(nom2>8)||(nom3>8)||(nom4>8)||(nom5>8)||(nom6>8)||(nom7>8)||(nom8>8)||(nom9>8)||(nom4==nom5)||(nom4==nom6)||(nom4==nom7)||(nom4==nom8)||(nom4==nom9)||(nom1==0)||(nom2==0)||(nom3==0)||(nom4==0)||(nom5==0)||(nom6==0)||(nom7==0)||(nom8==0)){
nom1=Math.floor(Math.random()*10)
nom2=Math.floor(Math.random()*10)
nom3=Math.floor(Math.random()*10)
nom4=Math.floor(Math.random()*10)
nom5=Math.floor(Math.random()*10)
nom6=Math.floor(Math.random()*10)
nom7=Math.floor(Math.random()*10)
nom8=Math.floor(Math.random()*10)
}

bt1.value=" "+nom1+" "
bt2.value=" "+nom2+" "
bt3.value=" "+nom3+" "
bt4.value=" "+nom4+" "
bt5.value=" "+nom5+" "
bt6.value=" "+nom6+" "
bt7.value=" "+nom7+" "
bt8.value=" "+nom8+" "
bt9.value=" "+nom9+" "

bt1.src=img+""+nom1+".gif"
bt2.src=img+""+nom2+".gif"
bt3.src=img+""+nom3+".gif"
bt4.src=img+""+nom4+".gif"
bt5.src=img+""+nom5+".gif"
bt6.src=img+""+nom6+".gif"
bt7.src=img+""+nom7+".gif"
bt8.src=img+""+nom8+".gif"
bt9.src="rien.gif"

coups=0
document.taquin.coup.value=0

}
function trier(){
bt1.value=" 1 "
bt2.value=" 2 "
bt3.value=" 3 "
bt4.value=" 4 "
bt5.value=" 5 "
bt6.value=" 6 "
bt7.value=" 7 "
bt8.value=" 8 "
bt9.value=" 0 "

bt1.src=img+"1.gif"
bt2.src=img+"2.gif"
bt3.src=img+"3.gif"
bt4.src=img+"4.gif"
bt5.src=img+"5.gif"
bt6.src=img+"6.gif"
bt7.src=img+"7.gif"
bt8.src=img+"8.gif"
bt9.src="rien.gif"

coups=0
document.taquin.coup.value=0

}
