function rm(id,myid){var rm_pk=$('#li_'+myid+'_'+id+' .delete_from_m2m').parent().attr('id').substr(myid.length+4);$('ul#list_'+myid+' li#li_'+myid+'_'+rm_pk+':first').remove();$('#id_'+myid+' #'+rm_pk+':first').remove();$('#id_'+myid+'_display_names #'+myid+'_name_'+rm_pk+':first').remove();}
function djmmsearch(myid,myapp,mymodel,mysearchfields,mysearchurl,media_url){$('#id_'+myid).hide();$('#id_'+myid).parent().children().filter('.add-another:last').hide();var event=$('#lookup_'+myid).autocomplete(mysearchurl,{extraParams:{search_fields:mysearchfields,app_label:myapp,model_name:mymodel}});event.result(function(event,data,formatted){$('#busy_'+myid).hide();if(data){var elem=$('#list_'+myid+' li#'+data[1]);if(!elem.attr("id")){$('#list_'+myid).html($('#list_'+myid).html()+'<li id="li_'+myid+'_'+data[1]+'"><div class="object_repr">'+data[0]+'</div><div class="delete_from_m2m"><a onClick="javascript:rm('+data[1]+',\''+myid+'\')"><img src="'+media_url+'admin/img/admin/icon_deletelink.gif" /></a></div></li>');$('#lookup_'+myid).val('');$('#id_'+myid).html($('#id_'+myid).html()+'<option id="'+data[1]+'" value="'+data[1]+'" selected="selected">'+data[0]+'</option>');$('#id_'+myid+'_display_names').html($('#id_'+myid+'_display_names').html()+'<option id="'+myid+'_name_'+data[1]+'" value="'+data[0]+'|'+data[1]+'" selected="selected">'+data[0]+'</option>');$('.delete_from_m2m').click(function(){var rm_li=$(this).parent();var rm_pk=$(rm_li).attr("id");$('ul#list_'+myid+' li#li_'+myid+'_'+rm_pk+':first').remove();$('#id_'+myid+' #'+rm_pk+':first').remove();$('#id_'+myid+'_display_names #'+myid+'_name_'+rm_pk+':first').remove();});}}});}