var options = { 
	beforeSubmit:  validate,  // pre-submit callback 
	success:       showResponse,  // post-submit callback 
	resetForm: true        // reset the form after successful submit 
}; 
var optionscmd = { 
	beforeSubmit:  validatecmd,  // pre-submit callback 
	success:       showResponsecmd,  // post-submit callback 
	resetForm: true        // reset the form after successful submit 
}; 
var optionss = { 
	success:       showResponse2,  // post-submit callback 
	resetForm: true 
}; 				
$('#contact_us').ajaxForm(options); 
$('#log_us').ajaxForm(optionss);
//$('#cmd_us').ajaxForm(optionscmd);
				
function showResponse(responseText, statusText){
	$('#contact_us').slideUp({ opacity: "hide" }, "normal")
	$('#success').fadeIn(2000)
}
function showResponsecmd(responseText, statusText){
	$('#cmd_us').slideUp({ opacity: "hide" }, "normal")
	$('#success').fadeIn()
}
function showResponse2(responseText, statusText){
	$('#success').slideUp({ opacity: "hide" }, "normal");
	$('#success').fadeIn();
	setInterval(function(){
  		location.href="epmembres.php";
	}, 1500);
}				
function validate(formData, jqForm, options) {
	$("p.error").slideUp({ opacity: "hide" }, "fast");
			 
	var nomValue = $('input[name=Nom]').fieldValue(); 
	var emailValue = $('input[name=Email]').fieldValue();
	//var messageValue = $('textarea[name=Message]').fieldValue(); 
	
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	var correct = true;
	
	if (!nomValue[0]) {
		$("p.error.wrong_nom").slideDown({ opacity: "show" }, "slow");
		correct = false;
	}
	
	if (!emailValue[0]) {
		$("p.error.wrong_email").slideDown({ opacity: "show" }, "slow");
		correct = false;
	} else if(!emailReg.test(emailValue[0])) {
		$("p.error.wrong_email").slideDown({ opacity: "show" }, "slow");
		correct = false;
	}
	
/*	if (!messageValue[0]) {
		$("p.error.wrong_message").slideDown({ opacity: "show" }, "slow");
		correct = false;
	}*/
	
	if (!correct) {return false;}
} 	
function validatecmd(formData, jqForm, optionscmd) {
	$("p.error").slideUp({ opacity: "hide" }, "fast");
	
	var radioValue = $('input[name=radio]').fieldValue();		 
	var nomValue = $('input[name=nom]').fieldValue(); 
	var emailValue = $('input[name=email]').fieldValue();
	//var messageValue = $('textarea[name=Message]').fieldValue(); 
	
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	var correct = true;
	
	if (!radioValue[0]) {
		$("p.error.wrong_radio").slideDown({ opacity: "show" }, "slow");
		correct = false;
	}
	if (!nomValue[0]) {
		$("p.error.wrong_nom").slideDown({ opacity: "show" }, "slow");
		correct = false;
	}
	
	if (!emailValue[0]) {
		$("p.error.wrong_email").slideDown({ opacity: "show" }, "slow");
		correct = false;
	} else if(!emailReg.test(emailValue[0])) {
		$("p.error.wrong_email").slideDown({ opacity: "show" }, "slow");
		correct = false;
	}
	
/*	if (!messageValue[0]) {
		$("p.error.wrong_message").slideDown({ opacity: "show" }, "slow");
		correct = false;
	}*/
	
	if (!correct) {return false;}
	else{return true;}
} 									 
