function makeRequest(e,url) 
{
	var pos_x = pointeurX(e)
	var pos_y = pointeurY(e)
	var http_request = false;

	if(window.XMLHttpRequest) 
	{ 
		// Mozilla, Safari,...
		http_request = new XMLHttpRequest();

		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType('text/xml');
			// Voir la note ci-dessous à propos de cette ligne
		}
	} 
	else if(window.ActiveXObject) 
	{ 
		// IE
		try 
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch(e)
		{
			try 
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(e){}
		}
	}

	if(!http_request) 
	{
		alert('Abandon :( Impossible de créer une instance XMLHTTP');
		return false;
	}

	http_request.onreadystatechange = function() { alertContents(http_request,e,pos_x,pos_y); };
	http_request.open('GET', url, true);
	http_request.setRequestHeader('Content-Type',  "text/xml");
	http_request.send(null);    
}

function alertContents(http_request,e,pos_x,pos_y) 
{
	if(http_request.readyState == 4) 
	{
		if(http_request.status == 200)
		{
			var div = document.getElementById("description_activite");
			div.style.position = "absolute";
			div.style.left = (pos_x+'px');
    		div.style.top = (pos_y+'px');
			div.innerHTML = http_request.responseText;
			div.style.display = "block";
		}
		else
		{
			document.getElementById("description_activite").style.display = "none";
			alert(http_request.responseText)
		}
	}
}

// Retourne la position horizontale sur la page du pointeur de la souris
function pointeurX(e) 
{
	if (window.event)
  		return (window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft);
  	else
		return(e.layerX);
}

// Retourne la position verticale sur la page du pointeur de la souris
function pointeurY(e) 
{
	if (window.event)
    	return (window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop);
  	else
		return(e.layerY);
}

function close_div()
{
	document.getElementById("description_activite").style.display = "none";
	return false;
}

