function Controllainput() {
  errore = "";
  Errore_email = check_email(document.quest.email.value);
  if (Errore_email != "") {
    errore += "\n\nL'indirizzo E-MAIL non e' corretto:" + Errore_email;
  }
  if (errore != "") {
    alert ("ATTENZIONE!" + errore + "\n\n");
    return false;
  }
}

function Completa_tabella() {
  email_utente = '';
  email_utente = get_cookie('email_utente');   
  codice_utente = '';
  codice_utente = get_cookie('codice_utente');   
  
  if ( email_utente != "" && codice_utente != "") {
    document.write('<tr><td bgcolor="#EAEAFF" colspan="2"> <h2><a href="adulti/video/hostess_pompinara.wmv">2. Hostess pompinara</a> </h2></td></tr>');
    document.write('<tr><td> <h2><a href="adulti/video/liceale_impara_anale_da_professore.wmv">3. Liceale impara anale dal professore</a></h2></td></tr>');
    document.write('<tr><td bgcolor="#EAEAFF"> <h2><a href="adulti/video/autostoppista.wmv">4. Autostoppista</a> </h2></td></tr>');
    document.write('<tr><td> <h2><a href="adulti/video/idraulico_scopa_studentessa_sul_tavolo.wmv">5. Idraulico scopa studentessa sul tavolo</a></h2></td></tr>');
    document.write('<tr><td bgcolor="#EAEAFF" colspan="2"> <h2><a href="adulti/video/segretaria_prova_doppia_penetrazione.wmv">6. Segretaria prova doppia penetrazione</a></h2></td></tr>');
    document.write('<tr><td> <h2><a href="adulti/video/masturbazione_dildo.wmv">7. Masturbazione dildo</a> </h2></td></tr>');
    document.write('<tr><td bgcolor="#EAEAFF" colspan="2"> <h2><a href="adulti/video/cane_fotte_babysitter.wmv">8. Cane fotte babysitter</a> </h2></td></tr>');
    document.write('<tr><td> <h2><a href="adulti/video/lesbiche_bionde_fanno_godere_amica.wmv">9. Lesbiche bionde fanno godere amica</a> </h2></td></tr>');
    document.write('<tr><td bgcolor="#EAEAFF" colspan="2"> <h2><a href="adulti/video/nero_superdotato_per_casalinghe_annoiate.wmv">10. Nero superdotato per casalinghe</a> </h2></td></tr>');

  } else {
     
   // Contenuto per utenti NON REGISTRATI o con cookies cancellati
   document.write('<tr><td colspan=3><hr noshade size="2"></td></tr>');
   document.write('<form name="quest" onSubmit="return Controllainput()" method="post" action="cgi-bin/login_adult.cgi">');
   document.write('<tr><input type="hidden" name="url" value="video_hard_erotici.htm"><td colspan="2"><p><br>');
   document.write('Per vedere tutti i filmati <a href="http://www.pollicinoannunci.it/registrazione.htm"><b>REGISTRATI</b></a> (gratis) in 1 minuto<br>');
   document.write('<br>Altrimenti, se sei già registrato inserisci: </p></td></tr>');
   document.write('<tr> <td>Email:</td><td> <input type="text" name="email" value="" size="30"></td></tr>');
   document.write('<tr><td>Codice utente:</td><td><input type="password" name="codice_utente" value="" size="30" maxlength="16">');
   document.write('<input type="submit" value="Invio" name="submit"></td></tr></form> ');
  }       
}


function get_cookie(Name) {
 var search = Name + "="
 var returnvalue = "";
 if (document.cookie.length > 0) {
  offset = document.cookie.indexOf(search)
  if (offset != -1) { // if the cookie exists
   offset += search.length
   end = document.cookie.indexOf(";", offset); // set the index of beginning value
   if (end == -1) // set the index of the end of cookie value
   end = document.cookie.length;
   returnvalue=unescape(document.cookie.substring(offset, end))
  }
 }
 return returnvalue;
}
function setCookie(NameOfCookie, value, expiredays) { 
 var ExpireDate = new Date ();
 ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
 document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString() + ";path=/");
}
function delCookie (NameOfCookie) {
 if (getCookie(NameOfCookie)) {
   document.cookie = NameOfCookie + "=" +"; expires=Thu, 01-Jan-70 00:00:01 GMT";
 }
}

function check_email(email) {

/*
LEGENDA DEGLI ERRORI:

1) La chiocciola e' presente: come primo o ultimo carattere o ne sono state digitate piu' di una;
2) L'e-mail contiene uno o piu' caratteri non ammessi contenuti nella variabile nochar;
3) Il punto e' presente: come primo, ultimo o penultimo carattere, prima o dopo la chiocciola;
4) Ci sono 2 punti (..) oppure due trattini (--) vicini;
5) Non c'e' nessun punto dopo la chiocciola
*/

var errors=""
var i

// Posizione della chiocciola.
var chiocPos=email.indexOf("@")

// Insieme dei caratteri non ammessi in un e-mail.
var nochar="\\/^,;:+àèìòù'<>()%=?!| " + '"'

// Prima lettera dell'e-mail.
var first_letter=email.substring(0,1)

// Ultima lettera dell'e-mail.
var last_letter=email.substring(email.length-1,email.length)

// Penultima lettera dell'e-mail.
var Penultima_letter=email.substring(email.length-2,email.length-1)

// Lettera a sinistra della chiocciola.
var sx_chioc=email.substring(chiocPos-1,chiocPos)

// Lettera a destra della chiocciola.
var dx_chioc=email.substring(chiocPos+1,chiocPos+2)


if ((chiocPos<"1") || (chiocPos==(email.length-1)) || (chiocPos!=(email.lastIndexOf("@")))) {
errors+="\n- Carattere chiocciola (@) mancante o in posizione errata"
}

else {
  for (var i=0; i<=nochar.length-1; i++) {
    if (email.indexOf(nochar.substring(i,i+1))!="-1") {
     errors+="\n- Hai digitato dei caratteri non ammessi"
     break
    }
  }
}

if (errors=="") {
  if ((first_letter==".") || (sx_chioc==".") || (dx_chioc==".") || (last_letter==".") || (Penultima_letter==".") ) {
     errors+="\n- Il punto (.) e' in posizione errata"
  }  
  else {

    for (var i=0; i<=email.length-1; i++) {
      if ((email.substring(i,i+1)==".") && (email.substring(i+1,i+2)==".")) {
        errors+="\n- Ci sono due caratteri punto (.) vicini"
        break
      }
      if ((email.substring(i,i+1)=="-") && (email.substring(i+1,i+2)=="-")) {
        errors+="\n- Ci sono due caratteri trattino (-) vicini"
        break
      }
    }
  }
}
PuntoDopoChioc = 0

if (errors=="") {

  for (var i=chiocPos+1; i<=email.length-3; i++) {
    if (email.substring(i,i+1)==".") {
      PuntoDopoChioc = 1
      break
    }
  }
  if (PuntoDopoChioc == 0) {
    errors+="\n- Non hai indicato il dominio (.it .com .net ecc..)"
  }
}
return errors
}
