//url_base = "http://www.generationcampus.com";
url_base = "http://www.generationcampus.com";

function changecom() 
{

 document.getElementById('faire_commentaire').className="tumevois";
  document.getElementById('faire_commentaire1').className="tumevois";
  document.getElementById('faire_commentaire2').className="tumevois";

 document.form_commentaire.texte.rows = 10;

}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-,";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

function VerificationEmail(elm) {
	if (elm.value.indexOf("@") != "-1" &&
		elm.value.indexOf(".") != "-1" &&
		elm.value != "")
		return true;
	
	return false;
}




// Module Formations

function maj_filiere(domaine) {
	//alert("maj_filiere domaine=" + domaine);
	var xhr=null;
    
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt
	url = url_base + "/formations/filiere_get_options.php?domaine=" + domaine;
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	pieces = resultat.split("#");
	//alert("resultat=" + resultat);
	nb_options = document.form_formations.formations_filiere.options.length;
	// Vider les options existantes
	for (f=0;f<nb_options;f++) {
		document.form_formations.formations_filiere.options[f] = null;
		
	}
	nb_options = pieces.length / 2;
	for (f=0;f<nb_options;f++) {
		document.form_formations.formations_filiere.options[f] = new Option(pieces[f + nb_options],pieces[f]);
		
	}
}

function maj_filiere_compte(domaine) {
	//alert("maj_filiere domaine=" + domaine);
	var xhr=null;
    
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt
	url = url_base + "/formations/filiere_get_options.php?domaine=" + domaine;
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	pieces = resultat.split("#");
	//alert("resultat=" + resultat);
	nb_options = document.form_membre.filiere.options.length;
	// Vider les options existantes
	for (f=0;f<nb_options;f++) {
		document.form_membre.filiere.options[f] = null;
		
	}
	nb_options = pieces.length / 2;
	for (f=0;f<nb_options;f++) {
		document.form_membre.filiere.options[f] = new Option(pieces[f + nb_options],pieces[f]);
		
	}
}

function maj_specialite(filiere) {
	//alert("maj_specialite filiere=" + filiere);
	var xhr=null;
    
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt
	url = url_base + "/formations/specialite_get_options.php?filiere=" + filiere;
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	pieces = resultat.split("#");
	//alert("resultat=" + resultat);
	nb_options = document.form_formations.formations_specialite.options.length;
	// Vider les options existantes
	for (f=0;f<nb_options;f++) {
		document.form_formations.formations_specialite.options[f] = null;
		
	}
	nb_options = pieces.length / 2;
	for (f=0;f<nb_options;f++) {
		document.form_formations.formations_specialite.options[f] = new Option(pieces[f + nb_options],pieces[f]);
		
	}
}

function maj_specialite_compte(filiere) {
	//alert("maj_specialite filiere=" + filiere);
	var xhr=null;
    
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt
	url = url_base + "/formations/specialite_get_options.php?filiere=" + filiere;
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	pieces = resultat.split("#");
	//alert("resultat=" + resultat);
	nb_options = document.form_membre.specialite.options.length;
	// Vider les options existantes
	for (f=0;f<nb_options;f++) {
		document.form_membre.specialite.options[f] = null;
		
	}
	nb_options = pieces.length / 2;
	for (f=0;f<nb_options;f++) {
		document.form_membre.specialite.options[f] = new Option(pieces[f + nb_options],pieces[f]);
		
	}
}

function maj_formation_compte(specialite) {
	//alert("maj_specialite filiere=" + filiere);
	var xhr=null;
    
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt
	url = url_base + "/formations/formation_get_options.php?specialite=" + specialite;
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	pieces = resultat.split("#");
	//alert("resultat=" + resultat);
	nb_options = document.form_membre.formation.options.length;
	// Vider les options existantes
	for (f=0;f<nb_options;f++) {
		document.form_membre.formation.options[f] = null;
		
	}
	nb_options = pieces.length / 2;
	for (f=0;f<nb_options;f++) {
		document.form_membre.formation.options[f] = new Option(pieces[f + nb_options],pieces[f]);
		
	}
}

function agenda_afficher_detail(id) {
	//alert("agenda_afficher_detail id=" + id);
	var xhr=null;
    
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt
	url = url_base + "/agenda/get_detail.php?id=" + id;
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	document.getElementById(id + "_court").innerHTML = resultat;
}

function agenda_cacher_detail(id) {
	//alert("agenda_cacher_detail id=" + id);
	var xhr=null;
    
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt
	url = url_base + "/agenda/cacher_detail.php?id=" + id;
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	document.getElementById(id + "_court").innerHTML = resultat;
}

// Module Annonces

function maj_annonces_logement(sid) {
	//alert("maj_filiere domaine=" + domaine);
	var xhr=null;
    
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt
	url = url_base + "/commun/bloc_annonces_logement.php?sid=" + sid;
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	
	document.getElementById("bloc_annonces").innerHTML = resultat;
		
}

function maj_annonces_emploi(sid) {
	//alert("maj_filiere domaine=" + domaine);
	var xhr=null;
    
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt
	url = url_base + "/commun/bloc_annonces_emploi.php?sid=" + sid;
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	
	document.getElementById("bloc_annonces").innerHTML = resultat;
		
}

