
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

//------------------------------------- Format JOUR/MOIS/ANNEE --------------------------------------------

function CutDateWithoutSeparator(date){
	var dateTab=new Array();
	
	if (date.length==3){
		dateTab[2]=date.substring(2,3);
		dateTab[1]=date.substring(1,2);
		dateTab[0]=date.substring(0,1);
	}
	if (date.length==4){
		dateTab[2]=date.substring(2,4);
		dateTab[1]=date.substring(1,2);
		dateTab[0]=date.substring(0,1);
	}
	if (date.length==5){
		if (date.substring(1,3)>12){
			dateTab[2]=date.substring(3,5);
			dateTab[1]=date.substring(2,3);
			dateTab[0]=date.substring(0,2);
		}
		else{
			dateTab[2]=date.substring(3,5);
			dateTab[1]=date.substring(1,3);
			dateTab[0]=date.substring(0,1);
		}
	}
	if (date.length==6){
		if (date.substring(2,4)>12){
			dateTab[2]=date.substring(2,6);
			dateTab[1]=date.substring(1,2);
			dateTab[0]=date.substring(0,1);
		}
		else{
			dateTab[2]=date.substring(4,6);
			dateTab[1]=date.substring(2,4);
			dateTab[0]=date.substring(0,2);
		}
	}
	if (date.length==7){
		if (date.substring(1,3)>12){
			dateTab[2]=date.substring(3,7);
			dateTab[1]=date.substring(2,3);
			dateTab[0]=date.substring(0,2);
		}
		else{
			dateTab[2]=date.substring(3,7);
			dateTab[1]=date.substring(1,3);
			dateTab[0]=date.substring(0,1);
		}
	}
	if (date.length==8){
		dateTab[2]=date.substring(4,8);
		dateTab[1]=date.substring(2,4);
		dateTab[0]=date.substring(0,2);
	}
	return(dateTab);
}

function CutDateWithSeparator(date){
	var dateTab=new Array();

	if ((date.substring(date.indexOf("/")+1,date.length)).indexOf("/")==-1)
		ChangeInputDateClassName(event.srcElement);
	else{
		dateTab[0]=date.substring(0,date.indexOf("/"));
		resteDate=date.substring(date.indexOf("/")+1,date.length);
		dateTab[1]=resteDate.substring(0,resteDate.indexOf("/"));
		dateTab[2]=resteDate.substring(resteDate.indexOf("/")+1,resteDate.length);
	}
	return(dateTab);	
}

function FormatYear(year){
	if (!isNaN(year)){
		year=(year.length==1)?"0"+year:year;
		return((year.length==2)?((year<20)?"20"+year:"19"+year):year);
	}
}

function CheckDate(day,month,year){
	
	if (isNaN(day)||day<1||day>31) 
		return(false); 
	if (isNaN(month)||month<1||month>12)
		return(false);

	if ((month==4||month==6||month==9||month==11)&&day>30)
		return(false);
	
	year=FormatYear(year);
	if (isNaN(year)||(year%4!=0&&month=="02"&&day>28))
		return(false);
	
	return(true);
}

function FormatDate(day,month,year){
	day=(day.length==1)?"0"+day:day;
	month=(month.length==1)?"0"+month:month;
	year=FormatYear(year);
	return(day + "/" + month + "/" + year);
}

function ChangeInputDateClassName(oElement){
	if (!oElement.requiredInError)
		oElement.className=(oElement.formatOk)?oElement.css:oElement.cssError;
}

function ValidateDate(errorMessage, p_event){
	var target = getEventSource(p_event);
	var oDate = target;
	var date  = oDate.value;
	
	oDate.errorFormatMessage=errorMessage;
	oDate.formatOk=true;

	if (Trim(date)==""){
		oDate.value="";
		ChangeInputDateClassName(oDate);
	}
	else{
		var dateTab=new Array();
		if (date.indexOf("/")==-1){
			if ((date.length<3)||(date.length>8)){
				oDate.formatOk=false;
				ChangeInputDateClassName(oDate);
			}
			else
				dateTab=CutDateWithoutSeparator(date);
		}
		else{
			var resteDate=date.substring(date.indexOf("/")+1,date.length);
			if (resteDate.indexOf("/")==-1||resteDate.indexOf("/")==resteDate.length){
				oDate.formatOk=false;
				ChangeInputDateClassName(oDate);
			}
			else
				dateTab=CutDateWithSeparator(date);
		}
		if (oDate.formatOk){
			oDate.formatOk=CheckDate(dateTab[0],dateTab[1],dateTab[2]);
			oDate.value=oDate.formatOk?FormatDate(dateTab[0],dateTab[1],dateTab[2]):date;
			ChangeInputDateClassName(oDate);
		}
	}
}

//-------------------------------------Calendrier--------------------------------------------

