// JavaScript Document
function cancelForm(){
	$("#f_booking")[0].reset();
	$('#bookingform').jqmHide(); 
}

function positionSite(){
	var margintop = (($(document).height()-$("#site").height())/2);
	var marginleft = (($(document).width()-$("#site").width())/2);
	if(margintop<0){
		margintop = 0;
	}
	if(marginleft<0){
		marginleft = 0;
	}	
	$("#site").css("marginTop",  margintop+"px"); 
	$("#site").css("marginLeft",  marginleft+"px"); 
}
$(document).ready(function(){
    positionSite();
	/*$("a.fancybox").fancybox({
							 'onClosed': cancelForm
							 });*/
	$("#f_booking").submit(function(){
		// 'this' refers to the current submitted form
		var str = $(this).serialize();
		$.ajax({
		   type: "POST",
		   url: "booking.php",
		   data: str,
		   success: function(data){
			   		$(":input").removeClass("errormsg");
					$("div.errormsg").remove();
					$.each(data.errors, function(n) {
						 result = data.errors[n];
                           $("#" + n).after("<div class=\"errormsg\">"+data.errors[n]+"</div>");
						   $("#" + n).addClass("errormsg");
                     })
				   if(data.status == 'OK'){ // Message Sent? Show the 'Thank You' message and hide the form
						result = '<div class="notification_ok"><p>Votre réservation a bien été envoyée.</p><p>Merci</p></div>';
						$("#f_booking")[0].reset();
						$("#f_booking").hide();
					}else{				
						result = data.msg;
					}
					$("#msg").html(result);
					$("#msg").show();
				
			},
			dataType: "json"
		});
		return false;
	});
});

$(window).resize(function(){
	positionSite();	
});
