function isValidEmailAddress(emailAddress)
{
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

	return pattern.test(emailAddress);
}

$(document).ready(function()
{
	// animazione offerte in home page
	$(".offerta-row").hover(function ()
	{
		$(this).animate({ backgroundColor: "#B4CCD0" }, 100);
	}, function ()
	{
		$(this).animate({ backgroundColor: "#FAF3E3" }, 100);		
	});
	
	
	// definizione iframes
	$(".iframe18").colorbox({iframe:true, innerWidth:800, innerHeight:620});
	$(".iframe").colorbox({iframe:true, innerWidth:800, innerHeight:620});
	$(".iframe2").colorbox({iframe:true, innerWidth:980, innerHeight:620});
	$(".iframe3").colorbox({iframe:true, innerWidth:1080, innerHeight:620});
	
	
	// definizione evento errore form contatti
	$('#btnsub').click(function()
	{
       err='';
	   if (jQuery.trim($('#nome').val())=='')
	   {
		   err+="<p><strong>&bull; Non &egrave; stato inserito alcun nome!</strong></p>";
	   }
	   
	   if (jQuery.trim($('#email').val())=='')
	   {
		   err+="<p><strong>&bull; Non &egrave; stata inserita alcuna e-mail!</strong></p>";
	   }
	   else
	   {
		   if(!isValidEmailAddress($('#email').val()))
		   {
			   err+="<p><strong>&bull; Non &egrave; stato inserito un indirizzo e-mail valido!</strong></p>";
		   }
	   }
	   
	   if (jQuery.trim($('#richiesta').val())=='')
	   {
		   err+="<p><strong>&bull; Non &egrave; stata inserita alcuna richiesta!</strong></p>";
	   }
	   
	   if (!$('#privacy').is(':checked'))
	   {
		   err+="<p><strong>&bull; Non hai autorizzato al trattamento dei tuoi dati personali!</strong></p>";
	   }
   
	   if (err!='')
	   {
		   $('#alert').colorbox({width:'50%', inline:true, href:'#alert'});
		   $('#errors').html(err);
		   $('#alert').click();
	   }
	   else
	   {
		   $('#form-contatti').submit();
	   }
	   
	});
	
	
	// definizione evento errore form contatti
	$('#btnpersreq').click(function()
	{
       err='';
	   if (jQuery.trim($('#nome').val())=='')
	   {
		   err+="<p><strong>&bull; Non &egrave; stato inserito alcun nome!</strong></p>";
	   }
	   
	   if (jQuery.trim($('#email').val())=='')
	   {
		   err+="<p><strong>&bull; Non &egrave; stata inserita alcuna e-mail!</strong></p>";
	   }
	   else
	   {
		   if(!isValidEmailAddress($('#email').val()))
		   {
			   err+="<p><strong>&bull; Non &egrave; stato inserito un indirizzo e-mail valido!</strong></p>";
		   }
	   }
	   
	   if (jQuery.trim($('#tipo_richiesta').val())=='')
	   {
		   err+="<p><strong>&bull; &Egrave; necessario scegliere un tipo richiesta!</strong></p>";
	   }
	   
	   if (jQuery.trim($('#richiesta').val())=='')
	   {
		   err+="<p><strong>&bull; &Egrave; necessario descrivere al meglio la richiesta scelta con i dettagli che si reputano necessari!</strong></p>";
	   }
	   
	   if (!$('#privacy').is(':checked'))
	   {
		   err+="<p><strong>&bull; Non hai autorizzato al trattamento dei tuoi dati personali!</strong></p>";
	   }
   
	   if (err!='')
	   {
		   $('#alert').colorbox({width:'50%', inline:true, href:'#alert'});
		   $('#errors').html(err);
		   $('#alert').click();
	   }
	   else
	   {
		   $('#form-richiesta-personalizzata').submit();
	   }
	   
	});
	
});

// definizione evento errore form richiesta dettagli

function check_dati_prev(numadulti,numbamb)
{
   err='';
   if (jQuery.trim($('#nome_princ').val())=='')
   {
	   err+="<p><strong>&bull; Non &egrave; stato inserito alcun nome!</strong></p>";
   }
   if (jQuery.trim($('#cognome_princ').val())=='')
   {
	   err+="<p><strong>&bull; Non &egrave; stato inserito alcun cognome!</strong></p>";
   }
   
   if (jQuery.trim($('#email_princ').val())=='')
   {
	   err+="<p><strong>&bull; Non &egrave; stata inserita alcuna e-mail!</strong></p>";
   }
   else
   {
	   if(!isValidEmailAddress($('#email_princ').val()))
	   {
		   err+="<p><strong>&bull; Non &egrave; stato inserito un indirizzo e-mail valido!</strong></p>";
	   }
   }
   
   if (jQuery.trim($('#tel_princ').val())=='')
   {
	   err+="<p><strong>&bull; Non &egrave; stato inserito alcun numero di telefono!</strong></p>";
   }
   
   if (jQuery.trim($('#n_pers').val())=='')
   {
	   err+="<p><strong>&bull; Non &egrave; stato inserito il numero adulti!</strong></p>";
   }
   
   if (!$('#privacycheck').is(':checked'))
   {
	   err+="<p><strong>&bull; Non hai autorizzato al trattamento dei tuoi dati personali!</strong></p>";
   }

   if (err!='')
   {
	   $('#alert').colorbox({width:'50%', inline:true, href:'#alert'});
	   $('#errors').html(err);
	   $('#alert').click();
   }
   else
   {
	   $('#form_richprev').submit();
   }
   
};

