$(document).ready(function(){

	
	$("#menu ul li a").mouseover( function(){
		$(".ss_menu").hide();
		$("#ss_"+$(this).attr("id")).show();
	});

	
	$("#overlay").width( document.documentElement.clientWidth );
	$("#overlay").height( document.documentElement.clientHeight );
	
	
	$("#overlay").click( function (){
		$(this).hide();
	});

	ie6_fix();

	$("#bg_gauche").css({
		"width"				:	""+Math.abs( parseInt( document.documentElement.clientWidth / 2 ) )+""
	});
	$("#bg_droit").css({
		"width"				:	""+Math.abs( parseInt( document.documentElement.clientWidth / 2 ) )+""
	});
	$("#wrap").css({
		"left"				:	"50%",
		"margin-left"		:	"-"+Math.abs( parseInt( $("#wrap").width() /2 ) )+"px"
	});

	taille_client		=	Math.abs( parseInt( document.documentElement.clientHeight ) );
	taille_body			=	Math.abs( parseInt( document.documentElement.offsetHeight ) );

	if( taille_client > taille_body )
	{
		$("#overlay").height( taille_client );
	}else{
		$("#overlay").height( taille_body );
	}

	if( $.browser.opera )
	{
		
	}

	if( $.browser.safari )
	{
		
	}

	$(".nutritionniste_liste_question tr .selectQuestion").hover( function() {  $(this).parent().children().children(".aide").children().css({"display":"block"}); }, function() { $(this).parent().children().children(".aide").children().css({"display":"none"});  });
});

function publierQuestion(idQuest) {

	if ( $("#publier_"+idQuest).attr('checked') == true ) {
		var check = "1";
	} else {
		var check = "0";
	}
	
	$.ajax({ 
		type: "post",url: "./espace_reponse.html",
		data: {choix:'publierQuestion',idQuest:idQuest,check:check }, 
		success: function(res) { 
			
		}
	});
}

function affiche_adresse(choix) {

	if ( choix == true ) {
		$("#adresse_perso").css("display","block");
	} else if ( choix == false ) {
		$("#adresse_perso").css("display","none");
	}
}


/* Affiche la liste des gagnants selon le mois */
function afficherGagnants(mois,mois2,mois3) {
	/* On display tous les tr */
		$("#tableau2 tr *").hide();
		
		$(".mois_"+mois+" * ").show();
		
		if ( mois2 != 0 ) {
			$(".mois_"+mois2+" * ").show();		
		}
		
		if ( mois3 != 0 ) {
			$(".mois_"+mois3+" * ").show();		
		}
		
}


