var arrBoxMonth = new Array(); 
var calenderLayer="";
var date = SRCDate;
var win="";
var mois1, mois2, mois3;
var spacing = "";
var cont = "";
var DateRec;
var DateAnRec;

function initCalendrierTJ(NumberOfMonth, objLay) {
	NumberOfMonth = 1
	
	if (sRequest.sQueryString("r") == 2){NumberOfMonth = 2}
	if (sRequest.sQueryString("r") == 3){NumberOfMonth = 3}

	win = new RastaMartWindow();
	calenderLayer = new RastaMartLay(objLay);
	
	for (y=1;y<=NumberOfMonth;y++) {

		if ((y == 2) && (NumberOfMonth == 3)) {y = 3}
		
		if (y == 1) {
			//alert(1)
			setNewBoxMonth("mois1", date.getDate(), date.getMonth(), date.getFullYear(), date.getHours(), date.getMinutes());
			if (NumberOfMonth == 1){
				cont += getContModele(BoxMonth("mois1"));
				cont += spacing;
			}
		} 
		
		if (y == 2) {
			
			if (NumberOfMonth == 2){
			//alert(2)
				setNewBoxMonth("mois"+y, BoxMonth("mois"+eval(y+"-1")).date, BoxMonth("mois"+eval(y+"-1")).getPrevMonth(), BoxMonth("mois"+eval(y+"-1")).getPrevMonthYear(1), date.getHours(), date.getMinutes());
				
				cont += getContModele(BoxMonth("mois"+y));
				cont += spacing;
				}
		}
		
		if (y == 3) {	
			
			if (NumberOfMonth == 3){
			
				DateRec = date.getMonth() - 2;
				DateAnRec = date.getFullYear();
				
				if(DateRec==-1) {
					DateRec=11;
					DateAnRec = DateAnRec - 1;
				}
				if(DateRec==-2) {
					DateRec=10;
					DateAnRec = DateAnRec - 1;
				}
				
				
				setNewBoxMonth("mois3", date.getDate(), DateRec, DateAnRec, date.getHours(), date.getMinutes());
				if (NumberOfMonth == 3){
					cont += getContModele(BoxMonth("mois3"));
					cont += spacing;
				}
			}
		}
	}

	var layCalCont = "";
	layCalCont+=(cont);
	calenderLayer.setCont(layCalCont);
}
function getContModele(objCurrDate) {

	var strry
	var strrm
	var strrd		
	var strrdayof		
	strry = date.getFullYear()
	strrm = date.getMonth() + 1
	strrd = date.getDate()
	strrdayof = date.getDay()
		
	FirstWeek = true;
	cont = "";

	if (objCurrDate.mois==date.getMonth()&&objCurrDate.annee==date.getFullYear()) cont += "";	
	cont += paramContentOfTable;
	cont += paramContentOfTdTitre;

	var rett 
	
	rett = 1
	
	if (sRequest.sQueryString("r") == 2){rett = 2}
	if (sRequest.sQueryString("r") == 3){rett = 3}
	

	if (rett == 1){
		cont += "";	
	}
	if (rett == 2){
		cont += "";	
	}
	cont += "";	
	cont += ArrMois[objCurrDate.mois];
	cont += "&nbsp;";	
	if (rett == 3){
		cont += "";	
	}
	if (rett == 2){
		cont += "";	
	}
	cont += "";
	cont += "";
	for(i=0;i<7;i++) {
		if ((strrdayof == i) && (objCurrDate.mois==date.getMonth())){
			cont += "" + ArrTitleColumns[i] + "";
		}else{
			cont += "" + ArrTitleColumns[i] + "";
		}

	}
	cont += paramContentOfTable2;
	cont += paramSpacingEntreTitreEtBoite;
	nbrD = 0;
	
	var AffLien = 0;
	
	for(i=1;i<=ArrlastDayOfMonth[objCurrDate.mois];i++) {
		if (i==1) {	
			for(x=1;x<=7;x++) {	
				if (x<=objCurrDate.firstDayduMois) {
					cont += paramEmptyCell;
					nbrD ++;
				}
			}
		}
		cont += paramContentOfTdFull;
		var tempStrMois = eval(objCurrDate.mois+"+"+1);
		if (tempStrMois<10) tempStrMois = "0"+tempStrMois;
		tempStrMois = tempStrMois + "";
		var tempStrDate = i;
		if (tempStrDate<10) tempStrDate = "0"+tempStrDate;
		tempStrDate = tempStrDate + "";
		strLien = '';
		if ((nbrD != 0) && (nbrD != 6)){
			strLien = ZapTJ(objCurrDate.annee + tempStrMois + tempStrDate);
		}
		
		AffLien = 0
		
		if (!checkForExeption(objCurrDate.annee, tempStrMois, tempStrDate)) {
			if (objCurrDate.mois!=date.getMonth()||objCurrDate.annee!=date.getFullYear()) {
				cont += strLien;
				if ((nbrD != 0) && (nbrD != 6)){AffLien = 1}
			} else { 
				if (i<objCurrDate.date) {
					cont += strLien;
					if ((nbrD != 0) && (nbrD != 6)){AffLien = 1}
				} else if (i==objCurrDate.date) {
					if (objCurrDate.heure>DispoHeure) {
						cont += strLien;
						if ((nbrD != 0) && (nbrD != 6)){AffLien = 1}
					} else if (objCurrDate.heure==DispoHeure) {
						if (objCurrDate.minute>DispoMinute) {
							cont += strLien;
							if ((nbrD != 0) && (nbrD != 6)){AffLien = 1}
						}
					}
				}
			}
		} else {
			cont += "<a href='javascript:;' onClick='showErreur();' >";
		}
		
		if (AffLien == 0){
			cont += "<div align=center class=cadreCalendrier>" + i + "</div></a>"
		}else{
			if ((strry == objCurrDate.annee)&&(strrm == tempStrMois)&&(strrd == i)){
				cont += "<div align=center class=dateChoisi>" + i + "</div></a>"
			}else{
				cont += "<div align=center class=cadreCalendrier>" + i + "</div></a>"
			}
		}
		
		
		nbrD ++;
		if (nbrD >= 7) {
			nbrD = 0;
			}
	}
	for(nbrD=nbrD;nbrD<7;nbrD++) {
		cont += "";
	}
	cont += "";

	if (objCurrDate.mois==date.getMonth()&&objCurrDate.annee==date.getFullYear()) cont += "";
	
	return cont;
}

