function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve contenere un indirizzo e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' deve contenere un numero.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' deve contenere un numero tra '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' è richiesto.\n'; }
  } if (errors) alert('Si è verificato il seguente errore:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function ver(){
 if(document.contatti.accetto_privacy[1].checked==true){
  alert('La richiesta non può essere processata.\nSi prega di spuntare il check box per il trattamento dei dati personali.')
  return false;
 }
}

function popup(str) {
searchWin =window.open(str,'popup','scrollbars=yes,resizable=yes,width=600,height=500,status=no,location=no,toolbar=no');
}

function popupstampa(str) {
searchWin =window.open(str,'popup','scrollbars=yes,resizable=yes,width=760,height=660,status=no,location=no,toolbar=no');
}

function IsDate(val)
{
var err=0;
var counter=0;
if(val!="")
	{
	if(val.length!=10)
		{
		alert('La lunghezza della data non e\' corretta');
		return "";
		}
	if(val.charAt(2)!='/') err++; 
	if(val.charAt(5)!='/') err++;
	if(err!=0) 
		{
		alert('Non hai utilizzato il separatore corretto');return "";
		}
	err=0;
	var day=val.substring(0,2)
	if(isNaN(day))
		{
		alert('Il giorno non e\' un numero');
		err++;
		return "";
		}
	
	if(day>31||day<1)	
		{
		alert('Errore nella formattazione del giorno');
		return "";
		}

	var month=val.substring(3,5);

	if(isNaN(month)) {alert('Il mese non e\' un numero');err++;return -5;}

	if(month>12||month<1){
		alert('Errore nella formattazione del mese');
		return "";
	}
	var year=val.substring(val.length-4,val.length);

	if(isNaN(year)) {alert('L\'anno non e\' un numero');err++; return "";}
 if (month=='04' || month=='06' || month=='09' || month=='11'){
  if (day>30)
	{alert('Questo mese ha 30 giorni');}
	}

 var bisest=String(year/4);
 if (month=='02'){
  if ( (bisest.indexOf(".")!=-1 && day>28) || (bisest.indexOf(".")==-1 && day>29) )
   {alert('Data Inesistente'); }
 }
return val;
}
}

function SeparaData(val) {
if (val.length > 10) { alert('Data troppo lunga !'); }
if (val.length == 10) { return val; }
if (val.length == 2) { val = val + "/";}
if (val.length == 5) { val = val + "/";}
return val;
}

 function printpage()
{
  if (window.print)
  {
    window.print();
  }
  else
  {
    alert('Funzione stampa non supportata da questo browser.');
  }
}
 
 