//	UNIFORM
jQuery(function(){
	jQuery("textarea, select").uniform();
});

//	PLACEHOLDER
jQuery(function(){
	$('input, input[type=password]').placeholder();
});

//	MOSTRA NASCONDI FORM RICERCA
jQuery(function(){
jQuery("a#sh").click(function () {
	if (jQuery("#ricerca-dettagliata").is(":hidden")) {
		jQuery("#ricerca-dettagliata").slideDown("slow");
		jQuery(this).text("Chiudi ricerca");
		
	} else {
		jQuery("#ricerca-dettagliata").slideUp();
		jQuery(this).text("Nuova ricerca");
	}
});
});

//	MOSTRA FORM RICERCA NELLA PAGINA DI RICERCA
jQuery(function(){
	jQuery(".ricerca #ricerca-dettagliata").slideDown("slow");
	jQuery(".ricerca #sh").text("Chiudi ricerca");
});


//	TABS
jQuery(function(){
	jQuery("#tabs").tabs({ fx: { opacity: 'toggle' } });
});

//	FANCYBOX
jQuery(function(){
	jQuery("a.fancy").attr('rel', 'gallery').fancybox({
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false,
		'showNavArrows' :	true,
		'cyclic'		:	true,
		'padding'		:	'1'
	});
});

//	MOSTRA NASCONDI FORM LOGIN
/*
jQuery(function(){
jQuery("a.login").click(function () {
	if (jQuery("#login-form").is(":hidden")) {
		jQuery("#login-form").show("slide", { direction: "right" }, 200);
		// due to ie6 
		jQuery(".ie6 .log-in").width(345);
		
	} else {
		jQuery("#login-form").hide("slide", { direction: "right" }, 200);
		// due to ie6 
		jQuery(".ie6 .log-in").width(85);
	}
});
});*/
//	APRE I LINK CON REL = EXTERNAL IN UN'ALTRA FINESTRA
jQuery(function(){
	jQuery("a[rel^='external']").click(function(){
	window.open(this.href);
	return false;
	});
});
//	AUTOCOMPLETE
jQuery(function(){
	function log(event, data, formatted) {
		$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
	}
	function formatItem(row) {
		return row[0] + " (<strong>id: " + row[1] + "</strong>)";
	}
	function formatResult(row) {
		return row[0].replace(/(<.+?>)/gi, '');
	}
	$("#txt_localitas").autocomplete(cities);
});
// MODAL PER IL PULSANTE DISPONIBILITA'
jQuery(function(){
	$(".btn-disponibilita").fancybox({
		ajax : {
				    type	: "GET"
				}
	});
});
// MODAL PER IL PULSANTE VISUALIZZA FOTO
jQuery(function(){
	$(".btn-foto").fancybox({
		'width':840,
		'height':640,
		'padding':0,
		'margin':0,
		'autoScale':false,
		'autoDimensions':false,
		'overlayShow':true,
		'overlayOpacity':0.6,
		'type':'iframe',
		'cyclic':false,
		'scrolling':'no'
	});
});
// MODAL PER IL PULSANTE CONTATTA PROPRIETARIO
jQuery(function(){
	$(".btn-modal").fancybox({
		'margin'			: 0,
		'padding' 			: 0,
		'autoDimensions' 	: true,
		'height'			: 440,
		'width' 			: 780,
		'type'				: 'iframe',
		'titleShow'			: false
	});
	$("#modal-form").bind("submit", function() {
	
	//Get the data from all the fields
	var nome = $('input[name=nome]');
	var surname = $('input[name=cognome]');
	var email = $('input[name=email]');
	var messaggio = $('textarea#messaggio');
	var telefono = $('input[name=telefono]');
	var adulti = $('input[name=adulti]');
	var bambini = $('input[name=bambini]');
        var code = $('input[name=code]');
	var error = 0;

	if (nome.val()=='') {
		nome.addClass('hightlight');
               
	    error = 1;
	} else nome.removeClass('hightlight');

	if (surname.val()=='') {
		surname.addClass('hightlight');
	     error = 1;
	} else surname.removeClass('hightlight');
	
	if (email.val()=='') {
		email.addClass('hightlight');
	     error = 1;
	} else email.removeClass('hightlight');
	
	if (messaggio.val()=='') {
		messaggio.addClass('hightlight');
	    error = 1;
	} else messaggio.removeClass('hightlight');

        if (code.val()=='') {
		code.addClass('hightlight');
	     error = 1;
	} else code.removeClass('hightlight');

	if (telefono.val()=='') {
		telefono.addClass('hightlight');
               
	    error = 1;
	} else telefono.removeClass('hightlight');

	if (adulti.val()=='') {
		adulti.addClass('hightlight');
               
	    error = 1;
	} else adulti.removeClass('hightlight');

	if (bambini.val()=='') {
		bambini.addClass('hightlight');
               
	    error = 1;
	} else bambini.removeClass('hightlight');

	if (bambini.val()=='') {
		messaggio.addClass('hightlight');
               
	    error = 1;
	} else messaggio.removeClass('hightlight');

	if(error==1) return false;




        // Ulteriori controllo inseriti da Andrea

        Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
        if (Filtro.test(email.val())){
            email.removeClass('hightlight');
        }
        else
        {
            email.addClass('hightlight');
            return false;
        }




		
		$.fancybox.showActivity();
	
		$.ajax({
			type		: "POST",
			cache		: false,
			url			: "contatta.php",
			data		: $(this).serializeArray(),
			success: function(data) {
				$.fancybox({
				content				: data, 
				showCloseButton 	: false,
				hideOnContentClick	: true,
				'onClosed'			: function() {
						    			parent.$.fancybox.close();
									}
				});

			}
		});
		return false;
	});
});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MODAL PER IL PULSANTE CONTATTA PROPRIETARIO
jQuery(function(){
	$(".btn-modal").fancybox({
		'margin'			: 0,
		'padding' 			: 0,
		'autoDimensions' 	: true,
		'height'			: 440,
		'width' 			: 780,
		'type'				: 'iframe',
		'titleShow'			: false
	});
	$("#modal-form").bind("submit", function() {

	//Get the data from all the fields
	var name = $('input[name=nome]');
	var surname = $('input[name=cognome]');
	var email = $('input[name=email]');
	var messaggio = $('input[name=messaggio]');
        var code = $('input[name=code]');

	if (name.val()=='') {
		//name.addClass('hightlight');

	    return false;
	} else name.removeClass('hightlight');

	if (surname.val()=='') {
		surname.addClass('hightlight');
	    return false;
	} else surname.removeClass('hightlight');

	if (email.val()=='') {
		email.addClass('hightlight');
	    return false;
	} else email.removeClass('hightlight');

	if (messaggio.val()=='') {
		messaggio.addClass('hightlight');
	    return false;
	} else messaggio.removeClass('hightlight');

        if (code.val()=='') {
		code.addClass('hightlight');
	    return false;
	} else code.removeClass('hightlight');




        // Ulteriori controllo inseriti da Andrea

        Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
        if (Filtro.test(email.val())){
            email.removeClass('hightlight');
        }
        else
        {
            email.addClass('hightlight');
            return false;
        }





		$.fancybox.showActivity();

		$.ajax({
			type		: "POST",
			cache		: false,
			url			: "contatta.php",
			data		: $(this).serializeArray(),
			success: function(data) {
				$.fancybox({
				content				: data,
				showCloseButton 	: false,
				hideOnContentClick	: true,
				'onClosed'			: function() {
						    			parent.$.fancybox.close();
									}
				});

			}
		});
		return false;
	});
});

