function login()
{
  var empty_fields = "";
  var result = 1;
     
  if (document.login.username.value == "")
  {
    empty_fields = empty_fields + "* Inserire User Name\n";
  }
  
  if (document.login.password.value == "")
  {
    empty_fields = empty_fields + "* Inserire Password\n";
  }
  
  if (document.login.sc.value == "")
  {
    empty_fields = empty_fields + "* Inserire AccessCode\n";
  }
  
  if (empty_fields == "")
  {
   if (document.login.sc.value != document.login.controlsc.value)
   {
     empty_fields = empty_fields + "* AccessCode Errato\n";
   }
  }
  
  if (empty_fields != "")
  {
    var msg = "I seguenti campi non possoono essere vuoti:\n\n" + empty_fields;
    alert (msg);
    result = 0;
  }
  if (result != 0)
  {
    document.login.submit();
  }
 
}


function controllaore(e) 
{
  var ie = (navigator.appName.indexOf('Microsoft Internet Explorer')>-1);
  if(ie) {
    key = event.keyCode;
  } else key = e.which;
  if((key < 48 || key > 58) && (key != 8 && key != 13)) {
    alert("Attenzione : questo parametro ammette esclusivamente numeri interi");
    if(!ie) {
      document.InsCommessa.oreassegnate.value = document.InsCommessa.oreassegnate.value.substr(0,document.InsCommessa.oreassegnate.value.length-1);
    }
    return false;
  }
}

function controllaoresur(e) 
{
  var ie = (navigator.appName.indexOf('Microsoft Internet Explorer')>-1);
  if(ie) {
    key = event.keyCode;
  } else key = e.which;
  if((key < 48 || key > 58) && (key != 8 && key != 13)) {
    alert("Attenzione : questo parametro ammette esclusivamente numeri interi");
    if(!ie) {
      document.InsCommessa.surplusore.value = document.InsCommessa.surplusore.value.substr(0,document.InsCommessa.surplusore.value.length-1);
    }
    return false;
  }
}


function qt(e) 
{
  var ie = (navigator.appName.indexOf('Microsoft Internet Explorer')>-1);
  if(ie) 
  {
    key = event.keyCode;
  } 
  else key = e.which;
  
  if((key < 48 || key > 58) && (key != 8 && key != 13))
  {
    alert("Attenzione : questo parametro ammette esclusivamente numeri interi");
    if(!ie)
    {
      document.InsSottoCommessa.quantita.value = document.InsSottoCommessa.quantita.value.substr(0,document.InsSottoCommessa.quantita.value.length-1);
    }
    return false;
  }
  
}

function qt2(e) 
{
  var ie = (navigator.appName.indexOf('Microsoft Internet Explorer')>-1);
  if(ie) 
  {
    key = event.keyCode;
  } 
  else key = e.which;
  
  if((key < 48 || key > 58) && (key != 8 && key != 13))
  {
    alert("Attenzione : questo parametro ammette esclusivamente numeri interi");
    if(!ie)
    {
      document.ModSottoCommessa.quantita.value = document.ModSottoCommessa.quantita.value.substr(0,document.ModSottoCommessa.quantita.value.length-1);
    }
    return false;
  }
  
}


function calc(e) 
{
  var molt = document.InsSottoCommessa.moltiplicatore.options[ document.InsSottoCommessa.moltiplicatore.selectedIndex].value;
  var quant = document.InsSottoCommessa.quantita.value;
  var ris = molt * quant;
  document.InsSottoCommessa.oresottocommessa.value = ris;
}

function mcalc(E) 
{
  var molt = document.ModSottoCommessa.moltiplicatore.options[ document.ModSottoCommessa.moltiplicatore.selectedIndex].value;
  var quant = document.ModSottoCommessa.quantita.value;
  var ris = molt * quant;
  document.ModSottoCommessa.oresottocommessa.value = ris;
}

function calc2(e) 
{
  var molt = document.InsSottoCommessa.moltiplicatore.options[ document.InsSottoCommessa.moltiplicatore.selectedIndex].value;
  var quant = document.InsSottoCommessa.quantita.value;
  var ris = molt * quant;
  document.InsSottoCommessa.oresottocommessa.value = ris;
}

