/*-----------------------------------------------------------------------------------
-- Nom Fichier :		fonctions.js
-- Date de creation :	25.08.10
-- Version :			0.0
-- Auteur :			Jérôme BARBOTIN
--------------------------------------------------------------------------------------
-- Role : Permet de traiter différentes fonctions javascript
--------------------------------------------------------------------------------------
-- Versions
-- Version : 	0.0		Jérôme Barbotin			Création
    --------------------------------------------------------------------------------*/
function deroulDiv(divInit,divID,speed)
{
	var tempo;
	if (speed < 0) return;
	tailleActuelle = document.getElementById(divID).offsetHeight;
	tailleActuelleInt = parseInt(tailleActuelle);
	if (tailleActuelleInt >= divInit)
	{
		clearTimeout(tempo); 
		document.getElementById(divID).style.height=divInit+"px"; 
		return; 
	}
	y = (tailleActuelleInt + speed);
	document.getElementById(divID).style.height=y+"px";
	tempo = setTimeout(function(){deroulDiv(divInit,divID,speed)}, 30);
}
function permalink(m)
{
	var divID = 'sousMenuArticleDialog';
	afficheZoneDiv(divID);
	document.getElementById(divID).innerHTML = 'http://www.ada-ensib.com/article' + m;
	divHeight = document.getElementById(divID).offsetHeight;
	document.getElementById(divID).style.height="0";
	afficheZoneDiv(divID);
	speed = ((divHeight/12)+8);
	deroulDiv(divHeight,divID,speed);
	setTimeout(function(){cacheZoneDiv('sousMenuArticleDialog');}, 10000);
}

function pdfiser(m)
{
	var divID = 'sousMenuArticleDialog';
	afficheZoneDiv(divID);
	document.getElementById(divID).innerHTML = 'Fonction non disponible pour le moment.';
	divHeight = document.getElementById(divID).offsetHeight;
	document.getElementById(divID).style.height="0";
	speed = ((divHeight/12)+8);
	deroulDiv(divHeight,divID,speed);
	setTimeout(function(){cacheZoneDiv('sousMenuArticleDialog');}, 10000);
}
function ouvrirFirstPlanFrame(widthFPF, heightFPF)
{
    if(!widthFPF) widthFPF=300;
    if(!heightFPF) heightFPF=300;
	afficheZoneDiv('firstPlanFrame');
	afficheZoneDiv('firstPlanBackground');

	document.getElementById('firstPlanFrame').style.width = widthFPF + 'px';
	document.getElementById('firstPlanFrame').style.height = heightFPF + 'px';
	document.getElementById('firstPlanFrame').style.zIndex = 9999;
	document.getElementById('firstPlanBackground').style.zIndex = 9998;
	document.getElementById('firstPlanBackground').style.width = '100%';
	document.getElementById('firstPlanBackground').style.height = '100%';
	var a = document.width;
	var c = document.height;
	var e = document.getElementById('firstPlanBackground').offsetWidth;
	var b = document.getElementById('firstPlanFrame').offsetWidth;
	document.getElementById('firstPlanFrame').style.left = (e-b)/2 + 'px';
	var f = document.getElementById('firstPlanBackground').offsetHeight;
	var d = document.getElementById('firstPlanFrame').offsetHeight;
	document.getElementById('firstPlanFrame').style.top = (f-d)/2 + 'px';
	if(a > e)
		document.getElementById('firstPlanBackground').style.width = a + 'px';
	else
		document.getElementById('firstPlanBackground').style.width = e + 'px';
	if(c > f)
		document.getElementById('firstPlanBackground').style.height = c + 'px';
	else
		document.getElementById('firstPlanBackground').style.height = f + 'px';
}
function mailer(m)
{	
	ouvrirFirstPlanFrame();
	var xhr = getXMLHTTP();
	xhr.onreadystatechange = function()
	{
		// 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)
		{
			truc = xhr.responseText;
			document.getElementById('firstPlanFrameContenu').innerHTML = truc;
		}
	}
	// Ici on va voir comment faire du post
	xhr.open("POST","../../pages/mailer.php",true);
	// ne pas oublier ça pour le post
	xhr.setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
	xhr.send("m=" + m);
}

function contactBox()
{	
	ouvrirFirstPlanFrame();
	var xhr = getXMLHTTP();
	xhr.onreadystatechange = function()
	{
		// 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)
		{
			truc = xhr.responseText;
			document.getElementById('firstPlanFrameContenu').innerHTML = truc;
		}
	}
	// Ici on va voir comment faire du post
	xhr.open("POST","../../pages/contact.php",true);
	// ne pas oublier ça pour le post
	xhr.setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
	xhr.send("");
}

