//************
// Open Window
//************

function OpenWin(URL,Width,Height)
  {
   var wp;
   wp=window.open(URL, "", "toolbar=no,status=yes,scrollbars=yes,resizable=yes,menubar=no,width=" + Width + ",height=" + Height + ",top=0,left=0");
  }

//**********************
// Validità Campo Empty
//**********************
function TestEmpty (Ctrl,msg)
 {if (Ctrl.value == "")
   {alert (msg);
    Ctrl.focus();
    return (false);
   }
  else
   return (true);   
 }

function TestCategorie ()
 {
  /*
  if (document.frmMain.chkSez2.value == undefined) 
   {
    alert(document.frmMain.chkSez2.value);
    return(true);
   }
  */
  var x = document.frmMain.elements.length-1;
  var j = 0;
  var form = document.frmMain;
  for (var i = 0; i <= x; i++)
   {
    if (form.elements[i].name.substring(0,6)=='chkSez')
     {
      j++;
      if (form.elements[i].checked) return (true)
     }
   }
  if (j==1)  return (true)

  alert ("Seleziona almeno una categoria.");
  return (false);
 } 

// Validità e-mail
// ===============
function TestEmail ()
 {if (document.frmNL.email.value == "")
   {alert ("Inserire la E-Mail !");
    document.frmNL.email.focus();
    return (false);
   }
    
  //deve esserci una sola @
  pos=document.frmNL.email.value.indexOf('@', 0)
  if (pos == 0)
   {alert ("Inserisci correttamente l'e-mail!");
    document.frmNL.email.focus();
    return (false);
   }

  if (pos == -1) 
   {alert ("Inserisci correttamente l'e-mail!");
    document.frmNL.email.focus();
    return (false);
   }
  else
   {if (document.frmNL.email.value.indexOf('@', pos+1) != -1)
    {alert ("Inserisci correttamente l'e-mail!");
     document.frmNL.email.focus();
     return (false);
    }
   }

  //devono esserci almeno 4 caratteri dopo @
  if (document.frmNL.email.value.substring(pos+1,document.frmNL.email.value.length).length < 4)
   {alert ("Inserisci correttamente l'e-mail!");
    document.frmNL.email.focus();
    return (false);
   }
  //deve esserci almeno un . dopo @
  if (document.frmNL.email.value.indexOf('.', pos+1) == -1)      
   {alert ("Inserisci correttamente l'e-mail!");
    document.frmNL.email.focus();
    return (false);
   }

  //caratteri ammessi
  stremail=document.frmNL.email.value.toUpperCase()
  for (var i = 0; i < stremail.length; i++)
   {if (".-_0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(stremail.charAt(i)) == -1) 
    {alert ("Inserisci correttamente l'e-mail!");
     document.frmNL.email.focus();
     return (false);
    }
   }
  //Tutto OK
  return (true);   
 }


 // runSubmit


function runSubmit ()
  {
   if (!TestEmail()) return;
   if (!TestEmpty(document.frmNL.txtNominativo,'Inserisci il nominativo')) return;
   if (!TestCategorie()) return;
      document.frmNL.submit();  
      return;
  }
