function IE_CorrectAlpha_PNG(){
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}

var userAgent=navigator.userAgent;
if (userAgent.indexOf('MSIE 6') != -1) {
    window.attachEvent("onload", IE_CorrectAlpha_PNG);
}

//Script par Nicolas Catez (http://esurf.fr.tc/)
var ie = document.all?true:false // On test le navigateur pour IE 
//onload = preloadImage // Appel de la function preloadImage() au chargement de la page. Peut etre remplacer par <body onload="preloadImage()">
function addZero(chiffre){ // Function qui ajoute un zero devant les chiffres
	if (chiffre < 10) { chiffre = "0"+chiffre; }
	//if (chiffre < 100) { chiffre = "0"+chiffre; }
	return chiffre; 
}
var i=0; // On initialise le comptage des images a 0.
var percent_prec=0; // On initialise le comptage des images a 0.
var totalImage_new=0; // On initialise le comptage des images a 0.
function preloadImage(){ 
	var myContent = document.getElementById("ppal").getElementsByTagName('img') // On repere les images contenu dans la page
	var totalImage = myContent.length // Et on compte combien il y'en a
	percent = Math.ceil((i+1)*100/totalImage) // A chaque passage dans la fonction, on calcule le pourcentage de i par rapport au nb d'image
	if (i < totalImage){ // Si l'image traité n'est pas la derniere image du doc on execute ce qui suit.
		if (myContent.item(i).complete) {  // si l'image i est chargée, on envoi le pourcentage dans le div
   	nb = totalImage-i-1;
		//document.getElementById("preloadPercent").innerHTML = "[Reste " + nb +" images à charger]"; 
//		if (percent != 100){document.getElementById("preloadPercent").innerHTML = "<div style='font-size:10px;'>chargement photos</div>"+ addZero(percent) + "%";} 
//		else{document.getElementById("preloadPercent").innerHTML = addZero(percent);}
		percent = Math.ceil(110 * percent / 100);
		if (percent > 110){percent=110;}
	//	if (percent < percent_prec && totalImage == totalImage_new){percent = percent_prec;}
		//alert(">>>"+percent);
		document.images["loadedGreen"].width = percent; // Et on redimension l'image rouge
		percent_prec = percent;
		totalImage_new = totalImage;
		//document.images["loadedRed"].width = 110-percent; // pareil en consequence avec la verte.
		i++; // On increment i, pour passer a l'image suivante
		setTimeout(preloadImage); // Et hop, on repasse dans la fonction avec l'image suivante
		}
	} else { // Sinon, on deduit que les images ont toute été chargées, et on cache le preload.
	//document.getElementById("preloadCache").style.visibility = "hidden"; // Si le client n'est pas IE on vire tout simplement le cache
	//else crosoftFade() // Sinon on applique un effet de fade progressif en appelant la fonction crosoftFade() 
	}
}

function urlencode(ch) {
   ch = ch.replace(/[ ]/g,"+") 
   return escape(ch) 
}

function montre(srcimg,sens){
val1=srcimg;
val2=sens;
}

function image(){
  ie = 'Microsoft Internet Explorer';
  if (navigator.appName != ie ){
    window.resizeTo(screen.width,screen.height);
    window.moveTo(0,0);
  }
  if (window.document.image.height > window.document.image.width ) {
    window.document.image.height = (screen.height * 0.94) ;}
  else {
    window.document.image.width = screen.width * 0.98 ;}
}

