var invite_proceeding = false;
var contacts = {
    contacts_tabs_click: function(item_name, page, param)
    {
    	jQuery('.contacts_tab').removeClass('act');        
    	switch (item_name)
    	{
            case 'header_invited_contacts':
                action_file = site_url + 'inc/contacts/get_invited.php';            
            break;        
            case 'header_contacts_members':
                action_file = site_url + 'inc/contacts/get_contacts_members.php';        
            break;
            case 'header_contacts_friends':
                action_file = site_url + 'inc/contacts/get_contacts_friends.php';            
            break;
    	}    
        params = 'id=' + user_id;
    	load_page(action_file, 'abcd', params);
    	jQuery('#'+item_name).addClass('act');        
    },
    
    set_user_id: function (_id)
    {
        user_id = _id;            
    },
    
    toggle_checkboxes: function ()
    {
        if (jQuery("#head_checkbox").attr('checked') == false)
        {
            jQuery(":checkbox").each(function(index)
            {        
                jQuery(this).attr('checked', false);
            });
        } else
        {
            jQuery(":checkbox").each(function(index)
            {        
                jQuery(this).attr('checked', true);
            });
        }        
    },
    
    distinct_toggle_checkbox: function (_this)
    {
        if (jQuery(_this).attr('checked') == false)
        {
            jQuery("#head_checkbox").attr('checked', false);
        }              
        if (jQuery('.contact_checkbox:checked').length == jQuery('.contact_checkbox').length)
            jQuery("#head_checkbox").attr('checked', true);
    },
    
    remove_contacts: function ()
    {
        var contacts = new Array();
        jQuery(".contact_checkbox").each(function (index)
            {                       
                if (jQuery(this).attr("checked")==true)
                {
                    contacts.push(jQuery(this).attr("name"));
                    
                }                                        
            });   
        if (contacts.length > 0)
        {
            jQuery.get("ajax/contacts/del_contact.php", {'ids[]': contacts}, function (data){ 
                click_inboxTabs('my_contacts', 'friend_content'); 
                });                        
        }                 
    },    
    
    mass_invite: function()
    {             
        if (invite_proceeding == false)
        {
            invite_proceeding = true;            
            var mails = new Array();
            jQuery(".contact_checkbox").each(function (index)
                {
                    if (jQuery(this).attr("checked")==true)
                    {
                        mails.push(jQuery(this).attr("name"));
                    }
                });    
            if (mails.length > 0)
            {
                jQuery.get("ajax/contacts/invite.php", {'ids[]': mails}, function (data) {
                    jconfirm.jmessage('You have sent a RoomFT invitation to "'+mails.length+'" contacts');
                    //alert ('You have sent a RoomFT invitation to "'+mails.length+'" contacts');
                    invite_proceeding = false;
                    click_inboxTabs('my_contacts', 'friend_content');                 
                    })                    
            }            
        } else 
        {
            alert ('Please wait until the current invite request is finished');
        }        
    }   
}
