function Produit(jour, uri){
     this.jour = jour;
     this.uri = uri;
}

function constructMonth(month,year,monArray,machaine){
 	document.write("<ul class=\"nw\">\r\n");
  document.write("<div id=\"mois"+month+"\" >\r\n");
  document.write("<div id=\"moisNom\">\r\n");
  document.write(" "+monthName(month,machaine)+" "+year+" \r\n");
  document.write("<\/div>\r\n");
  // afin de transtyper la varible month et ajouté 1 pour être à la norme js dans les construction de date.
  month=(month*1)-1;
  constructMonthDates(month,year,monArray);
  document.write("<\/div>\r\n"); 
  document.write("<\/div>\r\n");
}

function constructMonthDates(month,year, monArray){
 // corps du calendrier
 //document.write("<div class=\"corps\">\r\n");
 document.write("<div class=\"corpsDay\">\r\n");
 document.write("<div class=\"calendrier-sem\">lun<\/div>\r\n");
 document.write("<div class=\"calendrier-sem\">mar<\/div>\r\n");
 document.write("<div class=\"calendrier-sem\">mer<\/div>\r\n");
 document.write("<div class=\"calendrier-sem\">jeu<\/div>\r\n");
 document.write("<div class=\"calendrier-sem\">ven<\/div>\r\n");
 document.write("<div class=\"calendrier-fin-sem\">sam<\/div>\r\n");
 document.write("<div class=\"calendrier-fin-sem\">dim<\/div>\r\n");
 // Initialisation de dateIndex sur le premier jour de month,year
 var dateIndex=new Date(year,month,1,0,0,0);
 // Si le 1er n'est pas un lundi, on cherche le lundi précédent
 while(dateIndex.getDay()!=1){
  decDay(dateIndex);
 }
 // Ouverture de la première ligne de dates
 document.write("<div class=\"corpsDate\">\r\n");
 // On affiche les derniers jours du mois précédent
 while(dateIndex.getMonth()!=month){
  constructInactiveDay(dateIndex);
  incDay(dateIndex);
 }
 // On affiche les jours du mois courant
 while(dateIndex.getMonth()==month){
  if(dateIndex.getDay()==1&&dateIndex.getDate()!=1){
// Lundi=nouvelle ligne sauf si on est le 1er (la ligne a déjà été ouverte plus haut)
   document.write("<\/div>\r\n");
   document.write("<div class=\"corpsDate\">\r\n");
  }

  constructActiveDay(dateIndex,monArray);
  incDay(dateIndex);
 }
 // On affiche les premiers jours du mois suivant
 while(dateIndex.getDay()!=1){
  constructInactiveDay(dateIndex);
  incDay(dateIndex);
 }
 // fermeture de la dernière ligne de dates
 document.write("<\/div>\r\n");
}

function constructActiveDay(date, monArray ){
	var find=false;
	var r=0;
	for(var i = 0; i < monArray.length; i++){
		if (date.getDate()==monArray[i].jour){
			find=true;
			r=i;
		}
	}
 	if(find) document.write("<a class=\"activeDate\" href="+monArray[r].uri+">"+monArray[r].jour+"</a>");
 	else document.write("<div class=\"day\">"+date.getDate()+"</div>"); 		
 		
}

function constructInactiveDay(date){
 document.write("<div class=\"inactiveDate\">"+date.getDate()+"<\/div>");
}

function incDay(date){
 var jour=date.getDate();
 var nTime=date.getTime();
 date.setTime(nTime+24*3600*1000);
 if(date.getDate()==jour){
  nTime=date.getTime();
  date.setTime(nTime+24*3600*1000);
  date.setHours(0);
 }
}

function decDay(date){
 var nTime=date.getTime();
 date.setTime(nTime-24*3600*1000);
}

function monthName(month,machaine){
if(machaine=="Fecha de salida"){
	 if(month==1) return "enero";
		 else if(month==2) return "febrero";
		 else if(month==3) return "marzo";
		 else if(month==4) return "abril";
		 else if(month==5) return "mayo";
		 else if(month==6) return "junio";
		 else if(month==7) return "julio";
		 else if(month==8) return "agosto";
		 else if(month==9) return "septiembre";
		 else if(month==10) return "octubre";
		 else if(month==11) return "noviembre";
		 else if(month==12) return "diciembre";
		 else return "";

}else{
	if(month==1) return "janvier";
		 else if(month==2) return "février";
		 else if(month==3) return "mars";
		 else if(month==4) return "avril";
		 else if(month==5) return "mai";
		 else if(month==6) return "juin";
		 else if(month==7) return "jullet";
		 else if(month==8) return "aôut";
		 else if(month==9) return "septembre";
		 else if(month==10) return "octobre";
		 else if(month==11) return "novembre";
		 else if(month==12) return "décembre";
		 else return "";
}
}
function afficherCalendrier(chaine,dates){
		if(chaine=="Fecha de salida" || chaine=="date départ"){
				var annee = dates.substring(0,4);	
				var tmpmois = dates.substring(5,6);
				if(tmpmois==0) mois=dates.substring(6,7);
				else mois=dates.substring(5,7);
				var elts;
				for (i=0;i<document.getElementsByTagName("strong").length; i++){
						if(document.getElementsByTagName("strong").item(i).firstChild.nodeValue==chaine){
							var Node = document.getElementsByTagName("STRONG").item(i).parentNode;
							var NodeListe = Node.childNodes;
							var tableau = new Array();
							var montableau = new Array();
							for(j=0;j<NodeListe.length;j++){
									if(NodeListe.item(j).tagName=="UL"){
										var NodeListe2=NodeListe.item(j).getElementsByTagName("li");
										for(r=0;r<NodeListe2.length-1;r++){
											tableau[r] = NodeListe2.item(r).firstChild.firstChild.nodeValue.substring(8,10);
											montableau[r] = new Produit(tableau[r],NodeListe2.item(r).firstChild.href);
										}
										Node.removeChild(NodeListe.item(j));
									}
							}
										/*Suppression de tous les LI  
										elts=document.getElementsByTagName("strong").item(i).nextSibling.nextSibling;
										t=elts.getElementsByTagName("li");
										for(j=t.length-1;j>=0;j--){
											if(j!=0)elts.removeChild(t[j-1]);
											else elts.removeChild(t[j])
									 	}*/
									 	
									constructMonth(mois,annee,montableau,chaine);							
						}
				}	
		}

}