window.onload = init;
function init() {
        initab();
        loginForm = document.getElementById('formCommento');
        loginForm.onsubmit = function () {return valida(this);}
}
//Tab
function initab(){
var ntab = new Array("Informazioni");
var MainContainer=document.getElementById("info");
var tab=document.createElement("div");
tab.className="tab";
var Tabs=document.createElement("ul");
tab.appendChild(Tabs);
MainContainer.insertBefore(tab,MainContainer.firstChild);
for (i in ntab){
var TabLi=document.createElement("li");
if (i == 0) TabLi.className="active";
var span=document.createElement("span");
//span.style.cursor="pointer";
span.innerHTML = ntab[i];
TabLi.appendChild(span);
Tabs.appendChild(TabLi);
}
}
//Parte valida form
function vuoto(field) {
        if (field.value == "" || field.value == null) {return false;}
        else {return true;}
}

function rmessaggio(dove){
var precogg = document.getElementById('err'+dove);
alert(precogg);
elemento = document.getElementById(dove);
elemento.removeChild(precogg);
}
function messaggio(dove,msg){
 var precogg = document.getElementById('err'+dove);
 if (precogg == null){
 var span = document.createElement('span');
 span.setAttribute("id","err"+dove);
 span.setAttribute("class","errore");
 } else span = precogg;
 span.innerHTML = msg;
 elemento = document.getElementById(dove);
 elemento.parentNode.insertBefore(span,elemento.nextSibling);
}

function valida(form) {
errore = 0;
//Controllo autore
if (!vuoto(form.autore)){
messaggio("autore", "Inserisci il tuo nome");
errore = 1;
} else {messaggio("autore","");}
//controllo email
if (!vuoto(form.email)){
messaggio("email", "Inserisci un indirizzo email");
errore = 1;
} else {
  var espressione = /^[_a-zA-Z0-9+-]+(\.[_a-zA-Z0-9+-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/;
  if (!espressione.test(form.email.value)){
      messaggio("email", "Indirizzo email non corretto");
      errore = 1;
  } else {messaggio("email", "");}
}
if (!vuoto(form.commento)){
messaggio("commento", "Inserisci un commento");
errore = 1;
} else {messaggio("commento", "");}
//ritorno errore?
if (errore == 1) {return false;}
else {return true;}
}