var NV = NV||{}

NV.findParent = function (element){
    var isContactstable = false;
    try{
		if(typeof jQuery(element).attr !== 'undefined'){
			isContactstable = (jQuery(element).attr('class').indexOf('nv_contacts_table') != -1)||(jQuery(element).attr('class').indexOf('nv_addresslist_table') != -1);
		}
    } catch(e) {
		//console.log(e);
    }
    
    if(isContactstable){
        return element;
    } else {
        return NV.findParent(jQuery(element).parent());
    }
}
function openNewMailEditorWithCollection(element, collection,id) {
    url = 'index.php?eID=getRecipientlist&collection='+collection+'&id='+id;
    jQuery.post(url, function(data) {
		var parent = NV.findParent(element);
		mailAll = jQuery(parent).siblings('.mail_all');
		if(mailAll.length > 0){
			return;
		}
		jQuery(parent).before('<div class="mail_all"><textarea rows="4" style="width:724px">' + unescape(data) + '</textarea><p>Kopier ovenst&aring;ende ind i din mailklient. <a href="javascript:removeMailAll()" class="mail-all-remove">skjul denne boks</a></p></Div>');
    }
			   );
}

function removeMailAll(){
	jQuery('.mail_all').remove();
}

