$(function(){

	

	var ltie7 = ($.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent));

	if (ltie7) {

		$('img[@usemap]').css('border','none');

		$('img[@src$=.png]').ifixpng();

		$('input[@src$=.png]').ifixpng();

		$(' :radio').css('border','none');

	}

	

	/* CSS */ 

/*	$('.texte > p').each(function() {

		if ($(this).next().is('ul')) $(this).css('margin-bottom',0);

	});

*/



	/* footer */ 

	$('#footer > li:first ').css('border','none');

	i1=new Image;

	i1.src='/_media/img/bulle_chat_on.png';

	i2=new Image;

	i2.src='/_media/img/bulle_prix_special_on.png';

	i3=new Image;

	i3.src='/_media/img/bulle_quiz_on.png';

	i4=new Image;

	i4.src='/_media/img/bulle_radio_on.png';

	i5=new Image;

	i5.src='/_media/img/bulle_savoir_on.png';

	i6=new Image;

	i6.src='/_media/img/bulle_sondage_on.png';



	

	menu(ltie7);

	idee_recues(ltie7);

	verif_form();

});



function menu(ltie7) {

	if ($('#menu > li div').size == 0) return false;

	

	// prelod des images de rollover

	

	

	$('#menu > li div').each(function() {

		if($(this).hasClass('on')) {

			if (ltie7) { 

				url_bg = $(this).css('filter').replace('_off','_on');

				$(this).css('filter',url_bg);

			}

			else {

				url_bg = $(this).css('background-image').replace('_off','_on');

				$(this).css('background-image',url_bg);

			}

		}

	}).mouseover(function() {

		if(!$(this).hasClass('on')) {

			if (ltie7) { 

				url_bg = $(this).css('filter').replace('_off','_on');

				$(this).css('filter',url_bg);

			}

			else {

				url_bg = $(this).css('background-image').replace('_off','_on');

				$(this).css('background-image',url_bg);

			}

		}

		$(this).css('cursor','pointer');

		

	}).mouseout(function() {

		if(!$(this).hasClass('on')) {

			if (ltie7) { 

				url_bg = $(this).css('filter').replace('_on','_off');

				$(this).css('filter',url_bg);

			}

			else {

				url_bg = $(this).css('background-image').replace('_on','_off');

				$(this).css('background-image',url_bg);

			}

		}

	}).click(function() {
		nb_lien = $(this).find("a").size();

		if (nb_lien >= 1 && $(this).find("a:first[href]").size() != 0) {
			lien = $(this).find("a:first");
			href = lien.attr("href");
			target = lien.attr("target")

			if (!target) window.location.replace(href);
		}

		

		//if($(this).parent().attr('id') == "chat") window.open("http://213.186.46.105/chat/carac/", '', 'resizable=no, location=no, width=655, height=550, menubar=no, status=yes, scrollbars=no, menubar=no');

	});

	

	if ($('#form_sondage_home_id').size != 0) {

		$('#form_sondage_home_id').submit(function() {

		

			if ($('#form_sondage_home_id').find(":checked").size() != 0) {

				alert("Merci d'avoir voté");

				return true;

			}

			return false;

		});

	}

	

	if ($('#le_saviez_vous').size != 0) {

		var phrase = new Array();


		phrase[0]="50 % des Français ont entendu parler de l'épargne solidaire.";

		phrase[1]="L'encours de l'épargne solidaire a atteint 2,401 milliards d'euros en 2009.";

		phrase[2]="Le montant des investissements solidaires a progressé de 34 % en 2009.";

		phrase[3]="Le label Finansol garantit la transparence et l'éthique d'un placement solidaire.";

		phrase[4]="L'épargne solidaire permet de financer des projets de solidarité à l'étranger et en France.";

		phrase[5]="Grâce à l'épargne solidaire, 2&nbsp;000 familles ont pu être logées ou relogées en 2009.";

		phrase[6]="Chaque épargnant solidaire peut choisir les projets de solidarité qu'il souhaite soutenir.";

		phrase[7]="En 2009, l'épargne solidaire a permis de créer 26&nbsp;000 emplois en France .";

		var taille_dispo = 45;

		

		$('#le_saviez_vous a img').each(function() {

			nb = parseInt(Math.random()*phrase.length);

			$(this).parent().parent().find('p').html(phrase[nb]);

			taille = $(this).parent().parent().find('p').height()

			new_marge = (taille_dispo - taille) / 2;

			$(this).parent().parent().find('p').css('margin-top',new_marge);

			return false;

		}).mouseover(function() {

			if (ltie7) { 

				url_bg = $(this).css('filter').replace('_off','_on');

				$(this).css('filter',url_bg);

			}

			else {	

				url_bg = $(this).attr('src').replace('_off','_on');

				$(this).attr('src',url_bg);

			}

		}).mouseout(function() {

			if (ltie7) { 

				url_bg = $(this).css('filter').replace('_on','_off');

				$(this).css('filter',url_bg);

			}

			else {

				url_bg = $(this).attr('src').replace('_on','_off');

				$(this).attr('src',url_bg);

			}

		}).click(function() {

			nb = parseInt(Math.random()*phrase.length);

			$(this).parent().parent().find('p').html(phrase[nb]);

			

			

			taille = $(this).parent().parent().find('p').height()

			new_marge = (taille_dispo - taille) / 2;

			$(this).parent().parent().find('p').css('margin-top',new_marge);

			return false;

		});

		

		

		

	}

}



