var numMese = new Array(12);
numMese['Gennaio'] = "01";
numMese['Febbraio'] = "02";
numMese['Marzo'] = "03";
numMese['Aprile'] = "04";
numMese['Maggio'] = "05";
numMese['Giugno'] = "06";
numMese['Luglio'] = "07";
numMese['Agosto'] = "08";
numMese['Settembre'] = "09";
numMese['Ottobre'] = "10";
numMese['Novembre'] = "11";
numMese['Dicembre'] = "12";





function numberFromJsToPhp(campo, decimals)
{
	var trovato = 0;
	
	for(j=0; j<campo.value.length; j++)
	{
		carattere = campo.value.charAt(j);
		if (carattere == "." || carattere == ",")
		{
			trovato = trovato + 1;
		}
	}
	
	if (trovato >1)
	{
		alert("E' possibile usare un solo separatore!");
		return;
	}
		
	
	if (campo.readOnly == true || campo.value == "") return;
	
	number = campo.value;
	number = replaceAll(" ","", number);
	number = replaceAll(",",".", number);
	
	dec_point = ",";
	thousands_sep = " ";

	number = number.toString();
	number = number.replace(/\,|^0*/g, '');
	number = parseFloat(number);
	if (isNaN(number)) number = 0;
	number= Math.round(number * Math.pow(10, decimals)) / Math.pow(10, decimals);
	number = number.toString();
	f = number.split('.');
	if(!f[0]) f[0] = '0';
	if(!f[1]) f[1] = '';
	if(f[1].length < decimals)
        {
		g = f[1];
		for(i = f[1].length + 1; i <= decimals; i++) 
		{
			g += '0';
		}
		f[1] = g;
	}
	if(thousands_sep != '' && f[0].length > 3) 
 	{
		h = f[0];
		f[0] = '';
		for(j = 3; j < h.length; j += 3)
		 {
			i = h.slice(h.length - j, h.length - j + 3);
			f[0] = thousands_sep + i + f[0] + '';
		}
		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		f[0] = j + f[0];
 	}
	dec_point = (decimals <= 0) ? '': dec_point;
	
	risultato = f[0] + dec_point + f[1];
	
	campo.value = risultato;
}







function TMSControlExtraInfo(totOre,giorno)
{
	var totRighe = document.getElementById('NumComm').value;

	numCommSel = 0;
	for (i=1; i<=totRighe; i++)
	{
		if (document.getElementById('Ore[' + i + ']').value > 0) numCommSel++;
	}

	if (numCommSel > 5)
	{
		alert("E' possibile selezionare un massimo di 5 commesse!");
		return false;
	}

	sommaOre = 0;
	for (i=1; i<=totRighe; i++)
	{
	        var tmpMin = document.getElementById('Minuti[' + i + ']').value;
		if (tmpMin.length==1)
			tmpMin="0"+tmpMin;
		var tmp = parseFloat(document.getElementById('Ore[' + i + ']').value+"."+tmpMin);

		
		if(!checkOreExtra(i,totOre))
			{
				return false;	
			}
		
		sommaOre = addOre(sommaOre,tmp);
	}

	if (sommaOre == totOre || sommaOre == 0)
	{
		window.opener.document.getElementById('DettComm['+ giorno+']').src='./images/dettagli_verde.png';
		window.opener.document.getElementById('ImgDettExtra['+ giorno+']').value='dettagli_verde.png';
		document.ExtraData.op.value = 'save';
		document.ExtraData.submit();
	}
	else
	{
		alert("La somma delle ore delle commesse deve coincidere col numero di ore totali!");
	}

}



function checkOreExtra(index,totOre)
{
	var ore = document.getElementById('Ore[' + index + ']');
	var minuti = document.getElementById('Minuti[' + index + ']');

	if(isNaN(parseFloat(ore.value)) )
	{
		alert("Sono attesi solo numeri per le ore !");
		ore.focus();
		ore.select();
		return false;	
	}	
	
	if(isNaN(parseFloat(minuti.value)) )
	{
		alert("Sono attesi solo numeri per i minuti !");
		minuti.focus();
		minuti.select();
		return false;	
	}	

	if(parseFloat(ore.value<0) || parseFloat(ore.value>23))
	{
		alert("Le ore devono essere comprese tra 0 e 23 !");
		ore.focus();
		ore.select();
		return false;	
	}	


	if(parseFloat(minuti.value<0) || parseFloat(minuti.value>59))
	{
		alert("I minuti devono essere comprese tra 0 e 59 !");
		minuti.focus();
		minuti.select();
		return false;	
	}	
return true;
}


