function metDate (id, valeur) {
			
		$(id).value = valeur;
		Element.remove('calend');
		$(id).disabled = false;
		$(id).focus = false;	
}

function innerCalendarCode(id,mois,annee) {

	$(id).disabled = true;
	
	//Effacer un calendrier ventuellement existant. 
	        
	if($('calend')) Element.remove('calend');
	        
		//Si today est existant alors : 
	if(mois){
	        	
		var today = new Date(annee, mois, 1);		
	
	}else{
		//Sinon, c'est que c'est une premire ouverture
					
		var today = new Date();				
	        
	}
	

    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() {        
        
        moisLettre = new Array('Janvier', 'Fevrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aot', 'Septembre', 'Octobre', 'Novembre', 'Dcemebre');            
                var thisDay;        var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);        year = today.getYear();        if (year <= 200) {            year += 1900;        }        thisDay = today.getDate();        if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {            monthDays[1] = 29;        }        nDays = monthDays[today.getMonth()];        firstDay = today;        firstDay.setDate(1);        testMe = firstDay.getDate();        if (testMe == 2) {            firstDay.setDate(0);        }        startDay = firstDay.getDay();
        
        
        //Calcule des mois suivant et prcdent : 
        moisPrec = today.getMonth()-1;      
        moisSuiv = today.getMonth()+1;

                
        
        //Ecriture
        html = "<DIV style='position:absolute;background-color:#ffffff;width:180px;border:solid 1px #cccccc;' align='center' id='calend'>";
        
        html += "<TABLE width='100%'>";
        html += "<TR>";
        html += "<TD  onClick='innerCalendarCode(\""+id+"\",\""+moisPrec+"\", \""+year+"\");' style='cursor:pointer;'>prec</TD>";
        html += "<TD>"+moisLettre[today.getMonth()]+" "+year+"</TD>";
        html += "<TD onClick='innerCalendarCode(\""+id+"\",\""+moisSuiv+"\", \""+year+"\");' align='right'  style='cursor:pointer;'>suiv</TD>";
        html += "</TR>";
        html += "</TABLE>";
        
        html += "<TABLE>";       	        html += "<TR><TD>Dim</TD><TD>Lun</TD><TD>Mar</TD><TD>Mer</TD><TD>Jeu</TD><TD>Ven</TD><TD>Sam</TD></TR>";        html += "<TR>";        
        column = 0;        
        //TOUS LES JOURS AVANT LE PREMIER JOUR DU MOIS
        for (i = 0; i < startDay; i++) {            
            html += "<TD></TD>";            column++;        }
        
        //TOUS LES AUTRES JOUR DU MOIS        for (i = 1; i <= nDays; i++) {           
            if(column == 0) html += "<TR>";
           
           	mois = today.getMonth()+1;
           	
           	nouvDate = i+"/"+mois+"/"+year;
           
            html += "<TD align='center' style='cursor:pointer;' onClick='metDate(\""+id+"\", \""+nouvDate+"\");'>";            
            //Si c'est aujourd'hui on met en rouge
            if (i == thisDay) {                html += "<FONT COLOR=\"#FF0000\">";            }
            
            //On met le jour conern            html += i;
            
            //Si c'est aujourd'hui on ferme la balise de couleur            if (i == thisDay) {                html += "</FONT>";            }
            
            //Et on referme
            html += "</TD>";            
                        column++;
            
            //Si on est  la fin de semain, on ferme la ligne            if (column == 7) {               html += "</TR>";               column = 0;            }        }        html += "</TABLE>";        html += "</DIV>";
        
        new Insertion.After(id, html); 
        
            }    calendar();}  