function PlaceCalendar(oParent,oCalendar){
	var position=FindPositionInBody(oParent);
	var right=position[0]+oCalendar.offsetWidth;
	var bottom=position[1]+10+oParent.offsetHeight+195;
	
    var leftValue = (right>document.body.offsetWidth) ? (position[0]-oCalendar.offsetWidth+oParent.offsetWidth>0 ? position[0]-oCalendar.offsetWidth+oParent.offsetWidth : position[0]) : position[0];
    var topValue = (bottom>document.body.offsetHeight) ? (position[1]-195-10>0 ? position[1]-195-10 : position[1]+oParent.offsetHeight+10): position[1]+oParent.offsetHeight+10;    
    
    oCalendar.style.left = leftValue + "px";    
    oCalendar.style.top = topValue + "px";   
}

function Calendar(oParent,id,dayValue,monthValue,yearValue,dayName,monthName,yearJump,idInput){
	var oCalendar=document.createElement("div");
	oCalendar.id=id;
	oCalendar.dayName=dayName;
	oCalendar.monthName=monthName;
	oCalendar.idInput=idInput;
	oCalendar.yearJump=yearJump;
	oCalendar.className="calendar";
	document.body.appendChild(oCalendar);
	if ((dayValue!="")&&(monthValue!="")&&(yearValue!="")){
		oCalendar.dayValue=parseInt(dayValue);
		oCalendar.monthValue=monthValue-1;
		oCalendar.yearValue=parseInt(yearValue);
		oCalendar.monthSelected=monthValue-1;
		oCalendar.yearSelected=parseInt(yearValue);
	}
	else{
		InitCalendarAtToday(id);
	}
	if ( (isIE && isWin) || (isOpera && isWin) ){
		var innerHTML;
		innerHTML="<table width='220' class='calendarTable'>";
		innerHTML+=	"<tr class='calendarTitleBackground'>";
		innerHTML+=		"<td><table width='218'>";
		innerHTML+=			"<tr class='calendarTitle'>";
		innerHTML+=				"<td><B><span id='"+id+"_caption'></span></B></td>";
		innerHTML+=				"<td align=right>";
		innerHTML+=					"<IMG SRC='../../img/croixPopUp.gif' style='cursor=hand' onclick='CloseCalendar(\""+id+"\")'>";
		innerHTML+=				"</td>";
		innerHTML+=			"</tr>";
		innerHTML+=		"</table></td>";
		innerHTML+=	"</tr>";
		innerHTML+=	"<tr onclick='CloseListes(\""+id+"\")'><td class='calendarBody'><span id='"+id+"_content'></span></td></tr>";
		innerHTML+=	"<tr class='calendarToday' onclick='CloseListes(\""+id+"\")'><td><span id='"+id+"_today'></span></td></tr>";
		innerHTML+="</table>";
		oCalendar.innerHTML=innerHTML;
	}else{//Firefox Chrome
		var oTable=document.createElement("table");
		oTable.className="calendarTable";
		oTable.width="220";
		var oTr=document.createElement("tr");
		oTr.className="calendarTitleBackground";
		var oTd=document.createElement("td");
		
		var oTableInt=document.createElement("table");
		oTableInt.width="218";
		var oTrInt=document.createElement("tr");
		oTrInt.className="calendarTitle";
		var oTdInt=document.createElement("td");
		var oBInt=document.createElement("b");
		var oSpanInt=document.createElement("span");
		oSpanInt.id=id+"_caption";
		oBInt.appendChild(oSpanInt); 
		oTdInt.appendChild(oBInt); 
		oTrInt.appendChild(oTdInt); 
		var oTdInt1=document.createElement("td");
		oTdInt1.align="right";
		var oImg=document.createElement("img");
		oImg.src="../../img/croixPopUp.gif";
		oImg.setAttribute("onclick", "CloseCalendar('"+id+"');");	
		oImg.style.cursor="hand";
		oTdInt1.appendChild(oImg); 
		oTrInt.appendChild(oTdInt1); 
		oTableInt.appendChild(oTrInt); 
		
		oTd.appendChild(oTableInt); 
		oTr.appendChild(oTd); 
		oTable.appendChild(oTr); 
		
		var oTr1=document.createElement("tr");
		oTr1.onclick="CloseListes("+id+")";
		var oTd1=document.createElement("td");
		oTd1.className="calendarBody";
		var oSpan=document.createElement("span");
		oSpan.id=id+"_content";
		oTd1.appendChild(oSpan); 
		oTr1.appendChild(oTd1); 
		oTable.appendChild(oTr1); 
		
		var oTr2=document.createElement("tr");
		oTr2.onclick="CloseListes("+id+")";
		oTr2.className="calendarToday";
		var oTd2=document.createElement("td");
		var oSpan1=document.createElement("span");
		oSpan1.id=id+"_today";
		oTd2.appendChild(oSpan1); 
		oTr2.appendChild(oTd2); 
		oTable.appendChild(oTr2); 
		
		oCalendar.appendChild(oTable); 
	}
	PlaceCalendar(oParent,oCalendar);
}
function test(event,test){
	alert(test);
}
function CalendarHeader(idCalendar, idInput){
	var oCalendar=document.getElementById(idCalendar);
	if ( (isIE && isWin) || (isOpera && isWin) ){
		var innerHTML = "";
		innerHTML= "<span unselectable=on class='calendarTitleControlNormal' onclick='decMonth(\""+idCalendar+"\",\""+idInput+"\");CloseListes(\""+idCalendar+"\")'>&nbsp<&nbsp</span>&nbsp;";
		innerHTML+="<span unselectable=on id='"+idCalendar+"_month_select' class='calendarTitleControlNormal' onclick='PopUpMonthList(\""+idCalendar+"\",\""+idInput+"\");PopDownYearList(\""+idCalendar+"\")'></span>&nbsp;";
		innerHTML+="<span unselectable=on class='calendarTitleControlNormal' onclick='incMonth(\""+idCalendar+"\",\""+idInput+"\");CloseListes(\""+idCalendar+"\")'>&nbsp>&nbsp</span>&nbsp;";
		innerHTML+="<span unselectable=on class='calendarTitleControlNormal' onclick='decYear(\""+idCalendar+"\",\""+idInput+"\");CloseListes(\""+idCalendar+"\")'>&nbsp<&nbsp</span>&nbsp;";
		innerHTML+="<span unselectable=on id='"+idCalendar+"_year_select'  class='calendarTitleControlNormal' onclick='PopUpYearList(\""+idCalendar+"\",\""+idInput+"\");PopDownMonthList(\""+idCalendar+"\")'></span>&nbsp;";
		innerHTML+="<span unselectable=on class='calendarTitleControlNormal' onclick='incYear(\""+idCalendar+"\",\""+idInput+"\");CloseListes(\""+idCalendar+"\")'>&nbsp>&nbsp</span>&nbsp;";
		document.getElementById(idCalendar+"_caption").innerHTML=innerHTML;
	}else{
		var oSpan=document.createElement("span");
		oSpan.unselectable="on";
		oSpan.className="calendarTitleControlNormal";
		oSpan.setAttribute("onclick", "decMonth('"+idCalendar+"','"+idInput+"');CloseListes('"+idCalendar+"');");
		var oTxtSpan = document.createTextNode('\u00a0<\u00a0'); 
		oSpan.appendChild(oTxtSpan); 
		var oSpan1=document.createElement("span");
		oSpan1.unselectable="on";
		oSpan1.id=idCalendar+"_month_select";
		oSpan1.className="calendarTitleControlNormal";
		oSpan1.setAttribute("onclick", "PopUpMonthList('"+idCalendar+"','"+idInput+"');PopDownYearList('"+idCalendar+"');");
		var oSpan2=document.createElement("span");
		oSpan2.unselectable="on";
		oSpan2.className="calendarTitleControlNormal";
		oSpan2.setAttribute("onclick", "incMonth('"+idCalendar+"','"+idInput+"');CloseListes('"+idCalendar+"');");
		var oTxtSpan2 = document.createTextNode('\u00a0>\u00a0'); 
		oSpan2.appendChild(oTxtSpan2); 
		var oSpan3=document.createElement("span");
		oSpan3.unselectable="on";
		oSpan3.className="calendarTitleControlNormal";
		oSpan3.setAttribute("onclick", "decYear('"+idCalendar+"','"+idInput+"');CloseListes('"+idCalendar+"');");
		var oTxtSpan3 = document.createTextNode('\u00a0<\u00a0'); 
		oSpan3.appendChild(oTxtSpan3);
		var oSpan4=document.createElement("span");
		oSpan4.unselectable="on";
		oSpan4.id=idCalendar+"_year_select";
		oSpan4.className="calendarTitleControlNormal";
		oSpan4.setAttribute("onclick", "PopUpYearList('"+idCalendar+"','"+idInput+"');PopDownMonthList('"+idCalendar+"');");
		var oSpan5=document.createElement("span");
		oSpan5.unselectable="on";
		oSpan5.className="calendarTitleControlNormal";
		oSpan5.setAttribute("onclick", "incYear('"+idCalendar+"','"+idInput+"');CloseListes('"+idCalendar+"');");	
		var oTxtSpan5 = document.createTextNode('\u00a0>\u00a0'); 
		oSpan5.appendChild(oTxtSpan5); 
		var oCaption=document.getElementById(idCalendar+"_caption");
		oCaption.appendChild(oSpan);
		oCaption.appendChild(document.createTextNode('\u00a0'));
		oCaption.appendChild(oSpan1);
		oCaption.appendChild(document.createTextNode('\u00a0'));
		oCaption.appendChild(oSpan2);
		oCaption.appendChild(document.createTextNode('\u00a0'));
		oCaption.appendChild(oSpan3);
		oCaption.appendChild(document.createTextNode('\u00a0'));
		oCaption.appendChild(oSpan4);
		oCaption.appendChild(document.createTextNode('\u00a0'));
		oCaption.appendChild(oSpan5);
		oCaption.appendChild(document.createTextNode('\u00a0'));
	}
	
}

