var today=new Date();
var monthName=new Array('Jan','Fev','Mars','Avr','Mai','Juin','Juil','Aout','Sept','Oct','Nov','Dec')
var monthDays=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
cur_month=today.getMonth();
cur_year=today.getYear();
cur_day=today.getDate(); 
var month=new Array();
var year=new Array();
var classe1;
var objetretour =new Array();
var disableavt=new Array();
var imagleft,imagright;
var nbcal=0;
var calbgcalcolor1="#ffffff",calcolor1="#000000",calbgcolor2="#d5d5d5";

function initCalendar(id){
	if(year[id]%4==0 && year[id]%100!=0 || year[id]%400==0)
		monthDays[1]=29;
	else 		monthDays[1]=28;
	var contenu= ("<table class="+classe1+" width=140 cellpadding=0  border=0 ><tr style=\"color='"+calcolor1+"';\" height=18><td  width=1><a href=\"javascript:prevMonth('"+id+"');\"><img border=0 style=\"background-color="+calbgcalcolor1+"\" src=\""+imagleft+"\"></a></td><td bgcolor="+calbgcalcolor1+" align=center width=155>")
	contenu+=("<select name=calmonth onchange=\"changeMonth("+id+",this);\" style=\"background-color="+calbgcalcolor1+";color="+calcolor1+";font-family:terminal;line-height=10px;font-size=8px;\">")
	var n;
	for(n=0;n<monthName.length;n++){
		contenu+=("<option value="+n+" ");
		if (n==month[id]) contenu+=("selected");
		contenu+=(">"+monthName[n]);
	}
	contenu+="</select>&nbsp;<select class="+classe1+" onchange=\"changeYear("+id+",this);\" name=calyear style=\"background-color="+calbgcalcolor1+";color="+calcolor1+";font-family:terminal;font-size=8px;\">"
	for(n=1920;n<cur_year+5;n++){
		contenu+=("<option value="+n+" ");
		if(n==year[id]) contenu+=("selected");
		contenu+=(">"+n);
	}
	contenu+=("</select>")
	contenu+=("</td><td width=1><a href=\"javascript:nextMonth('"+id+"');\" ><img style=\"background-color="+calbgcalcolor1+"\" border=0 src=\""+imagright+"\"></a></td></tr>")
	contenu+=("<tr><td colspan=3><table width=140 class="+classe1+"><tr align=center style=\"color='"+calcolor1+"';\" bgcolor="+calbgcalcolor1+"><td width=20>D</td><td width=20>L</td><td width=20>M</td><td width=20>M</td><td width=20>J</td><td width=20>V</td><td width=20>S</td></tr>");
	contenu+=("<tr>")
	var day=1;
	var tempDate=new Date(year[id],month[id],day);	
	var tempDate2=new Date(disableavt[id].split("/")[2],(disableavt[id].split("/")[1]-1),disableavt[id].split("/")[0]);
	
	var firstDay=tempDate.getDay();
	var i=0;
	for (i=0;i<firstDay;i++){
		contenu+="<td>&nbsp;</td>"
	}

	while(i<=6){
		tempDate=new Date(year[id],month[id],day);
		if (tempDate<tempDate2) 
			contenu+="<td align=center style=\"cursor:hand;\" bgcolor="+calbgcolor2+">"+day+"</td>"
		else
			contenu+="<td align=center style=\"cursor:hand;\" alt="+day+" onclick=\"retourdate(this,'"+id+"');\" onmouseout=\"this.style.color='';this.style.backgroundColor='';\" onmouseover=\"this.style.color='"+calcolor1+"';this.style.backgroundColor='"+calbgcalcolor1+"';\">"+day+"</td>";day++;i++;
	}
	contenu+="</tr>"
	i=0;
	while(day<=monthDays[month[id]]){
		if (i==0) contenu+="<tr>";
		tempDate=new Date(year[id],month[id],day);
		if (tempDate<tempDate2) 
			contenu+="<td align=center style=\"cursor:hand;\" bgcolor="+calbgcolor2+">"+day+"</td>"
		else
			contenu+="<td align=center style=\"cursor:hand;\" alt="+day+" onclick=\"retourdate(this,'"+id+"');\" onmouseout=\"this.style.color='';this.style.backgroundColor='';\" onmouseover=\"this.style.color='"+calcolor1+"';this.style.backgroundColor='"+calbgcalcolor1+"';\">"+day+"</td>"
		
		i++;
		if (i>6){i=0;contenu+="</tr>";}
		day++;
	}
	if ((i!=0)&&(i<=6)){	
		while(i<=6){contenu+="<td align=center>&nbsp;</td>";i++;}
		contenu+="</tr>";
	}
	contenu+='</table>';
	eval('calendar'+id).innerHTML="<table cellpadding=0 cellspacing=0 class="+classe1+" border=1 bordercolor="+calbgcalcolor1+"><tr><td>"+contenu+"</td></tr></table></td></tr><tr><td><table width=100% class="+classe1+" cellpadding=0 cellspacing=0><tr><td width=50%>&nbsp;<div style=\"cursor:'hand';display:inline\" onclick=\"Raz('"+id+"');\" >[Effacer]</div></td><td align=right><div style=\"cursor:'hand';\" onclick=\"Hide('"+id+"');\" >[Fermer]</div></td></tr></table></td></tr></table>";
	
	
}
function changeMonth(id,obj){month[id]=parseInt(obj.item(obj.selectedIndex).value);initCalendar(id);}
function changeYear(id,obj){year[id]=parseInt(obj.item(obj.selectedIndex).value);initCalendar(id);}