function mcalc2(e) 
{
  var molt = document.ModSottoCommessa.moltiplicatore.options[ document.ModSottoCommessa.moltiplicatore.selectedIndex].value;
  var quant = document.ModSottoCommessa.quantita.value;
  var ris = molt * quant;
  document.ModSottoCommessa.oresottocommessa.value = ris;
}


function surpluse(e) 
{
  var ie = (navigator.appName.indexOf('Microsoft Internet Explorer')>-1);
  if(ie) {
    key = event.keyCode;
  } else key = e.which;
  if((key < 48 || key > 58) && (key != 8 && key != 13)) {
    alert("Attenzione : questo parametro ammette esclusivamente numeri interi");
    if(!ie) {
      document.InsSottoCommessa.surplusore.value = document.InsSottoCommessa.surplusore.value.substr(0,document.InsSottoCommessa.surplusore.value.length-1);
    }
    return false;
  }
}


function InsCommessa()
{
  var empty_fields = "";
  var result = 1;
     
  if (document.InsCommessa.tipoie.value == "")
  {
    empty_fields = empty_fields + "* Commessa Interna/Esterna\n";
  }
  
  if (document.InsCommessa.tipocom.value == "")
  {
    empty_fields = empty_fields + "* Tipologia di Commessa\n";
  }
  
  if (document.InsCommessa.area.value == "")
  {
    empty_fields = empty_fields + "* Area di Appartenenza\n";
  }
  
  if (document.InsCommessa.descrizione.value == "")
  {
    empty_fields = empty_fields + "* Descrizione\n";
  }

  if (document.InsCommessa.cliente.value == "")
  {
    empty_fields = empty_fields + "* Cliente\n";
  }
  
  if (document.InsCommessa.responsabile.value == "")
  {
    empty_fields = empty_fields + "* Responsabile\n";
  }
  
  if (empty_fields != "")
  {
    var msg = "I seguenti campi non possoono essere vuoti:\n\n" + empty_fields;
    alert (msg);
    result = 0;
  }

  var ris = 1;
  
  if (result != 0)
  {
  
   var testo = "I seguenti campi hanno valore 0 continuare ?\n\n";
   if (document.InsCommessa.oreassegnate.value == "0")
   {
    testo = testo + "* Ore Assegnate\n";
    ris = 0;
   }
   
   if (document.InsCommessa.surplusore.value == "0")
   {
    testo = testo + "* Surplus Ore per Commessa\n";
    ris = 0;
   }
   
   if (ris == "0")
   {   
    if (confirm(testo))
    {
     document.InsCommessa.submit();   
    }
    Else
    {
     result = 0;
    }
   } 
   
   if (ris == "1")
   { 
    document.InsCommessa.submit();   
   }
  }
}

function ModCommessa()
{
  var empty_fields = "";
  var result = 1;
    
 
  if (document.ModCommessa.tipocom.value == "")
  {
    empty_fields = empty_fields + "* Tipologia di Commessa\n";
  }
  
  if (document.ModCommessa.area.value == "")
  {
    empty_fields = empty_fields + "* Area di Appartenenza\n";
  }
  
  if (document.ModCommessa.descrizione.value == "")
  {
    empty_fields = empty_fields + "* Descrizione\n";
  }

  if (document.ModCommessa.cliente.value == "")
  {
    empty_fields = empty_fields + "* Cliente\n";
  }
  
  if (document.ModCommessa.responsabile.value == "")
  {
    empty_fields = empty_fields + "* Responsabile\n";
  }
  
  if (empty_fields != "")
  {
    var msg = "I seguenti campi non possoono essere vuoti:\n\n" + empty_fields;
    alert (msg);
    result = 0;
  }

  var ris = 1;
  
  if (result != 0)
  {
  
   var testo = "I seguenti campi hanno valore 0 continuare ?\n\n";
   if (document.ModCommessa.oreassegnate.value == "0")
   {
    testo = testo + "* Ore Assegnate\n";
    ris = 0;
   }
   
   if (document.ModCommessa.surplusore.value == "0")
   {
    testo = testo + "* Surplus Ore per Commessa\n";
    ris = 0;
   }
   
   if (ris == "0")
   {   
    if (confirm(testo))
    {
     document.ModCommessa.submit();   
    }
    
   } 
   
   if (ris == "1")
   { 
    document.ModCommessa.submit();   
   }
  }
}


