var obbl="Questo campo è obbligatorio.";

function err(campo,msg)
{
 var c=document.getElementById(campo);
 c.className+=(c.className?" ":"")+"valerr";
 if(c.scrollIntoView) c.scrollIntoView(true);
 c.focus();
 alert(msg);
}

function trim(s)
{
 var tmp=s.replace(/^ +/,"");
 tmp=s.replace(/ +$/,"");
 return s;
}

function contrData(data)
{
 if(data.length<4) return false;
 var adata=data.split(/[ \/\.\-\\]/);//])/
 var giorno=0,mese=0,anno=0;
 if(adata.length!=3) return false;
 if(isNaN(adata[0]) || isNaN(adata[1]) || isNaN(adata[2])) return false;
 giorno=parseInt(adata[0],10);
 mese=parseInt(adata[1],10);
 anno=parseInt(adata[2],10);
 if(!anno || !mese || !anno) return false;
 if(anno>99 && anno<1970) return false;
 if(anno<100 && anno>50) anno=1900+anno;
 else if(anno<100) anno=2000+anno;
 if(mese<1 || mese>12) return false;
 var bisestile;
 if((anno-Math.floor(anno/4)*4)!=0) bisestile=0;
 else if((anno-Math.floor(anno/400)*400)==0) bisestile=1;
 else if((anno-Math.floor(anno/100)*100)==0) bisestile=0;
 else bisestile=1;
 if(giorno<1) return false;
 if(mese==4 || mese==6 || mese==9 || mese==11)
 {
  if(giorno>30) return false;
 }
 else if(mese!=2)
 {
  if(giorno>31) return false;
 }
 else if(giorno>(28+bisestile)) return false;
 return ((giorno>9)?giorno:("0"+giorno))+"/"+((mese>9)?mese:("0"+mese))+"/"+anno;
}

function confrDate(dt1,dt2)
{
 var giorno1,mese1,anno1,giorno2,mese2,anno2;
 var d1,d2;
 var adata=dt1.split(/[ \/\.\-\\]/);//])/;
 giorno1=parseInt(adata[0],10); mese1=parseInt(adata[1],10)-1; anno1=parseInt(adata[2],10);
 var adata=dt2.split(/[ \/\.\-\\]/);//])/;
 giorno2=parseInt(adata[0],10); mese2=parseInt(adata[1],10)-1; anno2=parseInt(adata[2],10);
 d1=new Date(anno1,mese1,giorno1,0,0,0);
 d2=new Date(anno2,mese2,giorno2,0,0,0);
// return ((d1>d2)?1:((d1<d2)?-1:0));
 return Math.floor((d1.getTime()-d2.getTime())/86400000);
}

function invia(e)
{
 var f;
 if(!e) var e=window.event;
 if(e.target) f=e.target;
 else if(e.srcElement) f=e.srcElement;
 if(!controlla())
 {
  if(e.preventDefault) e.preventDefault();
  if(e.stopPropagation) e.stopPropagation();
  else if(e.cancelBubble) e.cancelBubble();
  return false;
 }
 else return true;
}

function init(idform)
{
 if(document.getElementById && document.getElementById(idform))
 {
  var f=document.getElementById(idform);
  if(f.addEventListener) f.addEventListener("submit",invia,false);
  else f.onsubmit=invia;
  try { initLocale(); } catch(e) {}
 }
}
