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+='<br><table width="205" border="0" cellspacing="0" cellpadding="0"><tr><td>';
	layCalCont+='<table width="100%"  border="0" cellspacing="0" cellpadding="0"><tr>';
	layCalCont+='<td width="33"><img src="/actualite/v2/telejournal_montreal/img/flecheColDrt.gif" border=0 width=33 height=29></td>';
	layCalCont+='<td><p class="titre">ÉCOUTEZ NOS ÉMISSIONS EN WINDOWS MÉDIA</p></td>';
	layCalCont+='</tr><tr>';
	layCalCont+='<td colspan="2"><img src="img/pointilleColonneDroite.gif" width="203" height="1" border="0" /></td>';
	layCalCont+='</tr></table>';
	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 = "";
	cont += "<table border='0' width='100%' cellspacing='0' cellpadding='0'><tr>";
	if (objCurrDate.mois==date.getMonth()&&objCurrDate.annee==date.getFullYear()) cont += "<td valign='bottom'></td>";	
	cont += "<td><table " + paramContentOfTable + "><tr>";
	cont += "<td colspan='7'><img src=Img/spacer.gif border=0 width=1 height=10></td></tr><tr><td colspan='7'" + paramContentOfTdTitre + "  ><div align=center class=calMois>"

	var rett 
	
	rett = 1
	
	if (sRequest.sQueryString("r") == 2){rett = 2}
	if (sRequest.sQueryString("r") == 3){rett = 3}
	

	if (rett == 1){
		cont += "<a href='" + location.pathname + "?r=2'>";	
	}
	if (rett == 2){
		cont += "<a href='" + location.pathname + "?r=3'>";	
	}
	cont += "««</a> ";	
	cont += ArrMois[objCurrDate.mois];
	cont += "&nbsp;";	
	if (rett == 3){
		cont += "<a href='" + location.pathname + "?r=2'>";	
	}
	if (rett == 2){
		cont += "<a href='" + location.pathname + "'>";	
	}
	cont += "»»</a></div></td></tr><table>";
	cont += "<table " + paramContentOfTable3 + "><tr>";
	for(i=0;i<7;i++) {
		if ((strrdayof == i) && (objCurrDate.mois==date.getMonth())){
			cont += "<td><div align=center class=cadreJour>" + ArrTitleColumns[i] + "</div></td>";
		}else{
			cont += "<td><div align=center class=cadreJour>" + ArrTitleColumns[i] + "</div></td>";
		}

	}
	cont += "</tr><tr><td><img src=Img/spacer.gif border=0 width=1 height=5></td></tr></table><table " + paramContentOfTable2 + ">";
	cont += paramSpacingEntreTitreEtBoite;
	cont += "<tr>";
	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 += "<td " + 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>"
			}
		}
		
		
		cont += "</td>";
		nbrD ++;
		if (nbrD >= 7) {
			nbrD = 0;
			cont += "</tr><tr>";
		}
	}
	for(nbrD=nbrD;nbrD<7;nbrD++) {
		cont += "<td></td>";
	}
	cont += "</tr></table><div class=note>Veuillez noter que les émissions sont conservées pour une période de deux mois après leur diffusion.</div></td>";

	if (objCurrDate.mois==date.getMonth()&&objCurrDate.annee==date.getFullYear()) cont += "<td valign='top'></td>";
	cont += "</tr></table> ";
	
	return cont;
}


function ZapTJ(sDate) {
	var sAnnee = sDate.substr(0,4);
	if(sDate >= 20071224 && sDate <= 20080101){
		return "";
	}else if (sDate < 20061223 || sDate > 20070101 ) {
			return "<a href='javascript:;' onClick=\"window.open('/util/zapmedia/version10/detecte.asp?menu=1&lien=/medianet/" + sAnnee + "/CBF/LheureDesComptes" + sDate + "1830.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;
}

