// JavaScript Document
function seton_priv(img){
	document.images[img].src="../images/m.freccia.over.gif";
}
		
function setoff_priv(img){
	document.images[img].src="../images/m.freccia.gif";
}
function seton(img){
	document.images[img].src="images/m.freccia.over.gif";
}
		
function setoff(img){
	document.images[img].src="images/m.freccia.gif";
}

function check_date(field)
{
var checkstr = "0123456789";
var DateField = field;var DateValue = "";var DateTemp = "";var seperator = "-";
var day;var month;var year;
var step = 0;var err = 0;var i;
   err = 0;
   DateValue = DateField.value;
   /* cancello tutti i dati tranne 0-9 */
   for (i = 0; i < DateValue.length; i++) 
	 {
      if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) 
			{
      	DateTemp = DateTemp + DateValue.substr(i,1);
      }
   }
   DateValue = DateTemp;
  /* se l'anno è inserito con 2 valori lo cambio sempre con  20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* anno sbagliato 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* validazione del mese*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* validazione del giorno */
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validazione anno / febbraio / gg */
   if ((year % 4 == 0)) {
      step = 1;
   }
   if ((month == 2) && (step == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (step != 1) && (day > 28)) {
      err = 24;
   }
   /* validazione dei mesi */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* se è inserito 00 cancello i dati */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* Se non ci sono errori inserisco la data (esempio 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Messaggio di errore, avviso di data corretta se err diverso da 0 */
   else {
      alert("La data inserita non è corretta.\n\nI formati supportati sono:\n  - ggmmaa\n  - ggmmaaaa\n  - gg-mm-aa\n  - gg-mm-aaaa\n");
      DateField.select();
      DateField.focus();
			DateField.value="";
   }
}

function check_time(field)
{
var checkstr = "0123456789";
var timeField = field;var timeValue = "";var timeTemp = "";var seperator = ":";
var minute;var hour;
var step = 0;var err = 0;var i;
   err = 0;
   timeValue = timeField.value;
   /* cancello tutti i dati tranne 0-9 */
   for (i = 0; i < timeValue.length; i++) 
	 {
      if (checkstr.indexOf(timeValue.substr(i,1)) >= 0) 
			{
      	timeTemp = timeTemp + timeValue.substr(i,1);
      }
   }
   timeValue = timeTemp;
  /* se c'è solo l'ora ci aggiungo 00*/
   if (timeValue.length == 2) {
      timeValue = timeValue + '00'; }
   if (timeValue.length != 4) {
      err = 19;}
   /* anno sbagliato 0000 */
/*   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }*/
   /* validazione ora*/
   hour = timeValue.substr(0,2);
   if ((hour < 1) || (hour > 24)) {
      err = 21;
   }
   /* validazione minuto */
   minute = timeValue.substr(2,2);
   if (minute > 59) {
     err = 22;
   }
   /* se è inserito 00 cancello i dati */
   if ((hour == 0) && (minute == 0)) {
      err = 0; hour = ""; minute = ""; seperator = "";
   }
//alert(err);
   /* Se non ci sono errori inserisco l'ora data (esempio 13:56) */
   if (err == 0) {
      timeField.value = hour + seperator + minute;
			return true;
   }
   /* Messaggio di errore, avviso di data corretta se err diverso da 0 */
   else {
      alert("L'ora inserita non è corretta.\n\nI formati supportati sono:\n  - hhmm\n  -  hh:mm\n ");
      timeField.focus();
      timeField.select();
			timeField.value="";
			return false;
   }
}
// APRO IL MENU ...
function apri(m)
{
    document.getElementById(m).style.visibility = "Visible";
}
// CHIUDO IL MENU ...
function chiudi(m)
{
    document.getElementById(m).style.visibility = "Hidden";
}
function apri_chiudi(m)
{
	for (var i=0;i<6;i++)
	{
		if (i!=m)
			document.getElementById(i).style.display="none";
	}
	var ele=document.getElementById(m);
	if (ele.style.display == "block")
		ele.style.display = "none";
	else
		ele.style.display = "block";
}
function show_div(id, e)
{
  if (document.all)
		var e=event;
	var el=document.getElementById(id);
	el.style.left=document.body.scrollLeft+e.clientX+1;
	el.style.top=document.body.scrollTop+e.clientY+1;
	el.style.display="block";
}
function hide_div(id)
{
	var el=document.getElementById(id);
	el.style.display="none";
}