function InsSottoCommessa()
{
  var empty_fields = "";
  var result = 1;
     
  if (document.InsSottoCommessa.tiposottocom.value == "")
  {
    empty_fields = empty_fields + "* Tipologia Sotto Commessa\n";
  }
  
  if (document.InsSottoCommessa.area.value == "")
  {
    empty_fields = empty_fields + "* Area Sotto Commessa\n";
  }
  
  if (document.InsSottoCommessa.descrizione.value == "")
  {
    empty_fields = empty_fields + "* Descrizione\n";
  }
  
  if (document.InsSottoCommessa.responsabile.value == "")
  {
    empty_fields = empty_fields + "* Responsabile\n";
  }

  if (document.InsSottoCommessa.unitamisura.value == "")
  {
    empty_fields = empty_fields + "* Unità di Misura\n";
  }
  
  
  
  if (document.InsSottoCommessa.quantita.value == "")
  {
    empty_fields = empty_fields + "* Quantità\n";
  }
  
  
  if (document.InsSottoCommessa.moltiplicatore.value == "")
  {
    empty_fields = empty_fields + "* Moltiplicatore\n";
  }
  
  
  if (document.InsSottoCommessa.surplusore.value == "")
  {
    empty_fields = empty_fields + "* Surplus Ore Sotto Commessa\n";
  }
  
  
  if (document.InsSottoCommessa.giornoinizio.value == "")
  {
    empty_fields = empty_fields + "* Giorno Data Inizio\n";
  }
  
  
  if (document.InsSottoCommessa.giornofine.value == "")
  {
    empty_fields = empty_fields + "* Giorno Data Fine\n";
  }
  
  
  if (document.InsSottoCommessa.annoinizio.value == "")
  {
    empty_fields = empty_fields + "* Anno Data Inizio\n";
  }
  
  
  if (document.InsSottoCommessa.annofine.value == "")
  {
    empty_fields = empty_fields + "* Anno Data Fine\n";
  }  
  
  if (empty_fields != "")
  {
    var msg = "I seguenti campi non possoono essere vuoti:\n\n" + empty_fields;
    alert (msg);
    result = 0;
  }
  
  var ris = 1;
  
  if (result != 0)
  {
  
   var testo = "I seguenti campi hanno valore 0 continuare ?\n\n";
   if (document.InsSottoCommessa.quantita.value == "0")
   {
    testo = testo + "* Quantità\n";
    ris = 0;
   }
   
   if (document.InsSottoCommessa.surplusore.value == "0")
   {
    testo = testo + "* Surplus Ore Sotto Commessa\n";
    ris = 0;
   }
   
   if (ris == "0")
   {   
    if (confirm(testo))
    {
     document.InsSottoCommessa.submit();   
    }
    Else
    {
     result = 0;
    }
   } 
   
   if (ris == "1")
   { 
    document.InsSottoCommessa.submit();   
   }
  }
 
}