function CloseCalendar(idCalendar){
	var oCalendar=document.getElementById(idCalendar);
	if ((String(oCalendar.dayValue)!="")&&(String(oCalendar.monthValue)!="")&&(String(oCalendar.yearValue)!="")){
		oCalendar.monthValue++;
		var dateCalendar = FormatDate(String(oCalendar.dayValue),String(oCalendar.monthValue),String(oCalendar.yearValue));
		var oInput = document.getElementById(oCalendar.idInput);
		if (dateCalendar!=oInput.value){
			oInput.value = dateCalendar;
			oInput.formatOk=true;
			ChangeInputDateClassName(oInput);
		}
	}
	var position=FindPositionInBody(oCalendar);
	ChangeAllElementVisibility("select","visible",position[0],position[1],oCalendar.offsetWidth,oCalendar.offsetHeight);
	ChangeFamilyAllElementVisibility("td_date","visible",position[0],position[1]+6,oCalendar.offsetWidth,oCalendar.offsetHeight);
	ChangeFamilyAllElementVisibility("td_buttonWithPopUp","visible",position[0],position[1]+6,oCalendar.offsetWidth,oCalendar.offsetHeight);
	document.body.removeChild(oCalendar);
}

function CloseListes(idCalendar){
	PopDownMonthList(idCalendar);
	PopDownYearList(idCalendar);
}

