
function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11) 
{
	this[0] = m0;
	this[1] = m1;
	this[2] = m2;
	this[3] = m3;
	this[4] = m4;
	this[5] = m5;
	this[6] = m6;
	this[7] = m7;
	this[8] = m8;
	this[9] = m9;
	this[10] = m10;
	this[11] = m11;
}

function calendar() 
{			
	//var monthNames = "JanFebMarAprMayJunJulAugSepOctNovDec";				
	var date_actuelle = new Date();
	var date_affichee = new Date();
	date_affichee.setMonth(document.getElementById("hidden_month").value);
	date_affichee.setFullYear(document.getElementById("hidden_year").value);
	var thisDay;				
	var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	year = date_affichee.getFullYear();
	
	if (year <= 200) 
	{
		year += 1900;
	}
	
	thisDay = date_affichee.getDate();
	
	if (((year % 4 == 0) & (year % 100 != 0)) || (year % 400 == 0)) 
	{
		monthDays[1] = 29;
	}
	
	nDays = monthDays[date_affichee.getMonth()];
	firstDay = date_affichee;
	firstDay.setDate(1);
	testMe = firstDay.getDate();
	
	if (testMe == 2) 
	{
		firstDay.setDate(0);
	}
	 //Ordre des jours du getDay() 0 : Dimanche, 1 : lundi, .... 6 : Samedi
	startDay = firstDay.getDay();
	if (firstDay.getDay() == 0)
		startDay = 7;
	
	document.writeln("<CENTER>");
	document.write("<TABLE BORDER='2' BGCOLOR='#FFFFFF' WIDTH='170px' BORDERCOLOR='#99BB22'>");
	document.write("<TR><TH COLSPAN=7>");
	document.write("<input id='subYear' type='button' value='<<' onclick='subYear()' style='background:white;border:none;font-weight:bold;width:23px' />");
	document.write("<input id='subMonth' type='button' value='<' onclick='subMonth()' style='background:white;border:none;font-weight:bold;width:23px' />");
	
	switch (date_affichee.getMonth())
	{
		case 0 : document.write("Janv "); break;
		case 1 : document.write("Févr "); break;
		case 2 : document.write("Mars "); break;
		case 3 : document.write("Avri "); break;
		case 4 : document.write("Mai "); break;
		case 5 : document.write("Juin "); break;
		case 6 : document.write("Juil "); break;
		case 7 : document.write("Août "); break;
		case 8 : document.write("Sept "); break;
		case 9 : document.write("Octo "); break;
		case 10 : document.write("Nove "); break;
		case 11 : document.write("Déce "); break;
		default : document.write("WTF??!!"); break;
	}				
	
	document.write(year);	
	document.write("<input id='addMonth' type='button' value='>' onclick='addMonth()' style='background:white;border:none;font-weight:bold;width:23px' align='right'/>");
	document.write("<input id='addYear' type='button' value='>>' onclick='addYear()' style='background:white;border:none;font-weight:bold;width:23px' align='right'/>");
	document.write("<TR><TH>Lu<TH>Ma<TH>Me<TH>Je<TH>Ve<TH>Sa<TH>Di");
	document.write("<TR>");
	column = 0;
	
	for (i = 1; i < startDay; i++)
	{
		document.write("<TD>");
		column++;
	}
	
	for (i = 1; i <= nDays; i++)
	{
		document.write("<TD>");
		
		// la date actuelle est écrite en rouge
		if (i == thisDay & date_affichee.getMonth() == date_actuelle.getMonth() & date_affichee.getFullYear() == date_actuelle.getFullYear()) 
		{
			document.write("<FONT COLOR=\"#FF0000\">");
			document.write(i);
			document.write("</FONT>");
		}
		else if ((i == 28 || i == 29 || i == 30) & date_affichee.getMonth() == 7 & date_affichee.getFullYear() == 2009)
		{
			document.write("<a href='agenda.html"+location.search+"#foire_chalons_09' style='text-decoration:none;font-weight:bold'><font color='blue'>");
			document.write(i);
			document.write("<span class='infotexte'> Campagne de France à la foire de Châlons </span></font></a>");
		}
		else if (i == 19 & date_affichee.getMonth() == 4 & date_affichee.getFullYear() == 2012)
		{
			document.write("<a href='agenda.html"+location.search+"#bdle_2012' style='text-decoration:none;font-weight:bold'><font color='blue'>");
			document.write(i);
			document.write("<span class='infotexte'> Bal de l'Empereur </span></font></a>");
		}
		else if ((i == 25 || i == 26) & date_affichee.getMonth() == 0 & date_affichee.getFullYear() == 2014)
		{
			document.write("<a href='agenda.html"+location.search+"#footer' style='text-decoration:none;font-weight:bold'><font color='blue'>");
			document.write(i);
			document.write("<span class='infotexte'> Concerts de musique à Châlons sur Marne </span></font></a>");
		}
		else if ((i == 15 || i == 16) & date_affichee.getMonth() == 1 & date_affichee.getFullYear() == 2014)
		{
			document.write("<a href='agenda.html"+location.search+"#footer' style='text-decoration:none;font-weight:bold'><font color='blue'>");
			document.write(i);
			document.write("<span class='infotexte'> Reconstitution bataille, Figurations, et parade à Montereau </span></font></a>");
		}
		else if ((i == 7 || i == 8) & date_affichee.getMonth() == 2 & date_affichee.getFullYear() == 2014)
		{
			document.write("<a href='agenda.html"+location.search+"#footer' style='text-decoration:none;font-weight:bold'><font color='blue'>");
			document.write(i);
			document.write("<span class='infotexte'> Les Marie-Louise & Poilus (1814-1914) à Craome </span></font></a>");
		}
		else if ((i == 28 || i == 29) & date_affichee.getMonth() == 2 & date_affichee.getFullYear() == 2014)
		{
			document.write("<a href='agenda.html"+location.search+"#footer' style='text-decoration:none;font-weight:bold'><font color='blue'>");
			document.write(i);
			document.write("<span class='infotexte'> Art lyrique, opéra Italien, la vie culturelle au 1er Empire à Saint-Dizier </span></font></a>");
		}
		else if ((i == 12 || i == 13) & date_affichee.getMonth() == 3 & date_affichee.getFullYear() == 2014)
		{
			document.write("<a href='agenda.html"+location.search+"#footer' style='text-decoration:none;font-weight:bold'><font color='blue'>");
			document.write(i);
			document.write("<span class='infotexte'> Colloque sciences & médecine sous le consulat & 1er Empire à Reims </span></font></a>");
		}
		else if ((i == 3 || i == 4) & date_affichee.getMonth() == 4 & date_affichee.getFullYear() == 2014)
		{
			document.write("<a href='agenda.html"+location.search+"#footer' style='text-decoration:none;font-weight:bold'><font color='blue'>");
			document.write(i);
			document.write("<span class='infotexte'> Cérémonie « Les Adieux » à Fontainebleau </span></font></a>");
		}		
		else if ((i == 17 || i == 18) & date_affichee.getMonth() == 4 & date_affichee.getFullYear() == 2014)
		{
			document.write("<a href='agenda.html"+location.search+"#footer' style='text-decoration:none;font-weight:bold'><font color='blue'>");
			document.write(i);
			document.write("<span class='infotexte'> Journées bourse aux armes à Brienne le Château </span></font></a>");
		}	
		else if ((i == 29 || i == 30 || i == 31) & date_affichee.getMonth() == 4 & date_affichee.getFullYear() == 2014)
		{
			document.write("<a href='agenda.html"+location.search+"#footer' style='text-decoration:none;font-weight:bold'><font color='blue'>");
			document.write(i);
			document.write("<span class='infotexte'> Bivouac & Reconstitution Internationale à Montmirail  </span></font></a>");
		}
		else if ((i == 25) & date_affichee.getMonth() == 0 & date_affichee.getFullYear() == 2012)
		{
			document.write("<a href='"+location.search+"' style='text-decoration:none;font-weight:bold'><font color='blue'>");
			document.write(i);
			document.write("<span class='infotexte'> Assemblée générale de l'association </span></font></a>");
		}
		else
		{
			document.write(i);
		}
		
		column++;
		
		if (column == 7) 
		{
			document.write("<TR>");
			column = 0;
		}
	}
	
	document.write("</TABLE>");
	//lien vers les évevements d'autres associations
	document.write("<br/><a href='autre_event.html' style='text-decoration:none'><font size='1'>événements d'autres associations</font></a>");
	document.writeln("</CENTER>");
}			