function open_popup( page, width, height )
{

	$("#popup_close").css({
		"margin-bottom"		:	"50px",
		"margin-top"		:	"50px"
	});
	$("#overlay_content").width( width );
	$("#overlay_popup").width( width );
	$("#overlay_content p").width( width - 24 );
	$("#overlay_content p").css({
		"margin-left"		:	"24px"
	});
	$("#overlay_popup").height( height );
	$("#overlay_popup").css({
		//"margin-top"		:	"-"+Math.abs( height / 2 )+"px",
		"margin-left"		:	"-"+Math.abs( width / 2 )+"px"
	});
	$("#overlay_content").css({
		//"margin-top"		:	"-"+Math.abs( ( height / 2 ) + ( parseInt($("#overlay_content").css( "height" )) ) )+"px",
		"margin-left"		:	"-"+Math.abs( width / 2 )+"px"
	});
	$("img.align_g").css({
		"margin-left"		:	"-"+Math.abs( width )+"px"
	});
	$("img.align_d").css({
		"margin-left"		:	"-12px"
	});
	$("img.align_h").css({
		"margin-top"		:	"12px"
	});
	$("img.align_h.align_d").css({
		"margin-top"		:	"-12px"
	});
	$("img.align_b").css({
		"margin-top"		:	""+Math.abs( height )+"px"
	});
	$("img.align_b.align_d").css({
		"margin-top"		:	"-12px"
	});
	$("p.align_h").css({
		"margin-left"		:	""+Math.abs( 12 )+"px",
		"margin-top"		:	""+Math.abs( 12 )+"px"
	});
	$("p.align_b").css({
		"margin-left"		:	""+Math.abs( 12 )+"px",
		"margin-top"		:	""+Math.abs( height )+"px"
	});
	$("#popup_close").css({
		"margin-top"		:	""+Math.abs( 6 )+"px"
	});
	if( page != "auto" )
	{
		$("#overlay_popup").attr( "src", page );
	}

	if( $.browser.msie )
	{

		// $("#overlay_content p.align_h").css({
			// "position"				:	"relative",
			// "left"					:	"-12px",
			// "top"					:	"-6px",
			// "z-index"				:	"9999"
		// });
		// $("#overlay_content p.align_b").css({
			// "position"				:	"relative",
			// "top"					:	"-6px",
			// "left"					:	"-12px"
		// });
		// if( Math.abs( parseInt( $.browser.version ) ) > 6 )
		// {
			// $("#overlay_content p.align_h").css({
				// "position"				:	"fixed",
				// "z-index"				:	"9999",
				// "left"					:	"50%",
				// "margin-left"			:	"-"+Math.abs( parseInt( $("img.align_g.align_h").css( "margin-left" ) ) + 12 )+"px",
				// "top"					:	"50%",
				// "margin-top"			:	"-"+Math.abs( parseInt( $("img.align_g.align_h").css( "margin-top" ) ) + 0 )+"px"
			// });
			// $("#overlay_content p.align_b").css({
				// "position"				:	"fixed",
				// "z-index"				:	"9999",
				// "left"					:	"50%",
				// "margin-left"			:	"-"+Math.abs( parseInt( $("img.align_g.align_b").css( "margin-left" ) ) + 12 )+"px",
				// "top"					:	"50%",
				// "margin-top"			:	""+Math.abs( parseInt( $("img.align_g.align_b").css( "margin-top" ) ) + 0 )+"px"
			// });
			// $("#overlay_popup").css({
				// "position"				:	"fixed",
				// "left"					:	"50%",
				// "margin-left"			:	"-"+Math.abs( parseInt( width / 2 ) )+"px",
				// "top"					:	"50%",
				// "margin-top"			:	"-"+Math.abs( parseInt( height / 2 ) )+"px"
			// });
			// $("img.align_g.align_h, img.align_d.align_h").css({
				// "margin-top"			:	"-"+Math.abs( ( height / 2 + 12 ) )+"px",
				// "z-index"				:	"9999"
			// });
			// $("img.align_g.align_b, img.align_d.align_b").css({
				// "margin-top"			:	""+Math.abs( parseInt( $("img.align_g.align_b").css("margin-top") ) )+"px",
				// "z-index"				:	"9999"
			// });
		// }

footer_id			=	$("div[id^=footer_]").attr( "id" );
$("#overlay").height( ( document.getElementById( footer_id ).offsetTop + 32 )+"px" );

// Test IE8
if( $.browser.version.search( /8/ ) != -1 )
{

	$("img.align_h").css({
		"margin-left":			"0",
		"z-index":				"9999"
	});
	$("img.align_b").css({
		"margin-left":			"0",
		"z-index":				"9999"
	});
	$("img.align_d").css({
		"margin-left":			""+Math.abs( width - 12 )+"px",
		"z-index":				"9999"
	});
	$("img.align_g").css({
		"margin-left":			"0",
		"z-index":				"9999"
	});

// Test IE7
}else if( $.browser.version.search( /7/ ) != -1 ){


	$("img.align_h").css({
		"margin-left":			"0",
		"left":					"0",
		"top":					"0",
		"z-index":				"9999"
	});
	$("img.align_b").css({
		"margin-left":			"0",
		"z-index":				"9999"
	});
	$("img.align_d").css({
		"margin-left":			"-12px",
		"z-index":				"9999"
	});
	$("img.align_g").css({
		"margin-left":			"-24px",
		"z-index":				"9999"
	});
	$("img.align_g").css({
		"margin-left":			"-"+Math.abs( width  )+"px",
		"z-index":				"9999"
	});
	$("p.align_h").css({
		"margin-right":			"12px",
		"height":				"12px",
		"line-height":			"12px",
		"padding":				"0"
		
	});
	$("p.align_h *").css({
		"margin":"0"
	});
	$("p.align_b").css({
		"height":				"12px",
		"margin-right":			"12px"
	});
	$("img.align_b.align_d").css({
		"margin-top":			"-13px"
	});
	$("img.align_h").css({
		"margin":				"0"
	});
	$("img.align_h.align_g").css({
		"margin":				"12px 0 0 0"
	});
	$("img.align_h.align_d").css({
		"margin":				"12px 0 0 "+Math.abs( width - 12 )+"px"
	});

// Test IE6 et inf.
}else{
$("img.align_h").css({
		"margin-left":			"0",
		"z-index":				"9999"
	});
	$("img.align_b").css({
		"margin-left":			"0",
		"z-index":				"9999"
	});
	$("img.align_d").css({
		"margin-left":			"-12px",
		"z-index":				"9999"
	});
	$("img.align_g").css({
		"margin-left":			"-"+Math.abs( width )+"px",
		"z-index":				"9999"
	});
	$("p.align_b").css({
		"height":				"10px",
		"margin-right":			"12px"
	});
	$("img.align_b.align_d").css({
		"margin-top":			"-13px"
	});
	$("p.align_h").css({
		"margin-right":			"12px",
		"height":				"12px",
		"line-height":			"12px",
		"padding":				"0"
		
	});
	$("p.align_h *").css({
		"margin":"0"
	});
}
// Fin test IE

	}

	$("#overlay").show();

};

function hide_popup()
{
	$("#overlay").hide();
}

