/* version du 15 novembre 2007 - cedric sam */

var arrBoxMonth = new Array(); 
var calenderLayer="";
var date = SRCDate;
var win="";
var mois1, mois2, mois3;
var spacing = "";
var cont = "";
var DateRec;
var DateAnRec;
var daysOfShow = new Array("0","1","2","3","4","5","6"); /* Dimanche = 0 ; Lundi = 1; etc. Ne pas omettre guillemets, lorsque une seule journee */
var timeShow = "2200";
var showName = "/CBFT/telejournal";
var calendarNote = "Veuillez noter que les émissions sont conservées pour une période de deux mois après leur diffusion.";
var startDate = "20070601"; /* Date de debut des emissions */

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+='<table width="100%" border=0 cellspacing="0" cellpadding="1">';
	layCalCont+='<tr valign=top>';
	layCalCont+='<td align="center">';	
	layCalCont+='<table width="100%" border=0 cellspacing="0" cellpadding="2" class="calCouleur">';
	layCalCont+='<tr valign=top>';
	layCalCont+='<td align="center"><img src=Img/spacer.gif border=0 width=1 height=1>';	
	layCalCont+='</td></tr><tr valign=top>';
	layCalCont+='<td align="center">';	
	layCalCont+='';
	layCalCont+=(cont);
	layCalCont+='</td>';
	layCalCont+='</tr></table> ';
	layCalCont+='</td>';
	layCalCont+='</tr></table> ';
	
	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><div align=center><span class=heure>TOUS LES SOIRS<br>SUR RDI à 21 H (HNE),<br>SUR RADIO-CANADA À 22 H (HNE)<br>ET SUR RDI À 23 H (HNE)<br><br></span></div><table width=99% align=center  border=0 cellpadding=3 cellspacing=0 background='img/trans.gif' bgcolor=#4A3B36><tr><td class=note><div align=center>Regarder nos émissions en&nbsp;windows média</div></td></tr></table><table " + paramContentOfTable + "><tr>";
	cont += "<td colspan='7'><img src=Img/spacer.gif border=0 width=1 height=4></td></tr><tr><td colspan='7'" + paramContentOfTdTitre + " class='titre' ><div align=center ><B>"
	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 + "";
		
		if (AffLien == 0){
			cont += "<div align=center class=cadreCalendrier>";
		}else{
			if ((strry == objCurrDate.annee)&&(strrm == tempStrMois)&&(strrd == i)){
				cont += "<div align=center class=dateChoisi>";
			}else{
				cont += "<div align=center class=cadreCalendrier>";
			}
		}

		strLien = '';		
		//strLien = ZapTJ(objCurrDate.annee + tempStrMois + tempStrDate);	
		strLien = myCalendar(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();' >";
		}
		
		cont += i + "</a></div>";
		
		cont += "</td>";
		nbrD ++;
		if (nbrD >= 7) {
			nbrD = 0;
			cont += "</tr><tr>";
		}
	}
	for(nbrD=nbrD;nbrD<7;nbrD++) {
		cont += "<td></td>";
	}
	cont += "</tr></table><table align=center  border='0' cellpadding=1 cellspacing=0 background='img/trans.gif'><tr><td class=note><br/>" + calendarNote +"</td></tr></table></td>";

	if (objCurrDate.mois==date.getMonth()&&objCurrDate.annee==date.getFullYear()) cont += "<td valign='top'></td>";
	cont += "</tr></table> ";
	
	return cont;
}

