//  SET ARRAYS
var day_of_week = [];
day_of_week[0] = new Array('L','M','M','J','V','S', 'D');
day_of_week[1] = new Array('Dl','Dm','Dm','Dj','Dv','Ds', 'Dg');
day_of_week[2] = new Array('M','T','W','T','F','S', 'S');
var month_of_year = [];
month_of_year[0] = new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
month_of_year[1] = new Array('Gener','Febrer','Mar&ccedil;','Abril','Maig','Juny','Juliol','Agost','Setembre','Octubre','Novembre','Desembre');
month_of_year[2] = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var tAnterior = [];
tAnterior[0] = "ANTERIOR";
tAnterior[1] = "ANTERIOR";
tAnterior[2] = "BACK";
var tSeguent= [];
tSeguent[0] = "SIGUIENTE";
tSeguent[1] = "SEG&Uuml;ENT";
tSeguent[2] = "FORWARD";
var tDe = []
tDe[0] = "de"
tDe[1] = "de"
tDe[2] = "of"

var fiestas = new Array("Fiestas", "Festes", "Holidays");
var municipales = new Array("Municipales", "Municipals", "Local");
var autonomicas = new Array("Auton&oacute;micas", "Auton&ograve;miques", "Regional");
var nacionales = new Array("Nacionales", "Nacionals", "National");
var domingos = new Array("Domingos", "Diumenges", "Sundays");
var fiestasMunicipales = new Array("Fiestas&nbsp;Municipales", "Festes&nbsp;Municipals", "Local holidays");
var fiestasAutonomicas = new Array("Fiestas&nbsp;Auton&oacute;micas", "Festes&nbsp;Auton&ograve;miques", "Regional holidays");
var fiestasNacionales = new Array("Fiestas&nbsp;Nacionales", "Festes&nbsp;Nacionals", "National holidays");


//  DECLARE AND INITIALIZE VARIABLES
var Calendar = new Date();

var year = Calendar.getYear();	    // Returns year
if (year < 2000) year = 1900 + year;// Per evitar l'efecte 2000 en Netscape i Opera
var month = Calendar.getMonth();    // Returns month (0-11)
var today = Calendar.getDate();    	// Returns day (1-31)
var weekday = Calendar.getDay();    // Returns day (0-6)

var DAYS_OF_WEEK = 7;   // "constant" for number of days in a week
var DAYS_OF_MONTH = 31; // "constant" for number of days in a month
var cal;    			// Used for printing

// VARIABLES GLOBALS QUE ES MODIFICARAN EN ALTRES FITXERS
var gEscriuCalendariContribuyente = 0;
var gEscriuCalendariFestes = 0;
var gEscriuCalendariFestesAmbDesplegables = 0;
var gEscriuCalendariHome = 0;
var gMunicipi = ""
var gComunitatAutonoma = ""
var gDesplegableMunicipis = ""

var mesActual;

Calendar.setDate(1);    	// Start the calendar day at '1'
Calendar.setMonth(month);   // Start the calendar month at now

var minMes = 0;		// DESDE 	gener de 2008
var minAny = 2008;
var maxMes = 11;	// A		desembre de 2008
var maxAny = 2008;	// ambdós inclosos
			
if (jsIdioma == "es") iIdioma = 0;
else if (jsIdioma == "ca") iIdioma = 1;
else if (jsIdioma == "en") iIdioma = 2;

var colors = [];
colors[0] = "#87B9AD";	// calendari contribuiyente
colors[1] = "#9B56B8";	// festes municipals 
colors[2] = "#FF7E00";	// festes autonòmiques 
colors[3] = "#568BB8";	// festes nacionals
colors[4] = "#BB0000";	// festes diumenges

//************************************************************************************************************************
// CREA L'OBJECTE "ANY"
//************************************************************************************************************************
function diaMarcat(dia, url){
	this.dia = dia;
	this.url = url;
	this.dadesCalendari = [];
	this.dadesCalendari[0] = [];
	this.dadesCalendari[1] = [];
	this.dadesCalendari[2] = [];
	this.numDadesCalendari = 0;
}
diaMarcat.prototype.introdueixDades = function(dadesES, dadesCA, dadesEN){
	this.dadesCalendari[0][this.numDadesCalendari] = dadesES;
	this.dadesCalendari[1][this.numDadesCalendari] = dadesCA;
	this.dadesCalendari[2][this.numDadesCalendari] = dadesEN;
	this.numDadesCalendari++;
}

