function Calendar(Langue)
{
	var isNav = navigator.appName.indexOf("Netscape") !=-1;
	var isN6 = ((isNav) && (document.getElementById));
	var isMac = navigator.appVersion.indexOf("Macintosh") !=-1;
	var isIE = document.all;
	var isIEPC = ((isIE) && (!(isMac)))
	var now = new Date();
	
	/*propriétés*/
	
	this.Egale = '=';
	this.Langue = Langue;
	this.Nom_Layer = "divCalendar";
	this.bo_TousLesJours = false;
	this.Today = new Date(now.getFullYear(),now.getMonth(),now.getDate(),0,0,0);
	this.DateCourante = new Date(now.getFullYear(),now.getMonth(),now.getDate(),0,0,0);
	this.DateDeb = new Date(2002,1,1,0,0,0);
	this.DateFin = new Date(now.getFullYear()+1,11,1,0,0,0);
	this.Nom_Variable = "objCalendar"; //Nom de la variable donné à l'objet crée.
	this.no_clic_apres = 0; //variable qui bloque la navigation après (0 bloque pas, 1 bloque)
	this.no_clic_avant = 1; //variable qui bloque la navigation avant (0 bloque pas, 1 bloque)
	this.table_generale_css = "";
	this.texte_css = "";
	this.liens_css = "";
	this.table_entete_css = "";
	this.td_entete_css = "";
	this.td_today_css = "";
	this.bo_navig_par_date = false;
	this.bo_use_system_date = false;
	
	if (isN6)
	{
		this.h=".left";
		this.v=".top";
		this.dS="document.getElementById('";
		this.sD="').style";
		this.appComp = "true";
		this.Hauteur = "').offsetHeight";
		this.Largeur = "').offsetWidth";
		this.ECRIRE = "').innerHTML=";
		this.VISIBLE = ".visibility='visible'";
		this.fD = "')";
	}
	else 
	{
		if (isNav)
		{
			this.h=".left";
			this.v=".top";
			this.dS="document.";
			this.sD="";
			this.appComp = "true";
			this.Hauteur = ".document.height";
			this.Largeur = ".document.largeur";
			this.VISIBLE = ".visibility='show'";
			this.fD = "";
		}
		else
		{
			this.h=".pixelLeft";
			this.v=".pixelTop";
			this.dS="";
			this.sD=".style";
			this.appComp = "true";
			this.Hauteur = ".offsetHeight";
			this.Largeur = ".offsetWidth";
			this.ECRIRE = ".innerHTML=";
			this.VISIBLE = ".visibility='visible'";
			this.fD = "";
		}
	}
	
	/* méthodes utilisées */
	this.PopCalendar = PopCalendar;
	this.EcrireLien = EcrireLien;
	this.NextMonth = NextMonth;
	this.PrevMonth = PrevMonth;
	this.RenvoieDate = RenvoieDate;
	this.InitDate = InitDate;
	this.EcrireJours = EcrireJours;
	this.AfficheLayer = PositionneLayer;
	this.findPosX = findPosX;
	this.findPosY = findPosY;
	this.EcrireCalendrier = EcrireCalendrier;
	this.navig_par_date = navig_par_date;
	this.EcrireDiv = EcrireDiv;
	this.InitDate = InitDate;
	this.EcrireDiv();
}

function EcrireDiv()
{
    if (!document.getElementById(this.Nom_Layer))
    {
        var div = document.createElement('div');
        /*if (cssClass != "") div.className = cssClass;*/
        div.id = this.Nom_Layer;
        document.body.appendChild(div);
        div.style.position = 'absolute';
        div.style.left = '-500px';
        div.style.top = '-500px';
        div.style.zIndex = '3';
        div.style.width = '400px';
    }
    /*else
        div = document.getElementById(this.Nom_Layer);*/
    //return div
	//document.write("<di"+"v id=\"" + this.Nom_Layer + "\" style=\"position:absolute; left:-500px; top:-500px;z-index:3\"></di"+"v>");
}

function EcrireCalendrier()
{
//	alert(this.EcrireJours());
	eval(this.dS+this.Nom_Layer+this.ECRIRE+"this.EcrireJours()");
}


