//************************************************************************************

function LunghezzaMinima(campo,nome,lun)
{ if (campo.value.length<lun) { alert("Attenzione: il campo '"+nome+"' è troppo corto! (min."+lun+" caratteri)"); campo.focus(); return true; } return false; }

function IsDifferent(campo1,campo2,nome1,nome2)
{ if (campo1.value!=campo2.value) { alert("Attenzione: i campi '"+nome1+"' e '"+nome2+"' devono essere uguali!"); campo1.focus(); return true; } return false; }

function TestoVuoto(campo,nome)
{ if (campo.value=="") { alert("Attenzione: il campo '"+nome+"' è obbligatorio!");  return true; } return false; }

function StringaVuotaLista(campo,nome,flag)
{ var indice=campo.selectedIndex; if (campo.options[indice].text=="") { if (flag) { alert("Attenzione: il campo '"+nome+"' è obbligatorio!"); campo.focus(); } return true; } return false; }

function ErrorString(campo,nomeCampo)
{ var st=campo.value; for (var k=0;k<st.length;k++) if ((st.charAt(k)>="0") && (st.charAt(k)<="9")) { alert("Attenzione: Il campo "+nomeCampo+" non deve contenere caratteri numerici."); campo.focus(); return true; } return false; }  

function ErrorNumber(campo,nomeCampo)
{ var st=campo.value; for (var k=0;k<st.length;k++) if ( ((st.charAt(k)<"0") || (st.charAt(k)>"9")) && (st.charAt(k)!="-") && (st.charAt(k)!="+") && (st.charAt(k)!=".")   ) { alert("Attenzione: Il campo "+nomeCampo+" deve contenere caratteri numerici."); campo.focus(); return true; } return false; }  


function ErrorEmail(campo)
{ var st=campo.value; 
  if (  (st.indexOf("@")==-1) ||
       	(st.indexOf(".")==-1) || 
		(st.length < 6) ||
		(st.indexOf("@.")!=-1) ||
       	(st.indexOf("@@")!=-1) 
     ) {  alert("Attenzione: indirizzo E- mail non valido."); campo.focus(); return true;} return false;
}

function ErrorTel(campo,nomeCampo)
{var st=campo.value;
 var car;
  for (var k=0;k<st.length;k++)
  { car=st.charAt(k);
    if (
        ((car<'0') || (car>'9'))
//        &&
//        ((car != '+') && (car !='/') && (car !='-'))
       )
     { alert("Attenzione: numero di "+nomeCampo+" non valido.");
       campo.focus();
       return true;
     }
  }
  return false;
} 
function check_form_contatto(frm,campo1,campo2,campo3){
  if (!frm) frm = 'form_contatti';
   var error = [];
   var ret=1;
  
  if (campo1 && document.forms[frm].elements[campo1].value=='') {ret=0; error[error.length] = 'Nome e cognome';}
  if (campo2 && document.forms[frm].elements[campo2].value=='') {ret=0; error[error.length] = 'eMail';} 
  if (campo3 && document.forms[frm].elements[campo3].value=='') {ret=0; error[error.length] = 'Telefono / Cellulare';} 
  
  if (ret==0){
    var msg = "I seguenti campi non sono stati compilati correttamente:";
	  var i = 0;
    for (i=0; i<error.length; i++) {
      msg += "\n- " + error[i];
    }
    alert(msg);
    return false;
  }else
    return true;   

} 

//************************************************************************************