//--Pied du Calendrier--
function CalendarToday(idCalendar, idInput){
	var oCalendar=document.getElementById(idCalendar);
	var oToday=document.getElementById(idCalendar+"_today");

	var innerHTML;
	innerHTML="<a class='calendarToday' id='calendarToday' href='javascript:";
	innerHTML+="document.getElementById(\""+idCalendar+"\").monthSelected=(new Date()).getMonth();";
	innerHTML+="document.getElementById(\""+idCalendar+"\").yearSelected=(new Date()).getFullYear();";
	innerHTML+="CalendarContent(\""+idCalendar+"\",\""+idInput+"\");'>";
	innerHTML+=oCalendar.dayName[((new Date()).getDay()-1==-1)?6:((new Date()).getDay()-1)]+", ";
	innerHTML+=(new Date()).getDate() + " " + oCalendar.monthName[(new Date()).getMonth()].substring(0,3)+" ";
	innerHTML+=(new Date()).getFullYear() + "</a>"
	oToday.innerHTML=innerHTML;
}

//--Gestion des mois--
function ChangeSelectedMonth(idCalendar){
	var oCalendar=document.getElementById(idCalendar);
	var oMonth=document.getElementById(idCalendar+"_month_select");
	oMonth.innerText=oCalendar.monthName[oCalendar.monthSelected];
}

function incMonth(idCalendar, idInput){
	var oCalendar=document.getElementById(idCalendar);
	oCalendar.monthSelected++;
	if (oCalendar.monthSelected>11){
		oCalendar.monthSelected=0;
		oCalendar.yearSelected++;
		ChangeSelectedYear(idCalendar);
	}
	ChangeSelectedMonth(idCalendar);
	CalendarContent(idCalendar, idInput);
}

function decMonth(idCalendar, idInput){
	var oCalendar=document.getElementById(idCalendar);
	oCalendar.monthSelected--;
	if (oCalendar.monthSelected<0){
		oCalendar.monthSelected=11;
		oCalendar.yearSelected--;
		ChangeSelectedYear(idCalendar);
	}
	ChangeSelectedMonth(idCalendar);
	CalendarContent(idCalendar, idInput);
}

//--Liste des mois--
function MonthList(idCalendar){
	var oMonth=document.createElement("div");
	oMonth.id=idCalendar+"_month_list";
	PlaceElement(idCalendar,oMonth,24,23)
}

function PopUpMonthList(idCalendar, idInput){
	var oCalendar=document.getElementById(idCalendar);
	var oMonthList=document.getElementById(idCalendar+"_month_list");

	if ( (isIE && isWin) || (isOpera && isWin) ){
		sHTML =	"";
		for(i=0;i<12;i++){
			month =	oCalendar.monthName[i];
			if (i==oCalendar.monthSelected)
				month =	"<B>" +	month +	"</B>";
			sHTML+="<tr><td onmouseover='this.className=\"calendarDropdownSelect\"' ";
			sHTML+="onmouseout='this.className=\"calendarDropdownNormal\"' ";
			sHTML+="onclick='document.getElementById(\""+idCalendar+"\").monthSelected=" + i + ";";
			sHTML+="PopDownMonthList(\""+idCalendar+"\");ChangeSelectedMonth(\""+idCalendar+"\");";
			sHTML+="CalendarContent(\""+idCalendar+"\", \"" + idInput + "\")'>";
			sHTML+="&nbsp;" + month + "&nbsp;</td></tr>";
		}
		
	        oMonthList.innerHTML = "<table width=70 class='calendarDropdown' cellspacing=0>" + sHTML + "</table>";
	}else{
		var oTable=document.createElement("table");
		oTable.width="70";
		oTable.className="calendarDropdown";
		oTable.cellspacing="0";
		for(i=0;i<12;i++){
			month =	oCalendar.monthName[i];
			if (i==oCalendar.monthSelected){
				oB=document.createElement("b");
				oTxtMois = document.createTextNode(month); 
				oB.appendChild(oTxtMois);
			}
			oTr=document.createElement("tr");
			oTd=document.createElement("td");
			oTd.setAttribute("onmouseover", "this.className='calendarDropdownSelect'");
			oTd.setAttribute("onmouseout", "this.className='calendarDropdownNormal'");
			oTd.setAttribute("onclick", "document.getElementById('"+idCalendar+"').monthSelected=" + i + ";" +
					"PopDownMonthList('"+idCalendar+"');ChangeSelectedMonth('"+idCalendar+"');" +
					"CalendarContent('"+idCalendar+"', '" + idInput + "')");
			oTxtTd = document.createTextNode("\u00a0" + month + "\u00a0"); 
			oTd.appendChild(oTxtTd);
			oTr.appendChild(oTd);
			oTable.appendChild(oTr);
		}
		if ( oMonthList.hasChildNodes() )
			oMonthList.removeChild( oMonthList.firstChild );
		oMonthList.appendChild(oTable);
	}
    oMonthList.style.left = document.getElementById(idCalendar+"_month_list").offsetLeft + "px";
    oMonthList.style.top = document.getElementById(idCalendar+"_month_list").offsetTop + "px";
    oMonthList.style.visibility="visible";
}