// MODAL PER contatti
jQuery(function(){

        $(".contatti").bind("submit", function() {
	//Get the data from all the fields

	var email = $('input[name=email]');
        var telefono = $('input[name=telefono]');
         var nome = $('input[name=nome]');
          var cognome = $('input[name=cognome]');

	if (email.val()=='') {
		email.addClass('hightlight');
	    return false;
	} else email.removeClass('hightlight');

        if (telefono.val()=='') {
		telefono.addClass('hightlight');
	    return false;
	} else telefono.removeClass('hightlight');



        if (nome.val()=='') {
		nome.addClass('hightlight');
	    return false;
	} else nome.removeClass('hightlight');


        if (cognome.val()=='') {
		cognome.addClass('hightlight');
	    return false;
	} else cognome.removeClass('hightlight');



        // Ulteriori controllo inseriti da Andrea

        Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
        if (Filtro.test(email.val())){
            email.removeClass('hightlight');
            return true;
        }
        else
        {
            email.addClass('hightlight');
            return false;
        }
	});
});



// Modal per ricerca avanzata

// MODAL PER contatti
jQuery(function(){

        $("#modulo").bind("submit", function() {
	//Get the data from all the fields

	var localita = $('select[name=localita]');


	if (localita.val()=='') {

           var messag="Attenzione, scegliere almeno una citta prima di andare avanti";
		$('#errmess').text(messag);

               

	    return false;
	} else localita.removeClass('hightlight');



        if (localita.val()=='0') {
	var messag="Attenzione, scegliere almeno una citta prima di andare avanti";
		$('#errmess').text(messag);

             

	    return false;
	} 


 


        // Ulteriori controllo inseriti da Andrea

        Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
        if (Filtro.test(email.val())){
            email.removeClass('hightlight');
            return true;
        }
        else
        {
            email.addClass('hightlight');
            return false;
        }
	});
});

