function trim(stringa){
while (stringa.substring(0,1) == ' '){
stringa = stringa.substring(1, stringa.length);}
while (stringa.substring(stringa.length-1, stringa.length) == ' '){
stringa = stringa.substring(0,stringa.length-1);}
return stringa;}

function check_nome(){
var nome = trim(document.request_form.nome.value);
if (nome == '' || nome == 'undefined')
   {
   $('nomediv').innerHTML = "<font color=#ff0000>* Nome</font>";
   $('first_alert').style.display = "block";
   return false;
}else{
$('nomediv').innerHTML = "* Nome";
   $('first_alert').style.display = "none";
   return true;}
}

function check_cnome(){
var cnome = trim(document.request_form.cognome.value);
if (cnome == '' || cnome == 'undefined')
   {
   $('cnomediv').innerHTML = "<font color=#ff0000>* Cognome</font>";
   $('first_alert').style.display = "block";
   return false;
}else{
$('cnomediv').innerHTML = "* Cognome";
   $('first_alert').style.display = "none";
   return true;}
}

function check_mail(){
var email = trim(document.request_form.email.value);
if (email == '' || email == 'undefined')
   {
   $('maildiv').innerHTML = "<font color=#ff0000>* E-mail</font>";
   $('first_alert').style.display = "block";
   return false;
}else{
$('maildiv').innerHTML = "* E-mail";
   $('first_alert').style.display = "none";
   return true;}
}

function check_mail_set(){
var email = trim(document.request_form.email.value);
var emailtest = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
if ((email == '') || (!emailtest.test(email)))
   {
   $('maildiv').innerHTML = "<font color=#ff0000>* E-mail non valida!</font>";
   $('first_alert').style.display = "block";
   return false;
}else{
$('maildiv').innerHTML = "* E-mail";
   $('first_alert').style.display = "none";
   return true;}
}

function check_invio(){
check_nome();
check_cnome();
check_mail();
check_mail_set();      

if(check_nome() == true && check_cnome() == true && check_mail() == true && check_mail_set() == true){

var pars = Form.serialize(document.request_form);
new Ajax.Updater('prenota','book_send.php',{asynchronous:true, method: 'post', parameters: pars});

}else{
return false;
}
}

function reset_invio(){
document.request_form.reset();
$('nomediv').innerHTML = "* Nome";
$('cnomediv').innerHTML = "* Cognome";
$('maildiv').innerHTML = "* E-mail";
$('first_alert').innerHTML = "";
}
