mesi = Array(	"Gennaio",
				"Febbraio",
				"Marzo",
				"Aprile",
				"Maggio",
				"Giugno",
				"Luglio",
				"Agosto",
				"Settembre",
				"Ottobre",
				"Novembre",
				"Dicembre");

function checkAvail() {
	var ret = false;
	for (i = 0; i < PeriodiDisponibili.length; i++)
		if ((PeriodiDisponibili[i][0] == AnnoCorrente) && (PeriodiDisponibili[i][1] == MeseCorrente)) {
			ret = true;
			break;
		}
	document.getElementById('mostrarisultati').className = (ret) ? 'submiton' : 'submitoff';
	document.getElementById('msgDisp').innerHTML = (ret) ? '' : 'Dati non disponibili per il periodo selezionato.';
	document.getElementById('mostrarisultati').disabled = !ret;
}

function evntKeyDwn(e) {
	if (!e.which) return
	if (e.which == 38 || e.which == 40) {
		AnnoCorrente = document.getElementById('yyyy').options[document.getElementById('yyyy').selectedIndex].value
		MeseCorrente = document.getElementById('mm').options[document.getElementById('mm').selectedIndex].value
		checkAvail();
	}
}


function fill_SelAnno() {
	var oSel = document.getElementById('yyyy');
	var oSelLen = oSel.length;
	var y;
	for (i = 0; i < Anni.length - 1; i++) {
		var oOptNew = document.createElement('option');
		oOptNew.text = Anni[i];
		oOptNew.value = Anni[i];
		try			{ oSel.add(oOptNew, null); }
		catch(ex)	{ oSel.add(oOptNew); }
		if (Anni[i] == AnnoCorrente) y = i;
	}
	if (y) oSel.options[y].selected = true;
}

function fill_SelMese() {
	var oSel = document.getElementById('mm');
	var oSelLen = oSel.length;
	var txt, w, z = 0;
	var lastMonth = parseInt(PeriodiDisponibili[0][1], 10);

	for (i = (lastMonth - 1); i > (lastMonth - 4); i--) {
		var d = new Date(2000, i, 1);
		var oOptNew = document.createElement('option');
		oOptNew.text = mesi[d.getMonth()];

		var txt = '0' + (d.getMonth() + 1).toString();
		if (txt.length > 2) txt = txt.substr(txt.length -2)
		oOptNew.value = txt;

		try			{ oSel.add(oOptNew, null); }
		catch(ex)	{ oSel.add(oOptNew); }

		if (i == (parseInt(MeseCorrente, 10) - 1)) w = z;
		z++;
	}
	if (w) oSel.options[w].selected = true;
}

function createDivBestUnit() {
	var newDiv = document.createElement("DIV");
	with (newDiv) {
		id						= "BestUnit";
		name					= "BestUnit";
		className				= "sm stdfont";
		with (style) {
			borderStyle			= "solid";
			borderWidth			= "1";
			borderColor			= "#666666";
			backgroundImage		= "url(img/pr_bg.gif)";
			position			= "absolute";
			top					= "-50";
		}
	}
	document.body.appendChild(newDiv);
}

function usr_Replace(pStr) {
	var re = new RegExp("  ", "ig");
	while (pStr.indexOf('  ') > -1)
		pStr = pStr.replace(re, " ");
	return pStr;
}

function UnShow() {
	var code = "gIsBestUnitVisible = false; document.getElementById('BestUnit').style.top = '-50';";
	window.setTimeout(code, 200);
}

function Show(e, id_aryBestUnita) {
	var gBestUnit = document.getElementById("BestUnit");
	gBestUnit.innerHTML = aryBestUnita[id_aryBestUnita];
	gBestUnit.style.top = e.clientY + (document.body.scrollTop - ((document.all) ? 35 : 33));
	gBestUnit.style.left = (e.clientX + 50) - (gBestUnit.offsetWidth);
	gBestUnit.style.display = 'inline';
	gIsBestUnitVisible = true;
}
