// Javascript functies voor administratiegedeelte
// Pros: Sessie nodig

var last_known_id = 0;
var last_known_text = null;
var last_known_title = null;

var template_full = null;
var template_style = 'style="width:80%; height: 25px;"';
var template_link = '<a href="javascript:void(0)" ';
var template_image = '<img src="/img/hoofd/hammer.png" width="16" height="16" alt="Annuleren" />';
var template_save_link = '&nbsp;<a href="javascript:void(0)" onclick="doTitle_save()">';
var template_save_img = '<img src="/img/hoofd/disk__arrow.png" width="16" height="16" alt="Opslaan?" />';
var debug = true;

function doText_box(titID)
{
	/* Laatst bekende ID en titel sluiten! */
	doText_cancel(last_known_id);
	
	/* Laatste settings opslaan */
	last_known_id = titID;
	last_known_text = String($("#text_" + last_known_id).html());
	var template_input_text = '<textarea id="wijzig_text_'+last_known_id+'" name="wijzig_text_'+last_known_id+'" style="width:95%;height:200px">';
	
	/* De oude knoppen hiden */
	$("#te_"+titID).hide();
	
	/* Volledige template zetten */
	template_full = '<form id="frmOpslaan_'+titID+'" name="frmOpslaan_'+titID+'" method="POST">';
	template_full += template_input_text + last_known_text + '</textarea>';
	template_full += '<br />';
	template_full += template_link + ' onClick="doText_cancel(\''+last_known_id+'\')">';
	template_full += template_image + ' </a>';
	template_full += '&nbsp;<a href="javascript:void(0)" onClick="doText_save()">';
	template_full += template_save_img + '</a>';
	template_full += '<input type="hidden" name="id" id="id" value="'+last_known_id+'" />'
	template_full += '</form>';
	
	$("#text_" + titID).empty().append("Moment ...");
	$("#text_" + titID).empty().append(template_full);
	
	$('textarea').fck({path: '/img/fckeditor/', toolbar:'Basic'}); 
		
}

function doText_save(titID)
{
	document.forms[0].submit();
}

function doText_cancel(titID)
{
	//alert("Gecancelled");
}

function doTitle_box(titID)
{
	/* Laatst bekende ID en titel sluiten! */
	doTitle_cancel(last_known_id);
	
	/* Laatst bekende ID en titel zetten */
	last_known_id = titID;
	last_known_title = String($("#tit_" + last_known_id).html());
	var template_input_title = '<input type="text" name="wijzig_titel_'+last_known_id+'" id="wijzig_titel_'+last_known_id+'" ';
	
	$("#tv_"+titID).hide();
	
	/* Volledige template zetten */
	template_full = template_input_title + 'value="'+last_known_title+'" '+template_style+' />';
	template_full += '&nbsp;';
	template_full += template_link + 'onClick="doTitle_cancel(\''+last_known_id+'\')">';
	template_full += template_image + '</a>';
	template_full += template_save_link;
	template_full += template_save_img + '</a>';
	
	$("#tit_" + titID).empty().append("Moment ...");
	$("#tit_" + titID).empty().append(template_full);
}

function doTitle_save()
{
	// Vergeet hier niet de String($("#...").html()) functie te gebruiken voor de tekst.
	//alert("De tekst '"+last_known_title+"' wordt opgeslagen op ID '"+last_known_id+"'");
	doAjax("POST", "/doSave.php", "id="+last_known_id+"&titel=" + $("#wijzig_titel_" + last_known_id).val());
	last_known_title = $("#wijzig_titel_" + last_known_id).val();
	doTitle_cancel(last_known_id);
}

function doTitle_cancel(titID)
{
	$("#tit_" + titID).empty().append(last_known_title);
	$("#tv_"+titID).show();
	last_known_id = null;
	last_known_title = null;
}

function doAjax(iType, iAdres, iData)
{
	$.ajax({
		type: iType,
		url: iAdres,
		data: iData,
		success: function(msg){
			if(debug == true)
			{
				alert("* Debug *\n\n" + msg);
			}
		}
	});
}


function confirmHet(el)
{
	if(confirm("Dit bericht wordt dus verwijderd. Doorgaan?"))
	{
		doAjax("POST", "/doSave.php", "verwijder=" + el);
	}
}













