// Funzione che elimina gli spazi dal valore dei campi di una form
function Strip(string) {
   var s_str = string.length
   for (var i=0; i<string.length; i++) {
      if (" " != string.substring(i,i+1)) {
         s_str = i;
         break;
      }
   }
   if (s_str == string.length) {
      return "";
   }
   for (i=string.length-1; i>=0; i--) {
      if (" " != string.substring(i,i+1)) {
         var s_end = i;
         break;
      }
   }
   return string.substring(s_str,s_end+1);
}


// Funzione di pausa che rimanda alla home (../index.asp)
function pausa(secondi) {
   var tempoattesa = setTimeout("location.href='../index.asp'", secondi*1000)
}


// Funzione che rimanda all' URL specificato
function go(sel) {
         document.location.href=sel[sel.selectedIndex].value
}


// Funzione che apre una nuova finestra personalizzata
function popup(nomefile, larghezza, altezza, x, y) {
   win_popup = window.open(nomefile,"popup","toolbar= 0,location= 0,directories= 0,status= 0,menubar= 0,scrollbars= 1,resizable= 0,copyhistory= 0,width=" + larghezza + ",height=" + altezza); 
   if(x && y); {
     x = parseInt(x);
     y = parseInt(y);
     win_popup.moveTo(x, y);
  }
}


// Funzione che consente la stampa di una pagina web
function printit(){  
   var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
   document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
   WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";   
}


// Funzione che effettua tutti i controlli inerenti un campo FLOAT
function controlli_float(campo, DescrizioneCampo) {

   var controllo="-,.0123456789"
   var verifica=0
   var punti_virgole=0
   for (var h=0 ; h<campo.length; h++) {
       variante = campo.substring(h,h+1) 
       for (var u=0 ; u<controllo.length; u++) {
           if (variante != controllo.substring(u,u+1))
              { verifica=1 }
           else
              { 
              if (variante == "." || variante == ",") { punti_virgole=punti_virgole+1; }
			  verifica=0; break
			  }
       }
       if (verifica == 1 || punti_virgole>1) { 
	   alert("Controllare il contenuto del campo " + DescrizioneCampo)
	   return 1
	    }
   }
return 0
}

// Funzione che effettua tutti i controlli inerenti un campo NUMERICO
function controlli_numerico(campo_num, DescrizioneCampo_num, messaggio_num) {

   var controllo_numerico="0123456789"
   var verifica_numerico=0
   for (var s=0 ; s<campo_num.length; s++) {
       variante_numerico = campo_num.substring(s,s+1) 
       for (var t=0 ; t<controllo_numerico.length; t++) {
           if (variante_numerico != controllo_numerico.substring(t,t+1))
              { verifica_numerico=1 }
           else
              { 
			  verifica_numerico=0; break
			  }
       }
       if (verifica_numerico == 1 ) { 
	   alert(messaggio_num + DescrizioneCampo_num)
	   return 1
	    }
   }
return 0
}

// Funzione che effettua tutti i controlli inerenti un campo TESTO
function controlli_testo(campo_tes, DescrizioneCampo_tes, messaggio_tes) {

   var controllo_testo="AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
   var verifica_testo=0
   for (var x=0 ; x<campo_tes.length; x++) {
       variante_testo = campo_tes.substring(x,x+1) 
       for (var z=0 ; z<controllo_testo.length; z++) {
           if (variante_testo != controllo_testo.substring(z,z+1))
              { verifica_testo=1 }
           else
              { 
			  verifica_testo=0; break
			  }
       }
       if (verifica_testo == 1 ) { 
	   alert(messaggio_tes + DescrizioneCampo_tes)
	   return 1
	    }
   }
return 0
}