function PopDownMonthList(idCalendar){
	document.getElementById(idCalendar+"_month_list").style.visibility="hidden";
}


//--Liste des années--
function ChangeSelectedYear(idCalendar){
	var oCalendar=document.getElementById(idCalendar);
	var oYear=document.getElementById(idCalendar+"_year_select");
	oYear.innerText=oCalendar.yearSelected;
}

function YearList(idCalendar){
	var oYear=document.createElement("div");
	oYear.id=idCalendar+"_year_list";
	PlaceElement(idCalendar,oYear,0,23);
}

function decYear(idCalendar, idInput){
	var oCalendar=document.getElementById(idCalendar);
	oCalendar.yearSelected--;
	ChangeSelectedYear(idCalendar);
	CalendarContent(idCalendar, idInput);
}

function incYear(idCalendar, idInput){
	var oCalendar=document.getElementById(idCalendar);
	oCalendar.yearSelected++;
	ChangeSelectedYear(idCalendar);
	CalendarContent(idCalendar, idInput);
}

function decYearList(idCalendar){
	var oCalendar=document.getElementById(idCalendar);
	var oYearList=document.getElementById(idCalendar+"_year_list");
	
	for (var i=0; i<7; i++){
		year = (i-1)*oCalendar.yearJump+oYearList.startingYear;
		if (year==oCalendar.yearSelected)
			innerHTML = "&nbsp;<B>" + year + "</B>&nbsp;"; 
		else
			innerHTML = "&nbsp;" + year + "&nbsp;";
	document.getElementById(idCalendar+"_year_list_"+i).innerHTML = innerHTML;
	}
	oYearList.startingYear=oYearList.startingYear-oCalendar.yearJump;
}

function incYearList(idCalendar){
	var oCalendar=document.getElementById(idCalendar);
	var oYearList=document.getElementById(idCalendar+"_year_list");
	
	for (var i=0; i<7; i++){
		year = (i+1)*oCalendar.yearJump+oYearList.startingYear;
		if (year==oCalendar.yearSelected)
			innerHTML = "&nbsp;<B>" + year + "</B>&nbsp;"; 
		else
			innerHTML = "&nbsp;" + year + "&nbsp;";
	document.getElementById(idCalendar+"_year_list_"+i).innerHTML = innerHTML;
	}
	oYearList.startingYear=oYearList.startingYear+oCalendar.yearJump;
}

function SelectYear(nYear,idCalendar, idInput){
	document.getElementById(idCalendar).yearSelected=nYear*oCalendar.yearJump+document.getElementById(idCalendar+"_year_list").startingYear;
	ChangeSelectedYear(idCalendar);
	PopDownYearList(idCalendar);
	CalendarContent(idCalendar, idInput);
}
	
