//*******************************************************
//                ROUTINE JAVASCRIPT
//*******************************************************
 
 
  //Per la visualizzazione del giorno della settimana
  function VisGiorno(g) {
    switch (g) {
      case 0: return ('Domenica'); 
      case 1: return ('Lunedì'); 
      case 2: return ('Martedì'); 
      case 3: return ('Mercoledì');
      case 4: return ('Giovedì');
      case 5: return ('Venerdì');
      case 6: return ('Sabato');
    }
  }
    
  //Per la visualizzazione il mese dell'anno
  function VisMese(m) {
    switch (m) {
      case 1: return ('Gennaio'); 
      case 2: return ('Febbraio'); 
      case 3: return ('Marzo'); 
      case 4: return ('Aprile');
      case 5: return ('Maggio');
      case 6: return ('Giugno');
      case 7: return ('Luglio');
      case 8: return ('Agosto');
      case 9: return ('Settembre');
      case 10: return ('Ottobre');
      case 11: return ('Novembre');
      case 12: return ('Dicembre');
    }
  }
  
  // Calcola l'anno con 4 cifre
  function FourDigits(number)	{
    return (number < 1000) ? number + 1900 : number;
  }
 
  //Visualizza data in formato gg/mm/aaaa
  function DTOS(dta) {
    return dta.getDate()+'/'+(dta.getMonth()+1)+'/'+FourDigits(dta.getYear());
  }
 
  //Controlla campo se formato data gg/mm/aaaa
  function STOD(str)
  {
    var g,m,a;
  
	arr=str.split("/");
    g=parseInt(arr[0]);
    m=parseInt(arr[1]);
    a=parseInt(arr[2]);

	return SetDate(g,m,a);
  }
 
  //Restituisce la data col mese,giorno,anno impostato
  function SetDate(gg,mm,aa) {
    var dta = new Date();
 
    dta.setDate(gg);
    dta.setMonth(mm-1);
    dta.setFullYear(aa);
    return dta;
  }  
 
  //Restituisce l'ultimo giorno del mese della data passata
  function EOM(m,a)
  {
    if (m==4 || m==6 || m==9 || m==11) return 30;
    if (a%4==0 && m==2) return 29; 
    if (a%4!=0 && m==2) return 28; 
    return 31;
  }
 
  //Controlla campo se formato data gg/mm/aaaa
  function isData(e,req)
  {
    var d,g,m,a,arr,msg;
  
    d=e.value;
    if ( (req==false) && d=='') return true;
	
	arr=d.split("/");
    g=parseInt(arr[0]);
    m=parseInt(arr[1]);
    a=parseInt(arr[2]);
  
    msg="";
    if (isNaN(a) || a<1900 || a>2050)
      msg='Anno valido solo se compreso tra 1900 e 2050';
    else if (isNaN(m) || m<1 || m>12)
      msg='Mese non valido';
    else if (isNaN(g) || g<0 || g>EOM(m,a))
      msg='Giorno non valido';
    
    if (msg!='')
    {
      alert(msg);
      e.select();
	  return false;
    }
	return true;
  }
 
  //Controlla campo se numerico 
  function isDigit(e,tipo,da,a)
  {
    var v;
 
    if (e.value=="") return;
    if (tipo=='I') 
      v=parseInt(e.value);
    else
      v=parseFloat(e.value);
 
    if (isNaN(v)) 
    {
      alert('Numero non valido');
      e.value=0;
      e.select();
	  return false;
    }
    else if ((da!=0 || a!=0) && (v<da || v>a))
    {
      alert('Numero compreso tra '+da+' e '+a);
      e.value=0;
      e.select();
	  return false;
    }
    else
      e.value=v;
	  return true;
  }
 
  //Controlla campo se alfanumerico
  function isAlphanum(e,req)
  {
    var s,c,i,Lett,Spec,Num,Match;
 
    Lett='ABCDEFGHIJKLMNOPQRSTUVWXYZ ';
    Spec='!£$&/()=?^*-_+.,<>|@'+'\x5C';
    Num='0123456789';
  
    Match=Lett+Spec+Num;
  
    s=e.value.toUpperCase();
    if ( (req==false) && s=='') return true;
    if ( (req==true) && s=='')
    {
	  alert('Campo obbligatorio mancante');
	  e.select();
	  return false;
	}	
  
    for (i=0;i<s.length;i++)
    {
      c=s.charAt(i);
      if (Match.indexOf(c)<0)
      {
        alert(c+': carattere non valido');
        e.select();
    	return false;
      }
    
    }
    return true;
  }

  //Controlla campo se alfanumerico
  function isAlphabetic(e,req)
  {
    var s,c,i,Match;
 
    Match='ABCDEFGHIJKLMNOPQRSTUVWXYZèàòùì ';
  
    s=e.value.toUpperCase();
    if ( (req==false) && s=='') return true;
    if ( (req==true) && s=='')
    {
	  alert('Campo obbligatorio mancante');
	  e.select();
	  return false;
	}	
 
    for (i=0;i<s.length;i++)
    {
      c=s.charAt(i);
      if (Match.indexOf(c)<0)
      {
        alert(c+': carattere non valido');
        e.select();
    	return false;
      }
    
    }
	return true;
  }
  
  //Controlla campo se telefono
  function isTel(e,req)
  {
    var s,c,i,Match;
  
    Match='0123456789/';
  
    s=e.value.toUpperCase();
    if ( (req==false) && s=='') return true;
    if ( (req==true) && s=='')
    {
	  alert('Campo obbligatorio mancante');
	  e.select();
	  return false;
	}	
 
    for (i=0;i<s.length;i++)
    {
      c=s.charAt(i);
      if (Match.indexOf(c)<0)
      {
        alert(c+': carattere non valido');
        e.select();
    	return false;
      }
    
    }
	return true;
  }

  //Controlla campo se email
  function isEmail(e,req)
  {
    var s,c,i,Match;
  
    Match='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_-.@';
  
    s=e.value.toUpperCase();
    if ( (req==false) && s=='') return true;
    if ( (req==true) && s=='')
    {
	  alert('Campo obbligatorio mancante');
	  e.select();
	  return false;
	}
  
    for (i=0;i<s.length;i++)
    {
      c=s.charAt(i);
      if (Match.indexOf(c)<0)
      {
        alert(c+': carattere non valido');
        e.select();
    	return false;
      }
    
    }
	
   if ( s.indexOf ('@',0) == -1 || s.indexOf ('.',0) == -1 )
      {
      alert("Indirizzo E-mail non valido.")
        e.select();
    	return false;
	  }
	
	return true;
  }

  //Controlla campo se tipo UserId o Password
  function isPassw(e,req)
  {
    var s,c,i,Match;
 
    Match='ABCDEFGHIJKLMNOPQRSTUVWXYZ-_@!£$*0123456789';
  
    s=e.value.toUpperCase();
    if ( (req==false) && s=='') return true;
    if ( (req==true) && s=='')
    {
	  alert('Campo obbligatorio mancante');
	  e.select();
	  return false;
	}	
  
    for (i=0;i<s.length;i++)
    {
      c=s.charAt(i);
      if (Match.indexOf(c)<0)
      {
        alert(c+': carattere non valido');
        e.select();
    	return false;
      }
    
    }
    e.value=s;
    return true;
  }

  //Per il cambio di immagini durante il passaggio del Mouse Over
  function onImgOn(n)
  {
    var f,p;
    f=document.images[n].src.toUpperCase();
    p=f.indexOf('OFF.GIF');
    if (p>0) {
      f=f.substring(0,p)+'ON.GIF';
      document.images[n].src=f;
    }
  }
  
  //Per il cambio di immagini durante il passaggio del Mouse Out
  function onImgOff(n)
  {
    var f,p;
    f=document.images[n].src.toUpperCase();
    p=f.indexOf('ON.GIF');
    if (p>0) {
      f=f.substring(0,p)+'OFF.GIF';
      document.images[n].src=f;
    }
  }  
 
  //Aggiungi a preferiti
  function AddPrefer(bookmarkurl,bookmarktitle)
  {
    if (document.all)
      window.external.AddFavorite(bookmarkurl,bookmarktitle)
  }
 
  //Open Window per links
  function OpenWinLink(L)
  {
    window.open(L,'Link','height=400,width=600,resizable=1,scrollbars=1');
  }
 
  //Mostra data in formato esteso
  function DataEstesa(d)
  {
    var s;
    s=VisGiorno(d.getDay())+','+d.getDate()+' '+VisMese(d.getMonth()+1)+' '+d.getFullYear();
    return s;
  }