function ZapTJ(sDate) {
	var sAnnee = sDate.substr(0,4);
	if (sDate < 20070429 || sDate > 20080105 ) {
			return "<a href='javascript:;' onClick=\"window.open('/util/zapmedia/version10/detecte.asp?menu=1&lien=/medianet/" + sAnnee + "/CBFT/auCoeurDelActualiteCombo" + sDate + "1130.asx','fenetreInter','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=1,height=1');\" >";
	}
			else {
				return "";
				}	
			
}

function showErreur() {
	alert(strLienErreur);
}


function checkForExeption(pAnnee, pMois, pJour) {
	for (var i=0; i < jourException.length; i++) {
		var tempDate = jourException[i].split("/");
		var tempAnnee = tempDate[0];
		var tempMois = tempDate[1];
		var tempJour = tempDate[2];
		if (tempAnnee == String(pAnnee) && tempMois == String(pMois) && tempJour == String(pJour)) {
			return true;
		}
	}
	return false;
}



function BoxMonth(ID) {
	var i;
	if ( typeof(ID) == "number")
		return arrBoxMonth[ID].content;
	for ( i = 0; i < arrBoxMonth.length; i++)
	{
		if(arrBoxMonth[i].idName == ID)
			return arrBoxMonth[i].content;
	}
}


function setNewBoxMonth(boxName,boxDate, boxMonth, boxYear, nowHours, nowMinutes) {
	arrBoxMonth[arrBoxMonth.length] = new ClassObjMois(boxDate, boxMonth, boxYear, nowHours, nowMinutes);
	arrBoxMonth[arrBoxMonth.length-1].idName = boxName;
	return BoxMonth(boxName);
}
function ClassObjMois(boxDate, boxMonth, boxYear, nowHours, nowMinutes) {
	this.content = new objMois(boxDate, boxMonth, boxYear, nowHours, nowMinutes);
	this.idName = "";
}
function objMois(date, month, year, hours, minutes) {
	this.date = date
	this.mois = month;
	this.annee = year;
	this.heure = hours;
	this.minute = minutes;
	
	firstDayOfMonth = new Date();
	firstDayOfMonth.setYear(year);
	firstDayOfMonth.setMonth(month);
	firstDayOfMonth.setDate(1);
	this.firstDayduMois = firstDayOfMonth.getDay();
	
	return this;
}

objMois.prototype.getPrevMonth = function() {
	prevMonth = this.mois-1; 
	if(prevMonth==-1) prevMonth=11; 
	return prevMonth;
}
objMois.prototype.getPrevMonthYear = function() {
	prevMonth = this.mois-1;
	prevMonthYear = this.annee;
	if(prevMonth==-1) prevMonthYear-=1;
	return prevMonthYear;
}