function PopUpYearList(idCalendar, idInput){
	var oCalendar=document.getElementById(idCalendar);
	var oYearList=document.getElementById(idCalendar+"_year_list");

	if ( (isIE && isWin) || (isOpera && isWin) ){
		sHTML="<tr><td align='center' unselectable=on ";
		sHTML+="onmouseover='this.className=\"calendarDropdownSelect\"' ";
		sHTML+="onmouseout='this.className=\"calendarDropdownNormal\"' ";
		sHTML+="onclick='decYearList(\""+idCalendar+"\")'>-</td></tr>";
			
		var yearString;
		oYearList.startingYear = oCalendar.yearSelected-3*oCalendar.yearJump;
		for (var i=0; i<7; i++) {
			year = i*oCalendar.yearJump+oYearList.startingYear;
			if (year==oCalendar.yearSelected)
				yearString =	"<B>"+year+"</B>";
			else
				yearString = year;
			sHTML+="<tr><td id='"+idCalendar+"_year_list_"+i+"' align='middle'";
			sHTML+="onmouseover='this.className=\"calendarDropdownSelect\"' ";
			sHTML+="onmouseout='this.className=\"calendarDropdownNormal\"' ";
			sHTML+="onclick='SelectYear("+i+",\""+idCalendar+"\",\""+idInput+"\")'>"
			sHTML+=yearString+"</td></tr>";
		}
			
		sHTML+="<tr><td align='center' unselectable=on ";
		sHTML+="onmouseover='this.className=\"calendarDropdownSelect\"' ";
		sHTML+="onmouseout='this.className=\"calendarDropdownNormal\"' ";
		sHTML+="onclick='incYearList(\""+idCalendar+"\")'>+</td></tr>";
	
		oYearList.innerHTML="<table width=44 class='calendarDropdown' cellspacing=0>" + sHTML + "</table>";
	}else{
		var oTable=document.createElement("table");
		oTable.width="44";
		oTable.className="calendarDropdown";
		oTable.cellspacing="0";
		var oTrtitle=document.createElement("tr");
		var oTdtitle=document.createElement("td");
		oTdtitle.setAttribute("onmouseover", "this.className='calendarDropdownSelect'");
		oTdtitle.setAttribute("onmouseout", "this.className='calendarDropdownNormal'");
		oTdtitle.setAttribute("onclick", "decYearList('"+idCalendar+"')");
		oTrtitle.appendChild(oTdtitle); 
		oTable.appendChild(oTrtitle); 
		
		var yearString;
		oYearList.startingYear = oCalendar.yearSelected-3*oCalendar.yearJump;
		for (var i=0; i<7; i++) {
			year = i*oCalendar.yearJump+oYearList.startingYear;
			if (year==oCalendar.yearSelected){
				
				yearString=document.createElement("b");
				oTxt = document.createTextNode(year); 
				yearString.appendChild(oTxt);
			}else{
				yearString=document.createTextNode(year); 
			}
			oTr=document.createElement("tr");
			oTd=document.createElement("td");
			oTd.id=idCalendar+"_year_list_"+i+"";
			oTd.aligne="middle";
			oTd.setAttribute("onmouseover", "this.className='calendarDropdownSelect'");
			oTd.setAttribute("onmouseout", "this.className='calendarDropdownNormal'");
			oTd.setAttribute("onclick", "SelectYear("+i+",'"+idCalendar+"','"+idInput+"');");
			oTd.appendChild(yearString); 
			oTr.appendChild(oTd); 
			oTable.appendChild(oTr); 
		}
		var oTrFin=document.createElement("tr");
		var oTdFin=document.createElement("td");
		oTdFin.aligne="middle";
		oTdFin.setAttribute("onmouseover", "this.className='calendarDropdownSelect'");
		oTdFin.setAttribute("onmouseout", "this.className='calendarDropdownNormal'");
		oTdFin.setAttribute("onclick", "incYearList('"+idCalendar+"')");
		oTrFin.appendChild(oTdFin); 
		oTable.appendChild(oTrFin); 
		if ( oYearList.hasChildNodes() )
			oYearList.removeChild( oYearList.firstChild );
		oYearList.appendChild(oTable); 
	}
    oYearList.style.left = document.getElementById(idCalendar+"_year_select").offsetLeft + "px";
    oYearList.style.top = document.getElementById(idCalendar+"_year_select").offsetTop + "px";
	
	oYearList.style.visibility="visible";
}

function PopDownYearList(idCalendar){
	document.getElementById(idCalendar+"_year_list").style.visibility= "hidden";
}


