// La table de Tjahzi
// ------------------
// Un jeu Copyright 2002-2008 Cpt Harddock
// http://www.thorgal-bd.fr/

this.ligne=1;
this.colonne=0;
var result=new Array(0,0,0,0,0);
var essai=new Array(0,0,0,0,0);
var result_eff=new Array(0,0,0,0,0);

for (i=1;i<=4;i++){
result[i]=Math.round(Math.random()*(8-1)+1)}

function tjahzi(perso){
if (this.result==1)return true;
if (this.colonne==4)return true;
var choix="<img src='images/tjahzi/"+perso+".gif'>";
this.colonne++;
if(document.all)document.all("l"+this.ligne+"_"+this.colonne).innerHTML=choix;
if(!document.all)document.getElementById("l"+this.ligne+"_"+this.colonne).innerHTML=choix;
essai[this.colonne]=perso;
}

function tj_retour(){
if (this.colonne<1)return true;
if(document.all)document.all("l"+this.ligne+"_"+this.colonne).innerHTML="";
if(!document.all)document.getElementById("l"+this.ligne+"_"+this.colonne).innerHTML="";
essai[this.colonne]=0;
this.colonne--;
}

function verifier(){
if (this.result==1)reset();
var victoire=0;
var perso_trouve="";
if (essai[1]==0||essai[2]==0||essai[3]==0||essai[4]==0)return true;
for (i=1;i<=4;i++){
if (essai[i]==result[i]){
perso_trouve=perso_trouve+"<img src='images/tjahzi/r1.gif'>";
essai[i]=0;
result_eff[i]=1;
victoire++;}}
if (victoire==4)ouais();
for (i=2;i<=4;i++){
if (essai[1]==result[i]&&result_eff[i]==0){
perso_trouve=perso_trouve+"<img src='images/tjahzi/r2.gif'>";
essai[1]=0;
result_eff[i]=1;}}
for (i=1;i<=4;i++){
if (i==2)i++;
if (essai[2]==result[i]&&result_eff[i]==0){
perso_trouve=perso_trouve+"<img src='images/tjahzi/r2.gif'>";
essai[2]=0;
result_eff[i]=1;}}
for (i=1;i<=4;i++){
if (i==3)i++;
if (essai[3]==result[i]&&result_eff[i]==0){
perso_trouve=perso_trouve+"<img src='images/tjahzi/r2.gif'>";
essai[3]=0;
result_eff[i]=1;}}
for (i=1;i<=3;i++){
if (essai[4]==result[i]&&result_eff[i]==0){
perso_trouve=perso_trouve+"<img src='images/tjahzi/r2.gif'>";
essai[4]=0;
result_eff[i]=1;}}
if (essai[1]!=0&&essai[2]!=0&&essai[3]!=0&&essai[4]!=0)perso_trouve=perso_trouve+"<img src='images/tjahzi/r3.gif'>";
if(document.all)document.all("r"+this.ligne).innerHTML=perso_trouve;
if(!document.all)document.getElementById("r"+this.ligne).innerHTML=perso_trouve;
for (i=1;i<=4;i++){
result_eff[i]=0;
essai[i]=0;}
this.ligne++;
this.colonne=0;
if (this.ligne==11&&victoire<=3)booof();
}

function ouais(){
this.victoire=1;
if(document.all){
for (i=1;i<=4;i++){document.all("res_"+i).innerHTML="<img src='images/tjahzi/"+result[i]+".gif'>";}
this.result=1;
document.all("bulle").style.visibility="visible";
document.all("bulle").style.pixelLeft=document.body.clientWidth/2-70;
document.all("bulle").style.pixelTop=document.body.clientHeight/2-100;
document.all("bulle").innerHTML="<table border='0' cellpadding='0' cellspacing='0' width='290' height='300' background='images/legende/bulle2.gif'><td width='290' height='39' colspan='3'></td></tr><tr><td width='44' height='156'></td><td width='208' height='156' align='center'><font face='Tahoma' size='4' color='black'><b>BRAVO !<br><br>Appuyer sur <b>&quot;Jouer&quot;</b> pour une nouvelle partie.</b></font></td><td width='48' height='156'></td></tr><tr><td width='290' height='105' colspan='3'></td></tr></table>";}
if(!document.all){
for (i=1;i<=4;i++){document.getElementById("res_"+i).innerHTML="<img src='images/tjahzi/"+result[i]+".gif'>";}
this.result=1;
document.getElementById("bulle").style.visibility="visible";
document.getElementById("bulle").style.left=window.innerWidth/2-70;
document.getElementById("bulle").style.top=window.innerHeight/2-100;
document.getElementById("bulle").innerHTML="<table border='0' cellpadding='0' cellspacing='0' width='290' height='300' background='images/legende/bulle2.gif'><td width='290' height='39' colspan='3'></td></tr><tr><td width='44' height='156'></td><td width='208' height='156' align='center'><font face='Tahoma' size='4' color='black'><b>BRAVO !<br><br>Appuyer sur <b>&quot;Jouer&quot;</b> pour une nouvelle partie.</b></font></td><td width='48' height='156'></td></tr><tr><td width='290' height='105' colspan='3'></td></tr></table>";}
}

