function getLocalityOptions(country,postalcode,language,span_locality,idlocality,locality_name,resp)
{
	if (country>0) {
		var c = country; }
    else {
		var c = $('#id_pays option:selected').val(); }
	var post = $(postalcode).val();
	
	var data = "country="+c+"&postalcode="+post+"&language="+language+"&idlocality="+idlocality; 
	var url = "https://www.guidesocial.be/assoc/javascript/locality.php";

	if (post.length > 3) {
		$.ajax({
		  type: "POST",
		  url: url,
		  data: data,
		  success: function(xml) {
		   
			var locality = new Array();
		  
		  $("locality",xml).each(function()
			{
				locality[parseInt($(this).attr("id"))] = $("name",this).text();
			});
	
			$(span_locality).html(ArrayAsOptions(locality,idlocality,c,locality_name,resp));	
			
		}
		});
		
		$("#tests").html($("#country[value='1']").text());
		}

}
function ArrayAsOptions(tab,idlocality,country,locality_name,resp)
{
    if (country>3 && country!=14) {
		var str = "<input name='locality_name' id='locality_name' type='text' value='"+locality_name+"' size=15 ";
		if (resp==1) {
			str += " disabled='disabled' class='disabled'"
			}
		str += ">"
		str += " <input id='locname' type='hidden'>"
		}
	else{
		var str = "<select name='id_commune' id='id_commune' class='span4' ";
		if (resp==1) {
			str += " disabled='disabled' class='disabled'";
			}
		str += ">"
		for (var propriete in tab)
	 		{
	 		if (propriete == parseInt(propriete)) 
				{
				if (idlocality==propriete) {
					str += "<option value='"+propriete+"' selected>"+tab[propriete]+"</option>"
					}
				else {
					str += "<option value='"+propriete+"'>"+tab[propriete]+"</option>"
					}
				}
			}
		str += "</select>"
		//str += " <input id='locality_name' type='hidden'>"
		}
		
	 return str;
}