
function cancella_mail(campo){
		if (campo.value=="la tua e-mail"){
			campo.value="";
		}
		else if (campo.value==""){
			campo.value="la tua e-mail";
		}
	}

 function eseguiRichiesta_nl(url,parameters) {

        var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // Vedi note sotto
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Non riesco a creare una istanza XMLHTTP');
            return false;
        }
          http_request.onreadystatechange = function() { alertContents_nl(http_request); };		  
          http_request.open('POST', url, true);
          http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		  http_request.setRequestHeader("Content-length", parameters.length);
		  http_request.setRequestHeader("Connection", "close");
		  http_request.send(parameters);

    }

    function alertContents_nl(http_request) {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				result = http_request.responseText;
              document.getElementById('newsletter').innerHTML = result; 
			  //document.getElementById('loader').src="images/bianco.jpg";
            } else {
                alert('Si è verificato un problema con la richiesta');
            }
        }

    }

    
   function get_newsletter(mail,page,dom,root) {     
	StrMail=document.getElementById('mailing-list-text').value;
	if (StrMail.length>6){
	  var pos;
	  var dotpos;
	  pos = StrMail.indexOf("@");
	  if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
		 {
		alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mailing-list-text').focus();
		 return (false);		 
		 }
	  pos=pos+1;
	  dotpos = StrMail.indexOf(".", pos);
	  if (dotpos > (StrMail.length-3) )
		 {
		alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mailing-list-text').focus();
		 return (false);
		 }
	  Strmail=StrMail.substr(pos);
	  if ( (StrMail.length < 5) || (dotpos <= 0) )
		 {			 
		 alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mailing-list-text').focus();
		 return (false);
		 }
	  }
   else
	  {
	  alert("Il campo email non è stato inserito nel formato corretto.");
	  document.getElementById('mailing-list-text').focus();
	  return (false);
	  }
	 var post_z ='mail='+ mail+'&page='+page+'&iddom='+dom;
	 document.getElementById('newsletter').innerHTML = "iscrizione in corso... <img src=\""+root+"/images/ajax-loader_1.gif\">";	
	 eseguiRichiesta_nl(root+'/news_letter_ajax.php', post_z);
	 return(false);
   }
   
   function del_newsletter(mail,page) {	
	StrMail=document.getElementById('mailing-list-text').value;
	if (StrMail.length>6){
	  var pos;
	  var dotpos;
	  pos = StrMail.indexOf("@");
	  if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
		 {
		alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mailing-list-text').focus();
		 return (false);		 
		 }
	  pos=pos+1;
	  dotpos = StrMail.indexOf(".", pos);
	  if (dotpos > (StrMail.length-3) )
		 {
		alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mailing-list-text').focus();
		 return (false);
		 }
	  Strmail=StrMail.substr(pos);
	  if ( (StrMail.length < 5) || (dotpos <= 0) )
		 {			 
		 alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mailing-list-text').focus();
		 return (false);
		 }
	  }
   else
	  {
	  alert("Il campo email non è stato inserito nel formato corretto.");
	  document.getElementById('mailing-list-text').focus();
	  return (false);
	  }	
	 var post_z ='mail='+ mail+'&page='+page;
	 document.getElementById('newsletter').innerHTML = "<h3>cancellazione in corso... <img src=\"images/ajax-loader_1.gif\"></h3>"; 
	 eseguiRichiesta_nl('news_letter_ajax.php', post_z);
	 return(false);
   }


function eseguiRichiesta_com(url,parameters,id) {

        var http_request = false;
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // Vedi note sotto
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Non riesco a creare una istanza XMLHTTP');
            return false;
        }
          http_request.onreadystatechange = function() { alertContents_com(http_request,id); };
          http_request.open('POST', url, true);
          http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		  http_request.setRequestHeader("Content-length", parameters.length);
		  http_request.setRequestHeader("Connection", "close");
		  http_request.send(parameters);

    }

    function alertContents_com(http_request,id) {

        if (http_request.readyState == 4) {			
            if (http_request.status == 200) {				
				result = http_request.responseText;	
				if(id==1){
					document.getElementById('comuni').innerHTML = result;	
				}else{
					window.opener.document.getElementById('comuni').innerHTML = result;
				}
              document.getElementById('comuni').innerHTML = result;			  
            } else {
                alert('Si è verificato un problema con la richiesta');
            }
        }

    }

   
   function carica_comuni(id_prov,id){
	var poststr ="";	
	poststr='id_prov='+id_prov;
	if(id==1){
		document.getElementById('comuni').innerHTML="<em>attendere la selezione dei comuni di appartenenza alla provincia selezionata...</em>";
	}else{
		window.opener.document.getElementById('comuni').innerHTML="<em>attendere la selezione dei comuni di appartenenza alla provincia selezionata...</em>";
	}
	eseguiRichiesta_com('comuni_ajax.php', poststr,id);
} 


