var list_delimiter = ",";
var list_text_only = false;

var list_counter = 1;
var list_values = Array();

function add_mini_to_list(mainList, subList, prefix) {
   var mc_name = subList.options[subList.selectedIndex].text;
   
   if ( mc_name == 'Please Select' || mc_name == 'Please select category first') {
      return;
   }

   var mc_list_html = document.getElementById (prefix + "list");   
   var mc_list = new Array();
   
   if ( mc_list_html.value ) {
      mc_list = mc_list_html.value.split(list_delimiter);
   }

   var to_add = ""
   if ( list_text_only ) {
      to_add = mainList.value + " - " + subList.value;
   } else {
      to_add = subList.value;
   }
   
      
   var i;
   for ( i in mc_list ) {
      if ( mc_list[i] == to_add ) {
         // mc already in list
         return;
      }
   }
   
   var to_add = ""
   if ( list_text_only ) {
      to_add = mainList.value + " - " + subList.value;
   } else {
      to_add = subList.value;
   }
   mc_list.push (to_add);
   
   mc_list_html.value = mc_list.join(list_delimiter);
   list_values[list_counter] = to_add;
   
   //alert ("in add_mini_to_list");
   //alert (mainList, subList);
   
   var mc_text = "<div id=\"" + prefix + list_counter + "\">" + mainList.value + " - " + mc_name +
      " [<a href=\"\" onclick=\"remove_mini_from_list(" + list_counter + ", '" + prefix + "'); return false;\">remove</a>]</div>";
      
   var mc_target = document.getElementById (prefix + "target");
   mc_target.innerHTML = mc_target.innerHTML + mc_text
 
   list_counter++;
   
   return     
}

function remove_mini_from_list ( mc, prefix ) {
   var mc_list_html = document.getElementById (prefix + "list");   
   var mc_list = mc_list_html.value.split(list_delimiter);
   
   var to_rm = list_values[mc];
   
   var new_list = new Array();
   var i = 0;
   for ( i in mc_list ) {
      if ( mc_list[i] != to_rm ) {
         new_list.push(mc_list[i]);   
      }
   }
   mc_list_html.value = new_list.join(list_delimiter);
   
   var to_remove = document.getElementById (prefix + mc);
   
   to_remove.parentNode.removeChild(to_remove);
 
   return  
}