/* Rich Text Editing functions */

function rte_preview(id) {
	var textarea = document.getElementById(id);
	var preview = document.getElementById(id + '_preview');

	if (preview.style.display == 'block')
		return; // Already in preview mode

	preview.innerHTML = textarea.value;
	textarea.style.display = 'none';
	preview.style.display = 'block';
}

function rte_edit(id) {
	var textarea = document.getElementById(id);
	var preview = document.getElementById(id + '_preview');

	if (preview.style.display == 'none')
		return; // Already in edit mode

	textarea.style.display = 'block';
	preview.style.display = 'none';
}

/* JavaScript needs a proper sprintf implementation and default parameters... */
function rte_insert0A(input_id, arg) {
	document.getElementById(input_id).value += arg;
}
function rte_insert1A(input_id, question, format, def) {
	var arg = prompt(question, def);
	document.getElementById(input_id).value += sprintf(format, arg);
}
function rte_insert2A(input_id, firstQuestion, secondQuestion, format, firstDefault, secondDefault) {
	var farg = prompt(firstQuestion, firstDefault);
	var sarg = prompt(secondQuestion, secondDefault);
	document.getElementById(input_id).value += sprintf(format, farg, sarg);
}
