//--------------------------------------------------------------------------------------//
// By ORIHOUX                                                                           //
//--------------------------------------------------------------------------------------//
var choix = new Array(-1,-1,-1,-1,-1,-1);
var choixtemp = new Array(-1,-1,-1,-1,-1,-1);
var msg = "";

function Is() {
    var agent  = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns   = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
    this.ns2  = (this.ns && (this.major == 2));
    this.ns3  = (this.ns && (this.major == 3));
    this.ns4b = (this.ns && (this.minor < 4.04));
    this.ns4  = (this.ns && (this.major >= 4));
    this.ns6  = (!document.all && document.getElementById);
    this.ie   = (agent.indexOf('msie') != -1);
    this.ie3  = (this.ie && (this.major == 2));
    this.ie4  = (this.ie && (this.major >= 4));
    this.ie5  = (document.all && document.getElementById)
    this.op3  = (agent.indexOf('opera') != -1);
}
var is = new Is();
/*##### DOCUMENT OBJECT SWITCH ######*/
if(is.ns6 || is.ie5) {
    doc = 'document.getElementById(';
    sty = ').style.color=';	
    styb = ').style.backgroundColor=';
	txt = ').innerHTML=';
 } else if(is.ns4) {
    doc = 'window.document.';
    sty = 'style.color=';	
    styb = 'style.backgroundColor=';
	txt = ').innerHTML=';
} else if(is.ie4) {
    doc = 'document.all[';
	sty = ']style.color=';
    styb = ']style.backgroundColor=';
	txt = ').innerHTML=';	
} else {
    alert('Attention, votre Browser est trop ancien pour profiter pleinement de ce site \n Allez vite chez www.microsoft.com ou www.netscape.com chercher quelque chose de plus récent...\nDans les deux cas, tout est gratuit');
}
 
function fix(numero) {
   if (choix[numero] == -1) {
     valeur = choixtemp[numero];
     isok = false;
     while (isok==false) {
       isok=true;
       if (valeur==choix[1]) {valeur=valeur+2; isok=false;}
       if (valeur==choix[2]) {valeur=valeur+2; isok=false;}
       if (valeur==choix[3]) {valeur=valeur+2; isok=false;}
       if (valeur==choix[4]) {valeur=valeur+2; isok=false;}
	   if (valeur>22) valeur=valeur-22;
       }
     choix[numero]=valeur;
	 choixtemp[numero] = valeur;
     }
   else {
      alert("Pas nécessaire");
     }	 
  } 
 
function rnd(maxi) {
num=Math.floor(Math.random()*maxi+1) ;
return num;
}

function init() {
   var nbr=0;
   for (var i=1;i<=4;i++) {
     if (choix[i]==-1) {
        choixtemp[i]=rnd(22);
		nbr++;
       }
    } 
	tarot1.src="t" + choixtemp[1] + ".gif"
	tarot2.src="t" + choixtemp[2] + ".gif"
	tarot3.src="t" + choixtemp[3] + ".gif"	
	tarot4.src="t" + choixtemp[4] + ".gif"
    if (nbr>0) {
	   setTimeout("init()",10);
	}
	else {
	   diagnostic();
	}   	
}

function diagnostic() {
//-------------------------------------------------------------------------------------
// Calculer la cinquième Image
//-------------------------------------------------------------------------------------
   var cinq = choix[1] + choix[2] + choix[3] + choix[4];
   if  (cinq > 10) {
      var dizaine = parseInt(cinq/10);
	  var unites = cinq - 10 * dizaine;
      cinq = dizaine + unites;
	  }
   choix[5]=cinq;
   choixtemp[5] = cinq;
   tarot5.src="t" + choixtemp[5] + ".gif"
//-------------------------------------------------------------------------------------
// Message 'patience ....'
//-------------------------------------------------------------------------------------
   var msg = "Patience, votre prédiction est en cours ....";	
   eval(doc + "'resultat'" + txt + "msg"); 	
//-------------------------------------------------------------------------------------
// Message 'patience ....'
//-------------------------------------------------------------------------------------
  setTimeout("appel()",5);
}

function appel() {
//-------------------------------------------------------------------------------------
// Générer le Diagnostic
//-------------------------------------------------------------------------------------
    var resultat="generer.php?";
    resultat=resultat+"c1="+choix[1];
    resultat=resultat+"&"+"c2="+choix[2];
    resultat=resultat+"&"+"c3="+choix[3];
    resultat=resultat+"&"+"c4="+choix[4];
    resultat=resultat+"&"+"c5="+choix[5];
    window.location=resultat;
   }
   
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