function festaMunicipal(municipi, dia, quinaFesta, comunitatAutonoma){
	this.dia = dia;
	this.municipi = municipi;
	this.quinaFesta = quinaFesta;
	this.comunitatAutonoma = comunitatAutonoma;

}
function festaAutonomica(comunitatAutonoma, dia, quinaFestaES, quinaFestaCA, quinaFestaEN){
	this.dia = dia;
	this.comunitatAutonoma = comunitatAutonoma;
	this.quinaFesta = [];
	this.quinaFesta[0] = quinaFestaES;
	this.quinaFesta[1] = quinaFestaCA;
	this.quinaFesta[2] = quinaFestaEN;
}
function festaNacional(dia, quinaFestaES, quinaFestaCA, quinaFestaEN){
	this.dia = dia;
	this.quinaFesta = [];
	this.quinaFesta[0] = quinaFestaES;
	this.quinaFesta[1] = quinaFestaCA;
	this.quinaFesta[2] = quinaFestaEN;
}
function festaDiumenge(dia){
	this.dia = dia;
}

function creaMes(nMes){
	this.nMes 					= nMes;	// (0 - 11)
	this.numDiesMarcats 		= 0;
	this.diesMarcats 			= [];
	this.numFestesMunicipals	= 0
	this.festesMunicipals 		= [];
	this.numFestesAutonomiques	= 0
	this.festesAutonomiques		= [];
	this.numFestesNacionals		= 0
	this.festesNacionals 		= [];
	this.numFestesDiumenges		= 0
	this.festesDiumenges 		= [];
}
creaMes.prototype.marcaDia = function(dia, url){
	this.diesMarcats[this.numDiesMarcats] = new diaMarcat(dia, url);
	this.numDiesMarcats++;
}
creaMes.prototype.marcaFestaMunicipal = function(municipi, dia, quinaFesta, comunitatAutonoma){
	this.festesMunicipals[this.numFestesMunicipals] = new festaMunicipal(municipi, dia, quinaFesta, comunitatAutonoma);
	this.numFestesMunicipals++;
}
creaMes.prototype.marcaFestaAutonomica = function(comunitatAutonoma, dia, quinaFestaES, quinaFestaCA, quinaFestaEN){
	this.festesAutonomiques[this.numFestesAutonomiques] = new festaAutonomica(comunitatAutonoma, dia, quinaFestaES, quinaFestaCA, quinaFestaEN);
	this.numFestesAutonomiques++;
}
creaMes.prototype.marcaFestaNacional = function(dia, quinaFestaES, quinaFestaCA, quinaFestaEN){
	this.festesNacionals[this.numFestesNacionals] = new festaNacional(dia, quinaFestaES, quinaFestaCA, quinaFestaEN);
	this.numFestesNacionals++;
}
creaMes.prototype.marcaFestaDiumenge = function(dia){
	this.festesDiumenges[this.numFestesDiumenges] = new festaDiumenge(dia);
	this.numFestesDiumenges++;
}



function creaAny(any){
	this.any = any;
	this.gener 		= new creaMes(0);
	this.febrer 	= new creaMes(1);
	this.marc 		= new creaMes(2);
	this.abril 		= new creaMes(3);
	this.maig 		= new creaMes(4);
	this.juny 		= new creaMes(5);
	this.juliol 	= new creaMes(6);
	this.agost 		= new creaMes(7);
	this.setembre 	= new creaMes(8);
	this.octubre 	= new creaMes(9);
	this.novembre 	= new creaMes(10);
	this.desembre 	= new creaMes(11);
}
//************************************************************************************************************************


//************************************************************************************************************************
// INICIALITZA L'OBJECTE "ANY" ELS DIES MARCATS
//************************************************************************************************************************
var any = new creaAny(year);



//************************************************************************************************************************



//************************************************************************************************************************
/* VARIABLES FOR FORMATTING
NOTE: You can format the 'BORDER', 'BGCOLOR', 'CELLPADDING', 'BORDERCOLOR'
      tags to customize your caledanr's look. */