function idee_recues(ltie7) {



	if($('#idee_recues').size()==0) return false;

	var reponce = new Array(6);

	var texte;

	//repponce[numéro de la question - 1] = bonne reponce (booléen?true:false)

	reponce[0]=0;

	reponce[1]=0;

	reponce[2]=0;

	reponce[3]=1;

	reponce[4]=0;

	reponce[5]=0;

	reponce[6]=0;





	$('input').each(function(){

		$(this).parent().find("p").hide();

	

	}).click(function() {

	

		q = $(this).attr('name').replace("rep_q","");

		q -= 1;

		rep = reponce[q] == $(this).attr('value');

		

		texte = (rep)?"Réponse juste":"Réponse fausse";

		if ($(this).parent().find("p").size() == 1)	{

			$(this).parent().find(":last").before('<p>'+texte+'</p>');

		}

		else {

			$(this).parent().find("p:first").html(texte);

		}

		

		$(this).parent().find(":last").show();

		

		img_src=(rep)?'_media/img/picto_smiley_bon.png':'_media/img/picto_smiley_faux.png';

		img = (rep)?'<img src="'+img_src+'" alt="picto réponse juste" width="22" height="22" />':'<img src="'+img_src+'" alt="picto réponse fausse" width="22" height="22" />';

		

		if($(this).parent().find("p:first").find("img").size()==0) {

			$(this).parent().find("p:first").prepend(img);

			if (ltie7) {$(this).parent().find("p:first").find("img").ifixpng();}

		}

		else {

			if (ltie7) {$(this).parent().find("p:first").find("img").iunfixpng().attr('src',img_src).ifixpng();}

			else $(this).parent().find("p:first").find("img").attr('src',img_src);

		}

		

		

		$(this).parent().find("p:first").removeClass((rep)?"faux":"juste").addClass((rep)?"juste":"faux");

		

	});

}



function verif_form() {

	

	if($('#form_reagissez_id').size != 0) {

	

		$('#form_reagissez_id').submit(function(){

			

			if (this.titre_id.value == "") {alert('Vous devez spécifier un titre'); return false;}

			if (this.message_id.value == "") {alert('Vous devez écrire un message'); return false;}

			if (this.nom_id.value == "") {alert('Vous devez spécifier votre nom'); return false;}

			return true;

		});

	}

	

	if($('#form_contact_id').size != 0) {

	

		$('#form_contact_id').submit(function(){

			

			if (this.nom.value == "") {alert('Vous devez spécifier votre nom'); return false;}

			if (this.prenom.value == "") {alert('Vous devez spécifier votre prénom'); return false;}

			if (this.email.value == "") {alert('Vous devez spécifier votre email'); return false;}

			if (!isEmail(this.email)) {alert('Vous devez spécifier une adresse email valide'); return false;}

			if (this.adr.value == "") {alert('Vous devez spécifier votre adresse'); return false;}

			if (this.cp.value == "") {alert('Vous devez spécifier code postal'); return false;}

			if (this.ville.value == "") {alert('Vous devez spécifier votre ville'); return false;}

			if (this.message.value == "") {alert('Vous devez spécifier votre message'); return false;}

			if (this.message.value.length > 1500) {	alert('Votre message est ttrop long'); return false;}

			return true;

		});

	}

}



function isEmail(eml)

{



	a = eml.value.search(/^[-a-z0-9_]+([-._]+[-a-z0-9_]+)*@[a-z0-9]([.-]?[a-z0-9])*\.[a-z]{2,4}$/i);

	if(a!=-1)

		return true

	else

		return false

}