function maxlength(text,length)
	{		if(text.value.length>length) text.value=text.value.substr(0,length);
	}

// Resize Image
function resize_images()
  {
    for (i = 0; i < document.images.length; i++)
    {
      while ( !document.images[i].complete )
      {
       break;
      }
      limitew = 700;
      if ( document.images[i].width > limitew )
      {
   w = document.images[i].width;
   h = document.images[i].height;
   distancedelalimite = w-limitew;
   coefficient = distancedelalimite/w;
   height = h-coefficient*h;
   document.images[i].height = Math.round(height);
   document.images[i].width = limitew;
      }
    }
  }

// Affiche les vignettes
function afficheVignette(cheminVignette,cheminMaxi)
        {
        document.write('<A HREF="javascript:afficheMaxi(\''+cheminMaxi+'\')"><IMG SRC="'+cheminVignette+'" HSPACE=0 VSPACE=0 BORDER=0 ALT="cliquez ici pour voir en grand"></A>');
        }
function afficheMaxi(chemin)
        {
        i1 = new Image;
        i1.src = chemin;
        html = '<HTML><HEAD><TITLE>Image</TITLE></HEAD><BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER><IMG SRC="'+chemin+'" BORDER=0 NAME=imageTest onLoad="window.resizeTo(document.imageTest.width+14,document.imageTest.height+32)"></CENTER></BODY></HTML>';
        popupImage = window.open('','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1');
        popupImage.document.open();
        popupImage.document.write(html);
        popupImage.document.close()
        };

// Verif formulaire
function VerifFormulaire(which) {
var ok=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var verif1=which.elements[i];
if (verif1.name=="sujet" || verif1.name=="message") {
if (((verif1.type=="text"||verif1.type=="textarea"||verif1.type=="password")&&
verif1.value=='')||(verif1.type.toString().charAt(0)=="s"&&
verif1.selectedIndex==0)) {
ok=false;
break;
}
}
}
}
if (!ok) {
NomChamp=verif1.name;
alert("Remplissez le champ "+NomChamp+" s'il vous plaît !");
return false;
}
else
return true;
}

//Loader AJAX
function searcher() {
    var tags = $('tags').value;

    $('resultat').innerHTML = '';
        $('load').innerHTML = '<center><IMG alt="" src="http://www.chevalannonce.com/images/looder.gif"></center>';

    new Ajax.Request('search.php?tags='+tags,
           {
           asynchronous:true,
           method: 'get',

        onCreate: function(t){
           $('load').innerHTML = '<center><IMG alt="" src="http://www.chevalannonce.com/images/looder.gif"></center>';
         },
         onSuccess: function(t){
          $('resultat').innerHTML = t.responseText;
                  $('load').innerHTML = '';
         },
         onComplete: function(t){
           $('load').innerHTML = '';
         }
      }
      );
}

// Fonction des favoris AJAX
function getXhr(){
                                var xhr = null;
                                if(window.XMLHttpRequest) // Firefox et autres
                                   xhr = new XMLHttpRequest();
                                else if(window.ActiveXObject){ // Internet Explorer
                                   try {
                                        xhr = new ActiveXObject("Msxml2.XMLHTTP");
                                    } catch (e) {
                                        xhr = new ActiveXObject("Microsoft.XMLHTTP");
                                    }
                                }
                                else { // XMLHttpRequest non supporté par le navigateur
                                   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
                                   xhr = false;
                                }
                                return xhr;
                        }

                        /**
                        * Méthode qui sera appelée sur le click du bouton
                        */
                        function go(){
                                var xhr = getXhr();
                                // On défini ce qu'on va faire quand on aura la réponse
                                xhr.onreadystatechange = function(){

                                                                if(xhr.readyState == 3)
                                                                document.getElementById('livre').innerHTML = "<br /><br /><br /><br /><center><img src='images/a-loader.gif'></center>";
                                        // On ne fait quelque chose que si on a tout reçu et que le serveur est ok
                                        if(xhr.readyState == 4 && xhr.status == 200){
                                                leselect = xhr.responseText;
                                                // On se sert de innerHTML pour rajouter les options a la liste
                                                document.getElementById('livre').innerHTML = leselect;
                                        }
                                }

                                // Ici on va voir comment faire du post
                                xhr.open("POST","forum_favoris.php",true);
                                // ne pas oublier ça pour le post
                                xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                                // ne pas oublier de poster les arguments
                                // ici, l'id du site
                                sel = document.getElementById('site');
                                idsite = sel.value;
                                xhr.send("idSite="+idsite);
                        }

// Fonction délai sur le menu
$(document).ready(function(){
			//http://james.padolsey.com/javascript/jquery-delay-plugin/
			$.fn.delay = function(time, callback){
				jQuery.fx.step.delay = function(){};
				return this.animate({delay:1}, time, callback);
			}

			$('.menupremier').hover(
				function(){
							$(this).stop(true, false).delay(400, function(){ $(this).find('.sousmenu').fadeIn("fast"); });
						  },
				function(){
							$(this).stop(true, false).delay(0, function(){ $(this).find('.sousmenu').hide(); });
						  }
			);
  		});

// AFFICHE / CACHE UNE DIV
function affCache(idpr)
{
        var pr = document.getElementById(idpr);

        if (pr.style.display == "") {
                pr.style.display = "none";
        } else {
                pr.style.display = "";
        }
}