function addMonth()
{
	var count = document.getElementById("hidden_month").value - 0; // utilisation de la soustraction pour faire une convertion du type string vers le type int
	count += 1; // de cette manière, Javascript interprête ceci comme une addition, alors qu'il aurait par défaut utilisé la concaténation			
	
	// si on vient d'arriver en janvier, on ajoute alors également l'année
	if(count == 12) 
	{
		document.getElementById("hidden_month").value = 0;
		addYear();
	}
	else document.getElementById("hidden_month").value = count;
	
	// "mémorise" la position verticale de manière à ne pas systématiquement revenir en haut de page pour chaque action de navigation dans le calendrier
	var Y_Position = get_scroll();
	
	// on redirige vers la même page, mais en ajoutant les paramètres nécéssaires à la mise à jour du calendrier
	var redirection = document.location.protocol + "//" + document.location.hostname + document.location.pathname;
	document.location.href = redirection + "?m=" + document.getElementById("hidden_month").value + "&a=" + document.getElementById("hidden_year").value + "&y=" + Y_Position;
}

function subMonth()
{
	var count = document.getElementById("hidden_month").value - 0; // utilisation de la soustraction pour faire une convertion du type string vers le type int
	count -= 1; // de cette manière, Javascript interprête ceci comme une addition, alors qu'il aurait par défaut utilisé la concaténation				
	document.getElementById("hidden_month").value = count;
		
	// si on vient d'arriver en décembre, on soustrait alors également l'année
	if(count == -1) 
	{
		document.getElementById("hidden_month").value = 11;
		subYear();
	}
	
	// "mémorise" la position verticale de manière à ne pas systématiquement revenir en haut de page pour chaque action de navigation dans le calendrier
	var Y_Position = get_scroll();
	
	// on redirige vers la même page, mais en ajoutant les paramètres nécéssaires à la mise à jour du calendrier
	var redirection = document.location.protocol + "//" + document.location.hostname + document.location.pathname;
	document.location.href = redirection + "?m=" + document.getElementById("hidden_month").value + "&a=" + document.getElementById("hidden_year").value + "&y=" + Y_Position;	
}