function show_calendrier(lang)
{	
	document.getElementById("description_activite").style.display = "none";
	
	// Vecteur des jours de la semaine
	var day_of_week = new Array();
	// Vecteur des mois de la semaine
	var month_of_year = new Array();
	
	switch(lang)
	{	// Langue française
		case "fr":
			day_of_week[0] = ('Dim');
			day_of_week[1] = ('Lun');
			day_of_week[2] = ('Mar');
			day_of_week[3] = ('Mer');
			day_of_week[4] = ('Jeu');
			day_of_week[5] = ('Ven');
			day_of_week[6] = ('Sam');
			
			month_of_year[0] = ('Janvier');
			month_of_year[1] = ('Février');
			month_of_year[2] = ('Mars');
			month_of_year[3] = ('Avril');
			month_of_year[4] = ('Mai');
			month_of_year[5] = ('Juin');
			month_of_year[6] = ('Juillet');
			month_of_year[7] = ('Août');
			month_of_year[8] = ('Septembre');
			month_of_year[9] = ('Octobre');
			month_of_year[10] = ('Novembre');
			month_of_year[11] = ('Décembre');
		break;		
		default:
			day_of_week[0] = ('Sun');
			day_of_week[1] = ('Mon');
			day_of_week[2] = ('Tue');
			day_of_week[3] = ('Wed');
			day_of_week[4] = ('Thu');
			day_of_week[5] = ('Fri');
			day_of_week[6] = ('Sat');
			
			month_of_year[0] = ('January');
			month_of_year[1] = ('February');
			month_of_year[2] = ('March');
			month_of_year[3] = ('April');
			month_of_year[4] = ('May');
			month_of_year[5] = ('June');
			month_of_year[6] = ('July');
			month_of_year[7] = ('August');
			month_of_year[8] = ('September');
			month_of_year[9] = ('October');
			month_of_year[10] = ('November');
			month_of_year[11] = ('December');
	}
	
	//  DECLARER ET INITIALISER LES VARIABLES
	var Calendar = new Date();
	
	// Année sélectionnée dans la liste
	var year = document.form_calendar.annee.value;
	
	// Mois sélectionné dans la liste
	var month = document.form_calendar.mois.value;
	
	var today = Calendar.getDate();    // Returns day (1-31)
	
	// Converti le jour en string
	var str_today = new String(today);
		
	var weekday = Calendar.getDay();    // Returns day (1-31)
	
	// Converti le mois en string
	var str_month = new String(parseInt(month)+1);
	str_month.length==1?str_month="0"+str_month:str_month=str_month;
	
	// Converti l'année et le mois en string
	var str_year_month = year+"-"+str_month;
	
	var DAYS_OF_WEEK = 7;    // "constant" pour le nombre du jour dans la semaine
	var DAYS_OF_MONTH = 31;    // "constant" pour le nombre du jour dans le mois
	var cal;    // UTILISER POUR IMPRIMER
	
	Calendar.setDate(1);    // commencer le calendrier avec le jour a  '1'
	Calendar.setMonth(month);    // commencer le mois du calendrier avec le mois actuel
	Calendar.setYear(year);
	
	/* LES VARIABLES POUR FORMATER
	NOTE: TU PEUX FORMATER LE 'BORDER', 'BGCOLOR', 'CELLPADDING', 'BORDERCOLOR'
		  les étiquettes pour personnaliser le regard de votre calendrier. */
	
	var TR_start = '<TR>';
	var TR_end = '</TR>';	
	var TD_start = '<TD class=td_cal><CENTER>';
	var TD_end = '</CENTER></TD>';
	
	/* COMMENCER LE CODE POUR LE CALENDRIER
	NOTE: Vous pouvez formater CEUX CI 'BORDER', 'BGCOLOR', 'CELLPADDING', 'BORDERCOLOR'
	les étiquettes pour personnaliser le regard de votre calendrier.*/
	
	//cal =  '<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 BORDERCOLOR=BBBBBB><TR><TD>';
	//cal += '<TD COLSPAN="' + DAYS_OF_WEEK + '" BGCOLOR="#EFEFEF"><CENTER><B>';
	//cal += month_of_year[month]  + '   ' + year + '</B>' + TD_end + TR_end;
	cal = '<TABLE BORDER=1 CELLSPACING=2 CELLPADDING=2 >';
	cal += '<TR>';
	
	//   Ne PAS EDITER AU DESSOUS DE CE POINT  //
	
	// LES BOUCLES POUR CHAQUE JOUR DE LA SEMAINE
	for(index=0; index < DAYS_OF_WEEK; index++)
	{
		// LE JOUR HARDI (VIF), LE JOUR ACTUEL DE LA SEMAINE(LE JOUR D'AUJOURD'HUI LE FAIRE VIF)
		//if(weekday == index)
		//cal += TD_start + '<B>' + day_of_week[index] + '</B>' + TD_end;
		
		// IMPRIMER LE JOUR 
		//else
			cal += '<TD class=td_day align="center">' + day_of_week[index] + '</TD>';
	}
	
	cal += '</TD></TR>';
	cal += '<TR>';
	
	// REMPLIR DES ECARTS BLANCS JUSQU' AU JOUR D'AUJOURD'HUI
	for(index=0; index < Calendar.getDay(); index++)
		cal += TD_start + '  ' + TD_end;
	
	tabActiviteDate = loadTableauActiviteDate();
	tabActivites = loadTableauActivites();
	tabActiviteDateFin = loadTableauActiviteDateFin();
	tabActiviteId = loadTableauActiviteId();
	// LES BOUCLES POUR CHAQUE JOUR DANS LE CALENDRIER
	for(index=0; index < DAYS_OF_MONTH; index++)
	{
		if(Calendar.getDate() > index)
		{		
			// RETOURNE SUR LE LENDEMAIN POUR IMPRIMER
		  	week_day =Calendar.getDay();
		
		  	// COMMENCER LE NOUVEAU RANG POUR LE PREMIER JOUR DE LA SEMAINE
		  	if(week_day == 0)
				cal += TR_start;
	
				// REGLER LA VARIABLE DANS LA BOUCLE POUR GRADUER JUSQU'AU BUTS
	 		 	var day  = Calendar.getDate();
	
			  	// SOULIGNER LA DATE D'AUJOURD'HUI
				var str_day = new String(index+1);
				str_day.length==1?str_day="0"+str_day:str_day=str_day;
				
				var str_year_month_day = str_year_month+"-"+str_day;
				var cmpt_tab = 0;
				var bool_trouve_plusieurs_activites = false;
				var bool_trouve_activites = false;
				var bool_activites_jours = false;
				var index_tab = 0;
				var index_tabFin = 0;
				var bgcolor="";
				var onclick = "";
				var tab_temp = new Array();
				var cmpt_temp = 0;
				var indexDateFin = 0;
				var boolDej = false;
				var boolCom = false;
				var boolCamarade =false
				var boolProj = false
				var lienDuJour = ""
				
				// Change la couleur du lien en rouge si celui-ci est la journée actuele 
				if(dateActuelle == str_year_month_day)
					lienDuJour = "style=\"color:#C66300;\""
					
				
					
				var highlight_start ="<TD class=td_cal BORDERCOLOR=#CCCCCC ><B><center>"
				var highlight_end="</center></B></TD>"
				
				// Compteur d'activités pour le même jour
				var cptPlusieur_Activites = 0
				
				cmpt_tab = 0;
				while(cmpt_tab < tabActiviteDateFin.length)
				{
					if(CompareDate(tabActiviteDate[cmpt_tab],tabActiviteDateFin[cmpt_tab],str_year_month_day))
					{
						bool_activites_jours = true;
						index_tabFin = cmpt_tab;
						cptPlusieur_Activites += 1
						if(tabActivites[cmpt_tab].toLowerCase() == "déjeuners" && !boolDej)
						{	
							boolDej = true;
							bgcolor += "<img id='carreVert' src=\"../../prospecteur/img/carreVert.jpg\" border=1 width=5 height=5 />";
							
						}
					    if(tabActivites[cmpt_tab].toLowerCase() == "comités/ca" && !boolCom)
						{
							boolCom = true;
							bgcolor += "<img id='carreRouge' src='../../prospecteur/img/carreRouge.jpg' border=1 width=5 height=5 />";
							
						}
						if(tabActivites[cmpt_tab].toLowerCase() == "camaraderies" && !boolCamarade)
						{
							boolCamarade = true;
							bgcolor += "<img id='carreBleu' src='../../prospecteur/img/carreBleu.jpg' border=1 width=5 height=5 />";
							
						}
						if(tabActivites[cmpt_tab].toLowerCase() == "projets" && !boolProj)
						{	
							boolProj = true;
							bgcolor += "<img id='carreOrange' src='../../prospecteur/img/carreOrange.jpg' border=1 width=5 height=5 />";	
							
						}
							// Rend la toute la zone de la date clickable lorsqu'il y a une activité
						if(cptPlusieur_Activites > 1)
							onclick = "onclick=\"document.location.href='calendrier.php?date="+str_year_month_day+"'\"";
						else
							onclick = "onclick=\"document.location.href='_calendrierActivite.php?date="+str_year_month_day+"&pk="+tabActiviteId[cmpt_tab]+"'\"";
							
				    }
					
					cmpt_tab += 1;
				
					highlight_start = "<TD class=td_cal BORDERCOLOR=#CCCCCC "+onclick+">"+bgcolor+"<B><CENTER>";
					highlight_end   = "</CENTER></B></TD>";	
				}
				// S'il y a plus d'une activité la même journée
				if(cptPlusieur_Activites != 1)	
					day = "<a "+lienDuJour+" href=\"calendrier.php?date="+str_year_month_day+"\" >"+day+"</a>";
				else
					day = "<a "+lienDuJour+" onclick=\"document.location.href='_calendrierActivite.php?date="+str_year_month_day+"&pk="+tabActiviteId[cmpt_tab]+"'\" href=\"#\" >"+day+"</a>";
				
				cal += highlight_start + day + highlight_end;
			
	  	}
	
	  // LES GRADUATIONS JUSQU' A LA FIN DU MOIS
	  Calendar.setDate(Calendar.getDate()+1);
	
	}// end for loop
	
	//cal += '</TD></TR></TABLE></TABLE>';
	cal += '</TD></TR></TABLE>';
	
	if(lang == "fr"){
		legende = '<table><tr><td style="background-color:#91AC5B">&nbsp;&nbsp;</td><td>Déjeuners </td><td style="background-color:#BA0000">&nbsp;&nbsp;</td><td>Comités/CA</td></tr><tr><td style="background-color:#C5E3FF"></td><td>Camaraderies</td><td style="background-color:#ED9803;height:5px;"></td><td>Projets</td></tr><table>';
	}else{
		legende = '<table><tr><td style="background-color:#91AC5B">&nbsp;&nbsp;</td><td>Economic Dev.</td><td style="background-color:#BA0000">&nbsp;&nbsp;</td><td>Formation</td></tr><tr><td style="background-color:#C5E3FF"></td><td>Recognition</td><td style="background-color:#ED9803"></td><td>Networking</td></tr><table>';
	}
	
	cal += legende;
	//  IMPRIMER LE CALENDRIER
	//document.write(cal);
	document.getElementById("calendrier").innerHTML = cal;
	return false;
}
// Fonction retournant le nombre de jours entre 2 dates 
function CompareDate(maDateDeb,maDateFin, maDateCal)
{	
	var anneeFin = maDateFin.substr(0,4);
	var moisFin = maDateFin.substr(5,2);
	var jourFin = maDateFin.substr(8,2);
	
	var anneeDeb = maDateDeb.substr(0,4);
	var moisDeb = maDateDeb.substr(5,2);
	var jourDeb = maDateDeb.substr(8,2);
	
	var anneeCal = maDateCal.substr(0,4);
	var moisCal = maDateCal.substr(5,2);
	var jourCal = maDateCal.substr(8,2);
	
	if(anneeCal >= anneeDeb && anneeFin >= anneeCal && moisCal >= moisDeb && moisFin >= moisCal &&
		jourCal >= jourDeb && jourFin >= jourCal)
		return true;
	else
		return false;
}