function ModSottoCommessa()
{
  var empty_fields = "";
  var result = 1;
     
  if (document.ModSottoCommessa.tiposottocom.value == "")
  {
    empty_fields = empty_fields + "* Tipologia Sotto Commessa\n";
  }
  
  if (document.ModSottoCommessa.area.value == "")
  {
    empty_fields = empty_fields + "* Area Sotto Commessa\n";
  }
  
  if (document.ModSottoCommessa.descrizione.value == "")
  {
    empty_fields = empty_fields + "* Descrizione\n";
  }
  
  if (document.ModSottoCommessa.responsabile.value == "")
  {
    empty_fields = empty_fields + "* Responsabile\n";
  }

  if (document.ModSottoCommessa.unitamisura.value == "")
  {
    empty_fields = empty_fields + "* Unità di Misura\n";
  }
  
  
  
  if (document.ModSottoCommessa.quantita.value == "")
  {
    empty_fields = empty_fields + "* Quantità\n";
  }
  
  
  if (document.ModSottoCommessa.moltiplicatore.value == "")
  {
    empty_fields = empty_fields + "* Moltiplicatore\n";
  }
  
  
  if (document.ModSottoCommessa.surplusore.value == "")
  {
    empty_fields = empty_fields + "* Surplus Ore Sotto Commessa\n";
  }
  
  
  if (document.ModSottoCommessa.giornoinizio.value == "")
  {
    empty_fields = empty_fields + "* Giorno Data Inizio\n";
  }
  
  
  if (document.ModSottoCommessa.giornofine.value == "")
  {
    empty_fields = empty_fields + "* Giorno Data Fine\n";
  }
  
  
  if (document.ModSottoCommessa.annoinizio.value == "")
  {
    empty_fields = empty_fields + "* Anno Data Inizio\n";
  }
  
  
  if (document.ModSottoCommessa.annofine.value == "")
  {
    empty_fields = empty_fields + "* Anno Data Fine\n";
  }  
  
  if (empty_fields != "")
  {
    var msg = "I seguenti campi non possoono essere vuoti:\n\n" + empty_fields;
    alert (msg);
    result = 0;
  }
  
  var ris = 1;
  
  if (result != 0)
  {
  
   var testo = "I seguenti campi hanno valore 0 continuare ?\n\n";
   if (document.ModSottoCommessa.quantita.value == "0")
   {
    testo = testo + "* Quantità\n";
    ris = 0;
   }
   
   if (document.ModSottoCommessa.surplusore.value == "0")
   {
    testo = testo + "* Surplus Ore Sotto Commessa\n";
    ris = 0;
   }
   
   if (ris == "0")
   {   
    if (confirm(testo))
    {
     document.ModSottoCommessa.submit();   
    }
    Else
    {
     result = 0;
    }
   } 
   
   if (ris == "1")
   { 
    document.ModSottoCommessa.submit();   
   }
  }
 
}

function selarea(e) 
{
  var codarea = window.document.SelelezioneArea.selarea.options[window.document.SelelezioneArea.selarea.selectedIndex].value;
  //alert(codarea);
  if (codarea != "")
  {
   //alert("Ciao2");
   window.document.SelelezioneArea.submit();
  }  
}

function DefAttivita()
{
  var empty_fields = "";
  var result = 1;
     
  if (document.DefAttivita.fase.value == "")
  {
    empty_fields = empty_fields + "* Fase\n";
  }
  
  if (document.DefAttivita.attivita.value == "")
  {
    empty_fields = empty_fields + "* Attività\n";
  }
  
  if (document.DefAttivita.resp.value == "")
  {
    empty_fields = empty_fields + "* Responsabile\n";
  }
  
  if (document.DefAttivita.gi.value == "")
  {
    empty_fields = empty_fields + "* Giorno Inizio Previsto\n";
  }
  
  if (document.DefAttivita.gf.value == "")
  {
    empty_fields = empty_fields + "* Giorno Fine Prevista\n";
  }
  
  if (document.DefAttivita.ai.value == "")
  {
    empty_fields = empty_fields + "* Anno Inizio Previsto\n";
  }
  
  if (document.DefAttivita.af.value == "")
  {
    empty_fields = empty_fields + "* Anno Fine Prevista\n";
  }
    
  if (empty_fields != "")
  {
    var msg = "I seguenti campi non possoono essere vuoti:\n\n" + empty_fields;
    alert (msg);
    result = 0;
  }
    
  if (result != 0)
  {
   document.DefAttivita.submit();   
  }
  
}


