function checkPartecipa(form){

	nome = document.partecipa.nome.value
	cognome = document.partecipa.cognome.value
	indirizzzo = document.partecipa.indirizzo.value
	numero = document.partecipa.indirizzo_num.value
	citta = document.partecipa.citta.value
	provincia = document.partecipa.provincia.value
	cap = document.partecipa.cap.value
	tel = document.partecipa.telefono.value
	email = document.partecipa.email.value
	autoriz = document.partecipa.autoriz.value
	
	

	
    	
	if(cap!=""){
		 if ( cap == "" || cap == null || isNaN(cap)  || cap.charAt(0) == ' '  || (cap.length != 5)) {
		    alert('CAP non valido');
		    return false;
		}
		
	} 
	
	
	
	if(email!=""){ 
		if (!indirizzoEmailValido(email)) {
				alert("Indirizzo email non valido");
				return false;
		} 
		 
		
	}
	
	if (nome!="" && cognome!="" && indirizzzo!="" && numero!="" && citta!="" && provincia!="" && cap!="" && tel!="" && email!="") {
		
		 if (document.partecipa.autoriz.checked==false) {
				alert('Per procedere con l\'invio del modulo e\' necessario accettare le condizioni presenti nell\'informativa.');
				return false;	
	    		}  
    		
    	}
	
	
	  else {
	    return true;
	}
}



function indirizzoEmailValido(indirizzo) {
  if (window.RegExp) {
    var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    var regnv = new RegExp(nonvalido);
    var regv = new RegExp(valido);
    if (!regnv.test(indirizzo) && regv.test(indirizzo))
      return true;
    return false;
	}
  else {
    if(indirizzo.indexOf("@") >= 0)
      return true;
    return false;
  	}
  };


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function checkNewsletter(form){

	nome = document.subscribe.firstName.value
	cognome = document.subscribe.lastName.value
	email = document.subscribe.email.value

	if ( nome == "" || nome == "nome*" || nome == null || !isNaN(nome) || nome.charAt(0) == ' ') {
	    alert('Nome non valido');
	    return false;
	}
	else if ( cognome == "" || cognome == "cognome*" || cognome == null || !isNaN(cognome)  || cognome.charAt(0) == ' ') {
	    alert('Cognome non valido');
	    return false;
	}
	else if ((email== "") || email == null || !isNaN(email) || email.charAt(0) == ' ' || (email.indexOf ('@') == -1) || (email.indexOf ('.') == -1)){
    	alert('Indirizzo email non valido');	
        return false;
    }
	else if(document.subscribe.checkbox.checked==false) {
		alert('Per procedere con l\'invio del modulo e\' necessario accettare le condizioni presenti nell\'informativa.');
		return false;	
    }
	else {
	    return true;
	}
}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function ShowHide(id1, id2) {
	  if (id1 != '') expMenu(id1);
	  if (id2 != '') expMenu(id2);
	}

	function expMenu(id) {
	  var itm = null;
	  if (document.getElementById) {
		itm = document.getElementById(id);
	  } else if (document.all){
		itm = document.all[id];
	  } else if (document.layers){
		itm = document.layers[id];
	  }

	  if (!itm) {
	  }
	  else if (itm.style) {
		if (itm.style.display == "none") { itm.style.display = ""; }
		else { itm.style.display = "none"; }
	  }
	  else { itm.visibility = "show"; }
	}
    //-->




//// show hide ////
var sdata;
var data;
var status;

function toggle(box,img) {
   sdata = getName();
      status = "open";
      if(sdata=='closed'){status = "open";}
          	   if (document.getElementById(box).style.display == "block") {
		           status = "closed";
		           document.getElementById(box).style.display = "none";
		           document.getElementById(img).src = "images/boton_info.gif";
	      	   } else {
	      
	           status = "open";
	           document.getElementById(box).style.display = "block";
	           document.getElementById(img).src = "images/boton_info_menos.gif";
	           }
      putCookie(box,status); 
}

