function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
	while(1) 
	{
		curleft += obj.offsetLeft;
		if(!obj.offsetParent)
			break;
		obj = obj.offsetParent;
	}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

// Trouve le Y des images (s'adapte au changement de rsolution)
function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	while(1)
	{
		curtop += obj.offsetTop;
		if(!obj.offsetParent)
			break;
		obj = obj.offsetParent;
	}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

function openMenu()
{
	var nav = navigator.appName;
	if (nav == "Microsoft Internet Explorer")
	{
		document.getElementById('fic_nutr_1').style.display="block";
	}
	else
	{
		menuSlide(1);
	}
}

function menuSlide(menu_)
{
		var i = menu_;
		var nav = navigator.appName;
		if(nav == "Microsoft Internet Explorer")
			var navigateur = 1;
		else
			var navigateur = 2;
		switch(i)
		{
			case 1:
			if(document.getElementById('fic_nutr_1').style.display=="block")
			{
				if(navigateur == 2)
					$('#left #fic_nutr_1').slideUp("normal");
				else
					document.getElementById('fic_nutr_1').style.display="none";
				$('#left #fiche_nutrition_1 .title').css("background", "url(img/fleche.png) no-repeat left #ff8212");	
			}
			else
			{
				$('#left #fiche_nutrition_1 .title').css("background", "url(img/flechebas.png) no-repeat left #ff8212");
				$('#left #fiche_nutrition_2 .title').css("background", "url(img/fleche.png) no-repeat left #ff8136");
				$('#left #fiche_nutrition_3 .title').css("background", "url(img/fleche.png) no-repeat left #ffb64b");
				$('#left #fiche_nutrition_4 .title').css("background", "url(img/fleche.png) no-repeat left #ff784b");
				$('#left #fiche_nutrition_5 .title').css("background", "url(img/fleche.png) no-repeat left #ffa913");
				$('#left #fiche_nutrition_6 .title').css("background", "url(img/fleche.png) no-repeat left #ff8136");
				if(navigateur == 2)
				{
					$('#left #fic_nutr_1').slideDown("normal");
					$('#left #fic_nutr_2').slideUp("normal");
					$('#left #fic_nutr_3').slideUp("normal");
					$('#left #fic_nutr_4').slideUp("normal");
					$('#left #fic_nutr_5').slideUp("normal");
					$('#left #fic_nutr_6').slideUp("normal");
				}
				else
				{
					document.getElementById('fic_nutr_1').style.display="block";
					document.getElementById('fic_nutr_2').style.display="none";
					document.getElementById('fic_nutr_3').style.display="none";
					document.getElementById('fic_nutr_4').style.display="none";
					document.getElementById('fic_nutr_5').style.display="none";
					document.getElementById('fic_nutr_6').style.display="none";
				}	
			}
			if (nav != "Microsoft Internet Explorer") setTimeout("menuSlide(2)",5000);
			break;
			
			case 2:
			if(document.getElementById('fic_nutr_2').style.display=="block")
			{
				if(navigateur == 2)
					$('#left #fic_nutr_2').slideUp("normal");
				else
					document.getElementById('fic_nutr_2').style.display="none";
				$('#left #fiche_nutrition_2 .title').css("background", "url(img/fleche.png) no-repeat left #ff8136");	
			}
			else
			{
				$('#left #fiche_nutrition_1 .title').css("background", "url(img/fleche.png) no-repeat left #ff8212");
				$('#left #fiche_nutrition_2 .title').css("background", "url(img/flechebas.png) no-repeat left #ff8136");
				$('#left #fiche_nutrition_3 .title').css("background", "url(img/fleche.png) no-repeat left #ffb64b");
				$('#left #fiche_nutrition_4 .title').css("background", "url(img/fleche.png) no-repeat left #ff784b");
				$('#left #fiche_nutrition_5 .title').css("background", "url(img/fleche.png) no-repeat left #ffa913");
				$('#left #fiche_nutrition_6 .title').css("background", "url(img/fleche.png) no-repeat left #ff8136");
				if(navigateur == 2)
				{
					$('#left #fic_nutr_1').slideUp("normal");
					$('#left #fic_nutr_2').slideDown("normal");
					$('#left #fic_nutr_3').slideUp("normal");
					$('#left #fic_nutr_4').slideUp("normal");
					$('#left #fic_nutr_5').slideUp("normal");
					$('#left #fic_nutr_6').slideUp("normal");
				}
				else
				{
					document.getElementById('fic_nutr_1').style.display="none";
					document.getElementById('fic_nutr_2').style.display="block";
					document.getElementById('fic_nutr_3').style.display="none";
					document.getElementById('fic_nutr_4').style.display="none";
					document.getElementById('fic_nutr_5').style.display="none";
					document.getElementById('fic_nutr_6').style.display="none";
				}	
			}
			if (nav != "Microsoft Internet Explorer") setTimeout("menuSlide(3)",5000);
			break;
			
			case 3:
			if(document.getElementById('fic_nutr_3').style.display=="block")
			{
				$('#left #fiche_nutrition_3 .title').css("background", "url(img/fleche.png) no-repeat left #ffb64b");
				if(navigateur == 2)
					$('#left #fic_nutr_3').slideUp("normal");
				else
					document.getElementById('fic_nutr_3').style.display="none";
			}
			else
			{
				$('#left #fiche_nutrition_1 .title').css("background", "url(img/fleche.png) no-repeat left #ff8212");
				$('#left #fiche_nutrition_2 .title').css("background", "url(img/fleche.png) no-repeat left #ff8136");
				$('#left #fiche_nutrition_3 .title').css("background", "url(img/flechebas.png) no-repeat left #ffb64b");
				$('#left #fiche_nutrition_4 .title').css("background", "url(img/fleche.png) no-repeat left #ff784b");
				$('#left #fiche_nutrition_5 .title').css("background", "url(img/fleche.png) no-repeat left #ffa913");
				$('#left #fiche_nutrition_6 .title').css("background", "url(img/fleche.png) no-repeat left #ff8136");
				if(navigateur == 2)
				{
					$('#left #fic_nutr_1').slideUp("normal");
					$('#left #fic_nutr_2').slideUp("normal");
					$('#left #fic_nutr_3').slideDown("normal");
					$('#left #fic_nutr_4').slideUp("normal");
					$('#left #fic_nutr_5').slideUp("normal");
					$('#left #fic_nutr_6').slideUp("normal");
				}
				else
				{
					document.getElementById('fic_nutr_1').style.display="none";
					document.getElementById('fic_nutr_2').style.display="none";
					document.getElementById('fic_nutr_3').style.display="block";
					document.getElementById('fic_nutr_4').style.display="none";
					document.getElementById('fic_nutr_5').style.display="none";
					document.getElementById('fic_nutr_6').style.display="none";
				}					
			}
			if (nav != "Microsoft Internet Explorer") setTimeout("menuSlide(4)",5000);
			break;
			
			case 4:
			if(document.getElementById('fic_nutr_4').style.display=="block")
			{
				if(navigateur == 2)
					$('#left #fic_nutr_4').slideUp("normal");
				else
					document.getElementById('fic_nutr_4').style.display="none";
				$('#left #fiche_nutrition_4 .title').css("background", "url(img/fleche.png) no-repeat left #ff784b");	
			}
			else
			{
				$('#left #fiche_nutrition_1 .title').css("background", "url(img/fleche.png) no-repeat left #ff8212");
				$('#left #fiche_nutrition_2 .title').css("background", "url(img/fleche.png) no-repeat left #ff8136");
				$('#left #fiche_nutrition_3 .title').css("background", "url(img/fleche.png) no-repeat left #ffb64b");
				$('#left #fiche_nutrition_4 .title').css("background", "url(img/flechebas.png) no-repeat left #ff784b");
				$('#left #fiche_nutrition_5 .title').css("background", "url(img/fleche.png) no-repeat left #ffa913");
				$('#left #fiche_nutrition_6 .title').css("background", "url(img/fleche.png) no-repeat left #ff8136");
				if(navigateur == 2)
				{
					$('#left #fic_nutr_1').slideUp("normal");
					$('#left #fic_nutr_2').slideUp("normal");
					$('#left #fic_nutr_3').slideUp("normal");
					$('#left #fic_nutr_4').slideDown("normal");
					$('#left #fic_nutr_5').slideUp("normal");
					$('#left #fic_nutr_6').slideUp("normal");
				}
				else
				{
					document.getElementById('fic_nutr_1').style.display="none";
					document.getElementById('fic_nutr_2').style.display="none";
					document.getElementById('fic_nutr_3').style.display="none";
					document.getElementById('fic_nutr_4').style.display="block";
					document.getElementById('fic_nutr_5').style.display="none";
					document.getElementById('fic_nutr_6').style.display="none";
				}
			}
			if (nav != "Microsoft Internet Explorer") setTimeout("menuSlide(5)",5000);
			break;
			
			case 5:
			if(document.getElementById('fic_nutr_5').style.display=="block")
			{
				if(navigateur==2)
					$('#left #fic_nutr_5').slideUp("normal");
				else
					document.getElementById('fic_nutr_5').style.display="none";
				$('#left #fiche_nutrition_5 .title').css("background", "url(img/fleche.png) no-repeat left #ffa913");	
			}
			else
			{
				$('#left #fiche_nutrition_1 .title').css("background", "url(img/fleche.png) no-repeat left #ff8212");
				$('#left #fiche_nutrition_2 .title').css("background", "url(img/fleche.png) no-repeat left #ff8136");
				$('#left #fiche_nutrition_3 .title').css("background", "url(img/fleche.png) no-repeat left #ffb64b");
				$('#left #fiche_nutrition_4 .title').css("background", "url(img/fleche.png) no-repeat left #ff784b");
				$('#left #fiche_nutrition_5 .title').css("background", "url(img/flechebas.png) no-repeat left #ffa913");
				$('#left #fiche_nutrition_6 .title').css("background", "url(img/fleche.png) no-repeat left #ff8136");
				if(navigateur==2)
				{
					$('#left #fic_nutr_1').slideUp("normal")
					$('#left #fic_nutr_2').slideUp("normal");
					$('#left #fic_nutr_3').slideUp("normal");
					$('#left #fic_nutr_4').slideUp("normal");
					$('#left #fic_nutr_5').slideDown("normal");
					$('#left #fic_nutr_6').slideUp("normal");
				}
				else
				{
					document.getElementById('fic_nutr_1').style.display="none";
					document.getElementById('fic_nutr_2').style.display="none";
					document.getElementById('fic_nutr_3').style.display="none";
					document.getElementById('fic_nutr_4').style.display="none";
					document.getElementById('fic_nutr_5').style.display="block";
					document.getElementById('fic_nutr_6').style.display="none";
				}
			}
			if (nav != "Microsoft Internet Explorer") setTimeout("menuSlide(6)",5000);
			break;	
			
			case 6:
			if(document.getElementById('fic_nutr_6').style.display=="block")
			{
				if(navigateur==2)
					$('#left #fic_nutr_6').slideUp("normal");
				else
					document.getElementById('fic_nutr_5').style.display="none";
				$('#left #fiche_nutrition_6 .title').css("background", "url(img/fleche.png) no-repeat left #ff8136");	
			}
			else
			{
				$('#left #fiche_nutrition_1 .title').css("background", "url(img/fleche.png) no-repeat left #ff8212");
				$('#left #fiche_nutrition_2 .title').css("background", "url(img/fleche.png) no-repeat left #ff8136");
				$('#left #fiche_nutrition_3 .title').css("background", "url(img/fleche.png) no-repeat left #ffb64b");
				$('#left #fiche_nutrition_4 .title').css("background", "url(img/fleche.png) no-repeat left #ff784b");
				$('#left #fiche_nutrition_5 .title').css("background", "url(img/fleche.png) no-repeat left #ffa913");
				$('#left #fiche_nutrition_6 .title').css("background", "url(img/flechebas.png) no-repeat left #ff8136");
				if(navigateur==2)
				{
					$('#left #fic_nutr_1').slideUp("normal");
					$('#left #fic_nutr_2').slideUp("normal");
					$('#left #fic_nutr_3').slideUp("normal");
					$('#left #fic_nutr_4').slideUp("normal");
					$('#left #fic_nutr_5').slideUp("normal");
					$('#left #fic_nutr_6').slideDown("normal");
				}
				else
				{
					document.getElementById('fic_nutr_1').style.display="none";
					document.getElementById('fic_nutr_2').style.display="none";
					document.getElementById('fic_nutr_3').style.display="none";
					document.getElementById('fic_nutr_4').style.display="none";
					document.getElementById('fic_nutr_5').style.display="none";
					document.getElementById('fic_nutr_6').style.display="block";
				}
			}
			if (nav != "Microsoft Internet Explorer") setTimeout("menuSlide(1)",5000);
			break;				
		}
}
		
