//This function load data into list, data must be 1,,Pepe;;2,,Juan;;3,,Pablo	
function fill_list(list2,data){
	
	var list= window.document.getElementById(list2);
	//clean list
	clean_list(list2);
	//add data
	var arr_list = data.split(';;');
	for (i in arr_list){
		arr_comp = arr_list[i].split(',,');
		//Put into list
		var id = arr_comp[0];
		var text = arr_comp[1];
		list.options[i] = new Option(text,id); 
		}
	}
	
//This function mark selected id_item in list
function list_set_selected(list2,id){
 var list= window.document.getElementById(list2);
 for(var i=0;i < list.length;i++){
  if(list.options[i].value==id){
   list.options[i].selected = true;
   }else{
   list.options[i].selected = false;	
   }	
  }
 }	
	
//This function remove all elements from list
function clean_list(list2){
	list = window.document.getElementById(list2);
	num = list.length;
	for (var j=0;j < num;j++){
		list.options[0] = null;
		}
	}	

//This function move selected items on list1 to list2
function move_list_to_list(list1,list2){
	var list1 = window.document.getElementById(list1);
	var list2 = window.document.getElementById(list2);
	var next_list2=list2.length;
	for(var i=0;i < list1.length;i++){
		if(list1.options[i].selected){
			//Move to list2
			list2.options[next_list2] = new Option(list1.options[i].text,list1.options[i].value);
			next_list2++;
			list1.options[i].borrar=1;
			}
		}	
	//Delete options from list1
	for(var j=0;j<list1.length;j++){
		if(list1.options[j].borrar==1){
			list1.options[j] = null;
			j--;
			}
		}	
	}
	
//This function do a string with options selected and set hidden on form
//string: 1,,Pepe;;3,,Pablo
function list_selected_to_hidden(list,hidden){
	var string='';
	var separator = '';
	vl_list=window.document.getElementById(list);
	for(var i=0;i<vl_list.length;i++){
		if(vl_list.options[i].selected=1){
			string = string + separator;
			string = string + vl_list.options[i].value;
			separator = ';;';
			}	
		}
	vl_hidden=window.document.getElementById(hidden);
	vl_hidden.value=string;
	}
	
//This function return number of elements in a list
function list_num_of_elements(list){
	vl_list = window.document.getElementById(list);
	return (vl_list.length);
	}