function putCookie(box,status) {
   if (document.cookie != document.cookie) {
      index = document.cookie.indexOf(box);
   } else {
      index = -1;
   }

   if (index == -1) {
      document.cookie = box+"="+status; 
   }
}

function getName(boxname) {
   if(document.cookie) {
      index = document.cookie.indexOf(boxname);
      if (index != -1) {
         namestart = (document.cookie.indexOf("=", index) + 1);
         nameend = document.cookie.indexOf(";", index);
         if (nameend == -1) {
            nameend = document.cookie.length;
         }

         data = document.cookie.substring(namestart, nameend);
         return data;
      }
   }

}

function check() {

split(document.cookie);
	
	 var tab1 = getName('tab1');
		 if (tab1=='open') {
		 	document.getElementById('tab1').style.display = "block";
		 	document.getElementById('tab1img').src = "images/icon_less_a.gif";
		 } else {
		 	document.getElementById('tab1').style.display = "none";
		 	document.getElementById('tab1img').src = "images/boton_info.gif";
		 }	 
	 var tab2 = getName('tab2');
		 if (tab2=='open') {
		 	document.getElementById('tab2').style.display = "block";
		 	document.getElementById('tab2img').src = "images/icon_less_a.gif";
		 } else {
		 	document.getElementById('tab2').style.display = "none";
		 	document.getElementById('tab2img').src = "images/boton_info.gif";
		 }
		 
}



function split(string) {
if(string.length>1){
  var result = new makeArray(); 
  i = 0;
  j = string.indexOf(";");
  if ( j==-1 )
    j = string.length;
  n = 0;
  while ( j!=-1 ) {
     result[n] = string.substring(i,j);
     var str = trim(result[n])
    		var stringa = str.substring(0,str.indexOf('='));
     
     		var ck = getName(stringa);
     		
			
		 	
		 	
		 if (ck=='open') {
		 document.getElementById(stringa).style.display = "block";
		 	document.getElementById(stringa+'img').src = "images/boton_info.gif";
		 } else if(ck=='closed') {
		 	document.getElementById(stringa).style.display = "none";
		 	document.getElementById(stringa+'img').src = "images/icon_less_a.gif";
		 } 
     
     
	     if ( j==string.length )
	      break;
	    i = j+1;
	    j = string.indexOf(";",i);
	    if ( j==-1 )
	      j = string.length;
	      
	      
	       
      
    n++;
  }

}
}

function makeArray(n) {
   this.length = n;
   while ( n>=0 )
   this[n--] = null;
   return this; 
}

function trim(text)
{
    while(text.charAt(text.length-1) == " ")
    {
        text = text.substring(0, text.length-1);
    }
    while(text.charAt(0)==" ")
    {
        text = text.substring(1);
    }
    return text;

} 

function openAll(string) {
	document.getElementById('chiudi').style.display = "block";
	document.getElementById('apri').style.display = "none";	
	var num = string;	
	for(i=1;i<=num;i++){
		eval("document.getElementById('tab"+i+"').style.display = 'block';");
		eval("document.getElementById('tab"+i+"img').src = 'images/icon_less_a.gif';");
	}
}

function closeAll(string) {
	document.getElementById('chiudi').style.display = "none";
	document.getElementById('apri').style.display = "block";	
	var num = string;	
	for(i=1;i<=num;i++){
		eval("document.getElementById('tab"+i+"').style.display = 'none';");
		eval("document.getElementById('tab"+i+"img').src = 'images/boton_info.gif';");
	}
}


//// agenzie ////
function controllo(theForm){
  if (theForm.provincia.value == "XX")

  {
   	alert("Scegliere la provincia");
	theForm.provincia.focus();
    return (false);
  }
  return (true);
}

function isnum(obj) {
	if (obj.value.length > 0){
		if (isNaN(obj.value) || parseInt(obj.value)<0 || parseInt(obj.value) > 99999){
				alert('Il cap deve essere numerico');
				obj.value="";
				obj.focus();
		}
	}
}