// Transfert une ligne de la liste Origine ? la liste Destination
function TransfertListe(idOrigine, idDestination)
{
	var objOrigine = document.getElementById(idOrigine);
	var objDestination = document.getElementById(idDestination);
	if (objOrigine.options.selectedIndex<0) return false;
	var text = objOrigine.options[objOrigine.options.selectedIndex].text;
	var value = objOrigine.options[objOrigine.options.selectedIndex].value;
	var res =false;
	if(idOrigine == "la_liste_2")
		res = AjaxDelUserGeo(login,text);
	else if(idOrigine == "map_liste_2"){
		var varT = value.split(",");
		res = AjaxDelCustRef(varT[0],varT[1],varT[2]);
	}
	else if(idOrigine == "map_liste_1"){
		text = prompt("This is the point that will show in the Map",text);
		var varT = value.split(",");
		res = AjaxAddCustRef(login,varT[0],varT[1],varT[2],varT[3],varT[4]);
	}
	else{
		text = prompt("This is the name that will show in the Menu",text);
		res = AjaxAddUserGeo(login,text,value);
	}
	if(res){
		var ADeplacer = new Option(text, value);
		objDestination.options[objDestination.length]=ADeplacer;
		objOrigine.options[objOrigine.options.selectedIndex]=null;
	}
	return true;
}


function initAjax(){
    var xhr = null; 
	 
	if(window.XMLHttpRequest) // Firefox 
	   xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject) // Internet Explorer 
	   xhr = new ActiveXObject("Microsoft.XMLHTTP"); 
	else { // XMLHttpRequest non support? par le navigateur 
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	   xhr = null;
       return xhr; 
	} 
    return xhr;
}

//Add a new row into usergeo DB 
function AjaxAddUserGeo(user,name,geocode){
	var xhr_object = initAjax();
    xhr_object.open("GET", cpath+"scripts/DB/addUserGeo.php?user="+user+"&name="+name+"&geocode="+geocode, false);  
	xhr_object.send(null);
	//TODO:should come from the php
	return true;
}
//Remove a row from usergeo DB 
function AjaxDelUserGeo(user,name){
	var del = confirm("deleting : "+user+"/"+name);
	if(del){
		var xhr_object = initAjax();
	    xhr_object.open("GET", cpath+"scripts/DB/deleteUserGeo.php?user="+user+"&name="+name, false);  
		xhr_object.send(null);
	} 
	return del;
}