//--Corps du calendrier--
function CalendarContent(idCalendar, idInput){
	var oCalendar=document.getElementById(idCalendar);
	var dateMessage;
	var startDate=new Date(oCalendar.yearSelected,oCalendar.monthSelected,1);
	var endDate=new Date (oCalendar.yearSelected,oCalendar.monthSelected+1,1);
	var endDate=new Date (endDate-(24*60*60*1000));
	var numDaysInMonth=endDate.getDate();

	var datePointer=0;
	dayPointer=startDate.getDay()-1;
		
	if (dayPointer<0)
		dayPointer=6;

	if ( (isIE && isWin) || (isOpera && isWin) ){
		sHTML="<table border=0 class='calendarBody'><tr>"
		for (var i=0; i<7; i++)
			sHTML+="<td width='27' align='right'><B>"+ oCalendar.dayName[i]+"</B></td>";
		sHTML +="</tr><tr>";
			
		for (var i=1; i<=dayPointer;i++ )
			sHTML+="<td>&nbsp;</td>"
		for (datePointer=1; datePointer<=numDaysInMonth; datePointer++ ){
			dayPointer++;
			sHTML+="<td align=right>"
	
			var selectedDay = (datePointer==oCalendar.dayValue) && (oCalendar.monthSelected==oCalendar.monthValue) && (oCalendar.yearSelected==oCalendar.yearValue);
			
			var sStyle= (!selectedDay) ? "calendarNormalDay" : "calendarNormalSelectedDay" ;
			
			if ((datePointer==(new Date()).getDate())&&(oCalendar.monthSelected==(new Date()).getMonth())&&(oCalendar.yearSelected==(new Date()).getYear()))
				sStyle = (!selectedDay) ? "calendarCurrentDay" : "calendarCurrentSelectedDay"; 	
			else if	(dayPointer % 7 == 0)
				sStyle = (!selectedDay) ? "calendarEndOfWeekDay" : "calendarEndOfWeekSelectedDay";
	
			var sHint = ""
			var regexp= /\"/g;
			sHint=sHint.replace(regexp,"&quot;");
			sHTML+="<a id='"+sStyle+"' ";
			sHTML+="href='javascript:document.getElementById(\""+idCalendar+"\").dayValue="+datePointer+";";
			sHTML+="document.getElementById(\""+idCalendar+"\").monthValue=document.getElementById(\""+idCalendar+"\").monthSelected;";
			sHTML+="document.getElementById(\""+idCalendar+"\").yearValue=document.getElementById(\""+idCalendar+"\").yearSelected;";
			sHTML+="CloseCalendar(\""+idCalendar+"\");";
			sHTML+="document.getElementById(\""+idInput+"\").focus();";
			sHTML+="document.getElementById(\""+idInput+"\").blur(); '>";
			sHTML+="&nbsp;" + datePointer + "&nbsp;</a>";
			if ((dayPointer+1) % 7 == 1) 
				sHTML += "</tr><tr>";
		}
	
		document.getElementById(idCalendar+"_content").innerHTML = sHTML;
		document.getElementById(idCalendar+"_month_select").innerHTML = "&nbsp;"+oCalendar.monthName[oCalendar.monthSelected]+"&nbsp;";
		document.getElementById(idCalendar+"_year_select").innerHTML =	"&nbsp;"+oCalendar.yearSelected+"&nbsp;";
	}else{
		
		//Dom special chrome / firefox
		var oTable=document.createElement("table");
		oTable.className="calendarBody";
		var oTrJour=document.createElement("tr");
		for (var i=0; i<7; i++){
			oTdJour=document.createElement("td");
			oTdJour.width="27"; 
			oTdJour.align="right"; 
			oBJour=document.createElement("b");
			oTxtJour = document.createTextNode(oCalendar.dayName[i]); 
			oBJour.appendChild(oTxtJour); 
			oTdJour.appendChild(oBJour); 
			oTrJour.appendChild(oTdJour); 
		}
		oTable.appendChild(oTrJour); 
		oTrEspace=document.createElement("tr");
		for (var i=1; i<=dayPointer;i++ ){
			oTdEspace=document.createElement("td");
			oTxtEspace = document.createTextNode('\u00a0'); 
			oTdEspace.appendChild(oTxtEspace); 
			oTrEspace.appendChild(oTdEspace); 
		}
		for (datePointer=1; datePointer<=numDaysInMonth; datePointer++ ){
			dayPointer++;
			oTdJr=document.createElement("td");
			oTdJr.align="right"; 
	
			var selectedDay = (datePointer==oCalendar.dayValue) && (oCalendar.monthSelected==oCalendar.monthValue) && (oCalendar.yearSelected==oCalendar.yearValue);
			
			var sStyle= (!selectedDay) ? "calendarNormalDay" : "calendarNormalSelectedDay" ;
			
			if ((datePointer==(new Date()).getDate())&&(oCalendar.monthSelected==(new Date()).getMonth())&&(oCalendar.yearSelected==(new Date()).getYear()))
				sStyle = (!selectedDay) ? "calendarCurrentDay" : "calendarCurrentSelectedDay"; 	
			else if	(dayPointer % 7 == 0)
				sStyle = (!selectedDay) ? "calendarEndOfWeekDay" : "calendarEndOfWeekSelectedDay";
	
			var sHint = ""
			var regexp= /\"/g;
			sHint=sHint.replace(regexp,"&quot;");
			oA=document.createElement("a");
			oA.id=sStyle;
			oA.setAttribute("href", "javascript:document.getElementById('"+idCalendar+"').dayValue="+datePointer+";" +
					"document.getElementById('"+idCalendar+"').monthValue=document.getElementById('"+idCalendar+"').monthSelected;" +
					"document.getElementById('"+idCalendar+"').yearValue=document.getElementById('"+idCalendar+"').yearSelected;" +
					"CloseCalendar('"+idCalendar+"');" +
					"document.getElementById('"+idInput+"').focus();" +
					"document.getElementById('"+idInput+"').blur();"); 
			oTxtA = document.createTextNode("\u00a0" + datePointer + "\u00a0"); 
			oA.appendChild(oTxtA); 
			oTdJr.appendChild(oA); 
			oTrEspace.appendChild(oTdJr); 
			if ((dayPointer+1) % 7 == 1) {				
				oTable.appendChild(oTrEspace); 
				oTrEspace=document.createElement("tr");
			}			
		}
		oTable.appendChild(oTrEspace); 
		var oContent=document.getElementById(idCalendar+"_content");
		if ( oContent.hasChildNodes() )
			oContent.removeChild( oContent.firstChild );   
		oContent.appendChild(oTable); 
		var oMoisSelected=document.getElementById(idCalendar+"_month_select");
		oTxtMois = document.createTextNode("\u00a0" + oCalendar.monthName[oCalendar.monthSelected] + "\u00a0"); 
		if ( oMoisSelected.hasChildNodes() )
			oMoisSelected.removeChild( oMoisSelected.firstChild );   
		oMoisSelected.appendChild(oTxtMois); 
		var oAnneeSelected=document.getElementById(idCalendar+"_year_select");
		oTxtAnnee = document.createTextNode("\u00a0" + oCalendar.yearSelected + "\u00a0"); 
		if ( oAnneeSelected.hasChildNodes() )
			oAnneeSelected.removeChild( oAnneeSelected.firstChild );   
		oAnneeSelected.appendChild(oTxtAnnee); 

	}
}