function changeTypeTruc(type_)
{
	switch(type_)
	{
		case 1:
		window.location = "index.php?app=4&id=1";
		break;
		
		case 2:
		window.location = "index.php?app=4&id=2";
		break;		
	}
}

function openDefinition(num_)
{
	if(document.getElementById('def'+num_).style.display =="none")
	{
		document.getElementById('def'+num_).style.display = "block";
		document.getElementById('title_'+num_).style.fontWeight = "bold";
		document.getElementById('title_'+num_).style.color = "#A1C700";
		
	}
	else
	{
		document.getElementById('def'+num_).style.display = "none";
		document.getElementById('title_'+num_).style.fontWeight = "normal";
		document.getElementById('title_'+num_).style.color = "#CF0615";
	}
	document.getElementById('defId').value = num_;
	for(z=1;z<=500;z++)
	{
		if(z!=num_ && document.getElementById('def'+z))
		{
			document.getElementById('def'+z).style.display = "none";
			document.getElementById('title_'+z).style.fontWeight = "normal";
			document.getElementById('title_'+z).style.color = "#CF0615";			
		}
	}
	
}

function verifForm()
{
	var auteur = document.getElementById('tru_auteur').value;
	var truc = document.getElementById('fcktru_corps').value;
	var title = document.getElementById('tru_title').value;
	
	if(auteur == "" || truc == "" || title == "")
		alert("Vous devez remplir tous les champs");
	else
		document.form_truc.submit();
}