function nextMonth(id){
	month[id]++;
	if (month[id]>11){month[id]=0;year[id]++;}
	initCalendar(id);
}
function Raz(id){eval(objetretour[id]).value='';Hide(id);}
function retourdate(obj,id){
var jour=obj.alt;
var mois=(month[id]+1).toString();
if (jour.length<2) jour="0"+jour;
if (mois.length<2) mois="0"+mois;
eval(objetretour[id]).value=jour+"/"+mois+"/"+year[id];

Hide(id);
}
function prevMonth(id){
	month[id]--;
	if (month[id]<0){month[id]=11;year[id]--;}
	initCalendar(id);
}
function Hide(id){
eval('calendar'+id+'.style').display='none';
calshowHideSelect(1);
}
function Show(mois,annee){
if (typeof mois!='undefined') month[this.id]=mois-1;
if (typeof annee!='undefined')year[this.id]=annee;
initCalendar(this.id);
calshowHideSelect(0);
eval('calendar'+this.id+'.style').display='block';
}

function calshowHideSelect(show) {
	var showhide='';if(show==0) showhide='hidden';var n;
	for (n = 0; n < document.forms.length; n++) {
		var f = document.forms[n]
	  for (var elt = 0; elt <document.forms[n].elements.length;elt++)
			if (f[elt] != null){if (typeof f[elt] != 'undefined')if (f[elt].type.toString().indexOf("select")!= "-1")
				if((f[elt].name!='calmonth')&&(f[elt].name!='calyear'))	f[elt].style.visibility = showhide;}
	}
}

function disableBefore(dat){

	disableavt[this.id]=dat;
	initCalendar(this.id)
}
function changeObjretour(objret){objetretour[this.id]=objret;}
function Calendar(classe,bgcolor,color,imgleft,imgright,objretour,disablebefore,mois,annee){
	nbcal++;this.id=nbcal
	this.show=Show;
	this.hide=Hide;
	this.init=Init;
	this.initCalendar=initCalendar;
	this.objRetour=changeObjretour;
	
	this.disableBefore=disableBefore;
	imagleft=imgleft;imagright=imgright;
	if (typeof disablebefore=='undefined') disablebefore='';

	disableavt[nbcal]=disablebefore;
	objetretour[nbcal]=objretour;
	calbgcalcolor1=bgcolor;calcolor1=color
	if (typeof mois!='undefined') 
		month[nbcal]=mois-1;
	else
		month[nbcal]=cur_month;
	if (typeof annee!='undefined') 
		year[nbcal]=annee;
	else
		year[nbcal]=cur_year;
	classe1=classe;
	
}

function Init(){
	document.write ("<div id=calendar"+this.id+" style=\"position:absolute;display:none; background-color=#ffffff;\"></div>");
	initCalendar(this.id);
	
}

