function impostaGiorni(mese, anno)
{
// Parto dal primo giorno del mese
	DData = new Date(anno, mese, 1);
	iGiorno = DData.getDay() - 1;
	if (iGiorno == -1) iGiorno = 6;
	
// Determino l'ultimo giorno del mese
	iUltimoGiorno = 27;
	do 
		DData = new Date(anno, mese, ++iUltimoGiorno + 1);
	while (DData.getMonth() == mese)
	
	iGiorno = -iGiorno + 1;
	for (y = 0; y < 6; y++)
		for (x = 0; x < 7; x++)
		{
			ODiv = document.getElementById("idDataSel"+y+x);
			if (iGiorno > 0 && iGiorno <= iUltimoGiorno) 
				ODiv.childNodes[0].nodeValue = iGiorno;
			else
				ODiv.childNodes[0].nodeValue = "";
			
			iGiorno++;
		}
}	

function resetData()
{
	OData = new Date();

	OI_sMese = document.getElementById("I_sMese");
	if (!OI_sMese) return;
	OI_sMese.selectedIndex = OData.getMonth();
	OI_sAnno = document.getElementById("I_sAnno");
	nAnnoCur = OData.getYear();
	if (nAnnoCur < 1900)
		nAnnoCur = nAnnoCur + 1900;
		
	for (iAnno = 0; iAnno < OI_sAnno.options.length; iAnno++)
	{
		if (parseInt(OI_sAnno.options[iAnno].value, 10) == nAnnoCur)
			OI_sAnno.selectedIndex = iAnno;
	}
		
	impostaGiorni(OData.getMonth(), nAnnoCur);
}

if (window.addEventListener)
	window.addEventListener("load", resetData, false);
else if (window.attachEvent) 
	window.attachEvent("onload", resetData);


function inviaData(sidDiv)
{
	ODiv = document.getElementById(sidDiv);
	if (ODiv && ODiv.childNodes[0] && ODiv.childNodes[0].nodeValue != "")
	{
		sValue = ODiv.childNodes[0].nodeValue;
		document.getElementById('I_sGiorno').value = sValue;
		document.getElementById('formCalendario').submit();
	}
}