function SchedaLav()
{
  var empty_fields = "";
  var result = 1;
     
  if (document.SchedaLav.prodotto.value == "")
  {
    empty_fields = empty_fields + "* Prodotto / Servizio\n";
  }
  
  if (document.SchedaLav.segnalata.value == "")
  {
    empty_fields = empty_fields + "* Segnalata / Riscontrata\n";
  }
  
  /*
  if (document.SchedaLav.protocollo.value == "")
  {
    empty_fields = empty_fields + "* Protocollo IASI\n";
  }
  */
  
  /*
  if (document.SchedaLav.schedacollegata.value == "")
  {
    empty_fields = empty_fields + "* Scheda Collegata\n";
  }
  */
  
  if (document.SchedaLav.valutazione.value == "")
  {
    empty_fields = empty_fields + "* Valutazione Compilatore\n";
  }
  
  if (document.SchedaLav.priorita.value == "")
  {
    empty_fields = empty_fields + "* Priorità Compilatore\n";
  }
  
  if (document.SchedaLav.descrizione.value == "")
  {
    empty_fields = empty_fields + "* Descrizione Attività\n";
  }
  
  /*
  if (document.SchedaLav.parereresp.value == "")
  {
    empty_fields = empty_fields + "* Parere Responsabile\n";
  }
  
  
  if (document.SchedaLav.difficoltaresp.value == "")
  {
    empty_fields = empty_fields + "* Difficoltà Responsabile\n";
  }
  
  */
  
  if (document.SchedaLav.giorniassegnati.value == "")
  {
    empty_fields = empty_fields + "* Giorni Assegnati\n";
  }
  
  if (document.SchedaLav.realizzatore.value == "")
  {
    empty_fields = empty_fields + "* Realizzatore\n";
  }
  
  if (document.SchedaLav.giorno.value == "")
  {
    empty_fields = empty_fields + "* Giorno Esecuzione\n";
  }
  
  if (document.SchedaLav.anno.value == "")
  {
    empty_fields = empty_fields + "* Anno Esecuzione\n";
  }
  
  if (document.SchedaLav.note.value == "")
  {
    empty_fields = empty_fields + "* Note\n";
  }
      
     
  if (empty_fields != "")
  {
    var msg = "I seguenti campi non possoono essere vuoti:\n\n" + empty_fields;
    alert (msg);
    result = 0;
  }
    
  if (result != 0)
  {
   document.SchedaLav.submit();   
  }
  
}


function SelProdotti()
{
   var scelte = "";
   var quanti = document.SelProdotti.NMaxProd.value;
   var da = 5;
   var a = (5 + (quanti-1)); 
   
   for (i=da;i<=a;i++)
   {
    if (document.SelProdotti.elements[i].checked == true) 
    {
     if (scelte == "")
     {
      scelte = document.SelProdotti.elements[i].value; 
     }
     else
     {
      scelte = scelte + ";" + document.SelProdotti.elements[i].value; 
     }
    }
   }  
   if (scelte != "")
   {
    document.SelProdotti.ProdSel.value = scelte;
    document.SelProdotti.submit();
   }
   
	 
}

function SelRisorse()
{
   var scelte = "";
   var quanti = document.SelRisorse.NMaxRis.value;
   var quanti2 = quanti * 2;
   var da = 5;
   var a = (5 + ( (quanti * 2 ) -1 ) ); 
   var i = 0;
     
  
   while (da <= a)
   {
    i = da;
    j = da + 1;
    if (document.SelRisorse.elements[i].checked == true) 
    {
     if (scelte == "")
     {
      scelte = document.SelRisorse.elements[i].value + "#" + document.SelRisorse.elements[j].value; 
      //alert(scelte);
     }
     else
     {
      scelte = scelte + ";" + document.SelRisorse.elements[i].value + "#" + document.SelRisorse.elements[j].value; 
      //alert(scelte);
     }
    }
    da = da + 2;
   } 
   
   if (scelte != "")
   {
    document.SelRisorse.RisSel.value = scelte;
    document.SelRisorse.submit();
   }
   
	 
}



function AggSchedaLav()
{
  var empty_fields = "";
  var result = 1;
  
  if (document.DettSchedaLav.attivita.value == "")
  {
    empty_fields = empty_fields + "* Attività\n";
  }
  
  if (document.DettSchedaLav.risorsastatoattuale.value == "")
  {
    empty_fields = empty_fields + "* Risorsa Stato Attuale\n";
  }
  
  if (document.DettSchedaLav.oreinterne.value == "")
  {
    empty_fields = empty_fields + "* Ore Attività Interne\n";
  }
  
  if (document.DettSchedaLav.oreesterne.value == "")
  {
    empty_fields = empty_fields + "* Ore Attività Esterne\n";
  }
      
     
  if (empty_fields != "")
  {
    var msg = "I seguenti campi non possoono essere vuoti:\n\n" + empty_fields;
    alert (msg);
    result = 0;
  }
    
  if (result != 0)
  {
   document.DettSchedaLav.submit();   
  }
    
}
