$(document).ready(function() {
	$('#reserv_form').submit(function() {
		var send_form = true;
		$(this).find('.required_field').each(function() {
			if(!send_form) return;
			if(this.value == null || this.value.length <= 0 || this.value == this.defaultValue || this.value == 'NULL') {
				alert(loc_fill_all_fields);
				send_form = false;
			}
		});
		
		if(!send_form) return false;
		
		$(this).find('.required_checked').each(function() {
			if(!send_form) return;
			if(!this.checked) {
				alert(loc_trattamento);
				send_form = false;
			}
		});
		
		//Check dates
		var fd = $('#from_date').val().split('/');
		var td = $('#to_date').val().split('/');
		var fromDate = new Date(fd[1]+"/"+fd[0]+"/"+fd[2]);
		var toDate = new Date(td[1]+"/"+td[0]+"/"+td[2]);
		
		if((fromDate-toDate) > 0) {
		//if(false) {
			alert(loc_date_error);
			send_form = false;
		}
		
		$('.placeholder_field').each(function() {
			if(this.value == this.defaultValue) {
				this.value = '';
			}
		});
				
		//return false;
		return send_form;
	});
	
	$('#reserv_form').find('.placeholder_field').focus(function() {
		if(this.value == this.defaultValue) {
			this.value = '';
		}
	}).blur(function() {
		if(this.value.length <= 0) {
			this.value = this.defaultValue;
		}
	});
	
	$('.reservMessage').each(function() {
		var t = $(this);
		setTimeout(function() { t.fadeOut(); }, 7000);
	});
	
	$('.brown_hover').hover(function() {
		this.oldColor = this.style.color;
		this.style.color = '#AC6D00';
	}, function() {
		this.style.color = this.oldColor;
	});
});

function openPopup(url) {
	var x = ((window.screen.width - 970) / 2) + (185/2);
	window.open(url, 'ADPopup', 'width=300,height=400,top=230,left='+x+',location=no,scrollbars=yes');
}