function ShowError(p_message) {
	form_error.innerHTML = p_message;
	$display(form_error);
	return false;
}
function reset_form() {
	$undisplay(form_error);
	txtVille_Nom.value = "";
	txtVille_Cp.value = "";
	txtNom.value = "";
	txtEmail.value = "";
	txtCodeImage.value = "";
	lstPays.options[0].selected = true;
	imgcode.src = "/ws/get_codeimage.php?uid=" + Math.round(Math.random() * 1000000);
}
function ValidateFields() {
	form_error.innerHTML = "";
	// nom de la ville
	if (txtVille_Nom.value.trim() == "")
		return ShowError("Veuillez indiquer le nom de la ville concern\351e");
	// code postal
	if (!txtVille_Cp.value.match(/\d{5}/))
		return ShowError("Veuillez indiquer un code postal valide");
	// nom
	if (txtNom.value.trim() == "")
		return ShowError("Veuillez indiquer votre nom");
	// email
	if (!txtEmail.value.isEmail())
		return ShowError("Veuillez indiquer une adresse email valide");
	// code image
	if (txtCodeImage.value.trim() == "" || txtCodeImage.value.trim().length != 6)
		return ShowError("Veuillez recopier le code contenu dans l'image");
	
	return true;
}
function SendSuggest() {
	// validation
	if (!ValidateFields())
		return;
		
	// afficher l'indicateur
	btSendSuggest.disabled = "disabled";
	$display(form_loading);
	
	var ville_nom = txtVille_Nom.value.trim();
	var ville_cp  = txtVille_Cp.value.trim();
	var pays	  = lstPays.options[lstPays.selectedIndex].text;
	var nom 	  = txtNom.value.trim();
	var email	  = txtEmail.value.trim();
	var codeimg	  = txtCodeImage.value.trim();
	var message	  = "** SUGGESTION DECOUPAGE **\r\n\r\n" + nom + " propose de placer la commune '" + ville_nom + " (" + ville_cp + ") dans '" + pays + "'";

	var datas = {
		"nom" : nom,
		"email" : email,
		"codeimg" : codeimg,
		"message" : message
	};
	EdLib.makeHTTPRequest("POST", "/ws/sendmail.php", SendSuggest_Callback, datas);
}
function SendSuggest_Callback(p_xhr) {
	// masquer l'indicateur
	btSendSuggest.disabled = null;
	$undisplay(form_loading);
	
	var reponse = null;
	try {
		reponse = p_xhr.responseText;
	}
	catch (e) { alert(e); return; }
	if (reponse == "OK") {
		alert("Votre suggestion a \351t\351 envoy\351e.");
		reset_form();
	}
	else
		alert(reponse);
		
}
