var is_ie = (document.all && document.getElementById);
var is_moz = (!document.all && document.getElementById);
var is_opera = (navigator.userAgent.indexOf("Opera") > -1);
var fondu_lst = new Array;

function changeDisplay(quoi, comment){
   document.getElementById(quoi).style.display = comment;
}

function fondu(objet, valeur, minimum, maximum, delai) {
   this.objet = objet;
   this.val = valeur;
   this.inc = 0;
   this.min = minimum;
   this.max = maximum;
   this.delai = delai;
   this.run = false;
   this.lanceFondu = function fonduObjet() {
	   var obj = this;
	   this.run = true;
	   this.val += this.inc;
	   if (this.val <= this.max) {
	      if (this.val >= this.min) {
	         if (is_ie) {
	            document.getElementById(this.objet).filters.alpha.opacity = this.val;
	         } else if (is_moz) {
	            document.getElementById(this.objet).style.MozOpacity = (this.val / 100);
	         } if (is_opera) {
	            this.val = 100;
	         }
	         setTimeout(function () { obj.lanceFondu(); }, this.delai);
	      } else { 
	         this.val = this.min;
	         this.run = false;
	      }
	   } else {
	      this.val = this.max;
	      this.run = false;
	   }
	}

}

function doFondu (objet, valeur, minimum, maximum, delai, increment) {
	if (fondu_lst[objet] == undefined) {
		fondu_lst[objet] = new fondu(objet, valeur, minimum, maximum, delai);
	}
	fondu_lst[objet].inc = increment;
	fondu_lst[objet].lanceFondu();
}

function affichePeche(num) {
   doFondu("rub" + num + "-peche", 100, 20, 100, 25, -20);
   doFondu("rub" + num + "-texte", 0, 0, 80, 25, +20);
}

function cachePeche(num) {
   doFondu("rub" + num + "-peche", 100, 20, 100, 25, +20);
   doFondu("rub" + num + "-texte", 0, 0, 80, 25, -20);
}
     
function afficheFormulaire() {
   changeDisplay('repondre','none'); 
   changeDisplay('formulaire','block');
   doFondu("formulaire", 0, 0, 100, 100, +20);
}

function cacheFormulaire() {
   changeDisplay('repondre','block'); 
   changeDisplay('formulaire','none');
   doFondu("formulaire", 0, 0, 100, 100, -20);
}


function addText(instext) {
var mess = document.commentaire.message;
    //IE support
    if (document.selection) {
        mess.focus();
        sel = document.selection.createRange();
        sel.text = instext;
        document.commentaire.focus();
    }
    //MOZILLA/NETSCAPE support
    else if (mess.selectionStart || mess.selectionStart == "0") {
        var startPos = mess.selectionStart;
        var endPos = mess.selectionEnd;
        var chaine = mess.value;

        mess.value = chaine.substring(0, startPos) + instext + chaine.substring(endPos, chaine.length);
 
        mess.selectionStart = startPos + instext.length;
        mess.selectionEnd = endPos + instext.length;
        mess.focus();
    } else {
        mess.value += instext;
        mess.focus();
    }
} 
 
function verif_mail(adresse) {
   var place = adresse.indexOf("@", 1);
   var point = adresse.indexOf(".", place + 1);
   
   if (place > -1 && adresse.length >2 && point > 1)
      return true;
   else
      return false;
}
 
function verif_add(){
   var nom = document.commentaire.email.value;
   var message = document.commentaire.message.value;
 
   if ((document.commentaire.site.value == "http://") || 
      (document.commentaire.site.value == document.commentaire.site.defaultValue)) {
      document.commentaire.site.value = "";
   }
   if (!verif_mail(nom)){
      alert("Ton mail n'est pas correct\n (nÃ©cessaire mais non publiÃ©)");
      return false;
   }
   else if (!message){
      alert("T'as rien à me dire ? :'-(");
      return false;
   }
}