function booof(){
if(document.all){
for (i=1;i<=4;i++){document.all("res_"+i).innerHTML="<img src='images/tjahzi/"+result[i]+".gif'>";}
this.result=1;
document.all("bulle").style.visibility="visible";
document.all("bulle").style.pixelLeft=document.body.clientWidth/2-70;
document.all("bulle").style.pixelTop=document.body.clientHeight/2-100;
document.all("bulle").innerHTML="<table border='0' cellpadding='0' cellspacing='0' width='290' height='300' background='images/legende/bulle2.gif'><td width='290' height='39' colspan='3'></td></tr><tr><td width='44' height='156'></td><td width='208' height='156' align='center'><font face='Tahoma' size='4' color='black'><b>PERDU...<br><br>Appuyer sur <b>&quot;Jouer&quot;</b> pour une nouvelle partie.</b></font></td><td width='48' height='156'></td></tr><tr><td width='290' height='105' colspan='3'></td></tr></table>";}
if(!document.all){
for (i=1;i<=4;i++){document.getElementById("res_"+i).innerHTML="<img src='images/tjahzi/"+result[i]+".gif'>";}
this.result=1;
document.getElementById("bulle").style.visibility="visible";
document.getElementById("bulle").style.left=window.innerWidth/2-70;
document.getElementById("bulle").style.top=window.innerHeight/2-100;
document.getElementById("bulle").innerHTML="<table border='0' cellpadding='0' cellspacing='0' width='290' height='300' background='images/legende/bulle2.gif'><td width='290' height='39' colspan='3'></td></tr><tr><td width='44' height='156'></td><td width='208' height='156' align='center'><font face='Tahoma' size='4' color='black'><b>PERDU...<br><br>Appuyer sur <b>&quot;Jouer&quot;</b> pour une nouvelle partie.</b></font></td><td width='48' height='156'></td></tr><tr><td width='290' height='105' colspan='3'></td></tr></table>";}
}

function reset(){
location.href="thorgal_table_de_tjahzi.php";
}

function fenetre(){
if(this.victoire==1||this.ligne==11)return;

if (document.all){
var g=(document.body.clientWidth-500)/2;
document.all("fond").style.visibility="hidden";
document.all("ivaldir").style.visibility="visible";
document.all("gars").style.visibility="visible";
document.all("nuage").style.visibility="visible";
document.all("ivaldir").style.pixelLeft=g;
document.all("ivaldir").style.pixelTop=document.body.clientHeight/2-180;
document.all("gars").style.pixelLeft=g+50;
document.all("gars").style.pixelTop=document.body.clientHeight/2-240;
document.all("nuage").style.pixelLeft=g-10;
document.all("nuage").style.pixelTop=document.body.clientHeight/2-170;
}

if (!document.all){
var g=(window.innerWidth-500)/2;
document.getElementById("fond").style.visibility="hidden";
document.getElementById("ivaldir").style.visibility="visible";
document.getElementById("gars").style.visibility="visible";
document.getElementById("nuage").style.visibility="visible";
document.getElementById("ivaldir").style.left=g;
document.getElementById("ivaldir").style.top=window.innerHeight/2-180;
document.getElementById("gars").style.left=g+50;
document.getElementById("gars").style.top=window.innerHeight/2-240;
document.getElementById("nuage").style.left=g-10;
document.getElementById("nuage").style.top=window.innerHeight/2-170;
}
}

function eff(){
if (document.all){
document.all("fond").style.visibility="visible";
document.all("ivaldir").style.visibility="hidden";
document.all("gars").style.visibility="hidden";
document.all("nuage").style.visibility="hidden";}
if (!document.all){
document.getElementById("fond").style.visibility="visible";
document.getElementById("ivaldir").style.visibility="hidden";
document.getElementById("gars").style.visibility="hidden";
document.getElementById("nuage").style.visibility="hidden";}
}