function submittaform(e,nomeform){
  var key=e.keyCode || e.which;
  if (key==13){
    form=eval("document."+nomeform);
    form.submit();
  }
}

function js_addtocaddycomp(selflink,nomeform,idvar,tipoalert,testoalert,qta_caddy,dispo,e){
  var key=e.keyCode || e.which;
  if (key==13){
    addtocaddycomp(selflink,nomeform,idvar,tipoalert,testoalert,qta_caddy,dispo)
  }
}

function resettacampo(nomecampo,valore0,avviso){
  campo=eval(nomecampo);
  if (campo.value>valore0){
    campo.value=valore0;
    if (avviso.length)
      alert(avviso);
  }
}


function addtocaddycomp(selflink,nomeform,idvar,tipoalert,testoalert,qta_caddy,dispo){
  campo=eval("document."+nomeform+".addtocaddycomp_"+idvar);
  continua=1;
  delta=new Number(campo.value);
  if (((tipoalert=="alert") || (tipoalert=="confirm")) && (delta+qta_caddy>dispo)){
    if (tipoalert=="alert"){
      alert(testoalert);
      continua=0;
    }
    else if (tipoalert=="confirm")
      if (!confirm(testoalert))
        continua=0;
  }
  if (continua){
    newloc=selflink+"&g2ac="+idvar+'_'+campo.value;
    newloc+='&'+stringaoffset();
    document.location=newloc;
  }
}

function js_addtocaddycomp_capsures(selflink,nomeform,idvar,iditem,tipoalert,testoalert,qta_caddy,dispo,e){
  var key=e.keyCode || e.which;
  if (key==13){
    addtocaddycomp_capsures(selflink,nomeform,idvar,iditem,tipoalert,testoalert,qta_caddy,dispo)
  }
}

function addtocaddycomp_capsures(selflink,nomeform,idvar,iditem,tipoalert,testoalert,qta_caddy,dispo){
  campo=eval("document."+nomeform+".addtocaddycomp_"+iditem+'_'+idvar);
  continua=1;
  delta=new Number(campo.value);
  if (((tipoalert=="alert") || (tipoalert=="confirm")) && (delta+qta_caddy>dispo)){
    if (tipoalert=="alert"){
      alert(testoalert);
      continua=0;
    }
    else if (tipoalert=="confirm")
      if (!confirm(testoalert))
        continua=0;
  }
  if (continua){
    newloc=selflink+"&g2ac="+iditem+'_'+idvar+'_'+campo.value;
    newloc+='&'+stringaoffset();
    document.location=newloc;
  }
}

var forseaggiungi1="";
var forseaggiungi2="";

function forseaggiungiqualcosa(url){
  if (forseaggiungi1.length)
    url.href+='&'+forseaggiungi1+'='+eval(forseaggiungi2);
}


function popcal(id_campo){
  valcampo=eval("document."+id_campo).value;
 showcalendar('popcal_js/js.php?css=css/antique.css&idc='+id_campo+'&valc='+escape(valcampo),220,225)
}

function popcal3(nomeform,prenomecampi){
  i_day=eval("document."+nomeform+'.'+prenomecampi+"_day");
  i_month=eval("document."+nomeform+'.'+prenomecampi+"_month");
  i_year=eval("document."+nomeform+'.'+prenomecampi+"_year");
  valcampo=i_day[i_day.selectedIndex].value+'.'+i_month[i_month.selectedIndex].value+'.'+i_year[i_year.selectedIndex].value;
  idc='_data3_'+nomeform+'.'+prenomecampi;
  showcalendar('popcal_js/js.php?css=css/antique.css&idc='+idc  +'&valc='+escape(valcampo),220,225)
}


function popupgruppodoc(id_gruppo,cs){
  site_popup=window.open("popupgruppodoc.php?id_gruppo="+id_gruppo+"&cs="+cs,'site_popup','resizable=yes,width=800,height=600,scrollbars=yes,status=no,location=no');
}


function XOffset(){
  x=window.pageXOffset;
  if (x==undefined)
    x=document.body.scrollLeft;
  return x;
}

function YOffset(){
  y=window.pageYOffset;
  if (y==undefined)
    y=document.body.scrollTop;
  return y;
}

function XYsubmitta(nomeform){
  form=eval("document."+nomeform);
  form.pXO.value=XOffset();
  form.pYO.value=YOffset();
  form.submit();
}


