// JS functions for FAQs

function faqs_add_new_cat(sort_id) { 
	var new_faq_cat_name = window.prompt("Please enter a new FAQ category name...", "New FAQ Category");
	if(new_faq_cat_name) {
		document.faqs_form.new_cat_label.value = new_faq_cat_name;
		document.faqs_form.new_sort_value.value = sort_id;
		document.faqs_form.action.value = 'manage_faqs';
		document.faqs_form.command.value = 'add_new_faq_cat';
		document.faqs_form.submit();
	}		
}


function faqs_update_cat(cat_id, cat_name) { 
	var new_faq_cat_name = window.prompt("Rename Category\n\n - "+cat_name+"\n\nto:");
	if(new_faq_cat_name) {
		document.faqs_form.new_cat_label.value = new_faq_cat_name;
		document.faqs_form.faq_cat_id.value = cat_id;
		document.faqs_form.action.value = 'manage_faqs';
		document.faqs_form.command.value = 'update_faq_cat';
		document.faqs_form.submit();
	}
}


function faqs_remove_global(faq_id, cat_id) { 
	if(faq_id) {
		if(confirm("Are you sure you want to remove this global FAQ?")) {
			document.faqs_form.faq_cat_id.value = cat_id;
			document.faqs_form.faq_id.value = faq_id;
			document.faqs_form.action.value = 'manage_faqs';
			document.faqs_form.command.value = 'remove_global';
			document.faqs_form.submit();
		}
	}
}


function faqs_remove_cat(cat_id, cat_label, cat_sort, cat_status) { 
	if(cat_status == true) {
		if(confirm("Are you sure you want to PERMANENTLY delete category:\n\n - "+cat_label)) {
			document.faqs_form.faq_cat_id.value = cat_id;
			document.faqs_form.new_sort_value.value = cat_sort;
			document.faqs_form.action.value = 'manage_faqs';
			document.faqs_form.command.value = 'delete_faq_cat';
			document.faqs_form.submit();
		}
	}else{
		alert("You can only delete categories that have no FAQs in them.\n\nRemove all FAQs from this category then remove it.");
	}
}


function faqs_edit(faq_id) { 
	if(faq_id) {
		document.faqs_form.faq_id.value = faq_id;
		document.faqs_form.action.value = 'add_faqs_form';
		document.faqs_form.submit();
	}
}


function faqs_move_cat(sort_dir, faq_id) { 
	if(faq_id) {
		document.faqs_form.faq_sort_dir.value = sort_dir;
		document.faqs_form.faq_cat_id.value = faq_id;
		document.faqs_form.action.value = 'manage_faqs';
		document.faqs_form.command.value = 'move_faq_cat';
		document.faqs_form.submit();
	}
}


function faqs_move(sort_dir, cat_id, faq_id) { 
	if(faq_id) {
		document.faqs_form.faq_sort_dir.value = sort_dir;
		document.faqs_form.faq_move_id.value = faq_id;
		document.faqs_form.faq_cat_id.value = cat_id;
		document.faqs_form.action.value = 'manage_faqs';
		document.faqs_form.command.value = 'move_faqs';
		document.faqs_form.submit();
	}	
}