
/***********  ajax  ***********/
function init_ajax_form(){
	J('.fieldvalue').clearField();
	J('.fieldvalue').clearField();
	
	//cette fonction permet de configurer le formulaire avec une falidation est un submit ajax
		jQuery().ajaxStart(function() {
			displayLoading();
		}).ajaxStop(function() {
			hideLoading();
		}).ajaxError(function(a, b, e) {
			throw e;
		});
		
		var v = jQuery("#contact_form").validate({
			submitHandler: function(form) {
				jQuery(form).ajaxSubmit(function(text){
					succes: displayResponse(text)
				});
			}
		});
}

function displayResponse(responseText, statusText)  { 
  if(responseText == "sendok"){
   		displayMessage("<p>Votre message a bien été envoyé.</p><p>Un de nos conseillers prendra contact avec vous dans les plus brefs délais.</p><p>Merci.</p>");
   }else{
   		displayMessage("<p>Erreur : votre message n'à pas été envoyé.</p>");
   }
} 

/******* message  *****/
function displayMessage(msg){
	hideLoading();
	J("#loading").replaceWith(msg+'<div class="wrapper"></div>');
}
/******* loading  *****/
function displayLoading(){
	var height = J("#module_forminfo").height();
	
	var height_form = J("#module_forminfo form").height();
	var width_form = J("#module_forminfo form").width();
	J("#contact_form").replaceWith('<div id="loading"></div>');
	J("#loading").css({ height:height_form, width:width_form });
	J("#module_forminfo").css({ height:height });
}
function hideLoading(){
	J("#loading").css({ backgroundImage : "none"});
}