// Funzione che controlla la validità della data singola
function controlladatasingola(d_data, msg){

// Array che contiene gli errori
err = new Array(18)
err[1]  = "Errore nella " + msg + ": Gennaio ha al massimo 31 giorni  ";
err[2]  = "Errore nella " + msg + ": Febbraio ha al massimo 29 giorni (Anno bisestile)";
err[3]  = "Errore nella " + msg + ": Febbraio ha al massimo 28 giorni (Anno non bisestile)";
err[4]  = "Errore nella " + msg + ": Marzo ha al massimo 31 giorni    ";
err[5]  = "Errore nella " + msg + ": Aprile ha al massimo 30 giorni   ";
err[6]  = "Errore nella " + msg + ": Maggio ha al massimo 31 giorni   ";
err[7]  = "Errore nella " + msg + ": Giugno ha al massimo 30 giorni   ";
err[8]  = "Errore nella " + msg + ": Luglio ha al massimo 31 giorni   ";
err[9]  = "Errore nella " + msg + ": Agosto ha al massimo 31 giorni   ";
err[10] = "Errore nella " + msg + ": Settembre ha al massimo 30 giorni";
err[11] = "Errore nella " + msg + ": Ottobre ha al massimo 31 giorni  ";
err[12] = "Errore nella " + msg + ": Novembre ha al massimo 30 giorni ";
err[13] = "Errore nella " + msg + ": Dicembre ha al massimo 31 giorni ";
err[14] = "Errore nella " + msg + ": Mese errato                      ";
err[15] = "Errore nella " + msg + ": Giorno errato                    ";
err[16] = "Errore nella " + msg + ": Anno errato                      ";
err[17] = msg + " errata: per correggere vedi le indicazioni sul formato";
err[18] = "Inserire la " + msg;

// Inizializza le variabili
data               = d_data
giorno             = data.substring(0,2)
mese               = data.substring(3,5)
anno               = data.substring(6,10)
ultimeduecifreanno = data.substring(8,10)

// Non deve essere vuota
if (data.length == 0 ) { alert(err[18]); return 1 }

// Deve contenere 2 lineette (-), come per la data nel formato italiano
contatore = 0
for (i=0; i<data.length; i++) {
   if (data.charAt(i) == "-") { contatore++ }
}
if ( contatore != 2 ) { alert(err[17]); return 1 }

// Deve essere lunga 10 caratteri (gg-mm-aaaa)
if (data.length != 10) { alert(err[17]); return 1 }

// Controllo se il giorno è valido
if ( giorno == "00" ) { alert(err[15]); return 1 }

// Controllo se il mese è valido
if (parseInt(mese) > 12 || mese == "00") { alert(err[14]); return 1 }

// Controllo se l'anno è valido
if (parseInt(anno) < 1000)  { alert(err[16]); return 1 }

// Controlli sulla correttezza della data inserita
if ( mese == "01" && parseInt(giorno) > 31) { alert(err[1]); return 1  }
if ( mese == "02" && parseInt(giorno) > 29 && ultimeduecifreanno == "00" && parseInt(anno)%400 == 0 ) { alert(err[2]); return 1 }
if ( mese == "02" && parseInt(giorno) > 29 && ultimeduecifreanno != "00" && parseInt(anno)%4   == 0 ) { alert(err[2]); return 1 }
if ( mese == "02" && parseInt(giorno) > 28 && ultimeduecifreanno == "00" && parseInt(anno)%400 != 0 ) { alert(err[3]); return 1 }
if ( mese == "02" && parseInt(giorno) > 28 && ultimeduecifreanno != "00" && parseInt(anno)%4   != 0 ) { alert(err[3]); return 1 }
if ( mese == "03" && parseInt(giorno) > 31) { alert(err[4]); return 1  }
if ( mese == "04" && parseInt(giorno) > 30) { alert(err[5]); return 1  }
if ( mese == "05" && parseInt(giorno) > 31) { alert(err[6]); return 1  }
if ( mese == "06" && parseInt(giorno) > 30) { alert(err[7]); return 1  }
if ( mese == "07" && parseInt(giorno) > 31) { alert(err[8]); return 1  }
if ( mese == "08" && parseInt(giorno) > 31) { alert(err[9]); return 1  }
if ( mese == "09" && parseInt(giorno) > 30) { alert(err[10]); return 1 }
if ( mese == "10" && parseInt(giorno) > 31) { alert(err[11]); return 1 }
if ( mese == "11" && parseInt(giorno) > 30) { alert(err[12]); return 1 }
if ( mese == "12" && parseInt(giorno) > 31) { alert(err[13]); return 1 }

return 0;
}

// Funzione che effettua tutti i controlli inerenti un campo ANNO (ad esempio 1999)
function controlli_anno_singolo(n_anno_da_controllare, s_descrizione) {

	// Controllo che la lunghezza del campo sia almeno 4 caratteri
	if ( n_anno_da_controllare.length != 4 ) { alert("Il campo " + s_descrizione + " deve contenere l'anno nel formato esteso (ad esempio: 1978)"); return 1}
	
	// Controllo che il campo contenga solo valori numerici interi
	var s_stringa_controllo="0123456789"
	for ( var h = 0 ; h < n_anno_da_controllare.length; h++ ) {
		var s_cerca_altro = s_stringa_controllo.indexOf(n_anno_da_controllare.substring(h, h+1))
		if ( s_cerca_altro == -1 ) { alert("Il campo " + s_descrizione + " contiene dei valori non consentiti"); return 1; break }
	}

	return 0
}


function maxWindow()
{
window.moveTo(0,0);


if (document.all)
{
  top.window.resizeTo(screen.availWidth,screen.availHeight);
}

else if (document.layers||document.getElementById)
{
  if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
  {
    top.window.outerHeight = screen.availHeight;
    top.window.outerWidth = screen.availWidth;
  }
}
}
