function fonduCouleurTexte(id){
	this.pas = 100;// Nombre de pourcents vers la couleur de destination à chaque itération
	this.temps = 100;// Temps en ms entre chaque itération
	this.tempsImmobile = 4000;//Temps en ms de visibilité avant de faire le fondu
	this.pas_refondu = 20;// Nombre de pourcents vers la couleur de destination à chaque itération pour la réapparition du texte
	this.temps_refondu = 100;// Temps en ms entre chaque itération pour la réapparition du texte
	this.tempsImmobile_refondu = 1;//Temps en ms de visibilité avant de faire le fondu pour la réapparition du texte
	this.adressePhrases = 'http://' + window.location.host + '/phrases.php';//Adresse du fichier contenant les phrases
	
	//******************* Rien à modifier sous cette ligne   ***************/
	/*this.rouge = 187;
	this.vert = 202;
	this.bleu = 27;*/
	this.rouge = 226;
	this.vert = 0;
	this.bleu = 36;
	this.rougeOrigine = 255;
	this.vertOrigine = 255;
	this.bleuOrigine = 255;
	this.div=document.getElementById(id);
	this.pourcentFait = 0;
	this.nom = "obj" + id;
	this.phrases= new Array();
	this.indexPhrase = -1;
	window["phrasesImadiff"] = this;
			
	this.dec2hex = function(n){
		n = parseInt(n); var c = 'ABCDEF';
		var b = n / 16; var r = n % 16; b = b-(r/16); 
		b = ((b>=0) && (b<=9)) ? b : c.charAt(b-10);    
		return ((r>=0) && (r<=9)) ? b+''+r : b+''+c.charAt(r-10);
	}

	this.h2d = function(h){
		return parseInt(h,16);
	} 
	
	this.trim = function (myString){
		return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
	} 
	
	this.objetXML = function(){
		var result = false;
		try {
			result=new ActiveXObject('Msxml2.XMLHTTP');
		} catch(e) {
			try {
				result=new ActiveXObject('Microsoft.XMLHTTP');
			} catch(e) {
				result= new XMLHttpRequest();
			}
		}
		return result;
	}

	this.trouverPhrases = function(valeur){
		ajax = new this.objetXML;
		ajax.onreadystatechange= function() {
			if(ajax.readyState==4) {
				texteBrut=ajax.responseText;
				window.phrasesImadiff.phrases=texteBrut.split("|");
				//window.phrasesImadiff.phrases=texteBrut.split("\n");
				//window.phrasesImadiff.phrases=texteBrut.split("\r");
				window.phrasesImadiff.remplacerPhrase();
				window.phrasesImadiff.sleep();
			}
		}
		ajax.open('GET',this.adressePhrases,true);
		ajax.send(null);
	}
	
	this.remplacerPhrase = function(){
		var ind=this.indexPhrase;
		this.indexPhrase++;
		if(this.indexPhrase>=this.phrases.length) this.indexPhrase=0;
		/*parseInt(Math.floor(Math.random()*this.phrases.length));
		cpt=0;
		while(this.indexPhrase==ind)
		{
			cpt++;
			this.indexPhrase=parseInt(Math.floor(Math.random()*this.phrases.length));
			if(cpt==50) break;
		}*/
		this.div.innerHTML=this.phrases[this.indexPhrase];
	}

	this.couleurActuelle = function(){
		var coul = this.div.style.color;
		if(coul.length==4){
			this.rouge=coul.substr(1,1) + coul.substr(1,1);
			this.rouge=this.h2d(this.rouge);
			this.vert=coul.substr(2,1) + coul.substr(2,1);
			this.vert=this.h2d(this.vert);
			this.bleu=coul.substr(3,1) + coul.substr(3,1);
			this.bleu=this.h2d(this.bleu);
		}
		if(coul.length==7){
			this.rouge=coul.substr(1,2);
			this.rouge=this.h2d(this.rouge);
			this.vert=coul.substr(3,2);
			this.vert=this.h2d(this.vert);
			this.bleu=coul.substr(5,2);
			this.bleu=this.h2d(this.bleu);
		}
		if(coul.substr(0,4)=='rgb('){
			var chaine=coul.substr(4,coul.length - 5);
			var segments=chaine.split(',');
			this.rouge=this.trim(segments[0]);
			this.vert=this.trim(segments[1]);
			this.bleu=this.trim(segments[2]);
		}
	}
	
	this.sleep = function(){
		setTimeout("window." + "phrasesImadiff" + ".fondu()", this.tempsImmobile);
	}
	
	this.fondu = function(){
		this.pourcentFait+= this.pas;
		this.rouge = parseInt(this.rougeOrigine) + parseInt(Math.round((226-this.rougeOrigine)*(this.pourcentFait/100)));
		this.vert = parseInt(this.vertOrigine) + parseInt(Math.round((0-this.vertOrigine)*(this.pourcentFait/100)));
		this.bleu = parseInt(this.bleuOrigine) + parseInt(Math.round((36-this.bleuOrigine)*(this.pourcentFait/100)));
		this.div.style.color = '#' + this.dec2hex(this.rouge) + this.dec2hex(this.vert) + this.dec2hex(this.bleu);
		this.div.firstChild.style.color = '#' + this.dec2hex(this.rouge) + this.dec2hex(this.vert) + this.dec2hex(this.bleu);
		if(this.pourcentFait<100){
			setTimeout ( "window." + "phrasesImadiff" + ".fondu()", this.temps );
		} else {
			this.remplacerPhrase();
			this.pourcentFait = 0;
			this.refondu();
		}
	}
	
	this.refondu = function(){
		this.pourcentFait+= this.pas_refondu;
		/*this.rouge = 187 - parseInt(Math.round((187-this.rougeOrigine)*(this.pourcentFait/100)));
		this.vert = 202 - parseInt(Math.round((202-this.vertOrigine)*(this.pourcentFait/100)));
		this.bleu = 27 - parseInt(Math.round((27-this.bleuOrigine)*(this.pourcentFait/100)));*/
		this.rouge = 226 - parseInt(Math.round((226-this.rougeOrigine)*(this.pourcentFait/100)));
		this.vert = 0 - parseInt(Math.round((0-this.vertOrigine)*(this.pourcentFait/100)));
		this.bleu = 36 - parseInt(Math.round((36-this.bleuOrigine)*(this.pourcentFait/100)));
		this.div.firstChild.style.color = '#' + this.dec2hex(this.rouge) + this.dec2hex(this.vert) + this.dec2hex(this.bleu);
		if(this.pourcentFait<100){
			setTimeout ( "window." + "phrasesImadiff" + ".refondu()", this.temps_refondu );
		} else {
			this.pourcentFait = 0;
			this.sleep();
		}
		
	}
			
	this.couleurActuelle();
	this.rougeOrigine = this.rouge;
	this.vertOrigine = this.vert;
	this.bleuOrigine = this.bleu;
	this.trouverPhrases();		
}