function maj_annonces_diverses(sid) {
	//alert("maj_filiere domaine=" + domaine);
	var xhr=null;
    
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt
	url = url_base + "/commun/bloc_annonces_diverses.php?sid=" + sid;
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	
	document.getElementById("bloc_annonces").innerHTML = resultat;
		
}
function LPad(ContentToSize,PadLength,PadChar)
  {
     var PaddedString=ContentToSize.toString();
     for(i=ContentToSize.length+1;I<=PadLength;i++)
     {
         PaddedString=PadChar+PaddedString;
     }
     return PaddedString;
  }


function afficher_commentaires(sid,id_objet,nom_objet,type) {

			//alert("-"+ id_objet +"");

	 
	var xhr=null;
	//alert(""+ PaddedString +"");
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt
		
		var s = new String(id_objet);
while(s.length< 6) s = "0"+s;
//alert(""+ s +"");			

	url = url_base + "/commun/afficher_commentaires.php?sid=" + sid + "&id_objet=" + s + "&nom_objet=" + nom_objet + "&type=" + type;
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	
	//document.getElementById("bloc_commentaires").innerHTML = resultat; 

	document.getElementById("bloc_commentaires_" + s).innerHTML = resultat;
	return false;
}

function afficher_commentaires2(sid,id_objet,nom_objet,type) {
	var xhr=null;

	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt

	url = url_base + "/commun/afficher_commentaires2.php?sid=" + sid + "&id_objet=" + id_objet + "&nom_objet=" + nom_objet + "&type=" + type;
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	
	//document.getElementById("bloc_commentaires").innerHTML = resultat; 
	document.getElementById("bloc_commentaires_" + id_objet).innerHTML = resultat;
	return false;
}

function ajouter_commentaire() {
	
	if (document.form_commentaire.id_user.value == "0") {
		if (document.form_commentaire.nom.value == "") {
			alert("Nom : champ obligatoire");
			document.form_commentaire.nom.focus();
			return false;
		}
		if (document.form_commentaire.pnom.value == "") {
			alert("Prénom : champ obligatoire");
			document.form_commentaire.pnom.focus();
			return false;
		}
		if (document.form_commentaire.CGU.value == "") {
			alert("Veuillez accepter les Conditions Générales d'utilisation");
			document.form_commentaire.CGU.focus();
			return false;
		}
		if (document.form_commentaire.email.value == "") {
			alert("E-mail : champ obligatoire");
			document.form_commentaire.email.focus();
			return false;
		}
		if (VerificationEmail(document.form_commentaire.email) == false) {
			alert("E-mail : Le format n'est pas correct");
			document.form_commentaire.email.focus();
			return false;
		}
	}
	
	if (document.form_commentaire.texte.value == "") {
		alert("Message : champ obligatoire");
		document.form_commentaire.texte.focus();
		return false;
	}

	//alert("maj_filiere domaine=" + domaine);
	var xhr=null;
    
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt

	url = url_base + "/commun/ajouter_commentaire.php?id_objet=" + document.form_commentaire.id_objet.value + "&nom_objet=" + document.form_commentaire.nom_objet.value + "&type=" + document.form_commentaire.type.value + "&nom=" + document.form_commentaire.nom.value + "&pnom=" + document.form_commentaire.pnom.value + "&email=" + document.form_commentaire.email.value + "&texte=" + document.form_commentaire.texte.value + "&id_user=" + document.form_commentaire.id_user.value;
	//alert("url = " + url);
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	
	
	afficher_commentaires("'" + document.form_commentaire.sid.value + "'",document.form_commentaire.id_objet.value,document.form_commentaire.nom_objet.value,document.form_commentaire.type.value);
	return false;
		
}


function maj_conseil(institution) {
	//alert("maj_specialite filiere=" + filiere);
	var xhr=null;
    
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt
	url = url_base + "/elus/conseil_get_options.php?institution=" + institution;
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	pieces = resultat.split("#");
	//alert("resultat=" + resultat);
	nb_options = document.form_elu.elu_conseil.options.length;
	// Vider les options existantes
	for (f=0;f<nb_options;f++) {
		document.form_elu.elu_conseil.options[f] = null;
		
	}
	nb_options = pieces.length / 2;
	for (f=0;f<nb_options;f++) {
		document.form_elu.elu_conseil.options[f] = new Option(pieces[f + nb_options],pieces[f]);
		
	}
}

function faq_poser_question() {

	if (document.form_faq.question_thematique.selectedIndex == 0) {
		alert("Thématique : veuillez faire votre choix");
		document.form_faq.question_thematique.focus();
		return false;
	}
	
	if (document.form_faq.question.value == "") {
		alert("Question : champ obligatoire");
		document.form_faq.question.focus();
		return false;
	}
	

	//alert("maj_filiere domaine=" + domaine);
	var xhr=null;
    
	if (window.XMLHttpRequest) { 
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on appelle le fichier reponse.txt
	url = url_base + "/elus/poser_question.php?question=" + document.form_faq.question.value + "&thematique=" + document.form_faq.question_thematique.options[document.form_faq.question_thematique.selectedIndex].value + "&id_user=" + document.form_faq.id_user.value;
	//alert("url = " + url);
	xhr.open("GET", url, false);
	xhr.send(null);
	
	resultat = xhr.responseText;
	
	document.getElementById("faq_retour_question").innerHTML = '<img src="../images/faq_bouton_plus.gif" alt="plus" width="15" height="17" align="absmiddle" />&nbsp;<span class="bloc_formations_texte">Votre Question a &eacute;t&eacute; envoy&eacute;e. merci!</span><br><br>';
	document.getElementById("faq_retour_question").style.visibility = "visible";
	document.getElementById("faq_poser_question").style.visibility = "collapse";
	
	return false;
		
}