// JavaScript Document
/*
LINK srl: 31/10/2003 - util.js - procedure e funzioni di utilità 
elenco layout: mostraOnOff, mostraOnOffplus, mostra_img, mostra_imgplus, cambia_div, openwin, apri,
MM_swapImgRestore, MM_findObj, MM_swapImage
elenco stringhe: cambia, formatta, trimLeadingBlanksCrLf, blanksToblank, LtrimBlanks, clearBlank, LtrimChars, replaceCar
allStrOK, allnumber, allnumeriOK, eurocifreOK, eurolettereOK 
elenco campi form: seleziona, as_gg, disabilita, sel_tutti, mod_tutti, verifica_selezione1, riempi_op, valida_numero, leggi_form,
verifica_ricerca, valida_data, GetDateDiff, checkdate, chkdate, LeapYear, verifica_anno
elenco funzioni layout: vistaHTML, saltapagxstampa, colorAOn, colorAOff, colorBOn, colorBOff, colorAAOn, colorAAOff, colorBBOn, colorBBOff, bordocontent
*/

// INIZIO FUNZIONI di layout
// funzione che mostra o nasconde una sezione di pagina utilizzando STYLE.DISPLAY
function mostraOnOff (v_ele) {
	var i;
	if (v_ele.length == 1) {
	   if (document.getElementById(v_ele[0]).style.display=='block') document.getElementById(v_ele[0]).style.display='none'
	   else document.getElementById(v_ele[0]).style.display='block'
	}
	else {
	  if (document.getElementById(v_ele[0]).style.display=='block') {
		 for (i=0; i < v_ele.length; i++) document.getElementById(v_ele[i]).style.display='none'
	  }
      else {
		    document.getElementById(v_ele[0]).style.display='block';
	        document.getElementById(v_ele[1]).style.display='block';
	        for (i=2; i < v_ele.length; i++) document.getElementById(v_ele[i]).style.display='none'
	  }
	}
  }

// funzione che mostra o nasconde una sezione di pagina utilizzando STYLE.DISPLAY 
  function mostraOnOffplus (v_ele,v_pos) {
	  var i;
	  if (document.getElementById(v_ele[0]).style.display=='block') {
		 for (i=0; i < v_ele.length; i++) document.getElementById(v_ele[i]).style.display='none'
	  }
      else {
	     for (i=0; i < v_ele.length; i++) document.getElementById(v_ele[i]).style.display='none'
	     for (i=0; i < v_pos.length; i++) document.getElementById(v_pos[i]).style.display='block'
	  }
  }

// funzione esegue un cambiamento di img
function mostra_img (n_ele,vettore) {
   var p1, n_img = document.getElementById(n_ele).src;
   if (mostra_img.arguments.length == 2) p1=''
   else p1=mostra_img.arguments[2]
   if(n_img.indexOf('frecciagiu') > -1) {
	  document.getElementById(n_ele).setAttribute('src',p1+'images/frecciadxoff.gif');
	   vettore[parseInt(n_ele.slice(1))]='frecciadx'
   }
   else {
	   document.getElementById(n_ele).setAttribute('src',p1+'images/frecciagiuoff.gif');
	   vettore[parseInt(n_ele.slice(1))]='frecciagiu'
   }
  }
  
// funzione esegue un cambiamento di più img
function mostra_imgplus (v_ele,vettore) {
	var i, k;
	for (i = 0; i < v_ele.length; i++) {
		k=parseInt(v_ele[i][0].slice(1));
        if (v_ele[i][1]) vettore[k]='frecciadx'
        else vettore[k]='frecciagiu'
        document.getElementById(v_ele[i][0]).setAttribute('src','images/' + vettore[k] +'off.gif')
	}
}
 
 // funzione che mostra/nasconde div utilizzando STYLE.DISPLAY