function InitCalendarAtToday(idCalendar){
	oCalendar=document.getElementById(idCalendar);
	oCalendar.monthSelected=(new Date()).getMonth();
	oCalendar.yearSelected=(new Date()).getFullYear();
	oCalendar.dayValue="";
	oCalendar.monthValue="";
	oCalendar.yearValue="";
}

function ShowCalendar(parent,id,idInput,dayName,monthName,yearJump, event){
	if(!document.getElementById(id)){
		var dayValue=""; var monthValue=""; var yearValue="";
		var date=document.getElementById(idInput).value;
		if (date.indexOf("/")!=-1){
			var dateTab=new Array();
			dateTab=CutDateWithSeparator(date);
			dateTab[2]=FormatYear(dateTab[2]);
			if (CheckDate(dateTab[0],dateTab[1],dateTab[2])==true){
				dayValue=dateTab[0]; monthValue=dateTab[1]; yearValue=dateTab[2];
			}			
		}
		oParent = getEventSource(event);
		
		Calendar(oParent,id,dayValue,monthValue,yearValue,dayName,monthName,yearJump,idInput);
		MonthList(id);
		YearList(id);
		CalendarHeader(id, idInput);
		CalendarContent(id, idInput);
		CalendarToday(id, idInput);
		oCalendar=document.getElementById(id);
		var position=FindPositionInBody(oCalendar);
		ChangeAllElementVisibility("select","hidden",position[0],position[1],oCalendar.offsetWidth,oCalendar.offsetHeight);
		ChangeFamilyAllElementVisibility("td_date","hidden",position[0],position[1]+6,oCalendar.offsetWidth,oCalendar.offsetHeight);
		ChangeFamilyAllElementVisibility("td_buttonWithPopUp","hidden",position[0],position[1]+6,oCalendar.offsetWidth,oCalendar.offsetHeight);
	}
}


//------------------------------------------- Format JOUR/MOIS -------------------------------------------

function CutJourMoisWithoutSeparator(date){
	var dateTab=new Array();
	
	if (date.length==2){
		dateTab[1]=date.substring(1,2);
		dateTab[0]=date.substring(0,1);
	}
	if (date.length==3){
		if (date.substring(1,3)>12){
			dateTab[1]=date.substring(2,3);
			dateTab[0]=date.substring(0,2);
		}
		else{
			dateTab[1]=date.substring(1,3);
			dateTab[0]=date.substring(0,1);
		}
	}
	if (date.length==4){
		dateTab[1]=date.substring(2,4);
		dateTab[0]=date.substring(0,2);
	}
	
	return(dateTab);
}

function CutJourMoisWithSeparator(date){
	var dateTab=new Array();

	dateTab[0]=date.substring(0,date.indexOf("/"));
	dateTab[1]=date.substring(date.indexOf("/")+1,date.length);

	return(dateTab);	
}

function CheckJourMois(day,month){
	
	if (isNaN(day)||day<1||day>31) 
		return(false); 
	if (isNaN(month)||month<1||month>12)
		return(false);

	if ((month==4||month==6||month==9||month==11)&&day>30)
		return(false);

	if (month==2&&day>28)
		return(false)
	
	return(true);
}

function FormatJourMois(day,month){
	day=(day.length==1)?"0"+day:day;
	month=(month.length==1)?"0"+month:month;
	return(day + "/" + month);
}

function ValidateJourMois(errorMessage){
	var oJourMois = event.srcElement;
	var jourMois  = oJourMois.value;
	
	oJourMois.errorFormatMessage = errorMessage;
	oJourMois.formatOk=true;

	if (Trim(jourMois)==""){
		oJourMois.value="";
		ChangeInputDateClassName(oJourMois);
	}
	else{
		var dateTab=new Array();
		if (jourMois.indexOf("/")==-1){
			if (jourMois.length>4){
				oJourMois.formatOk=false;
				ChangeInputDateClassName(oJourMois);
			}
			else
				dateTab=CutJourMoisWithoutSeparator(jourMois);
		}
		else{
				dateTab=CutJourMoisWithSeparator(jourMois);
		}
		if (oJourMois.formatOk){
			oJourMois.formatOk=CheckJourMois(dateTab[0],dateTab[1]);
			oJourMois.value=oJourMois.formatOk?FormatJourMois(dateTab[0],dateTab[1]):jourMois;
			ChangeInputDateClassName(oJourMois);
		}
	}
}