var xmlHttp;

var maxDayPerMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var monthStr = ['janvier', 'février', 'mars', 'avril', 'mai', 'juin',
	'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'];

function showMember(str) { 
	if(xmlHttp == null) {
	  xmlHttp=GetXmlHttpObject();
	}
  if(xmlHttp == null) {
    alert ("Your browser does not support AJAX!");
    return;
  } 

  var url="getMembers.php";
  url=url+"?idListe="+str;
  url=url+"&nocache="+Math.random();
  xmlHttp.onreadystatechange=function () {
	  if (xmlHttp.readyState==4) {
			document.getElementById("Membres").innerHTML = xmlHttp.responseText;
			updateSideLength();
	  }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function GetXmlHttpObject() {
  var xmlHttp=null;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  } catch (e) {
    // Internet Explorer
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

function setMyURL(form) {
  if(form.nom.value == "") {
    alert("Veuillez indiquer le nom de la personne.");
		return false;
	}
  if(form.email.value == "") {
    alert("Veuillez indiquer l'e-mail de la personne.");
		return false;
	}
	form.url.value = form.url.value + '&nom=' + escape(form.nom.value) + '&email=' + escape(form.email.value);
	return true;
}

function getActualiteList(archive, typeActu) { 
	if(xmlHttp == null) {
	  xmlHttp=GetXmlHttpObject();
	}
  if(xmlHttp == null) {
    alert ("Your browser does not support AJAX!");
    return;
  } 

  var url="getActualiteList.php";
  url=url+"?archive="+archive;
  url=url+"&type="+typeActu;
  url=url+"&nocache="+Math.random();
  xmlHttp.onreadystatechange=function () {
	  if (xmlHttp.readyState==4) {
			document.getElementById("actualiteList").innerHTML = xmlHttp.responseText;
			showEmptyActualite();
	  }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function showActualite(idActu, auteur, statut, creation, titre, jourF, moisF, anneeF, heureF, minutesF, jourT, moisT, anneeT, heureT, minutesT, lieu, descr, shortDesc) {
	var actuForm = document.getElementById("actuForm");
	actuForm.idActu.value = idActu;
	actuForm.auteur.value = auteur;
	actuForm.statut.value = statut;
	actuForm.creation.value = creation;
	actuForm.titre.value = titre;
	actuForm.jourFrom.value = jourF;
	actuForm.moisFrom.value = moisF;
	actuForm.anneeFrom.value = anneeF;
	actuForm.heureFrom.value = heureF;
	actuForm.minutesFrom.value = minutesF;
	actuForm.jourTo.value = jourT;
	actuForm.moisTo.value = moisT;
	actuForm.anneeTo.value = anneeT;
	actuForm.heureTo.value = heureT;
	actuForm.minutesTo.value = minutesT;
	actuForm.lieu.value = lieu;
	actuForm.shortDesc.value = shortDesc;
  if(statut < 2) {
  	actuForm.sauve.style.display = "inline";
  	actuForm.publie.style.display = "inline";
  	actuForm.visualise.style.display = "inline";
  	if(idActu > 0) {
  		actuForm.nouveau.style.display = "inline";
  		actuForm.copie.style.display = "inline";
  		actuForm.detruit.style.display = "inline";
  	} else {
  		actuForm.nouveau.style.display = "none";
  		actuForm.copie.style.display = "none";
  		actuForm.detruit.style.display = "none";
  	}
  	actuForm.reactive.style.display = "none";
  } else {
  	actuForm.sauve.style.display = "none";
  	actuForm.publie.style.display = "none";
  	actuForm.visualise.style.display = "none";
		actuForm.nouveau.style.display = "inline";
		actuForm.copie.style.display = "inline";
  	actuForm.detruit.style.display = "none";
  	actuForm.reactive.style.display = "inline";
  }
  FCKeditorAPI.GetInstance("description").SetHTML(descr);
}

function showEmptyActualite() {
	showActualite(0, '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')
}

function copyActualite() {
	var actuForm = document.getElementById("actuForm");
	showActualite(0, actuForm.auteur.value, 0, '', actuForm.titre.value, '', '', '', actuForm.heureFrom.value, actuForm.minutesFrom.value, '', '', '', '', '', actuForm.lieu.value, FCKeditorAPI.GetInstance("description").GetXHTML(true), actuForm.shortDesc.value);
	alert("L'actualité a été copiée, veuillez indiquer de nouvelles dates.");
}

function selectAction(bouton) {
	var actuForm = document.getElementById("actuForm");
	actuForm.execute.value = bouton.name;
	actuForm.submit();
}

function mouseClick(ligne) {
	var lignes = document.getElementsByName("actuLigne");
	for(i=0; i<lignes.length; i++) {
		if(lignes[i] == ligne) {
			lignes[i].style.fontWeight="bold";
		} else {
			lignes[i].style.fontWeight="normal";
		}
	}
}

function previewActualite() {
	var actuForm = document.getElementById("actuForm");
	var preview = document.getElementById("innerPreviewBox");
	var dateStr = '';
	if(((actuForm.jourFrom.value == actuForm.jourTo.value) &&
		  (actuForm.moisFrom.value == actuForm.moisTo.value) &&
		  (actuForm.anneeFrom.value == actuForm.anneeTo.value) &&
		  (actuForm.heureFrom.value == actuForm.heureTo.value) &&
		  (actuForm.minutesFrom.value == actuForm.minutesTo.value)) ||
		 ((actuForm.jourTo.value == '') &&
		  (actuForm.moisTo.value == '') &&
		  (actuForm.anneeTo.value == '') &&
		  (actuForm.heureTo.value == '') &&
		  (actuForm.minutesTo.value == ''))) {
		dateStr = actuForm.jourFrom.value + ' ' +
			monthStr[actuForm.moisFrom.value - 1] + ' ' +
			actuForm.anneeFrom.value + ' à ' +
			actuForm.heureFrom.value + 'h' + actuForm.minutesFrom.value;
	} else {
		dateStr = 'du ' + actuForm.jourFrom.value + ' ' +
			monthStr[actuForm.moisFrom.value - 1] + ' ' +
			actuForm.anneeFrom.value + ' au ' + actuForm.jourTo.value + ' ' +
			monthStr[actuForm.moisTo.value - 1] + ' ' +
			actuForm.anneeTo.value;
	}
	preview.innerHTML = '<h2>' + actuForm.titre.value + '</h2>' +
		'<p><b>Date :</b> ' + dateStr + '</p>' +
		'<p><b>Lieu :</b> ' + actuForm.lieu.value + '</p>' +
		'<p>' + FCKeditorAPI.GetInstance("description").GetXHTML(true) + '</p>';
	showBox('previewBox', 'innerPreviewBox');
}

function displayActu(idActu) { 
	if(xmlHttp == null) {
	  xmlHttp=GetXmlHttpObject();
	}
  if(xmlHttp == null) {
    alert ("Your browser does not support AJAX!");
    return;
  } 

  var url="getActualite.php";
  url=url + "?idActu=" + idActu;
  url=url+"&nocache="+Math.random();
  xmlHttp.onreadystatechange=function () {
	  if (xmlHttp.readyState==4) {
			document.getElementById("innerPreviewBox").innerHTML = xmlHttp.responseText;
			showBox('previewBox', 'innerPreviewBox');
	  }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}
