		function tag(id)	{return document.getElementById(id);}
		function poner_evento(elemento, evento, f)	{
			if (document.addEventListener)
				elemento.addEventListener(evento, f, true);
			else
				if (document.attachEvent)
					elemento.attachEvent("on" + evento, f);
				else
					elemento["on" + evento] = f;
		}

		var _el_editor;
		function validar_comentario(e)	{
			f = this;
			captch = f.captcha.value;
			coment = f.comentario.value;
			_email = f.comentario.value;
			var mensajes = [];
			if (captch == "")	mensajes.push("No se olvide escribir el código de seguridad.");
			if (coment == "")	mensajes.push("No se puede enviar un comentario en blanco.");
			if (mensajes.length > 0)	{
				alert(mensajes.join("\n"));
				cancelar_evento(e);
			}
		}



		function refrescarme()	{
			this.src = 'diario/captcha.png?azar=' + Math.floor(Math.random() * 9999);
		}

		function activar_editor()	{_el_editor = ini_editor(this);}
		function pon_web()	{
			texto_editor = _lector();
			url_web = prompt("Introduzca el enlace:", "http://");
			poner_texto = (texto_editor == "") ? url_web:texto_editor;
			_insertar(_el_editor, "[url=" + url_web + "]" + poner_texto + "[/url]");
		}

		function pon_foto()	{
			texto_editor = _lector();
			url_foto = prompt("Introduzca url de la foto:", "http://");
			_insertar(_el_editor, "[img]" + url_foto + "[/img]");
		}

		function pon_emoticon()	{_insertar(_el_editor, ";-)");}

		function pon_negrita()	{_insertar(_el_editor, "[n]" + _lector() + "[/n]");}
		function pon_cursiva()	{_insertar(_el_editor, "[c]" + _lector() + "[/c]");}
		function pon_subrayado()	{_insertar(_el_editor, "[s]" + _lector() + "[/s]");}


		window.onload = function()	{
			poner_evento(tag("form_comentar"), "submit", validar_comentario);
			poner_evento(tag("valorador"), "change", cambiar_evaluador_select);
			for (i = 1; i < 11; i++)
				poner_evento(tag("estrella_" + i), "click", cambiar_evaluador_estrella);
			poner_evento(tag("evaluar"), "submit", evaluar_con_Ajax);
			poner_evento(tag("listado_historial"), "submit", actualizar_historial);
			poner_evento(tag("imagen_captcha"), "click", refrescarme);
			poner_evento(tag("control_comentario"), "focus", activar_editor);
			poner_evento(tag("poner_negrita"), "click", pon_negrita);
			poner_evento(tag("poner_cursiva"), "click", pon_cursiva);
			poner_evento(tag("poner_subrayado"), "click", pon_subrayado);
			poner_evento(tag("poner_web"), "click", pon_web);
			poner_evento(tag("poner_foto"), "click", pon_foto);
			poner_evento(tag("poner_emoticon"), "click", pon_emoticon);
			_el_editor = ini_editor(tag("control_comentario"));
		}

		fondo_estrella = {"false" : "ffffff", "true": "ffcc00"};
		function cambiar_evaluador_select()	{
			valor = parseInt(this.value);
			for (i = 1; i < 11; i++)
				tag("estrella_" + i).src = "diario.estrella.php?color=" + fondo_estrella[i <= valor];
		}

		function cambiar_evaluador_estrella()	{
			valor = parseInt(this.id.substr(9));
			for (i = 1; i < 11; i++)
				tag("estrella_" + i).src = "diario.estrella.php?color=" + fondo_estrella[i <= valor];
			tag("valorador").value = valor;
		}

		function objetoAjax()	{
			if (window.XMLHttpRequest)
				_ajax = new XMLHttpRequest();
			else
				if (window.ActiveXObject)
					_ajax = new ActiveXObject("Microsoft.XMLHTTP");
				else
					_ajax = false;
			return _ajax;
		}

		function evaluar_con_Ajax(e)	{
			f = this;
			if (f.valor.value == "0")	{
				respuesta = "No ha hecho ninguna valoración...";
				tag("mensaje_respuesta_valorador").innerHTML = respuesta;
			}
			else	{
				url = f.action + "?pagina=" + f.pagina.value + "&valor=" + f.valor.value;
				Ajax = objetoAjax();
				params = "ajax=si";
				Ajax.open("POST", url, true);
				Ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				Ajax.onreadystatechange = function()	{
					if(Ajax.readyState == 4 && Ajax.status == 200) {
						nueva_imagen = "diario.estrellas.php?pagina=" + f.pagina.value + "&fantasma=" + Math.random();
						tag("valorada").src = nueva_imagen;
						respuesta = Ajax.responseXML.getElementsByTagName("error")[0].firstChild.data;
						tag("mensaje_respuesta_valorador").innerHTML = respuesta;
					}
				}
				Ajax.send(params);
			}
			cancelar_evento(e);
		}

		function cancelar_evento(e) {
			if (!e) e = window.event;
			if (e.preventDefault) {
				e.preventDefault();
			} else {
				e.returnValue = false;
			}
		}

		function actualizar_historial(e)	{
			f = this;
			hs = [];//[f["h[]"][0]];
			ns = [];
			for (i = 0, hhs = f["h[]"], total = hhs.length; i < total; i++)
				if (hhs[i].checked)
					hs.push("h[]=" + escape(hhs[i].value))
				else
					ns.push(hhs[i].value)
				
			if (ns.length == 0)	{
				alert("No hemos detectado cambios en el historial...");
			}
			else	{
				url = f.action;// + "diario.plugin.php?plugin=modificar_historial";
				Ajax = objetoAjax();
				params = "ajax=si&" + hs.join("&");
				Ajax.open("POST", url, true);
				Ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				Ajax.onreadystatechange = function()	{
					if(Ajax.readyState == 4 && Ajax.status == 200) {
						for (i = 0, hhs = f["h[]"], total = hhs.length; i < total; i++)
							if (!hhs[i].checked)
								hhs[i].parentNode.style.display = "none";
					
						//alert(Ajax.responseText);
					}
				}
				Ajax.send(params);
			}
			cancelar_evento(e);
		}

