// JavaScript Document for Inici Part

// Assigna les funcions als botons del calendari 
function setCalendarEvents(iMes, iAny) {

	oPrev = document.getElementById("prevm");
	oNext = document.getElementById("nextm");
	
	oPrev.onclick = function() {
		getMonth(iMes-1, iAny);
	};
	
	oNext.onclick = function() {
		getMonth(iMes+1, iAny);
	};

}


// Recupera per AJAX el mes indicat 
function getMonth(iMes, iAny) {
	
	if (iMes > 12) {
			iMes = 1;
			iAny++;
	} else if (iMes < 1) {
		iMes = 12;
		iAny--;
	}	
	
	sUrl = "ajax/acalendari.php?mes=" + iMes + "&any=" + iAny;
	oCalendari = document.getElementById("caltaula");
	
	// Canviem a la classe d'espera
	oCalendari.className = "esperant";

	// Executem el canvi de mes al calendari 
	$("#caltaula").load(sUrl, {}, function(responseText, textStatus, XMLHttpRequest){
		setCalendarEvents(iMes, iAny);		
	});

}