
function afficherFormLivredor() {
	
	$("div#livredor_linktoform").slideUp("slow", function() {
		$("form#livredor_form").slideDown("slow");	
	});


}

function masquerFormLivredor() {

	$("form#livredor_form").slideUp("slow", function() {
		// On remet les couleurs des labels input à couleur none
		$('div.input_label').css({ color: '' });
		
		// On recharge aussi le captcha
		rechargerCaptcha();
		
		$("div#livredor_linktoform").slideDown("slow");	
	});	

}

function rechargerCaptcha() {

	$("img#captcha").attr({ src: "img/captcha.php?notcache=" + Math.random() + "" });
	
}

// Gestion des données du formulaire
//

function verifierdonneesFormLivredor(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
	var bDonneesOk = true;
	
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 

	// On remet les couleurs des labels input à couleur none
	$('div.input_label').css({ color: '' });
	
    for (var i=0; i < formData.length; i++) {
		var fValue = formData[i].value;
		var fName  = formData[i].name;
		
		switch (fName)
		{
			case 'nomprenom':
				if (!fValue) {
					$('div#input_' + fName).css({ color:'red' });
					bDonneesOk = false;
				}
				break;
			case 'message':
				if (!fValue) {
					$('div#input_' + fName).css({ color:'red' });
					bDonneesOk = false;
				}
				break;
			case 'email':
				if (!fValue) {
					$('div#input_' + fName).css({ color:'red' });
					bDonneesOk = false;
				}
				else if (!verificationEmail(fValue)) {
					$('div#input_' + fName).css({ color:'red' });
					bDonneesOk = false;				
				}
				break;
			case 'captcha':
				if (!fValue) {
					$('div#input_' + fName).css({ color:'red' });
					bDonneesOk = false;
				}
				else {
					// On vérifie le captcha auprès du script PHP
					$.ajax({
						async: false,
						cache: false,
						type: "GET",
						url: 'img/captcha.php?verify=' + fValue,
						dataType: "html",
						success: function(data){
							// Si la réponse n'est pas correcte
							if (data != '1') {
								$('div#input_' + fName).css({ color:'red' });
								bDonneesOk = false;
							}
						}
					});
				
				}
				break;
			default:
				// Ne rien faire
				break;
		}			
		
    } 
	
    //alert('About to submit: \n\n' + queryString); 
 
	if (bDonneesOk) {
		var oDivChargement = document.getElementById("livredor_chargement");
		oDivChargement.style.display = "block";	
	}
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue	
    return bDonneesOk; 
} 

 
// post-submit callback 
function apresvalidationFormLivredor(responseText, statusText)  { 
	
	var oDivChargement = document.getElementById("livredor_chargement");
	oDivChargement.style.display = "none";
	
}