function loadExtra()
{
	//alert('loadExtra');
	var totRighe = document.getElementById('NumComm').value;

	for (index=1; index <= totRighe; index++)
	{
		var ore    = document.getElementById('Ore[' + index + ']');
		var minuti = document.getElementById('Minuti[' + index + ']');
		
		//alert("ore.length:"+ore.length);

		if (ore.value.length==1)
			ore.value="0"+ore.value;
		
		if (minuti.value.length==1)
			minuti.value="0"+minuti.value;	

		if (ore.value == "")
			ore.value = '00';
		if (minuti.value == "")
			minuti.value = '00';

	}
}


function popUpExtraInfo(data, idxOreEffetuate,idTms,IdDipendente,HOLD)
{
	var oreField = document.getElementById("OreEffettuate["+idxOreEffetuate+"]");

	var ore= oreField.value;

	if (isNaN(ore))
	{
		alert("Valorizzare prima le ore di lavoro!");
		return false;
	}

	var V_Larg = screen.width/3;
	var V_Alt = screen.height/3;

	window.open('index.php?file=timesheet_extra&Data='+data+'&Ore='+ore+'&Id='+idTms+'&IdDipendente='+IdDipendente+'&HOLD='+HOLD,'','width=420,height=270,left='+V_Larg+',top='+V_Alt+',toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0');

}

function popUpExtraInfoNotaSpesa(indice,commessa_principale,ID_NS,ID_DIP,anno,mese)
{
	var gg = document.getElementById("giorno_"+indice);
	if (gg.value == '')
	{
		alert('Valorizzare il campo giorno');
		return false;
	}
	else
	{
		var data = gg.value+"/"+mese+"/"+anno;
		var V_Larg = screen.width/3;
		var V_Alt = screen.height/3;
		var url  = 'index.php?file=nota_spese_extra_info&op=PrendiDati&ID_NS='+ID_NS+'&ID_DIP='+ID_DIP+'&Data='+data+'&Indx='+indice+'&CommessaPrincipale='+commessa_principale;
		window.open(url,'','width=420,height=270,left='+V_Larg+',top='+V_Alt+',toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0');
	}
}

function checkDatiExtraInfoNotaSpesa(formPassata)
{
	var check = document.getElementsByName("check[]");

	var CommessaPrincipale = document.getElementById("CommessaPrincipale");

	var indice = document.getElementById("Indx").value;

	var numCheckSelected = 0;

	var  lastSelected ;
	for( i = 0; i < check.length; i++)
	{
		if(check[i].checked)
		{
			numCheckSelected++;
			lastSelected =  check[i];
		}
	}
	
	if (numCheckSelected > 5)
	{
		alert('Puoi lavorare al massimo su cinque commesse ! ');
		return;
	}

	if (numCheckSelected == 1 && lastSelected.value == CommessaPrincipale.value )
	{
		if (confirm("Nessuna commessa oltre la principale selezionata !!! Cancellare le extra info ?"))
		{
			window.opener.document.getElementById('img_'+ indice).src='./images/dettagli_rosso.png';
			check[0].checked=false;
			formPassata.submit();
			return;
		}
		else
			return ;
	}
	
	
	if(numCheckSelected > 0)	
		window.opener.document.getElementById('img_'+ indice).src='./images/dettagli_verde.png';
	else
		window.opener.document.getElementById('img_'+ indice).src='./images/dettagli_rosso.png';

	formPassata.submit();

}

