function LISTE_getMyPosition(id_liste, id_li)
{
	var liste_li = $$("#"+id_liste+" "+"li");
	
	for(var l = 0; l < liste_li.length; l++)
	{
		if(liste_li[l].id == id_li)
		{
			return l;
		}
	}
	
	return -1;
}

function LISTE_MovePosition(id_liste, id_li, direction, prefix_li, prefix_champid)
{
	var liste_li = $$("#"+id_liste+" "+"li");
	var liste_id = $$("#"+id_liste+" "+"input[id^="+prefix_champid+"]");
	
	var nbr_element = liste_li.length;
	var position_actuelle = LISTE_getMyPosition(id_liste, id_li);
	var new_position = 0;
	var prefix_champid = prefix_champid || "";
	var prefix_li = prefix_li || "";
	
	var ordre_found = false;

	if(prefix_li != "" && prefix_champid != "")
	{
		var value_id = "";
		var input_ordre = 'ordre_'+prefix_li;
		if($(input_ordre))
		{
			ordre_found = true;
		}
	}
	
	if(direction == "up")
	{
		if(position_actuelle <= 0)
		{
			return;
		}
		else{
			new_position = position_actuelle - 1;
		}	
	}else if(direction == "down")
	{
		if(position_actuelle >= (nbr_element - 1))
		{
			return;
		}else{
			new_position = position_actuelle + 1;
		}	
	}
	
	var li_remplacee = liste_li[new_position];
	liste_li[new_position] = liste_li[position_actuelle];
	liste_li[position_actuelle] = li_remplacee;
	var id_remplace = liste_id[new_position];
	liste_id[new_position] = liste_id[position_actuelle];
	liste_id[position_actuelle] = id_remplace;
	
	$(id_liste).innerHTML = "";
	$(input_ordre).value = "";
	var id_bloc = "";
	for(var l = 0; l < liste_li.length; l++)
	{
		if(ordre_found == true)
		{
			$(input_ordre).value += liste_id[l].value + ",";
		}
		$(id_liste).appendChild(liste_li[l]);
	}

	Behaviour.apply();

	LISTE_checkIfBoutonsOK("solutioncontents","solutioncontent_","up:","down:");
}

function LISTE_checkIfBoutonsOK(liste_id, prefix_numbloc, prefix_boutonup, prefix_boutondown)
{
	var liste_li = $$("#"+liste_id+" "+"li");
	var numbloc = 0;
	var btnup = "";
	var btndown = "";
	var btnadd = "";
	
	for(var l = 0; l < liste_li.length; l++)
	{
		numbloc = liste_li[l].id.replace(prefix_numbloc,"");
		btnadd = liste_li[l].id.replace(prefix_numbloc,"bloc_ajoute:");
		
		if(l < (liste_li.length -1))
		{
			$(btnadd).style.display = "none";
		}else{
			$(btnadd).style.display = "block";			
		}
		
		if($(prefix_boutonup + numbloc))
		{
			btnup = $(prefix_boutonup + numbloc);
			if(l == 0)
			{
				btnup.style.display = "none";
			}else{
				btnup.style.display = "block";
			}
		}
		
		if($(prefix_boutondown + numbloc))
		{
			btndown = $(prefix_boutondown + numbloc);
			if(l == (liste_li.length-1))
			{
				btndown.style.display = "none";
			}else{
				btndown.style.display = "block";
			}
		}
	}
}

function getSelected(listeObj)
{
	var selected_value = new Array();
	var Obj;
	
	if(typeof(listeObj) != "object")
	{
		Obj = $(listeObj);
	}else{
		Obj = listeObj;
	}
	
	if(typeof(Obj) == "object")
	{
		var liste = Obj.getElementsByTagName('option');
		var options = $A(liste);
		
		options.each(function(ligne){
			if(ligne.selected == true)
			{
				selected_value.push(ligne.value);
			}
		});
	}
	
	return selected_value;
}


function URL_extractparams(){	

	var t = location.search.substring(1).split('&');

	var f = [];

	for (var i=0; i<t.length; i++){

		var x = t[ i ].split('=');

		f[x[0]]=x[1];

	}

	return f;

}
