function initdate2(j,m,y){
	m=m+1;
	jo=j;
	mo=m;
	j=""+j;
	m=""+m;
	y=""+y;
	if(j.length==1){j="0"+j;}
	if(m.length==1){m="0"+m;}	
	document.forms.resa.datedefin.value = j+"/"+m+'/'+y;
	NbNuit();	
	document.getElementById('moncalques').innerHTML=affiche_date2(mo,y,jo);
	document.getElementById('dateentiere2').innerHTML=affdate(mo,y,jo);
	
}

function affiche_date2(m,y,d){
	var date=new Date();
	var nomjour=new Array("Di","Lu","Ma","Me","Je","Ve","Sa");
	var nbjours = Array (31,0,31,30,31,30,31,31,30,31,30,31);
	date.setDate(1);
	date.setMonth(m-1);
	date.setYear(y);
	var mois=parseInt(date.getMonth())+1;
	
	// test bissecstile & seculaire
	var motan=date.getFullYear();
	var choix="";
	if (motan-(parseInt(motan/4)*4)==0){choix="bi";}
	if (motan-(parseInt(motan/4)*4)==0&&motan-(parseInt(motan/100)*100)==0) {choix="";} 
	if (motan-(parseInt(motan/4)*4)==0&&motan-(parseInt(motan/400)*400)==0) {choix="bi";}
	if(choix=="bi"){nbjours[1]=29;}
	if(choix!="bi"){nbjours[1]=28;}
	// fin du test bissecstile & seculaire

	//Début calendrier
	
	var valid="";
	var todaye = document.forms.resa.datededebut.value;
	if ( todaye.substring(0,1)=="0"){tojourest = todaye.substring(1,2);}else{tojourest = todaye.substring(0,2);}
	if ( todaye.substring(3,4)=="0"){tomoisest = todaye.substring(4,5);}else{tomoisest = todaye.substring(3,5);}
	toanest = todaye.substring(6,todaye.length);
	nowjour = parseInt(tojourest);
	nowjour = nowjour+1;
	nowmois = parseInt(tomoisest);
	nowmois = nowmois-1;
	nowan = parseInt(toanest);

	//nowan=now.getFullYear();
	//nowmois=now.getMonth();
	//nowjour=now.getDate();
	var AStyleNomJour = "border-left: #CAC9C8 1px solid;border-top: #CAC9C8 1px solid;border-right: #333333 1px solid;border-bottom: #333333 1px solid;font-size:9pt;text-align:center;color:black;font-family: Arial Verdana;cursor:pointer;padding:1px;z-index:99";
	var AStyleJourOK = "border-left: #CAC9C8 1px solid;border-top: #CAC9C8 1px solid;border-right: #333333 1px solid;border-bottom: #333333 1px solid;background-color:#00FF00;font-size:9pt;text-align:center;color:black;font-family: Arial Verdana;cursor:pointer;padding:1px;z-index:99";
	var AStyleJourKO = "border-left: #CAC9C8 1px solid;border-top: #CAC9C8 1px solid;border-right: #333333 1px solid;border-bottom: #333333 1px solid;background-color:#FF0000;font-size:9pt;text-align:center;color:white;font-family: Arial Verdana;cursor:pointer;padding:1px;z-index:99";
	var AStyleJourSelected = "border-left: #CAC9C8 1px solid;border-top: #CAC9C8 1px solid;border-right: #333333 1px solid;border-bottom: #333333 1px solid;background-color:#7951AE;font-weight: bold;font-size:9pt;text-align:center;color:white;font-family: Arial Verdana;cursor:pointer;padding:1px;z-index:99";
	txt="<table border='1px' width='165px'>";
	txt+="<tr>";
	var datefausse=1;
	for(i=0;i<nomjour.length; i++)
	{
		txt+="<td style='"+AStyleNomJour+"'>"+nomjour[i]+"</td>";
	}
	txt+="</tr>";
	for(i=0;i<6;i++)
	{
		txt+="<tr>";
		for(y=0;y<7;y++)
		{
			txt+="<td";
			if(i==0)
			{
				if(date.getDay()!=y){txt+="  >";}
				else
				{
					//TEST SUR L'ANNEE
					if(nowan>date.getFullYear())
					{
						txt+=" style='"+AStyleJourKO+"'>";
						txt+=date.getDate();
						date.setDate(parseInt(date.getDate())+1);
						datefausse+=1;
					}else if(nowan==date.getFullYear())
					{
						//TEST SUR LE MOIS
						if (nowmois>date.getMonth())
						{
							txt+=" style='"+AStyleJourKO+"'>";
							txt+=date.getDate();
							date.setDate(parseInt(date.getDate())+1);
							datefausse+=1;
						}else if (nowmois==date.getMonth())
						{
							//TEST JOUR
							if(nowjour>date.getDate()){
								txt+=" style='"+AStyleJourKO+"'>";
								txt+=date.getDate();
								date.setDate(parseInt(date.getDate())+1);
								datefausse+=1;
							}else{
								// restriction par logement
								valide=true;
								valide=traitrestr(date);
								

								if(valide==false){txt+=" style='"+AStyleJourKO+"'>";}
								else if(date.getDate()==d){
									txt+=" style='"+AStyleJourSelected+
									"' onMouseOver=\"this.style.backgroundcolor='#777777'\" onMouseOut=\"this.style.backgroundcolor='#7951AE'\" onClick='initdate2("+date.getDate()+","+date.getMonth()+","+date.getFullYear()+")'>";
								}
								else{
									txt+=" style='"+AStyleJourOK+
									"' onMouseOver=\"this.style.backgroundcolor='#777777'\" onMouseOut=\"this.style.backgroundcolor='#00FF00'\" onClick='initdate2("+date.getDate()+","+date.getMonth()+","+date.getFullYear()+")'>";
								}
								txt+=date.getDate();
								date.setDate(parseInt(date.getDate())+1);
								datefausse+=1;
							}
						}else{
							// restriction par logement
							valide=true;
							valide=traitrestr(date);
							

							if(valide==false){txt+=" style='"+AStyleJourKO+"'>";}
							else if(date.getDate()==d){
								txt+=" style='"+AStyleJourSelected+
								"' onMouseOver=\"this. style.backgroundcolor='#777777'\" onMouseOut=\"this. style.backgroundcolor='#7951AE'\" onClick='initdate2("+date.getDate()+","+date.getMonth()+","+date.getFullYear()+")'>";
							}
							else{
									txt+=" style='"+AStyleJourOK+
								"' onMouseOver=\"this. style.backgroundcolor='#777777'\" onMouseOut=\"this. style.backgroundcolor='#00FF00'\" onClick='initdate2("+date.getDate()+","+date.getMonth()+","+date.getFullYear()+")'>";
							}
							txt+=date.getDate();
							date.setDate(parseInt(date.getDate())+1);
							datefausse+=1;
						}
					}else{
					// restriction par logement
					valide=true;
					valide=traitrestr(date);
					

					if(valide==false){txt+=" style='"+AStyleJourKO+"'>";}
					else if(date.getDate()==d){
						txt+=" style='"+AStyleJourSelected+
						"' onMouseOver=\"this. style.backgroundcolor='#777777'\" onMouseOut=\"this. style.backgroundcolor='#7951AE'\" onClick='initdate2("+date.getDate()+","+date.getMonth()+","+date.getFullYear()+")'>";
					}
					else{
						txt+=" style='"+AStyleJourOK+
						"' onMouseOver=\"this. style.backgroundcolor='#777777'\" onMouseOut=\"this. style.backgroundcolor='#00FF00'\" onClick='initdate2("+date.getDate()+","+date.getMonth()+","+date.getFullYear()+")'>";
					}
					txt+=date.getDate();
					date.setDate(parseInt(date.getDate())+1);
					datefausse+=1;
					}
				}
			}
			else
			{
				if (datefausse<=nbjours[mois-1])
				{
					if(nowan>date.getFullYear())
					{
						txt+=" style='"+AStyleJourKO+"'>";
						txt+=date.getDate();
						date.setDate(parseInt(date.getDate())+1);
						datefausse+=1;
					}else if(nowan==date.getFullYear())
					{
						//TEST SUR LE MOIS
						if (nowmois>date.getMonth())
						{
							txt+=" style='"+AStyleJourKO+"'>";
							txt+=date.getDate();
							date.setDate(parseInt(date.getDate())+1);
							datefausse+=1;
						}else if (nowmois==date.getMonth())
						{
							//TEST JOUR
							if(nowjour>date.getDate()){
								txt+=" style='"+AStyleJourKO+"'>";
								txt+=date.getDate();
								date.setDate(parseInt(date.getDate())+1);
								datefausse+=1;
							}else{
								// restriction par logement
								valide=true;
								valide=traitrestr(date);
								

								if(valide==false){txt+=" style='"+AStyleJourKO+"'>";}
								else if(date.getDate()==d){
									txt+=" style='"+AStyleJourSelected+
									"' onMouseOver=\"this. style.backgroundcolor='#777777'\" onMouseOut=\"this. style.backgroundcolor='#7951AE'\" onClick='initdate2("+date.getDate()+","+date.getMonth()+","+date.getFullYear()+")'>";
								}
								else{
									txt+=" style='"+AStyleJourOK+
									"' onMouseOver=\"this. style.backgroundcolor='#777777'\" onMouseOut=\"this. style.backgroundcolor='#00FF00'\" onClick='initdate2("+date.getDate()+","+date.getMonth()+","+date.getFullYear()+")'>"; 
								}  
								txt+=date.getDate();
								date.setDate(parseInt(date.getDate())+1);
								datefausse+=1;
							}
						}else{
							// restriction par logement
							valide=true;
							valide=traitrestr(date);
							
	
							if(valide==false){txt+=" style='"+AStyleJourKO+"'>";}
							else if(date.getDate()==d){
								txt+=" style='"+AStyleJourSelected+
								"' onMouseOver=\"this. style.backgroundcolor='#777777'\" onMouseOut=\"this. style.backgroundcolor='#7951AE'\" onClick='initdate2("+date.getDate()+","+date.getMonth()+","+date.getFullYear()+")'>";
							}
							else{
								txt+=" style='"+AStyleJourOK+
								"' onMouseOver=\"this. style.backgroundcolor='#777777'\" onMouseOut=\"this. style.backgroundcolor='#00FF00'\" onClick='initdate2("+date.getDate()+","+date.getMonth()+","+date.getFullYear()+")'>";
							}
							txt+=date.getDate();
							date.setDate(parseInt(date.getDate())+1);
							datefausse+=1;
						}
					}else{
					// restriction par logement
					valide=true;
					valide=traitrestr(date);
					

					if(valide==false){txt+=" style='"+AStyleJourKO+"'>";}
					else if(date.getDate()==d){
						txt+=" style='"+AStyleJourSelected+
						"' onMouseOver=\"this. style.backgroundcolor='#777777'\" onMouseOut=\"this. style.backgroundcolor='#7951AE'\" onClick='initdate2("+date.getDate()+","+date.getMonth()+","+date.getFullYear()+")'>";
					}
					else{
						txt+=" style='"+AStyleJourOK+
						"' onMouseOver=\"this. style.backgroundcolor='#777777'\" onMouseOut=\"this. style.backgroundcolor='#00FF00'\" onClick='initdate2("+date.getDate()+","+date.getMonth()+","+date.getFullYear()+")'>";
					}
					txt+=date.getDate();
					date.setDate(parseInt(date.getDate())+1);
					datefausse+=1;
					}
				}
				else{txt+="  >";}
			}
			txt+="</td>";
		}
		txt+="</tr>";
	}
	txt+="</table>";

	return(txt);
}



// JavaScript Document