/********Fonctions formulaires sante***********/
function ouvre_conjoint () {
    document.getElementById('no-conj').style.visibility = 'hidden';
    document.getElementById('no-conj').style.display = 'none';
    document.getElementById('conj').style.visibility = 'visible';
    document.getElementById('conj').style.display = 'block';
    document.getElementById('conjoint').value = "1";
    document.getElementById('jour_conjoint').className = "validate[required]";
    document.getElementById('mois_conjoint').className = "validate[required]";
    document.getElementById('annee_conjoint').className = "validate[required]";
    document.getElementById('conj1').style.opacity = 1;
    document.getElementById('conj2').style.opacity = 1;
    document.getElementById('jour_conjoint').disabled = false;
    document.getElementById('mois_conjoint').disabled = false;
    document.getElementById('annee_conjoint').disabled = false;
    
}

function ferme_conjoint () {
    document.getElementById('conj').style.visibility = 'hidden';
    document.getElementById('conj').style.display = 'none';
    document.getElementById('no-conj').style.visibility = 'visible';
    document.getElementById('no-conj').style.display = 'block';
    /*document.getElementById('jour_conjoint').value = "";
    document.getElementById('mois_conjoint').value = "";
    document.getElementById('annee_conjoint').value = "";*/
    document.getElementById('conjoint').value = "0";
    document.getElementById('jour_conjoint').className = "";
    document.getElementById('mois_conjoint').className = "";
    document.getElementById('annee_conjoint').className = "";
    document.getElementById('conj1').style.opacity = 0.2;
    document.getElementById('conj2').style.opacity = 0.2;
    document.getElementById('jour_conjoint').disabled = true;
    document.getElementById('mois_conjoint').disabled = true;
    document.getElementById('annee_conjoint').disabled = true;
}