function PositionneLayer(x,y)
{	
	eval("document.getElementById(this.Nom_Layer).style.left='" + x + "px';");
	eval("document.getElementById(this.Nom_Layer).style.top='" + y + "px';");
	/*eval(this.dS+this.Nom_Layer+this.sD+this.v+this.Egale+y);
	eval(this.dS+this.Nom_Layer+this.sD+this.h+this.Egale+x);*/
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function NextMonth()
{
	this.DateCourante.setDate(1);
	this.DateCourante.setMonth(this.DateCourante.getMonth()+1);
	this.EcrireCalendrier();
}

function PrevMonth()
{
	this.DateCourante.setDate(1);
	this.DateCourante.setMonth(this.DateCourante.getMonth()-1);
	this.EcrireCalendrier();
}


function EcrireLien(mode)
{
	var DateTMP = new Date(this.DateCourante.getFullYear(),this.DateCourante.getMonth(),this.DateCourante.getDate());
	var DateCompare = new Date(this.Today.getFullYear(),this.Today.getMonth(),1);
	
	if (mode=="prev")
	{
		DateTMP.setDate(1);
		DateTMP.setMonth(DateTMP.getMonth()-1);
		
		if ((this.no_clic_avant==1 && !this.bo_TousLesJours && (DateTMP < DateCompare)) || (DateTMP < this.DateDeb))
			return ""
		else
			return "<a onmouseover=\"window.status=''\"; href=\"javascript:" + this.Nom_Variable + ".PrevMonth()\"><img src='/images/calendar/mois_prev.gif' border='0'></a>";
	}
	else
	{
		DateTMP.setDate(1);
		DateTMP.setMonth(DateTMP.getMonth()+1);
		
		if ((this.no_clic_apres==1 && !this.bo_TousLesJours && (DateTMP > DateCompare))  || (DateTMP > this.DateFin))
			return ""
		else
			return "<a onmouseover=\"window.status=''\"; href=\"javascript:" + this.Nom_Variable + ".NextMonth()\"><img src='/images/calendar/mois_suiv.gif' border='0'></a>";
			
	}
}



function PopCalendar(Hidden_Control,LeForm)
{
	Ctrl_Hidden = document.getElementById(Hidden_Control); 
	Ctrl_Label = document.getElementById("lbl_txt_" + Hidden_Control);
	var objButton  = document.getElementById("but" + Hidden_Control);
	var div_largeur = eval(this.dS+this.Nom_Layer+this.Largeur);
	this.AfficheLayer(this.findPosX(objButton)+objButton.offsetWidth,this.findPosY(objButton));
}

function RenvoieDate(DateValue,TexteValue)
{
	Ctrl_Hidden.value=DateValue;
	Ctrl_Label.innerHTML = TexteValue;
	checkExpiration();
	this.AfficheLayer(-500,-500);
}

function InitDate(Hidden_Control)
{
	if (document.getElementById(Hidden_Control))
		document.getElementById("lbl_txt_" + Hidden_Control).innerHTML=document.getElementById(Hidden_Control).value;
}

function navig_par_date(value,mode)
{
	var DateTMP = new Date(this.DateCourante.getFullYear(),this.DateCourante.getMonth(),1);
	var DateCompare = new Date(this.Today.getFullYear(),this.Today.getMonth(),1);
	var Phrase_Rec_fr = "Vous ne pouvez pas reculer à cette date là.";
	var Phrase_Av_fr = "Vous ne pouvez pas avancer à cette date là.";
	var Phrase_Rec_en = "You can not go back to this date.";
	var Phrase_Av_en = "You can not go ahead this date.";
	
	if (mode == "m") DateTMP.setMonth(value); else DateTMP.setFullYear(value);
	
	// on verifie si on peut ne 
	// depasse les limites de dates
	if (this.bo_TousLesJours) 
		this.DateCourante = DateTMP;
	else
		if ((this.no_clic_avant==1) && (DateTMP < DateCompare))
			alert(eval("Phrase_Rec_" + this.Langue));
		else
			if ((this.no_clic_apres==1) && (DateTMP > DateCompare))
				alert(eval("Phrase_Av_" + this.Langue));
			else
				this.DateCourante = DateTMP;
	
	this.EcrireCalendrier();

}

function EcrireJours()
{
	
	var month = this.DateCourante.getMonth();
	var date = this.DateCourante.getDate();
	var day = this.DateCourante.getDay();
	var year = this.DateCourante.getYear();
	var table_generale_css = this.table_generale_css == "" ? "style='background-color:#FFFFFF;border-color:gray; border-style:solid; border-width:1; border-collapse: collapse;' width='226'" : "class=" + this.table_generale_css;
	var table_entete_css = this.table_entete_css == "" ? "style='background-color:#87CEFA;'" : "class=" + this.table_entete_css;
	var td_entete_css = this.td_entete_css == "" ? "" : "class=" + this.td_entete_css;
	var liens_css = this.liens_css == "" ? "" : "class=" + this.liens_css;
	var texte_css = this.texte_css == "" ? "" : "class=" + this.texte_css;
	var td_today_css = this.td_today_css == "" ? "style='background-color; color:white;'" : "class=" + this.td_today_css;
	
	m_fr = new Array("janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre");
	m_en = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	m_abr_fr = new Array("janv.","févr.","mars","avr.","mai","juin","juil.","août","sept.","oct.","nov.","déc.");
	m_abr_en = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec");
	d_fr = new Array("Dim","Lun","Mar","Mer","Jeu","Ven","Sam");
	d_en = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	
	m = eval("m_" + this.Langue);
	m_abr = eval("m_abr_" + this.Langue);
	d = eval("d_" + this.Langue);
	
	
	if (year < 2000) year = year + 1900;
	//End of Month Calculations
	var monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	// check for leap year
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) monarr[1] = 29;
	//Finds the First Day for the Current Month
	while (date != 1){
	date = date - 1;
	day = day - 1;
	if (day < 0) day = day + 7;
	}
	
	
	CorpsTable = ""

	
    CorpsTable += "<table border='0' cellpadding='0' cellspacing='0' " + table_generale_css + " height='100%'>";
    CorpsTable += "		<tr>";
	CorpsTable += "			<td width='100%' colspan='7'>";
    CorpsTable += "				<table border='0' cellpadding='0' " + table_entete_css + " cellspacing='0' width='100%'>";
    CorpsTable += "					<tr>";
    CorpsTable += "						<td width='33%'>" + this.EcrireLien("prev") + "</td>";
    CorpsTable += "						<td width='34%' align='center' " + td_entete_css + " nowrap>";
    if (this.bo_navig_par_mois)
    {
		CorpsTable += "<select id='sel_month' name='sel_month' onchange='" + this.Nom_Variable + ".navig_par_date(this.options[this.selectedIndex].value,\"m\");'>";
		for (k=0;k<m_abr.length;k++)
		{
			CorpsTable += "<option value='" + k + "'" + (k==month ? " selected" : "") + ">" + m_abr[k] + "</option>";
		}
		CorpsTable += "</select>&nbsp;";
		
		CorpsTable += "<select id='sel_year' name='sel_year' onchange='" + this.Nom_Variable + ".navig_par_date(this.options[this.selectedIndex].value,\"y\");'>";
		for (k=this.DateDeb.getFullYear();k<=(this.no_clic_avant==1?this.DateFin.getFullYear():this.Today.getFullYear());k++)
		{
			CorpsTable += "<option value='" + k + "'" + (k==year ? " selected" : "") + ">" + k + "</option>";
		}
		CorpsTable += "</select>";
    }
    else
		 CorpsTable += m[month] + " " + year;
		 
	CorpsTable += "						</td>";
    CorpsTable += "						<td width='33%' align='right'>" + this.EcrireLien("next") + "</td>";
    CorpsTable += "					</tr>";
    CorpsTable += "				</table>";
    CorpsTable += "			</td>";
    CorpsTable += "		</tr>";
    

	CorpsTable += "		<tr height='20'>"
	for (k=0;k<d.length;k++)
	{
		CorpsTable += "<td width='14%' align='center'>" + d[k] + "</td>";
	}
	CorpsTable += "</tr>"
	if ((day+1+monarr[month])<=35) {NbCell = 34;} else {NbCell = 41;}
	for (boOuvreTR=true,i=0,NumJour=1;i<=NbCell;i++)
	{
		if (boOuvreTR) {CorpsTable += "<tr height='20'>";boOuvreTR=false;}
		if (i<day) {CorpsTable +="<td>&nbsp;</td>";}
		
		if ((i>=day)&& (i<(monarr[month]+day)))
		{
			LaDate = new Date(year,month,NumJour,0,0,0);
			
			if (this.bo_TousLesJours) //CorpsTable += "<td align='center' " + (LaDate.toString()==this.Today.toString() ? td_today_css : "") + "><a " + (LaDate.toString()==this.Today.toString() ? "" : liens_css) + " onmouseout=\"window.status='';return true;\" onmouseover=\"window.status='" + (this.Langue=="en" ? m[month] + " " + NumJour + ", " + year : NumJour + " " + m[month] + " " + year) + "';return true;\" href='javascript:" + this.Nom_Variable + ".RenvoieDate(\"" + (this.bo_use_system_date ? (this.Langue=="en" ? parseInt(month+1) + "/" + NumJour + "/" + year : NumJour + "/" + parseInt(month+1) + "/" + year) : parseInt(month+1) + "/" + NumJour + "/" + year) + "\",\"" + (this.Langue=="en" ? m[month] + " " + NumJour + ", " + year : NumJour + " " + m[month] + " " + year) + "\")'>" + NumJour + "</a></td>";
				CorpsTable += "<td align='center' " + (LaDate.toString()==this.Today.toString() ? td_today_css : "") + "><a " + (LaDate.toString()==this.Today.toString() ? "" : liens_css) + " onmouseout=\"window.status='';return true;\" onmouseover=\"window.status='" + (this.Langue=="en" ? m[month] + " " + NumJour + ", " + year : NumJour + " " + m[month] + " " + year) + "';return true;\" href='javascript:" + this.Nom_Variable + ".RenvoieDate(\"" + year + "-" +  parseInt(month+1) + "-" + NumJour + "\",\"" + (this.Langue=="en" ? m[month] + " " + NumJour + ", " + year : NumJour + " " + m[month] + " " + year) + "\")'>" + NumJour + "</a></td>";
			else
			{
				if ((LaDate<this.Today)&&(this.no_clic_avant)) //on empeche les clics sur les jours précédent la date d'aujourdhui.
					CorpsTable += "<td align='center' " + texte_css + ">" + NumJour + "</td>";
				else
					if ((LaDate>this.Today)&&(this.no_clic_apres)) //on empeche les clics sur les jours suivant la date d'aujourdhui.
						CorpsTable += "<td align='center' " + texte_css + ">" + NumJour + "</td>";
		            else //on affiche le jour. //CorpsTable += "<td align='center' " + (LaDate.toString()==this.Today.toString() ? td_today_css : "") + "><a " + (LaDate.toString()==this.Today.toString() ? "" : liens_css) + " onmouseout=\"window.status='';return true;\" onmouseover=\"window.status='" + (this.Langue=="en" ? m[month] + " " + NumJour + ", " + year : NumJour + " " + m[month] + " " + year) + "';return true;\" href='javascript:" + this.Nom_Variable + ".RenvoieDate(\"" + (this.bo_use_system_date ? (this.Langue=="en" ? parseInt(month+1) + "/" + NumJour + "/" + year : NumJour + "/" + parseInt(month+1) + "/" + year) : parseInt(month+1) + "/" + NumJour + "/" + year) + "\",\"" + (this.Langue=="en" ? m[month] + " " + NumJour + ", " + year : NumJour + " " + m[month] + " " + year) + "\")'>" + NumJour + "</a></td>";
                        CorpsTable += "<td align='center' " + (LaDate.toString() == this.Today.toString() ? td_today_css : "") + "><a " + (LaDate.toString() == this.Today.toString() ? "" : liens_css) + " onmouseout=\"window.status='';return true;\" onmouseover=\"window.status='" + (this.Langue == "en" ? m[month] + " " + NumJour + ", " + year : NumJour + " " + m[month] + " " + year) + "';return true;\" href='javascript:" + this.Nom_Variable + ".RenvoieDate(\"" + year + "-" + parseInt(month + 1) + "-" + NumJour + "\",\"" + (this.Langue == "en" ? m[month] + " " + NumJour + ", " + year : NumJour + " " + m[month] + " " + year) + "\")'>" + NumJour + "</a></td>";
			}
			NumJour+=1;
		}
		if (i>=(monarr[month]+day)) {CorpsTable += "<td>&nbsp;</td>";}
		if ((i==6)||(((i+1)%7==0)&&(i>6))) {CorpsTable += "</tr>";boOuvreTR=true;}
	}
	// on ajoute une ligne si le mois ne tient qu'en 5 semaines.
	if (NbCell==34) {CorpsTable += "<tr height='20'>"; for (k=0;k<7;k++) {CorpsTable += "<td width='14%' align='center'></td>";};CorpsTable += "</tr>";}
		
	CorpsTable += "				</table>";
	CorpsTable += "			</td>";
    CorpsTable += "		</tr>";
	CorpsTable += "</table>";
	return CorpsTable;
}