var TR_start = '<TR>';
var TR_end = '</TR>';
var highlight_start = '<TD style="width:14px; border:1px solid #999999; background:' + colors[0] +  ';"><B><CENTER>';
var highlight_end   = '</CENTER></B>';
var highlight2_start = '<TD style="width:14px; border:1px solid #999999; background:' + colors[1] + ';"><B><CENTER>';
var highlight3_start = '<TD style="width:14px; border:1px solid #999999; background:' + colors[2] + ';"><B><CENTER>';
var highlight4_start = '<TD style="width:14px; border:1px solid #999999; background:' + colors[3] + ';"><B><CENTER>';
var highlight5_start = '<TD style="width:14px; border:1px solid #999999; background:' + colors[4] + ';"><B><CENTER>';
var TD_start = '<TD style="width:14px; border:1px solid #999999"><CENTER>';
var TD_end = '</CENTER></TD>';
var TD_start_noBorder = '<TD style="border: none; width:10px;" ><CENTER>';
var TD_end_noBorder = '</CENTER></TD>';

/* BEGIN CODE FOR CALENDAR*/



function escriuCalendari(mes)
{

	Calendar.setDate(1);
	Calendar.setMonth(mes.nMes); //mes (0 - 11)
	month = mes.nMes;
	Calendar.setYear(year);
	
	//NOTE: You can format the 'BORDER', 'BGCOLOR', 'CELLPADDING', 'BORDERCOLOR'
	//tags to customize your calendar's look.
	
	cal =  '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BORDERCOLOR=BBBBBB><TR><TD>';
	cal += '<TABLE width="140px" BORDER=1 CELLSPACING=1 CELLPADDING=0 class=grisFosc>' + TR_start;
	cal += '<TD COLSPAN="' + DAYS_OF_WEEK + '" bordercolor="#999999" BGCOLOR="#EFEFEF" background="./img/calendari/degradat-titol.gif"><CENTER><B><font size= "2">';
	cal += month_of_year[iIdioma][month]  + '   ' + year + '</font></B>' + TD_end + TR_end;
	cal += TR_start;

	cal += TR_start + TD_start_noBorder + '&nbsp; ' + TD_end + TR_end ;

	//   DO NOT EDIT BELOW THIS POINT  // i did it and didn't happened anything at all
	
	// LOOPS FOR EACH DAY OF WEEK	(els dies de la setmana)
	for(index=0; index < DAYS_OF_WEEK; index++)
	{
		cal += TD_start_noBorder + day_of_week[iIdioma][index] + TD_end;
	}
	
	cal += TD_end + TR_end;
	
	cal += TR_start;
	
	// FILL IN BLANK GAPS UNTIL TODAY'S DAY
	var tday = Calendar.getDay();
	if (tday == 0) tday = 7;
	tday--;

	for(index=0; index < tday; index++)
		cal += TD_start_noBorder + '  ' + TD_end_noBorder;
	
	// LOOPS FOR EACH DAY IN CALENDAR
	for(index=0; index < DAYS_OF_MONTH; index++)
	{
		if( Calendar.getDate() > index )
		{
			// RETURNS THE NEXT DAY TO PRINT
			week_day =Calendar.getDay();
			
			// START NEW ROW FOR FIRST DAY OF WEEK (0 == Diumenge, 1 == Dilluns)
			if(week_day == 1)
				cal += TR_start;
			
			if(week_day != DAYS_OF_WEEK)
			{
				// SET VARIABLE INSIDE LOOP FOR INCREMENTING PURPOSES
				var day  = Calendar.getDate();
				
				// HIGHLIGHT dies marcats
				var highlight = 0;
				if (year == any.any){
					for (i=0; i<mes.diesMarcats.length; i++){
						if( mes.diesMarcats[i].dia == Calendar.getDate() ){
//							cal += highlight_start + "<a href=\"" + mes.diesMarcats[i].url + "\" class=blancPetit>" + day + "</a>" + highlight_end + TD_end;
							cal += highlight_start + "<span class=blancPetit>" + day + "</span>" + highlight_end + TD_end;
							highlight = 1;
							break;
						}
						else{
							highlight = 0;
						}
					}
					if (highlight == 0 && gEscriuCalendariFestes == 1){
						for (i=0; i<mes.festesMunicipals.length; i++){
							if (mes.festesMunicipals[i].dia == Calendar.getDate() && highlight == 0 ){
								fet = 1;
								cal += highlight2_start + "<span class=blancPetit>" + day + "</span>" + highlight_end + TD_end;
								highlight = 1;
							}
						}
						if (highlight == 0){
							for (i=0; i<mes.festesAutonomiques.length; i++){
								if (mes.festesAutonomiques[i].dia == Calendar.getDate() && highlight == 0 ){
									cal += highlight3_start + "<span class=blancPetit>" + day + "</span>" + highlight_end + TD_end;
									highlight = 1;
								}
							}
							if (highlight == 0){
								for (i=0; i<mes.festesNacionals.length; i++){
									if (mes.festesNacionals[i].dia == Calendar.getDate()){
										cal += highlight4_start + "<span class=blancPetit>" + day + "</span>" + highlight_end + TD_end;
										highlight = 1;
									}
								}
								if (highlight == 0){
									for (i=0; i<mes.festesDiumenges.length; i++){
										if (mes.festesDiumenges[i].dia == Calendar.getDate()){
											cal += highlight5_start + "<span class=blancPetit>" + day + "</span>" + highlight_end + TD_end;
											highlight = 1;
										}
									}
								}
							}
						}
					}
				}
				if( highlight == 0 )
					cal += TD_start + day + TD_end;
			}
			
			// END ROW FOR LAST DAY Of WEEK
			if(week_day == DAYS_OF_WEEK)
			cal += TR_end;
		}
		
		// INCREMENTS UNTIL END OF THE MONTH
		Calendar.setDate(Calendar.getDate()+1);
	
	}// end for loop
	
	
	cal += '</TD></TR><tr ><td style="border: none;" colspan=7>&nbsp;</td></tr>';
	
	cal += TR_start + '<TD COLSPAN="' + DAYS_OF_WEEK + '" bordercolor="#999999" BGCOLOR="#EFEFEF" background="./img/calendari/degradat-titol.gif"><CENTER>';

	// Botons "siguiente" y "anterior"	
	cal += '<table width="100%" ><tr><td><div align="left">';
	cal += '<a href="javascript:anterior();" class=negrePetit><b>  ' + tAnterior[iIdioma] + '</b></a></div></td><td><div align="right">';
	cal += '<a href="javascript:siguiente();" class=negrePetit><b>' + tSeguent[iIdioma] + ' </b></a></div></td></tr></table>';
	
	
	cal += TD_end + TR_end + '</TABLE></TABLE>';
	
	if (gEscriuCalendariFestes == 1)
	{
		cal += '<div style="position:relative; width:200px;" align="left">';
		cal += '<br><table  class="gris3"><tr><td colstan="2">';
		cal += fiestas[iIdioma] + ':';
		cal += '</td></tr>';
		cal += '<tr><td>';
		cal += '<span style="width:14px; height:14px; background-color: ' + colors[1] + '; overflow:hidden; layer-background-color: ' + colors[1] + '; border: 1px none #87B9AD;" class=grisPetit>&nbsp;&nbsp;&nbsp;&nbsp;</span> ' + municipales[iIdioma] + ' &nbsp; ';
		cal += '</td><td>';
		cal += '<span style="width:14px; height:14px; background-color: ' + colors[2] + '; overflow:hidden; layer-background-color: ' + colors[2] + '; border: 1px none #87B9AD;" class=grisPetit>&nbsp;&nbsp;&nbsp;&nbsp;</span> ' + autonomicas[iIdioma] + '<br>';
		cal += '</td><tr><td>';
		cal += '<span style="width:14px; height:14px; background-color: ' + colors[3] + '; overflow:hidden; layer-background-color: ' + colors[3] + '; border: 1px none #87B9AD;" class=grisPetit>&nbsp;&nbsp;&nbsp;&nbsp;</span> ' + nacionales[iIdioma] + ' &nbsp; ';
		cal += '</td><td>';
		cal += '<span style="width:14px; height:14px; background-color: ' + colors[4] + '; overflow:hidden; layer-background-color: ' + colors[4] + '; border: 1px none #87B9AD;" class=grisPetit>&nbsp;&nbsp;&nbsp;&nbsp;</span> ' + domingos[iIdioma] + '';
		cal += '</td></tr></table>';
		cal += '</div>';
	}

	//  PRINT CALENDAR
	if (gEscriuCalendariFestes != 1 || gEscriuCalendariFestesAmbDesplegables != 1){
		MM_setTextOfLayer('calendariDiv','', cal);
	}

	if (gEscriuCalendariContribuyente == 1 || gEscriuCalendariFestes == 1){
		escriuContingut(month);
	}
	if (gEscriuCalendariFestes == 1 && gEscriuCalendariFestesAmbDesplegables == 0){
		MM_setTextOfLayer('mesDiv','', month_of_year[iIdioma][month]);
	}
	
}


