
var _user = new Array();
var _userXMLElt = new Array();

function User( _id, _name, _group)
{
	this.id = _id;
	this.name = _name;
	this.group = _group;	
}

function initUser()
{	
	if( _userXMLElt.length>0)
		return;
		
	new Request(
	{
		url:contextPath+'/auth/xml/',
		method: 'get',
		encoding:'ISO-8859-1',
		onFailure:manageUserErrors,
		onSuccess:processUserList
	}).send();
}

function processUserList(e,xml) {
	
	var debug = false;
	if (debug) {console.info("[UserTools.js] [processUserList] Starting... ");}
	
	_userXMLElt = new Array();
	_userXMLElt = xml.documentElement.getElementsByTagName("user");
	
	for (var i = 0; i < _userXMLElt.length; i++) {
		var user = _userXMLElt[i];
		_user[i]  = new User( user.getAttribute("id"), user.getAttribute("user_name"), user.getAttribute("group"));
	}
	
	if (debug) {console.info("[UserTools.js] [processUserList] End ");}
}


function manageUserErrors()
{
	
}


function updateLocation( marker, urlkey)
{
	if( confirm( 'Vous avez déplacé un marqueur, voulez-vous enregistrer la modification ?'))
	{
		new Request(
		{
			url:contextPath+'/event/updateLocation/'+urlkey+'/'+marker.getLatLng().lat()+'/'+marker.getLatLng().lng(),
			method: 'post',
			encoding:'ISO-8859-1',
			onFailure:manageupdateLocationErrors,
			onSuccess:processupdateLocation
		}).send();
	}
}

function updateMediaLocation( marker, latitude, longitude)
{
	if( confirm( 'Vous avez déplacé un marqueur de médias, voulez-vous enregistrer la nouvelle position ?'))
	{
		new Request(
		{
			url:contextPath+'/media/updateLocation/'+latitude+'/'+longitude+'/'+marker.getLatLng().lat()+'/'+marker.getLatLng().lng(),
			method: 'post',
			encoding:'ISO-8859-1',
			onFailure:manageupdateLocationErrors,
			onSuccess:processupdateLocation
		}).send();
	}
}


function processupdateLocation()
{
}

function manageupdateLocationErrors()
{
}