function isInteger(s)
{
	var i;
	for (i = 0; i < s.length; i++)
	{
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

function stripCharsInBag(s, bag)
{
	var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
	// EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n)
{
	for (var i = 1; i <= n; i++)
	{
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
	}
	return this
}

function trim(val)
{
	a = val.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
}

function ControlloCambioPwd()
{

	conf = confirm("Sicuro di voler cambiare la password?");
	if (conf == false)
	{
		return false;
	}

	vPass_0 = document.cambio.pwd_0.value;
	vPass_1 = document.cambio.pwd_1.value;

	if (trim(vPass_0) == "" || trim(vPass_1) == "")
	{
		alert('valorizzare Campi!');
		return false;
	}
	else if (vPass_0 != vPass_1)
	{
		alert('Le password non corrispondono!');
		return false;
	}
	else
	{
		document.cambio.submit();
	}

}

function OpenNewWindow_malattia(note,datain, datafi)
{
	NoteWin=window.open('','','dependent=yes, width=600 height=100 resizable=no titlebar=no');
	NoteWin.document.write('<html><head><title>Note Comunicazione Malattia</title></head>');
	NoteWin.document.write('<BODY BGCOLOR=#EEEEEE>');
	NoteWin.document.write('<B>Nota relativa al periodo malattia dal ' + datain + ' al ' + datafi + ':</B><BR>');
	NoteWin.document.write('' + note + '');
	NoteWin.document.write('</font></body></html>');
}

function OpenNewWindow_permessi(note,data)
{
	NoteWin=window.open('','','dependent=yes, width=600 height=100 resizable=no titlebar=no');
	NoteWin.document.write('<html><head><title>Note Permesso Orario</title></head>');
	NoteWin.document.write('<body bgcolor=#EEEEEE>');
	NoteWin.document.write('<B>Nota relativa al permesso orario del ' + data + ':</B><BR>');
	NoteWin.document.write('' + note + '');
	NoteWin.document.write('</font></body></html>');
}

function OpenNewWindow_ferie(note,datain, datafi)
{
	NoteWin=window.open('','','dependent=yes, width=600 height=100 resizable=no titlebar=no');
	NoteWin.document.write('<html><head><title>Note Richiesta Ferie</title></head>');
	NoteWin.document.write('<body bgcolor=#EEEEEE>');
	NoteWin.document.write('<b>Nota relativa al periodo ferie dal ' + datain + ' al ' + datafi + ':</B><BR><BR>');
	NoteWin.document.write('' + note + '');
	NoteWin.document.write('</font></body></html>');
}


function OpenNewWindow_auto(note)
{
	NoteWin=window.open('','','dependent=yes, width=400 height=50 resizable=no titlebar=no');
	NoteWin.document.write('<html><head><title>Note Richiesta Autorizzazione Auto Propria</title></head>');
	NoteWin.document.write('<body bgcolor=#EEEEEE>');
	NoteWin.document.write('' + note + '');
	NoteWin.document.write('</font></body></html>');
}


function OpenNewWindow_missioni(note,datain)
{
	NoteWin=window.open('','','dependent=yes, width=600 height=100 resizable=no titlebar=no');
	NoteWin.document.write('<html><head><title>Note Comunicazione Missione</title></head>');
	NoteWin.document.write('<body bgcolor=#EEEEEE>');
	NoteWin.document.write('<b>Nota relativa alla missione del ' + datain + ':</B><BR><BR>');
	NoteWin.document.write('' + note + '');
	NoteWin.document.write('</font></body></html>');
}




var STR_PAD_LEFT = 1;
var STR_PAD_RIGHT = 2;
var STR_PAD_BOTH = 3;
 
function pad(str, len, pad, dir) 
{
 
	if (typeof(len) == "undefined") { var len = 0; }
	if (typeof(pad) == "undefined") { var pad = ' '; }
	if (typeof(dir) == "undefined") { var dir = STR_PAD_RIGHT; }
 
	if (len + 1 >= str.length) {
 
		switch (dir){
 
			case STR_PAD_LEFT:
				str = Array(len + 1 - str.length).join(pad) + str;
			break;
 
			case STR_PAD_BOTH:
				var right = Math.ceil((padlen = len - str.length) / 2);
				var left = padlen - right;
				str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
			break;
 
			default:
				str = str + Array(len + 1 - str.length).join(pad);
			break;
 
		} // switch
 
	}
 
	return str;
 
}



function check_field_malattia()
{	
	var itsok = 1;
	var dataIn = document.getElementById("dataInizio").value;
	var dataOut = document.getElementById("dataFine").value;
	//	trasformo le date nel formato aaaammgg (es. 20081103)
	dataInStr = dataIn.substr(6)+dataIn.substr(3, 2)+dataIn.substr(0, 2);
	dataOutStr = dataOut.substr(6)+dataOut.substr(3, 2)+dataOut.substr(0, 2);
	
	var oraIni = document.getElementById("O_I_MLT").value;
	oraIni = pad(oraIni, 2, '0', STR_PAD_LEFT) ;
	var minIni = document.getElementById("M_I_MLT").value;
	minIni = pad(minIni, 2, '0', STR_PAD_LEFT) ;
	
	var oraFine = document.getElementById("O_F_MLT").value;
	oraFine = pad(oraFine, 2, '0', STR_PAD_LEFT) ;
	var minFine = document.getElementById("M_F_MLT").value;
	minFine = pad(minFine, 2, '0', STR_PAD_LEFT) ;
	
	
	if (oraIni == "00" && minIni=="00")
	{
		alert ("L'ora di inizio malattia non e\' completa!");
		itsok = 0;
	}
	
	
	if (oraFine == "00" && minFine=="00")
	{
		alert ("L'ora di fine malattia non e\' completa!");
		itsok = 0;
	}
	
	 if (parseInt(oraFine+minFine)<parseInt(oraIni+minIni))
	{
		alert("L' ora di inizio deve essere precedente a quella finale");
		itsok = 0;
	}
	
	if (dataIn == "")
	{
		alert ("La data di inizio malattia non e\' completa!");
		itsok = 0;
	}
	else if (dataOut == "")
	{
		alert ("La data di fine malattia non e\' completa!");
		itsok = 0;
	}
	else if (document.getElementById("select_com").selectedIndex == 0)
	{
		alert ("Selezionare un codice commessa");
		itsok = 0;
	}
	//	controllo se la seconda data è successiva alla prima
	else if (parseInt(dataOutStr)<parseInt(dataInStr))
	{
		alert("La data iniziale deve essere precedente quella finale");
		itsok = 0;
	}
	
	if (itsok == 1)
	{
		document.getElementById("FIELD_OK").value = 1;
		document.getElementById("CLICK_SEND").value = 1;
		document.Form1.submit();
	}
}	

function check_field_missione()
{
	//flag che vale 1 se la tutti i campi sono correttamente valorizzati
	var itsok = 1;

	//non e' stato selezionato il giorno di inizio missione
	if (document.all.DataDal.value == "")
	{
		alert ("Specificare la data di inizio missione !");
		itsok = 0;
	}
	else if (document.all.DataAl.value == "")
	{
		alert ("Specificare la data di fine missione !");
		itsok = 0;
	}
	else if (document.all.destinazione.value == "")
	{
		alert ("Specificare una destinazione");
		itsok = 0;
	}

	//tutti i campi sono correttamente valorizzati
	if (itsok == 1)
	{
		document.all.FIELD_OK.value = 1;
		document.all.CLICK_SEND.value = 1;
		document.Form1.submit();
	}
}





function check_field_permessi()
{
	var itsok = 1;

	if (document.all.data.value == "")
	{
		alert ("Valorizzare il campo data!");
		itsok = 0;
	}
	else if (document.all.O_I_PRM.value == '' || document.all.M_I_PRM.value == '')
	{
		alert ("L\'orario di inizio permesso non e\' completo!");
		itsok = 0;
	}
	else if (document.all.O_F_PRM.value == '' || document.all.M_F_PRM.value == '')
	{
		alert ("L\'orario di fine permesso non e\' completo!");
		itsok = 0;
	}
	else if (document.all.select_com.selectedIndex == 0)
	{
		alert ("Selezionare un codice commessa");
		itsok = 0;
	}

	if (itsok == 1)
	{
		document.all.FIELD_OK.value = 1;
		document.all.CLICK_SEND.value = 1;
		document.Form1.submit();
	}
}

function check_field_report($flag)
{
	var itsok = 1;

	if (document.getElementById('DescAtt').value  == "")
	{
		alert ("Non e\' stata inserita la descrizione dell\'attivita\'!");
		itsok = 0;
	}
	else if ($flag == 1)
	document.getElementById('HOLD').value  = 1;
	else
	document.getElementById('HOLD').value  = 0;

	if (itsok)
	{
		document.Form1.submit();
	}
}

function check_hold_timesheet($tipo_hold)
{
	if ($tipo_hold == 1)
	document.getElementById('HOLD').value = "Y";
	else
	document.getElementById('HOLD').value = "N";

	document.Form1.submit();
}

function check_field_ferie()
{	
	var itsok = 1;
	var dataIn = document.getElementById("dataInizio").value;
	var dataOut = document.getElementById("dataFine").value;
	//	trasformo le date nel formato aaaammgg (es. 20081103)
	dataInStr = dataIn.substr(6)+dataIn.substr(3, 2)+dataIn.substr(0, 2);
	dataOutStr = dataOut.substr(6)+dataOut.substr(3, 2)+dataOut.substr(0, 2);
	
	
	if (dataIn == "")
	{
		alert ("La data di inizio ferie non e\' completa!");
		itsok = 0;
	}
	else if (dataOut == "")
	{
		alert ("La data di fine ferie non e\' completa!");
		itsok = 0;
	}
	else if (document.getElementById("select_com").selectedIndex == 0)
	{
		alert ("Selezionare un codice commessa");
		itsok = 0;
	}
	//	controllo se la seconda data è successiva alla prima
	else if (parseInt(dataOutStr)<parseInt(dataInStr))
	{
		alert("La data iniziale deve essere precedente quella finale");
		itsok = 0;
	}
	
	if (itsok == 1)
	{
		document.all.FIELD_OK.value = 1;
		document.all.CLICK_SEND.value = 1;
		document.Form1.submit();
	}
}





function check_field_auto_propria()
{	
	var itsok = 1;
	var dataIn = document.getElementById("dataInizio").value;
	var dataOut = document.getElementById("dataFine").value;
	
	var marca =  document.getElementById("marca").value;
	var modello =  document.getElementById("modello").value;
	var targa =  document.getElementById("targa").value;
	var coeff_aci =  document.getElementById("coeff_aci").value;
	var destinazione =  document.getElementById("destinazione").value;
	
	//	trasformo le date nel formato aaaammgg (es. 20081103)
	var dataInStr = dataIn.substr(6)+dataIn.substr(3, 2)+dataIn.substr(0, 2);
	var dataOutStr = dataOut.substr(6)+dataOut.substr(3, 2)+dataOut.substr(0, 2);
	
	var meseIn = dataIn.substr(3, 2);
	var meseFi = dataOut.substr(3, 2);
	
	
	if (dataIn == "")
	{
		alert ("La data di inizio  non e\' completa!");
		itsok = 0;
	}
	else if (dataOut == "")
	{
		alert ("La data di fine  non e\' completa!");
		itsok = 0;
	}
	else if (document.getElementById("select_com").selectedIndex == 0)
	{
		alert ("Selezionare un codice commessa");
		itsok = 0;
	}
	//	controllo se la seconda data è successiva alla prima
	else if (parseInt(dataOutStr)<parseInt(dataInStr))
	{
		alert("La data iniziale deve essere precedente quella finale");
		itsok = 0;
	}
	else if (marca == "")
	{
		alert ("La marca dell'auto e' obbligatoria!");
		itsok = 0;
	}
	else if (modello == "")
	{
		alert ("Il modello dell'auto e' obbligatorio!");
		itsok = 0;
	}
	else if (targa == "")
	{
		alert ("La targa dell'auto e' obbligatorio!");
		itsok = 0;
	}
	else if (coeff_aci == "")
	{
		alert ("Il coefficiente ACI dell'auto e' obbligatorio!");
		itsok = 0;
	}
	else if (destinazione == "")
	{
		alert ("La estinazione e' obbligatoria!");
		itsok = 0;
	}
	else if (!IsNumeric(coeff_aci) )
	{
		alert ("Il coefficiente ACI dell'auto deve essere numerico !");
		itsok = 0;
	}else if (meseIn!=meseFi)
	{
		alert ("Non è possibile effettuare richieste che si estendono su piu' mesi !");
		itsok = 0;
	}
	
	
	if (itsok == 1)
	{
		document.all.FIELD_OK.value = 1;
		document.all.CLICK_SEND.value = 1;
		document.Form1.submit();
	}
}


function submitFormPFM()
{
	document.form_pfm.submit();
}

function SubmitForm1()
{

	document.Form1.submit();
}

function ContrCampiNotaSpeseObb(UltimoGiornoDelMese,stato)
{


	//Se sto riaprendo una NS chiedo conferma prima di effettuare i controlli
	if(
	(document.form_nota_spese['vecchio_stato'].value=='C' && document.form_nota_spese['STATO'].value=='O' )
	|| document.form_nota_spese['vecchio_stato'].value=='A'
	)
	{
		var conf = confirm("Sicuro di voler riaprire la nota spese?");
		if (conf == false)
		{
			return false;
		}
	}


	var Nr_Giorni = 0;
	var Indx;

	for(Indx = 0; Indx < UltimoGiornoDelMese; Indx++)
	{
		if (document.form_nota_spese['GIORNO[]'][Indx].value != '')
		{
			Nr_Giorni++;
		}
	}

	if (Nr_Giorni == 0)
	{
		alert('Inserisci almeno un giorno!');
		return false;
	}

	for (Indx = 0; Indx < Nr_Giorni; Indx++)
	{
		if (document.form_nota_spese['GIORNO[]'][Indx].value != '')
		{
			if (document.form_nota_spese['GIORNO[]'][Indx].value > UltimoGiornoDelMese)
			{
				alert('Inserito giorno maggiore dei giorni del mese!');
				return false;
			}

			if (document.form_nota_spese['GIORNO[]'][Indx].value < 1)
			{
				alert('Inserito giorno minore di 1!');
				return false;
			}
		}


		if (document.form_nota_spese['DESC_SPOSTAMENTO[]'][Indx].value == '')
		{
			alert('La descrizione spostamento e\' obbligatoria!');
			return false;
		}

	/*	if( IsNumeric(document.form_nota_spese['KM_CON_AUTO_PROPRIA[]'][Indx].value)==false && document.form_nota_spese['KM_CON_AUTO_PROPRIA[]'][Indx].value!='' )
		{
			alert('Il campo \'km con auto propria\' deve essere numerico !');
			return false;
		}*/

		if( IsNumeric( document.form_nota_spese['SPESE_HOTEL[]'][Indx].value)==false && document.form_nota_spese['SPESE_HOTEL[]'][Indx].value!='' )
		{
			alert('Il campo \'Spese Hotel\' deve essere numerico !');
			return false;
		}

		if( IsNumeric( document.form_nota_spese['SPESE_PASTI[]'][Indx].value)==false && document.form_nota_spese['SPESE_PASTI[]'][Indx].value!='' )
		{
			alert('Il campo \'Spese Pasti\' deve essere numerico !');
			return false;
		}

		if( IsNumeric( document.form_nota_spese['SPESE_TRASPORTI[]'][Indx].value)==false && document.form_nota_spese['SPESE_TRASPORTI[]'][Indx].value!='' )
		{
			alert('Il campo \'Spese Trasporti\' deve essere numerico !');
			return false;
		}

		if( IsNumeric( document.form_nota_spese['SPESE_VARIE[]'][Indx].value)==false && document.form_nota_spese['SPESE_VARIE[]'][Indx].value!='' )
		{
			alert('Il campo \'Spese Varie\' deve essere numerico !');
			return false;
		}

		if( IsNumeric( document.form_nota_spese['CARBURANTE[]'][Indx].value)==false && document.form_nota_spese['CARBURANTE[]'][Indx].value!='' )
		{
			alert('Il campo \'Carburante\' deve essere numerico !');
			return false;
		}

		if( IsNumeric( document.form_nota_spese['ORE_VIAGGIO_EXTRA[]'][Indx].value)==false && document.form_nota_spese['ORE_VIAGGIO_EXTRA[]'][Indx].value!='' )
		{
			alert('Il campo \'Ore viaggio extra\' deve essere numerico !');
			return false;
		}


	}//fine for

	// controllo se ci sono + giorni uguali
	for (GG = 1; GG <= Nr_Giorni; GG++)
	{

		QtaStessoGiorno = 0;
		for (Indx = 0; Indx <  Nr_Giorni; Indx++)
		{
			if (document.form_nota_spese['GIORNO[]'][Indx].value == GG)
			{
				QtaStessoGiorno++;
			}
		}

		//alert("Giorno: "+GG+"("+QtaStessoGiorno+")");

		if (QtaStessoGiorno > 1)
		{
			alert('Inserito piu\' volte lo stesso giorno!');
			return false;
		}

	}

	if(stato != '')
	{
		document.form_nota_spese.STATO.value=stato;
	}
	document.form_nota_spese.submit();
}

function isArray(testObject)
{
	return testObject && !(testObject.propertyIsEnumerable('length')) && typeof testObject === 'object' && typeof testObject.length === 'number';
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789,.";
	var IsNumber=true;
	var Char;


	for (i = 0; i < sText.length && IsNumber == true; i++)
	{
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
			IsNumber = false;
		}
	}
	return IsNumber;

}

function Popup(apri)
{
	var stile = "top=10, left=10,  status=yes, menubar=no, toolbar=yes scrollbar=yes";
	//window.open(apri, "", stile);
	document.location=apri;
}


function redirect(url)
{
	//alert(url);
	document.location=url;
}

function settaPausa(Indice)
{
	var pausa = document.all["Pausa["+Indice+"]"];
	pausa.selectedIndex = 12;
}


function calcolaOreEffettuate(UltimoGiornoDelMese)
{
	TotOre = 0;
	Ore = 0;
	TotPerm = 0;
	OrePerm = 0;
	MinPerm = 0;
	permesso =0;
	document.all["TotOreEffettuate"].value = " -- ";
	document.all["TotPermessi"].value = " -- ";

	for(Indx = 1; Indx <= UltimoGiornoDelMese; Indx++)
	{
		document.all["OreEffettuate["+Indx+"]"].value = " -- ";
		document.all["OreEffettuate["+Indx+"]"].style.borderColor = "#B0C4DE";

		if((document.all["OreIn["+Indx+"]"].value!="" && IsNumeric(document.all["OreIn["+Indx+"]"].value)==true)
		&&(document.all["MinutiIn["+Indx+"]"].value!="" && IsNumeric(document.all["MinutiIn["+Indx+"]"].value)==true)
		&&(document.all["OreOut["+Indx+"]"].value!="" && IsNumeric(document.all["OreOut["+Indx+"]"].value)==true)
		&&(document.all["MinutiOut["+Indx+"]"].value!="" && IsNumeric(document.all["MinutiOut["+Indx+"]"].value)==true))
		{

			HHIn = document.all["OreIn["+Indx+"]"].value;

			if(document.all["MinutiIn["+Indx+"]"].value.length == 1)
				MMIn = "0"+document.all["MinutiIn["+Indx+"]"].value;
			else
				MMIn = document.all["MinutiIn["+Indx+"]"].value;

			
			var In = parseFloat(HHIn+"."+MMIn);

			HHOut = document.all["OreOut["+Indx+"]"].value;

			if(document.all["MinutiOut["+Indx+"]"].value.length == 1)
				MMOut = "0"+document.all["MinutiOut["+Indx+"]"].value;
			else
				MMOut = document.all["MinutiOut["+Indx+"]"].value;

			
			var Out = parseFloat(HHOut+"."+MMOut);

			

			AH = document.all["AH["+Indx+"]"].checked;

			
			if(AH==true)
				Out +=24;


			var p = document.all["Pausa["+Indx+"]"].value
			HHPausa = ""+Math.floor(parseFloat(p)/60);
			MMPausa = ""+(parseFloat(p)%60);
			
			
			if(MMPausa.length == 1)
				MMPausa = "0"+MMPausa;
			
			
			var Pausa = parseFloat(HHPausa+"."+MMPausa);

		

			if(document.all["OrePermessi["+Indx+"]"].value!="" && IsNumeric(document.all["OrePermessi["+Indx+"]"].value)==true)
			{
				HHPerm = ""+parseFloat(document.all["OrePermessi["+Indx+"]"].value);
				MMPerm = document.all["MinutiPermesso["+Indx+"]"].value;

				if(MMPerm.length == 1)
					MMPerm = "0"+MMPerm;
				
				var Perm = parseFloat(HHPerm+"."+MMPerm);

			
				TotPerm = addOre(TotPerm ,Perm);

			}	
			else
			{
				Perm=0;
			}

			/*if((document.all["OreInT["+Indx+"]"].value!="" && IsNumeric(document.all["OreInT["+Indx+"]"].value)==true)
			&&(document.all["MinutiInT["+Indx+"]"].value!="" && IsNumeric(document.all["MinutiInT["+Indx+"]"].value)==true)
			&&(document.all["OreOutT["+Indx+"]"].value!="" && IsNumeric(document.all["OreOutT["+Indx+"]"].value)==true)
			&&(document.all["MinutiOutT["+Indx+"]"].value!="" && IsNumeric(document.all["MinutiOutT["+Indx+"]"].value)==true))
			{
				var OreEffettuateSenzaPausa= diffOre(Out,In);

				OreEffettuate = diffOre (OreEffettuateSenzaPausa,Pausa);
			}
			else
			{*/
				var OreEffettuateSenzaPausa= diffOre(Out,In);

				OreEffettuate = diffOre (OreEffettuateSenzaPausa,Pausa);
				if (OreEffettuate>=8)
					OreEffettuate = diffOre(OreEffettuate,Perm);
			//}

			document.all["OreEffettuate["+Indx+"]"].value = OreEffettuate.toFixed(2);

			if (OreEffettuate < 8)
			{

				document.all["OreEffettuate["+Indx+"]"].style.borderColor = "Red";
				document.all["OreEffettuate["+Indx+"]"].style.color = "Red";
			}
			else
			{
				document.all["OreEffettuate["+Indx+"]"].style.borderColor = "Green";
				document.all["OreEffettuate["+Indx+"]"].style.color = "Green";
			}
		}

		if(document.all["OreEffettuate["+Indx+"]"].value!="" && IsNumeric(document.all["OreEffettuate["+Indx+"]"].value)==true)
		{
			Ore = parseFloat(document.all["OreEffettuate["+Indx+"]"].value);
			TotOre = addOre(TotOre , Ore);
		}

	}
	
	
	
	
	document.all["TotOreEffettuate"].value = TotOre.toFixed(2);
	document.all["TotPermessi"].value = TotPerm.toFixed(2);
}





function parteIntera(num)
{
    var str = ""+num;
    var posPunto = str.indexOf('.');
    
    if (posPunto==-1)
    	return num;
  	
  	var strInt = str.substring(0,posPunto);
  	
  	return parseFloat(strInt);  
  
}

function parteDec(num)
{
	var dec = num - parteIntera(num);

	
	return parseFloat(dec.toFixed(2));
}

function addOre(ore1,ore2)
{
	var intOre1 = parteIntera(ore1);
	var decOre1 = parteDec(ore1);

	var intOre2 = parteIntera(ore2);
	var decOre2 = parteDec(ore2);

	var sumDec = decOre1 + decOre2;
	var sumInt = intOre1 + intOre2;

	if (parseFloat(sumDec.toFixed(2))>=0.6)
	{
		sumDec -= 0.6;
		sumInt ++;	
	}
	
	var tot = sumInt+sumDec;
	
	return parseFloat(tot.toFixed(2));
}

function diffOre(ore1,ore2)
{
	var intOre1 = parteIntera(ore1);
	var decOre1 = parteDec(ore1);

	var intOre2 = parteIntera(ore2);
	var decOre2 = parteDec(ore2);

	if(parseFloat(decOre1.toFixed(2))<parseFloat(decOre2.toFixed(2)) )
	{
	   decOre1 += 0.6;
	   intOre1--;		
	}

	var diffDec = decOre1-decOre2;
	var diffInt = intOre1-intOre2;


	var diff = diffInt + diffDec;
	return parseFloat(diff.toFixed(2));
}

function calcolaOreLavorabili(numeroGiorniLavorabili)
{
	TotOreLavorabili = 0;
	OreAlGiorno = 8;
	
	TotOreLavorabili = (OreAlGiorno * numeroGiorniLavorabili);
			
	document.all["TotOreLavorabili"].value = TotOreLavorabili;
}

function popUpInfoAssenze(anno_mese, IdDipendente)
{
	var V_Larg = screen.width/3;
	var V_Alt = screen.height/3;
	
	window.open('index.php?file=info_assenze&AnnoMese='+anno_mese+'&IdDipendente='+IdDipendente,'','width=720,height=370,left='+V_Larg+',top='+V_Alt+',toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0');
	
}


function blurDateComunicazioni()
{
	var dtIni   = document.Form1.dataInizio.value;
	var dtFine  = document.Form1.dataFine.value;
	
	if(dtIni != dtFine )
	{
//		alert('Per valorizzare le ore le date di inizio e fine devono coincidere');
		document.Form1.O_I_PRM.value="";
		document.Form1.M_I_PRM.value="";
		document.Form1.O_F_PRM.value="";
		document.Form1.M_F_PRM.value="";
	}


}

