 function sopra(immagine) {
        chiudi_tutti();
        eval('document.'+immagine+'.src="images/menu/'+immagine+'_on.gif"');
     }
         
 function fuori(immagine) {
        eval('document.'+immagine+'.src="images/menu/'+immagine+'.gif"');
     }


 function getGiorno(data2) {
     var t = new Date(data2);
     var day="";
     if (t.getDay()==1) {day="Lunedì"; }
     if (t.getDay()==2) {day="Martedì"; }
     if (t.getDay()==3) {day="Mercoledì"; }
     if (t.getDay()==4) {day="Giovedì"; }
     if (t.getDay()==5) {day="Venerdì"; }
     if (t.getDay()==6) {day="Sabato"; }
     if (t.getDay()==0) {day="Domenica"; }
     return day;
 }

 function immagine(_file, _width, _height, _foto) {
        window.open('immagini.html?' + _file + '&' + _width + '&' + _height + '&' + _foto, 'Nuova', 'toolbar=no,menubar=no,location=no,status=no,resizable=no,scrollbars=no,width=' + _width + ',height=' + _height + ',top=15,left=15');
 }
 
 
 function Avviso(_finestra) {
        window.open(_finestra,'AvvisoFsc','toolbar=no,scrollbars=no,menubar=no,width=165,height=210,top=170,left=170'); 
}
    
    
// imposta i valori dei campi datainiziale e datafinale
function ImpostaData(_par)
{
	// memorizza la data corrente
	var now = new Date();
	var gs = now.getDay();	
	var day = now.getDate();
	var month = now.getMonth();
	var year = now.getYear();
	var netyear = 0;
	

	
	
	// corregge l'anno se il browser è Netscape 
	if (navigator.appName.match('Netscape'))
	 netyear += 3800;
		
	// crea la data iniziale e la data finale
	var d1 = new Date();
	var d2 = new Date();
	
	
	
	
	switch (_par)
	{   
		case "Ieri":
		{
			d1 = new Date(year, month, day - 1);
			d2 = new Date(year, month, day - 1);
			break;
		}
		case "Oggi":
		{
			d1 = new Date(year, month, day);
			d2 = new Date(year, month, day);
			break;
		}
		case "SettimanaScorsa":
		{
			d1 = new Date(year, month, day - gs - 7 + 1);
			d2 = new Date(year, month, day - gs);
			break;
		}
		case "SettimanaCorrente":
		{
			d1 = new Date(year, month, day - gs + 1);
			d2 = new Date(year, month, day);
			break;
		}
		case "SettimanaIntera":
		{
			d1 = new Date(year, month, day - gs + 1);
			d2 = new Date(year, month, day - gs + 7);
			break;
		}
		case "MeseScorso":
		{
			d1 = new Date(year, month - 1, 1);
			d2 = new Date(year, month, 0);
			break;
		}
		case "MeseCorrente":
		{
			d1 = new Date(year, month , 1);
			d2 = new Date(year, month, day);
			break;
		}
		case "MeseIntero":
		{
			d1 = new Date(year, month, 1);
			d2 = new Date(year, month + 1, 0);
			break;
		}
		case "AnnoScorso":
		{
			d1 = new Date(year - 1, 0, 1);
			d2 = new Date(year, 0, 0);
			break;
		}
		case "AnnoCorrente":
		{
			d1 = new Date(year, 0 , 1);
			d2 = new Date(year, month, day);
			break;
		}
		case "AnnoIntero":
		{
			d1 = new Date(year, 0, 1);
			d2 = new Date(year + 1, 0, 0);
			break;
		}
		default:
		{
			d1 = new Date(year, month , 1);
			d2 = new Date(year, month, day);
		}
	}
	
	var giorno1 = d1.getDate();
	var mese1 = d1.getMonth()+1;
	var giorno2 = d2.getDate();
	var mese2 = d2.getMonth()+1;
	if (giorno1 <= 9) giorno1 = "0" + giorno1;
	if (mese1  <= 9 ) mese1 = "0" + mese1;
	
	if (giorno2 <= 9) giorno2 = "0" + giorno2;
	if (mese2  <= 9 ) mese2 = "0" + mese2;
	
	// visualizza la data iniziale
	document.Scelta.datainiziale.value = String(giorno1) + "/" + String(mese1) + "/" + String(d1.getYear() + netyear);
	// visualizza la data finale
	document.Scelta.datafinale.value = String(giorno2) + "/" + String(mese2) + "/" + String(d2.getYear() + netyear);
}

