// 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;
      }
    }
  }

// Menu
$(document).ready( function( ) {

		var ie6 = ( $.browser.msie && parseInt( $.browser.version) < 7 );

		var a = '';
		var id = '';
		var num = '';
		var width = '';
		var height = '';
		var cible;
		var my_timer;

		$("li[id^=onglet] a").mouseover( function( ) {
			cible = $(this);
			my_timer = $.timer(500, function(timer) {
				a = cible.attr('class');

				cible.addClass('on');
				$("div[id^=" + a + "]").show( );

				timer.stop();
			});
		});

		$("li[id^=onglet] a").mouseleave( function( ) {
			my_timer.stop();
			$(this).removeClass('on');
			$("div[id^=bloque]").hide( );

			$("div[id^=bloque]").mouseover( function( ) {
				$("a[class=" + a + "]").addClass('on');
		  		$("div[id^=" + id + "]").show( );
			});
		});

		$("div[id^=bloque]").mouseover( function( ) { id = $(this).attr('id'); });

		$("div[id^=bloque]").mouseleave( function( ) {
			$("a." + $(this).attr('id')).removeClass('on');
			$(this).hide( );
		});
	});

// 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()
        };

// Pop pour les images
function PopupImage(img) {
        titre="Cheval Annonce - Petites annonces equestres";
        w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=yes');
        w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE><meta http-equiv='imagetoolbar' content='no'></HEAD>");
        w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+12,document.images[0].height+30); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
        w.document.write("<BODY oncontextmenu='return false' onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><IMG src='"+img+"' border=0>");
        w.document.write("");
        w.document.write("</BODY></HTML>");
        w.document.close();
}

// Ouverture
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Tous cochés ou décochés
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
 }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
 }
}

// Verif formulaire messagerie
function verifFormmm(poster) {
if (document.poster.pour.value == "")
        alert('Merci de préciser le pseudo de votre destinataire');
else
if (document.poster.message.value == "")
        {
        alert('Merci de remplir votre message');
        return(false);
        }

else
       {
       poster.submit();
       return(true);
       }
}

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

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

// CHANGE LA PHOTO
function change_photo(wcontenu) {
 document.getElementById("laphoto").innerHTML = wcontenu;
}

// POUR LES TABS DES ANNONCES
$(document).ready(function() {

	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});

// FORMULAIRE DES MP
function VerifFormulaire1(which) {
var ok=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var verif1=which.elements[i];
if (verif1.name=="pour" || 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 champs "+NomChamp+" s'il vous plaît !");
return false;
}
else
return true;
}

// Verif formulaire creation album
function verifAlbum(album) {
if (document.album.album_f.value == "")
        {
        alert('Merci de remplir le nom de votre album');
        return(false);
        }

else
       {
       poster.submit();
       return(true);
       }
}

// POUR METTRE LE SITE EN FAVORIS
function favoris() {
      if ( navigator.appName != 'Microsoft Internet Explorer' ){
          window.sidebar.addPanel("Cheval Annonce : votre portail d'échanges équestres","http://www.chevalannonce.com/","");
      }
      else {
          window.external.AddFavorite("http://www.chevalannonce.com/","Cheval Annonce : votre portail d'échanges équestres");
      }
}