function creaCalendariHome()
{
	gEscriuCalendariHome = 1;
	var mes;
	if 	(month == 0) mes = any.gener;
	else if (month == 1) mes = any.febrer;
	else if (month == 2) mes = any.marc;
	else if (month == 3) mes = any.abril;
	else if (month == 4) mes = any.maig;
	else if (month == 5) mes = any.juny;
	else if (month == 6) mes = any.juliol;
	else if (month == 7) mes = any.agost;
	else if (month == 8) mes = any.setembre;
	else if (month == 9) mes = any.octubre;
	else if (month == 10) mes = any.novembre;
	else if (month == 11) mes = any.desembre;
	
	var dies = mes.diesMarcats.length;	
	// Crea la taula on hi anirà el calendari i alguns continguts
	txt = "";
	txt += '<table class="gris" width="500px">																									 ';
	txt += '	<tr>                                                                                                                 ';
	txt += '		<td rowspan="3" width="150px">                                                                                                 ';
	txt += '			<span style="position:absolute; height:1; width:1; z-index:9;"><a href="5-calendarioFiscalMercantil.asp"><img src="img/transparent.gif" width="140" height="160" border="0" alt="calendario"></a></span>                                                                                                ';
	txt += '			<span id="calendariDiv" style="position:relative; left:0; width:100;" align="left"> </span>       ';
	txt += '		</td>                                                                                                            ';
	txt += '		<td>                                                                                                             ';
	
	if (dies >= 1){
		var strTmp = numerosAngles(mes.diesMarcats[0].dia);
		txt += '<span class="verdNegreta">' + mes.diesMarcats[0].dia + strTmp + ' ' + tDe[iIdioma] + ' ' + month_of_year[iIdioma][mes.nMes] + '</span>';
		txt += '<br>';
		ttt = mes.diesMarcats[0].dadesCalendari[iIdioma].length;
		if (ttt > 2) ttt = 2;
		for (i=0; i<ttt; i++){
			if (i > 0) txt += ', ';
			txt += mes.diesMarcats[0].dadesCalendari[iIdioma][i];
		}
		if (mes.diesMarcats[0].dadesCalendari[iIdioma].length > 2)
			txt += '<span class="verdNegreta"> [...]</span>';
		txt += '<br><br>';
	}
	else{
		txt += '&nbsp;';
	}
	
	txt += '		</td>                                                                                                            ';
	txt += '	</tr>                                                                                                                ';
	txt += '	<tr>                                                                                                                 ';
	txt += '		<td>                                                                                                             ';

	if (dies >= 2){
		var strTmp = numerosAngles(mes.diesMarcats[1].dia);
		txt += '<span class="verdNegreta">' + mes.diesMarcats[1].dia + strTmp + ' ' + tDe[iIdioma] + ' ' + month_of_year[iIdioma][mes.nMes] + '</span>';
		txt += '<br>';
		ttt = mes.diesMarcats[1].dadesCalendari[iIdioma].length;
		if (ttt > 2) ttt = 2;
		for (i=0; i<ttt; i++){
			if (i > 0) txt += ', ';
			txt += mes.diesMarcats[1].dadesCalendari[iIdioma][i];
		}
		if (mes.diesMarcats[1].dadesCalendari[iIdioma].length > 2)
			txt += '<span class="verdNegreta"> [...]</span>';
		txt += '<br><br>';
	}
	else{
		txt += '&nbsp;';
	}

	txt += '		</td>                                                                                                            ';
	txt += '	</tr>                                                                                                                ';
	txt += '	<tr>                                                                                                                 ';
	txt += '		<td>                                                                                                             ';

	if (dies >= 3){
		var strTmp = numerosAngles(mes.diesMarcats[2].dia);
		txt += '<span class="verdNegreta">' + mes.diesMarcats[2].dia + strTmp + ' ' + tDe[iIdioma] + ' ' + month_of_year[iIdioma][mes.nMes] + '</span>';
		txt += '<br>';
		ttt = mes.diesMarcats[2].dadesCalendari[iIdioma].length;
		if (ttt > 2) ttt = 2;
		for (i=0; i<ttt; i++){
			if (i > 0) txt += ', ';
			txt += mes.diesMarcats[2].dadesCalendari[iIdioma][i];
		}
		if (mes.diesMarcats[2].dadesCalendari[iIdioma].length > 2)
			txt += '<span class="verdNegreta"> [...]</span>';
		txt += '<br><br>';
	}
	else{
		txt += '&nbsp;';
	}

	txt += '		</td>    		                                                                                                 ';
	txt += '	</tr>        		                                                                                                 ';
	txt += '</table>	     		                                                                                                 ';
	
	
	//txt = '<span id="calendariDiv" style="position:relative; left:0; width:100;" align="left"> </span>';
	MM_setTextOfLayer('calendariHome','', txt);
	
	// Escriu el calendari
	escriuCalendari(mes);

}
function numerosAngles(num){
	if (jsIdioma != "en") return "";
	var strTmp = "";
	if (num == 1 || num == 11 || num == 21 || num == 31){
		strTmp = "st";
	}
	else if (num == 2 || num == 12 || num == 22){
		strTmp = "nd";
	}
	else if (num == 3 || num == 13 || num == 23){
		strTmp = "rd";
	}
	else{
		strTmp = "th";
	}
	return strTmp;
}