function initMonth()
{				
	if(document.getElementById("hidden_month").value == "TRUE_INIT")
	{
		var date_affichee = new Date();				
		var currentmonth = date_affichee.getMonth();
		currentmonth = currentmonth;
		document.getElementById("hidden_month").value = currentmonth;
	}
}

function addYear()
{
	var count = document.getElementById("hidden_year").value - 0; // utilisation de la soustraction pour faire une convertion du type string vers le type int
	count += 1; // de cette manière, Javascript interprête ceci comme une addition, alors qu'il aurait par défaut utilisé la concaténation				
	document.getElementById("hidden_year").value = count;
	
	// "mémorise" la position verticale de manière à ne pas systématiquement revenir en haut de page pour chaque action de navigation dans le calendrier
	var Y_Position = get_scroll();
	
	// on redirige vers la même page, mais en ajoutant les paramètres nécéssaires à la mise à jour du calendrier
	var redirection = document.location.protocol + "//" + document.location.hostname + document.location.pathname;
	document.location.href = redirection + "?m=" + document.getElementById("hidden_month").value + "&a=" + document.getElementById("hidden_year").value + "&y=" + Y_Position;		
}

function subYear()
{
	var count = document.getElementById("hidden_year").value - 0; // utilisation de la soustraction pour faire une convertion du type string vers le type int
	count -= 1; // de cette manière, Javascript interprête ceci comme une addition, alors qu'il aurait par défaut utilisé la concaténation				
	document.getElementById("hidden_year").value = count;
	
	// "mémorise" la position verticale de manière à ne pas systématiquement revenir en haut de page pour chaque action de navigation dans le calendrier
	var Y_Position = get_scroll();
	
	// on redirige vers la même page, mais en ajoutant les paramètres nécéssaires à la mise à jour du calendrier
	var redirection = document.location.protocol + "//" + document.location.hostname + document.location.pathname;
	document.location.href = redirection + "?m=" + document.getElementById("hidden_month").value + "&a=" + document.getElementById("hidden_year").value + "&y=" + Y_Position;			
}

function initYear()
{				
	if(document.getElementById("hidden_year").value == "TRUE_INIT")
	{
		var date_affichee = new Date();				
		var currentyear = date_affichee.getFullYear();
		currentyear = currentyear;
		document.getElementById("hidden_year").value = currentyear;
	}	
}


function extractUrlParams()
{		
	if(location.search != "")
	{
		var param = location.search.substring(1).split('&');
		var mois = param[0].split('=')[1];
		var annee = param[1].split('=')[1];	
		
		document.getElementById("hidden_month").value = mois;
		document.getElementById("hidden_year").value = annee;
	}
	else
	{
		initMonth();
		initYear();
	}	
}

// récupérer la position verticale
function get_scroll()
{
	var y = 0;
	if( typeof( window.pageYOffset ) == 'number' ){	y = window.pageYOffset; /*Netscape*/ } 
	else if( document.body && document.body.scrollTop ){ y = document.body.scrollTop; /*DOM*/ } 
	else if( document.documentElement && document.documentElement.scrollTop ){ y = document.documentElement.scrollTop; /*IE6*/ }
	
	return y;
}

// aller à la position verticale précédente (actions calendrier)
function set_scroll()
{
	var param = location.search.substring(1).split('&');
	var position = param[2].split('=')[1];
	window.scrollTo(0,position);
}

// permet d'être redirigé vers un autre onglet tout en gardant la position du calendrier
function save_param_calendar(nom_page)
{
	if(location.search != "")
	{
		var param = location.search.substring(1).split('&');
		var mois = param[0].split('=')[1];
		var annee = param[1].split('=')[1];	
		
		document.location.href = nom_page + ".html" + "?m=" + mois + "&a=" + annee + "&y=0";
	}
	else
	{
		document.location.href = nom_page + ".html";
	}
}