function cambia_div (flag,p,f,f1) {
//gestione delle etichette e delle schede	
  if ((flag == 0) || (flag == 2)) {
	  f.value=p+1;
	 // f1.value=p+1;
  }
  else {
	  f.value=p-1;
	 // f1.value=p-1;
  }
  p=f.value-1;
  for (var i=0; i < 7; i++) {
	   document.getElementById('etichetta'+i).style.display='none';
       document.getElementById('scheda'+i).style.display='none'
  }
  document.getElementById('etichetta'+p).style.display='block';
  document.getElementById('scheda'+p).style.display='block';
  
//gestione delle barra di stato della scheda  
  document.getElementById("submenuSx1").style.display='none';
  document.getElementById("facsimile").style.display='none';
  document.getElementById("verifica").style.display='none';
  document.getElementById("abbandona").style.display='none';
  
  if ((p > 0) && (p < 6))  {
	 // document.getElementById("submenuDx").style.display='block';
	  document.getElementById("indietro0").className='bottonescheda';
	  document.getElementById("avanti0").className='bottonescheda';
	  document.getElementById("indietro0").disabled='';  
	  document.getElementById("avanti0").disabled='';
	  document.getElementById("indietro0").title='mostra la sezione ' + sezioni[p-1];
	  document.getElementById("avanti0").title='mostra la sezione ' + sezioni[p+1];
	  document.getElementById("facsimile").style.display='inline';
	  document.getElementById("verifica").style.display='inline';
	  document.getElementById("abbandona").style.display='inline';
  }		  	
  else {
	  if (p == 0) {
		 document.getElementById("indietro0").className='bottoneschedaoff';
		 document.getElementById("avanti0").className='bottonescheda';
		 document.getElementById("indietro0").disabled='disabled'; 
		 document.getElementById("indietro0").title='';
	     document.getElementById("avanti0").title='mostra la sezione ' + sezioni[p+1];
		 document.getElementById("facsimile").style.display='inline';
	  }
	  else {
		 document.getElementById("indietro0").className='bottonescheda';
		 document.getElementById("avanti0").className='bottoneschedaoff';
		 document.getElementById("indietro0").disabled='';  
		 document.getElementById("avanti0").disabled='disabled';
		 document.getElementById("indietro0").title='mostra la sezione ' + sezioni[p-1];
	     document.getElementById("avanti0").title='';
	     document.getElementById("facsimile").style.display='inline';
	     document.getElementById("verifica").style.display='inline';
	     document.getElementById("abbandona").style.display='inline';
	  }
  }
  document.getElementById("submenuSx1").style.display='block'
}


// funzione di apertura di una nuova finestra
function openwin (theurl,scroll,larga,alta) {
	closewin();
    var features = 'toolbar=no,location=no,resizable=no,scrollbars='+ scroll + ',status=0,width='+ larga + ',height=' + alta + ',innerWidth=' + larga +',innerHeight=' + alta + ',top=20,left=20,screenX=20,screenY=20'; 
    finestra=window.open(theurl,'finestra',features);
    finestra.focus()
}

// funzione di chiususra di una nuova finestra
function closewin() {
    if (finestra != undefined) finestra.close()
}