/* Fonction qui genere les liens (par date de calendrier) vers la console Audio-Video */
function myCalendar(sDate) {
	var sAnnee = sDate.substr(0,4);
	var sMois = sDate.substr(4,2) - 1;
	var sJour = sDate.substr(6,2);
	var sChaine = "";
	var sHeure = "";
	/*if (nbrD == 0){
		sChaine = "RDI2";
		sHeure = "2100";
	} else {
		sChaine = "CBFT";
		sHeure = "2200";
	}*/
	var thisDate = new Date(sAnnee, sMois, sJour);
	var weekday = thisDate.getDay();
	if ((sDate > '20081219') && (weekday != 0)) {
		return "<a href='javascript:void(0);' onClick=\"window.open('/util/zapmedia/version10/detecte.asp?menu=1&lien=/medianet/" + sAnnee + "/CBFT/Telejournal" + sDate + "2200" + ".asx&promo=ZAPmedia_Telejournal','fenetreInter','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=1,height=1');\" class='CalTJLien'>";
	} else if ((sDate > '20081020') && (weekday == 0)) {
		return "<a href='javascript:void(0);' onClick=\"window.open('/util/zapmedia/version10/detecte.asp?menu=1&lien=/medianet/" + sAnnee + "/RDI2/TelejournalSurRDI21H" + sDate + "2100" + ".asx&promo=ZAPmedia_Telejournal','fenetreInter','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=1,height=1');\" class='CalTJLien'>";
	} else if ((sDate > '20071129') && (weekday == 0)) {
		return "<a href='javascript:void(0);' onClick=\"window.open('/util/zapmedia/version10/detecte.asp?menu=1&lien=/medianet/" + sAnnee + "/RDI2/TelejournalSurRDI" + sDate + "2100" + ".asx&promo=ZAPmedia_Telejournal','fenetreInter','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=1,height=1');\" class='CalTJLien'>";
	} else if ((sDate == '20070525') || (sDate == '20070601') || (sDate == '20070608') || (sDate == '20070615') || (sDate == '20070629') || (sDate == '20070824') || (sDate == '20070831') || (sDate == '20070909') || (sDate == '20070904') || (sDate == '20070916') || (sDate == '20070923') || (sDate == '20070930') || (sDate == '20071018') || (sDate == '20071207') || (sDate == '20071231') || (sDate == '20071025') || (sDate == '20071031')|| (sDate == '20080101')) {
		return "<a href='javascript:void(0);' onClick=\"window.open('/util/zapmedia/version10/detecte.asp?menu=1&lien=/medianet/" + sAnnee + "/RDI2/telejournal" + sDate + "2100" + ".asx&promo=ZAPmedia_Telejournal','fenetreInter','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=1,height=1');\" class='CalTJLien'>";
	} else if ((sDate > '20070929') && (weekday == 0)) {
		return "<a href='javascript:void(0);' onClick=\"window.open('/util/zapmedia/version10/detecte.asp?menu=1&lien=/medianet/" + sAnnee + "/RDI2/telejournal" + sDate + "2100" + ".asx&promo=ZAPmedia_Telejournal','fenetreInter','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=1,height=1');\" class='CalTJLien'>";
	} else  if (sDate == '20080701') {
		return "<a href='javascript:void(0);' onClick=\"window.open('/util/zapmedia/version10/detecte.asp?menu=1&lien=/medianet/" + sAnnee + "/CBFT/telejournal" + sDate + "2100" + ".asx&promo=ZAPmedia_Telejournal','fenetreInter','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=1,height=1');\" class='CalTJLien'>";
	} else  if (sDate == '20080711') {
		return "<a href='javascript:void(0);' onClick=\"window.open('/util/zapmedia/version10/detecte.asp?menu=1&lien=/medianet/" + sAnnee + "/CBFT/telejournal" + sDate + "2300" + ".asx&promo=ZAPmedia_Telejournal','fenetreInter','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=1,height=1');\" class='CalTJLien'>";
		} else  if (sDate > '20081023') {
		return "<a href='javascript:void(0);' onClick=\"window.open('/util/zapmedia/version10/detecte.asp?menu=1&lien=/medianet/" + sAnnee + "/RDI2/TelejournalSurRDI21H" + sDate + "2100" + ".asx&promo=ZAPmedia_Telejournal','fenetreInter','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=1,height=1');\" class='CalTJLien'>";
		} else  if ((sDate > '20080811') && (sDate < '20080824')) {
		return "<a href='javascript:void(0);' onClick=\"window.open('/util/zapmedia/version10/detecte.asp?menu=1&lien=/medianet/" + sAnnee + "/CBFT/telejournal" + sDate + "2100" + ".asx&promo=ZAPmedia_Telejournal','fenetreInter','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=1,height=1');\" class='CalTJLien'>";
	} else {
		return "<a href='javascript:void(0);' onClick=\"window.open('/util/zapmedia/version10/detecte.asp?menu=1&lien=/medianet/" + sAnnee + "/CBFT/telejournal" + sDate + "2200" + ".asx&promo=ZAPmedia_Telejournal','fenetreInter','toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=1,height=1');\" class='CalTJLien'>";
	}
}


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;
}