function mentionsLegalesBox()
{	
	ouvrirFirstPlanFrame(500,300);
	var xhr = getXMLHTTP();
	xhr.onreadystatechange = function()
	{
		// 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)
		{
			truc = xhr.responseText;
			document.getElementById('firstPlanFrameContenu').innerHTML = truc;
		}
	}
	// Ici on va voir comment faire du post
	xhr.open("POST","../../pages/mentions_legales.php",true);
	// ne pas oublier ça pour le post
	xhr.setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
	xhr.send("");
}
function fermerFirstPlanFrame()
{
	cacheZoneDiv('firstPlanFrame');
	cacheZoneDiv('firstPlanBackground');
	document.getElementById('firstPlanFrame').style.zIndex = 0;
	document.getElementById('firstPlanBackground').style.zIndex = 0;
	document.getElementById('firstPlanFrameContenu').innerHTML = '';
}
function repertoireAnciens()
{
	ouvrirFirstPlanFrame();
	var xhr = getXMLHTTP();
	xhr.onreadystatechange = function()
	{
		// 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)
		{
			truc = xhr.responseText;
			document.getElementById('firstPlanFrameContenu').innerHTML = truc;
		}
	}
	// Ici on va voir comment faire du post
	xhr.open("POST","../../pages/repertoire.php",true);
	// ne pas oublier ça pour le post
	xhr.setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
	xhr.send("");
}
function envoyerRepertoire()
{
	var nom = document.getElementById("nomRechercheMembre").value;
	var prenom = document.getElementById("prenomRechercheMembre").value;
	if(nom!="" && prenom!="")
	{
		var xhr = getXMLHTTP();
		xhr.onreadystatechange = function()
		{
			// 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)
			{
				doc = xhr.responseText;
				document.getElementById('firstPlanFrameContenu').innerHTML = doc;
			}
		}
		xhr.open("POST","./pages/repertoire.php",true);
		xhr.setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
		xhr.send("option=rechercher&prenomRechercheMembre="+prenom+"&nomRechercheMembre="+nom);
	}
	else
	{
		document.getElementById("nomRechercheMembre").style.border="";
		document.getElementById("erreurNom").innerHTML="";
		document.getElementById("prenomRechercheMembre").style.border="";
		document.getElementById("erreurPrenom").innerHTML="";
		if(nom=="")
		{
			document.getElementById("nomRechercheMembre").style.border="2px solid red";
			document.getElementById("erreurNom").innerHTML="Le champ 'Nom' est obligatoire";
		}
		if(prenom=="")
		{
			document.getElementById("prenomRechercheMembre").style.border="2px solid red";
			document.getElementById("erreurPrenom").innerHTML="Le champ 'Prénom' est obligatoire";
		}
	}	
	return false;
}
function envoyerMail(m)
{
	var from = document.getElementById("mailExpediteur").value;
	var to = document.getElementById("mailDestinataire").value;
	var sujet = document.getElementById("mailSujet").value;
	if(from!="" && to!="" && sujet!="" && m!="")
	{
		var xhr = getXMLHTTP();
		xhr.onreadystatechange = function()
		{
			// 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)
			{
				doc = xhr.responseText;
				document.getElementById('firstPlanFrameContenu').innerHTML = doc;
			}
		}
		xhr.open("POST","./pages/mailer.php",true);
		xhr.setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
		xhr.send("option=envoyer&mailExpediteur="+from+"&mailDestinataire="+to+"&mailSujet="+sujet+"&m="+m);
	}
	else
	{
		document.getElementById("mailExpediteur").style.border="";
		document.getElementById("erreurMailExpediteur").innerHTML="";
		document.getElementById("mailDestinataire").style.border="";
		document.getElementById("erreurMailDestinataire").innerHTML="";
		document.getElementById("mailSujet").style.border="";
		document.getElementById("erreurSujet").innerHTML="";
		if(from=="")
		{
			document.getElementById("mailExpediteur").style.border="2px solid red";
			document.getElementById("erreurMailExpediteur").innerHTML="Le champ 'Votre e-mail' est obligatoire";
		}
		if(to=="")
		{
			document.getElementById("mailDestinataire").style.border="2px solid red";
			document.getElementById("erreurMailDestinataire").innerHTML="Le champ 'E-mail du destinataire' est obligatoire";
		}
		if(sujet=="")
		{
			document.getElementById("mailSujet").style.border="2px solid red";
			document.getElementById("erreurSujet").innerHTML="Le champ 'Sujet' est obligatoire";
		}
	}
	return false;
}

