

jQuery.fn.anchorAnimate = function(settings) {
 	settings = jQuery.extend({
		speed : 1100
	}, settings);	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			var destination = ($(elementClick).offset().top);
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}

function isAfter(before, after){
						
				
				after = after.split("-");
				before = before.split("-");
				
				if(after[0]==0) return false;
				
				//anno
				if(parseInt(before[2])>parseInt(after[2])){ return false;}
				else if(parseInt(before[2])<parseInt(after[2])){ return true;}
				
				//mese
				if(parseInt(before[1])>parseInt(after[1])){return false;}
				else if(parseInt(before[1])<parseInt(after[1])){return true;}	
			
				//giorno
				if(parseInt(before[0])>parseInt(after[0])) return false;
				else if(parseInt(before[0])<parseInt(after[0])) return true;
							
				return true; 
}


function sendBook(){
	var dal = $('#dal').attr('value'); 
	var al = $('#al').attr('value');
	var unit = $('#tipologia').attr('value');
	var np = $('#persone').attr('value');
	var flag = true;
	var err = "";	
	
	if(!isAfter(dal, al)){
		flag = false;
		err = "Periodo non valido";
	}
	
	if((unit=="tenda" || unit=="camper" || unit=="roulotte") && (np<=0)){
		flag = false;
		if(err != "") err += " - ";
		err += "E' necessario inserire il numero di persone per il tipo di soggiorno richiesto";
	}
	
	if(flag){
		$.fancybox({
							'width'				: 500,
							'height'			: 650,
		        			'autoScale'     	: true,
							'type'				: 'iframe',
        					'showCloseButton'	: true,
        					'href'          	: 'booking_frontend.php?action=search&dal='+dal+'&al='+al+'&unit='+unit+'&np='+np
						});
	}
	else{
		alert(err);
	}
}

$(function(){
    // init anchor slide
	$("a.anchorLink").anchorAnimate();	
	// init select box styling
	$("select").uniform();
	// init calendar pick
	$('#al').datepicker({ dateFormat: 'dd-mm-yy', 'minDate': new Date(),  firstDay: 6 });
	$('#dal').datepicker({ dateFormat: 'dd-mm-yy', 
			 'minDate': new Date(), 
			  onSelect: function(dateText, inst) {$("#al").datepicker( "option", "minDate", dateText);},  
			  firstDay: 6,
		  });
	// init fancybox
	$(".info").fancybox({
		'overlayColor'		: '#000',
		'overlayOpacity'	: '0.6',
		'width'				: 600,
		'height'			: 300,
		'autoScale'     	: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	// init fancybox
	$("#but_dove").fancybox({
		'overlayColor'		: '#000',
		'overlayOpacity'	: '0.6',
		'width'				: 800,
		'height'			: 600,
		'autoScale'     	: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	

		
});

	
					
		 



