$(document).ready(function () {

	$('.form_submit').click(function (ev) {
		ev.stopPropagation();
		$(this).parents('form').submit();
		return false;
	});

	$('a.contact').click(function (ev) {
		ev.stopPropagation();
		$('#contact-dialog').dialog('open');
		return false;
	});

});

$(function () {

	$("#contact-dialog").dialog({
		autoOpen: false,
		height: 'auto',
		width: 400,
		modal: true,
		buttons: {
			'Annuler': function() {
				$(this).dialog('close');
			},
			'Envoyer': function() {
				var data = $('#contact-form').serialize();

				// Post le form en AJAX et recoit du JSON
				$.post('/fr/contact', data, function (res) {
					res = $.parseJSON(res);
					if(res.error) {
						$("#contact-dialog").html(res.html);
					} else {
						$("#contact-dialog").html(res.html).dialog({buttons: {
							'Fermer': function() {
								$(this).dialog('close');
							}
						}});
					}
					$("#contact-dialog").dialog( "option", "position", 'center' );
				});

			}
		},
		close: function() {}
	});

});


