diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index 3d6d08537d..b166e47106 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,18 @@
+2013-10-08  Sergio Martin <sergio.martin@artica.es>
+
+	* include/functions_alerts.php
+	include/javascript/jquery.pandora.controls.js
+	include/functions_treeview.php
+	operation/tree.php
+	operation/agentes/ver_agente.php
+	godmode/groups/group_list.php
+	godmode/massive/massive_add_alerts.php
+	godmode/massive/massive_delete_modules.php
+	godmode/massive/massive_delete_alerts.php
+	godmode/massive/massive_edit_modules.php
+	godmode/reporting/graph_builder.graph_editor.php: Add sorting
+	in many agents list retrieved by ajax and tree view
+
 2013-10-07  Sergio Martin <sergio.martin@artica.es>
 
 	* include/styles/pandora.css: Added a overflow hidden
diff --git a/pandora_console/godmode/groups/group_list.php b/pandora_console/godmode/groups/group_list.php
index 17de31a9f9..9e7d7b3b97 100644
--- a/pandora_console/godmode/groups/group_list.php
+++ b/pandora_console/godmode/groups/group_list.php
@@ -67,6 +67,8 @@ if (is_ajax ()) {
 		$disabled = (int) get_parameter ('disabled', 0);
 		$search = (string) get_parameter ('search', '');
 		$recursion = (int) get_parameter ('recursion', 0);
+		// Is is possible add keys prefix to avoid auto sorting in js object conversion
+		$keys_prefix = (string) get_parameter ('keys_prefix', '');
 		// Ids of agents to be include in the SQL clause as id_agent IN ()
 		$filter_agents_json = (string) get_parameter ('filter_agents_json', '');
 		
@@ -87,9 +89,16 @@ if (is_ajax ()) {
 			$filter['string'] = $search;
 		}
 		
-		
 		$agents = agents_get_group_agents ($id_group, $filter, "none", false, $recursion);
 		
+		// Add keys prefix
+		if ($keys_prefix !== "") {
+			foreach($agents as $k => $v) {
+				$agents[$keys_prefix . $k] = $v;
+				unset($agents[$k]);
+			}
+		}
+		
 		echo json_encode ($agents);
 		return;
 	}
