/* Edicion de texto */
var nuMax = 0;
function emoticon(emo) {
	var obj = document.getElementById('comentario');
	obj.value += emo;
	obj.focus();
	maximo();
}

function bbcode(type) {
	var obj = document.getElementById('comentario');
	obj.value += '[' + type + '][/' + type + ']';
	obj.focus();
	maximo();
}

function maximo() {
	if (nuMax == 0)
		nuMax = Number(document.getElementById('maximo').innerHTML);
	var obj = document.getElementById('comentario');
	if (obj.value.length > nuMax)
		obj.value = obj.value.substring(0, nuMax);
	else
		document.getElementById('maximo').innerHTML = (nuMax-obj.value.length);
}
/* Edicion de texto */


/* Transferencia de datos */
function Comentar(obj)
{
	if (obj.comentario.value != '')
	{
		micargador.setClase('cargadon');
		micargador.setAlpha(100);
		ajax.Request({
			url: obj.action,
			method: obj.method,
			param: ajax.DataForm(obj),
			onOK: ComentarRecibe
		});
		return false;
	}
	else return false
}

function ComentarRecibe(obj)
{
	//alert(obj.responseText);
	micargador.Animar({
		alfa: 0,
		onFin: ocultar
	});
	if (obj.responseText.substr(0, 5) == 'error')
		alert(obj.responseText.substr(6))
	else
	{
		$('comentarios').innerHTML += obj.responseText;
		$('previa').innerHTML = '';
	}
	//$('comentario').value = '';
}

//Vista previa
function Previa(obj)
{
	if (obj.value != '')
	{
		micargador.setClase('cargadon');
		micargador.setAlpha(100);
		ajax.Request({
			url: 'inc/comentar.php',
			method: 'POST',
			param: 'previa=' + obj.value,
			onOK: PreviaRecibir
		});
		return false;
	}
}
function PreviaRecibir(obj)
{
	micargador.Animar({
		alfa: 0,
		onFin: ocultar
	});
	$('previa').innerHTML = '<br /><br /><span class="t_blanco"><b>Vista Previa</b></span><br /><br />' + obj.responseText;
}
function ocultar(){ micargador.setClase('cargadoff'); }

//Eliminar
function Elimina(id_comentario, area, idarea)
{
	if (confirm("¿Seguro que quieres borrar este comentario?"))
	{
		ajax.Request({
			url: 'inc/comentar.php',
			method: 'POST',
			param: 'borra=' + id_comentario + '&area=' + area + '&id=' + idarea,
			onOK: EliminaRecibir
		});
	}
	return false;
}
function EliminaRecibir(obj)
{
	if (obj.responseText != '')
		alert(obj.responseText);
}