function retornaMes(m){
	switch (m){	// 0 - 11
		case 0:		mes = any.gener;		break;
		case 1:		mes = any.febrer;		break;
		case 2:		mes = any.marc;			break;
		case 3:		mes = any.abril;		break;
		case 4:		mes = any.maig;			break;
		case 5:		mes = any.juny;			break;
		case 6:		mes = any.juliol;		break;
		case 7:		mes = any.agost;		break;
		case 8:		mes = any.setembre;		break;
		case 9:		mes = any.octubre;		break;
		case 10:	mes = any.novembre;		break;
		case 11:	mes = any.desembre;		break;
	}
	return mes;
}


function escriuContingut(m)
{
	var mes = retornaMes(m);
	txt = "";

	txt += '<table class="unAltreGris" CELLSPACING=2 CELLPADDING=1>';
	
	if (gEscriuCalendariContribuyente == 1){ // Calendari contribuyente
		for (i=0; i<mes.diesMarcats.length; i++){
			txt += '	<tr>';
			if (is_ie){
				txt += '		<td width="4%" class=grisFosc align=center valign=top> <div style="width:16px; height:16px; background-color: ' + colors[0] + '; overflow:hidden; layer-background-color: ' + colors[0] + '; border: 1px none #87B9AD;" class=blancPetit> ';
			}
			else{
				txt += '		<td width="4%" class=grisFosc align=center valign=bottom> <div style="width:16px; height:16px; background-color: ' + colors[0] + '; overflow:hidden; layer-background-color: ' + colors[0] + '; border: 1px none #87B9AD;" class=blancPetit> ';
			}
			txt += mes.diesMarcats[i].dia;
			txt += '		</div></td>';
			txt += '		<td><p><ul><li>';
			txt += mes.diesMarcats[i].dadesCalendari[iIdioma][0];
			txt += '</ul></td>';
			txt += '	</tr>';
			for (j=1; j<mes.diesMarcats[i].dadesCalendari[iIdioma].length; j++){
				txt += '	<tr>';
				txt += '		<td></td>';
				txt += '		<td><p><ul><li>';
				txt += mes.diesMarcats[i].dadesCalendari[iIdioma][j];
				txt += '</ul></p></td>                                          ';
				txt += '	</tr>                                                                                                                           ';
			}
		}
	}
	else if (gEscriuCalendariFestes == 1){	// Calendari Festes
		bTitol = 0;
		var tDies = [];
		var tFet = [];
		var contador = 0;
		var tAmplada = 16;
		if (gEscriuCalendariFestesAmbDesplegables == 1) {
			tAmplada = 90;
		}
		for (j=0; j<12; j++)
		{
			if (gEscriuCalendariFestesAmbDesplegables == 1) {mes = retornaMes(j);}

			for (i=0; i<mes.festesMunicipals.length; i++){
				tDies = 0;
				tDies = [];
				tDies[i]  = mes.festesMunicipals[i].dia;
				tFet[i] = 0;
			}
			contador = 0;
			while(contador < tDies.length){
				for (i=0; i<tDies.length; i++){
						contador++;
					if (tFet[i] == 0 && mes.festesMunicipals[i])
					{
						if (gEscriuCalendariFestesAmbDesplegables == 1 && 
								(mes.festesMunicipals[i].comunitatAutonoma != gComunitatAutonoma || 
								mes.festesMunicipals[i].municipi != gDesplegableMunicipis)) 
						{
							continue;
						}
								
						tFet[i] = 1;
						if (bTitol == 0){ txt += '	<tr><td colspan="2">' + fiestasMunicipales[iIdioma] + '</td></tr>'; bTitol = 1;}
						txt += '	<tr>';
						if (is_ie){
							txt += '		<td width="4%" class=grisFosc align=center valign=top> <div style="width:'+tAmplada+'px; height:16px; background-color: ' + colors[1] + '; overflow:hidden; layer-background-color: ' + colors[1] + '; border: 1px none #87B9AD;" class=blancPetit> ';
						}
						else{
							txt += '		<td width="4%" class=grisFosc align=center valign=bottom> <div style="width:'+tAmplada+'px; height:16px; background-color: ' + colors[1] + '; overflow:hidden; layer-background-color: ' + colors[1] + '; border: 1px none #87B9AD;" class=blancPetit> ';
						}
						
						txt += mes.festesMunicipals[i].dia;
						if (gEscriuCalendariFestesAmbDesplegables == 1){
							txt += '&nbsp;-&nbsp;';
							txt += month_of_year[iIdioma][mes.nMes];
						}				
						txt += '		</div></td>';
						txt += '		<td><p><ul><li>';
						txt += mes.festesMunicipals[i].quinaFesta;
						txt += '</ul></td>';
						txt += '	</tr>';
					}
				}
			}
			if (gEscriuCalendariFestesAmbDesplegables == 0) {break;}
		}
		
		bTitol = 0;
		for (j=0; j<12; j++){
			if (gEscriuCalendariFestesAmbDesplegables == 1) {
				mes = retornaMes(j);
			}
			for (i=0; i<mes.festesAutonomiques.length; i++){
				if (gEscriuCalendariFestesAmbDesplegables == 1 && mes.festesAutonomiques[i].comunitatAutonoma != gComunitatAutonoma) {continue;}
				if (bTitol == 0){ txt += '	<tr><td colspan="2">' + fiestasAutonomicas[iIdioma] + '</td></tr>'; bTitol = 1;}
				txt += '	<tr>';
				if (is_ie){
					txt += '		<td width="4%" class=grisFosc align=center valign=top> <div style="width:'+tAmplada+'px; height:16px; background-color: ' + colors[2] + '; overflow:hidden; layer-background-color: ' + colors[2] + '; border: 1px none #87B9AD;" class=blancPetit >&nbsp;';
				}
				else{
					txt += '		<td width="4%" class=grisFosc align=center valign=bottom> <div style="width:'+tAmplada+'px; height:16px; background-color: ' + colors[2] + '; overflow:hidden; layer-background-color: ' + colors[2] + '; border: 1px none #87B9AD;" class=blancPetit >&nbsp;';
				}
				
				
					
				txt += mes.festesAutonomiques[i].dia;
				if (gEscriuCalendariFestesAmbDesplegables == 1){
					txt += '&nbsp;-&nbsp;';
					txt += month_of_year[iIdioma][mes.nMes];
				}				
				txt += '		</div></td>';
				txt += '		<td><p><ul><li>';
				txt += mes.festesAutonomiques[i].quinaFesta[iIdioma];
				txt += '</ul></td>';
				txt += '	</tr>';
			}
			if (gEscriuCalendariFestesAmbDesplegables == 0) {break;}
		}
		bTitol = 0;
		for (j=0; j<12; j++){
			if (gEscriuCalendariFestesAmbDesplegables == 1) {mes = retornaMes(j);}
			for (i=0; i<mes.festesNacionals.length; i++){
				if ( bTitol == 0) {txt += '	<tr><td colspan="2">' + fiestasNacionales[iIdioma] + '</td></tr>';bTitol=1;}
				txt += '	<tr>';
				if (is_ie){
					txt += '		<td width="4%" class=grisFosc align=center valign=top> <div style="width:'+tAmplada+'px; height:16px; background-color: ' + colors[3] + '; overflow:hidden; layer-background-color: ' + colors[3] + '; border: 1px none #87B9AD;" class=blancPetit> ';
				}
				else{
					txt += '		<td width="4%" class=grisFosc align=center valign=bottom> <div style="width:'+tAmplada+'px; height:16px; background-color: ' + colors[3] + '; overflow:hidden; layer-background-color: ' + colors[3] + '; border: 1px none #87B9AD;" class=blancPetit> ';
				}
				txt += mes.festesNacionals[i].dia;
				if (gEscriuCalendariFestesAmbDesplegables == 1){
					txt += '&nbsp;-&nbsp;';
					txt += month_of_year[iIdioma][mes.nMes];
				}				
				txt += '		</div></td>';
				txt += '		<td><p><ul><li>';
				txt += mes.festesNacionals[i].quinaFesta[iIdioma];
				txt += '</ul></td>';
				txt += '	</tr>';
			}
			if (gEscriuCalendariFestesAmbDesplegables == 0) {break;}
		}

	}
	txt += '	</table><br><br>';
 
   if (gEscriuCalendariFestesAmbDesplegables == 1)	escriuDesplegableMunicipis();

   MM_setTextOfLayer('textPrincipal','', txt);
   
}