function cambia_tipo(){
	 if((document.getElementById('tipologia').value=="1")||(document.getElementById('tipologia').value=="2")){
		 document.getElementById("set_part").style.display="block";
		 document.getElementById("nome_partner").value="";
	}else{
		document.getElementById("set_part").style.display="none";
		document.getElementById("nome_partner").value="";
		}
}


function cambia_mark(){
	 if(document.getElementById('motivazione').value=="1"){
		 document.getElementById("set_prov").style.display="block";
	}else{
		document.getElementById("set_prov").style.display="none";
		}
}
 function vai_a(idstr){
	 window.location=idstr;
	 }
	
function vai_a_old(idstr){
	 window.location='index3.php?idstruttura='+idstr;
	 }
 
 function vai_a_red(url){
	 window.location=url;
	 }
 
 
 function controlloModulo_reality_1(){
	
	if(document.getElementById('nome').value==""){
		 alert("campo NOME mancante!");
		 document.getElementById('nome').focus();
		 return (false);
		 }	 
 
	if(document.getElementById('cognome').value==""){
		 alert("campo COGNOME mancante!");
		 document.getElementById('cognome').focus();
		 return (false);
		 }	

if(document.getElementById('via').value==""){
		 alert("campo VIA  mancante!");
		 document.getElementById('via').focus();
		 return (false);
		 }		
			 
if(document.getElementById('citta').value==""){
		 alert("campo CITTA  mancante!");
		 document.getElementById('citta').focus();
		 return (false);
		 }		
	
	if(document.getElementById('provincia').value==""){
		 alert("campo PROVINCIA  mancante!");
		 document.getElementById('provincia').focus();
		 return (false);
		 }	
	
	if(document.getElementById('mail').value==""){
		 alert("campo E-MAIL mancante!");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	 
	 if(document.getElementById('telefono').value==""){
		 alert("campo TELEFONO mancante!");
		 document.getElementById('telefono').focus();
		 return (false);
		 }	
		

	StrMail=document.getElementById('mail').value;
   if (StrMail.length>6){
	  var pos;
	  var dotpos;
	  pos = StrMail.indexOf("@");
	  if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
		 {
		alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mail').focus();
		 return (false);		 
		 }
	  pos=pos+1;
	  dotpos = StrMail.indexOf(".", pos);
	  if (dotpos > (StrMail.length-3) )
		 {
		alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	  Strmail=StrMail.substr(pos);
	  if ( (StrMail.length < 5) || (dotpos <= 0) )
		 {			 
		 alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	  }
   else
	  {
	  alert("Il campo email non è stato inserito nel formato corretto.");
	  document.getElementById('mail').focus();
	  return (false);
	  }
		
	 if(document.getElementById('privacy').checked==0){
		 alert("informativa sulla privacy non accettata!");		 
		 return (false);
		 }
	if(document.getElementById('key').value==""){
		 alert("codice di controllo mancante!");
		 document.getElementById('key').focus();
		 return (false);
		 }
	document.getElementById('action').value="invia";
	return (true);
	//window.location='index3.php?idstruttura='+idstr+'&action=invia';
}
 
 function controlloModulo_reality(){
	
	if(document.getElementById('nome_sposa').value==""){
		 alert("campo NOME SPOSA mancante!");
		 document.getElementById('nome_sposa').focus();
		 return (false);
		 }	 
 
	if(document.getElementById('nome_sposo').value==""){
		 alert("campo NOME SPOSO mancante!");
		 document.getElementById('nome_sposo').focus();
		 return (false);
		 }	
	
	if(document.getElementById('data_in').value==""){
		 alert("campo DATA MATRIMONIO mancante!");
		 document.getElementById('data_in').focus();
		 return (false);
	//}else{
		//var diff=validateDate_anni(document.getElementById('data_in').value,"W","P");
	//	if (validateDate(document.getElementById('data_in').value,"W","F")==false){
	//		 alert("La data del matrimonio deve essere successiva alla data odierna");
	//		 document.getElementById('data_in').focus();
	//		 return (false);
	//		}
	}
	
	if(document.getElementById('id_provincia').value==""){
		 alert("campo PROVINCIA MATRIMONIO mancante!");
		 document.getElementById('id_provincia').focus();
		 return (false);
		 }	
	
	if(document.getElementById('mail').value==""){
		 alert("campo E-MAIL mancante!");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	 
	 if(document.getElementById('telefono').value==""){
		 alert("campo TELEFONO mancante!");
		 document.getElementById('telefono').focus();
		 return (false);
		 }	
	
	if(document.getElementById('motivazione').value=="0"){		
		 alert("campo COME CI HAI CONOSCIUTO mancante!");
		 document.getElementById('motivazione').focus();
		 return (false);
	 }	
	

	StrMail=document.getElementById('mail').value;
   if (StrMail.length>6){
	  var pos;
	  var dotpos;
	  pos = StrMail.indexOf("@");
	  if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
		 {
		alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mail').focus();
		 return (false);		 
		 }
	  pos=pos+1;
	  dotpos = StrMail.indexOf(".", pos);
	  if (dotpos > (StrMail.length-3) )
		 {
		alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	  Strmail=StrMail.substr(pos);
	  if ( (StrMail.length < 5) || (dotpos <= 0) )
		 {			 
		 alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	  }
   else
	  {
	  alert("Il campo email non è stato inserito nel formato corretto.");
	  document.getElementById('mail').focus();
	  return (false);
	  }
		
	 if(document.getElementById('privacy').checked==0){
		 alert("informativa sulla privacy non accettata!");		 
		 return (false);
		 }
	if(document.getElementById('key').value==""){
		 alert("codice di controllo mancante!");
		 document.getElementById('key').focus();
		 return (false);
		 }
	document.getElementById('action').value="invia";
	return (true);
	//window.location='index3.php?idstruttura='+idstr+'&action=invia';
}
  
 
function validateDate(fld,fmt,rng) {
var dd, mm, yy;
var today = new Date;
var t = new Date;
fld = stripBlanks(fld);

if (fld == '') return false;
var d1 = fld.split('/');



if (d1.length != 3) d1 = fld.split(' ');
if (d1.length != 3) return false;
if (fmt == 'u' || fmt == 'U') {
  dd = d1[1]; mm = d1[0]; yy = d1[2];}
else if (fmt == 'j' || fmt == 'J') {
  dd = d1[2]; mm = d1[1]; yy = d1[0];}
else if (fmt == 'w' || fmt == 'W'){
  dd = d1[0]; mm = d1[1]; yy = d1[2];}
else return false;
var n = dd.lastIndexOf('st');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('nd');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('rd');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('th');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf(',');
if (n > -1) dd = dd.substr(0,n);
n = mm.lastIndexOf(',');
if (n > -1) mm = mm.substr(0,n);
if (!isNum(dd)) return false;
if (!isNum(yy)) return false;
if (!isNum(mm)) {
  var nn = mm.toLowerCase();
  for (var i=1; i < 13; i++) {
    if (nn == mth[i] ||
        nn == mth[i].substr(0,3)) {mm = i; i = 13;}
  }
}
if (!isNum(mm)) return false;
dd = parseFloat(dd); mm = parseFloat(mm); yy = parseFloat(yy);
if (yy < 100) yy += 2000;
if (yy < 1582 || yy > 4881) return false;
if (mm == 2 && (yy%400 == 0 || (yy%4 == 0 && yy%100 != 0))) day[mm-1]++;
if (mm < 1 || mm > 12) return false;
if (dd < 1 || dd > day[mm-1]) return false;
t.setDate(dd); t.setMonth(mm-1); t.setFullYear(yy);
if (rng == 'p' || rng == 'P') {
if (t > today) return false;
}
else if (rng == 'f' || rng == 'F') {
if (t < today) return false;
}
else if (rng != 'a' && rng != 'A') return false;
return true;
}
 function stripBlanks(fld) {var result = "";for (i=0; i<fld.length; i++) {
if (fld.charAt(i) != " " || c > 0) {result += fld.charAt(i);
if (fld.charAt(i) != " ") c = result.length;}}return result.substr(0,c);}
 
 function controlloModulo_contatto(){
	
	 if(document.getElementById('motivazione').value=="1"){
		if(document.getElementById('id_provincia').value==""){
		 alert("campo PROVINCIA mancante!");
		 document.getElementById('id_provincia').focus();
		 return (false);
		 }	 
	 }	
	
	if(document.getElementById('nome').value==""){
		 alert("campo NOME mancante!");
		 document.getElementById('nome').focus();
		 return (false);
		 }	
	 if(document.getElementById('mail').value==""){
		 alert("campo E-MAIL mancante!");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	
	StrMail=document.getElementById('mail').value;
   if (StrMail.length>6){
	  var pos;
	  var dotpos;
	  pos = StrMail.indexOf("@");
	  if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
		 {
		alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mail').focus();
		 return (false);		 
		 }
	  pos=pos+1;
	  dotpos = StrMail.indexOf(".", pos);
	  if (dotpos > (StrMail.length-3) )
		 {
		alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	  Strmail=StrMail.substr(pos);
	  if ( (StrMail.length < 5) || (dotpos <= 0) )
		 {			 
		 alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	  }
   else
	  {
	  alert("Il campo email non è stato inserito nel formato corretto.");
	  document.getElementById('mail').focus();
	  return (false);
	  }
	
	
	 if(document.getElementById('telefono').value==""){
		 alert("campo TELEFONO mancante!");
		 document.getElementById('telefono').focus();
		 return (false);
		 }
	 if(document.getElementById('privacy').checked==0){
		 alert("informativa sulla privacy non accettata!");		 
		 return (false);
		 }
	if(document.getElementById('key').value==""){
		 alert("codice di controllo mancante!");
		 document.getElementById('key').focus();
		 return (false);
		 }
	document.getElementById('action').value="invia";
	return (true);
	//window.location='index3.php?idstruttura='+idstr+'&action=invia';
}
 
 function controlloModulo(){
	 
	 if(document.getElementById('nome').value==""){
		 alert("campo NOME mancante!");
		 document.getElementById('nome').focus();
		 return (false);
		 }
	 if(document.getElementById('cognome').value==""){
		 alert("campo COGNOME mancante!");
		 document.getElementById('cognome').focus();
		 return (false);
		 }
	 if(document.getElementById('mail').value==""){
		 alert("campo E-MAIL mancante!");
		 document.getElementById('mail').focus();
		 return (false);
		 }
  
	 if(document.getElementById('telefono').value==""){
		 alert("campo TELEFONO mancante!");
		 document.getElementById('telefono').focus();
		 return (false);
		 }	 
	 val=document.getElementById('datepicker').value
	 if((val=="gg/mm/aaaa")||(val.substr(2,1)!="/")||(val.substr(5,1)!="/")){
		 alert("campo DATA CERIMONIA mancante o errata!");
		 document.getElementById('datepicker').focus();
		 return (false);
		 }
		 
		 
	 if(document.getElementById('note').value==""){
		 alert("campo SERVIZI RICHIESTI mancante!");
		 document.getElementById('note').focus();
		 return (false);
		 }	 
		 
	/*val=document.getElementById('data_out').value
	 if((val=="gg/mm/aaaa")||(val.substr(2,1)!="/")||(val.substr(5,1)!="/")){
		 alert("campo DATA FINE CERIMONIA mancante o errata!");
		 document.getElementById('data_out').focus();
		 return (false);
		 } */
		 


	
	if(document.getElementById('privacy').checked==0){
		 alert("informativa sulla prinacy non accettata!");		 
		 return (false);
		 }
	
	StrMail=document.getElementById('mail').value;
	if (StrMail.length>6){
	  var pos;
	  var dotpos;
	  pos = StrMail.indexOf("@");
	  if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
		 {
		alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mail').focus();
		 return (false);		 
		 }
	  pos=pos+1;
	  dotpos = StrMail.indexOf(".", pos);
	  if (dotpos > (StrMail.length-3) )
		 {
		alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	  Strmail=StrMail.substr(pos);
	  if ( (StrMail.length < 5) || (dotpos <= 0) )
		 {			 
		 alert("Il campo email non è stato inserito nel formato corretto.");
		 document.getElementById('mail').focus();
		 return (false);
		 }
	  }
   else
	  {
	  alert("Il campo email non è stato inserito nel formato corretto.");
	  document.getElementById('mail').focus();
	  return (false);
	  }
	 if(document.getElementById('key').value==""){
		 alert("codice di controllo mancante!");
		 document.getElementById('key').focus();
		 return (false);
		 }
	document.getElementById('action').value="invia";
	return (true);
	//window.location='index3.php?idstruttura='+idstr+'&action=invia';
}
 
 
   
   function eseguiRichiesta(url,parameters) {

        var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // Vedi note sotto
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Non riesco a creare una istanza XMLHTTP');
            return false;
        }
          http_request.onreadystatechange = function() { alertContents(http_request); };		  
          http_request.open('POST', url, true);
          http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		  http_request.setRequestHeader("Content-length", parameters.length);
		  http_request.setRequestHeader("Connection", "close");
		  http_request.send(parameters);

    }

    function alertContents(http_request) {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				result = http_request.responseText;
              document.getElementById('ricerca_prov').innerHTML = result; 
			  document.getElementById('loader').src="images/bianco.jpg";
            } else {
                alert('Si è verificato un problema con la richiesta');
            }
        }

    }

    
   function get_ricerca_prov(zona,reg) {
     
	 var post_z ='zona=' + zona +'& reg=' + reg;
	 //var post_r ='reg=' + reg;
	 //alert(post_z+post_r+post_p);
	 //alert("zona="+post_z);
	 eseguiRichiesta('ricerca_prov_ajax.php', post_z);	 
   }
   
   function prova(){alert("prova ok");}
   
	function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function change(PERCORSO){

	document.getElementById("altre_foto_principale").style.background="url("+PERCORSO+") top center";
}

function change_1(PERCORSO){

	document.getElementById("loader").src=PERCORSO;
}