function pleinecran(src){
  var image=src.substring(src.lastIndexOf("/")+1);
    var chemin=src.substring(0,src.lastIndexOf("/"));
    var track=src.substring(src.indexOf("/", 7));
    _gaq.push(['_trackPageview',track]);
    var xhr_object = null;
    var position = 'sql';
    var url="../sql-image.php?img="+chemin+"/zoom/"+image;
//    alert(url);
  if(window.XMLHttpRequest) xhr_object = new XMLHttpRequest();
  else
  if (window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  xhr_object.open("GET", url, true);
  xhr_object.onreadystatechange = function (){
    if (xhr_object.readyState == 4 && xhr_object.status == 200){
      var c = document.getElementById(position);
      c.innerHTML = xhr_object.responseText;
      var allscript = c.getElementsByTagName('script');
      for(var i=0;i< allscript.length;i++){
        eval(allscript[i].text);
      }
    }
  }
  xhr_object.send(null);

  var voyage_annee=chemin.substring(chemin.lastIndexOf("/")+1);
  voyage=voyage_annee.substring(0, voyage_annee.lastIndexOf("-")).toUpperCase();
  annee=voyage_annee.substring(voyage_annee.lastIndexOf("-")+1);
  var url="href="+chemin+"/zoom/"+image+",,title="+voyage+",,comment= © "+annee+" The Co-Dream";
//  alert(url);
  if (userAgent.indexOf('MSIE') != -1) {
    CB_Open(url);
  }
}

//trace image
function t_img(src){
    var image=src.substring(src.lastIndexOf("/")+1);
    var chemin=src.substring(0,src.lastIndexOf("/"));
    //trackeur google analytics :
    var track=src.substring(src.indexOf("/", 7));
    _gaq.push(['_trackPageview',track]);

  	var xhr_object = null;
  	var position = 'sql';
  	var url="../sql-image2.php?img="+chemin+"/zoom/"+image;
  	
    if(window.XMLHttpRequest) xhr_object = new XMLHttpRequest();
    else
    if (window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
    
    // On ouvre la requete vers la page désirée
    xhr_object.open("GET", url, true);
    xhr_object.onreadystatechange = function (){
      if (xhr_object.readyState == 4 && xhr_object.status == 200){
        var c = document.getElementById(position);
        c.innerHTML = xhr_object.responseText;
        //maintenant que les données reçu on été placé dans la page,
        //il faut exécuter toutes les balise script :
        var allscript = c.getElementsByTagName('script');
        for(var i=0;i< allscript.length;i++){
          eval(allscript[i].text);
        }
        //alert(typeof(une_function_dans_mes_balise_script));//return function
      }
    }
    // dans le cas du get
    xhr_object.send(null);
    
}

function envoyer(no_sondage){
	document.choix.method = "POST";
	document.choix.action = "index.php#" + no_sondage;
	document.choix.submit();
}

function alerte_spam(){
     alert('Vous n\'avez pas signé votre message');
     exit;
   }

function ctrl_validite(){
  //alert('Ýa commence:' + document.fiche.message.value);
  var i = 0;
  if (document.fiche.nom.value =="" )
   {
     alert('Vous n\'avez pas signé votre message');
     document.fiche.nom.focus()
     exit;
   }
  if (document.fiche.email.value != "" && document.fiche.email.value != "cocherlacase" )
   {
      if (document.fiche.email.value.length < 6)
      {
       alert('Le format de votre e-mail n\'est pas valide !!!');
       document.fiche.email.focus()
       exit;
      }
      else
      {
       for (var j=1; (j<document.fiche.email.value.length); j++)
       {
        if (document.fiche.email.value.charAt(j) == " ")
         {
            alert('Il ne doit pas y avoir d\'espaces dans votre e-mail !!!');
            document.fiche.email.focus()
            exit;
         }
       }
       for (var j=1; (j<document.fiche.email.value.length) && (i != 1); j++)
       {
        if (document.fiche.email.value.charAt(j) == "@")
         {
           i = 1
         }
       }
       if (i == 1)
        {
         i = 0;
         for (var k=j+1; (k<document.fiche.email.value.length - 1) && (i != 1); k++)
          {
            if ((document.fiche.email.value.charAt(k) == ".") && (k != document.fiche.email.value.length))
             {
               i = 1;
             }
          }
         if (i == 0)
          {
            alert('Le format de votre e-mail n\'est pas valide');
            document.fiche.email.focus()
            exit;
          }
        }
       else
        {
           alert('Il manque le signe \'@\' dans votre e-mail !!!');
           document.fiche.email.focus()
           exit;
        }
      }
   }
  else
   {
     i = 1
   }
  if (document.fiche.comment.value == "")
   {
     alert('Vous n\'avez pas renseigné la zone message !!!');
     document.fiche.comment.focus()
     exit;
   }
  if (document.fiche.pageweb.value != ""){
   if (document.fiche.pageweb.value == "http://")
     {
       document.fiche.pageweb.value = "";
     }
    else
     {
      if (document.fiche.pageweb.value.substring(0,7) != "http://")
       {
        document.fiche.pageweb.value = "http://" + document.fiche.pageweb.value;
       }
     }
   }
   if (i == 1)
   {
  document.fiche.submit();
   }
}