//funzione di apertura di una nuova finestra da onsubmit (utlizzando una form)
function apri(form,car,nome) { 
   if (!nome) 
      nome = 'aa' + (new Date().getTime()); 
      form.target = nome; 
      open ('', nome, car); 
} 

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_findObj(n, d) { //v4.01
  var i,p,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
   var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// FINE FUNZIONI di layout


// INIZIO FUNZIONI che operano su stringhe  
// funzione che se il campo è vuoto riporta la scritta di base
  function cambia (f,v,flag) {
	formatta(f,flag);
	if (f.value.length == 0) f.value = v
  }
    
/* funzione che formatta un campo di testo togliendo gli spazi bianchi e CrLf all'inizio e alla fine
e sostituendo più spazi bianchi con un solo spazio bianco */
   function formatta (f,flag) {
     trimLeadingBlanksCrLf(f);
     blanksToblank(f);
	 if (flag && (f.value.length > 0)) f.value=f.value.charAt(0).toUpperCase()+f.value.slice(1)
   }

//funzione che toglie gli spazi bianchi e gli CrLf all'inizio e alla fine di un campo di testo
  function trimLeadingBlanksCrLf(f) {
//toglie i blank e i CrLf all'inizio
    var i, carat;
    if (f.value.length > 0) {
	   for (i=0; i < f.value.length; i++) {
		   carat=f.value.charAt(i);
		   if ((carat != ' ') && (carat != '\r') && (carat != '\n') && (carat != '\t')) {
			   f.value=f.value.slice(i);
		       break
		   }
	   }
	   if (i==f.value.length) f.value='';
	}
//toglie i blank e CrLf alla fine
    if (f.value.length > 0) {
	   for (i=f.value.length-1; i > -1; i--) {
		   carat=f.value.charAt(i);
		   if ((carat != ' ') && (carat != '\r') && (carat != '\n') && (carat != '\t')) {
			   f.value=f.value.slice(0,i+1);
		       break
		   }
	   }
	}
  }


//funzione che sostituisci più spazi bianchi con uno spazio bianco
  function blanksToblank(f){
	var firstBlank, lastBlank, newstr, tmpstr, iBlank;
    if (f.value.length > 0) {
       firstBlank = f.value.indexOf(' ');
       lastBlank = f.value.lastIndexOf(' ');
       if (firstBlank < lastBlank) {
          newstr = '';
     	  tmpstr = f.value;
          iBlank = firstBlank;
     	  while (iBlank > 0) { 
     	        newstr = newstr + tmpstr.substring(0,iBlank);
     	        tmpstr = LtrimBlanks(tmpstr.substring(iBlank,tmpstr.length));
     	        newstr = newstr + ' ';
     	        iBlank = tmpstr.indexOf(' ');
     	  }
          newstr = newstr + tmpstr;
          f.value = newstr
       }
    }
  }

//funzione che toglie gli spazi bianchi all'inizio di una stringa
  function LtrimBlanks(str) {
//toglie i blank
    var carat;
    if (str.length > 0) {
       carat=str.charAt(0);	
       while (carat == ' ' ) {

             str = str.substring(1,str.length);	
             carat = str.charAt(0)
       }
    }
   return str
  }
  
//funzione che togli tutti gli spazi bianchi
  function clearBlank(f) {
   var firstBlank, lastBlank, newstr, tmpstr, iBlank;
    if (f.value.length > 0) {	
       firstBlank = f.value.indexOf(' ');
       lastBlank = f.value.lastIndexOf(' ');
       if (firstBlank < lastBlank) {
          newstr = '';
     	  tmpstr = f.value;
          iBlank = firstBlank;
     	  while (iBlank > 0) { 
     	        newstr = newstr + tmpstr.substring(0,iBlank);
     	        tmpstr = LtrimBlanks(tmpstr.substring(iBlank,tmpstr.length));
     	        iBlank = tmpstr.indexOf(' ')
     	  }
          newstr = newstr + tmpstr;
          f.value = newstr
       }
    }
  }
  
//funzione che toglie un determinato carattere all'inizio di una stringa
  function LtrimChars(str,c) {
//toglie i blank
    var carat;
    if (str.length > 0) {
       carat=str.charAt(0);	
       while (carat == c ) {
             str = str.substring(1,str.length);	
             carat = str.charAt(0)
       }
    }
    return str
  }
  
// funzione che verifica che il campo di testo sia composto caratteri compresi nella stringa assegnata
  function allStrOK(val,strOK) {
     for (var i = 0;  i < val.length; i++) {
	     if (strOK.indexOf(val.charAt(i)) == -1) return false
     }
     return true
  } 

function allnumber(ff,p,l) {
   formatta(ff,false);	
   if(allnumeriOK(ff.value,p)) {
	  if(ff.value.length < l) {
		alert('ATTENZIONE!\r\nIl numero deve essere composto da ' + l + ' cifre.');
	    ff.focus();
	    return false
	  }
   }
   else {
	   ff.focus();
	   return false
   }
   return true
}

// funzione che verifica che il campo di testo sia numerico
  function allnumeriOK(str,ispositivo) {
	if (str.length == 0) return false
    if (isNaN(str)) {
		alert('ATTENZIONE!\r\nDigitare solo cifre.');
		return false
    }
    if(ispositivo) {
	   if (str < 0) {
		   alert('ATTENZIONE!\r\nDigitare solo numeri positivi.');
		   return false
	   }
	}
    return true 
}

// funzione che verifica che il campo EURO in cifre sia scritto correttamente
  function eurocifreOK(f,strOK,c,q,v) {
	var pos;  
    trimLeadingBlanksCrLf(f);
	if (f.value != v) {
       if (f.value.length > 0) {
		  clearBlank(f);
	      pos = f.value.indexOf(c);
		  if (!allStrOK(f.value.slice(0,pos),strOK) || !allStrOK(f.value.slice(pos+1),strOK)) {
             alert ('ATTENZIONE!\r\nBisogna digitare solo cifre separate da una sola \" , \".');
	         f.focus();
			 f.select();
	         return false
          }
	      if (pos == -1) {
		     alert ('ATTENZIONE!\r\nMancano le 2 cifre decimali (\" , \" mancante).');
	         f.focus();
			 f.select();
	         return false
	      }
          if (pos!=f.value.length-q) {
             alert ('ATTENZIONE!\r\nLe cifre decimali devono essere 2 (\",\" in posizione sbagliata)');
	         f.focus();
			 f.select();
	         return false
          }
       }
       else f.value=v
	}
    return true
  }
  
  // funzione che verifica che il campo EURO in lettere sia scritto correttamente
  function eurolettereOK(f,strcOK,strlOK,c,q,v) {
    trimLeadingBlanksCrLf(f);
	if (f.value != v) {
       clearBlank(f);
       if (f.value.length > 0) {
	      f.value=f.value.toLowerCase();
	      pos = f.value.indexOf(c);
	      if (pos == -1) {
		     alert ('ATTENZIONE!\r\nCarattere \"'+ c + '\" mancante');
	         f.focus();
			 f.select();
	         return false
	      }
          if (pos < f.value.lastIndexOf(c)) {
             alert ('ATTENZIONE!\r\nCarattere \" '+ c + ' \" ripetuto.');
	         f.focus();
			 f.select();
	         return false
          }
	      if (pos!=f.value.length-q) {
             alert ('ATTENZIONE!\r\nIl carattere \" '+ c + ' \" non occupa la posizione giusta.');
	         f.focus();
			 f.select();
	         return false
          }
	      ftmp=f.value.slice(0,pos);
          if (!allStrOK(ftmp,strlOK)) {
             alert ('ATTENZIONE!\r\nDigitare solo lettere.');
	         f.focus();
			 f.select();
	         return false
          }
	      ftmp=f.value.slice(pos+2);
          if (!allStrOK(ftmp,strcOK)) {
             alert ('ATTENZIONE!\r\nDigitare solo numeri.');
	         f.focus();
			 f.select();
	         return false
          }
       }
       else f.value=v
	}
    return true
  }
  
  function replaceCar(str,oldCar,newCar) {
   var iCar, firstCar, lastCar, tmpnewstr, tmpstr, carat;
   firstCar = str.indexOf(oldCar);
   lastCar = str.lastIndexOf(oldCar);
   if (firstCar <= lastCar)
   {
      tmpnewstr = '';
      tmpstr = str;
      iCar = firstCar;
      while (iCar >= 0)
      { 
     	 tmpnewstr = tmpnewstr + tmpstr.substring(0,iCar) + newCar;
     	 if (tmpstr.charAt(iCar+1) == '\n')
     	 {
     	    tmpstr = tmpstr.substring(iCar+2,tmpstr.length)
     	 }
     	 else
     	 {
     	    tmpstr = tmpstr.substring(iCar+1,tmpstr.length)
         }
     	 iCar = tmpstr.indexOf(oldCar);
      }
      return tmpnewstr + tmpstr
    }
    return str
}

  
// FINE FUNZIONI che operano su stringhe


// INIZIO FUNZIONI che operano su campi di una form
// funzione che seleziona il testo contenuto in campo di testo quando il focus si sposta in tale campo
  function seleziona (f,v) {
	if (f.value == v) f.select()
  }

//funzione che assegna ad una variabile globale l'indice del radio button selezionato nell'ambito di un insieme
function as_gg(f) {
	    if (isNaN(f.length)) {
		   if (f.checked) {
	        return 0
		   }
		}
		else {
		  for (var j=0; j<f.length; j++) {
		   if (f[j].checked) {
	          return j
		   }
		}
	}
return -1
}

//funzione che consente di disattivare un radio button già selezionato senza doverne selezionare un altro nell'ambito di un insieme
function disabilita(f,i) {
	if (isNaN(f.length)) {
		if ((f.checked) && (i==radio_index)) {
	        f.checked=!f.checked;
		}
	}
    else {

	   for (var j=0; j<f.length; j++) {
		   if ((f[j].checked) && (i==radio_index)) {
			  f[j].checked=!f[j].checked;
			  break
		   }
	   }
	}
}

// funzione che (de)seleziona tutti i checkbox di uno stesso insieme a seconda che un checkbox esterno sia (de)selezionato
function sel_tutti(f,f1) {
   if (f.length>0) {
       for (var i=0;i<f.length;i++) f[i].checked=f1.checked
   }
   else {
	  f.checked=f1.checked
   }
}

// funzione che resetta un checkbox in base al valore di un altro o di (un insieme) di checkebox
function mod_tutti(f,f1) {
	var i;
	if (f.length>0) {
	   for (i=0;i<f.length;i++) {
		 if (!f[i].checked) {
			 f1.checked=false;
			 break
		 }
	   }
	   if (i==f.length) f1.checked=true
	 }
	 else {
	   f1.checked=f.checked
	 }
}

//funzione che verifica che almeno un elemento nell'insieme "f" sia selezionato
function verifica_selezione1(f) {
	var numero=0
    if (!f.length>0) {
		if (f.checked==true) numero++;
	  }
	 else { 
	   for (var i=0; i<f.length;i++) {
		  if (f[i].checked==true) numero++
	     }
	  }
    if (numero==0)  {
		alert('ATTENZIONE!\r\nBisogna selezionare almeno una scheda di progetto.');
        return false
	}
    return true
}

// funzione per riempire una option list con gli elementi di un array semplice (valore e d etichetta sono uguali)
function riempi_op(vettore,flag) {
   if (flag==0) vettore.sort();
   for (var i=0;i<vettore.length;i++) {
        document.write('<option value="'+vettore[i]+'">&nbsp;&nbsp;&nbsp;'+vettore[i]+'</option>')
   }
}

// funzione che verifica che il campo di testo "f" per la form numero "nf" sia composto da determinati valori e sia compreso nell'intervallo e1 <= f <= e2
  function valida_numero (f,e1,e2) {
    formatta(f,0)
    if (f.value.length==0) {
        f.form.reset()
        return false
    } 
    if (! isNaN(f.value)) {
        f.value = parseInt(f.value);
        if (f.value < 1) {
            alert('ATTENZIONE!\r\nIl valore digitato non pu'+unescape('%F2')+' essere minore di '+1+'.');
           f.form.reset();
            return false
        } 
        if (f.value > e2) {
            alert('ATTENZIONE!\r\nIl valore digitato non pu'+unescape('%F2')+' essere maggiore di '+e2+'.');
            f.form.reset();
            return false
        } 
    }
    else {
        alert ('ATTENZIONE!\r\nDigitare solo cifre.')
        f.form.reset();
        return false
    }
    return true
  }
  
  //funzione che assegna da sistema i dati in una form e la invia al server
function leggiform(f,v) {
	f.asNp.value=v;
	f.submit();
	return true
}

function verifica_ricerca(f,t) {
	var elemento, valore, nofiltro=false;
	if ((t==11) && (f.cis.options[f.cis.selectedIndex].value == '') && (f.anno.options[f.anno.selectedIndex].value == '') && (f.stato.options[f.stato.selectedIndex].value == '') & (f.orgint.options[f.orgint.selectedIndex].value == '') && (f.orgest.options[f.orgest.selectedIndex].value == '') && (f.ateco.options[f.ateco.selectedIndex].value == '') && (f.prodotto.options[f.prodotto.selectedIndex].value == '')) nofiltro=true
	valore=f.testo.value;
	elemento = /[,?!;:()]/g;
	valore=valore.replace(elemento,'');
	f.testo.value=valore;
    formatta(f.testo,false);
    if ((t==11) && (f.testo.value.length == 0) && nofiltro) {
		alert('ATTENZIONE!\r\Bisogna digitare parole composte da almeno 3 caratteri e/o scegliere un filtro.');
        return false
	}
	if ((t==11) && (f.testo.value.length == 0) && !nofiltro) return true
	if (f.testo.value.length < 3) {
	    alert('ATTENZIONE!\r\nBisogna digitare parole composte da almeno 3 caratteri.');
	    return false
	}
	return true
}	
// FINE FUNZIONI che operano su campi di una form

function saltapagxstampa(ff,vmin,vmax) {
  if (ff[1].checked) for (var i=vmin;i<vmax;i++)  document.getElementById('s'+i).style.pageBreakBefore='always'
  window.print();
  window.close()
}

function colorAOn(v) {
	document.getElementById('livA'+v).style.color='#ff0000';
}

function colorAOff(v) {
	document.getElementById('livA'+v).style.color='';
}

function colorBOn(v) {
	document.getElementById('livB'+v).style.color='#ff0000';
}
function colorBOff(v) {
	document.getElementById('livB'+v).style.color='';
}
function colorAAOn(v) {
	document.getElementById('livAA'+v).style.color='#ff0000';
}

function colorAAOff(v) {
	document.getElementById('livAA'+v).style.color='';
}

function colorBBOn(v) {
	document.getElementById('livBB'+v).style.color='#ff0000';
}
function colorBBOff(v) {
	document.getElementById('livBB'+v).style.color='';
}

// INIZIO - funzioni per gestire le date

// funzione che verifica se la data "f1" è valida
function valida_data(f1,f2) {
   formatta(f1,false)
   if (! checkdate(f1)) {
      return false
   }   
   if (f1.name == 'dataini') {
	   if (f1.value.length==0) {
		  return false
	   } 
	   if (GetDateDiff(f1.value,f2.value) == 0) {
		   alert('ATTENZIONE!\r\nLe due date non possono coincidere.');
           f1.value="";
		   f1.focus();
           return false
       }
       if (GetDateDiff(f1.value,f2.value) >= 1) {
		   alert('ATTENZIONE!\r\nLa data di inizio non pu'+ unescape('%F2') +' essere posteriore alla data di fine.');
           f1.value="";
		   f1.focus();
           return false
       }
   } 
   else {
	   if (f1.value.length==0) {
		  return false
	   }  
	   if (GetDateDiff(f1.value,f2.value) == 0) {
		   alert('ATTENZIONE!\r\nLe due date non possono coincidere.');
           f1.value="";
		   f1.focus();
           return false
       }
       if (GetDateDiff(f1.value,f2.value) < 0) {
           alert('ATTENZIONE!\r\nLa data di fine non pu'+ unescape('%F2') +' essere anteriore alla data di inizio.');
		   f1.value="";
		   f1.focus();
           return false
       }
   }
   return true
 } 
 
// funzione che calcola e riporta la differenza fra due date
  function GetDateDiff(date1,date2) {
    var v_data1=date1.split('/');
    var v_data2=date2.split('/');
    date1_ms=new Date(Date.UTC(v_data1[2],v_data1[1]-1,v_data1[0]));
    date2_ms=new Date(Date.UTC(v_data2[2],v_data2[1]-1,v_data2[0]));
    var result=parseInt(date1_ms.getTime() - date2_ms.getTime());
    result=(result/1000)/60/60/24;
    return result
  }

// funzione che riporta messaggio d'errore se la data immessa non è rappresentata in un formato valido
  function checkdate(objName) {
     if (!chkdate(objName)) {
         alert('ATTENZIONE!\r\nLa data non ha un formato valido.');
         objName.focus();
         return false
     }
     return true
  }

// funzione che verifica la validità della data immessa
  function chkdate(objName) {
    var strDate;
    var strDateArray;
    var strDay = '';
    var strMonth = '';
    var strYear = '';
    var intday;
    var intMonth;
    var intYear;
    var booFound = false;
    var strSeparatorArray = new Array("-","/",".");
    var intElementNr;
    var err = 0;
    strDate = objName.value;
    if (strDate.length < 1) {
        return true
    }
    for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
       if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
           strDateArray = strDate.split(strSeparatorArray[intElementNr]);
           if (strDateArray.length != 3) {
               err = 1;
               return false
           }
           else {
               strDay = strDateArray[0];
               strMonth = strDateArray[1];
               strYear = strDateArray[2];
           }
           booFound = true
       }
    }
    if (booFound == false) {
        if (strDate.length>5) {
            strDay = strDate.substr(0, 2);
            strMonth = strDate.substr(2, 2);
            strYear = strDate.substr(4);
        }
    }
    if (strYear.length == 2) {
        strYear = '20' + strYear;
    }
	if (strYear.length != 4) {
        return false
    }

	
    intday = parseInt(strDay, 10);
    if (isNaN(intday)) {
        err = 2;
        return false;
    }
    intMonth = parseInt(strMonth, 10);
    if (isNaN(intMonth)) {
        err = 3;
        return false;
    }
    intYear = parseInt(strYear, 10);
    if (isNaN(intYear)) {
        err = 4;
        return false;
    }
    if (intMonth>12 || intMonth<1) {
        err = 5;
        return false;
    }
    if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
         err = 6;
         return false;
    }
    if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
        err = 7;
        return false;
    }
    if (intMonth == 2) {
        if (intday < 1) {
            err = 8;
            return false;
        }
        if (LeapYear(intYear) == true) {
            if (intday > 29) {
                err = 9;
                return false;
            }
        }
        else {
            if (intday > 28) {
                err = 10;
                return false;
            }
        }
    }
    objName.value = intday + "/" + intMonth + "/" + intYear;
    return true;
  }