function openLogin()
{
	document.getElementById("blocklogin").style.display = "block";
	document.getElementById("blocklogin").style.left = (findPosX(document.getElementById("form_trucs")) + 60);
	document.getElementById("blocklogin").style.top =  (findPosY(document.getElementById("form_trucs")) + 150);	
}

function addFavorites(idfav,table_)
{
	switch(table_)
	{
		case "Articles":
		window.location = 'index.php?app=15&tab=1&fav='+idfav;
		break;

		case "Definitions":
		window.location = 'index.php?app=15&tab=6&fav='+idfav;
		break;
		
		case "Fiches":
		window.location = 'index.php?app=15&tab=3&fav='+idfav;
		break;		
		
		case "Quizz":
		window.location = 'index.php?app=15&tab=2&fav='+idfav;
		break;

	case "Trucs":
		window.location = 'index.php?app=15&tab=5&fav='+idfav;
		break;		
	}
}

function supTrucs(num_)
{
	reponse=confirm('Etes vous sur de vouloir supprimer cette ligne ?');
	if (reponse==true)
	{
		window.location="index.php?app=10&opt=1&sup="+num_;
	}
}


function supFavoris(num_,table_)
{
	reponse=confirm('Etes vous sur de vouloir supprimer ce favori de votre compte ?');
	if (reponse==true)
	{
		switch(table_)
		{
			case "Articles":
			window.location="index.php?app=11&suppr="+num_;
			break;

			case "Definitions":
			window.location="index.php?app=12&suppr="+num_;
			break;

			case "Fiches":
			window.location="index.php?app=13&suppr="+num_;
			break;
			
			case "Quizz":
			window.location="index.php?app=16&suppr="+num_;
			break;

			case "Trucs":
			window.location="index.php?app=10&opt=2&suppr="+num_;
			break;
		}
		
	}
}

