// JavaScript Document
var old_menu = 1; //home page
var tab_sel=1;

function set_tab(num, count) 
{
//alert(num);
	// spegne tutto
	for (i=1;i<=count;i++) {
		a=document.getElementById("f_"+i);
		if (a)a.style.display='none';

		// l'angoletto
		a=document.getElementById("tangle_"+i);
		if (i==1)
			a.className='tab_angle_unselected';
		else
			a.className='tab_medlolo';

		// il testo			
		a=document.getElementById("tlabel_"+i);
		a.className='tab_unselected';
	}
	// spegne l'angoletto finale
	a=document.getElementById("tangle_"+(count+1));
	a.className='tab_angledx_unselected';

	// accende il riquadrino	
	//alert(num);
	a=document.getElementById("f_"+num);
	if (a)a.style.display='';
	
	// l'angoletto della cella 
	a=document.getElementById("tangle_"+num);
	if (num==1)
		a.className='tab_angle_selected';
	else
		a.className='tab_medlohi';

	// l'angoletto della cella a destra
	a=document.getElementById("tangle_"+(num+1));
	if (num==count)
		a.className='tab_angledx_selected';
	else
		a.className='tab_medhilo';

	a=document.getElementById("tlabel_"+num);
	a.className='tab_selected';
	tab_sel=num;
}

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 menu_sel(id_menu)
{
//alert(id_menu);
//alert(old_menu);
	var menu=document.getElementById("menu_"+id_menu);
	var menu_old=document.getElementById("menu_"+old_menu);
	menu.style.backgroundImage="url('../images/button_menu_sel.gif')";
//	menu_old.style.backgroundImage="url('../images/button_menu.gif')";
	old_menu=id_menu;
}
function menu_unsel(id_menu)
{
	var menu=document.getElementById("menu_"+id_menu);
	menu.style.backgroundImage="url('../images/button_menu.gif')";
}
function apri(m)
{
    document.getElementById(m).style.visibility = "Visible";
}
// CHIUDO IL MENU ...
function chiudi(m)
{
    document.getElementById(m).style.visibility = "Hidden";
}

