// JS functions for the links category

function dds_add_new_cat(sort_id) { 
			
			var new_dds_cat_name = window.prompt("Please enter a new document category name...", "New Document Category");
			
			if( new_dds_cat_name ) {
					document.dds_form.new_dds_cat_name.value = new_dds_cat_name;
					document.dds_form.new_sort_value.value = sort_id;
					document.dds_form.command.value = 'insert_cat';
					document.dds_form.submit();
			}
			
}

function dds_update_cat(cat_id, cat_name) { 
			
			var new_dds_cat_name = window.prompt("Rename your selected links category to...", cat_name);
			
			if( new_dds_cat_name ) {
					document.dds_form.new_dds_cat_name.value = new_dds_cat_name;
					document.dds_form.dds_cat_id.value = cat_id;
					document.dds_form.action.value = 'manage_docs';
					document.dds_form.command.value = 'rename_cat';
					document.dds_form.submit();
			}
			
}

function dds_switch_cat(cat_id, cat_status) { 
			
			if( cat_id ) {
					document.dds_form.dds_cat_status.value = cat_status;
					document.dds_form.dds_cat_id.value = cat_id;
					document.dds_form.action.value = 'manage_docs';
					document.dds_form.command.value = 'switch_cat';
					document.dds_form.submit();
			}
			
}


function dds_remove_global(link_id, cat_id) { 
			
	if( link_id ) {
			
		if( confirm("Are you sure you wish to remove this global link?") ) {
			
				document.dds_form.link_cat_id.value = cat_id;
				document.dds_form.link_id.value = link_id;
				document.dds_form.action.value = 'manage_links';
				document.dds_form.command.value = 'remove_global';
				document.dds_form.submit();
						
		}
		
	}
			
}


function dds_remove_cat(cat_id, cat_status) { 
			
	if( cat_status == true ) {
			
		if( confirm("Are you sure you wish to PERMANENTLY delete this category?") ) {
			
				document.dds_form.dds_cat_id.value = cat_id;
				document.dds_form.action.value = 'manage_docs';
				document.dds_form.command.value = 'delete_cat';
				document.dds_form.submit();
						
		}
		
	}else{
		
		alert("You can only delete categories that have no documents in them.\n\nRemove all documents from this category then remove it.");
		
	}
			
}

function dds_edit(link_id) { 
			
		if( link_id ) {
					document.dds_form.link_id.value = link_id;
					document.dds_form.action.value = 'add_dds_form';
					document.dds_form.submit();
		}
			
}


function dds_move_cat(sort_dir, link_id) { 
			
		if( link_id ) {
					document.dds_form.link_sort_dir.value = sort_dir;
					document.dds_form.link_cat_id.value = link_id;
					document.dds_form.action.value = 'manage_links';
					document.dds_form.command.value = 'move_link_cat';
					document.dds_form.submit();
		}
			
}

function dds_move(sort_dir, cat_id, link_id) { 
			
		if( link_id ) {
					document.dds_form.link_sort_dir.value = sort_dir;
					document.dds_form.link_move_id.value = link_id;
					document.dds_form.link_cat_id.value = cat_id;
					document.dds_form.action.value = 'manage_links';
					document.dds_form.command.value = 'move_link';
					document.dds_form.submit();
		}
			
}

