function escribir_mensaje(){
	Effect.toggle('contenido_ppal','blind');
	Effect.toggle('frm_comentar','blind');	
}

function mostrar_regalo(){
	setTimeout("Effect.toggle('div_regalos','blind');",2000);
	Effect.toggle('contenido_ppal','blind');
	
}

function contarCaracteres(elemento, elemento_informacion) {
	obj = document.getElementById(element);
	var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : '';

	text = obj.value;
	
	if (obj.getAttribute && obj.value.length>mlength) {
		obj.value = obj.value.substring(0, mlength);
	} else {
		document.getElementById(elemento_informacion).innerHTML = (mlength-text.length) + ' caracteres m&aacute;s';
	}
}

/* ----------------------------------- */
function cargar_comentarios(listURL) {
	defaultList = listURL;
	
	mostrar('espera', 'block');
	mostrar('list_', 'none');
	
	new Ajax.Updater('list_', listURL, {
		onComplete:function(request) {
			mostrar('espera', 'none');
			mostrar('list_', 'block');
		}
	});

}

/* ----------------------------------- */
function enviar() {
	mostrar('espera_envio', 'inline');
	
	new Ajax.Updater('add_', direccion, { 
		parameters:Form.serialize('_form'), 
		onComplete:function(request) {
			// hide indicator
			mostrar('espera_envio', 'none');

			// reload list
			if (document._form.success.value) {
				Effect.toggle('add_','blind');
				// clear form
				document._form.by_name.value  = '';
				document._form.by_email.value = '';
				document._form.by_url.value   = 'http://';
				document._form.texto.value     = '';
				document._form.success.value  = 0;
				
				cargar_comentarios(listURL);
			}
		}
	});
}
//-------------------------------------
function mostrar(element, style) {
	eval("document.getElementById('" + element + "').style.display = style;");	
}

/* ----------------------------------- */
function cambiarClase(elemento, nombre) {
	eval("document.getElementById('" + elemento + "').className = nombre;");	
}

/* ----------------------------------- */
function toggle(element, style) {
	if (document.getElementById(element).style.display != 'none') {
		style = 'none';
	}
	mostrar(element, style)
}