function LeapYear(intYear) {
  if (intYear % 100 == 0) {
      if (intYear % 400 == 0) { return true; }
  }
  else {
      if ((intYear % 4) == 0) { return true; }
  }
  return false;
}

function verifica_anno(f,v) {
	formatta(f,false)
	if (f.value.length == 0) f.value = v
	else {
		if (f.value != v) {
		   if (allStrOK(f.value,'0123456789')) {
			  if (f.value.length < 4) {
				 alert('ATTENZIONE!\r\nL\'anno deve essere composto da 4 cifre.');
				 f.focus()
			  }
		   }
		   else {
		      alert('ATTENZIONE!\r\nL\'anno deve essere composto solo da cifre.');
		      f.focus()
		   }
		}
	}
}

// FINE - funzioni per gestire le date

function bordocontent(par1,par2) {
   //if (navigator.userAgent.indexOf('Netscape') == -1) {
	   var altezza=document.getElementById(par1[0]).offsetHeight;
	   for (var i=1; i<par1.length; i++) altezza = Math.max(altezza,document.getElementById(par1[i]).offsetHeight)
	   document.getElementById(par2).style.height=altezza+'px'
   //}
}



// variabili di uso globale
var whilef;	
var radio_index=-1;	
var img1=new Array();
var finestra;





