/*
	Créer une boite d'autocompletion pour le champ spécifier
*/
function addAutoCompleteVille(champ)
{
	new AutoComplete(champ, 'ville', 'nom_fr,nom_be,nom_ba');
}

/*
	Vérifie si une ville existe
*/
function checkVilleExists(ville)
{
	var xhr_object = ajaxGetXMLHTTP(); 

	xhr_object.open("POST", "interfaces/ajx_ville.php", false); 
	 
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr_object.send("ville="+ville); 
	
	while(xhr_object.readyState != 4) {}
	
	if(xhr_object.responseText == "ok")
		return true;
	else
		return false;
}

/*
	Vérifie si une ville existe à partir de la valeur d'un champ
*/
function checkVilleExistsInput(champ, err_msg)
{
	if(checkVilleExists(champ.value))
	{
		showError(champ,"OFF");
		return true;
	}
	else
	{
		showError(champ,"ON");
		alert("La ville "+err_msg+" n'existe pas.");
		return false;
	}
}

/*
	Vérifie si une ville est dans le departement 64
*/
function checkVilleInDep(ville)
{
	var xhr_object = ajaxGetXMLHTTP(); 

	xhr_object.open("POST", "interfaces/ajx_ville.php", false); 
	 
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr_object.send("villeindep="+ville); 
	
	while(xhr_object.readyState != 4) {}
	
	if(xhr_object.responseText == "ok")
		return true;
	else
		return false;
}

/*
	Récupère le nombre de ville ayant le nom spécifier
*/
function listVilleWithName(ville)
{
	var xhr_object = ajaxGetXMLHTTP(); 

	xhr_object.open("POST", "interfaces/ajx_ville.php", false); 
	 
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr_object.send("list="+ville); 
	
	while(xhr_object.readyState != 4) {}
	
	return parseInt(xhr_object.responseText);
}