// restituisce il valore del menu a tendina
function ValoreSelezionato(campo)
{
	var valore = "";
	
	// scorre gli elementi del menu a tendina
	for (var i = 0; i < eval('document.Scelta.' + campo + '.length'); i++)
	 if (eval('document.Scelta.' + campo + '.options[' + i + '].selected'))
	  valore = eval('document.Scelta.' + campo + '.options[' + i + '].value');

	return valore;
}

// cancella i valori contenuti nei campi Login e Password
function ResetCampi()
{
	document.Scelta.periodo.options[7].selected = true;
	document.Scelta.Funzione.options[0].selected = true;
	ImpostaData();
}

// Cambia i layout del corpo

function CambiaLayout() 
{

	if (document.Scelta.riepilogo.checked) document.Scelta.cmd.value='layout2';
}

// controlla i campi nell'inserimento dei dati. ESTERNO
function ControllaCampi ()  
{
	/* Assegnazione variabili*/
	var check = new Boolean();
	var errore= 'ATTENZIONE!\nInserire i valori per i campi:\n';
	check = false;
	var _datainiziale = document.Scelta.datainiziale.value;
	var _datafinale = document.Scelta.datafinale.value;
	var _descrizione = document.Scelta.descrizione.value;
	
	/* Controlla se descrizione, data inziale e data finale sono stati inseriti correttamente */
	if (_descrizione !='')
	{
		check = true;
	} else {
		errore = errore + 'Descrizione\n';
	}
	
	if ( !ControllaData(_datainiziale) )
	{
		errore = errore + 'Data iniziale\n';
	}
	
	if ( !ControllaData(_datafinale) ) 
	{
		errore = errore + 'Data finale\n';
	}
	
	/* Se i campi sono stati inseriti corretrtamente invia la form*/
	if ( (check) && (ControllaData(_datafinale)) && (ControllaData(_datainiziale)) ) {				
		document.Scelta.submit();
		//window.close();
	} else {
		alert(errore);
	}
} 

function ControllaCampiMenu (_cmd, _target)  
{
	/* Assegnazione variabili*/
	var check = new Boolean();
	var errore= 'ATTENZIONE!\nInserire i valori per i campi:\n';
	check = false;
	var _datainiziale = document.Scelta.datainiziale.value;
	var _datafinale = document.Scelta.datafinale.value;
	
	if ( !ControllaData(_datainiziale) )
	{
		errore = errore + 'Data iniziale\n';
	} else check = true;
	
	if ( !ControllaData(_datafinale) ) 
	{
		errore = errore + 'Data finale\n';
	} else check = true;
	
	/* Se i campi sono stati inseriti corretrtamente invia la form*/
	if ( (check) && (ControllaData(_datafinale)) && (ControllaData(_datainiziale)) ) {				
	document.Scelta.cmd.value=_cmd; 
	document.Scelta.target=_target; 
	if (document.Scelta.riepilogo.checked && (document.Scelta.cmd.value == 'layout1') ) document.Scelta.cmd.value='layout2';
	ApriFinestraSmall(_target);
	document.Scelta.submit();
		//window.close();
	} else {
		/* Meggaggio di errore che indica quali campi sono sbagliati*/
		//alert(errore);
	}
	
}


function AggiornaMenu() {
		AggiornaMenuDuplica();
		window.close();
}

function AggiornaMenuDuplica() {
		if (navigator.appName.match('Netscape')) {			
			opener.document.Scelta.cmd.value='layout1';
		} else {
			if (opener.document.Scelta.riepilogo.checked == true) { opener.document.Scelta.cmd.value='layout2'; } else { opener.document.Scelta.cmd.value='layout1'; }
		}
		opener.document.Scelta.target = '_self';
		opener.document.Scelta.submit();
}

/*Controlla se la data passata */
function ControllaData( _data ) 
{
	
	var check = new Boolean();
	check=false;
	var data = new String(_data);
	var dim = new Array();
	dim = data.split("/");
	if ( dim.length == 3) check = true;
	if (check) {
		if ( (dim[0] >= 1) && (dim[0] <= 31)  && (check) ) check = true; else check=false
		if ( (dim[1] >= 1) && (dim[1] <= 12) && (check) ) check = true; else check=false
	
		if ( (dim[2] >= 2000) && (dim[2] <= 2099) && (check) ) check = true; else check=false
	}
	return check;
}

/* musica nelle popup */
var popup;

function checkMusica() {	     
		popup = window.open("musica.jsp","musica",'toolbar=no,scrollbars=yes,width=241,height=148,top=5,left=50');
		popup.focus();
}