var gComAutActual = "";
function escriuDesplegableMunicipis()
{
	var str = "";
	var str2 = "";
	if (gComAutActual != gComunitatAutonoma)
	{
		var municipisIntroduits = [];
		for (i=0; i<12; i++)
		{
			mes = retornaMes(i);
			for (j=0; j<mes.festesMunicipals.length; j++)
			{
				festaMun = mes.festesMunicipals[j];
		
				if (festaMun.comunitatAutonoma == gComunitatAutonoma && municipisIntroduits[festaMun.municipi] != 1)
				{
					municipisIntroduits[festaMun.municipi] = 1;
					
					str += '<option value="' + festaMun.municipi + '">' + festaMun.quinaFesta + '</option>';
				}
			}
		}
		
		if (str != "")
		{
			municipis = new Array("Municipios","Municipis","Towns ");
			str2 = municipis[iIdioma];
			str2 += ':<br>';
			str2 += '<select id="desplegableMunicipis" style="width:150px;" onChange="gDesplegableMunicipis=this.value; escriuContingut(0); return true;" class="unAltreGris"> ';
			str2 += '	<option value=""></option>';
			str2 += str;
			str2 += '</select>';
			MM_setTextOfLayer('desplegableMunicipisDiv','', str2);
			gComAutActual = gComunitatAutonoma;
		}
		else{
			gComAutActual = "";
			MM_setTextOfLayer('desplegableMunicipisDiv','', '');
		}
	}
}

