

jQuery(document).ready(function($)
{
		function registerRemoveAction()
		{
			
		    jQuery('a.catmanremoveaction').click(function () {
		        var postID = this.getAttribute('postID');
		        var category = this.getAttribute('catID');
		        var node = document.getElementById('catmanagerpost' + postID);
		
		        if( catmansettings.showConfirm != 'on'  || (catmansettings.showConfirm == 'on'
		            && confirm('Are you sure you want to remove the category from the post?')) )
		            {
		            $.ajax( {
		                type: "POST",
		                url: catmansettings.plugin_url + "manage-category.php",
		                data: "action=remove&category=" + category + "&postID=" + postID +'&_ajax_nonce=' + catmansettings.nonce,
		                success: function(msg){
		                    jQuery(node).fadeOut(500, null);
		                },
		                error: function(msg){
		                    alert('Error :' + msg.responseText);
		                }
		            });
		        }
		    });
		}

		registerRemoveAction();		

    jQuery('.catmanselection select').change(
                    function(){
                    	var cat = this.value;
                        jQuery('#catmanpostlist').fadeTo(200, 0.1).load(catmansettings.plugin_url + 'manage-category.php'
                            ,'action=getPosts&category=' + cat + '&_ajax_nonce=' + catmansettings.nonce
                            , function() { 
                            	jQuery('#catmanpostlist').fadeTo(200, 1.0); 
                            	jQuery('#cat_manager_dashboard_widget h3').html('<span>Managing Category - ' + cat + '</span>');
															registerRemoveAction();
                            	});
                    });
 });