function ouvre_enfant () {
    document.getElementById('no-enfant').style.visibility = 'hidden';
    document.getElementById('no-enfant').style.display = 'none';
    document.getElementById('enfant').style.visibility = 'visible';
    document.getElementById('enfant').style.display = 'block';
    document.getElementById('enf').value = "1";
    document.getElementById('enf1').style.opacity = 1;
    document.getElementById('enf2').style.opacity = 1;
    document.getElementById('nbr_enfant').disabled = false;

    var nbr = document.getElementById('nbr_enfant').value;
    for (i=1; i<=nbr; i++) {
   	 	document.getElementById('enfant'+i).style.opacity = 1;
        document.getElementById('jour_enfant'+i).disabled = false;
        document.getElementById('mois_enfant'+i).disabled = false;
        document.getElementById('annee_enfant'+i).disabled = false;
        document.getElementById('jour_enfant'+i).className = "validate[required]";
        document.getElementById('mois_enfant'+i).className = "validate[required]";
        document.getElementById('annee_enfant'+i).className = "validate[required]";
    }
}

function ferme_enfant () {
    document.getElementById('enfant').style.visibility = 'hidden';
    document.getElementById('enfant').style.display = 'none';
    document.getElementById('no-enfant').style.visibility = 'visible';
    document.getElementById('no-enfant').style.display = 'block';
   	document.getElementById('enfant'+i).style.opacity = 0.2;
    document.getElementById('enf').value = "0";
    document.getElementById('enf1').style.opacity = 0.2;
    document.getElementById('enf2').style.opacity = 0.2;
    document.getElementById('nbr_enfant').disabled = true;
    
    for (i=1; i<=10; i++) {
   	 	document.getElementById('enfant'+i).style.opacity = 0.2;
        document.getElementById('jour_enfant'+i).disabled = true;
        document.getElementById('mois_enfant'+i).disabled = true;
        document.getElementById('annee_enfant'+i).disabled = true;
        document.getElementById('jour_enfant'+i).className = "";
        document.getElementById('mois_enfant'+i).className = "";
        document.getElementById('annee_enfant'+i).className = ""
    }
}

function check_enfants() {
    var nbr = document.getElementById('nbr_enfant').value;
    var nbr2 = parseInt(nbr)+1;
    for (i=1; i<=nbr; i++) {
   	 	document.getElementById('enfant'+i).style.opacity = 1;
        document.getElementById('enfant'+i).style.visibility = 'visible';
        document.getElementById('enfant'+i).style.display = 'block';
        document.getElementById('jour_enfant'+i).disabled = false;
        document.getElementById('mois_enfant'+i).disabled = false;
        document.getElementById('annee_enfant'+i).disabled = false;
        document.getElementById('jour_enfant'+i).className = "validate[required]";
        document.getElementById('mois_enfant'+i).className = "validate[required]";
        document.getElementById('annee_enfant'+i).className = "validate[required]";
    }
    for (i=nbr2; i<=10; i++) {
        document.getElementById('enfant'+i).style.visibility = 'hidden';
        document.getElementById('enfant'+i).style.display = 'none';
        document.getElementById('jour_enfant'+i).className = "";
        document.getElementById('mois_enfant'+i).className = "";
        document.getElementById('annee_enfant'+i).className = "";
    }
}
/********************************************/