function siguiente()
{
	// Salta al seguent mes
	tmonth = month + 1;
	tyear = year;
	if (tmonth == 12){
		tmonth = 0;
		tyear++;
	}

	// Controlem que no ens sortim dels limits establerts
	ok = 0;
	if (maxAny > tyear) ok = 1;
	else if (maxAny == tyear && maxMes >= tmonth) ok = 1;

	if (ok == 1){	
		month = tmonth;
		year = tyear;
		Calendar.setYear(year);
		Calendar.setDate(1);    	 // Start the calendar day at '1'
		Calendar.setMonth(month);   // Start the calendar month at now
		
		if (gEscriuCalendariHome == 1){	//HOME
			creaCalendariHome();
		}
		else{
			seleccionaMes();
		}
	}
}

function anterior()
{
	// Salta al seguent mes
	tmonth = month - 1;
	tyear = year
	if (tmonth == -1) {
		tmonth = 11;
		tyear--;
	}

	// Controlem que no ens sortim dels limits establerts
	ok = 0;
	if (minAny < tyear) ok = 1;
	else if (minAny == tyear && minMes <= tmonth) ok = 1;

	if (ok == 1){
		month = tmonth;
		year = tyear;
		Calendar.setYear(year);
		Calendar.setDate(1);    	 // Start the calendar day at '1'
		Calendar.setMonth(month);   // Start the calendar month at now
		if (gEscriuCalendariHome == 1){	//HOME
			creaCalendariHome();
		}
		else{
			seleccionaMes();
		}
	}
}


function seleccionaMes()
{
	if 		(month == 0) mesActual = any.gener;
	else if (month == 1) mesActual= any.febrer;
	else if (month == 2) mesActual= any.marc;
	else if (month == 3) mesActual= any.abril;
	else if (month == 4) mesActual= any.maig;
	else if (month == 5) mesActual= any.juny;
	else if (month == 6) mesActual= any.juliol;
	else if (month == 7) mesActual= any.agost;
	else if (month == 8) mesActual= any.setembre;
	else if (month == 9) mesActual= any.octubre;
	else if (month == 10) mesActual= any.novembre;
	else if (month == 11) mesActual= any.desembre;
	
	escriuCalendari(mesActual);
}