diff --git a/pandora_console/godmode/massive/massive_add_alerts.php b/pandora_console/godmode/massive/massive_add_alerts.php
index 2b94fadb6c..407894a215 100644
--- a/pandora_console/godmode/massive/massive_add_alerts.php
+++ b/pandora_console/godmode/massive/massive_add_alerts.php
@@ -35,10 +35,20 @@ if (is_ajax ()) {
 	
 	if ($get_agents) {
 		$id_group = (int) get_parameter ('id_group');
+		// Is is possible add keys prefix to avoid auto sorting in js object conversion
+		$keys_prefix = (string) get_parameter ('keys_prefix', '');
 		
-		$agents_alerts = agents_get_group_agents ($id_group, false, "", false, $recursion);
+		$agents = agents_get_group_agents ($id_group, false, "", false, $recursion);
 		
-		echo json_encode ($agents_alerts);
+		// Add keys prefix
+		if ($keys_prefix !== "") {
+			foreach($agents as $k => $v) {
+				$agents[$keys_prefix . $k] = $v;
+				unset($agents[$k]);
+			}
+		}
+		
+		echo json_encode ($agents);
 		return;
 	}
 	return;
@@ -183,11 +193,16 @@ $(document).ready (function () {
 			{"page" : "godmode/massive/massive_add_alerts",
 			"get_agents" : 1,
 			"id_group" : this.value,
-			"recursion" : $("#checkbox-recursion").is(":checked") ? 1 : 0
+			"recursion" : $("#checkbox-recursion").is(":checked") ? 1 : 0,
+			// Add a key prefix to avoid auto sorting in js object conversion
+			"keys_prefix" : "_"
 			},
 			function (data, status) {
 				options = "";
 				jQuery.each (data, function (id, value) {
+					// Remove keys_prefix from the index
+					id = id.substring(1);
+					
 					options += "<option value=\""+id+"\">"+value+"</option>";
 				});
 				$("#id_agents").append (options);
diff --git a/pandora_console/godmode/massive/massive_delete_alerts.php b/pandora_console/godmode/massive/massive_delete_alerts.php
index d5c7fb8f34..59d31564f7 100644
--- a/pandora_console/godmode/massive/massive_delete_alerts.php
+++ b/pandora_console/godmode/massive/massive_delete_alerts.php
@@ -36,6 +36,8 @@ if (is_ajax ()) {
 	if ($get_agents) {
 		$id_group = (int) get_parameter ('id_group');
 		$id_alert_template = (int) get_parameter ('id_alert_template');
+		// Is is possible add keys prefix to avoid auto sorting in js object conversion
+		$keys_prefix = (string) get_parameter ('keys_prefix', '');
 		
 		if ($recursion) {
 			$groups = groups_get_id_recursive($id_group, true);
@@ -53,7 +55,19 @@ if (is_ajax ()) {
 			}
 		}
 		
-		echo json_encode (index_array ($agents_alerts, 'id_agente', 'nombre'));
+		$agents = index_array ($agents_alerts, 'id_agente', 'nombre');
+
+		asort($agents);
+		
+		// Add keys prefix
+		if ($keys_prefix !== "") {
+			foreach($agents as $k => $v) {
+				$agents[$keys_prefix . $k] = $v;
+				unset($agents[$k]);
+			}
+		}
+		
+		echo json_encode ($agents);
 		return;
 	}
 	return;
@@ -252,11 +266,16 @@ $(document).ready (function () {
 			"get_agents" : 1,
 			"id_group" : this.value,
 			"recursion" : $("#checkbox-recursion").is(":checked") ? 1 : 0,
-			"id_alert_template" : $("#id_alert_template").val()
+			"id_alert_template" : $("#id_alert_template").val(),
+			// Add a key prefix to avoid auto sorting in js object conversion
+			"keys_prefix" : "_"
 			},
 			function (data, status) {
 				options = "";
 				jQuery.each (data, function (id, value) {
+					// Remove keys_prefix from the index
+					id = id.substring(1);
+					
 					options += "<option value=\""+id+"\">"+value+"</option>";
 				});
 				$("#id_agents").append (options);
diff --git a/pandora_console/godmode/massive/massive_delete_modules.php b/pandora_console/godmode/massive/massive_delete_modules.php
index 7918c5f247..4427c6ef58 100644
--- a/pandora_console/godmode/massive/massive_delete_modules.php
+++ b/pandora_console/godmode/massive/massive_delete_modules.php
@@ -459,12 +459,16 @@ $(document).ready (function () {
 				{"page" : "operation/agentes/ver_agente",
 				"get_agents_group_json" : 1,
 				"recursion" : $("#checkbox-recursion").attr ("checked") ? 1 : 0,
-				"id_group" : this.value
+				"id_group" : this.value,
+				// Add a key prefix to avoid auto sorting in js object conversion
+				"keys_prefix" : "_"
 				},
 				function (data, status) {
 					$("#id_agents").html('');
-					
 					jQuery.each (data, function (id, value) {
+						// Remove keys_prefix from the index
+						id = id.substring(1);
+						
 						option = $("<option></option>").attr ("value", value["id_agente"]).html (value["nombre"]);
 						$("#id_agents").append (option);
 					});
diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php
index 1a69a593e3..98d8307608 100644
--- a/pandora_console/godmode/massive/massive_edit_modules.php
+++ b/pandora_console/godmode/massive/massive_edit_modules.php
@@ -776,12 +776,17 @@ $(document).ready (function () {
 				{"page" : "operation/agentes/ver_agente",
 				"get_agents_group_json" : 1,
 				"recursion" : $("#checkbox-recursion").attr ("checked") ? 1 : 0,
-				"id_group" : this.value
+				"id_group" : this.value,
+				// Add a key prefix to avoid auto sorting in js object conversion
+				"keys_prefix" : "_"
 				},
 				function (data, status) {
 					$("#id_agents").html('');
 					
 					jQuery.each (data, function (id, value) {
+						// Remove keys_prefix from the index
+						id = id.substring(1);
+						
 						option = $("<option></option>").attr ("value", value["id_agente"]).html (value["nombre"]);
 						$("#id_agents").append (option);
 					});
diff --git a/pandora_console/godmode/reporting/graph_builder.graph_editor.php b/pandora_console/godmode/reporting/graph_builder.graph_editor.php
index e22a702fb2..8965ee70bb 100644
--- a/pandora_console/godmode/reporting/graph_builder.graph_editor.php
+++ b/pandora_console/godmode/reporting/graph_builder.graph_editor.php
@@ -197,14 +197,20 @@ function filterByGroup(idGroup) {
 	jQuery.post ("ajax.php",
 			{"page" : "godmode/groups/group_list",
 			"get_group_agents" : 1,
-			"id_group" : idGroup
+			"id_group" : idGroup,
+			// Add a key prefix to avoid auto sorting in js object conversion
+			"keys_prefix" : "_"
 			},
 			function (data, status) {
 				i = 0
 				jQuery.each (data, function (id, value) {
+					// Remove keys_prefix from the index
+					id = id.substring(1);
+					
 					i++;
 					$("#id_agents").append ($("<option></option>").attr ("value", id).html (value));
 				});
+				
 				if (i == 0) {
 					$("#id_agents").append ($("<option></option>").attr ("value", 0).html ('<?php echo __('None');?>'));
 				}
diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php
index 8f6630d16d..3887ae8537 100644
--- a/pandora_console/include/functions_alerts.php
+++ b/pandora_console/include/functions_alerts.php
@@ -1370,6 +1370,7 @@ function alerts_get_agents_with_alert_template ($id_alert_template, $id_group, $
 	$filter['id_alert_template'] = $id_alert_template;
 	$filter['tagente_modulo.disabled'] = '<> 1';
 	$filter['delete_pending'] = '<> 1';
+	
 	if (empty ($id_agents)) {
 		switch ($config["dbtype"]) {
 			case "mysql":
diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php
index 7494d1831a..798043d2ee 100755
--- a/pandora_console/include/functions_treeview.php
+++ b/pandora_console/include/functions_treeview.php
@@ -693,10 +693,10 @@ function treeview_getData ($type) {
 			switch ($config["dbtype"]) {
 				case "mysql":
 				case "postgresql":
-					$list = db_get_all_rows_sql("SELECT * FROM tgrupo WHERE nombre IN (" . $stringAvariableGroups . ") $sql_search");
+					$list = db_get_all_rows_sql("SELECT * FROM tgrupo WHERE nombre IN (" . $stringAvariableGroups . ") $sql_search ORDER BY nombre COLLATE utf8_general_ci ASC");
 					break;
 				case "oracle":
-					$list = db_get_all_rows_sql("SELECT * FROM tgrupo WHERE dbms_lob.substr(nombre,4000,1) IN (" . $stringAvariableGroups . ")");
+					$list = db_get_all_rows_sql("SELECT * FROM tgrupo WHERE dbms_lob.substr(nombre,4000,1) IN (" . $stringAvariableGroups . ") ORDER BY nombre COLLATE utf8_general_ci ASC");
 					break;
 			}
 			break;
@@ -748,7 +748,8 @@ function treeview_getData ($type) {
 						tagente.id_grupo IN  ($groups) AND
 						tagente.nombre LIKE '%$search_free%' AND
 						tagente.disabled = 0 AND
-						tagente_modulo.disabled = 0";
+						tagente_modulo.disabled = 0
+						ORDER BY tpolicies.name COLLATE utf8_general_ci ASC";
 				
 				$list = db_get_all_rows_sql($sql);
 				
@@ -823,7 +824,8 @@ function treeview_getData ($type) {
 						tpolicies.id = tpolicy_modules.id_policy AND
 						tagente.id_grupo IN ($groups) AND
 						tagente.disabled = 0 AND
-						tagente_modulo.disabled = 0");
+						tagente_modulo.disabled = 0
+						ORDER BY tpolicies.name COLLATE utf8_general_ci ASC");
 				
 				$element = 0;
 				switch ($select_status) {
@@ -955,7 +957,8 @@ function treeview_getData ($type) {
 						AND tagente.disabled = 0
 						AND ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo" .
 						$search_sql . 
-						$user_tags_sql;
+						$user_tags_sql . 
+						"ORDER BY ttag.name COLLATE utf8_general_ci ASC";
 				
 				$list = db_get_all_rows_sql($sql);
 			break;
@@ -1301,7 +1304,7 @@ function treeview_getSecondBranchSQL ($fatherType, $id, $id_father) {
 		}
 	
 	// This line checks for initializated modules or (non-initialized) asyncronous modules	
-	$sql .= ' AND disabled = 0 AND (utimestamp > 0 OR id_tipo_modulo IN (21,22,23))';
+	$sql .= ' AND disabled = 0 AND (utimestamp > 0 OR id_tipo_modulo IN (21,22,23)) ORDER BY nombre COLLATE utf8_general_ci ASC';
 	return $sql;
 }
 ?>
diff --git a/pandora_console/include/javascript/jquery.pandora.controls.js b/pandora_console/include/javascript/jquery.pandora.controls.js
index 58e3287ce7..26d4b80dcf 100644
--- a/pandora_console/include/javascript/jquery.pandora.controls.js
+++ b/pandora_console/include/javascript/jquery.pandora.controls.js
@@ -41,12 +41,16 @@
 						"recursion" : config.recursion,
 						"filter_agents_json" : config.filter_agents_json,
 						"disabled" : config.disabled ? 1 : 0,
+						// Add a key prefix to avoid auto sorting in js object conversion
+						"keys_prefix" : "_"
 					};
 
 					jQuery.post ("ajax.php",
 						opts,
 						function (data, status) {
 							jQuery.each (data, function (id, value) {
+								// Remove keys_prefix from the index
+								id = id.substring(1);
 								if (id !== 'keycount'){
 									config.callbackPre ();
 									option = $("<option></option>")
diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php
index 329f99db93..dc805de755 100644
--- a/pandora_console/operation/agentes/ver_agente.php
+++ b/pandora_console/operation/agentes/ver_agente.php
@@ -46,6 +46,8 @@ if (is_ajax ()) {
 	if ($get_agents_group_json) {
 		$id_group = (int) get_parameter('id_group');
 		$recursion = (int) get_parameter ('recursion', 0);
+		// Is is possible add keys prefix to avoid auto sorting in js object conversion
+		$keys_prefix = (string) get_parameter ('keys_prefix', '');
 		
 		if ($id_group > 0) {
 			$groups = array($id_group);
@@ -59,10 +61,18 @@ if (is_ajax ()) {
 			$groups = array_keys($groups_orig);
 		}
 		
-		$filter = " WHERE id_grupo IN (". implode(',', $groups) .")";
+		$filter = " WHERE id_grupo IN (". implode(',', $groups) .") ORDER BY nombre ASC";
 		$agents = db_get_all_rows_sql("SELECT id_agente, nombre
 			FROM tagente" . $filter);
 		
+		// Add keys prefix
+		if ($keys_prefix !== "") {
+			foreach($agents as $k => $v) {
+				$agents[$keys_prefix . $k] = $v;
+				unset($agents[$k]);
+			}
+		}
+		
 		echo json_encode($agents);
 		return;
 	}
diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php
index 3f46c87c04..b2c4e384d8 100644
--- a/pandora_console/operation/tree.php
+++ b/pandora_console/operation/tree.php
@@ -123,6 +123,7 @@ if (is_ajax ())
 				$avariableGroups = users_get_groups();
 				$avariableGroupsIds = array_keys($avariableGroups);
 				$sql = treeview_getFirstBranchSQL ($type, $id, $avariableGroupsIds, $statusSel, $search_free);
+				
 				if ($sql === false) {
 					$rows = array ();
 				}