
var timerID = null;
var timerRunning = false;

// CAMBIA L'IMMAGINE DI UN LINK
function flipImage(theButton, theAction) 
{
	var NewImage;
	var N;
	NewImage = theButton.src;
	N = NewImage.lastIndexOf("_");
	NewImage = NewImage.substring(0,N);
	if (theAction == 0) theButton.src = NewImage + "_off.gif";
	if (theAction == 1) theButton.src = NewImage + "_on.gif";
	return true;
}

// EVIDENZIA LA CELLA SELEZIONATA
function setCell(theCell, newCellColor, newFontColor)
{
	//var newColor = SEL_COLOR;
	//theCell.setAttribute('bgcolor', newColor, 0);
	theCell.style.backgroundColor = newCellColor;
	theCell.style.color = newFontColor;
	theCell.style.cursor = "hand";
    return true;
} 

// RESTITUISCE IL NOME DI UN GIORNO
function nomegiorno(g)
{
	var t;
	switch (g) {
		case 1: t = "Lunedì";  break;
		case 2:	t = "Martedì"; break;
		case 3: t = "Mercoledì"; break;
		case 4: t = "Giovedì"; break;
		case 5: t = "Venerdì"; break;
		case 6: t = "Sabato"; break;
		case 7: t = "Domenica";	break;
	}	
	return  t;
}

// RESTITUISCE IL NOME DI UN MESE
function nomemese(m)
{
	var t;
	switch (m) {
		case 0:	t = "Gennaio"; break;
		case 1:	t = "Febbraio"; break;
		case 2: t = "Marzo"; break;
		case 3: t = "Aprile"; break;
		case 4: t = "Maggio"; break;
		case 5: t = "Giugno"; break;
		case 6: t = "Luglio"; break;
		case 7: t = "Agosto"; break;
		case 8:	t = "Settembre"; break;
		case 9: t = "Ottobre"; break;
		case 10:t = "Novembre";	break;
		case 11:t = "Dicembre";	break;
	}	
	return  t;
}

// Avvia il timer per l'aggiornamento dei secondi
function startclock()
{
	// Make sure the clock is stopped
	stopclock();
	//timerID = setInterval("showtime()",100);
	//timerRunning = true;
	for(i=0; i<(document.forms.length); i++)
	{
		if (document.forms[0].name == "clock")
		{
			timerID = setInterval("showtime()",100);
			timerRunning = true;
		}
	}
	
}

// Arresta il timer
function stopclock()
{
	if(timerRunning) clearInterval(timerID);
	timerRunning = false;
}

// SCRIVE LA STRINGA CALENDARIO CON DATA E ORA ODIERNA
function showtime()
{
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds();
	//var timeValue = "" + ((hours > 12) ? hours - 12 : hours);
	//var dayValue = nomegiorno(now.getUTCDay());
	var dateValue = nomegiorno(now.getUTCDay())+" "+now.getUTCDate()+" "+nomemese(now.getUTCMonth())+" "+now.getUTCFullYear();
	var	timeValue = hours;
	timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
	timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
	//timeValue += (hours >= 12) ? " P.M." : " A.M.";
	//document.clock.giorno.value = dayValue;
	document.clock.data.value = dateValue;
	document.clock.ora.value = timeValue;
}

function calendario(mData, mOra)
{
	document.writeln('<FORM NAME="clock" onSubmit="0">');
	//if (G) document.writeln('<INPUT TYPE="text" NAME="giorno" VALUE ="" class="calendario">');
	if (mData) document.writeln('<INPUT readonly TYPE="text" NAME="data" VALUE ="" class="calendario">');
	if (mOra) document.writeln('<INPUT readonly TYPE="text" NAME="ora" VALUE ="" class="calendario">');
	document.writeln('</FORM>');
}