function ie6_fix()
{

	if( $.browser.msie )
	{

		if( Math.abs( parseInt( $.browser.version ) ) <= 6  )
		{

			$("#tableau_header p").css({
				"margin"						:	"0px",
				"padding-bottom"				:	"0px",
				"padding-top"					:	"2px",
				"margin-top"					:	"10px"
			});
			$("#bienetre_col1").css({
				"margin-right"					:	"80px"
			});
			$("#bienetre_col2").css({
				"margin-right"					:	"80px"
			});
			$(".recette_explication p").css({
				"height"						:	"0px"
			});
			$(".bloc_recette").css({
				"padding-top"					:	"6px"
			});
			$("img.nouveau").css({
				"margin-top"					:	"0px"
			});
			$(".bloc_aspartame").css({
				"width"							:	"440px"
			});
			$(".sommaire").css({
				"padding-left"					:	"10px"
			});
			$(".sommaire li").css({
				"width"							:	"150px"
			});
			$("#astuces").css({
				"height"						:	"0px",
				"background-position"			:	"0px 8px"
			});
			$(".puce1 img.float_right").css({
				"position"						:	"absolute",
				"left"							:	"100%",
				"margin-left"					:	"-476px",
				"width"							:	"256px"
			});
			$(".puce1").css({
				"width"							:	"250px"
			});
			$(".puce2").css({
				"width"							:	"250px"
			});
			$("#menu li").css({
				"line-height"					:	"38px"
			});
			$("#menu img").css({
				"margin-left"					:	"-3px"
			});
			$(".encarts a").css({
				"font-weight"					:	"normal"
			});
			$("#encart_1").css({
				"margin-left"					:	"-25px",
				"padding-left"					:	"0px"
			});
			$("#prehome_contenu .p1").css({
				"margin-left"					:	"70px",
				"margin-top"					:	"-70px",
				"position"						:	"relative"
			});
			$("#prehome_contenu .p2").css({
				"margin-left"					:	"100px",
				"margin-top"					:	"-70px",
				"position"						:	"relative",
				"background-position"			:	"10px 0px"
			});
			$("#plan_site ul").css({
				"margin"						:	"0px auto"
			});
			$("#lien_club_canderel").css({
				"width"							:	"194px"
			});
			$("#lien_club_canderel img").css({
				"float"							:	"left"
			});
			$("#erreur_center").css({
				"padding"						:	"10px 0 0 0"
			});
			$("#contenu_centre").css({
				"margin-left"						:	"100px"
			});

		}else if( Math.abs( parseInt( $.browser.version ) ) <= 7  ){

			if( LANGAGE == "PT" )
			{
// DEBUT CSS CORRIGE IE7

$(".produit_resume .float_left").css({
	"width"					:	"300px"
});

$(".produit_resume .float_right").css({
	"width"					:	"150px"
});


// FIN CSS CORRIGE IE7
			}

		}else if( Math.abs( parseInt( $.browser.version ) ) <= 8  ){

			if( LANGAGE == "PT" )
			{
// DEBUT CSS CORRIGE IE8



// FIN CSS CORRIGE IE8
			}

		}else{

			$("#menu li").css({
				"line-height"					:	"38px"
			});
			$(".input_stylise").css({
				"margin"						:	"0px"
			});
			$("#adresse_boite").css({
				"margin-left"					:	"16px"
			});
			$("#adresse_ville").css({
				"padding-left"					:	"10px"
			});

		}

	}

}


/* Fonction ajax qui permet de sauvegarder les réponses */
function saveReponse(lng) {
	
	repNutri = $("#repNutri").val();
	if ( repNutri != "" ) {
		
		$.ajax({ type: "post",url: "/ajax.php",
			data: {choix:'sauvReponse',lng:lng,repNutri:repNutri}, 
			success: function(res) { 
				if ( res == '' ) alert("Réponse enregistrée");
			} 
		});	
				
	} // fin de la vérification
}

/* Fonction ajax qui permet de sauvegarder les réponses */
function recupReponse(lng) {
			
		$.ajax({ type: "post",url: "/ajax.php",
			data: {choix:'recupReponse',lng:lng}, 
			success: function(res) { 
				$("#listeReponses").html(res);
				$("#listeReponses").css("display","block");
			} 
		});	
				
}

/* Fonction ajax qui permet de sauvegarder les réponses */
function selectReponse(id) {
			
		$.ajax({ type: "post",url: "/ajax.php",
			data: {choix:'selectReponse',id:id}, 
			success: function(res) { 
				$("#listeReponses").css("display","none");
				$("#repNutri").html(res);
			} 
		});	
				
}

/* Fonction ajax qui permet de sauvegarder les réponses */
function suppReponse(id) {
			
		$.ajax({ type: "post",url: "/ajax.php",
			data: {choix:'suppReponse',id:id}, 
			success: function(res) { 
				$("#rep_"+id).remove();
			} 
		});	
				
}

function fermerAjourRep() {
	$("#listeReponses").css("display","none");
}

document.hide_popup			=	function(){
	hide_popup();
};