function checkFormForget()
{
	var error = 0;
	if(document.frm_forget.email.value == "")
		error = 1;
	
	switch(error)
	{
		case 0:
			// On valide le formulaire
			document.frm_forget.submit();
			break;
			
		case 1:
			alert("Veuillez remplir le champ email");
			break;

	}
}

function showCateg()
{
	var nav = navigator.appName;
	if (nav == "Microsoft Internet Explorer")
	{
		document.getElementById("menu_scateg").style.display = "block";
		document.getElementById("menu_scateg").style.left = (findPosX(document.getElementById("menu_center")) + 520);
		document.getElementById("menu_scateg").style.top =  (findPosY(document.getElementById("menu_center")) + 30);
	}
	else
	{
		document.getElementById("menu_scateg").style.display = "block";
		document.getElementById("menu_scateg").style.left = (findPosX(document.getElementById("menu_center")) + 520);
		document.getElementById("menu_scateg").style.top =  (findPosY(document.getElementById("menu_center")) + 30);
	}

}

function validFormQuizz()
{
	var error = 0;
	if(document.frm_quizz.rep_1[0].checked == false && document.frm_quizz.rep_1[1].checked == false)	
		error = error + 1;
	if(document.frm_quizz.rep_2[0].checked == false && document.frm_quizz.rep_2[1].checked == false)	
		error = error + 1;		
	if(document.frm_quizz.rep_3[0].checked == false && document.frm_quizz.rep_3[1].checked == false)	
		error = error + 1;		
	if(document.frm_quizz.rep_4[0].checked == false && document.frm_quizz.rep_4[1].checked == false)	
		error = error + 1;
	if(document.frm_quizz.rep_5[0].checked == false && document.frm_quizz.rep_5[1].checked == false)	
		error = error + 1;
		
	if(error==0)
		document.frm_quizz.submit();
	else
		alert("Vous n'avez pas répondu à toutes les questions du quizz!!!");
}