function popupindi(id_indi,cs){
  site_popup=window.open("displindi.php?id_indi="+id_indi+"&rif="+cs,'site_popup','resizable=yes,width=640,height=480,scrollbars=yes,status=no,location=no');
}

function popupindinew(id_indi,cs){
  site_popup=window.open("newpopupindi.php?id_indi="+id_indi+"&rif="+cs,'site_popup','resizable=yes,width=640,height=480,scrollbars=yes,status=no,location=no');
}


function popupeve(id_eve,cs){
  site_popup=window.open("displeve.php?id_eve="+id_eve+"&rif="+cs,'site_popup','resizable=yes,width=640,height=480,scrollbars=yes,status=no,location=no');
}

function stringaoffset(){
  pXO=window.pageXOffset;
  pYO=window.pageYOffset;
  if (pXO==undefined){
    pXO=document.body.scrollLeft;
    pYO=document.body.scrollTop;
    if (document.compatMode!='undefined'){
      if (document.compatMode!='BackCompat'){
        pXO=document.documentElement.scrollLeft;
        pYO=document.documentElement.scrollTop;
      }
    }
  }
  if (pXO==undefined)
    pXO=0;
  if (pYO==undefined)
    pYO=0;
  return "pXO="+pXO+"&pYO="+pYO;
}


function aggiungioffset(url){
  url.href+='&'+stringaoffset();
}


function popupg1(idgest,id0,cs){
  site_popup=window.open("displg1.php?idgest="+idgest+"&id0="+id0+"&lng="+fd_lng+"&rif="+cs,'site_popup','resizable=yes,width=640,height=480,scrollbars=yes,status=no,location=no');
}



function newpopupg1(idgest,id0,cs){
  site_popup=window.open("displg1new.php?idgest="+idgest+"&id_item="+id0+"&lng="+fd_lng+"&rif="+cs,'site_popup','resizable=yes,width=780,height=500,scrollbars=yes,status=no,location=no');
}




function newpopupg1(idgest,id0,cs){
  site_popup=window.open("displg1new.php?idgest="+idgest+"&id_item="+id0+"&lng="+fd_lng+"&rif="+cs,'site_popup','resizable=yes,width=780,height=500,scrollbars=yes,status=no,location=no');
}


function newpopupg2(idgest,id0,cs){
  pXO=window.pageXOffset;
  pYO=window.pageYOffset;
  if (pXO==undefined)
    pXO=document.body.scrollLeft;
  if (pYO==undefined)
    pYO=document.body.scrollTop;
  currpg=escape("node="+fd_node+"&lng="+fd_lng+"&pXO="+pXO+"&pYO="+pYO);
  site_popup=window.open("displg2new.php?idgest="+idgest+"&id_item="+id0+"&lng="+fd_lng+fd_url2suppl+"&rif="+cs+"&currpg="+currpg,'site_popup','resizable=yes,width=640,height=480,scrollbars=yes,status=no,location=no');
}

function popupgalle(id_gallery,wmaxgalle,hmaxgalle,wmax,hmax,cs){

  if (wmaxgalle)
    wmax=Math.min(wmax,wmaxgalle);
  else
    wmax=Math.min(wmax,fd_wmaxgalle);

  if (hmaxgalle)
    hmax=Math.min(hmax,hmaxgalle);
  else
    hmax=Math.min(hmax,fd_hmaxgalle);

  w=wmax+100;
  if (w<500)
    w=500;
  h=hmax+200;
  site_popup=window.open("displgalle.php?id_gallery="+id_gallery+"&lng="+fd_lng+"&rif="+cs,'site_popup','resizable=yes,width='+w+',height='+h+',scrollbars=yes,status=no,location=no');
}

function newpopupgalle(id_gallery,wmaxgalle,hmaxgalle,wmax,hmax,cs){

  if (wmaxgalle)
    wmax=Math.min(wmax,wmaxgalle);
  else
    wmax=Math.min(wmax,fd_wmaxgalle);

  if (hmaxgalle)
    hmax=Math.min(hmax,hmaxgalle);
  else
    hmax=Math.min(hmax,fd_wmaxgalle);

  w=wmax+100;
  if (w<500)
    w=500;
  h=hmax+200;
  site_popup=window.open("newpopupgalle.php?id_gallery="+id_gallery+"&lng="+fd_lng+"&rif="+cs,'site_popup','resizable=yes,width='+w+',height='+h+',scrollbars=yes,status=no,location=no');
}


function checkEmailAddress(field){
  return field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
}


