// controllo form contatti

		function MM_findObj(n, d) { 
		  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() {
      var myForm = document.formcontatti; 
		  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.title; 
              if ((val=val.value)!="") {
			           if (((myForm.email.value != "")) && (test.indexOf('isEmail')!=-1)) {                  
                    p=val.indexOf('@');
				            if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve contenere un indirizzo e-mail valido.\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 compreso tra '+min+' e '+max+'.\n';
			               } 
                  }
              } else if (test.charAt(0) == 'R') errors += '- '+nm+' è obbligatorio.\n'; 
          }
      }
      if ((myForm.telefono.value == "") && (myForm.email.value == "")) errors+=' è obbligatorio inserire telefono o e-mail.\n';
	  if (myForm.autorizzazione[0].checked == false) errors+=' devi dare l\'autorizzazione per essere contattato.\n';
      if (errors) alert('Compila i seguenti campi:\n'+errors);
		  document.MM_returnValue = (errors == '');
		}

// Controllo nazionalità cliente



function controllo_nazione()
      {
		if (document.formcontatti.Cittadinanza[1].checked == true)
		{
			
			if (document.all)	// Explorer
				{
				//inizializzare le variabili
				document.getElementById("provinciaIT").value = "";
				document.getElementById("nazioneIT").value = "";
				
				document.getElementById("provinciaIT").style.display='none';
				document.getElementById('provinciaIT').disabled=true;
				document.getElementById('nazioneIT').style.display='none';
				document.getElementById('nazioneIT').disabled=true;
				document.getElementById("provincia").style.display='block';
				document.getElementById('provincia').disabled=false;
				document.getElementById('nazione').style.display='block';
				document.getElementById('nazione').disabled=false;
				}
			else
				{
				//inizializzare le variabili
				document.getElementById("provinciaIT").value = "";
				document.getElementById("nazioneIT").value = "";
				
				document.getElementById("provinciaIT").style.visibility = "hidden";
				document.getElementById("provinciaIT").style.display='none'; //
				document.getElementById('provinciaIT').disabled=true;
				document.getElementById("nazioneIT").style.visibility = "hidden";
				document.getElementById("nazioneIT").style.display='none'; //
				document.getElementById('nazioneIT').disabled=true;
				document.getElementById("provincia").style.visibility = "visible";
				document.getElementById("provincia").style.display='block';  //
				document.getElementById('provincia').disabled=false;
				document.getElementById("nazione").style.visibility = "visible";
				document.getElementById("nazione").style.display='block'; //
				document.getElementById('nazione').disabled=false;
				}
		}
		else if (document.formcontatti.Cittadinanza[0].checked == true)
		{
			if (document.all)	// Explorer
				{
				//inizializzare le variabili
				document.getElementById("provincia").value = "";
				document.getElementById("nazione").value = "";
				document.getElementById("nazioneIT").value = "ITALIA";
				
				document.getElementById("provinciaIT").style.display='block';
				document.getElementById('provinciaIT').disabled=false;
				document.getElementById('nazioneIT').style.display='block';
				document.getElementById('nazioneIT').disabled=false;
				document.getElementById("provincia").style.display='none';
				document.getElementById('provincia').disabled=true;
				document.getElementById('nazione').style.display='none';
				document.getElementById('nazione').disabled=true;
				}
			else
				{
				//inizializzare le variabili
				document.getElementById("provincia").value = "";
				document.getElementById("nazione").value = "";
				document.getElementById("nazioneIT").value = "ITALIA";
				
				document.getElementById("provinciaIT").style.visibility = "visible";
				document.getElementById("provinciaIT").style.display='block'; //
				document.getElementById('provinciaIT').disabled=false;
				document.getElementById("nazioneIT").style.visibility = "visible";
				document.getElementById("nazioneIT").style.display='block'; //
				document.getElementById('nazioneIT').disabled=false;
				document.getElementById("provincia").style.visibility = "hidden";
				document.getElementById("provincia").style.display='none'; //
				document.getElementById('provincia').disabled=true;
				document.getElementById("nazione").style.visibility = "hidden";
				document.getElementById("nazione").style.display='none'; //
				document.getElementById('nazione').disabled=true;
				}
			
		}
      }




//Per richiamare codice javascript

function MM_callJS(jsStr) {
  return eval(jsStr)
}

// Per resettare il form dei contatti
function resetForm() {
	document.formcontatti.reset();
}

// Per inviare i dati del form contatti
function submitForm() {
	if(document.formcontatti.onsubmit()) { 
		document.formcontatti.submit();
	}
}

